diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 4dc3212..eb0155b 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -7,6 +7,7 @@ + diff --git a/pom.xml b/pom.xml index 1f08947..161a8d6 100644 --- a/pom.xml +++ b/pom.xml @@ -11,13 +11,17 @@ me.paradoxpixel themepark - 1.3.1 + 1.4.1 placeholderapi http://repo.extendedclip.com/content/repositories/placeholderapi/ + + dynmap + http://repo.mikeprimm.com/ + @@ -28,9 +32,9 @@ provided - me.clip - placeholderapi - 2.10.2 + org.dynmap + dynmap-api + 2.0 provided diff --git a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java index 49c4101..142b5d0 100644 --- a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java +++ b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java @@ -12,7 +12,6 @@ import me.paradoxpixel.themepark.listener.ClickListener; import me.paradoxpixel.themepark.listener.ChangeListener; import me.paradoxpixel.themepark.listener.PlayerListener; import me.paradoxpixel.themepark.listener.SignListener; -import me.paradoxpixel.themepark.placeholder.ThemeParkPlaceholder; import org.bukkit.Bukkit; import org.bukkit.command.CommandMap; import org.bukkit.plugin.PluginManager; @@ -46,9 +45,6 @@ public class ThemeParkPlugin extends JavaPlugin { private void loadData() { StatusManager.load(); AttractionMenu.load(); - if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new ThemeParkPlaceholder(this).register(); - } } private void loadDatabase() { diff --git a/src/main/java/me/paradoxpixel/themepark/action/PageAction.java b/src/main/java/me/paradoxpixel/themepark/action/PageAction.java new file mode 100644 index 0000000..9599593 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/action/PageAction.java @@ -0,0 +1,20 @@ +package me.paradoxpixel.themepark.action; + +import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.gui.GUIAction; +import org.bukkit.entity.Player; + +public class PageAction extends GUIAction { + + private int page; + + public PageAction(int page) { + this.page = page; + } + + @Override + public void click(Player player) { + AttractionMenu.openMenu(player, page); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java index e572000..31dfa97 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -21,9 +21,6 @@ public class API { if(isRegion(region.getId())) return; - if(regions.size() >= 6) - return; - region = toLower(region); regions.put(region.getId(), region); diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index b40808f..1ecb36e 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -1,6 +1,7 @@ package me.paradoxpixel.themepark.attraction; import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.action.PageAction; import me.paradoxpixel.themepark.action.TPUtils; import me.paradoxpixel.themepark.api.API; import me.paradoxpixel.themepark.api.attraction.Attraction; @@ -13,26 +14,39 @@ import me.paradoxpixel.themepark.gui.GUI; import me.paradoxpixel.themepark.gui.GUIItem; import me.paradoxpixel.themepark.utils.ItemBuilder; import me.paradoxpixel.themepark.api.LocationUtils; +import me.paradoxpixel.themepark.utils.Utils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import java.util.HashMap; import java.util.List; +import java.util.Set; public class AttractionMenu { private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); - private static GUI gui; + private static HashMap pages = new HashMap<>(); private static boolean loading = false; + private static String title; - private static HashMap index; + private static HashMap regionPage; + private static HashMap attractionIndex; + + private static Material mat = Material.NAME_TAG; + private static short data = 0; public static void load() { loading = true; - gui = new GUI(settings.getConfig().getString("menu.title"), 9); - index = new HashMap<>(); + title = settings.getConfig().getString("menu.title"); + + mat = Material.getMaterial(settings.getConfig().getString("region.material")); + data = Short.parseShort(settings.getConfig().getString("region.data")); + + regionPage = new HashMap<>(); + attractionIndex = new HashMap<>(); + loadData(); loading = false; loadItems(); @@ -73,11 +87,6 @@ public class AttractionMenu { HashMap regions = API.getRegions(); HashMap size = new HashMap<>(); for(String id : section.getKeys(false)) { - if(size.size() >= 6) { - config.getConfig().set("regions." + id, null); - continue; - } - String name = config.getConfig().getString("region." + id + ".name"); List lore = config.getConfig().getStringList("region." + id + ".lore"); @@ -91,7 +100,6 @@ public class AttractionMenu { Region region = new Region(id, name, lore); API.addRegion(region); - if(!id.toLowerCase().equals(id)) { config.getConfig().set("region." + id, null); id = id.toLowerCase(); @@ -101,10 +109,10 @@ public class AttractionMenu { } config.save(); - for(String string : regions.keySet()) API.removeRegion(string); + prepareGUI(); if(!config.getConfig().contains("attraction")) return; @@ -150,12 +158,13 @@ public class AttractionMenu { attraction.setLocation(location); attraction.setType(type); attraction.setStatus(status, null); + MapMarker.getMarker().setAttractionMarker(attraction); continue; } Attraction attraction = new Attraction(id, name, region_id, location, type, status); API.addAttraction(attraction); - + MapMarker.getMarker().setAttractionMarker(attraction); if(!id.toLowerCase().equals(id)) { config.getConfig().set("attraction." + id, null); id = id.toLowerCase(); @@ -167,11 +176,83 @@ public class AttractionMenu { } config.save(); - for(String string : attractions.keySet()) API.removeAttraction(string); } + private static void prepareGUI() { + int keySize = API.getRegions().size(); + if(pages.isEmpty()) { + if(keySize <= 6) { + pages.put(1, new GUI(title, keySize * 9)); + } else { + int p = keySize / 5; + for(int i = 0; i < p; i++) + pages.put(i + 1, new GUI(title, 54)); + + int rest = keySize % 5; + if(rest > 0) + pages.put(p + 1, new GUI(title, rest * 9 + 9)); + } + } else { + if(keySize <= 6) { + if(pages.size() > 1) { + for(int i = 1; i < pages.size(); i++) + pages.remove(i + 1); + } + + int z = keySize*9; + GUI gui = pages.get(1); + if(gui.getSize() != z) + gui.setSize(z); + } else { + int p = keySize / 5; + int rest = keySize % 5; + if (rest > 0) + p++; + + if (pages.size() < p) { + for (int i = (pages.size() + 1); i < p; i++) + pages.put(i, new GUI(title, 54)); + + pages.put(p, new GUI(title, rest * 9 + 9)); + } else { + if (pages.size() > p) { + for (int i = pages.size(); i > p; i--) + pages.remove(i); + } else { + if(rest != 0) { + pages.get(p).setSize(rest * 9 + 9); + } else { + pages.get(p).setSize(54); + } + } + } + } + } + } + + public static void update(Attraction attraction) { + if(attraction == null) + return; + + if(!API.isAttraction(attraction.getId())) + return; + + if(!attractionIndex.containsKey(attraction.getId())) + return; + + if(!regionPage.containsKey(attraction.getRegion_id())) + return; + + ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus())); + builder.setName(attraction.getName()); + builder.setLore(StatusManager.getName(attraction.getStatus())); + + GUI gui = pages.get(regionPage.get(attraction.getRegion_id())); + gui.addItem(attractionIndex.get(attraction.getId()), new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true)); + } + private static void loadItems() { if(loading) return; @@ -179,20 +260,34 @@ public class AttractionMenu { if(API.getRegions().values().size() == 0) return; - gui.clear(); - gui.setSize(API.getRegions().size() > 0 ? (API.getRegions().size() * 9) : 9); + for(GUI gui : pages.values()) + gui.clear(); + + int i = 1; + int j = 0; + boolean tb = pages.size() > 1; + HashMap index = new HashMap<>(); for(Region region : API.getRegions().values()) { + if(tb && j >= 5) { + i++; + j = 0; + } + + index.put(region.getId(), j * 9); + regionPage.put(region.getId(), i); if(!index.containsKey(region.getId())) index.put(region.getId(), index.size() * 9); - int i = index.get(region.getId()); - ItemBuilder builder = new ItemBuilder(Material.NAME_TAG); + ItemBuilder builder = new ItemBuilder(mat, 1, data); builder.setName(region.getName()); builder.setLore(region.getLore()); - gui.addItem(i, new GUIItem(builder.getItem(), null, true)); + GUI gui = pages.get(i); + gui.addItem(j * 9, new GUIItem(builder.getItem(), null, true)); + j++; } + for(Attraction attraction : API.getAttractions().values()) { if(!API.isRegion(attraction.getRegion_id())) { API.removeAttraction(attraction.getId()); @@ -202,11 +297,12 @@ public class AttractionMenu { if(!index.containsKey(attraction.getRegion_id())) continue; - int i = index.get(attraction.getRegion_id()); + int in = index.get(attraction.getRegion_id()); + GUI gui = pages.get(regionPage.get(attraction.getRegion_id())); boolean b = false; for(int a = 1; a < 9; a++) { - if(!gui.hasItem(i + a)) { - i += a; + if(!gui.hasItem(in + a)) { + in += a; b = true; break; } @@ -221,12 +317,43 @@ public class AttractionMenu { builder.setName(attraction.getName()); builder.setLore(StatusManager.getName(attraction.getStatus())); - gui.addItem(i, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true)); + gui.addItem(in, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true)); + attractionIndex.put(attraction.getId(), in); + } + + if(pages.size() <= 1) + return; + + i = 1; + for(GUI gui : pages.values()) { + int rows = gui.getSize() / 9; + int offset = (rows - 1) * 9; + + if(i > 1) { + ItemBuilder previous = new ItemBuilder(Material.ARROW); + previous.setName(Utils.color("&6Previous")); + gui.addItem(offset + 3, new GUIItem(previous.getItem(), new PageAction(i - 1), true)); + } + + ItemBuilder middle = new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 1); + middle.setName(Utils.color("&6Page: "+i)); + gui.addItem(offset + 4, new GUIItem(middle.getItem(), null, true)); + + if(i < pages.size()) { + ItemBuilder next = new ItemBuilder(Material.ARROW); + next.setName(Utils.color("&6Next")); + gui.addItem(offset + 5, new GUIItem(next.getItem(), new PageAction(i + 1), true)); + } + + i++; } } - public static void openMenu(Player player) { - player.openInventory(gui.getInventory()); + public static void openMenu(Player player, int page) { + if(page < 1 || page > pages.size()) + page = 1; + + player.openInventory(pages.get(page).getInventory()); } } \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java index c40a629..90408b7 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java @@ -27,10 +27,14 @@ public class StatusSign { public void update() { Status status = attraction.getStatus(); - if(!location.getChunk().isLoaded()) location.getChunk().load(); + if(!(location.getBlock().getState() instanceof Sign)) { + SignManager.removeSign(this); + return; + } + Sign sign = (Sign) location.getBlock().getState(); sign.setLine(2, Utils.color(StatusManager.getName(status))); sign.update(); diff --git a/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java b/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java index 5978fdc..6017db3 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java @@ -13,7 +13,7 @@ public class MenuCommand implements CommandExecutor { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(cmd.getName().equalsIgnoreCase("status")) { if(sender instanceof Player) { - AttractionMenu.openMenu((Player) sender); + AttractionMenu.openMenu((Player) sender, 1); return true; } else { sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command")); diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 49077f7..88d7521 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -7,6 +7,7 @@ import me.paradoxpixel.themepark.api.attraction.Attraction; import me.paradoxpixel.themepark.api.attraction.Region; import me.paradoxpixel.themepark.api.attraction.component.Status; import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.attraction.MapMarker; import me.paradoxpixel.themepark.attraction.status.StatusManager; import me.paradoxpixel.themepark.config.YamlConfig; import me.paradoxpixel.themepark.utils.ItemBuilder; @@ -290,6 +291,7 @@ public class ThemeParkCommand extends BukkitCommand { Attraction attraction = API.getAttraction(id); attraction.setLocation(location.clone()); + MapMarker.getMarker().setAttractionMarker(attraction); sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName()))); return true; } diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java index 45a2e15..b168302 100644 --- a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java +++ b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java @@ -10,6 +10,7 @@ import me.paradoxpixel.themepark.api.event.region.AddRegionEvent; import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent; import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent; import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.attraction.MapMarker; import me.paradoxpixel.themepark.attraction.sign.SignManager; import me.paradoxpixel.themepark.attraction.status.StatusManager; import me.paradoxpixel.themepark.config.YamlConfig; @@ -26,10 +27,11 @@ public class ChangeListener implements Listener { if(e.getAttraction() == null) return; - AttractionMenu.reload(); SignManager.update(e.getAttraction()); Attraction attraction = e.getAttraction(); + AttractionMenu.update(attraction); + Status status = e.getStatusAfter(); String message = Message.getMessage("attraction.changed.status." + status.toString()); message = message.replace("{name}", attraction.getName()); @@ -56,6 +58,7 @@ public class ChangeListener implements Listener { AttractionMenu.reload(); SignManager.remove(e.getAttraction()); + MapMarker.getMarker().removeAttractionMarker(e.getAttraction()); YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); config.getConfig().set("attraction." + e.getAttraction().getId(), null); config.save(); diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java index 27d7551..6a95676 100644 --- a/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java +++ b/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java @@ -39,7 +39,7 @@ public class ClickListener implements Listener { e.setCancelled(true); Player player = e.getPlayer(); - AttractionMenu.openMenu(player); + AttractionMenu.openMenu(player, 1); } } diff --git a/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java b/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java index 8d07c0e..ac71e64 100644 --- a/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java +++ b/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java @@ -10,8 +10,12 @@ import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.List; public class PlayerListener implements Listener { @@ -20,30 +24,12 @@ public class PlayerListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e) { - Material material = Material.getMaterial(settings.getConfig().getString("item.material")); - String name = Utils.color(settings.getConfig().getString("item.display-name")); - int slot = settings.getConfig().getInt("item.slot"); - if(material == null || name.isEmpty()) - return; + doItem(e.getPlayer()); + } - Player player = e.getPlayer(); - - boolean b = true; - if(config.getConfig().contains(player.getUniqueId().toString() + ".item")) { - b = config.getConfig().getBoolean(player.getUniqueId().toString() + ".item"); - } else { - config.getConfig().set(player.getUniqueId().toString() + ".item", true); - config.save(); - } - - if(b) { - ItemBuilder builder = new ItemBuilder(material); - builder.setName(name); - if(settings.getConfig().getBoolean("inventory.clear")) - player.getInventory().clear(); - - player.getInventory().setItem(slot, builder.getItem()); - } + @EventHandler + public void onSwitch(PlayerChangedWorldEvent e) { + doItem(e.getPlayer()); } @EventHandler @@ -65,4 +51,40 @@ public class PlayerListener implements Listener { player.sendMessage(Utils.color("&6ThemePark&f: &4You can't teleport while in a minecart")); } + public void doItem(Player player) { + if(!settings.getConfig().getBoolean("item.enabled")) + return; + + Material material = Material.getMaterial(settings.getConfig().getString("item.material")); + String name = Utils.color(settings.getConfig().getString("item.display-name")); + int slot = settings.getConfig().getInt("item.slot"); + if(material == null || name.isEmpty()) + return; + + boolean b = true; + if(config.getConfig().contains(player.getUniqueId().toString() + ".item")) { + b = config.getConfig().getBoolean(player.getUniqueId().toString() + ".item"); + } else { + config.getConfig().set(player.getUniqueId().toString() + ".item", true); + config.save(); + } + + if(b) { + if(settings.getConfig().getBoolean("inventory.clear")) + player.getInventory().clear(); + + List worlds = settings.getConfig().getStringList("item.worlds"); + if(worlds != null && !worlds.isEmpty()) { + if (worlds.contains(player.getLocation().getWorld().getName())) { + player.getInventory().setItem(slot, new ItemStack(Material.AIR)); + return; + } + } + + ItemBuilder builder = new ItemBuilder(material); + builder.setName(name); + player.getInventory().setItem(slot, builder.getItem()); + } + } + } \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java b/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java deleted file mode 100644 index 96bf767..0000000 --- a/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.paradoxpixel.themepark.placeholder; - -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.OfflinePlayer; -import org.bukkit.plugin.Plugin; - -public class ThemeParkPlaceholder extends PlaceholderExpansion { - - private Plugin plugin; - - public ThemeParkPlaceholder(Plugin plugin){ - this.plugin = plugin; - } - - @Override - public boolean persist(){ - return true; - } - - @Override - public boolean canRegister() { - return true; - } - - @Override - public String getAuthor() { - return "ParadoxPixel"; - } - - @Override - public String getIdentifier() { - return "tp"; - } - - @Override - public String getVersion() { - return plugin.getDescription().getVersion(); - } - - @Override - public String onRequest(OfflinePlayer player, String identifier){ - if(identifier == null || player == null) - return ""; - - if(identifier.startsWith("status")) { - String[] args = identifier.split(":"); - if(args.length < 2) - return ""; - - String id = args[1]; - if(!API.isAttraction(id)) - return ""; - - Status status = API.getAttraction(id).getStatus(); - return Utils.color(StatusManager.getName(status)); - } - - if(identifier.startsWith("name")) { - String[] args = identifier.split(":"); - if(args.length < 2) - return ""; - - String id = args[1]; - if(!API.isAttraction(id)) - return ""; - - String name = API.getAttraction(id).getName(); - return Utils.color(name); - } - - return ""; - } - -} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 374ba73..8f03e2a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: ThemePark -version: 1.3.1 +version: 1.4.1 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel -softdepend: [PlaceholderAPI] +softdepend: [PlaceholderAPI,Dynmap] commands: status: \ No newline at end of file diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index 4137d02..f188b3d 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -11,9 +11,13 @@ inventory: clear: true item: + enabled: true material: NETHER_STAR display-name: 'Themepark' slot: 4 + worlds: + - world_nether + - world_the_end mysql: enabled: false @@ -24,6 +28,10 @@ mysql: password: 'password' url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false' +region: + material: NAME_TAG + data: 0 + CONSTRUCTION: name: "&7Under Construction" material: STAINED_CLAY