public void addChair(Player player, Block block) { if (disabled) return; try { PacketContainer entitymeta = ProtocolLibrary.getProtocolManager().createPacket(40); entitymeta.getSpecificModifier(int.class).write(0, player.getEntityId()); WrappedDataWatcher watcher = new WrappedDataWatcher(); watcher.setObject(0, (byte) 4); entitymeta.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); for (Player play : plugin.getServer().getOnlinePlayers()) { if (play.getWorld().equals(player.getPlayer().getWorld())) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(play, entitymeta); } catch (InvocationTargetException e) { BukkitUtil.printStacktrace(e); } } } } catch (Error e) { Bukkit.getLogger().severe("Chairs do not work without ProtocolLib!"); disabled = true; return; } if (chairs.containsKey(player.getName())) return; plugin.wrapPlayer(player).print(ChatColor.YELLOW + "You are now sitting."); chairs.put(player.getName(), block); }
/** * Simulate receiving the current packet from the given sender. * * @param sender - the sender. * @throws RuntimeException If the packet cannot be received. */ public void recievePacket(Player sender) { try { ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); } catch (Exception e) { throw new RuntimeException("Cannot recieve packet.", e); } }
/** * Send the current packet to the given receiver. * * @param receiver - the receiver. * @throws RuntimeException If the packet cannot be sent. */ public void sendPacket(Player receiver) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); } catch (InvocationTargetException e) { throw new RuntimeException("Cannot send packet.", e); } }
@SuppressWarnings("deprecation") public static void creaListen(JavaPlugin plug) { if (!NamesTags.APIprotocol) { return; } ProtocolLibrary.getProtocolManager() .addPacketListener( new PacketAdapter( plug, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGH, new Integer[] {Integer.valueOf(20)}) { public void onPacketSending(PacketEvent event) { if (event.getPacketID() != 20) { return; } PacketContainer packetContainer = event.getPacket(); try { String s = NamesTags.getName(event.getPlayer()); packetContainer.getSpecificModifier(String.class).write(0, s); } catch (FieldAccessException e) { e.printStackTrace(); } } }); }
@Override public void onEnable() { PluginManager pm = Bukkit.getPluginManager(); AccountsConfig config; try { config = getLoader().loadOrCreate("config.json", AccountsConfig.class); } catch (GsonLoadException exc) { getLogger().log(Level.SEVERE, "Unable to load config.json", exc); config = new AccountsConfig(); } Accounts accounts = new EVAccounts(this, config); EthilVan.registerAccounts(accounts); Listener accountsListener = new AccountsListener(this); pm.registerEvents(accountsListener, this); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); protocolManager.addPacketListener(new NamePlatePacketListener(this)); CommandsRegistration registration = new CommandsRegistration(this, Locale.FRANCE); registration.register(new AccountsCommands()); Bukkit.getScheduler().runTaskTimer(this, this, 6000, 6000); }
@Override public void onEnable() { logger = getLoggerSafely(); protocolManager = ProtocolLibrary.getProtocolManager(); enchantmentsListener = new HideEnchantmentsListener(getServer(), logger); enchantmentsListener.addListener(protocolManager, this); }
public static void removeSelfDisguise(Player player) { if (selfDisguised.contains(player.getUniqueId())) { // Send a packet to destroy the fake entity PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); packet.getModifier().write(0, new int[] {DisguiseAPI.getSelfDisguiseId()}); try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } catch (Exception ex) { ex.printStackTrace(); } // Remove the fake entity ID from the disguise bin selfDisguised.remove(player.getUniqueId()); // Get the entity tracker try { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); // If the tracker exists. Remove himself from his tracker trackedPlayers.remove(ReflectionManager.getNmsEntity(player)); } } catch (Exception ex) { ex.printStackTrace(); } // Resend entity metadata else he will be invisible to himself until its resent try { ProtocolLibrary.getProtocolManager() .sendServerPacket( player, ProtocolLibrary.getProtocolManager() .createPacketConstructor( PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true) .createPacket( player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true)); } catch (Exception ex) { ex.printStackTrace(); } player.updateInventory(); } }
@Override public void onEnable() { selfieCooldown = new HashMap<UUID, Long>(); saveDefaultConfig(); reloadConfig(); initializeVisibilityManager(); selfieDelay = getConfig().getLong("selfieDelay", 60000); ProtocolLibrary.getProtocolManager().addPacketListener(new PlayerListManager(this)); getCommand("selfie").setExecutor(this); CompatManager.initialize(); }
public void removeChair(Player player) { if (disabled) return; PacketContainer entitymeta = ProtocolLibrary.getProtocolManager().createPacket(40); entitymeta.getSpecificModifier(int.class).write(0, player.getEntityId()); WrappedDataWatcher watcher = new WrappedDataWatcher(); watcher.setObject(0, (byte) 0); entitymeta.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); for (Player play : plugin.getServer().getOnlinePlayers()) { if (play.getWorld().equals(player.getPlayer().getWorld())) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(play, entitymeta); } catch (InvocationTargetException e) { BukkitUtil.printStacktrace(e); } } } plugin.wrapPlayer(player).print(ChatColor.YELLOW + "You are no longer sitting."); chairs.remove(player.getName()); }
public void onEnable() { plugin = this; FileConfiguration config = getConfig(); config.options().copyDefaults(true); MemoryConfiguration defaultConfig = new MemoryConfiguration(); defaultConfig.set("flickerPrevention", Long.valueOf(flickerPrevention)); config.setDefaults(defaultConfig); saveConfig(); reloadConfiguration(); getCommand("tabapi").setExecutor(this); try { new Metrics(this).start(); } catch (IOException e) { e.printStackTrace(); } protocolManager = ProtocolLibrary.getProtocolManager(); Bukkit.getServer().getPluginManager().registerEvents(this, this); for (Player p : Bukkit.getOnlinePlayers()) { Plugin plugin = Bukkit.getPluginManager().getPlugin("TabAPI"); setPriority(plugin, p, 2); resetTabList(p); setPriority(plugin, p, -2); } protocolManager.addPacketListener( new PacketAdapter( this, ListenerPriority.NORMAL, new PacketType[] {PacketType.Play.Server.PLAYER_INFO}) { public void onPacketSending(PacketEvent event) { PacketContainer p = event.getPacket(); List<PlayerInfoData> pinfodata = (List<PlayerInfoData>) p.getPlayerInfoDataLists().read(0); String s = ((PlayerInfoData) pinfodata.get(0)).getProfile().getName(); if (s.startsWith("$")) { List<PlayerInfoData> pinfodataReSend = new ArrayList<PlayerInfoData>(); PlayerInfoData pinfod = (PlayerInfoData) pinfodata.get(0); pinfodataReSend.add( new PlayerInfoData( pinfod.getProfile().withName(s.substring(1)), pinfod.getPing(), pinfod.getGameMode(), WrappedChatComponent.fromText(pinfod.getProfile().getName().substring(1)))); p.getPlayerInfoDataLists().write(0, pinfodataReSend); event.setPacket(p); } else if (TabAPI.protocolManager.getProtocolVersion(event.getPlayer()) < 47) { event.setCancelled(true); } } }); }
@Override public void initialize() throws InvalidConfigurationException { // make sure to enable the respawn module respawnModule.enable(); if (!respawnModule.isEnabled()) { throw new InvalidConfigurationException( "Error enabling the respawn module. The respawn module is required to run hardcore hearts"); } ProtocolLibrary.getProtocolManager().addPacketListener(new HardcoreHeartsListener()); this.icon.setLore(messages.getRawStrings("lore")); }
public UHProtocolLibIntegration(UHPlugin p) { // The plugin is available if this is called. PacketsListener packetsListener = new PacketsListener(p); if (p.getConfig().getBoolean("hardcore-hearts.display")) { ProtocolLibrary.getProtocolManager().addPacketListener(packetsListener); } if (p.getConfig().getBoolean("auto-respawn.do")) { p.getServer().getPluginManager().registerEvents(packetsListener, p); } p.getLogger().info("Successfully hooked into ProtocolLib."); }
/** Method to send a packet to the self disguise, translate his entity ID to the fake id. */ private static void sendSelfPacket(Player player, PacketContainer packet) { PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); try { if (packets == null) { packets = new PacketContainer[] {packet}; } for (PacketContainer p : packets) { p = p.deepClone(); p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false); } } catch (InvocationTargetException e) { e.printStackTrace(); } }
/** A convenience method for me to refresh trackers in other plugins */ public static void refreshTrackers(Entity entity) { if (entity.isValid()) { try { PacketContainer destroyPacket = getDestroyPacket(entity.getEntityId()); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity); if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); Method clear = ReflectionManager.getNmsMethod( "EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod( "EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); HashSet cloned = (HashSet) trackedPlayers.clone(); for (final Object p : cloned) { Player player = (Player) ReflectionManager.getBukkitEntity(p); if (player != entity) { clear.invoke(entityTrackerEntry, p); ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); Bukkit.getScheduler() .scheduleSyncDelayedTask( libsDisguises, new Runnable() { public void run() { try { updatePlayer.invoke(entityTrackerEntry, p); } catch (Exception ex) { ex.printStackTrace(); } } }, 2); } } } } catch (Exception ex) { ex.printStackTrace(); } } }
private static void registerEnderDragonFix() { ProtocolLibrary.getProtocolManager() .addPacketListener( new PacketAdapter( MyPetApi.getPlugin(), PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_TELEPORT) { @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); final Entity entity = packet.getEntityModifier(event).readSafely(0); // Now - are we dealing with an invisible slime? if (entity != null && entity instanceof MyPetBukkitEntity && ((MyPetBukkitEntity) entity).getPetType() == MyPetType.EnderDragon) { if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) { // MyPetLogger.write("ENTITY_LOOK: " + packet.getBytes().getValues()); byte angle = packet.getBytes().read(3); angle += Byte.MAX_VALUE; packet.getBytes().write(3, angle); } else if (packet.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK) { // MyPetLogger.write("ENTITY_MOVE_LOOK: " + packet.getBytes().getValues()); byte angle = packet.getBytes().read(3); angle += Byte.MAX_VALUE; packet.getBytes().write(3, angle); } else if (packet.getType() == PacketType.Play.Server.ENTITY_TELEPORT) { // MyPetLogger.write("ENTITY_TELEPORT: " + packet.getBytes().getValues()); byte angle = packet.getBytes().read(1); angle += Byte.MAX_VALUE; packet.getBytes().write(1, angle); } } } }); }
public TabListener() { ProtocolLibrary.getProtocolManager() .addPacketListener( new PacketAdapter( Gearz.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE) { @Override public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) { try { if (event.getPlayer().hasPermission("gearz.staff")) return; PacketContainer packet = event.getPacket(); String message = packet.getSpecificModifier(String.class).read(0); if ((message.startsWith("/"))) event.setCancelled(true); } catch (FieldAccessException ignored) { } } } }); }
/** Sends entity removal packets, as this disguise was removed */ public static void destroyEntity(TargetedDisguise disguise) { try { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); HashSet cloned = (HashSet) trackedPlayers.clone(); PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); destroyPacket.getIntegerArrays().write(0, new int[] {disguise.getEntity().getEntityId()}); for (Object p : cloned) { Player player = (Player) ReflectionManager.getBukkitEntity(p); if (player == disguise.getEntity() || disguise.canSee(player.getName())) { ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); } } } } catch (Exception ex) { ex.printStackTrace(); } }
private static void registerCompatFix_1_8() { ProtocolLibrary.getProtocolManager() .addPacketListener( new PacketAdapter( MyPetApi.getPlugin(), ListenerPriority.HIGHEST, PacketType.Play.Server.SPAWN_ENTITY_LIVING, PacketType.Play.Server.ENTITY_METADATA) { Class entityClass = ReflectionUtil.getClass( "org.bukkit.craftbukkit." + MyPetApi.getCompatUtil().getInternalVersion() + ".entity.CraftEntity"); Method getHandleMethod = ReflectionUtil.getMethod(entityClass, "getHandle"); private final EnumMap<DyeColor, Integer> convertedDyeColors = new EnumMap<DyeColor, Integer>(DyeColor.class) { { put(DyeColor.WHITE, 15); put(DyeColor.ORANGE, 14); put(DyeColor.MAGENTA, 13); put(DyeColor.LIGHT_BLUE, 12); put(DyeColor.YELLOW, 11); put(DyeColor.LIME, 10); put(DyeColor.PINK, 9); put(DyeColor.GRAY, 8); put(DyeColor.SILVER, 7); put(DyeColor.CYAN, 6); put(DyeColor.PURPLE, 5); put(DyeColor.BLUE, 4); put(DyeColor.BROWN, 3); put(DyeColor.GREEN, 2); put(DyeColor.RED, 1); put(DyeColor.BLACK, 0); } }; @Override public void onPacketSending(PacketEvent event) { if (event.isCancelled()) { return; } Player player = event.getPlayer(); if (!isPlayerRunningv1_8(player)) { return; } PacketContainer newPacketContainer = event.getPacket().deepClone(); event.setPacket(newPacketContainer); if (event.getPacketType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) { Entity entity = newPacketContainer.getEntityModifier(event).readSafely(0); if (entity != null && entity instanceof MyPetBukkitEntity) { MyPetBukkitEntity petEntity = (MyPetBukkitEntity) entity; List<WrappedWatchableObject> wrappedWatchableObjectList = newPacketContainer.getDataWatcherModifier().read(0).getWatchableObjects(); newPacketContainer .getDataWatcherModifier() .write( 0, new WrappedDataWatcher( fixMetadata(petEntity, wrappedWatchableObjectList))); } } else if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) { Entity entity = newPacketContainer.getEntityModifier(event).read(0); if (entity != null && entity instanceof MyPetBukkitEntity) { MyPetBukkitEntity petEntity = (MyPetBukkitEntity) entity; List<WrappedWatchableObject> wrappedWatchableObjectList = newPacketContainer.getWatchableCollectionModifier().read(0); newPacketContainer .getWatchableCollectionModifier() .write(0, fixMetadata(petEntity, wrappedWatchableObjectList)); } } } private List<WrappedWatchableObject> fixMetadata( MyPetBukkitEntity petEntity, List<WrappedWatchableObject> wrappedWatchableObjectList) { if (petEntity == null || wrappedWatchableObjectList == null) { return wrappedWatchableObjectList; } if (petEntity.getMyPet() instanceof MyPetBaby && hasKey(12, wrappedWatchableObjectList)) { Object object = getKeyValue(12, wrappedWatchableObjectList); if (object instanceof Integer) { int value = ((Number) object).intValue(); removeKey(12, wrappedWatchableObjectList); if (petEntity.getPetType() == MyPetType.Horse) { if (value == -24000) { value = -1; } } wrappedWatchableObjectList.add(new WrappedWatchableObject(12, (byte) value)); } } if (petEntity.getPetType() == MyPetType.Wolf && hasKey(20, wrappedWatchableObjectList)) { Object object = getKeyValue(20, wrappedWatchableObjectList); if (object instanceof Byte) { DyeColor color = DyeColor.getByWoolData((byte) ((Byte) object & 0xF)); removeKey(20, wrappedWatchableObjectList); wrappedWatchableObjectList.add( new WrappedWatchableObject( 20, (byte) ((this.convertedDyeColors.get(color)) & 0xF))); } } if (petEntity.getPetType() == MyPetType.Enderman && hasKey(16, wrappedWatchableObjectList)) { Object object = getKeyValue(16, wrappedWatchableObjectList); if (object instanceof Byte) { removeKey(16, wrappedWatchableObjectList); wrappedWatchableObjectList.add( new WrappedWatchableObject(16, Short.valueOf((Byte) object))); } } return wrappedWatchableObjectList; } private boolean hasKey( int key, List<WrappedWatchableObject> wrappedWatchableObjectList) { for (WrappedWatchableObject next : wrappedWatchableObjectList) { if (next.getIndex() == key) { return true; } } return false; } private Object getKeyValue( int key, List<WrappedWatchableObject> wrappedWatchableObjectList) { for (WrappedWatchableObject next : wrappedWatchableObjectList) { if (next.getIndex() == key) { return next.getValue(); } } return null; } private void removeKey( int key, List<WrappedWatchableObject> wrappedWatchableObjectList) { for (Iterator<WrappedWatchableObject> wrappedWatchableObjectIterator = wrappedWatchableObjectList.iterator(); wrappedWatchableObjectIterator.hasNext(); ) { WrappedWatchableObject next = wrappedWatchableObjectIterator.next(); if (next.getIndex() == key) { wrappedWatchableObjectIterator.remove(); break; } } } @SuppressWarnings("unchecked") private boolean isPlayerRunningv1_8(Player player) { try { Object nmsPlayer = getHandleMethod.invoke(player); Object playerConnection = ReflectionUtil.getFieldValue( nmsPlayer.getClass(), nmsPlayer, "playerConnection"); Object networkManager = ReflectionUtil.getFieldValue( playerConnection.getClass(), playerConnection, "networkManager"); Method getVersionMethod = ReflectionUtil.getMethod(networkManager.getClass(), "getVersion"); return (Integer) getVersionMethod.invoke(networkManager) > 5; } catch (Exception exception) { return false; } } }); }
@Override public void onEnable() { try { getMensagensConfig().options().copyDefaults(true); saveDefaultMensagem(); getConfig().options().copyDefaults(true); saveDefaultConfig(); } catch (Exception ex) { ex.printStackTrace(); } try { saveResource("sons.zip", false); saveResource("leia.yml", false); } catch (Exception e) { e.printStackTrace(); } SystemDebugg("-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x"); SystemDebugg("Aguarde, o plugin está sendo carregado..."); setupVersionSystemAndPlugin(); setupNMS(); SystemDebugg("Pesquisando por ProtocolLib..."); if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) { SystemDebugg( "ProtocolLib não foi encontrado! Desabilitando plugin... Porfavor instale ProtocolLib!"); setEnabled(false); return; } SystemDebugg("ProtocolLib foi encontrado com sucesso!"); protocolManager = ProtocolLibrary.getProtocolManager(); SystemDebugg("Registrando configurações e classes..."); setupClasses(); SystemDebugg("Registrado com sucesso!"); SystemDebugg("Registrando Eventos e Runnables..."); SetupGadgets.registerGadgets(this); Bukkit.getServer().getPluginManager().registerEvents(new LocalUpdate(), this); Bukkit.getServer().getPluginManager().registerEvents(new InventoryMoveManager(), this); Bukkit.getServer().getPluginManager().registerEvents(new PetManager(), this); Bukkit.getServer().getPluginManager().registerEvents(new MenuManager(), this); Bukkit.getServer().getPluginManager().registerEvents(new ParticlesMenu(), this); Bukkit.getServer().getPluginManager().registerEvents(new DisguiseMenu(), this); Bukkit.getServer().getPluginManager().registerEvents(new SuperMenu(), this); Bukkit.getServer().getPluginManager().registerEvents(new Gadgets(), this); Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), this); Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this); Bukkit.getServer().getPluginManager().registerEvents(new DisguisesEvent(), this); Bukkit.getServer().getPluginManager().registerEvents(new Pets(), this); Bukkit.getServer().getPluginManager().registerEvents(new PetMenu(), this); Bukkit.getServer().getPluginManager().registerEvents(new PluginListener(), this); Bukkit.getServer().getPluginManager().registerEvents(new WorldChange(), this); ParticleSetup.setupParticles(this); Bukkit.getServer().getPluginManager().registerEvents(new QuitEvent(), this); Bukkit.getServer().getPluginManager().registerEvents(new HatsMenu(), this); Bukkit.getServer().getPluginManager().registerEvents(new IFallingBlocks(), this); Bukkit.getServer().getPluginManager().registerEvents(new EntitySpawnPriority(), this); Bukkit.getServer().getPluginManager().registerEvents(new UtilGravity(), this); Bukkit.getServer().getPluginManager().registerEvents(new UtilPet_vR3(), this); RegisterMounts.registerMouts(this); WardrobeUtils w = new WardrobeUtils(); Bukkit.getPluginManager().registerEvents(w, this); Bukkit.getPluginManager().registerEvents(new UtilLag(this), this); Bukkit.getServer() .getScheduler() .scheduleSyncRepeatingTask(this, new SchedulerRunner(this), 1L, 1L); SystemDebugg("Registrado com sucesso!"); SystemDebugg("Registrando comandos e Listeners..."); getCommand("ultragadgets").setExecutor(new UltraGadgetsCMD()); getCommand("ug").setExecutor(new UltraGadgetsCMD()); SystemDebugg("Comandos e Listeners registrados com sucesso!"); SystemDebugg("Você pode remover este log na configuração. Em 'System-Debugg'"); System.out.print("[UltraGadgets] Desenvolvido por: [Floodeer]"); System.out.print("[UltraGadgets] Versão: Suporte v_1.8-R1 & v_1.8-R3"); System.out.print("[UltraGadgets] Todos os direitos reservados."); System.out.print("[UltraGadgets] Dev Page: https://github.com/Floodeer/UltraGadgets"); System.out.print("[UltraGadgets] Core Utils: Core for 1.8X version 2.2.0"); System.out.print("O plugin foi habilitado."); System.out.print("-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x"); }
public void onEnable() { version = getDescription().getVersion(); name = getDescription().getName(); final List<String> hiddenCommands = new ArrayList<String>(); hiddenCommands.add("all"); try { Metrics metrics = new Metrics(this); metrics.start(); Logger.getLogger("Minecraft") .info( "[" + name + "] Version: " + version + " Metrics started: http://mcstats.org/plugin/HideAndCustomPlugins"); } catch (IOException e) { System.out.println("Error Submitting stats!"); } loadConfig(); Bukkit.getServer().getPluginManager().registerEvents(this, this); if (getConfig().getBoolean("update-notification")) { try { new Updater( this, 80016, "http://dev.bukkit.org/bukkit-plugins/hideandcustomplugins/", "SearchForUpdates") .search(); } catch (MalformedURLException e1) { e1.printStackTrace(); } } final ProtocolManager manager = ProtocolLibrary.getProtocolManager(); manager.addPacketListener( new PacketAdapter(this, new PacketType[] {PacketType.Play.Client.TAB_COMPLETE}) { @SuppressWarnings("rawtypes") public void onPacketReceiving(PacketEvent event) { if ((event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) && (!event.getPlayer().hasPermission("hideandcustomplugins.bypass")) && (((String) event.getPacket().getStrings().read(0)).startsWith("/")) && (((String) event.getPacket().getStrings().read(0)).split(" ").length == 1)) { event.setCancelled(true); List<?> list = new ArrayList(); List<?> extra = new ArrayList(); String[] tabList = new String[list.size() + extra.size()]; for (int index = 0; index < list.size(); index++) { tabList[index] = ((String) list.get(index)); } for (int index = 0; index < extra.size(); index++) { tabList[(index + list.size())] = ('/' + (String) extra.get(index)); } PacketContainer tabComplete = manager.createPacket(PacketType.Play.Server.TAB_COMPLETE); tabComplete.getStringArrays().write(0, tabList); try { manager.sendServerPacket(event.getPlayer(), tabComplete); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }); for (String s : getConfig().getString("plugins").split(", ")) { this.plugins.add(s); } Logger.getLogger("Minecraft") .info("[" + name + "] Version: " + version + " Plugin has been activated successfully."); }
/** Resends the entity to all the watching players, which is where the magic begins */ public static void refreshTrackers(final TargetedDisguise disguise) { if (disguise.getEntity().isValid()) { PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); try { if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) { removeSelfDisguise((Player) disguise.getEntity()); ProtocolLibrary.getProtocolManager() .sendServerPacket((Player) disguise.getEntity(), destroyPacket); Bukkit.getScheduler() .scheduleSyncDelayedTask( libsDisguises, new Runnable() { public void run() { try { DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); } catch (Exception ex) { ex.printStackTrace(); } } }, 2); } final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); Method clear = ReflectionManager.getNmsMethod( "EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod( "EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); HashSet cloned = (HashSet) trackedPlayers.clone(); for (final Object p : cloned) { Player player = (Player) ReflectionManager.getBukkitEntity(p); if (disguise.getEntity() != player && disguise.canSee(player.getName())) { clear.invoke(entityTrackerEntry, p); ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); Bukkit.getScheduler() .scheduleSyncDelayedTask( libsDisguises, new Runnable() { public void run() { try { updatePlayer.invoke(entityTrackerEntry, p); } catch (Exception ex) { ex.printStackTrace(); } } }, 2); } } } } catch (Exception ex) { ex.printStackTrace(); } } }
public VolatileCodeProtocolLib() { protocolManager = ProtocolLibrary.getProtocolManager(); }
public static void removeListen(JavaPlugin pluging) { ProtocolLibrary.getProtocolManager().removePacketListeners(pluging); }
@Override public void onDisable() { ProtocolLibrary.getProtocolManager().removePacketListeners(MyPetApi.getPlugin()); }
/** Sends the self disguise to the player */ public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) { try { if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible() || !disguise.canSee(player)) { return; } Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); if (entityTrackerEntry == null) { // A check incase the tracker is null. // If it is, then this method will be run again in one tick. Which is when it should be // constructed. // Else its going to run in a infinite loop hue hue hue.. // At least until this disguise is discarded Bukkit.getScheduler() .runTask( libsDisguises, new Runnable() { public void run() { if (DisguiseAPI.getDisguise(player, player) == disguise) { sendSelfDisguise(player, disguise); } } }); return; } // Add himself to his own entity tracker ((HashSet<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry)) .add(ReflectionManager.getNmsEntity(player)); ProtocolManager manager = ProtocolLibrary.getProtocolManager(); // Send the player a packet with himself being spawned manager.sendServerPacket( player, manager .createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player) .createPacket(player)); WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player); sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true) .createPacket(player.getEntityId(), dataWatcher, true)); boolean isMoving = false; try { Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving"); field.setAccessible(true); isMoving = field.getBoolean(entityTrackerEntry); } catch (Exception ex) { ex.printStackTrace(); } // Send the velocity packets if (isMoving) { Vector velocity = player.getVelocity(); sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()) .createPacket( player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ())); } // Why the hell would he even need this. Meh. if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) { sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle()) .createPacket(0, player, player.getVehicle())); } else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) { sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player) .createPacket(0, player.getPassenger(), player)); } // Resend the armor for (int i = 0; i < 5; i++) { ItemStack item; if (i == 0) { item = player.getItemInHand(); } else { item = player.getInventory().getArmorContents()[i - 1]; } if (item != null && item.getType() != Material.AIR) { sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item) .createPacket(player.getEntityId(), i, item)); } } Location loc = player.getLocation(); // If the disguised is sleeping for w/e reason if (player.isSleeping()) { sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.BED, player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) .createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); } // Resend any active potion effects for (Object potionEffect : player.getActivePotionEffects()) { sendSelfPacket( player, manager .createPacketConstructor( PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect) .createPacket(player.getEntityId(), potionEffect)); } } catch (Exception ex) { ex.printStackTrace(); } }
/** Schedule the packet transmission or reception. */ public void schedule() { schedule(ProtocolLibrary.getProtocolManager()); }