diff --git a/Examples/ItemDisguise/pom.xml b/Examples/ItemDisguise/pom.xml index 5c4e488d..566a8eb8 100644 --- a/Examples/ItemDisguise/pom.xml +++ b/Examples/ItemDisguise/pom.xml @@ -1,27 +1,31 @@ - + 4.0.0 com.comphenix.itemdisguise ItemDisguise - 1.0.0 + 1.1.0 Item Disguise Change the appearance of inventory items. - + cp1252 - + - bukkit-rep - http://repo.bukkit.org/content/groups/public + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ - comphenix-rep - Comphenix Maven Releases - http://repo.comphenix.net/content/groups/public + comphenix-releases + http://repo.comphenix.net/content/repositories/releases/ + + + shadowvolt-repo + http://ci.shadowvolt.com/plugin/repository/everything/ - + src/main/java @@ -43,13 +47,13 @@ - + scm:git:git://github.com/aadnk/ProtocolLib.git scm:git:git@github.com:aadnk/ProtocolLib.git https://github.com/aadnk/ProtocolLib - + GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 @@ -58,15 +62,21 @@ - - org.bukkit - bukkit - 1.3.2-R1.0 - - - com.comphenix.protocol - ProtocolLib - 1.3.2 - + + org.spigotmc + spigot-api + 1.8-R0.1-SNAPSHOT + + + org.spigotmc + spigot + 1.8-R0.1-SNAPSHOT + provided + + + com.comphenix.protocol + ProtocolLib + 3.6.3-SNAPSHOT + \ No newline at end of file diff --git a/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java b/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java index e9ea5c79..d4839eb0 100644 --- a/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java +++ b/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java @@ -2,16 +2,16 @@ * ItemDisguise - A simple Bukkit plugin that illustrates how to use ProtocolLib. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -25,8 +25,8 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -36,62 +36,52 @@ public class HideEnchantmentsListener { private final Server server; private final Logger logger; - + public HideEnchantmentsListener(Server server, Logger logger) { this.server = server; this.logger = logger; } - - public void addListener(ProtocolManager protocolManager, JavaPlugin plugin) { + public void addListener(ProtocolManager protocolManager, JavaPlugin plugin) { // Hide all enchantments - protocolManager.addPacketListener(new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, 0x67, 0x68, 0x3E) { + protocolManager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS, + PacketType.Play.Server.NAMED_SOUND_EFFECT) { @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); - + try { // Item packets - switch (event.getPacketID()) { - case 0x67: // Set slot + if (event.getPacketType() == PacketType.Play.Server.SET_SLOT) { removeEnchantments(packet.getItemModifier().read(0)); - break; - - case 0x68: // Set Window Items + } else if (event.getPacketType() == PacketType.Play.Server.WINDOW_ITEMS) { ItemStack[] elements = packet.getItemArrayModifier().read(0); - + for (int i = 0; i < elements.length; i++) { if (elements[i] != null) { removeEnchantments(elements[i]); } } - break; - - case 0x3E: // Sound effect + } else if (event.getPacketType() == PacketType.Play.Server.NAMED_SOUND_EFFECT) { event.setCancelled(true); - break; } - } catch (FieldAccessException e) { logger.log(Level.SEVERE, "Couldn't access field.", e); } } }); - + // Censor - protocolManager.addPacketListener(new PacketAdapter(plugin, ConnectionSide.CLIENT_SIDE, 0x3) { + protocolManager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { - if (event.getPacketID() == 0x3) { + if (event.getPacketType() == PacketType.Play.Client.CHAT) { try { - String message = event.getPacket(). - getSpecificModifier(String.class).read(0); - + String message = event.getPacket().getSpecificModifier(String.class).read(0); if (message.contains("shit") || message.contains("fuck")) { event.setCancelled(true); event.getPlayer().sendMessage("Bad manners!"); } - } catch (FieldAccessException e) { logger.log(Level.SEVERE, "Couldn't access field.", e); } @@ -99,24 +89,23 @@ public class HideEnchantmentsListener { } }); } - + public Server getServer() { return server; } - + public void removeListener(ProtocolManager protocolManager, JavaPlugin plugin) { // Just remove every adapter with this plugin protocolManager.removePacketListeners(plugin); } - + private void removeEnchantments(ItemStack stack) { if (stack == null) return; - - Object[] copy = stack.getEnchantments().keySet().toArray(); - - for (Object enchantment : copy) { - stack.removeEnchantment((Enchantment) enchantment); + + Enchantment[] copy = stack.getEnchantments().keySet().toArray(new Enchantment[0]); + for (Enchantment enchantment : copy) { + stack.removeEnchantment(enchantment); } } } diff --git a/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java b/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java index a6d83b20..fc625522 100644 --- a/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java +++ b/Examples/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java @@ -2,16 +2,16 @@ * ItemDisguise - A simple Bukkit plugin that illustrates how to use ProtocolLib. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -24,23 +24,23 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; public class ItemDisguiseMod extends JavaPlugin { - + private ProtocolManager protocolManager; private Logger logger; - + private HideEnchantmentsListener enchantmentsListener; - + @Override public void onEnable() { - logger = getLoggerSafely(); protocolManager = ProtocolLibrary.getProtocolManager(); - + enchantmentsListener = new HideEnchantmentsListener(getServer(), logger); enchantmentsListener.addListener(protocolManager, this); } @@ -49,49 +49,42 @@ public class ItemDisguiseMod extends JavaPlugin { public void onDisable() { enchantmentsListener.removeListener(protocolManager, this); } - + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { - Player player = (Player) sender; - if (label.equalsIgnoreCase("explosion")) { - PacketContainer fakeExplosion = protocolManager.createPacket(0x3C); - + PacketContainer fakeExplosion = protocolManager.createPacket(PacketType.Play.Server.EXPLOSION); + // Set the coordinates try { - fakeExplosion.getSpecificModifier(double.class). - write(0, player.getLocation().getX()). - write(1, player.getLocation().getY()). - write(2, player.getLocation().getZ()); - fakeExplosion.getSpecificModifier(float.class). - write(0, 3.0F); - + fakeExplosion.getSpecificModifier(double.class).write(0, player.getLocation().getX()).write(1, player.getLocation().getY()).write(2, player.getLocation().getZ()); + fakeExplosion.getSpecificModifier(float.class).write(0, 3.0F); + protocolManager.sendServerPacket(player, fakeExplosion); - } catch (Exception e) { e.printStackTrace(); } } - + return true; } - + return false; } - + // Get the Bukkit logger first, before we try to create our own private Logger getLoggerSafely() { - + Logger log = null; - + try { log = getLogger(); } catch (Throwable e) { // We'll handle it } - + if (log == null) log = Logger.getLogger("Minecraft"); return log;