From 3af91967403637ca4bb7a82d589cbc2234e7396c Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 11 Oct 2012 09:09:42 +0200 Subject: [PATCH] Converted ItemDisguise to a maven project. --- ItemDisguise/.classpath | 20 +- ItemDisguise/.gitignore | 1 + ItemDisguise/.project | 40 +-- .../.settings/org.eclipse.jdt.core.prefs | 23 +- .../.settings/org.eclipse.m2e.core.prefs | 4 + ItemDisguise/pom.xml | 68 +++++ .../HideEnchantmentsListener.java | 238 +++++++++--------- .../itemdisguise/ItemDisguiseMod.java | 198 +++++++-------- ItemDisguise/src/{ => main/java}/plugin.yml | 26 +- 9 files changed, 351 insertions(+), 267 deletions(-) create mode 100644 ItemDisguise/.gitignore create mode 100644 ItemDisguise/.settings/org.eclipse.m2e.core.prefs create mode 100644 ItemDisguise/pom.xml rename ItemDisguise/src/{ => main/java}/com/comphenix/itemdisguise/HideEnchantmentsListener.java (96%) rename ItemDisguise/src/{ => main/java}/com/comphenix/itemdisguise/ItemDisguiseMod.java (96%) rename ItemDisguise/src/{ => main/java}/plugin.yml (96%) diff --git a/ItemDisguise/.classpath b/ItemDisguise/.classpath index 24f68324..012c5985 100644 --- a/ItemDisguise/.classpath +++ b/ItemDisguise/.classpath @@ -1,8 +1,12 @@ - - - - - - - - + + + + + + + + + + + + diff --git a/ItemDisguise/.gitignore b/ItemDisguise/.gitignore new file mode 100644 index 00000000..9f970225 --- /dev/null +++ b/ItemDisguise/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/ItemDisguise/.project b/ItemDisguise/.project index 513103b3..c8e5edca 100644 --- a/ItemDisguise/.project +++ b/ItemDisguise/.project @@ -1,17 +1,23 @@ - - - ItemDisguise - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - + + + ItemDisguise + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/ItemDisguise/.settings/org.eclipse.jdt.core.prefs b/ItemDisguise/.settings/org.eclipse.jdt.core.prefs index 838bd9d6..62492222 100644 --- a/ItemDisguise/.settings/org.eclipse.jdt.core.prefs +++ b/ItemDisguise/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,12 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ItemDisguise/.settings/org.eclipse.m2e.core.prefs b/ItemDisguise/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/ItemDisguise/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ItemDisguise/pom.xml b/ItemDisguise/pom.xml new file mode 100644 index 00000000..623aa497 --- /dev/null +++ b/ItemDisguise/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.comphenix.itemdisguise + ItemDisguise + 1.0.0 + Item Disguise + Change the appearance of inventory items. + + + + bukkit-rep + http://repo.bukkit.org/content/groups/public + + + comphenix-releases + Comphenix Maven Releases + http://comphenix.net/maven/content/repositories/releases/ + + + + + src/main/java + + + src/main/java + + **/*.java + + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + + + 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 + http://www.gnu.org/licenses/gpl-2.0.txt + repo + + + + + org.bukkit + bukkit + 1.3.2-R1.0 + + + com.comphenix.protocol + ProtocolLib + 1.3.1 + + + \ No newline at end of file diff --git a/ItemDisguise/src/com/comphenix/itemdisguise/HideEnchantmentsListener.java b/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java similarity index 96% rename from ItemDisguise/src/com/comphenix/itemdisguise/HideEnchantmentsListener.java rename to ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java index 013055fb..a85c0779 100644 --- a/ItemDisguise/src/com/comphenix/itemdisguise/HideEnchantmentsListener.java +++ b/ItemDisguise/src/main/java/com/comphenix/itemdisguise/HideEnchantmentsListener.java @@ -1,119 +1,119 @@ -/* - * 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 - * 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. - * 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 - * 02111-1307 USA - */ - -package com.comphenix.itemdisguise; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.bukkit.Server; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; - -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; -import com.comphenix.protocol.reflect.FieldAccessException; - -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) { - - // Hide all enchantments - protocolManager.addPacketListener(new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, 0x67, 0x68, 0x3E) { - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - - try { - // Item packets - switch (event.getPacketID()) { - case 0x67: // Set slot - removeEnchantments(packet.getItemModifier().read(0)); - break; - - case 0x68: // Set 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 - 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) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (event.getPacketID() == 0x3) { - try { - 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); - } - } - } - }); - } - - 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) { - Object[] copy = stack.getEnchantments().keySet().toArray(); - - for (Object enchantment : copy) { - stack.removeEnchantment((Enchantment) enchantment); - } - } -} +/* + * 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 + * 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. + * 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 + * 02111-1307 USA + */ + +package com.comphenix.itemdisguise; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.bukkit.Server; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +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; +import com.comphenix.protocol.reflect.FieldAccessException; + +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) { + + // Hide all enchantments + protocolManager.addPacketListener(new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, 0x67, 0x68, 0x3E) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + + try { + // Item packets + switch (event.getPacketID()) { + case 0x67: // Set slot + removeEnchantments(packet.getItemModifier().read(0)); + break; + + case 0x68: // Set 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 + 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) { + @Override + public void onPacketReceiving(PacketEvent event) { + if (event.getPacketID() == 0x3) { + try { + 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); + } + } + } + }); + } + + 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) { + Object[] copy = stack.getEnchantments().keySet().toArray(); + + for (Object enchantment : copy) { + stack.removeEnchantment((Enchantment) enchantment); + } + } +} diff --git a/ItemDisguise/src/com/comphenix/itemdisguise/ItemDisguiseMod.java b/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java similarity index 96% rename from ItemDisguise/src/com/comphenix/itemdisguise/ItemDisguiseMod.java rename to ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java index 649062e2..29bf32e6 100644 --- a/ItemDisguise/src/com/comphenix/itemdisguise/ItemDisguiseMod.java +++ b/ItemDisguise/src/main/java/com/comphenix/itemdisguise/ItemDisguiseMod.java @@ -1,99 +1,99 @@ -/* - * 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 - * 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. - * 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 - * 02111-1307 USA - */ - -package com.comphenix.itemdisguise; - -import java.util.logging.Logger; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -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); - } - - @Override - 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); - - // 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); - - 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; - } -} +/* + * 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 + * 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. + * 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 + * 02111-1307 USA + */ + +package com.comphenix.itemdisguise; + +import java.util.logging.Logger; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +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); + } + + @Override + 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); + + // 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); + + 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; + } +} diff --git a/ItemDisguise/src/plugin.yml b/ItemDisguise/src/main/java/plugin.yml similarity index 96% rename from ItemDisguise/src/plugin.yml rename to ItemDisguise/src/main/java/plugin.yml index a91f9720..7639f0b5 100644 --- a/ItemDisguise/src/plugin.yml +++ b/ItemDisguise/src/main/java/plugin.yml @@ -1,14 +1,14 @@ -name: ItemDisguiseMod -version: 1.0.0 -description: Change the appearance of inventory items. -author: Comphenix -website: http://www.comphenix.net/ItemDisguise - -main: com.comphenix.itemdisguise.ItemDisguiseMod -depends: [ProtocolLib] -database: false - -commands: - explosion: - description: Creates a fake explosion around the caller. +name: ItemDisguiseMod +version: 1.0.0 +description: Change the appearance of inventory items. +author: Comphenix +website: http://www.comphenix.net/ItemDisguise + +main: com.comphenix.itemdisguise.ItemDisguiseMod +depends: [ProtocolLib] +database: false + +commands: + explosion: + description: Creates a fake explosion around the caller. usage: / \ No newline at end of file