From 6be1fb5f68633feafbd5d7e4147f186c0a8451ed Mon Sep 17 00:00:00 2001 From: Jordan Dalton Date: Wed, 5 Oct 2016 17:50:16 +0100 Subject: [PATCH] 1.8 Release (#40) * Let's get started... Again Set the default values to "guiGadgetWorlds" to an empty array, just to allow users to use the plugin out-of-the-box. I've also added a new config option to allow the users to set whether the players can drop the gadget items or not. Because of the added config option I've also added a new message to tell the players they cannot drop items. * Gadget registration Re-done how the gadgets are registered on the server. The main gadget class (Gadget.java) checks to see if it's already called the Gadget#registerEvent method and shouldn't call it multiple times. * 1.8 Stable Plugin should now be stable on 1.8.x servers (If not, then at least 1.8.4 and above). * 1.8 Stable Plugin should now be stable on 1.8.x servers (If not, then at least 1.8.4 and above). --- .gitignore | 1 + changelog.md | 33 ++++ config.yml | 17 +- messages.yml | 3 + src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java | 122 +++----------- .../mvpgadgets/commands/GUIGadgetCommand.java | 60 ++----- .../mvpgadgets/events/GadgetHandler.java | 101 ++++++------ .../tgrhavoc/mvpgadgets/gadgets/Gadget.java | 44 ++--- .../disguisegadget/DisguiseListener.java | 10 +- .../disguisegadget/nms/DisguiseFactory.java | 2 +- .../gadgets/disguisegadget/nms/IDisguise.java | 24 ++- .../disguisegadget/nms/v1_10_R1/Disguise.java | 91 +++++++++++ .../disguisegadget/nms/v1_8_R3/Disguise.java | 25 ++- .../disguisegadget/nms/v1_9_R1/Disguise.java | 154 ++++++++++++++++++ .../disguisegadget/nms/v1_9_R2/Disguise.java | 91 +++++++++++ .../gadgets/guigadget/GUIGadget.java | 1 + .../gadgets/guigadget/GUIGadgetListener.java | 38 ++--- .../paintballgun/PaintballGunGadget.java | 2 +- .../tgrhavoc/mvpvpgadgets/tests/JarUtil.java | 57 ------- 19 files changed, 550 insertions(+), 326 deletions(-) create mode 100644 src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_10_R1/Disguise.java create mode 100644 src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R1/Disguise.java create mode 100644 src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R2/Disguise.java delete mode 100644 src/ovh/tgrhavoc/mvpvpgadgets/tests/JarUtil.java diff --git a/.gitignore b/.gitignore index 1fe7b51..df481f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/ .project .classpath +.settings diff --git a/changelog.md b/changelog.md index 2e0edc7..272d496 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,39 @@ ChangeLog - Please create an issue to log your changes. ===== +### Bukkit 1.8.x Release +###### Date: 05-Oct-2016 +###### Developer: TGRHavoc +- Set the default values to "guiGadgetWorlds" to an empty array, just to allow users to use the plugin out-of-the-box. I've also added a new config option to allow the users to set whether the players can drop the gadget items or not. + +- Because of the added config option I've also added a new message to tell the players they cannot drop items. + +- Re-done how the gadgets are registered on the server. The main gadget class (Gadget.java) checks to see if it's already called the Gadget#registerEvent method and shouldn't call it multiple times. + +### Turned this into releasable, working plugin +###### Date: 21-Jul-2016 +###### Developer: pookeythekid +- Recoded the entire paintball gun so that it uses packets now. This is much better at not destroying the contents of container blocks and signs. + - Also massively expanded PaintballGunListener's BlockData class (and made it its own separate class), though it turned out to be useless once I went to packets. + +- Redesigned the gadget-adding system. Players now own their individual sets of Gadgets; each players' gadgets have their events registered **once**. Re-registering gadgets was a major bug. + - The MVPGadgets class's _availableGadgets_ contains ownerless gadgets, for the sake of seeing what they are without having redundant listeners registered. + +- Added a few settings in messages.yml. + +- Made a bunch of OCD edits throughout the code and config files. + +- Wrote up an HTML file in the resources folder that covers all commands and permissions. Feel free to add to it if necessary. + +- Did I say I fixed a crapton of bugs? + +- Added commands /mvpgadgets reload and /gadget + - /gadget will swap your gadget out for the GUI Gadget and open the GUI display. + +- Added config settings guiGadgetWorlds and guiGadgetSlot (I think the latter is correct, too lazy to check right now). Basically self-explanatory. + +- Made gadgets functional after a plugin reload with players online, instead of the plugin vomiting NPEs everywhere. + ### Disguises Updated ###### Date: 4-Oct-2015 ###### Developer: TGRHavoc diff --git a/config.yml b/config.yml index 9986527..cfafd77 100644 --- a/config.yml +++ b/config.yml @@ -14,12 +14,23 @@ Gadget_Prices: # In which worlds will players receive the Gadget Selector gadget upon login? # You should put your hub worlds in this setting. Delete the original list if you want to; it's just an example. -guiGadgetWorlds: -- Hub -- Spawn +# If you want gadgets to be usable in all worlds, set it to an empty list e.g. guiGadgetWorlds: [] +# Example configuration: +# guiGadgetWorlds: +# - Spawn +# - Hub +guiGadgetWorlds: [] + +# Do you want the players to be able to drop their gadgets? +# If you do, set this to 'true'. +allowDropping: false + # In which slot in the player's hotbar should the Gadget Selector be placed? (5 is the middle) guiGadgetSlot: 5 +# In which slot in the player's hotbar should the other Gadgets be placed ( default = 6 ) +gadgetSlot: 6 + ## Disguise Gadget Settings ## # This is a list of mobs that the players can disguise as (Look at mob cannon settings for a list of mobs) Disguises_List: diff --git a/messages.yml b/messages.yml index 6b24840..d924108 100644 --- a/messages.yml +++ b/messages.yml @@ -82,6 +82,9 @@ Messages: # the MVPGadgets config as hub worlds. Leave this as empty quotes to remove the message. WRONG_WORLD: "&cYou are not in a hub world! An admin can change this in the MVPGadgets config." + # For when people try to throw a gadget when the throw_gadget option is set to false in the config file. + NO_THROW: "&cYou cannot throw gadgets on the floor! Who do you think you are, the Queen?" + Disguises: # When a player disguises themselves DISGUISED: "You are now disguised as a(n) {ENTITY}" diff --git a/src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java b/src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java index 6af5511..7fccf96 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java +++ b/src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java @@ -5,22 +5,18 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.Constructor; -import java.net.URL; -import java.net.URLClassLoader; import java.util.HashSet; import java.util.Set; -import me.pookeythekid.mobcannon.MobCannon; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import me.pookeythekid.mobcannon.MobCannon; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; import ovh.tgrhavoc.mvpgadgets.commands.GUIGadgetCommand; import ovh.tgrhavoc.mvpgadgets.commands.MVPGadgetsCommand; import ovh.tgrhavoc.mvpgadgets.events.GadgetHandler; @@ -31,7 +27,6 @@ import ovh.tgrhavoc.mvpgadgets.gadgets.mobcannon.MobCannonGadget; import ovh.tgrhavoc.mvpgadgets.gadgets.paintballgun.PaintballGunGadget; import ovh.tgrhavoc.mvpgadgets.gadgets.paintballgun.PaintballListener; -import ovh.tgrhavoc.mvpvpgadgets.tests.JarUtil; import ovh.tgrhavoc.utils.VaultUtil; public class MVPGadgets extends JavaPlugin { @@ -44,7 +39,9 @@ public class MVPGadgets extends JavaPlugin { private static Economy economy = null; private static Permission permission = null; - public static String nmsVersion = "v1_8_R3"; + private static String nmsVersion = Bukkit.getServer().getClass().getPackage().getName() + .substring(23); + @Override public void onDisable(){ @@ -61,9 +58,12 @@ public void onEnable(){ getServer().getPluginManager().registerEvents(new GadgetHandler(this), this); - registerGadgets(); - //registerGadetEvents(); + registerGadgets(); // Gadgets should register their own events. + registerCommands(); + + Bukkit.getLogger().info("Hey, our NMS version is " + nmsVersion); + } private void registerGadgets() { @@ -76,11 +76,7 @@ private void registerGadgets() { addGadget(new GUIGadget(this)); } - @SuppressWarnings("unused") - @Deprecated - private void registerGadetEvents() { - getServer().getPluginManager().registerEvents(paintListener, this); //Going to keep this here for now. - } + private void registerCommands(){ getCommand("gadget").setExecutor(new GUIGadgetCommand(this)); getCommand("mvpgadgets").setExecutor(new MVPGadgetsCommand(this)); @@ -131,7 +127,7 @@ private void writeToFile(InputStream in, File file) throws IOException{ /** * Get the messages.yml file in a YamlConfiguration class. - * @return YamlConfiguration that represnts the Messages.yml file in the resources folder + * @return YamlConfiguration that represents the Messages.yml file in the resources folder */ public YamlConfiguration getMessages(){ return messages; @@ -164,14 +160,7 @@ public static void addGadgetStatic(Gadget g){ Bukkit.getLogger().info("Someone tried to register a gadget that already exists"); return; } - if (g.getOwningPlayer() != null) { - try { - // add simple-constructed gadget, not the kind that has its events registered - Gadget gadget = g.getClass().getConstructor(MVPGadgets.class).newInstance(g.getPlugin()); - availableGadgets.add(gadget); - return; - } catch (Exception ex){ ex.printStackTrace(); } - } + availableGadgets.add(g); } @@ -184,14 +173,7 @@ public void addGadget(Gadget g){ Bukkit.getLogger().info("Someone tried to register a gadget that already exists"); return; } - if (g.getOwningPlayer() != null) { - try { - // add simple-constructed gadget, not the kind that has its events registered - Gadget gadget = g.getClass().getConstructor(MVPGadgets.class).newInstance(g.getPlugin()); - availableGadgets.add(gadget); - return; - } catch (Exception ex){ ex.printStackTrace(); } - } + availableGadgets.add(g); } @@ -252,6 +234,7 @@ private void initVault(){ Bukkit.getLogger().info("Vault permissions hooked"); VaultUtil.setPlugin(this); } + private boolean setupPermissions() { RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); @@ -262,6 +245,7 @@ private boolean setupPermissions() { return false; return (permission != null); } + private boolean setupEconomy(){ RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); @@ -271,74 +255,8 @@ private boolean setupEconomy(){ return (economy != null); } //End vault hook - - //Method which loads .class files found in the "mods" folder so you can dynamically add or remove gadgets - @SuppressWarnings({ "unused", "unchecked" }) - @Deprecated - private void loadGadgetClasses() { - File basePath = new File(this.getDataFolder() + "/mods"); - File[] files = new File(this.getDataFolder() + "/mods").listFiles(); - - boolean shouldLoad = true; - - ClassLoader cl = null; - - try { - URL url = basePath.toURL(); - URL[] urls = new URL[]{url}; - cl = new URLClassLoader(urls); - } catch (Exception e) { - shouldLoad = false; - e.printStackTrace(); - } - - if (shouldLoad) { - for (File file : files) { - String fileName = file.getName(); - //If it is not a .class file contiue to the next entry. - if (!fileName.split(".")[fileName.split(".").length - 1].equals(".class")) continue; - - try { - - @SuppressWarnings("rawtypes") - Class clazz = cl.loadClass(fileName.replace(".class","")); - //Our .class file extends Gadget - if(clazz.isAssignableFrom(Gadget.class)){ - Gadget gadget = (Gadget) clazz.newInstance(); - addGadget(gadget); - } - - } catch (Exception e) { - - } - } - } - } - - @Deprecated - public void test(){ - for (String s: JarUtil.getGadetClasses(this.getDataFolder().getParent() + "/MVPGadgets.jar")){ - try { - System.out.println("Constructing... " + s); - - if (s.contains("\\$[0-9]")) - System.out.println("Found funny class: " + s); - - Class gadgetClass = Class.forName(s); - Constructor constr = gadgetClass.getConstructor(); - Gadget gadgetFromClass = null; - if (constr.getParameterTypes().length > 0){ - System.out.println("Found aruments for " + s); - - }else{ // No constructor args (Assume it's a gadget) - gadgetFromClass = (Gadget)constr.newInstance(); - } - - //addGadget(gadgetFromClass); - System.out.println("Just added a gadget " + gadgetFromClass); - } catch (Exception e) { - e.printStackTrace(); - } - } + + public static String getNmsVersion(){ + return nmsVersion; } } diff --git a/src/ovh/tgrhavoc/mvpgadgets/commands/GUIGadgetCommand.java b/src/ovh/tgrhavoc/mvpgadgets/commands/GUIGadgetCommand.java index 8fd38ad..670ee06 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/commands/GUIGadgetCommand.java +++ b/src/ovh/tgrhavoc/mvpgadgets/commands/GUIGadgetCommand.java @@ -1,14 +1,11 @@ package ovh.tgrhavoc.mvpgadgets.commands; -import java.util.UUID; - import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import ovh.tgrhavoc.mvpgadgets.MVPGadgets; -import ovh.tgrhavoc.mvpgadgets.gadgets.Gadget; import ovh.tgrhavoc.mvpgadgets.gadgets.guigadget.GUIGadget; import ovh.tgrhavoc.mvpgadgets.gadgets.guigadget.GUIGadgetListener; @@ -32,48 +29,25 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String } else { Player player = (Player) sender; - try { - // don't want to open a gadget GUI if the player isn't in a hub world - if (plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) { - player.openInventory(GUIGadgetListener.getInv(player)); - int slot; - if (plugin.getConfig().getInt("guiGadgetSlot") < 1) - slot = 0; - else if (plugin.getConfig().getInt("guiGadgetSlot") > 9) - slot = 8; - else slot = plugin.getConfig().getInt("guiGadgetSlot") - 1; - - GUIGadget guiGadget = new GUIGadget(plugin); - player.getInventory().setItem(slot, guiGadget.getItemStack()); - } else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty()) - player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD")); - } catch (NullPointerException npe) { - // player probably didn't log into the server via a hub world listed in the config, so gadgets didn't register - // either that, or the server reloaded with players online - for (Gadget gadget : plugin.getGadgets()){ - try { - gadget.getClass().getConstructor(MVPGadgets.class, UUID.class).newInstance( - gadget.getPlugin(), player.getUniqueId()); - } catch (Exception ex){ ex.printStackTrace(); } - } + + // don't want to open a gadget GUI if the player isn't in a hub world + if ( plugin.getConfig().getStringList("guiGadgetWorlds").size() == 0 || + plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) { + player.openInventory(GUIGadgetListener.getInv(player)); + + int slot; + if (plugin.getConfig().getInt("gadgetSlot") <= 1) + slot = 0; + else if (plugin.getConfig().getInt("gadgetSlot") >= 9) + slot = 8; + else slot = plugin.getConfig().getInt("gadgetSlot") - 1; - // yay, copy-pasted code because a tired programmer is a lazy one - // but hey, a lazy programmer is a great one am i rite - if (plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) { - player.openInventory(GUIGadgetListener.getInv(player)); - int slot; - if (plugin.getConfig().getInt("guiGadgetSlot") < 1) - slot = 0; - else if (plugin.getConfig().getInt("guiGadgetSlot") > 9) - slot = 8; - else slot = plugin.getConfig().getInt("guiGadgetSlot") - 1; - - GUIGadget guiGadget = new GUIGadget(plugin); - player.getInventory().setItem(slot, guiGadget.getItemStack()); - } else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty()) - player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD")); + GUIGadget guiGadget = new GUIGadget(plugin); + player.getInventory().setItem(slot, guiGadget.getItemStack()); - } + } else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty()) + player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD")); + } } diff --git a/src/ovh/tgrhavoc/mvpgadgets/events/GadgetHandler.java b/src/ovh/tgrhavoc/mvpgadgets/events/GadgetHandler.java index ec81851..b02e9a4 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/events/GadgetHandler.java +++ b/src/ovh/tgrhavoc/mvpgadgets/events/GadgetHandler.java @@ -3,12 +3,15 @@ import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; import ovh.tgrhavoc.mvpgadgets.MVPGadgets; import ovh.tgrhavoc.mvpgadgets.gadgets.Gadget; @@ -36,29 +39,49 @@ public void gadgetEvent (final GadgetEvent e){ e.getGadget().execute(e.getPlayer()); } + @EventHandler + public void dropItem(PlayerDropItemEvent e){ + ItemStack dropped = e.getItemDrop().getItemStack(); + if(dropped.hasItemMeta()){ + if(dropped.getItemMeta().getDisplayName().contains("(Gadget)")){ + if (!(ref.getConfig().getBoolean("allowDropping"))){ + e.setCancelled(true); + e.getPlayer().sendMessage(ref.getMessageFromConfig("Messages.NO_THROW")); + } + } + } + } + @EventHandler public void playerJoinEvent(PlayerJoinEvent e){ //Used to give the player the GUI when they spawn - for (String str : ref.getConfig().getStringList("guiGadgetWorlds")) - if (e.getPlayer().getWorld().getName().equals(str)) { - int slot; - if (ref.getConfig().getInt("guiGadgetSlot") < 1) - slot = 0; - else if (ref.getConfig().getInt("guiGadgetSlot") > 9) - slot = 8; - else slot = ref.getConfig().getInt("guiGadgetSlot") - 1; - - GUIGadget guiGadget = new GUIGadget(ref); - e.getPlayer().getInventory().setItem(slot, guiGadget.getItemStack()); - for (Gadget gadget : ref.getGadgets()){ - try { - gadget.getClass().getConstructor(MVPGadgets.class, UUID.class).newInstance( - gadget.getPlugin(), e.getPlayer().getUniqueId()); - } catch (Exception ex){ ex.printStackTrace(); } - } - - break; + int slot; + // We want to check equality as well, someone might think 1 = the first slot. and 9 = the last slot. + if (ref.getConfig().getInt("guiGadgetSlot") <= 1) + slot = 0; + else if (ref.getConfig().getInt("guiGadgetSlot") >= 9) + slot = 8; + else slot = ref.getConfig().getInt("guiGadgetSlot") - 1; + + GUIGadget guiGadget = new GUIGadget(ref); + + if (ref.getConfig().getStringList("guiGadgetWorlds").size() == 0){ // If they have an empty list + e.getPlayer().getInventory().setItem(slot, guiGadget.getItemStack() ); + return; + } + + boolean foundWorld = false; + for (String str : ref.getConfig().getStringList("guiGadgetWorlds")){ + if ( ! (e.getPlayer().getWorld().getName().equals(str)) ){ + continue; } + + e.getPlayer().getInventory().setItem(slot, guiGadget.getItemStack() ); + foundWorld = true; + } + + if (!foundWorld) + e.getPlayer().sendMessage(ref.getMessageFromConfig("Messages.WRONG_WORLD")); } @@ -68,39 +91,17 @@ public void playerInteractEvent(PlayerInteractEvent e){ if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){ if (player.getItemInHand().hasItemMeta()){ if (player.getItemInHand().getItemMeta().getDisplayName().contains("(Gadget)")){ - if (ref.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) { + // If the server doesn't want a hub world.. Or the player is in the specified world. + if ( ref.getConfig().getStringList("guiGadgetWorlds").size() == 0 || + ref.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) { - try { - - for (Gadget g : Gadget.getOwnerGadgets(player.getUniqueId())){ - if (g.getItemStack().getItemMeta().getDisplayName().equals( - player.getItemInHand().getItemMeta().getDisplayName())){ - GadgetEvent e1 = new GadgetEvent(g, player); - Bukkit.getPluginManager().callEvent(e1); - e.setCancelled(true); - } - } - - } catch (NullPointerException npe) { - // player probably didn't log into the server via a hub world listed in the config, so gadgets didn't register - // either that, or the server reloaded with players online - for (Gadget gadget : ref.getGadgets()){ - try { - gadget.getClass().getConstructor(MVPGadgets.class, UUID.class).newInstance( - gadget.getPlugin(), player.getUniqueId()); - } catch (Exception ex){ ex.printStackTrace(); } - } - - // Hopefully fixed the problem, now retry the GadgetEvent firing - for (Gadget g : Gadget.getOwnerGadgets(player.getUniqueId())){ - if (g.getItemStack().getItemMeta().getDisplayName().equals( - player.getItemInHand().getItemMeta().getDisplayName())){ - GadgetEvent e1 = new GadgetEvent(g, player); - Bukkit.getPluginManager().callEvent(e1); - e.setCancelled(true); - } + for (Gadget g : ref.getGadgets() ){ + if (g.getItemStack().getItemMeta().getDisplayName().equals( + player.getItemInHand().getItemMeta().getDisplayName())){ + GadgetEvent e1 = new GadgetEvent(g, player); + Bukkit.getPluginManager().callEvent(e1); + e.setCancelled(true); } - } } else if (!ref.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty()) diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/Gadget.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/Gadget.java index 77e7d65..06facca 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/Gadget.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/Gadget.java @@ -24,6 +24,8 @@ */ public abstract class Gadget { + private static List registeredEvents = new ArrayList(); + //Messages.yml paths static final String MESSAGE_PATH = "Gadgets.{gadget_name}"; static final String NAME_PATH = MESSAGE_PATH +".name"; @@ -34,9 +36,6 @@ public abstract class Gadget { protected ItemStack gadgetItem; private MVPGadgets plugin; - private UUID owningPlayer; - - private static Map> gadgetOwners = new HashMap<>(); /** * Main constructor for the gadgets. Registers gadget events to the server. This constructor @@ -63,23 +62,16 @@ public Gadget(MVPGadgets plugin, String name, ItemStack itemStack, UUID owningPl if (owningPlayer == null) throw new IllegalArgumentException("owningPlayer cannot be null!"); - - if (gadgetOwners.containsKey(owningPlayer)) - for (Gadget gadget : gadgetOwners.get(owningPlayer)) - if (gadget.gadgetName.equals(name)) - return; this.gadgetName = name; this.plugin = plugin; setItemStack(plugin.getMessages().getString(getNamePath()), itemStack); - registerEvents(plugin, plugin.getServer().getPluginManager()); - this.owningPlayer = owningPlayer; - Set set = new HashSet<>(); - if (gadgetOwners.get(owningPlayer) != null) - set = gadgetOwners.get(owningPlayer); - set.add(this); - gadgetOwners.put(owningPlayer, set); + if (! (registeredEvents.contains(name)) ){ + registerEvents(plugin, plugin.getServer().getPluginManager()); + registeredEvents.add(name); + } + } /** @@ -104,7 +96,10 @@ public Gadget(MVPGadgets plugin, String name, ItemStack itemStack){ this.gadgetName = name; this.plugin = plugin; + setItemStack(plugin.getMessages().getString(getNamePath()), itemStack); + registerEvents(plugin, plugin.getServer().getPluginManager()); + } /** @@ -271,22 +266,5 @@ public String getGadgetName(){ */ public MVPGadgets getPlugin(){ return plugin; - } - - /** - * Get the player who owns this gadget. - */ - public UUID getOwningPlayer() { - return owningPlayer; - } - - /** - * Get the gadgets that belong to a certain player. - * @param owner Gadget owner - * @return A Set containing the owner's gadgets - */ - public static Set getOwnerGadgets(UUID owner) { - return gadgetOwners.get(owner); - } - + } } diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/DisguiseListener.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/DisguiseListener.java index 7b8f0fd..629bf00 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/DisguiseListener.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/DisguiseListener.java @@ -107,14 +107,20 @@ public void disguise(Player p, EntityDisguises type, String displayName) { p.sendMessage(plugin.getMessageFromConfig("Messages.Disguises.UPDATED").replace("{ENTITY}", type.getName(plugin))); }else{ //Add them with a disguise - disguised.put(p, DisguiseFactory.getDisguiseFor(p, type, MVPGadgets.nmsVersion)); + AbstractDisguise playerDisguise = DisguiseFactory.getDisguiseFor(p, type, MVPGadgets.getNmsVersion() ); + + if (playerDisguise != null) + disguised.put( p, playerDisguise ); + //else, they should have already received a player#message telling them what went wrong. p.sendMessage(plugin.getMessageFromConfig("Messages.Disguises.DISGUISED").replace("{ENTITY}", type.getName(plugin))); } // Bukkit.broadcastMessage(disguised.get(p).getDisguise().getClassName()); - disguised.get(p).updateDisguise(Bukkit.getOnlinePlayers()); + if (disguised.containsKey(p)){ + disguised.get(p).updateDisguise(Bukkit.getOnlinePlayers()); + } } diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/DisguiseFactory.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/DisguiseFactory.java index 08621a2..01b246e 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/DisguiseFactory.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/DisguiseFactory.java @@ -29,7 +29,7 @@ public static AbstractDisguise getDisguiseFor(Player player, EntityDisguises dis return null; } - player.sendMessage("Null"); + player.sendMessage("Null. Seriously. If you see this message, something bad has screwed up... And I mean something HUGE."); return null; } diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/IDisguise.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/IDisguise.java index 3b3b5dd..90fc68b 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/IDisguise.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/IDisguise.java @@ -2,8 +2,6 @@ import java.util.Collection; -import net.minecraft.server.v1_8_R3.Packet; - import org.bukkit.entity.Player; public interface IDisguise { @@ -16,15 +14,25 @@ public interface IDisguise { public void updateDisguise(Player...players); public void updateDisguise(Collection player); - @SuppressWarnings("rawtypes") - public void sendPacket(Player player, Packet packet); - @SuppressWarnings("rawtypes") - public void sendPacket(Collection players, Packet packet); - @SuppressWarnings("rawtypes") - public void sendPacket(Packet packet, Player...players); + /*** + * Send a raw packet to a specific player. + * @param player The Bukkit player to send the packet to + * @param packet Must be an object that implements the raw Packet interface (e.g. net.minecraft.v1_8_R3.Packet) + */ + public void sendPacket(Player player, Object packet); + + /*** + * Send a raw packet to a specific players. + * @param player A collection of Bukkit players to send the packet to (e.g. {@link Bukkit.getOnlinePlayers()}) + * @param packet Must be an object that implements the raw Packet interface (e.g. net.minecraft.v1_8_R3.Packet) + */ + public void sendPacket(Collection players, Object packet); + + public void sendPacket(Object packet, Player...players); public void changeDisguise(EntityDisguises newDisguise); + @Deprecated public String getEntityClassName(EntityDisguises entity); public void removeDisguise(); diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_10_R1/Disguise.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_10_R1/Disguise.java new file mode 100644 index 0000000..03bd2a5 --- /dev/null +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_10_R1/Disguise.java @@ -0,0 +1,91 @@ +package ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.v1_10_R1; + + +import java.util.Collection; + +import org.bukkit.entity.Player; + +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.AbstractDisguise; +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.EntityDisguises; + +// v1_10_R1 = 1.10 & 1.10.2 +public class Disguise extends AbstractDisguise { + + public Disguise(Player toDisguise, EntityDisguises disguise) { + super(toDisguise, disguise); + } + + + @Override + public void sendDisguise(Collection players) { + // TODO Auto-generated method stub + + } + + @Override + public void sendDisguise(Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void sendDisguise(Player player) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Player updateFor) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Collection player) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Player player, Object packet) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Collection players, Object packet) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Object packet, Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void changeDisguise(EntityDisguises newDisguise) { + // TODO Auto-generated method stub + + } + + @Override + public String getEntityClassName(EntityDisguises entity) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void removeDisguise() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_8_R3/Disguise.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_8_R3/Disguise.java index 8430688..a716ec5 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_8_R3/Disguise.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_8_R3/Disguise.java @@ -17,6 +17,7 @@ import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.AbstractDisguise; import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.EntityDisguises; +// v1_8_R3 = 1.8.x public class Disguise extends AbstractDisguise { public Disguise(Player toDisguise, EntityDisguises disguise) { @@ -60,6 +61,11 @@ public void sendDisguise(Player player) { entity = (EntityLiving) entityClass.getConstructor(World.class).newInstance(world); } + if (entity == null){ + System.out.println("Error.. Entity is now null"); + return; + } + //Hopefully entity is now the entity the player wants to be! entity.setPosition(getPlayer().getLocation().getX(), getPlayer().getLocation().getY(), getPlayer().getLocation().getZ()); @@ -99,24 +105,29 @@ public void updateDisguise(Collection players) { sendDisguise(players); } - @SuppressWarnings("rawtypes") @Override - public void sendPacket(Player player, Packet packet) { + public void sendPacket(Player player, Object packet) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); CraftPlayer cP = (CraftPlayer)player; - cP.getHandle().playerConnection.sendPacket(packet); + cP.getHandle().playerConnection.sendPacket((Packet)packet); } - @SuppressWarnings("rawtypes") @Override - public void sendPacket(Collection players, Packet packet) { + public void sendPacket(Collection players, Object packet) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); + for(Player p: players) { sendPacket(p, packet); } } - @SuppressWarnings("rawtypes") @Override - public void sendPacket(Packet packet, Player... players) { + public void sendPacket(Object packet, Player... players) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); + for(Player p: players) sendPacket(p, packet); } diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R1/Disguise.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R1/Disguise.java new file mode 100644 index 0000000..2904a2f --- /dev/null +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R1/Disguise.java @@ -0,0 +1,154 @@ +package ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.v1_9_R1; + +import java.util.Collection; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import net.minecraft.server.v1_9_R1.EntityLiving; +import net.minecraft.server.v1_9_R1.Packet; +import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_9_R1.PacketPlayOutNamedEntitySpawn; +import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving; +import net.minecraft.server.v1_9_R1.World; +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.AbstractDisguise; +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.EntityDisguises; + +// v1_9_R1 = 1.9 & 1.9.2 +public class Disguise extends AbstractDisguise { + + public Disguise(Player toDisguise, EntityDisguises disguise) { + super(toDisguise, disguise); + } + + + @Override + public void sendDisguise(Collection players) { + for(Player p: players){ + if(p.equals(getPlayer())) + continue; + + sendDisguise(p); + } + } + + @Override + public void sendDisguise(Player... players) { + for(Player p: players){ + if(p.equals(getPlayer())) + continue; + + sendDisguise(p); + } + } + + @Override + public void sendDisguise(Player player) { + if (player.equals(this.getPlayer())) + throw new IllegalArgumentException("Target player cannot be the disguised player"); + + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(getPlayer().getEntityId()); + World world = ((CraftWorld) getPlayer().getWorld()).getHandle(); + + try{ + Class entityClass = Class.forName(getDisguise().getClassName()); + + EntityLiving entity = null; + if (EntityLiving.class.isAssignableFrom(entityClass)){ + entity = (EntityLiving) entityClass.getConstructor(World.class).newInstance(world); + } + + if (entity == null){ + System.out.println("Error.. Entity is now null"); + return; + } + + entity.setPosition(getPlayer().getLocation().getX(), getPlayer().getLocation().getY(), + getPlayer().getLocation().getZ()); + entity.f(getPlayer().getEntityId()); + + PacketPlayOutSpawnEntityLiving livingPacket = new PacketPlayOutSpawnEntityLiving(entity); + sendPacket(player, packet); + sendPacket(player, livingPacket); + + } catch (Exception e){ + e.printStackTrace(); + } + + } + + @Override + public void updateDisguise(Player updateFor) { + sendDisguise(updateFor); + } + + @Override + public void updateDisguise(Player... players) { + sendDisguise(players); + } + + @Override + public void updateDisguise(Collection player) { + sendDisguise(player); + } + + @Override + public void sendPacket(Player player, Object packet) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); + + CraftPlayer cP = (CraftPlayer)player; + cP.getHandle().playerConnection.sendPacket((Packet)packet); + } + + @Override + public void sendPacket(Collection players, Object packet) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); + + for(Player p: players) { + sendPacket(p, packet); + } + } + + @Override + public void sendPacket(Object packet, Player... players) { + if( ! (packet instanceof Packet) ) + throw new IllegalArgumentException("sendPacket called without a Packet "); + + for(Player p: players) { + sendPacket(p, packet); + } + } + + @Override + public void changeDisguise(EntityDisguises newDisguise) { + this.setDisguise(newDisguise); + + sendDisguise(Bukkit.getOnlinePlayers()); + } + + @Override + public void removeDisguise() { + PacketPlayOutEntityDestroy dP = new PacketPlayOutEntityDestroy( getPlayer().getEntityId() ); + PacketPlayOutNamedEntitySpawn sP = new PacketPlayOutNamedEntitySpawn( ((CraftPlayer)getPlayer()).getHandle() ); + + for(Player p: Bukkit.getOnlinePlayers()){ + if (p.equals(getPlayer())) + continue; + + sendPacket(p, dP); + sendPacket(p, sP); + } + + } + + @Override + public String getEntityClassName(EntityDisguises entity) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R2/Disguise.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R2/Disguise.java new file mode 100644 index 0000000..a0c49d9 --- /dev/null +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/disguisegadget/nms/v1_9_R2/Disguise.java @@ -0,0 +1,91 @@ +package ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.v1_9_R2; + + +import java.util.Collection; + +import org.bukkit.entity.Player; + +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.AbstractDisguise; +import ovh.tgrhavoc.mvpgadgets.gadgets.disguisegadget.nms.EntityDisguises; + +// v1_9_R2 = 1.9.4 +public class Disguise extends AbstractDisguise { + + public Disguise(Player toDisguise, EntityDisguises disguise) { + super(toDisguise, disguise); + } + + + @Override + public void sendDisguise(Collection players) { + // TODO Auto-generated method stub + + } + + @Override + public void sendDisguise(Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void sendDisguise(Player player) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Player updateFor) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDisguise(Collection player) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Player player, Object packet) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Collection players, Object packet) { + // TODO Auto-generated method stub + + } + + @Override + public void sendPacket(Object packet, Player... players) { + // TODO Auto-generated method stub + + } + + @Override + public void changeDisguise(EntityDisguises newDisguise) { + // TODO Auto-generated method stub + + } + + @Override + public String getEntityClassName(EntityDisguises entity) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void removeDisguise() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadget.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadget.java index 10dab69..7a4007f 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadget.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadget.java @@ -35,6 +35,7 @@ public void execute(Player player) { @Override public void registerEvents(MVPGadgets plugin, PluginManager pm) { + GUIGadgetListener l = new GUIGadgetListener(plugin, this); pm.registerEvents(l, plugin); diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadgetListener.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadgetListener.java index 70dfcb8..a3ce83f 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadgetListener.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/guigadget/GUIGadgetListener.java @@ -46,31 +46,31 @@ public void onInventoryClick(InventoryClickEvent event){ if (event.getWhoClicked() instanceof Player){ Player player = (Player) event.getWhoClicked(); - for (Gadget g : Gadget.getOwnerGadgets(player.getUniqueId())){ + for (Gadget g : mainPlugin.getGadgets() ){ if (g.getItemStack().getItemMeta().getDisplayName().equals(event.getCurrentItem().getItemMeta().getDisplayName())){ - if(mainPlugin.hookedVault() && !player.hasPermission("mvpgadgets." + g.getGadgetName())){ - - if (!VaultUtil.transaction(player, mainPlugin.getGadgetPrice(g))){ - player.sendMessage(formatMessage(mainPlugin.getMessageFromConfig("Messages.UNABLE_BUY"), g)); - return; - }else{ - mainPlugin.getPermission().playerAdd(player, "mvpgadgets." +g.getGadgetName().toLowerCase()); - player.sendMessage(formatMessage(mainPlugin.getMessageFromConfig("Messages.BOUGHT"), g)); - } - + if(mainPlugin.hookedVault() && !player.hasPermission("mvpgadgets." + g.getGadgetName())){ + + if (!VaultUtil.transaction(player, mainPlugin.getGadgetPrice(g))){ + player.sendMessage(formatMessage(mainPlugin.getMessageFromConfig("Messages.UNABLE_BUY"), g)); + return; + }else{ + mainPlugin.getPermission().playerAdd(player, "mvpgadgets." +g.getGadgetName().toLowerCase()); + player.sendMessage(formatMessage(mainPlugin.getMessageFromConfig("Messages.BOUGHT"), g)); } + + } - player.sendMessage(formatMessage(mainPlugin.getMessages().getString("Messages.SELECTED"), g)); + player.sendMessage(formatMessage(mainPlugin.getMessages().getString("Messages.SELECTED"), g)); - int slot; - if (mainPlugin.getConfig().getInt("guiGadgetSlot") < 1) - slot = 0; - else if (mainPlugin.getConfig().getInt("guiGadgetSlot") > 9) - slot = 8; - else slot = mainPlugin.getConfig().getInt("guiGadgetSlot") - 1; + int slot; + if (mainPlugin.getConfig().getInt("gadgetSlot") <= 1) + slot = 0; + else if (mainPlugin.getConfig().getInt("gadgetSlot") >= 9) + slot = 8; + else slot = mainPlugin.getConfig().getInt("gadgetSlot") - 1; - player.getInventory().setItem(slot, g.getItemStack()); + player.getInventory().setItem(slot, g.getItemStack()); // According to Bukkit JavaDocs, it's unsafe to close the inventory in an InventoryClickEvent until the next tick. // https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryClickEvent.html diff --git a/src/ovh/tgrhavoc/mvpgadgets/gadgets/paintballgun/PaintballGunGadget.java b/src/ovh/tgrhavoc/mvpgadgets/gadgets/paintballgun/PaintballGunGadget.java index fead0cd..474592e 100644 --- a/src/ovh/tgrhavoc/mvpgadgets/gadgets/paintballgun/PaintballGunGadget.java +++ b/src/ovh/tgrhavoc/mvpgadgets/gadgets/paintballgun/PaintballGunGadget.java @@ -13,7 +13,7 @@ import ovh.tgrhavoc.mvpgadgets.gadgets.Gadget; public class PaintballGunGadget extends Gadget { - + public PaintballGunGadget(MVPGadgets plugin, UUID owningPlayer) { super(plugin, "paintballGadget", new ItemStack(Material.DIAMOND_BARDING), owningPlayer); } diff --git a/src/ovh/tgrhavoc/mvpvpgadgets/tests/JarUtil.java b/src/ovh/tgrhavoc/mvpvpgadgets/tests/JarUtil.java deleted file mode 100644 index f10470f..0000000 --- a/src/ovh/tgrhavoc/mvpvpgadgets/tests/JarUtil.java +++ /dev/null @@ -1,57 +0,0 @@ -package ovh.tgrhavoc.mvpvpgadgets.tests; - -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.regex.Pattern; - -public class JarUtil { - - public static List getGadetClasses(String pathToJar){ - ArrayList classes = new ArrayList(); - - String packageName = "ovh/tgrhavoc/mvpgadgets/gadgets"; // Package in which to find the gadgets - System.out.println("Getting classes for jar :" + pathToJar + " in package " - + packageName); - - JarInputStream jarFile = null; - try{ - jarFile = new JarInputStream( - new FileInputStream( pathToJar )); - JarEntry jarEntry = null; - - while (true){ - jarEntry = jarFile.getNextJarEntry(); - if (jarEntry == null) - break; - if (jarEntry.getName().endsWith("/Gadget.class") || - jarEntry.getName().contains("Listener.class") || - Pattern.compile("\\$[0-9]").matcher(jarEntry.getName()).find()){ - - System.out.println("Not adding.. " + jarEntry.getName()); - - }else if (jarEntry.getName().startsWith(packageName) - && jarEntry.getName().endsWith(".class") ){ - classes.add(jarEntry.getName().replace("/", ".").replace(".class", "")); - } - - } - - }catch(Exception e){ - e.printStackTrace(); - }finally{ - try { - jarFile.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - return classes; - } - -}