commit 769fd577ec147be968ca47908db0b2e31227d464 Author: j502647092 Date: Tue Jul 7 16:09:51 2015 +0800 update to Maven project... Signed-off-by: j502647092 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..4c682ec --- /dev/null +++ b/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d7b730 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin/ +/target/ +.settings \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..b5a4103 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + GuiShopManager + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..06d2308 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,59 @@ +<> + +You want virtual and easy-to-use shops? [[http://dev.bukkit.org/bukkit-plugins/bossshop|**BossShop**]] allows to create the most player friendly shops ever! + +Tired of promoting your Players by hand? [[http://dev.bukkit.org/server-mods/commandrank-permissionsbukkit/|**CommandRank**]] promotes players for money/kills/passwords/exp etc.! + +Unleash the Power of an unique economy system: [[http://dev.bukkit.org/bukkit-plugins/playerpoints/|**PlayerPoints**]] (You can run this beside an other economy plugin) + +You want your VIPs to be able to become invincible but you are afraid of abusing players? Use [[http://dev.bukkit.org/bukkit-plugins/vip-god/|**VIP-God**]] :) + +<> + +v1.3.2: + +*[FIX] Now you can set the Inventory Location of your items to "0" +*[NOTE] World Settings coming soon! + + +v1.3.1 **(REQUIRES BOSSSHOP v1.9.0 or newer. Sorry for that... Important parts of BossShop were rewritten and work way better now!)**: + +*[UPDATE] Updated to BossShop v1.9.0 + + +v1.3.0 **(REQUIRES BOSSSHOP v1.8.3)**: + +*[ADD] Added a command (/gsm give [player]) which allows to spawn GuiShopManager items +*[ADD] Now you can define the inventory locations of the items +*[UPDATE] Now working with the new BossShop API + + +v1.2.0: +*[IMPROVE] Improved the GuiShopManager API +*[FIX] Fixed a tiny bug +*[NOTE] With the next update you will be able to define the location of the items in the inventory + + +v1.1.3: + +*[UPDATE] Updated to 1.7.2 + + +v1.1.2: + +*[FIX] Fixed an other tiny error + + +v1.1.1: + +* [FIX] An error was caused when a player clicked in the space **around** his inventory + + +v1.1: + +*[FIX] An error was caused when a player who joined had items without special display name in the inventory + + +v1.0: + +*Release \ No newline at end of file diff --git a/lib/BossShop.jar b/lib/BossShop.jar new file mode 100644 index 0000000..929ee58 Binary files /dev/null and b/lib/BossShop.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..428ff2c --- /dev/null +++ b/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + cn.citycraft + GuiShopManager + 0.0.1-SNAPSHOT + GuiShopManager + + ${project.name} + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + org.spigotmc + spigot-api + jar + 1.8.3-R0.1-SNAPSHOT + + + org.black_ixx.bossshop + BossShop + 2.01 + system + ${project.basedir}/lib/BossShop.jar + + + + UTF-8 + + \ No newline at end of file diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/Commander.java b/src/org/black_ixx/bossshop/addon/guishopmanager/Commander.java new file mode 100644 index 0000000..de815d5 --- /dev/null +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/Commander.java @@ -0,0 +1,108 @@ +package org.black_ixx.bossshop.addon.guishopmanager; + +import org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class Commander implements CommandExecutor { + private GuiShopManager plugin; + + public Commander(GuiShopManager plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] args) { + if ((args.length == 1) || (args.length == 2) || (args.length == 3)) { + if (args[0].equalsIgnoreCase("reload")) { + if (!sender.hasPermission("GUIShopManager.reload")) { + sender.sendMessage(ChatColor.RED + "No Permissions!"); + return false; + } + + this.plugin.reload(); + sender.sendMessage(ChatColor.RED + "Reloaded " + ChatColor.YELLOW + + "GUIShopManager"); + return true; + } + + if (args[0].equalsIgnoreCase("items")) { + if (!sender.hasPermission("GUIShopManager.Items")) { + sender.sendMessage(ChatColor.RED + "No Permissions!"); + return false; + } + + sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "GuiShopManager Items"); + for (String name : this.plugin.getGSMItems().getItemNames().keySet()) { + sender.sendMessage(ChatColor.YELLOW + "- " + name); + } + return true; + } + + if (args[0].equalsIgnoreCase("give")) { + if (!sender.hasPermission("GUIShopManager.give")) { + sender.sendMessage(ChatColor.RED + "No Permissions!"); + return false; + } + + if ((args.length != 2) && (args.length != 3)) { + sendInfo(sender); + return false; + } + + String itemname = args[1]; + String playername = sender.getName(); + if (args.length == 3) { + playername = args[2]; + } else if (!(sender instanceof Player)) { + sendInfo(sender); + return false; + } + + ItemStack item = this.plugin.getGSMItems().getItemByName(itemname); + + if (item == null) { + sender.sendMessage(ChatColor.RED + "GuiShopManager Item " + ChatColor.GOLD + + itemname + ChatColor.RED + " not found!"); + return false; + } + + Player player = Bukkit.getPlayerExact(playername); + if (player == null) { + player = Bukkit.getPlayer(playername); + } + + if (player == null) { + sender.sendMessage(ChatColor.RED + "Player " + ChatColor.GOLD + playername + + ChatColor.RED + " not found!"); + return false; + } + + player.getInventory().addItem(new ItemStack[] { item }); + sender.sendMessage(ChatColor.YELLOW + "Added GSM Item " + ChatColor.RED + itemname + + ChatColor.YELLOW + " to " + ChatColor.RED + playername + "'s" + + ChatColor.YELLOW + " Inventory."); + + return true; + } + + } + + sendInfo(sender); + + return false; + } + + private void sendInfo(CommandSender s) { + s.sendMessage(ChatColor.YELLOW + "/GSM reload " + ChatColor.RED + + "- Reloads GUIShopManager"); + s.sendMessage(ChatColor.YELLOW + "/GSM items " + ChatColor.RED + "- Lists all GSM Items"); + s.sendMessage(ChatColor.YELLOW + "/GSM give [Player] " + ChatColor.RED + + "- Gives [Player] the named item"); + } +} \ No newline at end of file diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/GSMItems.java b/src/org/black_ixx/bossshop/addon/guishopmanager/GSMItems.java new file mode 100644 index 0000000..86591c3 --- /dev/null +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/GSMItems.java @@ -0,0 +1,169 @@ +package org.black_ixx.bossshop.addon.guishopmanager; + +import java.util.HashMap; +import java.util.List; + +import org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class GSMItems implements Reloadable { + private HashMap items = new HashMap(); + private HashMap item_names = new HashMap(); + private HashMap joinItems = new HashMap(); + private GuiShopManager plugin; + + public GSMItems(GuiShopManager plugin) { + this.plugin = plugin; + + loadItems(plugin); + } + + public ItemStack getItemByName(String name) { + ItemStack i = this.item_names.get(name); + if (i != null) + return i; + for (String s : this.item_names.keySet()) { + if (s.equalsIgnoreCase(name)) + return this.item_names.get(s); + } + for (String s : this.item_names.keySet()) { + if (s.toLowerCase().startsWith(name.toLowerCase())) + return this.item_names.get(s); + } + return null; + } + + public HashMap getItemNames() { + return this.item_names; + } + + public void giveJoinItems(Player p) { + if (!this.joinItems.isEmpty()) { + for (Integer integer : this.joinItems.keySet()) { + int loc = integer.intValue(); + ItemStack i = this.joinItems.get(Integer.valueOf(loc)); + + if ((!p.getInventory().contains(i.getType())) + || (!hasItem(i, p))) { + loc--; + + boolean b = false; + + if ((loc >= p.getInventory().getSize()) || (loc < 0)) { + loc = 0; + b = true; + } + + if ((!b) || (p.getInventory().getItem(loc) == null)) { + p.getInventory().setItem(loc, i.clone()); + } else { + p.getInventory().addItem(new ItemStack[] { i.clone() }); + } + } + } + } + } + + private boolean hasItem(ItemStack i, Player p) { + for (ItemStack s : p.getInventory().getContents()) { + if ((s != null) + && (s.hasItemMeta()) + && (s.getItemMeta().hasDisplayName()) + && (s.getItemMeta().getDisplayName().equalsIgnoreCase(i + .getItemMeta().getDisplayName()))) + return true; + + } + + return false; + } + + public boolean isShopItem(ItemStack s) { + if (s == null) + return false; + + for (ItemStack i : this.items.keySet()) { + if (i != null) { + if (i.getType() == s.getType()) { + if (i.getItemMeta().getDisplayName() + .equalsIgnoreCase(s.getItemMeta().getDisplayName())) + return true; + } + } + } + + return false; + } + + private void loadItems(GuiShopManager plugin) { + ConfigurationSection c = plugin.getConfig().getConfigurationSection( + "Items"); + if (c == null) { + Bukkit.getLogger() + .severe("[GuiShopManager] No Items were found in the config :/ Delete your config and restart the server to generate a new config file."); + return; + } + + for (String path_name : c.getKeys(false)) { + ConfigurationSection sec = c.getConfigurationSection(path_name); + + String open_shop = sec.getString("OpenShop"); + + if (open_shop != null) { + boolean give_on_join = sec.getBoolean("GiveOnJoin"); + int inventoryloc = sec.getInt("InventoryLocation"); + + List list = sec.getStringList("Look"); + if (list != null) { + ItemStack item = plugin.getBossShop().getClassManager() + .getItemStackCreator().createItemStack(list); + + this.items.put(item, open_shop); + this.item_names.put(path_name, item); + + if (give_on_join) { + this.joinItems.put(Integer.valueOf(inventoryloc), item); + } + } + } + } + } + + public void playerClicked(PlayerInteractEvent e) { + if (((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) + && (e.getItem() != null)) { + for (ItemStack i : this.items.keySet()) { + if (i != null && i.hasItemMeta() + && i.getItemMeta().hasDisplayName()) { + if (e.getItem() != null && e.getItem().hasItemMeta() + && e.getItem().getItemMeta().hasDisplayName()) { + if (i.getItemMeta() + .getDisplayName() + .equalsIgnoreCase( + e.getItem().getItemMeta() + .getDisplayName())) { + String n = this.items.get(i); + this.plugin.getBossShop().getAPI() + .openShop(e.getPlayer(), n); + e.setCancelled(true); + } + } + } + } + } + } + + @Override + public void reload(GuiShopManager plugin) { + this.items.clear(); + this.item_names.clear(); + this.joinItems.clear(); + + loadItems(plugin); + } +} \ No newline at end of file diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/GuiShopManager.java b/src/org/black_ixx/bossshop/addon/guishopmanager/GuiShopManager.java new file mode 100644 index 0000000..6703808 --- /dev/null +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/GuiShopManager.java @@ -0,0 +1,98 @@ +package org.black_ixx.bossshop.addon.guishopmanager; + +import java.util.ArrayList; +import java.util.List; + +import org.black_ixx.bossshop.addon.guishopmanager.Commander; +import org.black_ixx.bossshop.addon.guishopmanager.GSMItems; +import org.black_ixx.bossshop.addon.guishopmanager.PlayerListener; +import org.black_ixx.bossshop.api.BossShopAddon; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; + +public class GuiShopManager extends BossShopAddon { + private GSMItems items; + private PlayerListener listener; + + private void addDefaultConfig() { + FileConfiguration c = getConfig(); + + c.set("Version", getDescription().getVersion()); + c.set("Settings.AllowPlaceItems", Boolean.valueOf(false)); + c.set("Settings.AllowMoveItems", Boolean.valueOf(false)); + c.set("Settings.AllowDropItems", Boolean.valueOf(false)); + c.set("Settings.DropItemsOnDeath", Boolean.valueOf(false)); + c.set("Settings.GetItemsOnRespawn", Boolean.valueOf(true)); + + List compass = new ArrayList(); + compass.add("name:&aQuick Warp &7(Right Click) &6[x]"); + compass.add("type:COMPASS"); + compass.add("amount:1"); + + List book = new ArrayList(); + book.add("name:&6[o] &4&lBossShop &r&6Menu &6[o]"); + book.add("lore:&7Right Click to open the Menu!"); + book.add("type:BOOK"); + book.add("amount:1"); + + c.set("Items.BossShopMenu.Look", book); + c.set("Items.BossShopMenu.GiveOnJoin", Boolean.valueOf(true)); + c.set("Items.BossShopMenu.InventoryLocation", Integer.valueOf(1)); + c.set("Items.BossShopMenu.OpenShop", "menu"); + + c.set("Items.Servers.Look", compass); + c.set("Items.Servers.GiveOnJoin", Boolean.valueOf(true)); + c.set("Items.Servers.InventoryLocation", Integer.valueOf(9)); + c.set("Items.Servers.OpenShop", "bungeecordservers"); + + saveConfig(); + } + + @Override + public void bossShopReloaded(CommandSender sender) { + reload(); + sender.sendMessage(ChatColor.YELLOW + "Reloaded BossShop Addon " + ChatColor.GOLD + + getAddonName()); + } + + @Override + public void disableAddon() { + } + + @Override + public void enableAddon() { + if (getConfig().getString("Version") == null) { + addDefaultConfig(); + } + + this.items = new GSMItems(this); + this.listener = new PlayerListener(this); + getServer().getPluginManager().registerEvents(this.listener, this); + + getCommand("gsm").setExecutor(new Commander(this)); + } + + @Override + public String getAddonName() { + return "GuiShopManager"; + } + + public GSMItems getGSMItems() { + return this.items; + } + + @Override + public String getRequiredBossShopVersion() { + return "1.9.0"; + } + + public void reload() { + reloadConfig(); + if (getConfig().getString("Version") == null) { + addDefaultConfig(); + } + this.items.reload(this); + this.listener.reload(this); + } +} \ No newline at end of file diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java b/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java new file mode 100644 index 0000000..96ee81e --- /dev/null +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java @@ -0,0 +1,110 @@ +package org.black_ixx.bossshop.addon.guishopmanager; + +import java.util.ArrayList; +import java.util.List; + +import org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; + +public class PlayerListener implements Listener, Reloadable { + private GuiShopManager plugin; + private boolean drop; + private boolean move; + private boolean place; + private boolean death; + private boolean respawn; + + public PlayerListener(GuiShopManager plugin) { + this.plugin = plugin; + loadSettings(plugin); + } + + private void loadSettings(GuiShopManager plugin) { + ConfigurationSection s = plugin.getConfig().getConfigurationSection("Settings"); + + this.drop = s.getBoolean("AllowDropItems"); + this.move = s.getBoolean("AllowMoveItems"); + this.place = s.getBoolean("AllowPlaceItems"); + this.death = s.getBoolean("DropItemsOnDeath"); + this.respawn = s.getBoolean("GetItemsOnRespawn"); + } + + @EventHandler(ignoreCancelled = true) + public void onDeath(PlayerDeathEvent event) { + if (!this.death) { + List toRemove = new ArrayList(); + + for (ItemStack i : event.getDrops()) { + if (this.plugin.getGSMItems().isShopItem(i)) { + toRemove.add(i); + } + + } + + for (ItemStack i : toRemove) { + event.getDrops().remove(i); + } + toRemove.clear(); + } + } + + @EventHandler(ignoreCancelled = true) + public void onDrop(PlayerDropItemEvent event) { + if ((!this.drop) + && (this.plugin.getGSMItems().isShopItem(event.getItemDrop().getItemStack()))) { + event.setCancelled(true); + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) + public void onInteract(PlayerInteractEvent event) { + this.plugin.getGSMItems().playerClicked(event); + } + + @EventHandler(ignoreCancelled = true) + public void onJoin(PlayerJoinEvent event) { + this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); + } + + @EventHandler(ignoreCancelled = true) + public void onMove(InventoryClickEvent event) { + if (event.getWhoClicked().isOp()) + return; + if (!this.move) { + if (this.plugin.getGSMItems().isShopItem(event.getCurrentItem()) + || this.plugin.getGSMItems().isShopItem(event.getCursor())) { + event.setCancelled(true); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlace(BlockPlaceEvent event) { + if ((!this.place) && (this.plugin.getGSMItems().isShopItem(event.getItemInHand()))) { + event.setCancelled(true); + } + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + if (this.respawn) { + this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); + } + } + + @Override + public void reload(GuiShopManager plugin) { + loadSettings(plugin); + } +} \ No newline at end of file diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/Reloadable.java b/src/org/black_ixx/bossshop/addon/guishopmanager/Reloadable.java new file mode 100644 index 0000000..7af00e1 --- /dev/null +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/Reloadable.java @@ -0,0 +1,8 @@ +package org.black_ixx.bossshop.addon.guishopmanager; + +import org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager; + +public abstract interface Reloadable +{ + public abstract void reload(GuiShopManager paramGuiShopManager); +} \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..72a28b9 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,10 @@ +name: GuiShopManager +version: 1.3.3 +description: BossShop Addon managing the GUIs +author: Black_ixx +website: http://felix.neuby.de +main: org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager +depend: [BossShop] +commands: + gsm: + description: GUIShopManager command \ No newline at end of file