33namespace org \CreadoresProgram \BarrelClassicDetect ;
44use pocketmine \plugin \PluginBase ;
55use pocketmine \player \Player ;
6- use pocketmine \event \Listener ;
7- use pocketmine \event \server \DataPacketSendEvent ;
8- use pocketmine \network \mcpe \protocol \TextPacket ;
9- class PocketmineMain extends PluginBase implements Listener{
6+ class PocketmineMain extends PluginBase{
107 private static ?self $ instance = null ;
8+ private static string $ deviceModelCC = "Barrel CREA Classic " ;
9+ private static string $ deviceModelP = "DeviceModel " ;
10+ private static string $ deviceOSP = "DeviceOS " ;
11+ private static string $ defDeviceModel = "" ;
1112 public static function getInstance () : ?self {
1213 return self ::$ instance ;
1314 }
@@ -19,35 +20,11 @@ public function onDisable() : void{
1920 }
2021 public function isCCPlayer (Player $ player ) : bool {
2122 $ extraData = $ player ->getNetworkSession ()->getPlayerInfo ()->getExtraData ();
22- $ deviceModel = $ extraData [" DeviceModel " ] ?? "" ;
23- $ osId = $ extraData [" DeviceOS " ] ?? -1 ;
24- return ($ deviceModel == " Barrel CREA Classic " ) && ($ osId == 7 );
23+ $ deviceModel = $ extraData [self :: $ deviceModelP ] ?? self :: $ defDeviceModel ;
24+ $ osId = $ extraData [self :: $ deviceOSP ] ?? -1 ;
25+ return ($ deviceModel == self :: $ deviceModelCC ) && ($ osId == 7 );
2526 }
2627 public function getCCPlayers () : array {
2728 return array_filter ($ this ->getServer ()->getOnlinePlayers (), fn ($ player ) => $ this ->isCCPlayer ($ player ));
2829 }
29- public function onDataPacketSend (DataPacketSendEvent $ event ) : void {
30- $ packets = $ event ->getPackets ();
31-
32- foreach ($ packets as $ packet ){
33- if ($ packet instanceof TextPacket){
34- if ($ packet ->type !== TextPacket::TYPE_TRANSLATION ){
35- continue ;
36- }
37- foreach ($ event ->getTargets () as $ target ){
38- $ player = $ target ->getPlayer ();
39- if ($ player instanceof Player && $ this ->isCCPlayer ($ player )){
40-
41- $ event ->cancel ();
42-
43- $ newPacket = TextPacket::raw (
44- $ this ->getServer ()->getLanguage ()->translateString ($ packet ->message , $ packet ->parameters )
45- );
46-
47- $ target ->sendDataPacket ($ newPacket );
48- }
49- }
50- }
51- }
52- }
5330}
0 commit comments