From 184d8c59cbc395f2af574212f0f55f8cf4df06d4 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 15 Jan 2019 18:16:59 +0100 Subject: [PATCH 01/25] Initial commit --- .idea/.name | 1 + .idea/compiler.xml | 13 + .idea/encodings.xml | 4 + .idea/misc.xml | 14 + pom.xml | 24 ++ .../themepark/ThemeParkPlugin.java | 118 ++++++ .../themepark/action/TPUtils.java | 46 +++ .../me/paradoxpixel/themepark/api/API.java | 148 +++++++ .../themepark/api/attraction/Attraction.java | 72 ++++ .../themepark/api/attraction/Region.java | 96 +++++ .../api/attraction/component/Status.java | 35 ++ .../api/attraction/component/Type.java | 59 +++ .../event/attraction/AddAttractionEvent.java | 29 ++ .../attraction/PreStatusChangeEvent.java | 61 +++ .../attraction/RemoveAttractionEvent.java | 29 ++ .../event/attraction/StatusChangeEvent.java | 48 +++ .../api/event/region/AddRegionEvent.java | 30 ++ .../api/event/region/ChangeRegionEvent.java | 53 +++ .../api/event/region/RemoveRegionEvent.java | 30 ++ .../themepark/attraction/AttractionMenu.java | 170 ++++++++ .../attraction/sign/SignManager.java | 142 +++++++ .../themepark/attraction/sign/StatusSign.java | 36 ++ .../attraction/status/StatusManager.java | 76 ++++ .../themepark/command/MenuCommand.java | 25 ++ .../themepark/command/ThemeParkCommand.java | 373 ++++++++++++++++++ .../themepark/config/YamlConfig.java | 87 ++++ .../themepark/database/Database.java | 187 +++++++++ .../themepark/database/DatabaseHandler.java | 117 ++++++ .../me/paradoxpixel/themepark/gui/GUI.java | 120 ++++++ .../paradoxpixel/themepark/gui/GUIAction.java | 9 + .../paradoxpixel/themepark/gui/GUIHolder.java | 11 + .../paradoxpixel/themepark/gui/GUIItem.java | 45 +++ .../themepark/gui/GUIListener.java | 29 ++ .../themepark/listener/ChangeListener.java | 115 ++++++ .../themepark/listener/ClickListener.java | 45 +++ .../themepark/listener/PlayerListener.java | 68 ++++ .../themepark/listener/SignListener.java | 64 +++ .../themepark/utils/ItemBuilder.java | 111 ++++++ .../themepark/utils/LocationUtils.java | 50 +++ .../paradoxpixel/themepark/utils/Message.java | 25 ++ .../paradoxpixel/themepark/utils/Utils.java | 15 + src/main/resources/attraction.yml | 40 ++ src/main/resources/message.yml | 42 ++ src/main/resources/plugin.yml | 6 + src/main/resources/settings.yml | 72 ++++ 45 files changed, 2990 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 pom.xml create mode 100644 src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java create mode 100644 src/main/java/me/paradoxpixel/themepark/action/TPUtils.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/API.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java create mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java create mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java create mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java create mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java create mode 100644 src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java create mode 100644 src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java create mode 100644 src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java create mode 100644 src/main/java/me/paradoxpixel/themepark/database/Database.java create mode 100644 src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java create mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUI.java create mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java create mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java create mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java create mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java create mode 100644 src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java create mode 100644 src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java create mode 100644 src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java create mode 100644 src/main/java/me/paradoxpixel/themepark/listener/SignListener.java create mode 100644 src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java create mode 100644 src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java create mode 100644 src/main/java/me/paradoxpixel/themepark/utils/Message.java create mode 100644 src/main/java/me/paradoxpixel/themepark/utils/Utils.java create mode 100644 src/main/resources/attraction.yml create mode 100644 src/main/resources/message.yml create mode 100644 src/main/resources/plugin.yml create mode 100644 src/main/resources/settings.yml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..09564ec --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Theme \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..4dc3212 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..05431e9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + + 1.8 + 1.8 + + + me.paradoxpixel + themepark + 1.1 + + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java new file mode 100644 index 0000000..142b5d0 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java @@ -0,0 +1,118 @@ +package me.paradoxpixel.themepark; + +import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.attraction.sign.SignManager; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.command.MenuCommand; +import me.paradoxpixel.themepark.command.ThemeParkCommand; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.database.DatabaseHandler; +import me.paradoxpixel.themepark.gui.GUIListener; +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 org.bukkit.Bukkit; +import org.bukkit.command.CommandMap; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import java.lang.reflect.Field; + +public class ThemeParkPlugin extends JavaPlugin { + + private static ThemeParkPlugin instance; + private YamlConfig settings, attraction, message, signs, data; + private DatabaseHandler database; + + @Override + public void onEnable() { + instance = this; + loadConfig(); + loadListener(); + loadCommand(); + loadData(); + loadDatabase(); + } + + private void loadConfig() { + settings = new YamlConfig("settings", this); + attraction = new YamlConfig("attraction", this); + message = new YamlConfig("message", this); + signs = new YamlConfig("signs", this); + data = new YamlConfig("data", this); + } + + private void loadData() { + StatusManager.load(); + AttractionMenu.load(); + } + + private void loadDatabase() { + database = new DatabaseHandler(settings); + } + + private void loadCommand() { + getCommand("status").setExecutor(new MenuCommand()); + + String command = settings.getConfig().getString("command"); + if(command == null || command.isEmpty()) + return; + + try { + final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); + + bukkitCommandMap.setAccessible(true); + CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); + + commandMap.register(command, new ThemeParkCommand(command)); + } catch(ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + private void loadListener() { + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new GUIListener(), this); + pm.registerEvents(new ClickListener(), this); + pm.registerEvents(new ChangeListener(), this); + pm.registerEvents(new SignListener(), this); + pm.registerEvents(new PlayerListener(), this); + } + + @Override + public void onDisable() { + AttractionMenu.save(); + SignManager.saveSigns(); + database.disconnect(); + instance = null; + } + + public static ThemeParkPlugin getInstance() { + return instance; + } + + public YamlConfig getSettings() { + return settings; + } + + public YamlConfig getAttraction() { + return attraction; + } + + public YamlConfig getMessage() { + return message; + } + + public YamlConfig getSigns() { + return signs; + } + + public YamlConfig getData() { + return data; + } + + public DatabaseHandler getDatabaseHandler() { + return database; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java b/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java new file mode 100644 index 0000000..c91c062 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java @@ -0,0 +1,46 @@ +package me.paradoxpixel.themepark.action; + +import me.paradoxpixel.themepark.api.API; +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.gui.GUIAction; +import me.paradoxpixel.themepark.utils.Message; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; + +public class TPUtils extends GUIAction { + + private String id; + + public TPUtils(String id) { + this.id = id; + } + + @Override + public void click(Player player) { + player.closeInventory(); + Attraction attraction = API.getAttraction(id); + if(attraction == null) + return; + + if(!StatusManager.canTeleport(attraction.getStatus())) { + String message = Message.getMessage("attraction.teleport.status"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + player.sendMessage(Utils.color(message)); + return; + } + + player.teleport(attraction.getLocation()); + if(player.isInsideVehicle()) + if(player.getVehicle() instanceof Minecart) + return; + + String message = Message.getMessage("attraction.teleport.success"); + message = message.replace("{name}", attraction.getName()); + player.sendMessage(Utils.color(message)); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java new file mode 100644 index 0000000..900fda3 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -0,0 +1,148 @@ +package me.paradoxpixel.themepark.api; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.Region; +import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent; +import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent; +import me.paradoxpixel.themepark.api.event.region.AddRegionEvent; +import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +public class API { + + private static LinkedHashMap regions = new LinkedHashMap<>(); + private static LinkedHashMap attractions = new LinkedHashMap<>(); + + public static void addRegion(Region region) { + if(isRegion(region.getId())) + return; + + if(regions.size() >= 6) + return; + + region = toLower(region); + regions.put(region.getId(), region); + + AddRegionEvent event = new AddRegionEvent(region); + Bukkit.getPluginManager().callEvent(event); + } + + public static boolean isRegion(String id) { + return regions.containsKey(id.toLowerCase()); + } + + public static boolean isRegionFull(String id) { + if(!isRegion(id)) + return false; + + return getRegion(id).getAttractions().size() >= 8; + } + + public static Region getRegion(String id) { + return regions.get(id.toLowerCase()); + } + + public static HashMap getRegions() { + return new LinkedHashMap<>(regions); + } + + public static void removeRegion(String id) { + if(!isRegion(id)) + return; + + HashMap map = new HashMap<>(attractions); + for(Map.Entry entry : map.entrySet()) { + Attraction attraction = entry.getValue(); + if(!attraction.getRegion_id().equalsIgnoreCase(id)) + continue; + + removeAttraction(attraction.getId()); + } + + RemoveRegionEvent event = new RemoveRegionEvent(getRegion(id)); + Bukkit.getPluginManager().callEvent(event); + regions.remove(id.toLowerCase()); + } + + public static void addAttraction(Attraction attraction) { + if(!isRegion(attraction.getRegion_id())) + return; + + if(isRegionFull(attraction.getRegion_id())) + return; + + if(isAttraction(attraction.getId())) + return; + + attraction = toLower(attraction); + getRegion(attraction.getRegion_id()).addAttraction(attraction); + attractions.put(attraction.getId(), attraction); + + AddAttractionEvent event = new AddAttractionEvent(attraction); + Bukkit.getPluginManager().callEvent(event); + } + + public static boolean isAttraction(String id) { + return attractions.containsKey(id.toLowerCase()); + } + + public static Attraction getAttraction(String id) { + return attractions.get(id.toLowerCase()); + } + + public static Attraction getAttractionFromName(String name) { + for(Attraction attraction : attractions.values()) { + if(!color(attraction.getName()).equals(name)) + continue; + + return attraction; + } + + return null; + } + + public static HashMap getAttractions() { + return new LinkedHashMap<>(attractions); + } + + public static void removeAttraction(String id) { + if(!isAttraction(id)) + return; + + Attraction attraction = getAttraction(id); + if(isRegion(attraction.getRegion_id())) + getRegion(attraction.getRegion_id()).removeAttraction(attraction); + + attractions.remove(id.toLowerCase()); + + RemoveAttractionEvent event = new RemoveAttractionEvent(attraction); + Bukkit.getPluginManager().callEvent(event); + } + + private static Region toLower(Region region) { + Region re = new Region(region.getId().toLowerCase(), + region.getName(), + region.getLore()); + + re.setAttractions(region.getAttractions()); + return re; + } + + private static Attraction toLower(Attraction attraction) { + return new Attraction(attraction.getId().toLowerCase(), + attraction.getName(), + attraction.getRegion_id().toLowerCase(), + attraction.getLocation(), + attraction.getType(), + attraction.getStatus()); + } + + private static String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java new file mode 100644 index 0000000..d8d8ec6 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -0,0 +1,72 @@ +package me.paradoxpixel.themepark.api.attraction; + +import me.paradoxpixel.themepark.api.attraction.component.Status; +import me.paradoxpixel.themepark.api.attraction.component.Type; +import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; +import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class Attraction { + + private String id, name, region_id; + private Location location; + private Type type; + private Status status; + + public Attraction(String id, String name, String region_id, Location location, Type type, Status status) { + this.id = id; + this.name = name; + this.region_id = region_id; + this.location = location; + this.type = type; + this.status = type.containsStatus(status) ? status : type.getDefefault(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getRegion_id() { + return region_id; + } + + public Location getLocation() { + return location; + } + + public void setLocation(Location location) { + this.location = location; + } + + public Type getType() { + return type; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status, Player player) { + if(!type.hasStatus()) + return; + + if(!type.containsStatus(status)) + return; + + PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status); + Bukkit.getPluginManager().callEvent(event); + if(event.isCancelled()) + return; + + this.status = status; + StatusChangeEvent e = new StatusChangeEvent(this, player, this.status, status); + Bukkit.getPluginManager().callEvent(e); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java new file mode 100644 index 0000000..a41e236 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java @@ -0,0 +1,96 @@ +package me.paradoxpixel.themepark.api.attraction; + +import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent; +import org.bukkit.Bukkit; +import java.util.ArrayList; +import java.util.List; + +public class Region { + + private String id, name; + private List lore; + private ArrayList attractions; + + public Region(String id, String name, List lore) { + this.id = id; + this.name = name; + this.lore = lore; + this.attractions = new ArrayList<>(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String string) { + if(string == null || string.equals("")) + return; + + String old = name; + name = string; + + ChangeRegionEvent event = new ChangeRegionEvent(this, old, string, lore, lore); + Bukkit.getPluginManager().callEvent(event); + } + + public List getLore() { + return lore; + } + + public void setLore(List lore) { + List old = lore; + this.lore = lore; + + ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore); + Bukkit.getPluginManager().callEvent(event); + } + + public void setLore(int i, String string) { + if(lore.size() >= 4 || i >= 4) + return; + + List old = lore; + lore = new ArrayList<>(); + lore.addAll(old); + + if(!string.equals("NULL")) { + if (lore.size() >= i) + for (int a = 0; a <= (i - lore.size()); a++) + lore.add(" "); + + lore.set(i, string); + } else { + lore.remove(i); + } + + ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore); + Bukkit.getPluginManager().callEvent(event); + } + + public ArrayList getAttractions() { + return attractions; + } + + public void setAttractions(ArrayList attractions) { + this.attractions = attractions; + } + + public void addAttraction(Attraction attraction) { + if(!isAttraction(attraction)) + attractions.add(attraction); + } + + public boolean isAttraction(Attraction attraction) { + return attractions.contains(attraction); + } + + public void removeAttraction(Attraction attraction) { + if(isAttraction(attraction)) + attractions.remove(attraction); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java new file mode 100644 index 0000000..78f03e5 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java @@ -0,0 +1,35 @@ +package me.paradoxpixel.themepark.api.attraction.component; + +public enum Status { + + CONSTRUCTION, OPEN, + CLOSED, MAINTENANCE, + MALFUNCTION, ACTIVE, + INACTIVE, GLOBAL; + + public static Status getStatus(String string) { + if(string == null) + return null; + + string = string.toUpperCase(); + switch(string) { + case "CONSTRUCTION": + return Status.CONSTRUCTION; + case "OPEN": + return Status.OPEN; + case "CLOSED": + return Status.CLOSED; + case "MAINTENANCE": + return Status.MAINTENANCE; + case "MALFUNCTION": + return Status.MALFUNCTION; + case "ACTIVE": + return Status.ACTIVE; + case "INACTIVE": + return Status.INACTIVE; + default: + return null; + } + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java new file mode 100644 index 0000000..9339df6 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java @@ -0,0 +1,59 @@ +package me.paradoxpixel.themepark.api.attraction.component; + +public enum Type { + + RIDE(true, Status.CLOSED, Status.CONSTRUCTION, Status.OPEN, Status.CLOSED, Status.MAINTENANCE, Status.MALFUNCTION), + SHOW(true, Status.CLOSED, Status.CONSTRUCTION, Status.ACTIVE, Status.INACTIVE), + GLOBAL(false, Status.GLOBAL); + + private boolean status; + private Status def; + private Status[] array; + + Type(boolean status, Status def, Status... array) { + this.status = status; + this.def = def; + this.array = array; + } + + public boolean hasStatus() { + return status; + } + + public Status getDefefault() { + return def; + } + + public boolean containsStatus(Status status) { + if(status == null) + return false; + + if(!hasStatus()) + return false; + + for(int i = 0; i < array.length; i++) + if(array[i] == status) + return true; + + return false; + } + + + public static Type getType(String string) { + if(string == null) + return null; + + string = string.toUpperCase(); + switch(string) { + case "RIDE": + return Type.RIDE; + case "SHOW": + return Type.SHOW; + case "GLOBAL": + return Type.GLOBAL; + default: + return null; + } + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java new file mode 100644 index 0000000..56899fe --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java @@ -0,0 +1,29 @@ +package me.paradoxpixel.themepark.api.event.attraction; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class AddAttractionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Attraction attraction; + + public AddAttractionEvent(Attraction attraction) { + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java new file mode 100644 index 0000000..529e6da --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java @@ -0,0 +1,61 @@ +package me.paradoxpixel.themepark.api.event.attraction; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.component.Status; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PreStatusChangeEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + private boolean cancel; + private Attraction attraction; + private Player player; + private Status before, after; + + public PreStatusChangeEvent(Attraction attraction, Player player, Status before, Status after) { + this.attraction = attraction; + this.player = player; + this.before = before; + this.after = after; + cancel = false; + } + + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean b) { + cancel = b; + } + + public Attraction getAttraction() { + return attraction; + } + + public Player getPlayer() { + return player; + } + + public Status getStatusBefore() { + return before; + } + + public Status getStatusAfter() { + return after; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java new file mode 100644 index 0000000..a07cb09 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java @@ -0,0 +1,29 @@ +package me.paradoxpixel.themepark.api.event.attraction; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class RemoveAttractionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Attraction attraction; + + public RemoveAttractionEvent(Attraction attraction) { + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java new file mode 100644 index 0000000..2e80350 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java @@ -0,0 +1,48 @@ +package me.paradoxpixel.themepark.api.event.attraction; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.component.Status; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class StatusChangeEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Attraction attraction; + private Player player; + private Status before, after; + + public StatusChangeEvent(Attraction attraction, Player player, Status before, Status after) { + this.attraction = attraction; + this.player = player; + this.before = before; + this.after = after; + } + + public Attraction getAttraction() { + return attraction; + } + + public Player getPlayer() { + return player; + } + + public Status getStatusBefore() { + return before; + } + + public Status getStatusAfter() { + return after; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java new file mode 100644 index 0000000..21fc13e --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java @@ -0,0 +1,30 @@ +package me.paradoxpixel.themepark.api.event.region; + +import me.paradoxpixel.themepark.api.attraction.Region; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class AddRegionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Region region; + + public AddRegionEvent(Region region) { + this.region = region; + } + + public Region getRegion() { + return region; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} + diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java new file mode 100644 index 0000000..5a8ae8a --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java @@ -0,0 +1,53 @@ +package me.paradoxpixel.themepark.api.event.region; + +import me.paradoxpixel.themepark.api.attraction.Region; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import java.util.List; + +public class ChangeRegionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Region region; + private String bname, aname; + private List blore, alore; + + public ChangeRegionEvent(Region region, String bname, String aname, List blore, List alore) { + this.region = region; + this.bname = bname; + this.aname = aname; + this.blore = blore; + this.alore = alore; + } + + public Region getRegion() { + return region; + } + + public String getNameBefore() { + return bname; + } + + public String getNameAfter() { + return aname; + } + + public List getLoreBefore() { + return blore; + } + + public List getLoreAfter() { + return alore; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} + diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java new file mode 100644 index 0000000..8c7d47c --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java @@ -0,0 +1,30 @@ +package me.paradoxpixel.themepark.api.event.region; + +import me.paradoxpixel.themepark.api.attraction.Region; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class RemoveRegionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Region region; + + public RemoveRegionEvent(Region region) { + this.region = region; + } + + public Region getRegion() { + return region; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + +} diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java new file mode 100644 index 0000000..e3fae0c --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -0,0 +1,170 @@ +package me.paradoxpixel.themepark.attraction; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.action.TPUtils; +import me.paradoxpixel.themepark.api.API; +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.api.attraction.component.Type; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.gui.GUI; +import me.paradoxpixel.themepark.gui.GUIItem; +import me.paradoxpixel.themepark.utils.ItemBuilder; +import me.paradoxpixel.themepark.utils.LocationUtils; +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; + +public class AttractionMenu { + + private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); + private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); + private static GUI gui; + + private static HashMap index = new HashMap<>(); + + public static void load() { + gui = new GUI(settings.getConfig().getString("menu.title"), 9); + loadData(); + loadItems(); + } + + public static void reload() { + loadItems(); + } + + public static void save() { + for(Region region : API.getRegions().values()) { + config.getConfig().set("region." + region.getId() + ".name", region.getName()); + config.getConfig().set("region." + region.getId() + ".lore", region.getLore()); + } + + for(Attraction attraction : API.getAttractions().values()) { + config.getConfig().set("attraction." + attraction.getId() + ".name", attraction.getName()); + config.getConfig().set("attraction." + attraction.getId() + ".region_id", attraction.getRegion_id()); + config.getConfig().set("attraction." + attraction.getId() + ".type", attraction.getType().toString()); + config.getConfig().set("attraction." + attraction.getId() + ".status", attraction.getStatus().toString()); + config.getConfig().set("attraction." + attraction.getId() + ".location", LocationUtils.toString(attraction.getLocation())); + } + + config.save(); + } + + private static void loadData() { + if(!config.getConfig().contains("region")) + return; + + if(!config.getConfig().isConfigurationSection("region")) + return; + + ConfigurationSection section = config.getConfig().getConfigurationSection("region"); + if(section.getKeys(false).isEmpty()) + return; + + for(String id : section.getKeys(false)) { + if(API.getRegions().size() >= 6) { + config.getConfig().set("regions." + id, null); + config.save(); + continue; + } + + String name = config.getConfig().getString("region." + id + ".name"); + List lore = config.getConfig().getStringList("region." + id + ".lore"); + + Region region = new Region(id, name, lore); + API.addRegion(region); + } + + if(!config.getConfig().contains("attraction")) + return; + + if(!config.getConfig().isConfigurationSection("attraction")) + return; + + section = config.getConfig().getConfigurationSection("attraction"); + if(section.getKeys(false).isEmpty()) + return; + + for(String id : section.getKeys(false)) { + String region_id = config.getConfig().getString("attraction." + id + ".region_id"); + if(!API.isRegion(region_id)) + continue; + + if(API.isRegionFull(region_id)) + continue; + + String name = config.getConfig().getString("attraction." + id + ".name"); + Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location")); + Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); + Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); + + Attraction attraction = new Attraction(id, name, region_id, location, type, status); + API.addAttraction(attraction); + } + + for(Region region : API.getRegions().values()) + if(region.getAttractions().isEmpty()) + API.removeRegion(region.getId()); + } + + private static void loadItems() { + if(API.getRegions().values().size() == 0) + return; + + gui.clear(); + gui.setSize(API.getRegions().size() > 0 ? (API.getRegions().size() * 9) : 9); + for(Region region : API.getRegions().values()) { + 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); + builder.setName(region.getName()); + builder.setLore(region.getLore()); + + gui.addItem(i, new GUIItem(builder.getItem(), null, true)); + } + + for(Attraction attraction : API.getAttractions().values()) { + if(!API.isRegion(attraction.getRegion_id())) { + API.removeAttraction(attraction.getId()); + continue; + } + + if(!index.containsKey(attraction.getRegion_id())) + continue; + + int i = index.get(attraction.getRegion_id()); + boolean b = false; + for(int a = 1; a < 9; a++) { + if(!gui.hasItem(i + a)) { + i += a; + b = true; + break; + } + } + + if(!b) { + API.getRegion(attraction.getRegion_id()).removeAttraction(attraction); + API.removeAttraction(attraction.getId()); + continue; + } + + ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus())); + builder.setName(attraction.getName()); + builder.setLore(StatusManager.getName(attraction.getStatus())); + + gui.addItem(i, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true)); + } + } + + public static void openMenu(Player player) { + player.openInventory(gui.getInventory()); + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java new file mode 100644 index 0000000..554e154 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java @@ -0,0 +1,142 @@ +package me.paradoxpixel.themepark.attraction.sign; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.utils.LocationUtils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SignManager { + + private static YamlConfig config = ThemeParkPlugin.getInstance().getSigns(); + private static HashMap> signs = new HashMap<>(); + + public static void loadSigns(Attraction attraction) { + if(attraction == null) + return; + + if(!config.getConfig().contains("signs." + attraction.getId())) + return; + + if(!config.getConfig().isList("signs." + attraction.getId())) { + config.getConfig().set("signs." + attraction.getId(), null); + config.save(); + return; + } + + ArrayList array = new ArrayList<>(); + List locations = config.getConfig().getStringList("signs." + attraction.getId()); + for(String string : locations) { + Location location = LocationUtils.toLocation(string); + if(location == null) + continue; + + if(!(location.getBlock().getState() instanceof Sign)) + return; + + array.add(new StatusSign(attraction, location)); + } + + signs.put(attraction, array); + } + + public static void saveSigns() { + for(Map.Entry> entry : signs.entrySet()) { + List array = new ArrayList<>(); + for(StatusSign sign : entry.getValue()) + array.add(LocationUtils.toString(sign.getLocation())); + + config.getConfig().set("signs." + entry.getKey().getId(), new ArrayList<>()); + config.getConfig().set("signs." + entry.getKey().getId(), array); + config.save(); + } + } + + public static void addSign(StatusSign sign) { + if(sign == null || sign.getLocation() == null) + return; + + if(!(sign.getLocation().getBlock().getState() instanceof Sign)) + return; + + if(signs.containsKey(sign.getAttraction())) { + signs.get(sign.getAttraction()).add(sign); + return; + } + + ArrayList array = new ArrayList<>(); + array.add(sign); + signs.put(sign.getAttraction(), array); + } + + public static boolean hasSigns(Attraction attraction) { + if(attraction == null) + return false; + + return signs.containsKey(attraction) && (signs.get(attraction).size() > 0); + } + + public static void update(Attraction attraction) { + if(attraction == null) + return; + + if(!hasSigns(attraction)) + return; + + for(StatusSign sign : signs.get(attraction)) + sign.update(); + } + + public static void remove(Attraction attraction) { + if(attraction == null || !signs.containsKey(attraction)) + return; + + for(StatusSign sign : signs.get(attraction)) + sign.getLocation().getBlock().setType(Material.AIR); + + signs.remove(attraction); + config.getConfig().set("signs." + attraction.getId(), null); + config.save(); + } + + public static void removeSign(StatusSign sign) { + if(sign == null || sign.getLocation() == null || sign.getAttraction() == null) + return; + + if(!hasSigns(sign.getAttraction())) + return; + + ArrayList array = signs.get(sign.getAttraction()); + for(StatusSign s : new ArrayList<>(array)) { + Location loc1 = sign.getLocation(); + Location loc2 = s.getLocation(); + + if(loc1 == null || loc2 == null) + return; + + if(LocationUtils.toString(loc1) == null || LocationUtils.toString(loc2) == null) + return; + + if(!LocationUtils.toString(loc1).equals(LocationUtils.toString(loc2))) + return; + + array.remove(s); + } + + if(array.isEmpty()) { + signs.remove(sign.getAttraction()); + config.getConfig().set("signs." + sign.getAttraction().getId(), null); + config.save(); + return; + } + + signs.put(sign.getAttraction(), array); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java new file mode 100644 index 0000000..ce86094 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java @@ -0,0 +1,36 @@ +package me.paradoxpixel.themepark.attraction.sign; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.component.Status; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Location; +import org.bukkit.block.Sign; + +public class StatusSign { + + private Attraction attraction; + private Location location; + + public StatusSign(Attraction attraction, Location location) { + this.attraction = attraction; + this.location = location; + } + + public Attraction getAttraction() { + return attraction; + } + + public Location getLocation() { + return location; + } + + public void update() { + Status status = attraction.getStatus(); + + 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/attraction/status/StatusManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java new file mode 100644 index 0000000..d632502 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java @@ -0,0 +1,76 @@ +package me.paradoxpixel.themepark.attraction.status; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.api.attraction.component.Status; +import me.paradoxpixel.themepark.config.YamlConfig; +import org.bukkit.Material; +import java.util.HashMap; + +public class StatusManager { + + private static YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); + private static HashMap names; + private static HashMap materials; + private static HashMap data; + private static HashMap teleport; + + public static void load() { + names = new HashMap<>(); + materials = new HashMap<>(); + data = new HashMap<>(); + teleport = new HashMap<>(); + + for(Status status : Status.values()) { + if(config.getConfig().contains(status.toString() + ".name")) { + names.put(status, config.getConfig().getString(status.toString() + ".name")); + } else { + names.put(status, "UNKNOWN"); + } + + if(config.getConfig().contains(status.toString() + ".material")) { + Material material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material")); + if(material == null) + material = Material.STAINED_CLAY; + + materials.put(status, material); + } else { + materials.put(status, Material.STAINED_CLAY); + } + + if(config.getConfig().contains(status.toString() + ".data")) { + String string = config.getConfig().getString(status.toString() + ".data"); + if(string.isEmpty()) { + data.put(status, (short) 0); + continue; + } + + data.put(status, Short.parseShort(string)); + } else { + data.put(status, (short) 0); + } + + if(config.getConfig().contains(status.toString() + ".teleport")) { + teleport.put(status, config.getConfig().getBoolean(status.toString() + ".teleport")); + } else { + teleport.put(status, false); + } + } + } + + public static String getName(Status status) { + return names.get(status); + } + + public static Material getMaterial(Status status) { + return materials.get(status); + } + + public static short getData(Status status) { + return data.get(status); + } + + public static boolean canTeleport(Status status) { + return teleport.get(status); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java b/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java new file mode 100644 index 0000000..5978fdc --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java @@ -0,0 +1,25 @@ +package me.paradoxpixel.themepark.command; + +import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class MenuCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(cmd.getName().equalsIgnoreCase("status")) { + if(sender instanceof Player) { + AttractionMenu.openMenu((Player) sender); + return true; + } else { + sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command")); + } + } + return false; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java new file mode 100644 index 0000000..628004d --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -0,0 +1,373 @@ +package me.paradoxpixel.themepark.command; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.api.API; +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.status.StatusManager; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.utils.ItemBuilder; +import me.paradoxpixel.themepark.utils.Message; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.BukkitCommand; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; +import java.util.Scanner; +import java.util.UUID; + +public class ThemeParkCommand extends BukkitCommand { + + private String name; + + public ThemeParkCommand(String name) { + super(name); + + this.name = name; + } + + public boolean execute(CommandSender sender,String label, String[] args) { + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<")); + sender.sendMessage(Utils.color("&f/" + name + " help")); + sender.sendMessage(Utils.color("&f/" + name + " list")); + sender.sendMessage(Utils.color("&f/" + name + " warp [id]")); + if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) { + sender.sendMessage(Utils.color("&f/" + name + " toggleitem")); + sender.sendMessage(Utils.color("&f/" + name + " getitem")); + } + + if(sender.hasPermission("themepark.admin")) { + sender.sendMessage(Utils.color("&f/" + name + " reload")); + sender.sendMessage(Utils.color("&f/" + name + " regionname [id] [name]")); + sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]")); + sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]")); + sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]")); + sender.sendMessage(Utils.color("&f/" + name + " ridecount [id] [player]")); + } + + return true; + } + + if (args[0].equalsIgnoreCase("list")) { + sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<")); + if (API.getAttractions().size() == 0) { + sender.sendMessage(Utils.color(Message.getMessage("attraction.notfound"))); + return true; + } + + for (Attraction attraction : API.getAttractions().values()) { + String message = Message.getMessage("attraction.list"); + message = message.replace("{id}", attraction.getId()); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).getName()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + sender.sendMessage(Utils.color(message)); + } + + return true; + } + + if(args[0].equalsIgnoreCase("warp")) { + if(args.length < 2) { + sender.sendMessage(Utils.color( "&6Themepark&f: &4/" + name + " warp [id]")); + return true; + } + + String id = args[1]; + if(!API.isAttraction(id)) { + String message = Message.getMessage("attraction.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + if(sender instanceof Player) { + Attraction attraction = API.getAttraction(id); + Player player = (Player) sender; + if(!StatusManager.canTeleport(attraction.getStatus())) { + String message = Message.getMessage("attraction.teleport.status"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + player.sendMessage(Utils.color(message)); + return true; + } + + player.teleport(attraction.getLocation()); + if(player.isInsideVehicle()) + if(player.getVehicle() instanceof Minecart) + return true; + + player.sendMessage(Utils.color(Message.getMessage("attraction.teleport.success").replace("{name}", attraction.getName()))); + return true; + } else { + sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); + return true; + } + } + + if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) { + sender.sendMessage(Utils.color(Message.getMessage("nopermission"))); + return true; + } + + if(args[0].equalsIgnoreCase("toggleitem")) { + if(!(sender instanceof Player)) { + sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); + return true; + } + + Player player = (Player) sender; + UUID uuid = player.getUniqueId(); + + YamlConfig config = ThemeParkPlugin.getInstance().getData(); + boolean b = config.getConfig().getBoolean(uuid.toString() + ".item"); + b = !b; + + config.getConfig().set(uuid.toString() + ".item", b); + config.save(); + + String message = Message.getMessage("menu.item.toggle"); + message = message.replace("{status}", b ? Message.getMessage("enabled") : Message.getMessage("disabled")); + sender.sendMessage(Utils.color(message)); + return true; + } + + if(args[0].equalsIgnoreCase("getitem")) { + YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); + Material material = Material.getMaterial(settings.getConfig().getString("item.material")); + String name = Utils.color(settings.getConfig().getString("item.display-name")); + if(material == null || name.isEmpty()) + return true; + + Player player; + if(args.length >= 2) { + String string = args[1]; + if(Bukkit.getPlayerExact(string) == null) { + String message = Message.getMessage("noplayer"); + message = message.replace("{name}", string); + sender.sendMessage(Utils.color(message)); + return true; + } + + player = Bukkit.getPlayerExact(string); + } else { + if(!(sender instanceof Player)) { + sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); + return true; + } + + player = (Player) sender; + } + + + ItemBuilder builder = new ItemBuilder(material); + builder.setName(name); + player.getInventory().addItem(builder.getItem()); + } + + if(!sender.hasPermission("themepark.admin")) { + sender.sendMessage(Utils.color(Message.getMessage("nopermission"))); + return true; + } + + if(args[0].equalsIgnoreCase("reload")) { + ThemeParkPlugin.getInstance().getData().reload(); + ThemeParkPlugin.getInstance().getAttraction().reload(); + ThemeParkPlugin.getInstance().getSigns().reload(); + ThemeParkPlugin.getInstance().getSettings().reload(); + ThemeParkPlugin.getInstance().getMessage().reload(); + + API.getRegions().clear(); + API.getAttractions().clear(); + + StatusManager.load(); + AttractionMenu.load(); + for(Region region : API.getRegions().values()) + if(region.getAttractions().isEmpty()) + API.removeRegion(region.getId()); + + sender.sendMessage(Utils.color(Message.getMessage("reloaded"))); + } + + if (args[0].equalsIgnoreCase("regionname")) { + if (args.length < 3) { + sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionname [id] [name]")); + return true; + } + + String id = args[1]; + if (!API.isRegion(id)) { + String message = Message.getMessage("region.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + String name = args[2]; + name = name.replaceAll("_", " "); + + Region region = API.getRegion(id); + if(region.getName().equals(name)) + return true; + + region.setName(name); + + String message = Message.getMessage("region.changed.name"); + message = message.replace("{id}", id); + message = message.replace("{name}", name); + sender.sendMessage(Utils.color(message)); + return true; + } + + if (args[0].equalsIgnoreCase("regionlore")) { + if (args.length < 4) { + sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionlore[id] [index] [lore]")); + return true; + } + + String id = args[1]; + if (!API.isRegion(id)) { + String message = Message.getMessage("region.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + String string = args[2]; + if(!isInteger(string)) { + sender.sendMessage(Message.getMessage("nonumber").replace("{number}", string)); + return true; + } + + int i = Integer.parseInt(string); + + String lore = args[3]; + lore = lore.replaceAll("_", " "); + + Region region = API.getRegion(id); + + if(region.getLore().size() > i && region.getLore().get(i).equals(lore)) + return true; + + region.setLore(i, lore); + + String message = Message.getMessage("region.changed.lore"); + message = message.replace("{id}", id); + message = message.replace("{index}", "" + i); + message = message.replace("{lore}", lore); + sender.sendMessage(Utils.color(message)); + return true; + } + + if (args[0].equalsIgnoreCase("setlocation")) { + if (args.length < 2 ) { + sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " setlocation [id]")); + return true; + } + + String id = args[1]; + if(!API.isAttraction(id)) { + String message = Message.getMessage("attraction.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + if(!(sender instanceof Player)) { + sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); + return true; + } + + Attraction attraction = API.getAttraction(id); + attraction.setLocation(((Player) sender).getLocation().clone()); + sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName()))); + return true; + } + + if (args[0].equalsIgnoreCase("attraction")) { + if (args.length < 3 ) { + sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " attraction [id] [status]")); + return true; + } + + String id = args[1]; + if (!API.isAttraction(id)) { + String message = Message.getMessage("attraction.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + Status status = Status.getStatus(args[2]); + if (status == null) { + String message = Message.getMessage("status.no"); + message = message.replace("{status}", args[2]); + sender.sendMessage(Utils.color(message)); + return true; + } + + Attraction attraction = API.getAttraction(id); + if(!attraction.getType().containsStatus(status)) { + String message = Message.getMessage("attraction.nostatus"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", status.toString()); + sender.sendMessage(Utils.color(message)); + return true; + } + + if(attraction.getStatus() == status) + return true; + + Player player = (sender instanceof Player) ? (Player) sender : null; + + attraction.setStatus(status, player); + return true; + } + + if (args[0].equalsIgnoreCase("ridecount")) { + if (args.length < 3) { + sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " ridecount [id] [player]")); + return true; + } + + String id = args[1]; + if (!API.isAttraction(id)) { + String message = Message.getMessage("attraction.no"); + message = message.replace("{id}", id); + sender.sendMessage(Utils.color(message)); + return true; + } + + Attraction attraction = API.getAttraction(id); + String string = args[2]; + if(Bukkit.getPlayerExact(string) == null) { + String message = Message.getMessage("noplayer"); + message = message.replace("{name}", string); + sender.sendMessage(Utils.color(message)); + return true; + } + + Player player = Bukkit.getPlayerExact(string); + + ThemeParkPlugin.getInstance().getDatabaseHandler().addCount(player.getUniqueId(), attraction); + //TODO MESSAGE + return true; + } + + return false; + } + + private boolean isInteger(String s) { + int radix = 10; + Scanner sc = new Scanner(s.trim()); + if(!sc.hasNextInt(radix)) return false; + sc.nextInt(radix); + return !sc.hasNext(); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java b/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java new file mode 100644 index 0000000..2fa00b5 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java @@ -0,0 +1,87 @@ +package me.paradoxpixel.themepark.config; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import java.io.File; + +public class YamlConfig { + + private String name; + private File file; + private FileConfiguration config; + private Plugin plugin; + + public YamlConfig(String name, Plugin plugin) { + this.name = name.endsWith(".yml") ? name : name + ".yml"; + this.plugin = plugin; + + load(); + } + + public void load() { + if(!plugin.getDataFolder().exists()) + plugin.getDataFolder().mkdir(); + + file = new File(plugin.getDataFolder(), name); + if(!file.exists()) { + if(plugin.getResource(name) == null) { + try { + if(!file.createNewFile()) + System.out.print("Couldn't create config file: " + name); + } catch(Exception e) { + e.printStackTrace(); + return; + } + } else { + plugin.saveResource(name, true); + } + } + + config = YamlConfiguration.loadConfiguration(file); + } + + public FileConfiguration getConfig() { + return config; + } + + public void reload() { + if(file == null) { + load(); + return; + } + + config = YamlConfiguration.loadConfiguration(file); + } + + public void save() { + try { + config.save(file); + } catch(Exception e) { + e.printStackTrace(); + } + } + + public YamlConfig copy(String name) { + name = name.endsWith(".yml") ? name : name + ".yml"; + + File file = new File(plugin.getDataFolder(), name); + try { + config.save(file); + } catch(Exception e) { + e.printStackTrace(); + return null; + } + + return new YamlConfig(name, plugin); + } + + public void delete() { + try { + if(!file.delete()) + System.out.print("Couldn't delete config file: " + name); + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/me/paradoxpixel/themepark/database/Database.java b/src/main/java/me/paradoxpixel/themepark/database/Database.java new file mode 100644 index 0000000..1ab6dc9 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/database/Database.java @@ -0,0 +1,187 @@ +package me.paradoxpixel.themepark.database; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.config.YamlConfig; +import org.bukkit.Bukkit; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Map; + +public class Database { + + public Database(YamlConfig config) { + if(config == null) { + enabled = false; + return; + } + + enabled = config.getConfig().getBoolean("mysql.enabled"); + host = config.getConfig().getString("mysql.host"); + port = config.getConfig().getInt("mysql.port"); + database = config.getConfig().getString("mysql.database"); + user = config.getConfig().getString("mysql.user"); + password = config.getConfig().getString("mysql.password"); + } + + private boolean enabled; + private String host; + private int port; + private String database; + private String user; + private String password; + + private Connection connection; + private int TaskID; + + public boolean isEnabled() { + return enabled; + } + + public void connect() { + try { + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password); + + startPool(); + } catch(Exception e) { + enabled = false; + e.printStackTrace(); + } + } + + public void disconnect() { + if(connection == null) + return; + + try { + connection.close(); + connection = null; + } catch(Exception e) { + e.printStackTrace(); + } + } + + private boolean connected() { + if(connection == null) + return false; + + try { + return !connection.isClosed(); + } catch(Exception e) { + e.printStackTrace(); + } + + return false; + } + + private void startPool() { + TaskID = Bukkit.getScheduler().runTaskLater(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + disconnect(); + TaskID = 0; + } + }, 1200L).getTaskId(); + } + + private void stopPool() { + if(TaskID == 0) + return; + + Bukkit.getScheduler().cancelTask(TaskID); + TaskID = 0; + } + + public boolean execute(String query, HashMap objects) { + if(query == null || query.isEmpty()) + return false; + + if(!enabled) + return false; + + if(!connected()) + connect(); + + stopPool(); + try { + PreparedStatement statement = connection.prepareStatement(query); + if(objects != null) + for(Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + boolean b = statement.execute(); + statement.close(); + startPool(); + + return b; + } catch(Exception e) { + e.printStackTrace(); + } + + startPool(); + return false; + } + + public int executeUpdate(String query, HashMap objects) { + if(query == null || query.isEmpty()) + return 0; + + if(!enabled) + return 0; + + if(!connected()) + connect(); + + stopPool(); + try { + PreparedStatement statement = connection.prepareStatement(query); + for(Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + int i = statement.executeUpdate(); + statement.close(); + startPool(); + + return i; + } catch(Exception e) { + e.printStackTrace(); + } + + startPool(); + return 0; + } + + public ResultSet executeQuery(String query, HashMap objects) { + if(query == null || query.isEmpty()) + return null; + + + if(!enabled) + return null; + + if(!connected()) + connect(); + + stopPool(); + try { + PreparedStatement statement = connection.prepareStatement(query); + for(Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + ResultSet result = statement.executeQuery(); + statement.close(); + startPool(); + + return result; + } catch(Exception e) { + e.printStackTrace(); + } + + startPool(); + return null; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java new file mode 100644 index 0000000..b6a9f8f --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java @@ -0,0 +1,117 @@ +package me.paradoxpixel.themepark.database; + +import me.paradoxpixel.themepark.api.API; +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.status.StatusManager; +import me.paradoxpixel.themepark.config.YamlConfig; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.UUID; + +public class DatabaseHandler { + + private Database database; + + public DatabaseHandler(YamlConfig config) { + database = new Database(config); + load(); + } + + private void load() { + database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); + database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); + database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null); + database.execute("CREATE TABLE IF NOT EXISTS ridecount (uuid VARCHAR(256) NOT NULL, attractionId VARCHAR(256) NOT NULL, date VARCHAR(256), count INT(11) NOT NULL)", null); + + database.execute("TRUNCATE TABLE attraction", null); + database.execute("TRUNCATE TABLE region", null); + database.execute("TRUNCATE TABLE status", null); + + for(Attraction attraction : API.getAttractions().values()) + addAttraction(attraction); + + for(Region region : API.getRegions().values()) + addRegion(region); + + for(Status status : Status.values()) { + HashMap objects = new HashMap<>(); + objects.put(1, status.toString()); + objects.put(2, StatusManager.getName(status)); + database.execute("INSERT INTO status (statusId,statusName) VALUES(?,?)", objects); + } + } + + public void addAttraction(Attraction attraction) { + HashMap objects = new HashMap<>(); + objects.put(1, attraction.getId()); + objects.put(2, attraction.getName()); + objects.put(3, attraction.getRegion_id()); + objects.put(4, attraction.getType().toString()); + objects.put(5, attraction.getStatus().toString()); + + database.execute("INSERT IGNORE INTO attraction(id, name, region_id, type, status) VALUES (?,?,?,?,?)", objects); + } + + public void updateAttraction(Attraction attraction) { + HashMap objects = new HashMap<>(); + objects.put(1, attraction.getStatus().toString()); + objects.put(2, attraction.getId()); + + database.execute("UPDATE attraction SET status=? WHERE id=?", objects); + } + + public void removeAttraction(Attraction attraction) { + HashMap objects = new HashMap<>(); + objects.put(1, attraction.getId()); + + database.execute("DELETE FROM attraction WHERE id=?", objects); + database.execute("DELETE FROM ridecount WHERE attractionId=?", objects); + } + + public void addRegion(Region region) { + HashMap objects = new HashMap<>(); + objects.put(1, region.getId()); + objects.put(2, region.getName()); + + database.execute("INSERT IGNORE INTO region(id, name) VALUES (?,?)", objects); + } + + public void updateRegion(Region region) { + HashMap objects = new HashMap<>(); + objects.put(1, region.getName()); + objects.put(2, region.getId()); + + database.execute("UPDATE region SET name=? WHERE id=?", objects); + } + + public void removeRegion(Region region) { + HashMap objects = new HashMap<>(); + objects.put(1, region.getId()); + + database.execute("DELETE FROM region WHERE id=?", objects); + } + + public void addCount(UUID uuid, Attraction attraction) { + String pattern = "dd-MM-yyyy"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String date = simpleDateFormat.format(new Date()); + + HashMap objects = new HashMap<>(); + objects.put(1, uuid.toString()); + objects.put(2, attraction.getId()); + objects.put(3, date); + + if(database.executeUpdate("UPDATE ridecount SET count=count+1 WHERE uuid=? AND attractionId=? AND date=?", objects) < 1) { + database.execute("INSERT INTO ridecount(uuid,attractionId,date,count) VALUES (?,?,?,1)", objects); + } + } + + public void disconnect() { + database.disconnect(); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUI.java b/src/main/java/me/paradoxpixel/themepark/gui/GUI.java new file mode 100644 index 0000000..6a1d572 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUI.java @@ -0,0 +1,120 @@ +package me.paradoxpixel.themepark.gui; + +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class GUI extends GUIHolder { + + private String title; + private int size; + private Inventory inventory; + private HashMap items = new HashMap<>(); + + public GUI(String title, int size) { + if(size > 54) + size = 54; + + this.title = title; + this.size = Utils.toSize(size, 9); + inventory = Bukkit.createInventory(this, this.size, Utils.color(title)); + } + + private void update() { + ArrayList toRemove = new ArrayList<>(); + for(Map.Entry entry : items.entrySet()) { + if(entry.getKey() >= getSize()) { + toRemove.add(entry.getKey()); + continue; + } + + inventory.setItem(entry.getKey(), entry.getValue().getItem()); + } + + for(int i : toRemove) + items.remove(i); + } + + public void setSize(int size) { + if(size > 54) + size = 54; + + this.size = Utils.toSize(size, 9); + inventory = Bukkit.createInventory(this, this.size, Utils.color(title)); + update(); + } + + public int getSize() { + return size; + } + + public void clear() { + inventory = Bukkit.createInventory(this, Utils.toSize(size, 9), Utils.color(title)); + items.clear(); + } + + public void addItems(HashMap items) { + for(Map.Entry entry : items.entrySet()) + addItem(entry.getKey(), entry.getValue()); + } + + public void addItem(int slot, GUIItem item) { + if(slot >= getSize() || slot < 0) + return; + + items.put(slot, item); + inventory.setItem(slot, item.getItem()); + } + + public void removeItem(int slot) { + items.remove(slot); + } + + public void switchSlot(int from, int to) { + if(!items.containsKey(from)) + return; + + GUIItem item = items.get(from); + items.put(to, item); + items.remove(from); + } + + public boolean hasItem(int slot) { + return items.containsKey(slot); + } + + @Override + public boolean execute(Player player, int slot, ClickType type) { + if(player == null || slot >= getSize() || slot < 0 || type == null) + return false; + + if(!items.containsKey(slot)) + return false; + + GUIItem item = items.get(slot); + if(type == ClickType.RIGHT) { + if(item.getActionRight() != null) + item.getActionRight().click(player); + + return item.hasCancelRight(); + } else { + if(item.getActionLeft() != null) + item.getActionLeft().click(player); + + return item.hasCancelLeft(); + } + } + + @Override + public Inventory getInventory() { + return inventory; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java new file mode 100644 index 0000000..539ef03 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java @@ -0,0 +1,9 @@ +package me.paradoxpixel.themepark.gui; + +import org.bukkit.entity.Player; + +public abstract class GUIAction { + + public abstract void click(Player player); + +} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java new file mode 100644 index 0000000..4477573 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java @@ -0,0 +1,11 @@ +package me.paradoxpixel.themepark.gui; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.InventoryHolder; + +public abstract class GUIHolder implements InventoryHolder { + + public abstract boolean execute(Player player, int slot, ClickType type); + +} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java new file mode 100644 index 0000000..62a8382 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java @@ -0,0 +1,45 @@ +package me.paradoxpixel.themepark.gui; + +import org.bukkit.inventory.ItemStack; + +public class GUIItem { + + private ItemStack item; + private GUIAction aleft, aright; + private boolean cleft, cright; + + public GUIItem(ItemStack item, GUIAction action, boolean cancel) { + this.item = item; + aleft = aright = action; + cleft = cright = cancel; + } + + public GUIItem(ItemStack item, GUIAction aleft, GUIAction aright, boolean cleft, boolean cright) { + this.item = item; + this.aleft = aleft; + this.aright = aright; + this.cleft = cleft; + this.cright = cright; + } + + public ItemStack getItem() { + return item; + } + + public boolean hasCancelLeft() { + return cleft; + } + + public boolean hasCancelRight() { + return cright; + } + + public GUIAction getActionLeft() { + return aleft; + } + + public GUIAction getActionRight() { + return aright; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java new file mode 100644 index 0000000..6c4a3d8 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java @@ -0,0 +1,29 @@ +package me.paradoxpixel.themepark.gui; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; + +public class GUIListener implements Listener { + + @EventHandler + public void onClick(InventoryClickEvent e) { + if(e.getClickedInventory() == null) + return; + + Inventory inventory = e.getClickedInventory(); + if(!(inventory.getHolder() instanceof GUIHolder)) + return; + + Player player = (Player) e.getWhoClicked(); + int slot = e.getRawSlot(); + ClickType type = e.getClick(); + + GUI gui = (GUI) inventory.getHolder(); + e.setCancelled(gui.execute(player, slot, type)); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java new file mode 100644 index 0000000..fc37a15 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java @@ -0,0 +1,115 @@ +package me.paradoxpixel.themepark.listener; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.component.Status; +import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent; +import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent; +import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; +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.sign.SignManager; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.utils.Message; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class ChangeListener implements Listener { + + @EventHandler + public void onChange(StatusChangeEvent e) { + AttractionMenu.reload(); + SignManager.update(e.getAttraction()); + + Attraction attraction = e.getAttraction(); + Status status = e.getStatusAfter(); + String message = Message.getMessage("attraction.changed.status." + status.toString()); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", StatusManager.getName(status)); + Bukkit.broadcastMessage(Utils.color(message)); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction()); + } + }); + } + + @EventHandler + public void onChange(AddAttractionEvent e) { + AttractionMenu.reload(); + SignManager.loadSigns(e.getAttraction()); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction()); + } + }); + } + + @EventHandler + public void onChange(RemoveAttractionEvent e) { + AttractionMenu.reload(); + SignManager.remove(e.getAttraction()); + + YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); + config.getConfig().set("attraction." + e.getAttraction().getId(), null); + config.save(); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction()); + } + }); + } + + @EventHandler + public void onChange(AddRegionEvent e) { + AttractionMenu.reload(); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion()); + } + }); + } + + @EventHandler + public void onChange(ChangeRegionEvent e) { + AttractionMenu.reload(); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion()); + } + }); + } + + @EventHandler + public void onChange(RemoveRegionEvent e) { + AttractionMenu.reload(); + + YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); + config.getConfig().set("region." + e.getRegion().getId(), null); + config.save(); + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { + @Override + public void run() { + ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion()); + } + }); + } + + +} diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java new file mode 100644 index 0000000..27d7551 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java @@ -0,0 +1,45 @@ +package me.paradoxpixel.themepark.listener; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.attraction.AttractionMenu; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Material; +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.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class ClickListener implements Listener { + + private YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + Material material = Material.getMaterial(config.getConfig().getString("item.material")); + String name = Utils.color(config.getConfig().getString("item.display-name")); + if(e.getItem() == null) + return; + + ItemStack item = e.getItem(); + if(item.getType() != material) + return; + + if(!item.hasItemMeta()) + return; + + if(!item.getItemMeta().getDisplayName().equals(name)) + return; + + if(e.getAction() == Action.LEFT_CLICK_AIR || + e.getAction() == Action.LEFT_CLICK_BLOCK) + return; + + e.setCancelled(true); + Player player = e.getPlayer(); + AttractionMenu.openMenu(player); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java b/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java new file mode 100644 index 0000000..8d07c0e --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java @@ -0,0 +1,68 @@ +package me.paradoxpixel.themepark.listener; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.database.DatabaseHandler; +import me.paradoxpixel.themepark.utils.ItemBuilder; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Material; +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.PlayerJoinEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class PlayerListener implements Listener { + + private YamlConfig config = ThemeParkPlugin.getInstance().getData(); + private YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); + + @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; + + 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 onTeleport(PlayerTeleportEvent e) { + Player player = e.getPlayer(); + if(e.getCause() != PlayerTeleportEvent.TeleportCause.PLUGIN) + return; + + if(!player.isInsideVehicle()) + return; + + if(player.getVehicle() == null) + return; + + if(!(player.getVehicle() instanceof Minecart)) + return; + + e.setCancelled(true); + player.sendMessage(Utils.color("&6ThemePark&f: &4You can't teleport while in a minecart")); + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/listener/SignListener.java b/src/main/java/me/paradoxpixel/themepark/listener/SignListener.java new file mode 100644 index 0000000..c2b46dc --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/listener/SignListener.java @@ -0,0 +1,64 @@ +package me.paradoxpixel.themepark.listener; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.api.API; +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.attraction.sign.SignManager; +import me.paradoxpixel.themepark.attraction.sign.StatusSign; +import me.paradoxpixel.themepark.attraction.status.StatusManager; +import me.paradoxpixel.themepark.config.YamlConfig; +import me.paradoxpixel.themepark.utils.Utils; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.SignChangeEvent; + +public class SignListener implements Listener { + + private YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); + private String name = config.getConfig().getString("sign.name"); + private String title = config.getConfig().getString("sign.title"); + + @EventHandler + public void onPlace(SignChangeEvent e) { + if(!e.getLine(0).equalsIgnoreCase(name)) + return; + + String id = e.getLine(1); + if(id == null || id.isEmpty() || !API.isAttraction(id)) + return; + + Attraction attraction = API.getAttraction(id); + e.setLine(0, Utils.color(title)); + e.setLine(1, Utils.color(attraction.getName())); + e.setLine(2, Utils.color(StatusManager.getName(attraction.getStatus()))); + + Location location = e.getBlock().getLocation(); + StatusSign statusSign = new StatusSign(attraction, location); + SignManager.addSign(statusSign); + } + + @EventHandler + public void onBreak(BlockBreakEvent e) { + if(e.getBlock() == null) + return; + + Block block = e.getBlock(); + if(!(block.getState() instanceof Sign)) + return; + + Sign sign = (Sign) block.getState(); + if(!sign.getLine(0).equals(Utils.color(title))) + return; + + Attraction attraction = API.getAttractionFromName(sign.getLine(1)); + Location location = e.getBlock().getLocation(); + + StatusSign s = new StatusSign(attraction, location); + SignManager.removeSign(s); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java b/src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java new file mode 100644 index 0000000..d9d8009 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java @@ -0,0 +1,111 @@ +package me.paradoxpixel.themepark.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class ItemBuilder { + + private ItemStack item; + + public ItemBuilder(ItemStack item) { + this.item = item; + } + + public ItemBuilder(Material material) { + item = new ItemStack(material, 1); + } + + public ItemBuilder(Material material, int amount) { + item = new ItemStack(material, amount); + } + + public ItemBuilder(Material material, int amount, short data) { + item = new ItemStack(material, amount, data); + } + + public ItemStack getItem() { + return item; + } + + public ItemBuilder setDurability(short durability) { + item.setDurability(durability); + return this; + } + + public ItemBuilder setName(String name) { + if(name == null) + return this; + + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(Utils.color(name)); + this.item.setItemMeta(meta); + return this; + } + + public ItemBuilder setLore(List lore) { + if(lore == null) + return this; + + ItemMeta meta = item.getItemMeta(); + for(String string : lore) + lore.set(lore.indexOf(string), Utils.color(string)); + + meta.setLore(lore); + item.setItemMeta(meta); + return this; + } + + public ItemBuilder setLore(String lore) { + List list = new ArrayList<>(); + list.add(lore); + setLore(list); + return this; + } + + public ItemBuilder addLore(String lore) { + List list = item.getItemMeta().getLore(); + list.add(lore); + setLore(list); + return this; + } + + public ItemBuilder setEnchantment(HashMap enchantments) { + ItemMeta meta = item.getItemMeta(); + if(!meta.getEnchants().isEmpty()) + meta.getEnchants().clear(); + + for(Map.Entry entry : enchantments.entrySet()) + meta.addEnchant(entry.getKey(), entry.getValue(), true); + + item.setItemMeta(meta); + return this; + } + + public ItemBuilder setEnchantment(Enchantment enchantment, int i) { + ItemMeta meta = item.getItemMeta(); + if (!meta.getEnchants().isEmpty()) + meta.getEnchants().clear(); + + meta.addEnchant(enchantment, i, true); + item.setItemMeta(meta); + return this; + } + + public ItemBuilder addEnchantment(Enchantment enchantment, int i) { + ItemMeta meta = item.getItemMeta(); + meta.addEnchant(enchantment, i, true); + item.setItemMeta(meta); + return this; + } + + public ItemBuilder clone() { + return new ItemBuilder(item); + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java b/src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java new file mode 100644 index 0000000..b7b391e --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java @@ -0,0 +1,50 @@ +package me.paradoxpixel.themepark.utils; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +public class LocationUtils { + + public static String toString(Location location) { + if(location == null) + return null; + + World world = location.getWorld(); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + + String string = world.getName() + ":" + x + ":" + y + ":" + z; + if(location.getYaw() != 0 || location.getPitch() != 0) + string += ":" + location.getYaw() + ":" + location.getPitch(); + + return string; + } + + public static Location toLocation(String string) { + if(string == null) + return null; + + String[] args = string.split(":"); + if(args.length < 4) + return null; + + World world = Bukkit.getWorld(args[0]); + double x = Double.parseDouble(args[1]); + double y = Double.parseDouble(args[2]); + double z = Double.parseDouble(args[3]); + + Location location = new Location(world, x, y, z); + if(args.length < 6) + return location; + + float yaw = Float.parseFloat(args[4]); + float pitch = Float.parseFloat(args[5]); + location.setYaw(yaw); + location.setPitch(pitch); + + return location; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/Message.java b/src/main/java/me/paradoxpixel/themepark/utils/Message.java new file mode 100644 index 0000000..204ada2 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/utils/Message.java @@ -0,0 +1,25 @@ +package me.paradoxpixel.themepark.utils; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +import me.paradoxpixel.themepark.config.YamlConfig; + +public class Message { + + private static YamlConfig config = ThemeParkPlugin.getInstance().getMessage(); + + public static boolean isMessage(String string) { + return config.getConfig().contains(string); + } + + public static String getMessage(String string) { + if(!isMessage(string)) + return ""; + + String message = config.getConfig().getString(string); + if(isMessage("prefix")) + message = message.replace("{prefix}", config.getConfig().getString("prefix")); + + return message; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/Utils.java b/src/main/java/me/paradoxpixel/themepark/utils/Utils.java new file mode 100644 index 0000000..1116260 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/utils/Utils.java @@ -0,0 +1,15 @@ +package me.paradoxpixel.themepark.utils; + +import org.bukkit.ChatColor; + +public class Utils { + + public static String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + + public static int toSize(int i, int size) { + return i % size == 0 ? i : i + (size - (i % size)); + } + +} diff --git a/src/main/resources/attraction.yml b/src/main/resources/attraction.yml new file mode 100644 index 0000000..1eb28e1 --- /dev/null +++ b/src/main/resources/attraction.yml @@ -0,0 +1,40 @@ +region: + global: + name: "&5Global" + lore: + - "&5Global Locations" + fantasy: + name: "&aFantasy" + lore: + - "&aFantasy Themed rides" + multiple: + name: "&fMultiple" + lore: + - "&fYou can have" + - "&fMultiple lines" + - "&fWith Lore" + +attraction: + ride1: + name: "&aRide #1" + region_id: "fantasy" + type: RIDE + status: CLOSED + location: "world:0:0:0" + show1: + name: "&aFirst Show" + region_id: "fantasy" + type: SHOW + status: INACTIVE + location: "world:0:0:0" + global1: + name: "&aFirst Global" + region_id: "global" + type: GLOBAL + location: "world:0:0:0" + random: + name: "&fRandom" + type: RIDE + status: CLOSED + region_id: multiple + location: "world:0:0:0" \ No newline at end of file diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml new file mode 100644 index 0000000..2aa923e --- /dev/null +++ b/src/main/resources/message.yml @@ -0,0 +1,42 @@ +prefix: "&6Themepark&f:" + +onlyplayers: "{prefix} &4Only players can use this command" +nopermission: "{prefix} &4You don't have permission to use this command" +noplayer: "{prefix} &4No player found with name: {name}" +nonumber: "&6Themepark&f: &4{number} &4is not a valid number" + +reloaded: "{prefix} &aThe plugin has been reloaded" + +menu: + item: + enabled: "&aENABLED" + disabled: "&4DISABLED" + toggle: "{prefix} &aMenu item has been {status}" + +region: + no: "{prefix} &4There is no region with ID: {id}" + changed: + name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}" + lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}" + +status: + no: "{prefix} &4There is no status named: {status}" + +attraction: + notfound: "&4No attractions found" + list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}" + no: "{prefix} &4There is no attraction with ID: {id}" + nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}" + changed: + status: + CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction" + OPEN: "{prefix} &fAttraction: {name} &fhas been &aOpened" + CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed" + MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance" + MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction" + ACTIVE: "{prefix} &fShow: {name} &fis now &aActive" + INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active" + location: "&6ThemePark&f: &aChanged locatation of attraction: {name} &ato your current location" + teleport: + status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}" + success: "{prefix} &ayou have been teleported to the attraction: {name}" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..2a30d0d --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: ThemePark +version: 1.1 +main: me.paradoxpixel.themepark.ThemeParkPlugin +author: ParadoxPixel +commands: + status: \ No newline at end of file diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml new file mode 100644 index 0000000..ac29cbc --- /dev/null +++ b/src/main/resources/settings.yml @@ -0,0 +1,72 @@ +command: 'themepark' + +sign: + name: "[ThemePark]" + title: "&f[&6ThemePark&f]" + +menu: + title: "&6StatusMenu" + +inventory: + clear: true + +item: + material: NETHER_STAR + display-name: 'Themepark' + slot: 4 + +mysql: + enabled: false + host: 'localhost' + port: 3306 + database: 'database' + user: 'username' + password: 'password' + +CONSTRUCTION: + name: "&7Under Construction" + material: STAINED_CLAY + data: 1 + teleport: false + +OPEN: + name: "&aOpen" + material: STAINED_CLAY + data: 5 + teleport: true + +CLOSED: + name: "&4Closed" + material: STAINED_CLAY + data: 14 + teleport: true + +MAINTENANCE: + name: "&6Maintenance" + material: STAINED_CLAY + data: 4 + teleport: true + +MALFUNCTION: + name: "&5Malfunction" + material: STAINED_CLAY + data: 10 + teleport: true + +ACTIVE: + name: "&aActive" + material: STAINED_CLAY + data: 5 + teleport: true + +INACTIVE: + name: "&4In Active" + material: STAINED_CLAY + data: 14 + teleport: true + +GLOBAL: + name: "&bGlobal" + material: STAINED_CLAY + data: 11 + teleport: true \ No newline at end of file From 7c7fbbdfa633ae792fe26e727a716c236b833669 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 15 Jan 2019 18:31:26 +0100 Subject: [PATCH 02/25] Removed Ridecount --- .idea/vcs.xml | 6 ++++ .../themepark/command/ThemeParkCommand.java | 31 ------------------- .../themepark/database/DatabaseHandler.java | 16 ---------- 3 files changed, 6 insertions(+), 47 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 628004d..4b17939 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -47,7 +47,6 @@ public class ThemeParkCommand extends BukkitCommand { sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]")); sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]")); sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]")); - sender.sendMessage(Utils.color("&f/" + name + " ridecount [id] [player]")); } return true; @@ -329,36 +328,6 @@ public class ThemeParkCommand extends BukkitCommand { return true; } - if (args[0].equalsIgnoreCase("ridecount")) { - if (args.length < 3) { - sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " ridecount [id] [player]")); - return true; - } - - String id = args[1]; - if (!API.isAttraction(id)) { - String message = Message.getMessage("attraction.no"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - Attraction attraction = API.getAttraction(id); - String string = args[2]; - if(Bukkit.getPlayerExact(string) == null) { - String message = Message.getMessage("noplayer"); - message = message.replace("{name}", string); - sender.sendMessage(Utils.color(message)); - return true; - } - - Player player = Bukkit.getPlayerExact(string); - - ThemeParkPlugin.getInstance().getDatabaseHandler().addCount(player.getUniqueId(), attraction); - //TODO MESSAGE - return true; - } - return false; } diff --git a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java index b6a9f8f..708e5cf 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java +++ b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java @@ -25,7 +25,6 @@ public class DatabaseHandler { database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null); - database.execute("CREATE TABLE IF NOT EXISTS ridecount (uuid VARCHAR(256) NOT NULL, attractionId VARCHAR(256) NOT NULL, date VARCHAR(256), count INT(11) NOT NULL)", null); database.execute("TRUNCATE TABLE attraction", null); database.execute("TRUNCATE TABLE region", null); @@ -95,21 +94,6 @@ public class DatabaseHandler { database.execute("DELETE FROM region WHERE id=?", objects); } - public void addCount(UUID uuid, Attraction attraction) { - String pattern = "dd-MM-yyyy"; - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - String date = simpleDateFormat.format(new Date()); - - HashMap objects = new HashMap<>(); - objects.put(1, uuid.toString()); - objects.put(2, attraction.getId()); - objects.put(3, date); - - if(database.executeUpdate("UPDATE ridecount SET count=count+1 WHERE uuid=? AND attractionId=? AND date=?", objects) < 1) { - database.execute("INSERT INTO ridecount(uuid,attractionId,date,count) VALUES (?,?,?,1)", objects); - } - } - public void disconnect() { database.disconnect(); } From 35984bc18ca4340a2cee9aa3ce7f37ffbf6106a0 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 15 Jan 2019 19:39:29 +0100 Subject: [PATCH 03/25] Change to database class --- .../me/paradoxpixel/themepark/database/Database.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/me/paradoxpixel/themepark/database/Database.java b/src/main/java/me/paradoxpixel/themepark/database/Database.java index 1ab6dc9..9bcb549 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/Database.java +++ b/src/main/java/me/paradoxpixel/themepark/database/Database.java @@ -105,6 +105,9 @@ public class Database { if(!connected()) connect(); + if(!connected()) + return false; + stopPool(); try { PreparedStatement statement = connection.prepareStatement(query); @@ -135,6 +138,9 @@ public class Database { if(!connected()) connect(); + if(!connected()) + return 0; + stopPool(); try { PreparedStatement statement = connection.prepareStatement(query); @@ -165,6 +171,9 @@ public class Database { if(!connected()) connect(); + if(!connected()) + return null; + stopPool(); try { PreparedStatement statement = connection.prepareStatement(query); From a4425949e61d25825e81c02af3f24b60bae259ad Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 21:50:39 +0100 Subject: [PATCH 04/25] Bug fix --- src/main/java/me/paradoxpixel/themepark/api/API.java | 5 +++++ .../themepark/attraction/AttractionMenu.java | 7 ++----- .../themepark/command/ThemeParkCommand.java | 11 ++++------- .../themepark/database/DatabaseHandler.java | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java index 900fda3..300367d 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -68,6 +68,11 @@ public class API { regions.remove(id.toLowerCase()); } + public static void clearRegions() { + regions.clear(); + attractions.clear(); + } + public static void addAttraction(Attraction attraction) { if(!isRegion(attraction.getRegion_id())) return; diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index e3fae0c..1f4180d 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -26,10 +26,11 @@ public class AttractionMenu { private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); private static GUI gui; - private static HashMap index = new HashMap<>(); + private static HashMap index; public static void load() { gui = new GUI(settings.getConfig().getString("menu.title"), 9); + index = new HashMap<>(); loadData(); loadItems(); } @@ -106,10 +107,6 @@ public class AttractionMenu { Attraction attraction = new Attraction(id, name, region_id, location, type, status); API.addAttraction(attraction); } - - for(Region region : API.getRegions().values()) - if(region.getAttractions().isEmpty()) - API.removeRegion(region.getId()); } private static void loadItems() { diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 4b17939..9ad8b4a 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -180,16 +180,13 @@ public class ThemeParkCommand extends BukkitCommand { ThemeParkPlugin.getInstance().getSigns().reload(); ThemeParkPlugin.getInstance().getSettings().reload(); ThemeParkPlugin.getInstance().getMessage().reload(); - - API.getRegions().clear(); - API.getAttractions().clear(); + API.clearRegions(); StatusManager.load(); AttractionMenu.load(); - for(Region region : API.getRegions().values()) - if(region.getAttractions().isEmpty()) - API.removeRegion(region.getId()); - + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(),() -> { + ThemeParkPlugin.getInstance().getDatabaseHandler().load(); + }); sender.sendMessage(Utils.color(Message.getMessage("reloaded"))); } diff --git a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java index 708e5cf..6967e1b 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java +++ b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java @@ -21,7 +21,7 @@ public class DatabaseHandler { load(); } - private void load() { + public void load() { database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null); From 7a136e28d1669ba3e9123e0092b21f727afeb21f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 23:22:15 +0100 Subject: [PATCH 05/25] Small Change optimizing future updates --- .../me/paradoxpixel/themepark/api/API.java | 5 -- .../themepark/api/attraction/Attraction.java | 21 +++++ .../event/region/ChangeAttractionEvent.java | 79 +++++++++++++++++++ .../themepark/attraction/AttractionMenu.java | 33 +++++++- .../themepark/command/ThemeParkCommand.java | 1 - 5 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java index 300367d..900fda3 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -68,11 +68,6 @@ public class API { regions.remove(id.toLowerCase()); } - public static void clearRegions() { - regions.clear(); - attractions.clear(); - } - public static void addAttraction(Attraction attraction) { if(!isRegion(attraction.getRegion_id())) return; diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java index d8d8ec6..b97f697 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -4,6 +4,7 @@ import me.paradoxpixel.themepark.api.attraction.component.Status; import me.paradoxpixel.themepark.api.attraction.component.Type; import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; +import me.paradoxpixel.themepark.api.event.region.ChangeAttractionEvent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -32,22 +33,42 @@ public class Attraction { return name; } + public void setName(String name) { + ChangeAttractionEvent event = new ChangeAttractionEvent(this, this.name, name, region_id, region_id, location, location, type, type); + this.name = name; + Bukkit.getPluginManager().callEvent(event); + } + public String getRegion_id() { return region_id; } + public void setRegion_id(String region_id) { + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, this.region_id, region_id, location, location, type, type); + this.region_id = region_id; + Bukkit.getPluginManager().callEvent(event); + } + public Location getLocation() { return location; } public void setLocation(Location location) { + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type); this.location = location; + Bukkit.getPluginManager().callEvent(event); } public Type getType() { return type; } + public void setType(Type type) { + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, location, location, this.type, type); + this.type = type; + Bukkit.getPluginManager().callEvent(event); + } + public Status getStatus() { return status; } diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java new file mode 100644 index 0000000..a4d767e --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java @@ -0,0 +1,79 @@ +package me.paradoxpixel.themepark.api.event.region; + +import me.paradoxpixel.themepark.api.attraction.Attraction; +import me.paradoxpixel.themepark.api.attraction.component.Type; +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ChangeAttractionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private Attraction attraction; + private String bname, aname, bregion_id, aregion_id; + private Location blocation, alocation; + private Type btype, atype; + + public ChangeAttractionEvent(Attraction attraction, + String bname, String aname, + String aregion_id, String bregion_id, + Location alocation, Location blocation, + Type btype, Type atype) { + this.attraction = attraction; + this.bname = bname; + this.aname = aname; + this.bregion_id = bregion_id; + this.aregion_id = aregion_id; + this.alocation = alocation; + this.blocation = blocation; + this.btype = btype; + this.atype = atype; + } + + public Attraction getAttraction() { + return attraction; + } + + public String getNameBefore() { + return bname; + } + + public String getNameAfter() { + return aname; + } + + public String getRegionIdBefore() { + return bregion_id; + } + + public String getRegionIdAfter() { + return aregion_id; + } + + public Location getLocationBefore() { + return blocation; + } + + public Location getLocationAfter() { + return alocation; + } + + public Type getTypeBefore() { + return btype; + } + + public Type getTypeAfter() { + return atype; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} + diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index 1f4180d..a0cc2cf 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -25,14 +25,17 @@ public class AttractionMenu { private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); private static GUI gui; + private static boolean loading = false; private static HashMap index; public static void load() { + loading = true; gui = new GUI(settings.getConfig().getString("menu.title"), 9); index = new HashMap<>(); loadData(); loadItems(); + loading = false; } public static void reload() { @@ -67,6 +70,7 @@ public class AttractionMenu { if(section.getKeys(false).isEmpty()) return; + HashMap regions = API.getRegions(); for(String id : section.getKeys(false)) { if(API.getRegions().size() >= 6) { config.getConfig().set("regions." + id, null); @@ -77,10 +81,20 @@ public class AttractionMenu { String name = config.getConfig().getString("region." + id + ".name"); List lore = config.getConfig().getStringList("region." + id + ".lore"); + regions.remove(id); + if(API.isRegion(id)) { + API.getRegion(id).setName(name); + API.getRegion(id).setLore(lore); + continue; + } + Region region = new Region(id, name, lore); API.addRegion(region); } + for(String string : regions.keySet()) + API.removeRegion(string); + if(!config.getConfig().contains("attraction")) return; @@ -91,6 +105,7 @@ public class AttractionMenu { if(section.getKeys(false).isEmpty()) return; + HashMap attractions = API.getAttractions(); for(String id : section.getKeys(false)) { String region_id = config.getConfig().getString("attraction." + id + ".region_id"); if(!API.isRegion(region_id)) @@ -104,12 +119,29 @@ public class AttractionMenu { Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); + attractions.remove(id); + if(API.isAttraction(id)) { + Attraction attraction = API.getAttraction(id); + attraction.setName(name); + attraction.setRegion_id(region_id); + attraction.setLocation(location); + attraction.setType(type); + attraction.setStatus(status, null); + continue; + } + Attraction attraction = new Attraction(id, name, region_id, location, type, status); API.addAttraction(attraction); } + + for(String string : attractions.keySet()) + API.removeAttraction(string); } private static void loadItems() { + if(loading) + return; + if(API.getRegions().values().size() == 0) return; @@ -147,7 +179,6 @@ public class AttractionMenu { } if(!b) { - API.getRegion(attraction.getRegion_id()).removeAttraction(attraction); API.removeAttraction(attraction.getId()); continue; } diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 9ad8b4a..bcfa800 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -180,7 +180,6 @@ public class ThemeParkCommand extends BukkitCommand { ThemeParkPlugin.getInstance().getSigns().reload(); ThemeParkPlugin.getInstance().getSettings().reload(); ThemeParkPlugin.getInstance().getMessage().reload(); - API.clearRegions(); StatusManager.load(); AttractionMenu.load(); From 317e33a542bfef8bed1e96ff48acf281db1f4a2f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 23:44:14 +0100 Subject: [PATCH 06/25] Small Change optimizing future updates --- .../themepark/action/TPUtils.java | 5 ++++- .../themepark/api/attraction/Attraction.java | 21 ++++++++++++++++++- .../api/attraction/component/Type.java | 4 ++-- .../themepark/attraction/AttractionMenu.java | 6 +++++- .../themepark/command/ThemeParkCommand.java | 1 + 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java b/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java index c91c062..58477e6 100644 --- a/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java +++ b/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java @@ -25,6 +25,9 @@ public class TPUtils extends GUIAction { if(attraction == null) return; + if(attraction.getLocation() == null) + return; + if(!StatusManager.canTeleport(attraction.getStatus())) { String message = Message.getMessage("attraction.teleport.status"); message = message.replace("{name}", attraction.getName()); @@ -33,11 +36,11 @@ public class TPUtils extends GUIAction { return; } - player.teleport(attraction.getLocation()); if(player.isInsideVehicle()) if(player.getVehicle() instanceof Minecart) return; + player.teleport(attraction.getLocation()); String message = Message.getMessage("attraction.teleport.success"); message = message.replace("{name}", attraction.getName()); player.sendMessage(Utils.color(message)); diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java index b97f697..9a37c57 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -5,6 +5,7 @@ import me.paradoxpixel.themepark.api.attraction.component.Type; import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; import me.paradoxpixel.themepark.api.event.region.ChangeAttractionEvent; +import me.paradoxpixel.themepark.utils.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -22,7 +23,7 @@ public class Attraction { this.region_id = region_id; this.location = location; this.type = type; - this.status = type.containsStatus(status) ? status : type.getDefefault(); + this.status = type.containsStatus(status) ? status : type.getDefault(); } public String getId() { @@ -34,6 +35,9 @@ public class Attraction { } public void setName(String name) { + if(this.name.equals(name)) + return; + ChangeAttractionEvent event = new ChangeAttractionEvent(this, this.name, name, region_id, region_id, location, location, type, type); this.name = name; Bukkit.getPluginManager().callEvent(event); @@ -44,6 +48,9 @@ public class Attraction { } public void setRegion_id(String region_id) { + if(this.region_id.equals(region_id)) + return; + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, this.region_id, region_id, location, location, type, type); this.region_id = region_id; Bukkit.getPluginManager().callEvent(event); @@ -54,6 +61,13 @@ public class Attraction { } public void setLocation(Location location) { + if(location == this.location) + return; + + if(LocationUtils.toString(location) != null && LocationUtils.toString(location) != null) + if(LocationUtils.toString(this.location).equals(LocationUtils.toString(location))) + return; + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type); this.location = location; Bukkit.getPluginManager().callEvent(event); @@ -67,6 +81,8 @@ public class Attraction { ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, location, location, this.type, type); this.type = type; Bukkit.getPluginManager().callEvent(event); + if(!type.containsStatus(status)) + setStatus(type.getDefault(), null); } public Status getStatus() { @@ -80,6 +96,9 @@ public class Attraction { if(!type.containsStatus(status)) return; + if(this.status == status) + return; + PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status); Bukkit.getPluginManager().callEvent(event); if(event.isCancelled()) diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java index 9339df6..d220036 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java @@ -3,7 +3,7 @@ package me.paradoxpixel.themepark.api.attraction.component; public enum Type { RIDE(true, Status.CLOSED, Status.CONSTRUCTION, Status.OPEN, Status.CLOSED, Status.MAINTENANCE, Status.MALFUNCTION), - SHOW(true, Status.CLOSED, Status.CONSTRUCTION, Status.ACTIVE, Status.INACTIVE), + SHOW(true, Status.INACTIVE, Status.CONSTRUCTION, Status.ACTIVE, Status.INACTIVE), GLOBAL(false, Status.GLOBAL); private boolean status; @@ -20,7 +20,7 @@ public enum Type { return status; } - public Status getDefefault() { + public Status getDefault() { return def; } diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index a0cc2cf..bcb7086 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -34,8 +34,8 @@ public class AttractionMenu { gui = new GUI(settings.getConfig().getString("menu.title"), 9); index = new HashMap<>(); loadData(); - loadItems(); loading = false; + loadItems(); } public static void reload() { @@ -127,6 +127,10 @@ public class AttractionMenu { attraction.setLocation(location); attraction.setType(type); attraction.setStatus(status, null); + if(!type.containsStatus(status)) { + config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); + config.save(); + } continue; } diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index bcfa800..195d1c0 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -64,6 +64,7 @@ public class ThemeParkCommand extends BukkitCommand { message = message.replace("{id}", attraction.getId()); message = message.replace("{name}", attraction.getName()); message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).getName()); + message = message.replace("{type}", attraction.getType().toString()); message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); sender.sendMessage(Utils.color(message)); } From 9530d7bc660cc858a3bf8624e6751bb1f1b18f7c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 23:47:40 +0100 Subject: [PATCH 07/25] Small Change --- .../me/paradoxpixel/themepark/api/attraction/Attraction.java | 2 +- .../api/event/{region => attraction}/ChangeAttractionEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/me/paradoxpixel/themepark/api/event/{region => attraction}/ChangeAttractionEvent.java (97%) diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java index 9a37c57..abb31a6 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -4,7 +4,7 @@ import me.paradoxpixel.themepark.api.attraction.component.Status; import me.paradoxpixel.themepark.api.attraction.component.Type; import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; -import me.paradoxpixel.themepark.api.event.region.ChangeAttractionEvent; +import me.paradoxpixel.themepark.api.event.attraction.ChangeAttractionEvent; import me.paradoxpixel.themepark.utils.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java similarity index 97% rename from src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java rename to src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java index a4d767e..92f4450 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeAttractionEvent.java +++ b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java @@ -1,4 +1,4 @@ -package me.paradoxpixel.themepark.api.event.region; +package me.paradoxpixel.themepark.api.event.attraction; import me.paradoxpixel.themepark.api.attraction.Attraction; import me.paradoxpixel.themepark.api.attraction.component.Type; From d9c80259c5920ec3fd2a215acd239dfe9ca8b3ef Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 23:49:29 +0100 Subject: [PATCH 08/25] Small Change --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../{utils => api}/LocationUtils.java | 2 +- .../themepark/api/attraction/Attraction.java | 2 +- .../themepark/attraction/AttractionMenu.java | 2 +- .../attraction/sign/SignManager.java | 2 +- 5 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 .idea/uiDesigner.xml rename src/main/java/me/paradoxpixel/themepark/{utils => api}/LocationUtils.java (96%) diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java similarity index 96% rename from src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java rename to src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java index b7b391e..3875e81 100644 --- a/src/main/java/me/paradoxpixel/themepark/utils/LocationUtils.java +++ b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java @@ -1,4 +1,4 @@ -package me.paradoxpixel.themepark.utils; +package me.paradoxpixel.themepark.api; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java index abb31a6..8fe6340 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -5,7 +5,7 @@ import me.paradoxpixel.themepark.api.attraction.component.Type; import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.ChangeAttractionEvent; -import me.paradoxpixel.themepark.utils.LocationUtils; +import me.paradoxpixel.themepark.api.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index bcb7086..2a82f4e 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -12,7 +12,7 @@ import me.paradoxpixel.themepark.config.YamlConfig; import me.paradoxpixel.themepark.gui.GUI; import me.paradoxpixel.themepark.gui.GUIItem; import me.paradoxpixel.themepark.utils.ItemBuilder; -import me.paradoxpixel.themepark.utils.LocationUtils; +import me.paradoxpixel.themepark.api.LocationUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java index 554e154..b2fd940 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java @@ -3,7 +3,7 @@ package me.paradoxpixel.themepark.attraction.sign; import me.paradoxpixel.themepark.ThemeParkPlugin; import me.paradoxpixel.themepark.api.attraction.Attraction; import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.utils.LocationUtils; +import me.paradoxpixel.themepark.api.LocationUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Sign; From f9100dd560e66c9ab3f30c8217bb1fa06bf7c4aa Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 17 Feb 2019 13:03:20 +0100 Subject: [PATCH 09/25] Bug Fix --- pom.xml | 2 +- .../me/paradoxpixel/themepark/api/API.java | 15 +++++++++ .../themepark/command/ThemeParkCommand.java | 31 +++++++++++++------ .../themepark/listener/ChangeListener.java | 18 +++++++++++ src/main/resources/message.yml | 4 +-- src/main/resources/plugin.yml | 2 +- 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 05431e9..af7510c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.1 + 1.2 diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java index 900fda3..e572000 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -32,6 +32,9 @@ public class API { } public static boolean isRegion(String id) { + if(id == null || id.isEmpty()) + return false; + return regions.containsKey(id.toLowerCase()); } @@ -43,6 +46,9 @@ public class API { } public static Region getRegion(String id) { + if(id == null || id.isEmpty()) + return null; + return regions.get(id.toLowerCase()); } @@ -87,14 +93,23 @@ public class API { } public static boolean isAttraction(String id) { + if(id == null || id.isEmpty()) + return false; + return attractions.containsKey(id.toLowerCase()); } public static Attraction getAttraction(String id) { + if(id == null || id.isEmpty()) + return null; + return attractions.get(id.toLowerCase()); } public static Attraction getAttractionFromName(String name) { + if(name == null || name.isEmpty()) + return null; + for(Attraction attraction : attractions.values()) { if(!color(attraction.getName()).equals(name)) continue; diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 195d1c0..12d109d 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -2,6 +2,7 @@ package me.paradoxpixel.themepark.command; import me.paradoxpixel.themepark.ThemeParkPlugin; import me.paradoxpixel.themepark.api.API; +import me.paradoxpixel.themepark.api.LocationUtils; import me.paradoxpixel.themepark.api.attraction.Attraction; import me.paradoxpixel.themepark.api.attraction.Region; import me.paradoxpixel.themepark.api.attraction.component.Status; @@ -12,6 +13,7 @@ import me.paradoxpixel.themepark.utils.ItemBuilder; import me.paradoxpixel.themepark.utils.Message; import me.paradoxpixel.themepark.utils.Utils; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; @@ -23,6 +25,7 @@ import java.util.UUID; public class ThemeParkCommand extends BukkitCommand { private String name; + private YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); public ThemeParkCommand(String name) { super(name); @@ -132,7 +135,7 @@ public class ThemeParkCommand extends BukkitCommand { config.save(); String message = Message.getMessage("menu.item.toggle"); - message = message.replace("{status}", b ? Message.getMessage("enabled") : Message.getMessage("disabled")); + message = message.replace("{status}", b ? Message.getMessage("menu.item.enabled") : Message.getMessage("menu.item.disabled")); sender.sendMessage(Utils.color(message)); return true; } @@ -197,8 +200,8 @@ public class ThemeParkCommand extends BukkitCommand { } String id = args[1]; - if (!API.isRegion(id)) { - String message = Message.getMessage("region.no"); + if(!API.isRegion(id)) { + String message = Message.getMessage("region.not"); message = message.replace("{id}", id); sender.sendMessage(Utils.color(message)); return true; @@ -208,10 +211,11 @@ public class ThemeParkCommand extends BukkitCommand { name = name.replaceAll("_", " "); Region region = API.getRegion(id); - if(region.getName().equals(name)) - return true; + if(!region.getName().equals(name)) + region.setName(name); - region.setName(name); + config.getConfig().set("region." + id + ".name", name); + config.save(); String message = Message.getMessage("region.changed.name"); message = message.replace("{id}", id); @@ -228,7 +232,7 @@ public class ThemeParkCommand extends BukkitCommand { String id = args[1]; if (!API.isRegion(id)) { - String message = Message.getMessage("region.no"); + String message = Message.getMessage("region.not"); message = message.replace("{id}", id); sender.sendMessage(Utils.color(message)); return true; @@ -246,11 +250,12 @@ public class ThemeParkCommand extends BukkitCommand { lore = lore.replaceAll("_", " "); Region region = API.getRegion(id); - if(region.getLore().size() > i && region.getLore().get(i).equals(lore)) return true; region.setLore(i, lore); + config.getConfig().set("region." + id + ".lore", region.getLore()); + config.save(); String message = Message.getMessage("region.changed.lore"); message = message.replace("{id}", id); @@ -279,8 +284,12 @@ public class ThemeParkCommand extends BukkitCommand { return true; } + Location location = ((Player) sender).getLocation(); + config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location)); + config.save(); + Attraction attraction = API.getAttraction(id); - attraction.setLocation(((Player) sender).getLocation().clone()); + attraction.setLocation(location.clone()); sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName()))); return true; } @@ -301,7 +310,7 @@ public class ThemeParkCommand extends BukkitCommand { Status status = Status.getStatus(args[2]); if (status == null) { - String message = Message.getMessage("status.no"); + String message = Message.getMessage("status.not"); message = message.replace("{status}", args[2]); sender.sendMessage(Utils.color(message)); return true; @@ -322,6 +331,8 @@ public class ThemeParkCommand extends BukkitCommand { Player player = (sender instanceof Player) ? (Player) sender : null; attraction.setStatus(status, player); + config.getConfig().set("attraction." + id + ".status", status.toString()); + config.save(); 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 fc37a15..fb717e7 100644 --- a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java +++ b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java @@ -23,6 +23,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(StatusChangeEvent e) { + if(e.getAttraction() == null) + return; + AttractionMenu.reload(); SignManager.update(e.getAttraction()); @@ -43,6 +46,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(AddAttractionEvent e) { + if(e.getAttraction() == null) + return; + AttractionMenu.reload(); SignManager.loadSigns(e.getAttraction()); @@ -56,6 +62,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(RemoveAttractionEvent e) { + if(e.getAttraction() == null) + return; + AttractionMenu.reload(); SignManager.remove(e.getAttraction()); @@ -73,6 +82,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(AddRegionEvent e) { + if(e.getRegion() == null) + return; + AttractionMenu.reload(); Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { @@ -85,6 +97,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(ChangeRegionEvent e) { + if(e.getRegion() == null) + return; + AttractionMenu.reload(); Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { @@ -97,6 +112,9 @@ public class ChangeListener implements Listener { @EventHandler public void onChange(RemoveRegionEvent e) { + if(e.getRegion() == null) + return; + AttractionMenu.reload(); YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml index 2aa923e..5f524ec 100644 --- a/src/main/resources/message.yml +++ b/src/main/resources/message.yml @@ -14,13 +14,13 @@ menu: toggle: "{prefix} &aMenu item has been {status}" region: - no: "{prefix} &4There is no region with ID: {id}" + not: "{prefix} &4There is no region with ID: {id}" changed: name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}" lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}" status: - no: "{prefix} &4There is no status named: {status}" + not: "{prefix} &4There is no status named: {status}" attraction: notfound: "&4No attractions found" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2a30d0d..7f2b59b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.1 +version: 1.2 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel commands: From 8856ebe07730dc43d18e11feedf22d51980d1223 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 18 Feb 2019 19:50:58 +0100 Subject: [PATCH 10/25] Bug Fix --- pom.xml | 2 +- .../java/me/paradoxpixel/themepark/api/LocationUtils.java | 6 ++++++ .../me/paradoxpixel/themepark/command/ThemeParkCommand.java | 4 ++-- .../java/me/paradoxpixel/themepark/config/YamlConfig.java | 2 +- src/main/resources/message.yml | 2 +- src/main/resources/plugin.yml | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index af7510c..f9f303f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2 + 1.2.2 diff --git a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java index 3875e81..a62f8b5 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java +++ b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java @@ -11,6 +11,9 @@ public class LocationUtils { return null; World world = location.getWorld(); + if(world == null) + return null; + double x = location.getX(); double y = location.getY(); double z = location.getZ(); @@ -31,6 +34,9 @@ public class LocationUtils { return null; World world = Bukkit.getWorld(args[0]); + if(world == null) + return null; + double x = Double.parseDouble(args[1]); double y = Double.parseDouble(args[2]); double z = Double.parseDouble(args[3]); diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 12d109d..3eefa22 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -273,7 +273,7 @@ public class ThemeParkCommand extends BukkitCommand { String id = args[1]; if(!API.isAttraction(id)) { - String message = Message.getMessage("attraction.no"); + String message = Message.getMessage("attraction.not"); message = message.replace("{id}", id); sender.sendMessage(Utils.color(message)); return true; @@ -302,7 +302,7 @@ public class ThemeParkCommand extends BukkitCommand { String id = args[1]; if (!API.isAttraction(id)) { - String message = Message.getMessage("attraction.no"); + String message = Message.getMessage("attraction.not"); message = message.replace("{id}", id); sender.sendMessage(Utils.color(message)); return true; diff --git a/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java b/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java index 2fa00b5..5c4f9f3 100644 --- a/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java +++ b/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java @@ -46,7 +46,7 @@ public class YamlConfig { } public void reload() { - if(file == null) { + if(file == null || !file.exists()) { load(); return; } diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml index 5f524ec..9bc27ca 100644 --- a/src/main/resources/message.yml +++ b/src/main/resources/message.yml @@ -25,7 +25,7 @@ status: attraction: notfound: "&4No attractions found" list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}" - no: "{prefix} &4There is no attraction with ID: {id}" + not: "{prefix} &4There is no attraction with ID: {id}" nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}" changed: status: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7f2b59b..684224f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2 +version: 1.2.2 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel commands: From ce792b222608f977976e5cb74eb47e089cd411f9 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 1 Mar 2019 14:13:14 +0100 Subject: [PATCH 11/25] Bug Fix --- .../themepark/database/Database.java | 67 +------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/src/main/java/me/paradoxpixel/themepark/database/Database.java b/src/main/java/me/paradoxpixel/themepark/database/Database.java index 9bcb549..c73653f 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/Database.java +++ b/src/main/java/me/paradoxpixel/themepark/database/Database.java @@ -43,7 +43,7 @@ public class Database { public void connect() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password); + connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false", user, password); startPool(); } catch(Exception e) { @@ -128,69 +128,4 @@ public class Database { return false; } - public int executeUpdate(String query, HashMap objects) { - if(query == null || query.isEmpty()) - return 0; - - if(!enabled) - return 0; - - if(!connected()) - connect(); - - if(!connected()) - return 0; - - stopPool(); - try { - PreparedStatement statement = connection.prepareStatement(query); - for(Map.Entry entry : objects.entrySet()) - statement.setObject(entry.getKey(), entry.getValue()); - - int i = statement.executeUpdate(); - statement.close(); - startPool(); - - return i; - } catch(Exception e) { - e.printStackTrace(); - } - - startPool(); - return 0; - } - - public ResultSet executeQuery(String query, HashMap objects) { - if(query == null || query.isEmpty()) - return null; - - - if(!enabled) - return null; - - if(!connected()) - connect(); - - if(!connected()) - return null; - - stopPool(); - try { - PreparedStatement statement = connection.prepareStatement(query); - for(Map.Entry entry : objects.entrySet()) - statement.setObject(entry.getKey(), entry.getValue()); - - ResultSet result = statement.executeQuery(); - statement.close(); - startPool(); - - return result; - } catch(Exception e) { - e.printStackTrace(); - } - - startPool(); - return null; - } - } From 3eab1d3a4e2e8b2e72aa81021cac448164e83690 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 4 Mar 2019 15:29:21 +0100 Subject: [PATCH 12/25] Fixes --- pom.xml | 13 +++++ .../themepark/ThemeParkPlugin.java | 4 ++ .../themepark/api/attraction/Attraction.java | 10 +++- .../themepark/gui/GUIListener.java | 13 +++++ .../placeholder/ThemeParkPlaceholder.java | 51 +++++++++++++++++++ src/main/resources/plugin.yml | 1 + 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java diff --git a/pom.xml b/pom.xml index f9f303f..47b32a3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,13 @@ themepark 1.2.2 + + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + org.spigotmc @@ -20,5 +27,11 @@ 1.8.8-R0.1-SNAPSHOT provided + + me.clip + placeholderapi + 2.0.6 + provided + \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java index 142b5d0..325183d 100644 --- a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java +++ b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java @@ -12,6 +12,7 @@ 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; @@ -45,6 +46,9 @@ public class ThemeParkPlugin extends JavaPlugin { private void loadData() { StatusManager.load(); AttractionMenu.load(); + if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + new ThemeParkPlaceholder(this).hook(); + } } private void loadDatabase() { diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java index 8fe6340..85ef631 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java @@ -64,10 +64,16 @@ public class Attraction { if(location == this.location) return; - if(LocationUtils.toString(location) != null && LocationUtils.toString(location) != null) - if(LocationUtils.toString(this.location).equals(LocationUtils.toString(location))) + if(location == null) return; + if(LocationUtils.toString(location) == null) + return; + + if(LocationUtils.toString(this.location) != null && LocationUtils.toString(location) != null) + if(LocationUtils.toString(this.location).equals(LocationUtils.toString(location))) + return; + ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type); this.location = location; Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java index 6c4a3d8..0d8ab0d 100644 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java @@ -5,6 +5,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.inventory.Inventory; public class GUIListener implements Listener { @@ -26,4 +27,16 @@ public class GUIListener implements Listener { e.setCancelled(gui.execute(player, slot, type)); } + @EventHandler + public void onMove(InventoryMoveItemEvent e) { + if(e.getDestination() == null) + return; + + Inventory inventory = e.getDestination(); + if(!(inventory.getHolder() instanceof GUIHolder)) + return; + + e.setCancelled(true); + } + } diff --git a/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java b/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java new file mode 100644 index 0000000..24cfe02 --- /dev/null +++ b/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java @@ -0,0 +1,51 @@ +package me.paradoxpixel.themepark.placeholder; + +import me.paradoxpixel.themepark.ThemeParkPlugin; +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.entity.Player; +import me.clip.placeholderapi.external.EZPlaceholderHook; + +public class ThemeParkPlaceholder extends EZPlaceholderHook { + + public ThemeParkPlaceholder(ThemeParkPlugin plugin) { + super(plugin, "tp"); + } + + @Override + public String onPlaceholderRequest(Player player, String identifier) { + if(identifier == null) + return null; + + if(identifier.startsWith("status")) { + String[] args = identifier.split(":"); + if(args.length < 2) + return null; + + String id = args[1]; + if(!API.isAttraction(id)) + return null; + + 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 null; + + String id = args[1]; + if(!API.isAttraction(id)) + return null; + + String name = API.getAttraction(id).getName(); + return Utils.color(name); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 684224f..7ee7d06 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,5 +2,6 @@ name: ThemePark version: 1.2.2 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel +softdepend: [PlaceholderAPI] commands: status: \ No newline at end of file From 7a0c4bded9a85666ef8cae75a9800aa24d172816 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 4 Mar 2019 15:53:34 +0100 Subject: [PATCH 13/25] Fixes --- pom.xml | 2 +- .../me/paradoxpixel/themepark/gui/GUIListener.java | 10 ++++------ src/main/resources/plugin.yml | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 47b32a3..a2812bc 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2.2 + 1.2.4 diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java index 0d8ab0d..db3b3c4 100644 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java @@ -3,9 +3,7 @@ package me.paradoxpixel.themepark.gui; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.*; import org.bukkit.inventory.Inventory; public class GUIListener implements Listener { @@ -28,11 +26,11 @@ public class GUIListener implements Listener { } @EventHandler - public void onMove(InventoryMoveItemEvent e) { - if(e.getDestination() == null) + public void onMove(InventoryClickEvent e) { + if(e.getInventory() == null) return; - Inventory inventory = e.getDestination(); + Inventory inventory = e.getInventory(); if(!(inventory.getHolder() instanceof GUIHolder)) return; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7ee7d06..869a5a3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2.2 +version: 1.2.4 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] From a3a09d7e8f6a31d5365bbd974c393ce40a425500 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 16 Mar 2019 23:44:45 +0100 Subject: [PATCH 14/25] Bug Fix with inventory --- pom.xml | 2 +- .../java/me/paradoxpixel/themepark/gui/GUIListener.java | 7 ++++--- src/main/resources/plugin.yml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a2812bc..15f5163 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2.4 + 1.2.5 diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java index db3b3c4..2855bc5 100644 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java +++ b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java @@ -2,13 +2,14 @@ package me.paradoxpixel.themepark.gui; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.inventory.*; import org.bukkit.inventory.Inventory; public class GUIListener implements Listener { - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onClick(InventoryClickEvent e) { if(e.getClickedInventory() == null) return; @@ -22,10 +23,10 @@ public class GUIListener implements Listener { ClickType type = e.getClick(); GUI gui = (GUI) inventory.getHolder(); - e.setCancelled(gui.execute(player, slot, type)); + gui.execute(player, slot, type); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onMove(InventoryClickEvent e) { if(e.getInventory() == null) return; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 869a5a3..1fb8185 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2.4 +version: 1.2.5 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] From bb654279daa13077393fc11ef6ebd85c3bba51f3 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 12 May 2019 22:04:47 +0200 Subject: [PATCH 15/25] Updates for PlaceHolderAPI and some changes to the SignManager --- .idea/.name | 1 - .idea/uiDesigner.xml | 124 ------------------ pom.xml | 2 +- .../themepark/ThemeParkPlugin.java | 2 +- .../attraction/sign/SignManager.java | 7 +- .../placeholder/ThemeParkPlaceholder.java | 55 ++++++-- 6 files changed, 47 insertions(+), 144 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/uiDesigner.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 09564ec..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Theme \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 15f5163..2765fa8 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ me.clip placeholderapi - 2.0.6 + 2.10.2 provided diff --git a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java index 325183d..49c4101 100644 --- a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java +++ b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java @@ -47,7 +47,7 @@ public class ThemeParkPlugin extends JavaPlugin { StatusManager.load(); AttractionMenu.load(); if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new ThemeParkPlaceholder(this).hook(); + new ThemeParkPlaceholder(this).register(); } } diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java index b2fd940..1632f28 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java @@ -50,12 +50,13 @@ public class SignManager { for(Map.Entry> entry : signs.entrySet()) { List array = new ArrayList<>(); for(StatusSign sign : entry.getValue()) - array.add(LocationUtils.toString(sign.getLocation())); + if(LocationUtils.toString(sign.getLocation()) != null) + array.add(LocationUtils.toString(sign.getLocation())); - config.getConfig().set("signs." + entry.getKey().getId(), new ArrayList<>()); config.getConfig().set("signs." + entry.getKey().getId(), array); - config.save(); } + + config.save(); } public static void addSign(StatusSign sign) { diff --git a/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java b/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java index 24cfe02..96bf767 100644 --- a/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java +++ b/src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java @@ -1,32 +1,59 @@ package me.paradoxpixel.themepark.placeholder; -import me.paradoxpixel.themepark.ThemeParkPlugin; +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.entity.Player; -import me.clip.placeholderapi.external.EZPlaceholderHook; +import org.bukkit.OfflinePlayer; +import org.bukkit.plugin.Plugin; -public class ThemeParkPlaceholder extends EZPlaceholderHook { +public class ThemeParkPlaceholder extends PlaceholderExpansion { - public ThemeParkPlaceholder(ThemeParkPlugin plugin) { - super(plugin, "tp"); + private Plugin plugin; + + public ThemeParkPlaceholder(Plugin plugin){ + this.plugin = plugin; } @Override - public String onPlaceholderRequest(Player player, String identifier) { - if(identifier == null) - return null; + 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 null; + return ""; String id = args[1]; if(!API.isAttraction(id)) - return null; + return ""; Status status = API.getAttraction(id).getStatus(); return Utils.color(StatusManager.getName(status)); @@ -35,17 +62,17 @@ public class ThemeParkPlaceholder extends EZPlaceholderHook { if(identifier.startsWith("name")) { String[] args = identifier.split(":"); if(args.length < 2) - return null; + return ""; String id = args[1]; if(!API.isAttraction(id)) - return null; + return ""; String name = API.getAttraction(id).getName(); return Utils.color(name); } - return null; + return ""; } } \ No newline at end of file From d4244e813d4ac0c5c3ada8750dcd1648a10d9d19 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 12 May 2019 22:10:59 +0200 Subject: [PATCH 16/25] Changed Version files --- pom.xml | 2 +- src/main/resources/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2765fa8..38c6f85 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2.5 + 1.2.6 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1fb8185..59ec34f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2.5 +version: 1.2.6 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] From 332945095e024098adf2728244380f5245033621 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 28 Aug 2019 17:50:17 +0200 Subject: [PATCH 17/25] Fixed a problem with the Menu --- pom.xml | 2 +- .../themepark/attraction/AttractionMenu.java | 43 +++++++++++++++---- src/main/resources/plugin.yml | 2 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 38c6f85..f2f4cae 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2.6 + 1.2.7 diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index 2a82f4e..78efab5 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -71,16 +71,17 @@ public class AttractionMenu { return; HashMap regions = API.getRegions(); + HashMap size = new HashMap<>(); for(String id : section.getKeys(false)) { - if(API.getRegions().size() >= 6) { + if(size.size() >= 6) { config.getConfig().set("regions." + id, null); - config.save(); continue; } String name = config.getConfig().getString("region." + id + ".name"); List lore = config.getConfig().getStringList("region." + id + ".lore"); + size.put(id.toLowerCase(), 0); regions.remove(id); if(API.isRegion(id)) { API.getRegion(id).setName(name); @@ -90,8 +91,17 @@ 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(); + config.getConfig().set("region." + id + ".name", name); + config.getConfig().set("region." + id + ".lore", lore); + } } + config.save(); + for(String string : regions.keySet()) API.removeRegion(string); @@ -108,18 +118,28 @@ public class AttractionMenu { HashMap attractions = API.getAttractions(); for(String id : section.getKeys(false)) { String region_id = config.getConfig().getString("attraction." + id + ".region_id"); + if(!region_id.toLowerCase().equals(region_id)) { + region_id = region_id.toLowerCase(); + config.getConfig().set("attraction." + id + ".region_id", region_id); + } + if(!API.isRegion(region_id)) continue; - if(API.isRegionFull(region_id)) + if(size.get(region_id.toLowerCase()) >= 8) continue; String name = config.getConfig().getString("attraction." + id + ".name"); Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location")); Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); + if(!type.containsStatus(status)) { + status = type.getDefault(); + config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); + } - attractions.remove(id); + attractions.remove(id.toLowerCase()); + size.put(region_id.toLowerCase(), size.get(region_id.toLowerCase()) + 1); if(API.isAttraction(id)) { Attraction attraction = API.getAttraction(id); attraction.setName(name); @@ -127,17 +147,24 @@ public class AttractionMenu { attraction.setLocation(location); attraction.setType(type); attraction.setStatus(status, null); - if(!type.containsStatus(status)) { - config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); - config.save(); - } continue; } Attraction attraction = new Attraction(id, name, region_id, location, type, status); API.addAttraction(attraction); + + if(!id.toLowerCase().equals(id)) { + config.getConfig().set("attraction." + id, null); + id = id.toLowerCase(); + config.getConfig().set("attraction." + id + ".name", name); + config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location)); + config.getConfig().set("attraction." + id + ".type", type.toString()); + config.getConfig().set("attraction." + id + ".status", status.toString()); + } } + config.save(); + for(String string : attractions.keySet()) API.removeAttraction(string); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 59ec34f..e1d04a8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2.6 +version: 1.2.7 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] From bb38cea1bb79b4437c8c4e84747b0788e5c1e19a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 30 Aug 2019 21:24:18 +0200 Subject: [PATCH 18/25] Small code Cleanup --- .../api/attraction/component/Status.java | 25 ------------------- .../api/attraction/component/Type.java | 18 ------------- .../themepark/attraction/AttractionMenu.java | 4 +-- .../themepark/command/ThemeParkCommand.java | 2 +- 4 files changed, 3 insertions(+), 46 deletions(-) diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java index 78f03e5..71277f5 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java @@ -7,29 +7,4 @@ public enum Status { MALFUNCTION, ACTIVE, INACTIVE, GLOBAL; - public static Status getStatus(String string) { - if(string == null) - return null; - - string = string.toUpperCase(); - switch(string) { - case "CONSTRUCTION": - return Status.CONSTRUCTION; - case "OPEN": - return Status.OPEN; - case "CLOSED": - return Status.CLOSED; - case "MAINTENANCE": - return Status.MAINTENANCE; - case "MALFUNCTION": - return Status.MALFUNCTION; - case "ACTIVE": - return Status.ACTIVE; - case "INACTIVE": - return Status.INACTIVE; - default: - return null; - } - } - } diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java index d220036..7bf3101 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java @@ -38,22 +38,4 @@ public enum Type { return false; } - - public static Type getType(String string) { - if(string == null) - return null; - - string = string.toUpperCase(); - switch(string) { - case "RIDE": - return Type.RIDE; - case "SHOW": - return Type.SHOW; - case "GLOBAL": - return Type.GLOBAL; - default: - return null; - } - } - } diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index 78efab5..c332129 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -131,8 +131,8 @@ public class AttractionMenu { String name = config.getConfig().getString("attraction." + id + ".name"); Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location")); - Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); - Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); + Type type = Type.valueOf(config.getConfig().getString("attraction." + id + ".type")); + Status status = Status.valueOf(config.getConfig().getString("attraction." + id + ".status")); if(!type.containsStatus(status)) { status = type.getDefault(); config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 3eefa22..76e2c49 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -308,7 +308,7 @@ public class ThemeParkCommand extends BukkitCommand { return true; } - Status status = Status.getStatus(args[2]); + Status status = Status.valueOf(args[2]); if (status == null) { String message = Message.getMessage("status.not"); message = message.replace("{status}", args[2]); From 41784cb4e882d91cff75d352a4857a8bc6d91910 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 18 Sep 2019 19:18:09 +0200 Subject: [PATCH 19/25] Some small fixes --- .idea/.gitignore | 2 ++ pom.xml | 2 +- .../api/attraction/component/Status.java | 25 +++++++++++++++++++ .../api/attraction/component/Type.java | 17 +++++++++++++ .../themepark/attraction/AttractionMenu.java | 7 ++++-- .../themepark/attraction/sign/StatusSign.java | 3 +++ .../themepark/command/ThemeParkCommand.java | 4 +-- src/main/resources/plugin.yml | 2 +- 8 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2f4cae..949e7b1 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.2.7 + 1.3 diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java index 71277f5..62683fb 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java @@ -7,4 +7,29 @@ public enum Status { MALFUNCTION, ACTIVE, INACTIVE, GLOBAL; + public static Status getStatus(String str) { + if(str == null || str.isEmpty()) + return null; + + str = str.toUpperCase(); + switch(str) { + case "CONSTRUCTION": + return CONSTRUCTION; + case "OPEN": + return OPEN; + case "CLOSED": + return CLOSED; + case "MAINTENANCE": + return MAINTENANCE; + case "ACTIVE": + return ACTIVE; + case "INACTIVE": + return INACTIVE; + case "GLOBAL": + return GLOBAL; + default: + return null; + } + } + } diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java index 7bf3101..e0a0465 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java @@ -38,4 +38,21 @@ public enum Type { return false; } + public static Type getType(String str) { + if(str == null || str.isEmpty()) + return null; + + str = str.toUpperCase(); + switch (str) { + case "RIDE": + return RIDE; + case "SHOW": + return SHOW; + case "GLOBAL": + return GLOBAL; + default: + return null; + } + } + } diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index c332129..b40808f 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -118,6 +118,9 @@ public class AttractionMenu { HashMap attractions = API.getAttractions(); for(String id : section.getKeys(false)) { String region_id = config.getConfig().getString("attraction." + id + ".region_id"); + if(region_id == null || region_id.isEmpty()) + continue; + if(!region_id.toLowerCase().equals(region_id)) { region_id = region_id.toLowerCase(); config.getConfig().set("attraction." + id + ".region_id", region_id); @@ -131,8 +134,8 @@ public class AttractionMenu { String name = config.getConfig().getString("attraction." + id + ".name"); Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location")); - Type type = Type.valueOf(config.getConfig().getString("attraction." + id + ".type")); - Status status = Status.valueOf(config.getConfig().getString("attraction." + id + ".status")); + Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); + Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); if(!type.containsStatus(status)) { status = type.getDefault(); config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); 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 ce86094..c40a629 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java @@ -28,6 +28,9 @@ public class StatusSign { public void update() { Status status = attraction.getStatus(); + if(!location.getChunk().isLoaded()) + location.getChunk().load(); + 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/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 76e2c49..49077f7 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -240,7 +240,7 @@ public class ThemeParkCommand extends BukkitCommand { String string = args[2]; if(!isInteger(string)) { - sender.sendMessage(Message.getMessage("nonumber").replace("{number}", string)); + sender.sendMessage(Utils.color(Message.getMessage("nonumber").replace("{number}", string))); return true; } @@ -308,7 +308,7 @@ public class ThemeParkCommand extends BukkitCommand { return true; } - Status status = Status.valueOf(args[2]); + Status status = Status.getStatus(args[2]); if (status == null) { String message = Message.getMessage("status.not"); message = message.replace("{status}", args[2]); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e1d04a8..f5cef00 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.2.7 +version: 1.3 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] From ceafeebede2de7910ca58d7dea8fc93783237215 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 28 Jan 2020 19:16:19 +0100 Subject: [PATCH 20/25] Some small fixes --- pom.xml | 2 +- .../themepark/api/LocationUtils.java | 12 +++-- .../api/attraction/component/Status.java | 2 + .../attraction/sign/SignManager.java | 19 ++++++-- .../themepark/database/Database.java | 25 +++++----- .../themepark/listener/ChangeListener.java | 47 +++---------------- src/main/resources/plugin.yml | 2 +- src/main/resources/settings.yml | 1 + 8 files changed, 47 insertions(+), 63 deletions(-) diff --git a/pom.xml b/pom.xml index 949e7b1..1f08947 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ me.paradoxpixel themepark - 1.3 + 1.3.1 diff --git a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java index a62f8b5..ab0a920 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java +++ b/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java @@ -26,16 +26,22 @@ public class LocationUtils { } public static Location toLocation(String string) { - if(string == null) + if(string == null || string.isEmpty()) { + System.out.println("LocationUtils: Incorrect String passed"); return null; + } String[] args = string.split(":"); - if(args.length < 4) + if(args.length < 4) { + System.out.println("LocationUtils: Not enough arguments"); return null; + } World world = Bukkit.getWorld(args[0]); - if(world == null) + if(world == null) { + System.out.println("LocationUtils: No world with name: "+args[0]); return null; + } double x = Double.parseDouble(args[1]); double y = Double.parseDouble(args[2]); diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java index 62683fb..ea82f85 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java +++ b/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java @@ -21,6 +21,8 @@ public enum Status { return CLOSED; case "MAINTENANCE": return MAINTENANCE; + case "MALFUNCTION": + return MALFUNCTION; case "ACTIVE": return ACTIVE; case "INACTIVE": diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java index 1632f28..3c9c56c 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java @@ -18,13 +18,18 @@ public class SignManager { private static HashMap> signs = new HashMap<>(); public static void loadSigns(Attraction attraction) { - if(attraction == null) + if(attraction == null) { + System.out.println("SignManager: No attraction passed"); return; + } - if(!config.getConfig().contains("signs." + attraction.getId())) + if(!config.getConfig().contains("signs." + attraction.getId())) { + System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId()); return; + } if(!config.getConfig().isList("signs." + attraction.getId())) { + System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId()); config.getConfig().set("signs." + attraction.getId(), null); config.save(); return; @@ -34,11 +39,15 @@ public class SignManager { List locations = config.getConfig().getStringList("signs." + attraction.getId()); for(String string : locations) { Location location = LocationUtils.toLocation(string); - if(location == null) + if(location == null) { + System.out.println("SignManager: Incorrect sign Location"); continue; + } - if(!(location.getBlock().getState() instanceof Sign)) - return; + if(!(location.getBlock().getState() instanceof Sign)) { + System.out.println("SignManager: Block is not a sign at: "+string); + continue; + } array.add(new StatusSign(attraction, location)); } diff --git a/src/main/java/me/paradoxpixel/themepark/database/Database.java b/src/main/java/me/paradoxpixel/themepark/database/Database.java index c73653f..ac544f8 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/Database.java +++ b/src/main/java/me/paradoxpixel/themepark/database/Database.java @@ -18,20 +18,21 @@ public class Database { return; } - enabled = config.getConfig().getBoolean("mysql.enabled"); - host = config.getConfig().getString("mysql.host"); - port = config.getConfig().getInt("mysql.port"); - database = config.getConfig().getString("mysql.database"); - user = config.getConfig().getString("mysql.user"); - password = config.getConfig().getString("mysql.password"); + enabled = config.getConfig().getBoolean("mysql.enabled"); + String host = config.getConfig().getString("mysql.host"); + int port = config.getConfig().getInt("mysql.port"); + String database = config.getConfig().getString("mysql.database"); + user = config.getConfig().getString("mysql.user"); + password = config.getConfig().getString("mysql.password"); + url = config.getConfig().getString("mysql.url"); + + url = url.replace("%host%", host); + url = url.replace("%port%", Integer.toString(port)); + url = url.replace("%database%", database); } private boolean enabled; - private String host; - private int port; - private String database; - private String user; - private String password; + private String user, password, url; private Connection connection; private int TaskID; @@ -43,7 +44,7 @@ public class Database { public void connect() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false", user, password); + connection = DriverManager.getConnection(url, user, password); startPool(); } catch(Exception e) { diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java index fb717e7..45a2e15 100644 --- a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java +++ b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java @@ -36,12 +36,7 @@ public class ChangeListener implements Listener { message = message.replace("{status}", StatusManager.getName(status)); Bukkit.broadcastMessage(Utils.color(message)); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction())); } @EventHandler @@ -51,13 +46,7 @@ public class ChangeListener implements Listener { AttractionMenu.reload(); SignManager.loadSigns(e.getAttraction()); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction())); } @EventHandler @@ -67,17 +56,11 @@ public class ChangeListener implements Listener { AttractionMenu.reload(); SignManager.remove(e.getAttraction()); - YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); config.getConfig().set("attraction." + e.getAttraction().getId(), null); config.save(); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction())); } @EventHandler @@ -86,13 +69,7 @@ public class ChangeListener implements Listener { return; AttractionMenu.reload(); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion())); } @EventHandler @@ -101,13 +78,7 @@ public class ChangeListener implements Listener { return; AttractionMenu.reload(); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion())); } @EventHandler @@ -116,17 +87,11 @@ public class ChangeListener implements Listener { return; AttractionMenu.reload(); - YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); config.getConfig().set("region." + e.getRegion().getId(), null); config.save(); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion()); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion())); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f5cef00..374ba73 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ThemePark -version: 1.3 +version: 1.3.1 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel softdepend: [PlaceholderAPI] diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index ac29cbc..4137d02 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -22,6 +22,7 @@ mysql: database: 'database' user: 'username' password: 'password' + url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false' CONSTRUCTION: name: "&7Under Construction" From 6b85ced40ba519913d848242b441206ae338e600 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 18 Apr 2020 21:46:53 +0200 Subject: [PATCH 21/25] Big Update --- .idea/compiler.xml | 1 + pom.xml | 12 +- .../themepark/ThemeParkPlugin.java | 4 - .../themepark/action/PageAction.java | 20 ++ .../me/paradoxpixel/themepark/api/API.java | 3 - .../themepark/attraction/AttractionMenu.java | 175 +++++++++++++++--- .../themepark/attraction/sign/StatusSign.java | 6 +- .../themepark/command/MenuCommand.java | 2 +- .../themepark/command/ThemeParkCommand.java | 2 + .../themepark/listener/ChangeListener.java | 5 +- .../themepark/listener/ClickListener.java | 2 +- .../themepark/listener/PlayerListener.java | 68 ++++--- .../placeholder/ThemeParkPlaceholder.java | 78 -------- src/main/resources/plugin.yml | 4 +- src/main/resources/settings.yml | 8 + 15 files changed, 248 insertions(+), 142 deletions(-) create mode 100644 src/main/java/me/paradoxpixel/themepark/action/PageAction.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/placeholder/ThemeParkPlaceholder.java 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 From fe3350cc4ff40f90719150bb635f3b5b399b6e00 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 23 Apr 2020 18:57:46 +0200 Subject: [PATCH 22/25] Dynmap to dynmap --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8f03e2a..6fd307e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,6 +2,6 @@ name: ThemePark version: 1.4.1 main: me.paradoxpixel.themepark.ThemeParkPlugin author: ParadoxPixel -softdepend: [PlaceholderAPI,Dynmap] +softdepend: [PlaceholderAPI,dynmap] commands: status: \ No newline at end of file From ad9c5d413986d2ceabffda0603f53be9c74b8e61 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 16 Jun 2020 18:30:29 +0200 Subject: [PATCH 23/25] ThemePark 2.0 --- .idea/ThemePark.iml | 31 ++ .idea/modules.xml | 8 + dependency-reduced-pom.xml | 95 +++++ pom.xml | 45 +- .../themepark/ThemeParkPlugin.java | 118 ----- .../themepark/action/PageAction.java | 20 - .../themepark/action/TPUtils.java | 49 --- .../me/paradoxpixel/themepark/api/API.java | 160 ------- .../themepark/api/attraction/Attraction.java | 118 ----- .../themepark/api/attraction/Region.java | 96 ----- .../event/attraction/AddAttractionEvent.java | 29 -- .../attraction/ChangeAttractionEvent.java | 79 ---- .../attraction/PreStatusChangeEvent.java | 61 --- .../attraction/RemoveAttractionEvent.java | 29 -- .../event/attraction/StatusChangeEvent.java | 48 --- .../api/event/region/AddRegionEvent.java | 30 -- .../api/event/region/ChangeRegionEvent.java | 53 --- .../api/event/region/RemoveRegionEvent.java | 30 -- .../themepark/attraction/AttractionMenu.java | 359 ---------------- .../attraction/sign/SignManager.java | 152 ------- .../themepark/attraction/sign/StatusSign.java | 43 -- .../attraction/status/StatusManager.java | 76 ---- .../themepark/command/ThemeParkCommand.java | 352 --------------- .../themepark/database/Database.java | 132 ------ .../themepark/database/DatabaseHandler.java | 101 ----- .../me/paradoxpixel/themepark/gui/GUI.java | 120 ------ .../paradoxpixel/themepark/gui/GUIAction.java | 9 - .../paradoxpixel/themepark/gui/GUIHolder.java | 11 - .../paradoxpixel/themepark/gui/GUIItem.java | 45 -- .../themepark/gui/GUIListener.java | 41 -- .../themepark/listener/ChangeListener.java | 101 ----- .../themepark/listener/ClickListener.java | 45 -- .../themepark/listener/PlayerListener.java | 90 ---- .../themepark/listener/SignListener.java | 64 --- .../paradoxpixel/themepark/utils/Message.java | 25 -- .../paradoxpixel/themepark/utils/Utils.java | 15 - .../nl/iobyte/themepark/ThemeParkPlugin.java | 139 ++++++ .../java/nl/iobyte/themepark/api/API.java | 110 +++++ .../themepark/api/attraction/Attraction.java | 119 ++++++ .../themepark/api/attraction/Region.java | 152 +++++++ .../api/attraction/component/Status.java | 2 +- .../api/attraction/component/Type.java | 2 +- .../api/attraction/manager/StatusManager.java | 43 ++ .../themepark/api/events/ChangeEvent.java | 33 ++ .../attraction/ChangeLocationEvent.java | 20 + .../events/attraction/ChangeNameEvent.java | 19 + .../events/attraction/ChangeStatusEvent.java | 27 ++ .../events/attraction/ChangeTypeEvent.java | 20 + .../attraction/PreChangeStatusEvent.java | 37 ++ .../api/events/region/ChangeDataEvent.java | 19 + .../api/events/region/ChangeLoreEvent.java | 20 + .../events/region/ChangeMaterialEvent.java | 20 + .../api/events/region/ChangeNameEvent.java | 19 + .../events/ridecount/ChangeCountEvent.java | 34 ++ .../api/events/ridecount/SetCountEvent.java | 33 ++ .../api/ridecount/AttractionCount.java | 92 ++++ .../themepark/api/ridecount/CountManager.java | 73 ++++ .../themepark/api/ridecount/RideCount.java | 38 ++ .../themepark/api}/utils/ItemBuilder.java | 21 +- .../api/utils/LocationSerializer.java} | 16 +- .../iobyte/themepark/command/MainCommand.java | 403 ++++++++++++++++++ .../themepark/command/MenuCommand.java | 16 +- .../themepark/command/RidecountCommand.java | 107 +++++ .../iobyte}/themepark/config/YamlConfig.java | 2 +- .../java/nl/iobyte/themepark/database/DB.java | 77 ++++ .../iobyte/themepark/database/DBManager.java | 90 ++++ .../nl/iobyte/themepark/database/MySQL.java | 66 +++ .../nl/iobyte/themepark/database/SQLite.java | 84 ++++ .../listener/AttractionListener.java | 118 +++++ .../themepark/listener/PlayerListener.java | 190 +++++++++ .../themepark/listener/RegionListener.java | 68 +++ .../themepark/menu/AttractionLoader.java | 240 +++++++++++ .../iobyte/themepark/menu/AttractionMenu.java | 173 ++++++++ .../themepark/menu/actions/PageAction.java | 20 + .../themepark/menu/actions/TPAction.java | 39 ++ .../themepark/ridecount/RideCountAPI.java | 326 ++++++++++++++ .../java/nl/iobyte/themepark/util/Color.java | 11 + .../nl/iobyte/themepark/util/MessageUtil.java | 82 ++++ src/main/resources/attraction.yml | 40 -- src/main/resources/message.yml | 42 -- src/main/resources/messages.yml | 47 ++ src/main/resources/plugin.yml | 12 +- src/main/resources/regions.yml | 12 + src/main/resources/settings.yml | 32 +- 84 files changed, 3446 insertions(+), 2839 deletions(-) create mode 100644 .idea/ThemePark.iml create mode 100644 .idea/modules.xml create mode 100644 dependency-reduced-pom.xml delete mode 100644 src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/action/PageAction.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/action/TPUtils.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/API.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/database/Database.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUI.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/listener/SignListener.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/utils/Message.java delete mode 100644 src/main/java/me/paradoxpixel/themepark/utils/Utils.java create mode 100644 src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java create mode 100644 src/main/java/nl/iobyte/themepark/api/API.java create mode 100644 src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java create mode 100644 src/main/java/nl/iobyte/themepark/api/attraction/Region.java rename src/main/java/{me/paradoxpixel => nl/iobyte}/themepark/api/attraction/component/Status.java (93%) rename src/main/java/{me/paradoxpixel => nl/iobyte}/themepark/api/attraction/component/Type.java (95%) create mode 100644 src/main/java/nl/iobyte/themepark/api/attraction/manager/StatusManager.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/ChangeEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeLocationEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeNameEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeStatusEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeTypeEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/PreChangeStatusEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/ChangeDataEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/ChangeLoreEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/ChangeMaterialEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/ChangeNameEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/ridecount/ChangeCountEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/ridecount/SetCountEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/ridecount/AttractionCount.java create mode 100644 src/main/java/nl/iobyte/themepark/api/ridecount/CountManager.java create mode 100644 src/main/java/nl/iobyte/themepark/api/ridecount/RideCount.java rename src/main/java/{me/paradoxpixel/themepark => nl/iobyte/themepark/api}/utils/ItemBuilder.java (90%) rename src/main/java/{me/paradoxpixel/themepark/api/LocationUtils.java => nl/iobyte/themepark/api/utils/LocationSerializer.java} (75%) create mode 100644 src/main/java/nl/iobyte/themepark/command/MainCommand.java rename src/main/java/{me/paradoxpixel => nl/iobyte}/themepark/command/MenuCommand.java (58%) create mode 100644 src/main/java/nl/iobyte/themepark/command/RidecountCommand.java rename src/main/java/{me/paradoxpixel => nl/iobyte}/themepark/config/YamlConfig.java (98%) create mode 100644 src/main/java/nl/iobyte/themepark/database/DB.java create mode 100644 src/main/java/nl/iobyte/themepark/database/DBManager.java create mode 100644 src/main/java/nl/iobyte/themepark/database/MySQL.java create mode 100644 src/main/java/nl/iobyte/themepark/database/SQLite.java create mode 100644 src/main/java/nl/iobyte/themepark/listener/AttractionListener.java create mode 100644 src/main/java/nl/iobyte/themepark/listener/PlayerListener.java create mode 100644 src/main/java/nl/iobyte/themepark/listener/RegionListener.java create mode 100644 src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java create mode 100644 src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java create mode 100644 src/main/java/nl/iobyte/themepark/menu/actions/PageAction.java create mode 100644 src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java create mode 100644 src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java create mode 100644 src/main/java/nl/iobyte/themepark/util/Color.java create mode 100644 src/main/java/nl/iobyte/themepark/util/MessageUtil.java delete mode 100644 src/main/resources/attraction.yml delete mode 100644 src/main/resources/message.yml create mode 100644 src/main/resources/messages.yml create mode 100644 src/main/resources/regions.yml diff --git a/.idea/ThemePark.iml b/.idea/ThemePark.iml new file mode 100644 index 0000000..f63550d --- /dev/null +++ b/.idea/ThemePark.iml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..141afb8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..ad97fa7 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + nl.iobyte + themepark + 2.0 + + + + maven-shade-plugin + 3.2.0 + + + package + + shade + + + + + + + de.tr7zw.changeme.nbtapi + de.tr7zw.nbtapi + + + + + + + + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + dynmap + http://repo.mikeprimm.com/ + + + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + json-simple + com.googlecode.json-simple + + + guava + com.google.guava + + + gson + com.google.code.gson + + + ebean + org.avaje + + + snakeyaml + org.yaml + + + bungeecord-chat + net.md-5 + + + + + org.dynmap + dynmap-api + 2.0 + provided + + + bukkit + org.bukkit + + + + + + 1.8 + 1.8 + + diff --git a/pom.xml b/pom.xml index 161a8d6..5174913 100644 --- a/pom.xml +++ b/pom.xml @@ -9,9 +9,9 @@ 1.8 - me.paradoxpixel + nl.iobyte themepark - 1.4.1 + 2.0 @@ -37,5 +37,46 @@ 2.0 provided + + nl.iobyte + menuapi + 1.0 + + + com.zaxxer + HikariCP + 3.4.3 + + + nl.iobyte + workchain + 1.0 + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.0 + + + package + + shade + + + + + + + de.tr7zw.changeme.nbtapi + de.tr7zw.nbtapi + + + + + + \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java b/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java deleted file mode 100644 index 142b5d0..0000000 --- a/src/main/java/me/paradoxpixel/themepark/ThemeParkPlugin.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.paradoxpixel.themepark; - -import me.paradoxpixel.themepark.attraction.AttractionMenu; -import me.paradoxpixel.themepark.attraction.sign.SignManager; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.command.MenuCommand; -import me.paradoxpixel.themepark.command.ThemeParkCommand; -import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.database.DatabaseHandler; -import me.paradoxpixel.themepark.gui.GUIListener; -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 org.bukkit.Bukkit; -import org.bukkit.command.CommandMap; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import java.lang.reflect.Field; - -public class ThemeParkPlugin extends JavaPlugin { - - private static ThemeParkPlugin instance; - private YamlConfig settings, attraction, message, signs, data; - private DatabaseHandler database; - - @Override - public void onEnable() { - instance = this; - loadConfig(); - loadListener(); - loadCommand(); - loadData(); - loadDatabase(); - } - - private void loadConfig() { - settings = new YamlConfig("settings", this); - attraction = new YamlConfig("attraction", this); - message = new YamlConfig("message", this); - signs = new YamlConfig("signs", this); - data = new YamlConfig("data", this); - } - - private void loadData() { - StatusManager.load(); - AttractionMenu.load(); - } - - private void loadDatabase() { - database = new DatabaseHandler(settings); - } - - private void loadCommand() { - getCommand("status").setExecutor(new MenuCommand()); - - String command = settings.getConfig().getString("command"); - if(command == null || command.isEmpty()) - return; - - try { - final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); - - bukkitCommandMap.setAccessible(true); - CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); - - commandMap.register(command, new ThemeParkCommand(command)); - } catch(ReflectiveOperationException e) { - e.printStackTrace(); - } - } - - private void loadListener() { - PluginManager pm = Bukkit.getPluginManager(); - pm.registerEvents(new GUIListener(), this); - pm.registerEvents(new ClickListener(), this); - pm.registerEvents(new ChangeListener(), this); - pm.registerEvents(new SignListener(), this); - pm.registerEvents(new PlayerListener(), this); - } - - @Override - public void onDisable() { - AttractionMenu.save(); - SignManager.saveSigns(); - database.disconnect(); - instance = null; - } - - public static ThemeParkPlugin getInstance() { - return instance; - } - - public YamlConfig getSettings() { - return settings; - } - - public YamlConfig getAttraction() { - return attraction; - } - - public YamlConfig getMessage() { - return message; - } - - public YamlConfig getSigns() { - return signs; - } - - public YamlConfig getData() { - return data; - } - - public DatabaseHandler getDatabaseHandler() { - return database; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/action/PageAction.java b/src/main/java/me/paradoxpixel/themepark/action/PageAction.java deleted file mode 100644 index 9599593..0000000 --- a/src/main/java/me/paradoxpixel/themepark/action/PageAction.java +++ /dev/null @@ -1,20 +0,0 @@ -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/action/TPUtils.java b/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java deleted file mode 100644 index 58477e6..0000000 --- a/src/main/java/me/paradoxpixel/themepark/action/TPUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.paradoxpixel.themepark.action; - -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.attraction.AttractionMenu; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.gui.GUIAction; -import me.paradoxpixel.themepark.utils.Message; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Player; - -public class TPUtils extends GUIAction { - - private String id; - - public TPUtils(String id) { - this.id = id; - } - - @Override - public void click(Player player) { - player.closeInventory(); - Attraction attraction = API.getAttraction(id); - if(attraction == null) - return; - - if(attraction.getLocation() == null) - return; - - if(!StatusManager.canTeleport(attraction.getStatus())) { - String message = Message.getMessage("attraction.teleport.status"); - message = message.replace("{name}", attraction.getName()); - message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); - player.sendMessage(Utils.color(message)); - return; - } - - if(player.isInsideVehicle()) - if(player.getVehicle() instanceof Minecart) - return; - - player.teleport(attraction.getLocation()); - String message = Message.getMessage("attraction.teleport.success"); - message = message.replace("{name}", attraction.getName()); - player.sendMessage(Utils.color(message)); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java deleted file mode 100644 index 31dfa97..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ /dev/null @@ -1,160 +0,0 @@ -package me.paradoxpixel.themepark.api; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.Region; -import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent; -import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent; -import me.paradoxpixel.themepark.api.event.region.AddRegionEvent; -import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -public class API { - - private static LinkedHashMap regions = new LinkedHashMap<>(); - private static LinkedHashMap attractions = new LinkedHashMap<>(); - - public static void addRegion(Region region) { - if(isRegion(region.getId())) - return; - - region = toLower(region); - regions.put(region.getId(), region); - - AddRegionEvent event = new AddRegionEvent(region); - Bukkit.getPluginManager().callEvent(event); - } - - public static boolean isRegion(String id) { - if(id == null || id.isEmpty()) - return false; - - return regions.containsKey(id.toLowerCase()); - } - - public static boolean isRegionFull(String id) { - if(!isRegion(id)) - return false; - - return getRegion(id).getAttractions().size() >= 8; - } - - public static Region getRegion(String id) { - if(id == null || id.isEmpty()) - return null; - - return regions.get(id.toLowerCase()); - } - - public static HashMap getRegions() { - return new LinkedHashMap<>(regions); - } - - public static void removeRegion(String id) { - if(!isRegion(id)) - return; - - HashMap map = new HashMap<>(attractions); - for(Map.Entry entry : map.entrySet()) { - Attraction attraction = entry.getValue(); - if(!attraction.getRegion_id().equalsIgnoreCase(id)) - continue; - - removeAttraction(attraction.getId()); - } - - RemoveRegionEvent event = new RemoveRegionEvent(getRegion(id)); - Bukkit.getPluginManager().callEvent(event); - regions.remove(id.toLowerCase()); - } - - public static void addAttraction(Attraction attraction) { - if(!isRegion(attraction.getRegion_id())) - return; - - if(isRegionFull(attraction.getRegion_id())) - return; - - if(isAttraction(attraction.getId())) - return; - - attraction = toLower(attraction); - getRegion(attraction.getRegion_id()).addAttraction(attraction); - attractions.put(attraction.getId(), attraction); - - AddAttractionEvent event = new AddAttractionEvent(attraction); - Bukkit.getPluginManager().callEvent(event); - } - - public static boolean isAttraction(String id) { - if(id == null || id.isEmpty()) - return false; - - return attractions.containsKey(id.toLowerCase()); - } - - public static Attraction getAttraction(String id) { - if(id == null || id.isEmpty()) - return null; - - return attractions.get(id.toLowerCase()); - } - - public static Attraction getAttractionFromName(String name) { - if(name == null || name.isEmpty()) - return null; - - for(Attraction attraction : attractions.values()) { - if(!color(attraction.getName()).equals(name)) - continue; - - return attraction; - } - - return null; - } - - public static HashMap getAttractions() { - return new LinkedHashMap<>(attractions); - } - - public static void removeAttraction(String id) { - if(!isAttraction(id)) - return; - - Attraction attraction = getAttraction(id); - if(isRegion(attraction.getRegion_id())) - getRegion(attraction.getRegion_id()).removeAttraction(attraction); - - attractions.remove(id.toLowerCase()); - - RemoveAttractionEvent event = new RemoveAttractionEvent(attraction); - Bukkit.getPluginManager().callEvent(event); - } - - private static Region toLower(Region region) { - Region re = new Region(region.getId().toLowerCase(), - region.getName(), - region.getLore()); - - re.setAttractions(region.getAttractions()); - return re; - } - - private static Attraction toLower(Attraction attraction) { - return new Attraction(attraction.getId().toLowerCase(), - attraction.getName(), - attraction.getRegion_id().toLowerCase(), - attraction.getLocation(), - attraction.getType(), - attraction.getStatus()); - } - - private static String color(String string) { - return ChatColor.translateAlternateColorCodes('&', string); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java deleted file mode 100644 index 85ef631..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Attraction.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.paradoxpixel.themepark.api.attraction; - -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.api.attraction.component.Type; -import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent; -import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; -import me.paradoxpixel.themepark.api.event.attraction.ChangeAttractionEvent; -import me.paradoxpixel.themepark.api.LocationUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -public class Attraction { - - private String id, name, region_id; - private Location location; - private Type type; - private Status status; - - public Attraction(String id, String name, String region_id, Location location, Type type, Status status) { - this.id = id; - this.name = name; - this.region_id = region_id; - this.location = location; - this.type = type; - this.status = type.containsStatus(status) ? status : type.getDefault(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - if(this.name.equals(name)) - return; - - ChangeAttractionEvent event = new ChangeAttractionEvent(this, this.name, name, region_id, region_id, location, location, type, type); - this.name = name; - Bukkit.getPluginManager().callEvent(event); - } - - public String getRegion_id() { - return region_id; - } - - public void setRegion_id(String region_id) { - if(this.region_id.equals(region_id)) - return; - - ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, this.region_id, region_id, location, location, type, type); - this.region_id = region_id; - Bukkit.getPluginManager().callEvent(event); - } - - public Location getLocation() { - return location; - } - - public void setLocation(Location location) { - if(location == this.location) - return; - - if(location == null) - return; - - if(LocationUtils.toString(location) == null) - return; - - if(LocationUtils.toString(this.location) != null && LocationUtils.toString(location) != null) - if(LocationUtils.toString(this.location).equals(LocationUtils.toString(location))) - return; - - ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type); - this.location = location; - Bukkit.getPluginManager().callEvent(event); - } - - public Type getType() { - return type; - } - - public void setType(Type type) { - ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, location, location, this.type, type); - this.type = type; - Bukkit.getPluginManager().callEvent(event); - if(!type.containsStatus(status)) - setStatus(type.getDefault(), null); - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status, Player player) { - if(!type.hasStatus()) - return; - - if(!type.containsStatus(status)) - return; - - if(this.status == status) - return; - - PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status); - Bukkit.getPluginManager().callEvent(event); - if(event.isCancelled()) - return; - - this.status = status; - StatusChangeEvent e = new StatusChangeEvent(this, player, this.status, status); - Bukkit.getPluginManager().callEvent(e); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java b/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java deleted file mode 100644 index a41e236..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/Region.java +++ /dev/null @@ -1,96 +0,0 @@ -package me.paradoxpixel.themepark.api.attraction; - -import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent; -import org.bukkit.Bukkit; -import java.util.ArrayList; -import java.util.List; - -public class Region { - - private String id, name; - private List lore; - private ArrayList attractions; - - public Region(String id, String name, List lore) { - this.id = id; - this.name = name; - this.lore = lore; - this.attractions = new ArrayList<>(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String string) { - if(string == null || string.equals("")) - return; - - String old = name; - name = string; - - ChangeRegionEvent event = new ChangeRegionEvent(this, old, string, lore, lore); - Bukkit.getPluginManager().callEvent(event); - } - - public List getLore() { - return lore; - } - - public void setLore(List lore) { - List old = lore; - this.lore = lore; - - ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore); - Bukkit.getPluginManager().callEvent(event); - } - - public void setLore(int i, String string) { - if(lore.size() >= 4 || i >= 4) - return; - - List old = lore; - lore = new ArrayList<>(); - lore.addAll(old); - - if(!string.equals("NULL")) { - if (lore.size() >= i) - for (int a = 0; a <= (i - lore.size()); a++) - lore.add(" "); - - lore.set(i, string); - } else { - lore.remove(i); - } - - ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore); - Bukkit.getPluginManager().callEvent(event); - } - - public ArrayList getAttractions() { - return attractions; - } - - public void setAttractions(ArrayList attractions) { - this.attractions = attractions; - } - - public void addAttraction(Attraction attraction) { - if(!isAttraction(attraction)) - attractions.add(attraction); - } - - public boolean isAttraction(Attraction attraction) { - return attractions.contains(attraction); - } - - public void removeAttraction(Attraction attraction) { - if(isAttraction(attraction)) - attractions.remove(attraction); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java deleted file mode 100644 index 56899fe..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/AddAttractionEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.paradoxpixel.themepark.api.event.attraction; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class AddAttractionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Attraction attraction; - - public AddAttractionEvent(Attraction attraction) { - this.attraction = attraction; - } - - public Attraction getAttraction() { - return attraction; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java deleted file mode 100644 index 92f4450..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/ChangeAttractionEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -package me.paradoxpixel.themepark.api.event.attraction; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Type; -import org.bukkit.Location; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class ChangeAttractionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Attraction attraction; - private String bname, aname, bregion_id, aregion_id; - private Location blocation, alocation; - private Type btype, atype; - - public ChangeAttractionEvent(Attraction attraction, - String bname, String aname, - String aregion_id, String bregion_id, - Location alocation, Location blocation, - Type btype, Type atype) { - this.attraction = attraction; - this.bname = bname; - this.aname = aname; - this.bregion_id = bregion_id; - this.aregion_id = aregion_id; - this.alocation = alocation; - this.blocation = blocation; - this.btype = btype; - this.atype = atype; - } - - public Attraction getAttraction() { - return attraction; - } - - public String getNameBefore() { - return bname; - } - - public String getNameAfter() { - return aname; - } - - public String getRegionIdBefore() { - return bregion_id; - } - - public String getRegionIdAfter() { - return aregion_id; - } - - public Location getLocationBefore() { - return blocation; - } - - public Location getLocationAfter() { - return alocation; - } - - public Type getTypeBefore() { - return btype; - } - - public Type getTypeAfter() { - return atype; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} - diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java deleted file mode 100644 index 529e6da..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/PreStatusChangeEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.paradoxpixel.themepark.api.event.attraction; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class PreStatusChangeEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - private boolean cancel; - private Attraction attraction; - private Player player; - private Status before, after; - - public PreStatusChangeEvent(Attraction attraction, Player player, Status before, Status after) { - this.attraction = attraction; - this.player = player; - this.before = before; - this.after = after; - cancel = false; - } - - @Override - public boolean isCancelled() { - return cancel; - } - - @Override - public void setCancelled(boolean b) { - cancel = b; - } - - public Attraction getAttraction() { - return attraction; - } - - public Player getPlayer() { - return player; - } - - public Status getStatusBefore() { - return before; - } - - public Status getStatusAfter() { - return after; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java deleted file mode 100644 index a07cb09..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/RemoveAttractionEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.paradoxpixel.themepark.api.event.attraction; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class RemoveAttractionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Attraction attraction; - - public RemoveAttractionEvent(Attraction attraction) { - this.attraction = attraction; - } - - public Attraction getAttraction() { - return attraction; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java deleted file mode 100644 index 2e80350..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/attraction/StatusChangeEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -package me.paradoxpixel.themepark.api.event.attraction; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class StatusChangeEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Attraction attraction; - private Player player; - private Status before, after; - - public StatusChangeEvent(Attraction attraction, Player player, Status before, Status after) { - this.attraction = attraction; - this.player = player; - this.before = before; - this.after = after; - } - - public Attraction getAttraction() { - return attraction; - } - - public Player getPlayer() { - return player; - } - - public Status getStatusBefore() { - return before; - } - - public Status getStatusAfter() { - return after; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java deleted file mode 100644 index 21fc13e..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/region/AddRegionEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.paradoxpixel.themepark.api.event.region; - -import me.paradoxpixel.themepark.api.attraction.Region; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class AddRegionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Region region; - - public AddRegionEvent(Region region) { - this.region = region; - } - - public Region getRegion() { - return region; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} - diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java deleted file mode 100644 index 5a8ae8a..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/region/ChangeRegionEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.paradoxpixel.themepark.api.event.region; - -import me.paradoxpixel.themepark.api.attraction.Region; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import java.util.List; - -public class ChangeRegionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Region region; - private String bname, aname; - private List blore, alore; - - public ChangeRegionEvent(Region region, String bname, String aname, List blore, List alore) { - this.region = region; - this.bname = bname; - this.aname = aname; - this.blore = blore; - this.alore = alore; - } - - public Region getRegion() { - return region; - } - - public String getNameBefore() { - return bname; - } - - public String getNameAfter() { - return aname; - } - - public List getLoreBefore() { - return blore; - } - - public List getLoreAfter() { - return alore; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - -} - diff --git a/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java b/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java deleted file mode 100644 index 8c7d47c..0000000 --- a/src/main/java/me/paradoxpixel/themepark/api/event/region/RemoveRegionEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.paradoxpixel.themepark.api.event.region; - -import me.paradoxpixel.themepark.api.attraction.Region; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class RemoveRegionEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - - private Region region; - - public RemoveRegionEvent(Region region) { - this.region = region; - } - - public Region getRegion() { - return region; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - -} diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java deleted file mode 100644 index 1ecb36e..0000000 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ /dev/null @@ -1,359 +0,0 @@ -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; -import me.paradoxpixel.themepark.api.attraction.Region; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.api.attraction.component.Type; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.config.YamlConfig; -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 HashMap pages = new HashMap<>(); - private static boolean loading = false; - private static String title; - - 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; - 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(); - } - - public static void reload() { - loadItems(); - } - - public static void save() { - for(Region region : API.getRegions().values()) { - config.getConfig().set("region." + region.getId() + ".name", region.getName()); - config.getConfig().set("region." + region.getId() + ".lore", region.getLore()); - } - - for(Attraction attraction : API.getAttractions().values()) { - config.getConfig().set("attraction." + attraction.getId() + ".name", attraction.getName()); - config.getConfig().set("attraction." + attraction.getId() + ".region_id", attraction.getRegion_id()); - config.getConfig().set("attraction." + attraction.getId() + ".type", attraction.getType().toString()); - config.getConfig().set("attraction." + attraction.getId() + ".status", attraction.getStatus().toString()); - config.getConfig().set("attraction." + attraction.getId() + ".location", LocationUtils.toString(attraction.getLocation())); - } - - config.save(); - } - - private static void loadData() { - if(!config.getConfig().contains("region")) - return; - - if(!config.getConfig().isConfigurationSection("region")) - return; - - ConfigurationSection section = config.getConfig().getConfigurationSection("region"); - if(section.getKeys(false).isEmpty()) - return; - - HashMap regions = API.getRegions(); - HashMap size = new HashMap<>(); - for(String id : section.getKeys(false)) { - String name = config.getConfig().getString("region." + id + ".name"); - List lore = config.getConfig().getStringList("region." + id + ".lore"); - - size.put(id.toLowerCase(), 0); - regions.remove(id); - if(API.isRegion(id)) { - API.getRegion(id).setName(name); - API.getRegion(id).setLore(lore); - continue; - } - - Region region = new Region(id, name, lore); - API.addRegion(region); - if(!id.toLowerCase().equals(id)) { - config.getConfig().set("region." + id, null); - id = id.toLowerCase(); - config.getConfig().set("region." + id + ".name", name); - config.getConfig().set("region." + id + ".lore", lore); - } - } - - config.save(); - for(String string : regions.keySet()) - API.removeRegion(string); - - prepareGUI(); - if(!config.getConfig().contains("attraction")) - return; - - if(!config.getConfig().isConfigurationSection("attraction")) - return; - - section = config.getConfig().getConfigurationSection("attraction"); - if(section.getKeys(false).isEmpty()) - return; - - HashMap attractions = API.getAttractions(); - for(String id : section.getKeys(false)) { - String region_id = config.getConfig().getString("attraction." + id + ".region_id"); - if(region_id == null || region_id.isEmpty()) - continue; - - if(!region_id.toLowerCase().equals(region_id)) { - region_id = region_id.toLowerCase(); - config.getConfig().set("attraction." + id + ".region_id", region_id); - } - - if(!API.isRegion(region_id)) - continue; - - if(size.get(region_id.toLowerCase()) >= 8) - continue; - - String name = config.getConfig().getString("attraction." + id + ".name"); - Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location")); - Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type")); - Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status")); - if(!type.containsStatus(status)) { - status = type.getDefault(); - config.getConfig().set("attraction." + id + ".status", type.getDefault().toString()); - } - - attractions.remove(id.toLowerCase()); - size.put(region_id.toLowerCase(), size.get(region_id.toLowerCase()) + 1); - if(API.isAttraction(id)) { - Attraction attraction = API.getAttraction(id); - attraction.setName(name); - attraction.setRegion_id(region_id); - 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(); - config.getConfig().set("attraction." + id + ".name", name); - config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location)); - config.getConfig().set("attraction." + id + ".type", type.toString()); - config.getConfig().set("attraction." + id + ".status", status.toString()); - } - } - - 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; - - if(API.getRegions().values().size() == 0) - return; - - 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); - - ItemBuilder builder = new ItemBuilder(mat, 1, data); - builder.setName(region.getName()); - builder.setLore(region.getLore()); - - 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()); - continue; - } - - if(!index.containsKey(attraction.getRegion_id())) - continue; - - 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(in + a)) { - in += a; - b = true; - break; - } - } - - if(!b) { - API.removeAttraction(attraction.getId()); - continue; - } - - ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus())); - builder.setName(attraction.getName()); - builder.setLore(StatusManager.getName(attraction.getStatus())); - - 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, 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/SignManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java deleted file mode 100644 index 3c9c56c..0000000 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/SignManager.java +++ /dev/null @@ -1,152 +0,0 @@ -package me.paradoxpixel.themepark.attraction.sign; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.api.LocationUtils; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Sign; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class SignManager { - - private static YamlConfig config = ThemeParkPlugin.getInstance().getSigns(); - private static HashMap> signs = new HashMap<>(); - - public static void loadSigns(Attraction attraction) { - if(attraction == null) { - System.out.println("SignManager: No attraction passed"); - return; - } - - if(!config.getConfig().contains("signs." + attraction.getId())) { - System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId()); - return; - } - - if(!config.getConfig().isList("signs." + attraction.getId())) { - System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId()); - config.getConfig().set("signs." + attraction.getId(), null); - config.save(); - return; - } - - ArrayList array = new ArrayList<>(); - List locations = config.getConfig().getStringList("signs." + attraction.getId()); - for(String string : locations) { - Location location = LocationUtils.toLocation(string); - if(location == null) { - System.out.println("SignManager: Incorrect sign Location"); - continue; - } - - if(!(location.getBlock().getState() instanceof Sign)) { - System.out.println("SignManager: Block is not a sign at: "+string); - continue; - } - - array.add(new StatusSign(attraction, location)); - } - - signs.put(attraction, array); - } - - public static void saveSigns() { - for(Map.Entry> entry : signs.entrySet()) { - List array = new ArrayList<>(); - for(StatusSign sign : entry.getValue()) - if(LocationUtils.toString(sign.getLocation()) != null) - array.add(LocationUtils.toString(sign.getLocation())); - - config.getConfig().set("signs." + entry.getKey().getId(), array); - } - - config.save(); - } - - public static void addSign(StatusSign sign) { - if(sign == null || sign.getLocation() == null) - return; - - if(!(sign.getLocation().getBlock().getState() instanceof Sign)) - return; - - if(signs.containsKey(sign.getAttraction())) { - signs.get(sign.getAttraction()).add(sign); - return; - } - - ArrayList array = new ArrayList<>(); - array.add(sign); - signs.put(sign.getAttraction(), array); - } - - public static boolean hasSigns(Attraction attraction) { - if(attraction == null) - return false; - - return signs.containsKey(attraction) && (signs.get(attraction).size() > 0); - } - - public static void update(Attraction attraction) { - if(attraction == null) - return; - - if(!hasSigns(attraction)) - return; - - for(StatusSign sign : signs.get(attraction)) - sign.update(); - } - - public static void remove(Attraction attraction) { - if(attraction == null || !signs.containsKey(attraction)) - return; - - for(StatusSign sign : signs.get(attraction)) - sign.getLocation().getBlock().setType(Material.AIR); - - signs.remove(attraction); - config.getConfig().set("signs." + attraction.getId(), null); - config.save(); - } - - public static void removeSign(StatusSign sign) { - if(sign == null || sign.getLocation() == null || sign.getAttraction() == null) - return; - - if(!hasSigns(sign.getAttraction())) - return; - - ArrayList array = signs.get(sign.getAttraction()); - for(StatusSign s : new ArrayList<>(array)) { - Location loc1 = sign.getLocation(); - Location loc2 = s.getLocation(); - - if(loc1 == null || loc2 == null) - return; - - if(LocationUtils.toString(loc1) == null || LocationUtils.toString(loc2) == null) - return; - - if(!LocationUtils.toString(loc1).equals(LocationUtils.toString(loc2))) - return; - - array.remove(s); - } - - if(array.isEmpty()) { - signs.remove(sign.getAttraction()); - config.getConfig().set("signs." + sign.getAttraction().getId(), null); - config.save(); - return; - } - - signs.put(sign.getAttraction(), array); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java b/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java deleted file mode 100644 index 90408b7..0000000 --- a/src/main/java/me/paradoxpixel/themepark/attraction/sign/StatusSign.java +++ /dev/null @@ -1,43 +0,0 @@ -package me.paradoxpixel.themepark.attraction.sign; - -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Location; -import org.bukkit.block.Sign; - -public class StatusSign { - - private Attraction attraction; - private Location location; - - public StatusSign(Attraction attraction, Location location) { - this.attraction = attraction; - this.location = location; - } - - public Attraction getAttraction() { - return attraction; - } - - public Location getLocation() { - return location; - } - - 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/attraction/status/StatusManager.java b/src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java deleted file mode 100644 index d632502..0000000 --- a/src/main/java/me/paradoxpixel/themepark/attraction/status/StatusManager.java +++ /dev/null @@ -1,76 +0,0 @@ -package me.paradoxpixel.themepark.attraction.status; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.config.YamlConfig; -import org.bukkit.Material; -import java.util.HashMap; - -public class StatusManager { - - private static YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); - private static HashMap names; - private static HashMap materials; - private static HashMap data; - private static HashMap teleport; - - public static void load() { - names = new HashMap<>(); - materials = new HashMap<>(); - data = new HashMap<>(); - teleport = new HashMap<>(); - - for(Status status : Status.values()) { - if(config.getConfig().contains(status.toString() + ".name")) { - names.put(status, config.getConfig().getString(status.toString() + ".name")); - } else { - names.put(status, "UNKNOWN"); - } - - if(config.getConfig().contains(status.toString() + ".material")) { - Material material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material")); - if(material == null) - material = Material.STAINED_CLAY; - - materials.put(status, material); - } else { - materials.put(status, Material.STAINED_CLAY); - } - - if(config.getConfig().contains(status.toString() + ".data")) { - String string = config.getConfig().getString(status.toString() + ".data"); - if(string.isEmpty()) { - data.put(status, (short) 0); - continue; - } - - data.put(status, Short.parseShort(string)); - } else { - data.put(status, (short) 0); - } - - if(config.getConfig().contains(status.toString() + ".teleport")) { - teleport.put(status, config.getConfig().getBoolean(status.toString() + ".teleport")); - } else { - teleport.put(status, false); - } - } - } - - public static String getName(Status status) { - return names.get(status); - } - - public static Material getMaterial(Status status) { - return materials.get(status); - } - - public static short getData(Status status) { - return data.get(status); - } - - public static boolean canTeleport(Status status) { - return teleport.get(status); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java deleted file mode 100644 index 88d7521..0000000 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ /dev/null @@ -1,352 +0,0 @@ -package me.paradoxpixel.themepark.command; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.LocationUtils; -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; -import me.paradoxpixel.themepark.utils.Message; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.command.defaults.BukkitCommand; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Player; -import java.util.Scanner; -import java.util.UUID; - -public class ThemeParkCommand extends BukkitCommand { - - private String name; - private YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); - - public ThemeParkCommand(String name) { - super(name); - - this.name = name; - } - - public boolean execute(CommandSender sender,String label, String[] args) { - if (args.length == 0 || args[0].equalsIgnoreCase("help")) { - sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<")); - sender.sendMessage(Utils.color("&f/" + name + " help")); - sender.sendMessage(Utils.color("&f/" + name + " list")); - sender.sendMessage(Utils.color("&f/" + name + " warp [id]")); - if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) { - sender.sendMessage(Utils.color("&f/" + name + " toggleitem")); - sender.sendMessage(Utils.color("&f/" + name + " getitem")); - } - - if(sender.hasPermission("themepark.admin")) { - sender.sendMessage(Utils.color("&f/" + name + " reload")); - sender.sendMessage(Utils.color("&f/" + name + " regionname [id] [name]")); - sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]")); - sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]")); - sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]")); - } - - return true; - } - - if (args[0].equalsIgnoreCase("list")) { - sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<")); - if (API.getAttractions().size() == 0) { - sender.sendMessage(Utils.color(Message.getMessage("attraction.notfound"))); - return true; - } - - for (Attraction attraction : API.getAttractions().values()) { - String message = Message.getMessage("attraction.list"); - message = message.replace("{id}", attraction.getId()); - message = message.replace("{name}", attraction.getName()); - message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).getName()); - message = message.replace("{type}", attraction.getType().toString()); - message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); - sender.sendMessage(Utils.color(message)); - } - - return true; - } - - if(args[0].equalsIgnoreCase("warp")) { - if(args.length < 2) { - sender.sendMessage(Utils.color( "&6Themepark&f: &4/" + name + " warp [id]")); - return true; - } - - String id = args[1]; - if(!API.isAttraction(id)) { - String message = Message.getMessage("attraction.no"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - if(sender instanceof Player) { - Attraction attraction = API.getAttraction(id); - Player player = (Player) sender; - if(!StatusManager.canTeleport(attraction.getStatus())) { - String message = Message.getMessage("attraction.teleport.status"); - message = message.replace("{name}", attraction.getName()); - message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); - player.sendMessage(Utils.color(message)); - return true; - } - - player.teleport(attraction.getLocation()); - if(player.isInsideVehicle()) - if(player.getVehicle() instanceof Minecart) - return true; - - player.sendMessage(Utils.color(Message.getMessage("attraction.teleport.success").replace("{name}", attraction.getName()))); - return true; - } else { - sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); - return true; - } - } - - if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) { - sender.sendMessage(Utils.color(Message.getMessage("nopermission"))); - return true; - } - - if(args[0].equalsIgnoreCase("toggleitem")) { - if(!(sender instanceof Player)) { - sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); - return true; - } - - Player player = (Player) sender; - UUID uuid = player.getUniqueId(); - - YamlConfig config = ThemeParkPlugin.getInstance().getData(); - boolean b = config.getConfig().getBoolean(uuid.toString() + ".item"); - b = !b; - - config.getConfig().set(uuid.toString() + ".item", b); - config.save(); - - String message = Message.getMessage("menu.item.toggle"); - message = message.replace("{status}", b ? Message.getMessage("menu.item.enabled") : Message.getMessage("menu.item.disabled")); - sender.sendMessage(Utils.color(message)); - return true; - } - - if(args[0].equalsIgnoreCase("getitem")) { - YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); - Material material = Material.getMaterial(settings.getConfig().getString("item.material")); - String name = Utils.color(settings.getConfig().getString("item.display-name")); - if(material == null || name.isEmpty()) - return true; - - Player player; - if(args.length >= 2) { - String string = args[1]; - if(Bukkit.getPlayerExact(string) == null) { - String message = Message.getMessage("noplayer"); - message = message.replace("{name}", string); - sender.sendMessage(Utils.color(message)); - return true; - } - - player = Bukkit.getPlayerExact(string); - } else { - if(!(sender instanceof Player)) { - sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); - return true; - } - - player = (Player) sender; - } - - - ItemBuilder builder = new ItemBuilder(material); - builder.setName(name); - player.getInventory().addItem(builder.getItem()); - } - - if(!sender.hasPermission("themepark.admin")) { - sender.sendMessage(Utils.color(Message.getMessage("nopermission"))); - return true; - } - - if(args[0].equalsIgnoreCase("reload")) { - ThemeParkPlugin.getInstance().getData().reload(); - ThemeParkPlugin.getInstance().getAttraction().reload(); - ThemeParkPlugin.getInstance().getSigns().reload(); - ThemeParkPlugin.getInstance().getSettings().reload(); - ThemeParkPlugin.getInstance().getMessage().reload(); - - StatusManager.load(); - AttractionMenu.load(); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(),() -> { - ThemeParkPlugin.getInstance().getDatabaseHandler().load(); - }); - sender.sendMessage(Utils.color(Message.getMessage("reloaded"))); - } - - if (args[0].equalsIgnoreCase("regionname")) { - if (args.length < 3) { - sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionname [id] [name]")); - return true; - } - - String id = args[1]; - if(!API.isRegion(id)) { - String message = Message.getMessage("region.not"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - String name = args[2]; - name = name.replaceAll("_", " "); - - Region region = API.getRegion(id); - if(!region.getName().equals(name)) - region.setName(name); - - config.getConfig().set("region." + id + ".name", name); - config.save(); - - String message = Message.getMessage("region.changed.name"); - message = message.replace("{id}", id); - message = message.replace("{name}", name); - sender.sendMessage(Utils.color(message)); - return true; - } - - if (args[0].equalsIgnoreCase("regionlore")) { - if (args.length < 4) { - sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionlore[id] [index] [lore]")); - return true; - } - - String id = args[1]; - if (!API.isRegion(id)) { - String message = Message.getMessage("region.not"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - String string = args[2]; - if(!isInteger(string)) { - sender.sendMessage(Utils.color(Message.getMessage("nonumber").replace("{number}", string))); - return true; - } - - int i = Integer.parseInt(string); - - String lore = args[3]; - lore = lore.replaceAll("_", " "); - - Region region = API.getRegion(id); - if(region.getLore().size() > i && region.getLore().get(i).equals(lore)) - return true; - - region.setLore(i, lore); - config.getConfig().set("region." + id + ".lore", region.getLore()); - config.save(); - - String message = Message.getMessage("region.changed.lore"); - message = message.replace("{id}", id); - message = message.replace("{index}", "" + i); - message = message.replace("{lore}", lore); - sender.sendMessage(Utils.color(message)); - return true; - } - - if (args[0].equalsIgnoreCase("setlocation")) { - if (args.length < 2 ) { - sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " setlocation [id]")); - return true; - } - - String id = args[1]; - if(!API.isAttraction(id)) { - String message = Message.getMessage("attraction.not"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - if(!(sender instanceof Player)) { - sender.sendMessage(Utils.color(Message.getMessage("onlyplayers"))); - return true; - } - - Location location = ((Player) sender).getLocation(); - config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location)); - config.save(); - - 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; - } - - if (args[0].equalsIgnoreCase("attraction")) { - if (args.length < 3 ) { - sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " attraction [id] [status]")); - return true; - } - - String id = args[1]; - if (!API.isAttraction(id)) { - String message = Message.getMessage("attraction.not"); - message = message.replace("{id}", id); - sender.sendMessage(Utils.color(message)); - return true; - } - - Status status = Status.getStatus(args[2]); - if (status == null) { - String message = Message.getMessage("status.not"); - message = message.replace("{status}", args[2]); - sender.sendMessage(Utils.color(message)); - return true; - } - - Attraction attraction = API.getAttraction(id); - if(!attraction.getType().containsStatus(status)) { - String message = Message.getMessage("attraction.nostatus"); - message = message.replace("{name}", attraction.getName()); - message = message.replace("{status}", status.toString()); - sender.sendMessage(Utils.color(message)); - return true; - } - - if(attraction.getStatus() == status) - return true; - - Player player = (sender instanceof Player) ? (Player) sender : null; - - attraction.setStatus(status, player); - config.getConfig().set("attraction." + id + ".status", status.toString()); - config.save(); - return true; - } - - return false; - } - - private boolean isInteger(String s) { - int radix = 10; - Scanner sc = new Scanner(s.trim()); - if(!sc.hasNextInt(radix)) return false; - sc.nextInt(radix); - return !sc.hasNext(); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/database/Database.java b/src/main/java/me/paradoxpixel/themepark/database/Database.java deleted file mode 100644 index ac544f8..0000000 --- a/src/main/java/me/paradoxpixel/themepark/database/Database.java +++ /dev/null @@ -1,132 +0,0 @@ -package me.paradoxpixel.themepark.database; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.config.YamlConfig; -import org.bukkit.Bukkit; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.HashMap; -import java.util.Map; - -public class Database { - - public Database(YamlConfig config) { - if(config == null) { - enabled = false; - return; - } - - enabled = config.getConfig().getBoolean("mysql.enabled"); - String host = config.getConfig().getString("mysql.host"); - int port = config.getConfig().getInt("mysql.port"); - String database = config.getConfig().getString("mysql.database"); - user = config.getConfig().getString("mysql.user"); - password = config.getConfig().getString("mysql.password"); - url = config.getConfig().getString("mysql.url"); - - url = url.replace("%host%", host); - url = url.replace("%port%", Integer.toString(port)); - url = url.replace("%database%", database); - } - - private boolean enabled; - private String user, password, url; - - private Connection connection; - private int TaskID; - - public boolean isEnabled() { - return enabled; - } - - public void connect() { - try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection(url, user, password); - - startPool(); - } catch(Exception e) { - enabled = false; - e.printStackTrace(); - } - } - - public void disconnect() { - if(connection == null) - return; - - try { - connection.close(); - connection = null; - } catch(Exception e) { - e.printStackTrace(); - } - } - - private boolean connected() { - if(connection == null) - return false; - - try { - return !connection.isClosed(); - } catch(Exception e) { - e.printStackTrace(); - } - - return false; - } - - private void startPool() { - TaskID = Bukkit.getScheduler().runTaskLater(ThemeParkPlugin.getInstance(), new Runnable() { - @Override - public void run() { - disconnect(); - TaskID = 0; - } - }, 1200L).getTaskId(); - } - - private void stopPool() { - if(TaskID == 0) - return; - - Bukkit.getScheduler().cancelTask(TaskID); - TaskID = 0; - } - - public boolean execute(String query, HashMap objects) { - if(query == null || query.isEmpty()) - return false; - - if(!enabled) - return false; - - if(!connected()) - connect(); - - if(!connected()) - return false; - - stopPool(); - try { - PreparedStatement statement = connection.prepareStatement(query); - if(objects != null) - for(Map.Entry entry : objects.entrySet()) - statement.setObject(entry.getKey(), entry.getValue()); - - boolean b = statement.execute(); - statement.close(); - startPool(); - - return b; - } catch(Exception e) { - e.printStackTrace(); - } - - startPool(); - return false; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java deleted file mode 100644 index 6967e1b..0000000 --- a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -package me.paradoxpixel.themepark.database; - -import me.paradoxpixel.themepark.api.API; -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.status.StatusManager; -import me.paradoxpixel.themepark.config.YamlConfig; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.UUID; - -public class DatabaseHandler { - - private Database database; - - public DatabaseHandler(YamlConfig config) { - database = new Database(config); - load(); - } - - public void load() { - database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); - database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); - database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null); - - database.execute("TRUNCATE TABLE attraction", null); - database.execute("TRUNCATE TABLE region", null); - database.execute("TRUNCATE TABLE status", null); - - for(Attraction attraction : API.getAttractions().values()) - addAttraction(attraction); - - for(Region region : API.getRegions().values()) - addRegion(region); - - for(Status status : Status.values()) { - HashMap objects = new HashMap<>(); - objects.put(1, status.toString()); - objects.put(2, StatusManager.getName(status)); - database.execute("INSERT INTO status (statusId,statusName) VALUES(?,?)", objects); - } - } - - public void addAttraction(Attraction attraction) { - HashMap objects = new HashMap<>(); - objects.put(1, attraction.getId()); - objects.put(2, attraction.getName()); - objects.put(3, attraction.getRegion_id()); - objects.put(4, attraction.getType().toString()); - objects.put(5, attraction.getStatus().toString()); - - database.execute("INSERT IGNORE INTO attraction(id, name, region_id, type, status) VALUES (?,?,?,?,?)", objects); - } - - public void updateAttraction(Attraction attraction) { - HashMap objects = new HashMap<>(); - objects.put(1, attraction.getStatus().toString()); - objects.put(2, attraction.getId()); - - database.execute("UPDATE attraction SET status=? WHERE id=?", objects); - } - - public void removeAttraction(Attraction attraction) { - HashMap objects = new HashMap<>(); - objects.put(1, attraction.getId()); - - database.execute("DELETE FROM attraction WHERE id=?", objects); - database.execute("DELETE FROM ridecount WHERE attractionId=?", objects); - } - - public void addRegion(Region region) { - HashMap objects = new HashMap<>(); - objects.put(1, region.getId()); - objects.put(2, region.getName()); - - database.execute("INSERT IGNORE INTO region(id, name) VALUES (?,?)", objects); - } - - public void updateRegion(Region region) { - HashMap objects = new HashMap<>(); - objects.put(1, region.getName()); - objects.put(2, region.getId()); - - database.execute("UPDATE region SET name=? WHERE id=?", objects); - } - - public void removeRegion(Region region) { - HashMap objects = new HashMap<>(); - objects.put(1, region.getId()); - - database.execute("DELETE FROM region WHERE id=?", objects); - } - - public void disconnect() { - database.disconnect(); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUI.java b/src/main/java/me/paradoxpixel/themepark/gui/GUI.java deleted file mode 100644 index 6a1d572..0000000 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUI.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.paradoxpixel.themepark.gui; - -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -public class GUI extends GUIHolder { - - private String title; - private int size; - private Inventory inventory; - private HashMap items = new HashMap<>(); - - public GUI(String title, int size) { - if(size > 54) - size = 54; - - this.title = title; - this.size = Utils.toSize(size, 9); - inventory = Bukkit.createInventory(this, this.size, Utils.color(title)); - } - - private void update() { - ArrayList toRemove = new ArrayList<>(); - for(Map.Entry entry : items.entrySet()) { - if(entry.getKey() >= getSize()) { - toRemove.add(entry.getKey()); - continue; - } - - inventory.setItem(entry.getKey(), entry.getValue().getItem()); - } - - for(int i : toRemove) - items.remove(i); - } - - public void setSize(int size) { - if(size > 54) - size = 54; - - this.size = Utils.toSize(size, 9); - inventory = Bukkit.createInventory(this, this.size, Utils.color(title)); - update(); - } - - public int getSize() { - return size; - } - - public void clear() { - inventory = Bukkit.createInventory(this, Utils.toSize(size, 9), Utils.color(title)); - items.clear(); - } - - public void addItems(HashMap items) { - for(Map.Entry entry : items.entrySet()) - addItem(entry.getKey(), entry.getValue()); - } - - public void addItem(int slot, GUIItem item) { - if(slot >= getSize() || slot < 0) - return; - - items.put(slot, item); - inventory.setItem(slot, item.getItem()); - } - - public void removeItem(int slot) { - items.remove(slot); - } - - public void switchSlot(int from, int to) { - if(!items.containsKey(from)) - return; - - GUIItem item = items.get(from); - items.put(to, item); - items.remove(from); - } - - public boolean hasItem(int slot) { - return items.containsKey(slot); - } - - @Override - public boolean execute(Player player, int slot, ClickType type) { - if(player == null || slot >= getSize() || slot < 0 || type == null) - return false; - - if(!items.containsKey(slot)) - return false; - - GUIItem item = items.get(slot); - if(type == ClickType.RIGHT) { - if(item.getActionRight() != null) - item.getActionRight().click(player); - - return item.hasCancelRight(); - } else { - if(item.getActionLeft() != null) - item.getActionLeft().click(player); - - return item.hasCancelLeft(); - } - } - - @Override - public Inventory getInventory() { - return inventory; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java deleted file mode 100644 index 539ef03..0000000 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIAction.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.paradoxpixel.themepark.gui; - -import org.bukkit.entity.Player; - -public abstract class GUIAction { - - public abstract void click(Player player); - -} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java deleted file mode 100644 index 4477573..0000000 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIHolder.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.paradoxpixel.themepark.gui; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; - -public abstract class GUIHolder implements InventoryHolder { - - public abstract boolean execute(Player player, int slot, ClickType type); - -} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java deleted file mode 100644 index 62a8382..0000000 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIItem.java +++ /dev/null @@ -1,45 +0,0 @@ -package me.paradoxpixel.themepark.gui; - -import org.bukkit.inventory.ItemStack; - -public class GUIItem { - - private ItemStack item; - private GUIAction aleft, aright; - private boolean cleft, cright; - - public GUIItem(ItemStack item, GUIAction action, boolean cancel) { - this.item = item; - aleft = aright = action; - cleft = cright = cancel; - } - - public GUIItem(ItemStack item, GUIAction aleft, GUIAction aright, boolean cleft, boolean cright) { - this.item = item; - this.aleft = aleft; - this.aright = aright; - this.cleft = cleft; - this.cright = cright; - } - - public ItemStack getItem() { - return item; - } - - public boolean hasCancelLeft() { - return cleft; - } - - public boolean hasCancelRight() { - return cright; - } - - public GUIAction getActionLeft() { - return aleft; - } - - public GUIAction getActionRight() { - return aright; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java b/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java deleted file mode 100644 index 2855bc5..0000000 --- a/src/main/java/me/paradoxpixel/themepark/gui/GUIListener.java +++ /dev/null @@ -1,41 +0,0 @@ -package me.paradoxpixel.themepark.gui; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.*; -import org.bukkit.inventory.Inventory; - -public class GUIListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST) - public void onClick(InventoryClickEvent e) { - if(e.getClickedInventory() == null) - return; - - Inventory inventory = e.getClickedInventory(); - if(!(inventory.getHolder() instanceof GUIHolder)) - return; - - Player player = (Player) e.getWhoClicked(); - int slot = e.getRawSlot(); - ClickType type = e.getClick(); - - GUI gui = (GUI) inventory.getHolder(); - gui.execute(player, slot, type); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onMove(InventoryClickEvent e) { - if(e.getInventory() == null) - return; - - Inventory inventory = e.getInventory(); - if(!(inventory.getHolder() instanceof GUIHolder)) - return; - - e.setCancelled(true); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java deleted file mode 100644 index b168302..0000000 --- a/src/main/java/me/paradoxpixel/themepark/listener/ChangeListener.java +++ /dev/null @@ -1,101 +0,0 @@ -package me.paradoxpixel.themepark.listener; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent; -import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent; -import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; -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; -import me.paradoxpixel.themepark.utils.Message; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -public class ChangeListener implements Listener { - - @EventHandler - public void onChange(StatusChangeEvent e) { - if(e.getAttraction() == null) - return; - - 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()); - message = message.replace("{status}", StatusManager.getName(status)); - Bukkit.broadcastMessage(Utils.color(message)); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction())); - } - - @EventHandler - public void onChange(AddAttractionEvent e) { - if(e.getAttraction() == null) - return; - - AttractionMenu.reload(); - SignManager.loadSigns(e.getAttraction()); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction())); - } - - @EventHandler - public void onChange(RemoveAttractionEvent e) { - if(e.getAttraction() == null) - return; - - 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(); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction())); - } - - @EventHandler - public void onChange(AddRegionEvent e) { - if(e.getRegion() == null) - return; - - AttractionMenu.reload(); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion())); - } - - @EventHandler - public void onChange(ChangeRegionEvent e) { - if(e.getRegion() == null) - return; - - AttractionMenu.reload(); - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion())); - } - - @EventHandler - public void onChange(RemoveRegionEvent e) { - if(e.getRegion() == null) - return; - - AttractionMenu.reload(); - YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); - config.getConfig().set("region." + e.getRegion().getId(), null); - config.save(); - - Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion())); - } - - -} diff --git a/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java b/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java deleted file mode 100644 index 6a95676..0000000 --- a/src/main/java/me/paradoxpixel/themepark/listener/ClickListener.java +++ /dev/null @@ -1,45 +0,0 @@ -package me.paradoxpixel.themepark.listener; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.attraction.AttractionMenu; -import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Material; -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.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; - -public class ClickListener implements Listener { - - private YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); - - @EventHandler - public void onInteract(PlayerInteractEvent e) { - Material material = Material.getMaterial(config.getConfig().getString("item.material")); - String name = Utils.color(config.getConfig().getString("item.display-name")); - if(e.getItem() == null) - return; - - ItemStack item = e.getItem(); - if(item.getType() != material) - return; - - if(!item.hasItemMeta()) - return; - - if(!item.getItemMeta().getDisplayName().equals(name)) - return; - - if(e.getAction() == Action.LEFT_CLICK_AIR || - e.getAction() == Action.LEFT_CLICK_BLOCK) - return; - - e.setCancelled(true); - Player player = e.getPlayer(); - 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 deleted file mode 100644 index ac71e64..0000000 --- a/src/main/java/me/paradoxpixel/themepark/listener/PlayerListener.java +++ /dev/null @@ -1,90 +0,0 @@ -package me.paradoxpixel.themepark.listener; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.database.DatabaseHandler; -import me.paradoxpixel.themepark.utils.ItemBuilder; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Material; -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 { - - private YamlConfig config = ThemeParkPlugin.getInstance().getData(); - private YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - doItem(e.getPlayer()); - } - - @EventHandler - public void onSwitch(PlayerChangedWorldEvent e) { - doItem(e.getPlayer()); - } - - @EventHandler - public void onTeleport(PlayerTeleportEvent e) { - Player player = e.getPlayer(); - if(e.getCause() != PlayerTeleportEvent.TeleportCause.PLUGIN) - return; - - if(!player.isInsideVehicle()) - return; - - if(player.getVehicle() == null) - return; - - if(!(player.getVehicle() instanceof Minecart)) - return; - - e.setCancelled(true); - 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/listener/SignListener.java b/src/main/java/me/paradoxpixel/themepark/listener/SignListener.java deleted file mode 100644 index c2b46dc..0000000 --- a/src/main/java/me/paradoxpixel/themepark/listener/SignListener.java +++ /dev/null @@ -1,64 +0,0 @@ -package me.paradoxpixel.themepark.listener; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.attraction.sign.SignManager; -import me.paradoxpixel.themepark.attraction.sign.StatusSign; -import me.paradoxpixel.themepark.attraction.status.StatusManager; -import me.paradoxpixel.themepark.config.YamlConfig; -import me.paradoxpixel.themepark.utils.Utils; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.SignChangeEvent; - -public class SignListener implements Listener { - - private YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); - private String name = config.getConfig().getString("sign.name"); - private String title = config.getConfig().getString("sign.title"); - - @EventHandler - public void onPlace(SignChangeEvent e) { - if(!e.getLine(0).equalsIgnoreCase(name)) - return; - - String id = e.getLine(1); - if(id == null || id.isEmpty() || !API.isAttraction(id)) - return; - - Attraction attraction = API.getAttraction(id); - e.setLine(0, Utils.color(title)); - e.setLine(1, Utils.color(attraction.getName())); - e.setLine(2, Utils.color(StatusManager.getName(attraction.getStatus()))); - - Location location = e.getBlock().getLocation(); - StatusSign statusSign = new StatusSign(attraction, location); - SignManager.addSign(statusSign); - } - - @EventHandler - public void onBreak(BlockBreakEvent e) { - if(e.getBlock() == null) - return; - - Block block = e.getBlock(); - if(!(block.getState() instanceof Sign)) - return; - - Sign sign = (Sign) block.getState(); - if(!sign.getLine(0).equals(Utils.color(title))) - return; - - Attraction attraction = API.getAttractionFromName(sign.getLine(1)); - Location location = e.getBlock().getLocation(); - - StatusSign s = new StatusSign(attraction, location); - SignManager.removeSign(s); - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/Message.java b/src/main/java/me/paradoxpixel/themepark/utils/Message.java deleted file mode 100644 index 204ada2..0000000 --- a/src/main/java/me/paradoxpixel/themepark/utils/Message.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.paradoxpixel.themepark.utils; - -import me.paradoxpixel.themepark.ThemeParkPlugin; -import me.paradoxpixel.themepark.config.YamlConfig; - -public class Message { - - private static YamlConfig config = ThemeParkPlugin.getInstance().getMessage(); - - public static boolean isMessage(String string) { - return config.getConfig().contains(string); - } - - public static String getMessage(String string) { - if(!isMessage(string)) - return ""; - - String message = config.getConfig().getString(string); - if(isMessage("prefix")) - message = message.replace("{prefix}", config.getConfig().getString("prefix")); - - return message; - } - -} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/Utils.java b/src/main/java/me/paradoxpixel/themepark/utils/Utils.java deleted file mode 100644 index 1116260..0000000 --- a/src/main/java/me/paradoxpixel/themepark/utils/Utils.java +++ /dev/null @@ -1,15 +0,0 @@ -package me.paradoxpixel.themepark.utils; - -import org.bukkit.ChatColor; - -public class Utils { - - public static String color(String string) { - return ChatColor.translateAlternateColorCodes('&', string); - } - - public static int toSize(int i, int size) { - return i % size == 0 ? i : i + (size - (i % size)); - } - -} diff --git a/src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java b/src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java new file mode 100644 index 0000000..9064b15 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java @@ -0,0 +1,139 @@ +package nl.iobyte.themepark; + +import nl.iobyte.menuapi.MenuAPI; +import nl.iobyte.themepark.command.MainCommand; +import nl.iobyte.themepark.command.MenuCommand; +import nl.iobyte.themepark.command.RidecountCommand; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.database.DB; +import nl.iobyte.themepark.database.DBManager; +import nl.iobyte.themepark.database.MySQL; +import nl.iobyte.themepark.database.SQLite; +import nl.iobyte.themepark.listener.AttractionListener; +import nl.iobyte.themepark.listener.PlayerListener; +import nl.iobyte.themepark.listener.RegionListener; +import nl.iobyte.themepark.menu.AttractionLoader; +import nl.iobyte.workchain.thread.WorkThreader; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandMap; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import java.lang.reflect.Field; + +public class ThemeParkPlugin extends JavaPlugin { + + private static ThemeParkPlugin instance; + private YamlConfig settings, messages, data, regions; + private WorkThreader threader; + + public void onEnable() { + instance = this; + loadConfigs(); + loadDatabases(); + loadWorkers(); + loadListeners(); + loadCommands(); + AttractionLoader.load(); + } + + private void loadConfigs() { + settings = new YamlConfig("settings", this); + messages = new YamlConfig("messages", this); + data = new YamlConfig("data", this); + regions = new YamlConfig("regions", this); + } + + private void loadDatabases() { + DBManager.addDatabase("data", new SQLite("data")); + + FileConfiguration fc = settings.getConfig(); + if(fc.getBoolean("mysql.enabled")) { + String host = fc.getString("mysql.host"); + int port = fc.getInt("mysql.port"); + String database = fc.getString("mysql.database"); + String username = fc.getString("mysql.user"); + String password = fc.getString("mysql.pass"); + DBManager.addDatabase("public", new MySQL(host, port, database, username, password)); + } + + loadTables(); + } + + private void loadTables() { + DB db = DBManager.getDatabase("data"); + DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS counts(uuid VARCHAR(255) NOT NULL, attraction_id VARCHAR(255) NOT NULL, points BIGINT(20), created_at TEXT DEFAULT CURRENT_DATE, UNIQUE(uuid, attraction_id))"); + + db = DBManager.getDatabase("public"); + if(db == null) + return; + + DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))"); + DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))"); + DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)"); + } + + private void loadWorkers() { + int workers = settings.getConfig().getInt("workers"); + if(workers < 1) + workers = 1; + + threader = new WorkThreader(workers); + threader.createWorkers(); + threader.start(); + } + + private void loadListeners() { + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerListener(), this); + pm.registerEvents(new AttractionListener(), this); + pm.registerEvents(new RegionListener(), this); + MenuAPI.register(this); + } + + private void loadCommands() { + getCommand("status").setExecutor(new MenuCommand()); + getCommand("ridecount").setExecutor(new RidecountCommand()); + String command = settings.getConfig().getString("command"); + if(command == null || command.isEmpty()) + return; + + try { + final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); + + bukkitCommandMap.setAccessible(true); + CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); + + commandMap.register(command, new MainCommand(command)); + } catch(ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + public void onDisable() { + threader.stop(); + DBManager.shutdown(); + instance = null; + } + + public static ThemeParkPlugin getInstance() { + return instance; + } + + public YamlConfig getSettings() { + return settings; + } + + public YamlConfig getMessages() { + return messages; + } + + public YamlConfig getData() { + return data; + } + + public YamlConfig getRegions() { + return regions; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/API.java b/src/main/java/nl/iobyte/themepark/api/API.java new file mode 100644 index 0000000..10e9514 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/API.java @@ -0,0 +1,110 @@ +package nl.iobyte.themepark.api; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.ridecount.CountManager; +import org.bukkit.ChatColor; +import java.util.LinkedHashMap; + +public class API { + + private static LinkedHashMap regions = new LinkedHashMap<>(); + private static LinkedHashMap attractions = new LinkedHashMap<>(); + + public static void addRegion(Region region) { + if(isRegion(region.getId())) + return; + + regions.put(region.getId(), region); + } + + public static boolean isRegion(String id) { + if(id == null || id.isEmpty()) + return false; + + return regions.containsKey(id); + } + + public static Region getRegion(String id) { + if(id == null || id.isEmpty()) + return null; + + return regions.get(id); + } + + public static LinkedHashMap getRegions() { + return regions; + } + + public static void removeRegion(String id) { + Region region = getRegion(id); + if(region == null) + return; + + for(Attraction attraction : region.getAttractions().values()) + attractions.remove(attraction.getId()); + + regions.remove(id); + } + + public static void addAttraction(Attraction attraction) { + if(!isRegion(attraction.getRegionId())) + return; + + if(isAttraction(attraction.getId())) + return; + + getRegion(attraction.getRegionId()).addAttraction(attraction); + attractions.put(attraction.getId(), attraction); + CountManager.addCounter(attraction); + } + + public static boolean isAttraction(String id) { + if(id == null || id.isEmpty()) + return false; + + return attractions.containsKey(id); + } + + public static Attraction getAttraction(String id) { + if(id == null || id.isEmpty()) + return null; + + return attractions.get(id); + } + + public static Attraction getAttractionFromName(String name) { + if(name == null || name.isEmpty()) + return null; + + for(Attraction attraction : attractions.values()) { + if(!color(attraction.getName()).equals(name)) + continue; + + return attraction; + } + + return null; + } + + public static LinkedHashMap getAttractions() { + return attractions; + } + + public static void removeAttraction(String id) { + if(!isAttraction(id)) + return; + + Attraction attraction = getAttraction(id); + if(isRegion(attraction.getRegionId())) + getRegion(attraction.getRegionId()).removeAttraction(attraction); + + attractions.remove(id); + CountManager.removeCounter(id); + } + + private static String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java b/src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java new file mode 100644 index 0000000..9e70854 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java @@ -0,0 +1,119 @@ +package nl.iobyte.themepark.api.attraction; + +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.attraction.component.Type; +import nl.iobyte.themepark.api.events.attraction.*; +import nl.iobyte.themepark.api.utils.LocationSerializer; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class Attraction { + + private String id, name, region_id; + private Location location; + private Type type; + private Status status; + + public Attraction(String id, String name, String region_id, Location location, Type type, Status status) { + this.id = id; + this.name = name; + this.region_id = region_id; + this.location = location; + this.type = type; + this.status = type.containsStatus(status) ? status : type.getDefault(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + if(this.name.equals(name)) + return; + + String old = this.name; + this.name = name; + ChangeNameEvent e = new ChangeNameEvent(this, old, name); + Bukkit.getPluginManager().callEvent(e); + } + + public String getRegionId() { + return region_id; + } + + public Region getRegion() { + return API.getRegion(region_id); + } + + public Location getLocation() { + return location; + } + + public void setLocation(Location location) { + if(location == this.location) + return; + + if(location == null) + return; + + String loc = LocationSerializer.toString(location); + if(loc == null) + return; + + if(this.location != null) + if(loc.equals(LocationSerializer.toString(location))) + return; + + Location old = this.location; + this.location = location; + ChangeLocationEvent e = new ChangeLocationEvent(this, old, location); + Bukkit.getPluginManager().callEvent(e); + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + Type old = this.type; + this.type = type; + if(!type.containsStatus(status)) + setStatus(type.getDefault(), null); + + ChangeTypeEvent e = new ChangeTypeEvent(this, old, type); + Bukkit.getPluginManager().callEvent(e); + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status, Player player) { + if(!type.hasStatus()) + return; + + if(!type.containsStatus(status)) + return; + + if(this.status == status) + return; + + Status old = this.status; + + PreChangeStatusEvent e = new PreChangeStatusEvent(this, player, old, status); + Bukkit.getPluginManager().callEvent(e); + if(e.isCancelled()) + return; + + this.status = status; + ChangeStatusEvent ev = new ChangeStatusEvent(this, player, old, status); + Bukkit.getPluginManager().callEvent(ev); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/attraction/Region.java b/src/main/java/nl/iobyte/themepark/api/attraction/Region.java new file mode 100644 index 0000000..8a6618e --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/attraction/Region.java @@ -0,0 +1,152 @@ +package nl.iobyte.themepark.api.attraction; + +import nl.iobyte.themepark.api.events.region.ChangeDataEvent; +import nl.iobyte.themepark.api.events.region.ChangeLoreEvent; +import nl.iobyte.themepark.api.events.region.ChangeMaterialEvent; +import nl.iobyte.themepark.api.events.region.ChangeNameEvent; +import org.bukkit.Bukkit; +import org.bukkit.Material; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +public class Region { + + private String id, name; + private Material material; + private short data; + private List lore; + private LinkedHashMap attractions = new LinkedHashMap<>(); + + public Region(String id, String name, List lore) { + this.id = id; + this.name = name; + this.material = Material.NAME_TAG; + this.data = 0; + this.lore = lore; + } + + public Region(String id, String name, List lore, Material material, short data) { + this.id = id; + this.name = name; + this.material = material; + this.data = data; + this.lore = lore; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String string) { + if(string == null || string.equals("")) + return; + + if(string.equals(name)) + return; + + String old = name; + name = string; + ChangeNameEvent e = new ChangeNameEvent(this, old, string); + Bukkit.getPluginManager().callEvent(e); + } + + public Material getMaterial() { + return material; + } + + public void setMaterial(Material material) { + if(material == null || material == this.material) + return; + + Material old = this.material; + this.material = material; + ChangeMaterialEvent e = new ChangeMaterialEvent(this, old, material); + Bukkit.getPluginManager().callEvent(e); + } + + public short getData() { + return data; + } + + public void setData(short data) { + if(this.data == data) + return; + + short old = this.data; + this.data = data; + ChangeDataEvent e = new ChangeDataEvent(this, old, data); + Bukkit.getPluginManager().callEvent(e); + } + + public List getLore() { + return lore; + } + + public void setLore(List lore) { + if(this.lore.equals(lore)) + return; + + List old = this.lore; + this.lore = lore; + + ChangeLoreEvent e = new ChangeLoreEvent(this, old, lore); + Bukkit.getPluginManager().callEvent(e); + } + + public void setLore(int i, String string) { + if(lore.size() >= 4 || i >= 4) + return; + + List old = lore; + lore = new ArrayList<>(); + lore.addAll(old); + + if(!string.equals("NULL")) { + if (lore.size() >= i) + for (int a = 0; a <= (i - lore.size()); a++) + lore.add(" "); + + lore.set(i, string); + } else { + lore.remove(i); + } + + ChangeLoreEvent e = new ChangeLoreEvent(this, old, lore); + Bukkit.getPluginManager().callEvent(e); + } + + public LinkedHashMap getAttractions() { + return attractions; + } + + public void setAttractions(LinkedHashMap attractions) { + this.attractions = attractions; + } + + public void addAttraction(Attraction attraction) { + if(attraction == null) + return; + + if(!isAttraction(attraction)) + attractions.put(attraction.getId(), attraction); + } + + public boolean isAttraction(Attraction attraction) { + if(attraction == null) + return false; + + return attractions.containsKey(attraction.getId()); + } + + public void removeAttraction(Attraction attraction) { + if(isAttraction(attraction)) + attractions.remove(attraction.getId()); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java b/src/main/java/nl/iobyte/themepark/api/attraction/component/Status.java similarity index 93% rename from src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java rename to src/main/java/nl/iobyte/themepark/api/attraction/component/Status.java index ea82f85..357ba57 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Status.java +++ b/src/main/java/nl/iobyte/themepark/api/attraction/component/Status.java @@ -1,4 +1,4 @@ -package me.paradoxpixel.themepark.api.attraction.component; +package nl.iobyte.themepark.api.attraction.component; public enum Status { diff --git a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java b/src/main/java/nl/iobyte/themepark/api/attraction/component/Type.java similarity index 95% rename from src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java rename to src/main/java/nl/iobyte/themepark/api/attraction/component/Type.java index e0a0465..ef5dbbd 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/attraction/component/Type.java +++ b/src/main/java/nl/iobyte/themepark/api/attraction/component/Type.java @@ -1,4 +1,4 @@ -package me.paradoxpixel.themepark.api.attraction.component; +package nl.iobyte.themepark.api.attraction.component; public enum Type { diff --git a/src/main/java/nl/iobyte/themepark/api/attraction/manager/StatusManager.java b/src/main/java/nl/iobyte/themepark/api/attraction/manager/StatusManager.java new file mode 100644 index 0000000..af438fa --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/attraction/manager/StatusManager.java @@ -0,0 +1,43 @@ +package nl.iobyte.themepark.api.attraction.manager; + +import nl.iobyte.themepark.api.attraction.component.Status; +import org.bukkit.Material; +import java.util.HashMap; + +public class StatusManager { + + private static HashMap names = new HashMap<>(); + private static HashMap materials = new HashMap<>(); + private static HashMap datas = new HashMap<>(); + private static HashMap teleports = new HashMap<>(); + + public static void addStatus(Status status, String name, Material material, short data, boolean teleport) { + if(status == null || name == null || material == null || data < 0) + return; + + if(name.isEmpty()) + return; + + names.put(status, name); + materials.put(status, material); + datas.put(status, data); + teleports.put(status, teleport); + } + + public static String getName(Status status) { + return names.get(status); + } + + public static Material getMaterial(Status status) { + return materials.get(status); + } + + public static short getData(Status status) { + return datas.get(status); + } + + public static boolean canTeleport(Status status) { + return teleports.get(status); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/ChangeEvent.java b/src/main/java/nl/iobyte/themepark/api/events/ChangeEvent.java new file mode 100644 index 0000000..a6fee04 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/ChangeEvent.java @@ -0,0 +1,33 @@ +package nl.iobyte.themepark.api.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ChangeEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private T before, after; + + public ChangeEvent(T before, T after) { + this.before = before; + this.after = after; + } + + public T getBefore() { + return before; + } + + public T getAfter() { + return after; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeLocationEvent.java b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeLocationEvent.java new file mode 100644 index 0000000..561373d --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeLocationEvent.java @@ -0,0 +1,20 @@ +package nl.iobyte.themepark.api.events.attraction; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ChangeEvent; +import org.bukkit.Location; + +public class ChangeLocationEvent extends ChangeEvent { + + private Attraction attraction; + + public ChangeLocationEvent(Attraction attraction, Location before, Location after) { + super(before, after); + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeNameEvent.java b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeNameEvent.java new file mode 100644 index 0000000..9e7d365 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeNameEvent.java @@ -0,0 +1,19 @@ +package nl.iobyte.themepark.api.events.attraction; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ChangeEvent; + +public class ChangeNameEvent extends ChangeEvent { + + private Attraction attraction; + + public ChangeNameEvent(Attraction attraction, String before, String after) { + super(before, after); + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeStatusEvent.java b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeStatusEvent.java new file mode 100644 index 0000000..51fc33a --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeStatusEvent.java @@ -0,0 +1,27 @@ +package nl.iobyte.themepark.api.events.attraction; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.events.ChangeEvent; +import org.bukkit.entity.Player; + +public class ChangeStatusEvent extends ChangeEvent { + + private Attraction attraction; + private Player player; + + public ChangeStatusEvent(Attraction attraction, Player player, Status before, Status after) { + super(before, after); + this.attraction = attraction; + this.player = player; + } + + public Attraction getAttraction() { + return attraction; + } + + public Player getPlayer() { + return player; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeTypeEvent.java b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeTypeEvent.java new file mode 100644 index 0000000..7d96891 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/attraction/ChangeTypeEvent.java @@ -0,0 +1,20 @@ +package nl.iobyte.themepark.api.events.attraction; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.component.Type; +import nl.iobyte.themepark.api.events.ChangeEvent; + +public class ChangeTypeEvent extends ChangeEvent { + + private Attraction attraction; + + public ChangeTypeEvent(Attraction attraction, Type before, Type after) { + super(before, after); + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/attraction/PreChangeStatusEvent.java b/src/main/java/nl/iobyte/themepark/api/events/attraction/PreChangeStatusEvent.java new file mode 100644 index 0000000..5bc302d --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/attraction/PreChangeStatusEvent.java @@ -0,0 +1,37 @@ +package nl.iobyte.themepark.api.events.attraction; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.events.ChangeEvent; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +public class PreChangeStatusEvent extends ChangeEvent implements Cancellable { + + private Attraction attraction; + private Player player; + private boolean cancel = false; + + public PreChangeStatusEvent(Attraction attraction, Player player, Status before, Status after) { + super(before, after); + this.attraction = attraction; + this.player = player; + } + + public Attraction getAttraction() { + return attraction; + } + + public Player getPlayer() { + return player; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean b) { + cancel = b; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/region/ChangeDataEvent.java b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeDataEvent.java new file mode 100644 index 0000000..7ef4cc3 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeDataEvent.java @@ -0,0 +1,19 @@ +package nl.iobyte.themepark.api.events.region; + +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.events.ChangeEvent; + +public class ChangeDataEvent extends ChangeEvent { + + private Region region; + + public ChangeDataEvent(Region region, short before, short after) { + super(before, after); + this.region = region; + } + + public Region getRegion() { + return region; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/region/ChangeLoreEvent.java b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeLoreEvent.java new file mode 100644 index 0000000..8cb17fa --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeLoreEvent.java @@ -0,0 +1,20 @@ +package nl.iobyte.themepark.api.events.region; + +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.events.ChangeEvent; +import java.util.List; + +public class ChangeLoreEvent extends ChangeEvent> { + + private Region region; + + public ChangeLoreEvent(Region region, List before, List after) { + super(before, after); + this.region = region; + } + + public Region getRegion() { + return region; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/region/ChangeMaterialEvent.java b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeMaterialEvent.java new file mode 100644 index 0000000..e355c26 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeMaterialEvent.java @@ -0,0 +1,20 @@ +package nl.iobyte.themepark.api.events.region; + +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.events.ChangeEvent; +import org.bukkit.Material; + +public class ChangeMaterialEvent extends ChangeEvent { + + private Region region; + + public ChangeMaterialEvent(Region region, Material before, Material after) { + super(before, after); + this.region = region; + } + + public Region getRegion() { + return region; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/region/ChangeNameEvent.java b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeNameEvent.java new file mode 100644 index 0000000..c7513be --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/region/ChangeNameEvent.java @@ -0,0 +1,19 @@ +package nl.iobyte.themepark.api.events.region; + +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.events.ChangeEvent; + +public class ChangeNameEvent extends ChangeEvent { + + private Region region; + + public ChangeNameEvent(Region region, String before, String after) { + super(before, after); + this.region = region; + } + + public Region getRegion() { + return region; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/ridecount/ChangeCountEvent.java b/src/main/java/nl/iobyte/themepark/api/events/ridecount/ChangeCountEvent.java new file mode 100644 index 0000000..254ea10 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/ridecount/ChangeCountEvent.java @@ -0,0 +1,34 @@ +package nl.iobyte.themepark.api.events.ridecount; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ChangeEvent; +import nl.iobyte.themepark.api.ridecount.AttractionCount; + +import java.util.UUID; + +public class ChangeCountEvent extends ChangeEvent { + + private Attraction attraction; + private AttractionCount counter; + private UUID uuid; + + public ChangeCountEvent(Attraction attraction, AttractionCount counter, UUID uuid, int before, int after) { + super(before, after); + this.attraction = attraction; + this.counter = counter; + this.uuid = uuid; + } + + public Attraction getAttraction() { + return attraction; + } + + public AttractionCount getCounter() { + return counter; + } + + public UUID getUUID() { + return uuid; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/events/ridecount/SetCountEvent.java b/src/main/java/nl/iobyte/themepark/api/events/ridecount/SetCountEvent.java new file mode 100644 index 0000000..b694a9f --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/events/ridecount/SetCountEvent.java @@ -0,0 +1,33 @@ +package nl.iobyte.themepark.api.events.ridecount; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ChangeEvent; +import nl.iobyte.themepark.api.ridecount.AttractionCount; +import java.util.UUID; + +public class SetCountEvent extends ChangeEvent { + + private Attraction attraction; + private AttractionCount counter; + private UUID uuid; + + public SetCountEvent(Attraction attraction, AttractionCount counter, UUID uuid, int before, int after) { + super(before, after); + this.attraction = attraction; + this.counter = counter; + this.uuid = uuid; + } + + public Attraction getAttraction() { + return attraction; + } + + public AttractionCount getCounter() { + return counter; + } + + public UUID getUUID() { + return uuid; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/ridecount/AttractionCount.java b/src/main/java/nl/iobyte/themepark/api/ridecount/AttractionCount.java new file mode 100644 index 0000000..5a4c408 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/ridecount/AttractionCount.java @@ -0,0 +1,92 @@ +package nl.iobyte.themepark.api.ridecount; + +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent; +import nl.iobyte.themepark.api.events.ridecount.SetCountEvent; +import org.bukkit.Bukkit; + +import java.util.HashMap; +import java.util.UUID; + +public class AttractionCount { + + private Attraction attraction; + private HashMap counts = new HashMap<>(); + + public AttractionCount(Attraction attraction) { + this.attraction = attraction; + } + + public Attraction getAttraction() { + return attraction; + } + + public void addCount(RideCount rideCount) { + if(rideCount == null) + return; + + if(!attraction.getId().equals(rideCount.getAttraction().getId())) + return; + + counts.put(rideCount.getUUID(), rideCount); + } + + public boolean hasCount(UUID uuid) { + if(uuid == null) + return false; + + return counts.containsKey(uuid); + } + + public RideCount getCount(UUID uuid) { + if(!hasCount(uuid)) + return null; + + return counts.get(uuid); + } + + public void removeCount(UUID uuid) { + if(!hasCount(uuid)) + return; + + counts.remove(uuid); + } + + public void addCount(UUID uuid, int amount) { + if(amount < 1) + return; + + int before = 0; + int after = amount; + RideCount count = getCount(uuid); + if(count == null) { + count = new RideCount(uuid, attraction, amount); + counts.put(uuid, count); + } else { + before = count.getCount(); + after += before; + count.addCount(amount); + } + + ChangeCountEvent e = new ChangeCountEvent(attraction, this, uuid, before, after); + Bukkit.getPluginManager().callEvent(e); + } + + public void setCount(UUID uuid, int amount) { + RideCount count = getCount(uuid); + + if(count == null) { + count = new RideCount(uuid, attraction, amount); + counts.put(uuid, count); + } else { + if(count.getCount() == amount) + return; + + int before = count.getCount(); + count.setCount(amount); + SetCountEvent e = new SetCountEvent(attraction, this, uuid, before, amount); + Bukkit.getPluginManager().callEvent(e); + } + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/ridecount/CountManager.java b/src/main/java/nl/iobyte/themepark/api/ridecount/CountManager.java new file mode 100644 index 0000000..452b8c1 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/ridecount/CountManager.java @@ -0,0 +1,73 @@ +package nl.iobyte.themepark.api.ridecount; + +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import java.util.HashMap; +import java.util.UUID; + +public class CountManager { + + private static HashMap counts = new HashMap<>(); + + public static void addCounter(Attraction attraction) { + if(attraction == null) + return; + + if(counts.containsKey(attraction.getId())) + return; + + if(!API.isAttraction(attraction.getId())) + return; + + counts.put(attraction.getId(), new AttractionCount(attraction)); + } + + public static boolean isCounter(String id) { + if(id == null || id.isEmpty()) + return false; + + return counts.containsKey(id); + } + + public static AttractionCount getCounter(String id) { + if(!isCounter(id)) + return null; + + return counts.get(id); + } + + public static void removeCounter(String id) { + if(!isCounter(id)) + return; + + counts.remove(id); + } + + public static void addCount(Attraction attraction, UUID uuid, int amount) { + if(attraction == null) + return; + + AttractionCount count = getCounter(attraction.getId()); + if(count == null) + return; + + count.addCount(uuid, amount); + } + + public static void setCount(Attraction attraction, UUID uuid, int amount) { + if(attraction == null) + return; + + AttractionCount count = getCounter(attraction.getId()); + if(count == null) + return; + + count.setCount(uuid, amount); + } + + public static void removeCount(UUID uuid) { + for(AttractionCount attractionCount : counts.values()) + attractionCount.removeCount(uuid); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/ridecount/RideCount.java b/src/main/java/nl/iobyte/themepark/api/ridecount/RideCount.java new file mode 100644 index 0000000..feb923a --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/ridecount/RideCount.java @@ -0,0 +1,38 @@ +package nl.iobyte.themepark.api.ridecount; + +import nl.iobyte.themepark.api.attraction.Attraction; +import java.util.UUID; + +public class RideCount { + + private UUID uuid; + private Attraction attraction; + private int count; + + public RideCount(UUID uuid, Attraction attraction, int count) { + this.uuid = uuid; + this.attraction = attraction; + this.count = count; + } + + public UUID getUUID() { + return uuid; + } + + public Attraction getAttraction() { + return attraction; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public void addCount(int amount) { + count += amount; + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java b/src/main/java/nl/iobyte/themepark/api/utils/ItemBuilder.java similarity index 90% rename from src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java rename to src/main/java/nl/iobyte/themepark/api/utils/ItemBuilder.java index d9d8009..019bfd2 100644 --- a/src/main/java/me/paradoxpixel/themepark/utils/ItemBuilder.java +++ b/src/main/java/nl/iobyte/themepark/api/utils/ItemBuilder.java @@ -1,13 +1,14 @@ -package me.paradoxpixel.themepark.utils; +package nl.iobyte.themepark.api.utils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ItemBuilder { @@ -43,7 +44,7 @@ public class ItemBuilder { return this; ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Utils.color(name)); + meta.setDisplayName(color(name)); this.item.setItemMeta(meta); return this; } @@ -54,7 +55,7 @@ public class ItemBuilder { ItemMeta meta = item.getItemMeta(); for(String string : lore) - lore.set(lore.indexOf(string), Utils.color(string)); + lore.set(lore.indexOf(string), color(string)); meta.setLore(lore); item.setItemMeta(meta); @@ -108,4 +109,8 @@ public class ItemBuilder { return new ItemBuilder(item); } -} \ No newline at end of file + private String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + +} diff --git a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java b/src/main/java/nl/iobyte/themepark/api/utils/LocationSerializer.java similarity index 75% rename from src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java rename to src/main/java/nl/iobyte/themepark/api/utils/LocationSerializer.java index ab0a920..b6dfac0 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/LocationUtils.java +++ b/src/main/java/nl/iobyte/themepark/api/utils/LocationSerializer.java @@ -1,10 +1,10 @@ -package me.paradoxpixel.themepark.api; +package nl.iobyte.themepark.api.utils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -public class LocationUtils { +public class LocationSerializer { public static String toString(Location location) { if(location == null) @@ -26,22 +26,16 @@ public class LocationUtils { } public static Location toLocation(String string) { - if(string == null || string.isEmpty()) { - System.out.println("LocationUtils: Incorrect String passed"); + if(string == null || string.isEmpty()) return null; - } String[] args = string.split(":"); - if(args.length < 4) { - System.out.println("LocationUtils: Not enough arguments"); + if(args.length < 4) return null; - } World world = Bukkit.getWorld(args[0]); - if(world == null) { - System.out.println("LocationUtils: No world with name: "+args[0]); + if(world == null) return null; - } double x = Double.parseDouble(args[1]); double y = Double.parseDouble(args[2]); diff --git a/src/main/java/nl/iobyte/themepark/command/MainCommand.java b/src/main/java/nl/iobyte/themepark/command/MainCommand.java new file mode 100644 index 0000000..a30dd6f --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/command/MainCommand.java @@ -0,0 +1,403 @@ +package nl.iobyte.themepark.command; + +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.attraction.component.Type; +import nl.iobyte.themepark.api.attraction.manager.StatusManager; +import nl.iobyte.themepark.api.utils.ItemBuilder; +import nl.iobyte.themepark.api.utils.LocationSerializer; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.menu.AttractionLoader; +import nl.iobyte.themepark.menu.AttractionMenu; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.BukkitCommand; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.UUID; + +public class MainCommand extends BukkitCommand { + + private String name; + + public MainCommand(String name) { + super(name); + + this.name = name; + } + + public boolean execute(CommandSender sender,String label, String[] args) { + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + sender.sendMessage(Color.color("&f&L>==== &r&6ThemePark &L&f ====<")); + sender.sendMessage(Color.color("&f/" + name + " help")); + sender.sendMessage(Color.color("&f/" + name + " list")); + sender.sendMessage(Color.color("&f/" + name + " warp ")); + if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) { + sender.sendMessage(Color.color("&f/" + name + " toggleitem")); + sender.sendMessage(Color.color("&f/" + name + " getitem")); + } + + if(sender.hasPermission("themepark.admin")) { + sender.sendMessage(Color.color("&f/" + name + " region create ")); + sender.sendMessage(Color.color("&f/" + name + " region name ")); + sender.sendMessage(Color.color("&f/" + name + " attraction create ")); + sender.sendMessage(Color.color("&f/" + name + " attraction name ")); + sender.sendMessage(Color.color("&f/" + name + " attraction status ")); + sender.sendMessage(Color.color("&f/" + name + " attraction location ")); + } + + return true; + } + + if (args[0].equalsIgnoreCase("list")) { + sender.sendMessage(Color.color("&f&L>==== &r&6ThemePark &f&L ====<")); + if (API.getAttractions().size() == 0) { + sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.notfound"))); + return true; + } + + for (Attraction attraction : API.getAttractions().values()) { + String message = MessageUtil.getMessage("attraction.list"); + message = message.replace("{id}", attraction.getId()); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{region}", attraction.getRegion().getName()); + message = message.replace("{type}", attraction.getType().toString()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + sender.sendMessage(Color.color(message)); + } + + return true; + } + + if(args[0].equalsIgnoreCase("warp")) { + if(args.length < 2) { + sender.sendMessage(Color.color( MessageUtil.getMessage("prefix")+" &4/" + name + " warp ")); + return true; + } + + String id = args[1]; + if(!API.isAttraction(id)) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + if(sender instanceof Player) { + Attraction attraction = API.getAttraction(id); + Player player = (Player) sender; + if(!StatusManager.canTeleport(attraction.getStatus())) { + String message = MessageUtil.getMessage("attraction.teleport.status"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + player.sendMessage(Color.color(message)); + return true; + } + + player.teleport(attraction.getLocation()); + if(player.isInsideVehicle()) + if(player.getVehicle() instanceof Minecart) + return true; + + player.sendMessage(Color.color(MessageUtil.getMessage("attraction.teleport.success").replace("{name}", attraction.getName()))); + return true; + } else { + sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers"))); + return true; + } + } + + if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) { + sender.sendMessage(Color.color(MessageUtil.getMessage("nopermission"))); + return true; + } + + if(args[0].equalsIgnoreCase("toggleitem")) { + if(!(sender instanceof Player)) { + sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers"))); + return true; + } + + Player player = (Player) sender; + UUID uuid = player.getUniqueId(); + + YamlConfig config = ThemeParkPlugin.getInstance().getData(); + boolean b = config.getConfig().getBoolean(uuid.toString() + ".item"); + b = !b; + + config.getConfig().set(uuid.toString() + ".item", b); + config.save(); + + String message = MessageUtil.getMessage("menu-item.toggle"); + message = message.replace("{status}", b ? MessageUtil.getMessage("menu-item.enabled") : MessageUtil.getMessage("menu-item.disabled")); + sender.sendMessage(Color.color(message)); + return true; + } + + if(args[0].equalsIgnoreCase("getitem")) { + YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); + Material material = Material.getMaterial(settings.getConfig().getString("item.material")); + short data = Short.parseShort(settings.getConfig().getString("item.data")); + String name = Color.color(settings.getConfig().getString("item.display-name")); + if(material == null || name.isEmpty()) + return true; + + Player player; + if(args.length >= 2) { + String string = args[1]; + if(Bukkit.getPlayerExact(string) == null) { + String message = MessageUtil.getMessage("noplayer"); + message = message.replace("{name}", string); + sender.sendMessage(Color.color(message)); + return true; + } + + player = Bukkit.getPlayerExact(string); + } else { + if(!(sender instanceof Player)) { + sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers"))); + return true; + } + + player = (Player) sender; + } + + + ItemBuilder builder = new ItemBuilder(material, 1, data); + builder.setName(name); + player.getInventory().addItem(builder.getItem()); + } + + if(!sender.hasPermission("themepark.admin")) { + sender.sendMessage(Color.color(MessageUtil.getMessage("nopermission"))); + return true; + } + + if (args[0].equalsIgnoreCase("region")) { + if(args.length < 2) + return false; + + if (args[1].equalsIgnoreCase("create")) { + if (args.length < 4 ) { + sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " region create ")); + return true; + } + + String id = args[2]; + if (API.isRegion(id)) { + String message = MessageUtil.getMessage("region.exists"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + StringBuilder builder = new StringBuilder(); + builder.append(args[3]); + for(int i = 4; i < args.length; i++) + builder.append(" ").append(args[i]); + + String name = builder.toString(); + Region region = new Region(id, name, new ArrayList<>()); + API.addRegion(region); + AttractionMenu.load(); + AttractionLoader.addRegion(id); + + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + FileConfiguration fc = config.getConfig(); + String path = "regions."+id+"."; + fc.set(path+"name", name); + fc.set(path+"lore", region.getLore()); + config.save(); + + sender.sendMessage(Color.color(MessageUtil.getMessage("region.create").replace("{name}", name))); + return true; + } + + if(args[1].equalsIgnoreCase("name")) { + if (args.length < 4 ) { + sender.sendMessage(Color.color("&f/" + name + " region name ")); + return true; + } + + String id = args[2]; + if(!API.isRegion(id)) { + String message = MessageUtil.getMessage("region.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + StringBuilder builder = new StringBuilder(); + builder.append(args[3]); + for(int i = 4; i < args.length; i++) + builder.append(" ").append(args[i]); + + String name = builder.toString(); + Region region = API.getRegion(id); + region.setName(name); + sender.sendMessage(Color.color(MessageUtil.getMessage("region.name").replace("{name}", region.getName()))); + return true; + } + } + + if (args[0].equalsIgnoreCase("attraction")) { + if(args.length < 2) + return false; + + if (args[1].equalsIgnoreCase("create")) { + if (args.length < 6 ) { + sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction create ")); + return true; + } + + String id = args[2]; + if(!API.isRegion(id)) { + String message = MessageUtil.getMessage("region.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + id = args[3]; + if (API.isAttraction(id)) { + String message = MessageUtil.getMessage("attraction.exists"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + Type type = Type.getType(args[4]); + if(type == null) { + String message = MessageUtil.getMessage("no-type"); + message = message.replace("{type}", args[4]); + sender.sendMessage(Color.color(message)); + return true; + } + + StringBuilder builder = new StringBuilder(); + builder.append(args[5]); + for(int i = 6; i < args.length; i++) + builder.append(" ").append(args[i]); + + String name = builder.toString(); + Attraction attraction = new Attraction(args[3], name, args[2], null, type, type.getDefault()); + API.addAttraction(attraction); + AttractionMenu.load(); + + YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId()); + FileConfiguration fc = config.getConfig(); + String path = "attractions."+attraction.getId()+"."; + fc.set(path+"name", attraction.getName()); + fc.set(path+"type", type.toString()); + fc.set(path+"status", attraction.getStatus().toString()); + config.save(); + + sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.create").replace("{name}", name))); + return true; + } + + if(args[1].equalsIgnoreCase("name")) { + if (args.length < 4 ) { + sender.sendMessage(Color.color("&f/" + name + " attraction name ")); + return true; + } + + String id = args[2]; + if(!API.isAttraction(id)) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + StringBuilder builder = new StringBuilder(); + builder.append(args[3]); + for(int i = 4; i < args.length; i++) + builder.append(" ").append(args[i]); + + String name = builder.toString(); + Attraction attraction = API.getAttraction(id); + attraction.setName(name); + sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.name").replace("{name}", attraction.getName()))); + return true; + } + + if (args[1].equalsIgnoreCase("status")) { + if (args.length < 4 ) { + sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction status ")); + return true; + } + + String id = args[2]; + if (!API.isAttraction(id)) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + Status status = Status.getStatus(args[3].toUpperCase()); + if (status == null) { + String message = MessageUtil.getMessage("no-status"); + message = message.replace("{status}", args[3]); + sender.sendMessage(Color.color(message)); + return true; + } + + Attraction attraction = API.getAttraction(id); + if(!attraction.getType().containsStatus(status)) { + String message = MessageUtil.getMessage("attraction.nostatus"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", status.toString()); + sender.sendMessage(Color.color(message)); + return true; + } + + if(attraction.getStatus() == status) + return true; + + Player player = (sender instanceof Player) ? (Player) sender : null; + attraction.setStatus(status, player); + return true; + } + + if(args[1].equalsIgnoreCase("location")) { + if (args.length < 3 ) { + sender.sendMessage(Color.color("&f/" + name + " attraction location ")); + return true; + } + + String id = args[2]; + if(!API.isAttraction(id)) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", id); + sender.sendMessage(Color.color(message)); + return true; + } + + if(!(sender instanceof Player)) { + sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers"))); + return true; + } + + Attraction attraction = API.getAttraction(id); + Location location = ((Player) sender).getLocation(); + attraction.setLocation(location.clone()); + sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.location").replace("{name}", attraction.getName()))); + return true; + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java b/src/main/java/nl/iobyte/themepark/command/MenuCommand.java similarity index 58% rename from src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java rename to src/main/java/nl/iobyte/themepark/command/MenuCommand.java index 6017db3..b181a90 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/MenuCommand.java +++ b/src/main/java/nl/iobyte/themepark/command/MenuCommand.java @@ -1,7 +1,8 @@ -package me.paradoxpixel.themepark.command; +package nl.iobyte.themepark.command; -import me.paradoxpixel.themepark.attraction.AttractionMenu; -import me.paradoxpixel.themepark.utils.Utils; +import nl.iobyte.themepark.menu.AttractionMenu; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -13,13 +14,16 @@ 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, 1); - return true; + AttractionMenu.open((Player) sender); } else { - sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command")); + sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers"))); } + + return true; } + return false; } } + diff --git a/src/main/java/nl/iobyte/themepark/command/RidecountCommand.java b/src/main/java/nl/iobyte/themepark/command/RidecountCommand.java new file mode 100644 index 0000000..4bb8aac --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/command/RidecountCommand.java @@ -0,0 +1,107 @@ +package nl.iobyte.themepark.command; + +import nl.iobyte.menuapi.map.WeakConcurrentHashMap; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.ridecount.RideCountAPI; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import java.util.Scanner; + +public class RidecountCommand implements CommandExecutor { + + private static WeakConcurrentHashMap data = new WeakConcurrentHashMap<>(5 * 60 * 1000); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!cmd.getName().equalsIgnoreCase("ridecount")) + return false; + + if(args.length == 0 || args[0].equalsIgnoreCase("help")) { + sender.sendMessage(Color.color("&f&L>==== &r&6Ridecount &L&f ====<")); + sender.sendMessage(Color.color("&f/ridecount help")); + sender.sendMessage(Color.color("&f/ridecount get ")); + sender.sendMessage(Color.color("&f/ridecount add ")); + return true; + } + + if(args[0].equalsIgnoreCase("get")) { + if(args.length < 3) { + sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/ridecount get ")); + return true; + } + + if(!API.isAttraction(args[2])) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", args[2]); + sender.sendMessage(Color.color(message)); + return true; + } + + Attraction attraction = API.getAttraction(args[2]); + RideCountAPI.getCount(args[1], attraction).thenAccept(points -> { + if(points < 0) { + sender.sendMessage(Color.color(MessageUtil.getMessage("noplayer").replace("{name}", args[1]))); + return; + } + + String mesage = MessageUtil.getMessage("ridecount.count"); + mesage = mesage.replace("{name}", attraction.getName()); + mesage = mesage.replace("{count}", points.toString()); + sender.sendMessage(Color.color(mesage)); + }); + return true; + } + + if(args[0].equalsIgnoreCase("add")) { + if(args.length < 4) { + sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/ridecount add ")); + return true; + } + + if(!API.isAttraction(args[2])) { + String message = MessageUtil.getMessage("attraction.not"); + message = message.replace("{id}", args[2]); + sender.sendMessage(Color.color(message)); + return true; + } + + if(!isInteger(args[3])) { + sender.sendMessage(Color.color(MessageUtil.getMessage("nonumber").replace("{number}", args[3]))); + return true; + } + + int amount = Integer.parseInt(args[3]); + Attraction attraction = API.getAttraction(args[2]); + RideCountAPI.addCount(args[1], attraction, amount).thenAccept(result -> { + if(!result) { + sender.sendMessage(Color.color(MessageUtil.getMessage("noplayer").replace("{name}", args[1]))); + return; + } + + String mesage = MessageUtil.getMessage("ridecount.add"); + mesage = mesage.replace("{name}", API.getAttraction(args[2]).getName()); + mesage = mesage.replace("{count}", Integer.toString(amount)); + sender.sendMessage(Color.color(mesage)); + }); + return true; + } + + return false; + } + + + + private boolean isInteger(String s) { + int radix = 10; + Scanner sc = new Scanner(s.trim()); + if(!sc.hasNextInt(radix)) return false; + sc.nextInt(radix); + return !sc.hasNext(); + } + +} + diff --git a/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java b/src/main/java/nl/iobyte/themepark/config/YamlConfig.java similarity index 98% rename from src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java rename to src/main/java/nl/iobyte/themepark/config/YamlConfig.java index 5c4f9f3..0b92d9e 100644 --- a/src/main/java/me/paradoxpixel/themepark/config/YamlConfig.java +++ b/src/main/java/nl/iobyte/themepark/config/YamlConfig.java @@ -1,4 +1,4 @@ -package me.paradoxpixel.themepark.config; +package nl.iobyte.themepark.config; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/nl/iobyte/themepark/database/DB.java b/src/main/java/nl/iobyte/themepark/database/DB.java new file mode 100644 index 0000000..0d8c5d9 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/database/DB.java @@ -0,0 +1,77 @@ +package nl.iobyte.themepark.database; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Map; + +public abstract class DB { + + public abstract Connection getConnection(); + + public abstract void closeConnection(); + + public boolean execute(String query, HashMap objects) { + if(query == null || query.isEmpty()) + return false; + + if(getConnection() == null) + return false; + + try { + PreparedStatement statement = getConnection().prepareStatement(query); + statement.closeOnCompletion(); + if(objects != null) + for(Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + return statement.execute(); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + + public int executeUpdate(String query, HashMap objects) { + if (query == null || query.isEmpty()) + return 0; + + if(getConnection() == null) + return 0; + + try { + PreparedStatement statement = getConnection().prepareStatement(query); + statement.closeOnCompletion(); + for (Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + return statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + public ResultSet executeQuery(String query, HashMap objects) { + if (query == null || query.isEmpty()) + return null; + + if (getConnection() == null) + return null; + + try { + PreparedStatement statement = getConnection().prepareStatement(query); + statement.closeOnCompletion(); + if (objects != null) + for (Map.Entry entry : objects.entrySet()) + statement.setObject(entry.getKey(), entry.getValue()); + + return statement.executeQuery(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/main/java/nl/iobyte/themepark/database/DBManager.java b/src/main/java/nl/iobyte/themepark/database/DBManager.java new file mode 100644 index 0000000..3da41b0 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/database/DBManager.java @@ -0,0 +1,90 @@ +package nl.iobyte.themepark.database; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.util.HashMap; + +public class DBManager { + + private static HashMap databases = new HashMap<>(); + + /** + * Add DB to manager + * @param id identifier + * @param db DB Instance + */ + public static void addDatabase(String id, DB db) { + if(id == null || id.isEmpty() || db == null) + return; + + if(databases.containsKey(id)) + return; + + databases.put(id, db); + } + + /** + * Get Database + * @param id identifier + * @return DB Instance + */ + public static DB getDatabase(String id) { + if(id == null || id.isEmpty()) + return null; + + return databases.get(id); + } + + /** + * Database exists + * @param id identifier + * @return boolean + */ + public static boolean hasDatabase(String id) { + if(id == null || id.isEmpty()) + return false; + + return databases.containsKey(id); + } + + /** + * Remove Database + * @param id identifier + */ + public static void removeDatabase(String id) { + DB db = getDatabase(id); + if(db == null) + return; + + db.closeConnection(); + databases.remove(id); + } + + /** + * Close all connections + */ + public static void shutdown() { + for(DB db : databases.values()) + db.closeConnection(); + } + + /** + * Create tabke + * @param db DB Instance + * @param query Query + */ + public static void createTable(DB db, String query) { + if(db == null || query == null || query.isEmpty()) + return; + + try { + Connection connection = db.getConnection(); + PreparedStatement statement = connection.prepareStatement(query); + statement.execute(); + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/nl/iobyte/themepark/database/MySQL.java b/src/main/java/nl/iobyte/themepark/database/MySQL.java new file mode 100644 index 0000000..a78ba00 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/database/MySQL.java @@ -0,0 +1,66 @@ +package nl.iobyte.themepark.database; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import nl.iobyte.themepark.ThemeParkPlugin; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +public class MySQL extends DB { + + private String dbName; + private HikariDataSource source; + private Connection con; + + /** + * Initialize a new connection + * + * @param dbName The database name + */ + public MySQL(String host, int port, String dbName, String username, String password) { + this.dbName = dbName; + HikariConfig config = new HikariConfig(); + config.setPoolName(ThemeParkPlugin.getInstance().getName()); + config.setUsername(username); + config.setPassword(password); + config.setDriverClassName("com.mysql.jdbc.Driver"); + config.setConnectionTestQuery("SELECT 1"); + config.setMaximumPoolSize(1); + + Properties prop = new Properties(); + prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss"); + config.setJdbcUrl("jdbc:mysql://"+host+":"+port+"/"+dbName); + config.setDataSourceProperties(prop); + source = new HikariDataSource(config); + + try { + con = source.getConnection(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * Get connection + * @return Connection Instance + */ + public Connection getConnection() { + return con; + } + + /** + * Close connection + */ + public void closeConnection() { + System.out.println("Closing the database connection for " + dbName + ".db!"); + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + source.close(); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/database/SQLite.java b/src/main/java/nl/iobyte/themepark/database/SQLite.java new file mode 100644 index 0000000..de18c01 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/database/SQLite.java @@ -0,0 +1,84 @@ +package nl.iobyte.themepark.database; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import nl.iobyte.themepark.ThemeParkPlugin; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +public class SQLite extends DB { + + private String dbName; + private HikariDataSource source; + private Connection con; + + /** + * Initialize a new connection + * + * @param dbName The database name + */ + public SQLite(String dbName) { + this.dbName = dbName; + + File dbFile = new File(ThemeParkPlugin.getInstance().getDataFolder(), dbName + ".db"); + if (!dbFile.exists()) { + try { + System.out.println("Generating the " + dbName + ".db!"); + if (!dbFile.createNewFile()) { + System.out.println("Couldn't generate the " + dbName + ".db!"); + return; + } + } catch (IOException e) { + System.out.println("Couldn't generate the " + dbName + ".db!"); + return; + } + } + + HikariConfig config = new HikariConfig(); + config.setPoolName(ThemeParkPlugin.getInstance().getName()); + config.setUsername(null); + config.setPassword(null); + config.setDriverClassName("org.sqlite.JDBC"); + config.setConnectionTestQuery("SELECT 1"); + config.setMaximumPoolSize(1); + + Properties prop = new Properties(); + prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss"); + + config.setJdbcUrl("jdbc:sqlite:" + dbFile.getAbsolutePath()); + config.setDataSourceProperties(prop); + source = new HikariDataSource(config); + + try { + con = source.getConnection(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * Get connection + * @return Connection Instance + */ + public Connection getConnection() { + return con; + } + + /** + * Close connection + */ + public void closeConnection() { + System.out.println("Closing the database connection for " + dbName + ".db!"); + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + source.close(); + } + +} \ No newline at end of file diff --git a/src/main/java/nl/iobyte/themepark/listener/AttractionListener.java b/src/main/java/nl/iobyte/themepark/listener/AttractionListener.java new file mode 100644 index 0000000..8a0e2ec --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/listener/AttractionListener.java @@ -0,0 +1,118 @@ +package nl.iobyte.themepark.listener; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.attraction.ChangeLocationEvent; +import nl.iobyte.themepark.api.events.attraction.ChangeNameEvent; +import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent; +import nl.iobyte.themepark.api.events.attraction.ChangeTypeEvent; +import nl.iobyte.themepark.api.utils.LocationSerializer; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.database.DB; +import nl.iobyte.themepark.database.DBManager; +import nl.iobyte.themepark.menu.AttractionLoader; +import nl.iobyte.themepark.menu.AttractionMenu; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; +import nl.iobyte.workchain.components.Work; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.HashMap; + +public class AttractionListener implements Listener { + + @EventHandler + public void onChange(ChangeStatusEvent e) { + AttractionMenu.updateAttraction(e.getAttraction()); + + Attraction attraction = e.getAttraction(); + YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId()); + config.getConfig().set("attractions." + attraction.getId() + ".status", e.getAfter().toString()); + config.save(); + + Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> { + HashMap obj = new HashMap<>(); + obj.put(1, e.getAfter().toString()); + obj.put(2, attraction.getId()); + + String query ="UPDATE attraction SET status=? WHERE id=?"; + database.execute(query, obj); + }).execute(); + + String command = ThemeParkPlugin.getInstance().getSettings().getConfig().getString("command"); + if(command == null || command.isEmpty()) + return; + + HashMap change = new HashMap<>(); + change.put("{name}", attraction.getName()); + ClickEvent click = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+command+" warp "+attraction.getId()); + HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Color.color(ThemeParkPlugin.getInstance().getMessages().getConfig().getString("attraction.changed.hover")))); + if(hover.getValue()[0].toPlainText().isEmpty()) + hover = null; + + BaseComponent message = MessageUtil.parseTP("attraction.changed."+e.getAfter().toString(), change, click, hover); + if(message == null) + return; + + for(Player player : Bukkit.getOnlinePlayers()) + player.spigot().sendMessage(message); + } + + @EventHandler + public void onChange(ChangeTypeEvent e) { + AttractionMenu.updateAttraction(e.getAttraction()); + + Attraction attraction = e.getAttraction(); + YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId()); + config.getConfig().set("attractions." + attraction.getId() + ".type", e.getAfter().toString()); + config.save(); + + Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> { + HashMap obj = new HashMap<>(); + obj.put(1, e.getAfter().toString()); + obj.put(2, attraction.getStatus().toString()); + obj.put(3, attraction.getId()); + + String query ="UPDATE attraction SET type=?, status=? WHERE id=?"; + database.execute(query, obj); + }).execute(); + } + + @EventHandler + public void onChange(ChangeNameEvent e) { + AttractionMenu.updateAttraction(e.getAttraction()); + + Attraction attraction = e.getAttraction(); + YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId()); + config.getConfig().set("attractions." + attraction.getId() + ".name", e.getAfter()); + config.save(); + + Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> { + HashMap obj = new HashMap<>(); + obj.put(1, e.getAfter()); + obj.put(2, attraction.getId()); + + String query ="UPDATE attraction SET name=? WHERE id=?"; + database.execute(query, obj); + }).execute(); + } + + @EventHandler + public void onChange(ChangeLocationEvent e) { + Attraction attraction = e.getAttraction(); + YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId()); + config.getConfig().set("attractions." + attraction.getId() + ".location", LocationSerializer.toString(e.getAfter())); + config.save(); + + //TODO MapMarker.getMarker().setAttractionMarker(attraction); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/listener/PlayerListener.java b/src/main/java/nl/iobyte/themepark/listener/PlayerListener.java new file mode 100644 index 0000000..0d807a8 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/listener/PlayerListener.java @@ -0,0 +1,190 @@ +package nl.iobyte.themepark.listener; + +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent; +import nl.iobyte.themepark.api.ridecount.CountManager; +import nl.iobyte.themepark.api.utils.ItemBuilder; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.database.DB; +import nl.iobyte.themepark.database.DBManager; +import nl.iobyte.themepark.menu.AttractionMenu; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; +import nl.iobyte.workchain.components.Work; +import org.bukkit.Bukkit; +import org.bukkit.Material; +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.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class PlayerListener implements Listener { + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + UUID uuid = player.getUniqueId(); + + doItem(e.getPlayer()); + loadRideCount(uuid); + } + + @EventHandler + public void onSwitch(PlayerChangedWorldEvent e) { + doItem(e.getPlayer()); + } + + public void doItem(Player player) { + YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); + YamlConfig config = ThemeParkPlugin.getInstance().getData(); + + CompletableFuture fc = new CompletableFuture<>(); + Work.firstTask(() -> { + if(!settings.getConfig().getBoolean("item.enabled")) + return null; + + 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(); + } + + return b; + }).abortIfNull(() -> { + fc.complete(null); + }).nextTask(b -> { + if(!b) + return null; + + Material material = Material.getMaterial(settings.getConfig().getString("item.material")); + short data = Short.parseShort(settings.getConfig().getString("item.data")); + String name = Color.color(settings.getConfig().getString("item.display-name")); + if(material == null || name.isEmpty()) + return null; + + ItemBuilder builder = new ItemBuilder(material, 1, data); + builder.setName(name); + return builder.getItem(); + }).abortIfNull(() -> { + fc.complete(null); + }).lastTask(item -> { + if(settings.getConfig().getBoolean("item.clear")) + player.getInventory().clear(); + + List worlds = settings.getConfig().getStringList("item.worlds"); + if(worlds != null && !worlds.isEmpty()) { + if (worlds.contains(player.getLocation().getWorld().getName())) { + fc.complete(new ItemStack(Material.AIR)); + return; + } + } + + fc.complete(item); + }).setFullExecute(true).execute(); + + fc.thenAccept(item -> { + if(item == null) + return; + + int slot = settings.getConfig().getInt("item.slot"); + player.getInventory().setItem(slot, item); + player.updateInventory(); + }); + } + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); + Material material = Material.getMaterial(config.getConfig().getString("item.material")); + String name = Color.color(config.getConfig().getString("item.display-name")); + if(e.getItem() == null) + return; + + ItemStack item = e.getItem(); + if(item.getType() != material) + return; + + if(!item.hasItemMeta()) + return; + + if(!item.getItemMeta().getDisplayName().equals(name)) + return; + + if(e.getAction() == Action.LEFT_CLICK_AIR || + e.getAction() == Action.LEFT_CLICK_BLOCK) + return; + + e.setCancelled(true); + Player player = e.getPlayer(); + AttractionMenu.open(player); + } + + @EventHandler + public void onQuit(PlayerQuitEvent e) { + Player player = e.getPlayer(); + UUID uuid = player.getUniqueId(); + + CountManager.removeCount(uuid); + } + + private void loadRideCount(UUID uuid) { + Work.firstTask(() -> { + DB db = DBManager.getDatabase("data"); + if(db == null) + return null; + + Connection connection = db.getConnection(); + if(connection == null || connection.isClosed()) + return null; + + PreparedStatement statement = connection.prepareStatement("SELECT points, attraction_id FROM counts WHERE uuid=?"); + statement.setString(1, uuid.toString()); + statement.closeOnCompletion(); + return statement.executeQuery(); + }).abortIfNull().lastTask(result -> { + while(result.next()) { + Attraction attraction = API.getAttraction(result.getString("attraction_id")); + if(attraction == null) + continue; + + int points = result.getInt("points"); + if(points < 0) + continue; + + CountManager.setCount(attraction, uuid, points); + } + + result.close(); + }).setFullExecute(true).execute(); + } + + @EventHandler + public void onChange(ChangeCountEvent e) { + Player player = Bukkit.getPlayer(e.getUUID()); + if(player == null || !player.isOnline()) + return; + + Attraction attraction = e.getAttraction(); + int amount = e.getAfter() - e.getBefore(); + String message = MessageUtil.getMessage("ridecount.message"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{amount}", Integer.toString(amount)); + message = message.replace("{total}", Integer.toString(e.getCounter().getCount(e.getUUID()).getCount())); + player.sendMessage(Color.color(message)); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/listener/RegionListener.java b/src/main/java/nl/iobyte/themepark/listener/RegionListener.java new file mode 100644 index 0000000..e3c221f --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/listener/RegionListener.java @@ -0,0 +1,68 @@ +package nl.iobyte.themepark.listener; + +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.events.region.ChangeDataEvent; +import nl.iobyte.themepark.api.events.region.ChangeLoreEvent; +import nl.iobyte.themepark.api.events.region.ChangeMaterialEvent; +import nl.iobyte.themepark.api.events.region.ChangeNameEvent; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.database.DBManager; +import nl.iobyte.themepark.menu.AttractionMenu; +import nl.iobyte.workchain.components.Work; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import java.util.HashMap; + +public class RegionListener implements Listener { + + @EventHandler + public void onChange(ChangeNameEvent e) { + AttractionMenu.updateRegion(e.getRegion()); + + Region region = e.getRegion(); + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + config.getConfig().set("regions." + region.getId() + ".name", e.getAfter()); + config.save(); + + Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> { + HashMap obj = new HashMap<>(); + obj.put(1, e.getAfter()); + obj.put(2, region.getId()); + + String query ="UPDATE region SET name=? WHERE id=?"; + database.execute(query, obj); + }).execute(); + } + + @EventHandler + public void onChange(ChangeLoreEvent e) { + AttractionMenu.updateRegion(e.getRegion()); + + Region region = e.getRegion(); + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + config.getConfig().set("regions." + region.getId() + ".lore", e.getAfter()); + config.save(); + } + + @EventHandler + public void onChange(ChangeMaterialEvent e) { + AttractionMenu.updateRegion(e.getRegion()); + + Region region = e.getRegion(); + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + config.getConfig().set("regions." + region.getId() + ".material", e.getAfter().toString()); + config.save(); + } + + @EventHandler + public void onChange(ChangeDataEvent e) { + AttractionMenu.updateRegion(e.getRegion()); + + Region region = e.getRegion(); + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + config.getConfig().set("regions." + region.getId() + ".data", e.getAfter()); + config.save(); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java b/src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java new file mode 100644 index 0000000..a882309 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java @@ -0,0 +1,240 @@ +package nl.iobyte.themepark.menu; + +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.attraction.component.Type; +import nl.iobyte.themepark.api.attraction.manager.StatusManager; +import nl.iobyte.themepark.api.utils.LocationSerializer; +import nl.iobyte.themepark.config.YamlConfig; +import nl.iobyte.themepark.database.DB; +import nl.iobyte.themepark.database.DBManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class AttractionLoader { + + private static HashMap configs = new HashMap<>(); + + public static YamlConfig getConfig(String id) { + if(id == null || id.isEmpty()) + return null; + + return configs.get(id); + } + + public static void load() { + loadRegions(); + loadAttractions(); + loadStatusData(); + AttractionMenu.load(); + loadDatabase(); + } + + private static void loadRegions() { + YamlConfig config = ThemeParkPlugin.getInstance().getRegions(); + FileConfiguration fc = config.getConfig(); + if(!fc.contains("regions")) + return; + + ConfigurationSection section = fc.getConfigurationSection("regions"); + if(section == null) + return; + + for(String id : section.getKeys(false)) { + if(API.isRegion(id)) + continue; + + String path = "regions."+id+"."; + String name = fc.getString(path+"name"); + List lore = fc.getStringList(path+"lore"); + if(fc.contains(path+"material")) { + Material material = Material.getMaterial(fc.getString(path + "material")); + short data = Short.parseShort(fc.getString(path + "data")); + Region region = new Region(id, name, lore, material, data); + API.addRegion(region); + continue; + } + + Region region = new Region(id, name, lore); + API.addRegion(region); + } + } + + public static YamlConfig addRegion(String id) { + if(!API.isRegion(id)) + return null; + + File root = new File(ThemeParkPlugin.getInstance().getDataFolder(), "attractions"); + if(!root.exists()) + if(!root.mkdirs()) + return null; + + YamlConfig config = new YamlConfig("attractions/"+id, ThemeParkPlugin.getInstance()); + configs.put(id, config); + return config; + } + + private static void loadAttractions() { + File root = new File(ThemeParkPlugin.getInstance().getDataFolder(), "attractions"); + if(!root.exists()) + if(!root.mkdirs()) + return; + + try { + for(Region region : API.getRegions().values()) { + YamlConfig config = new YamlConfig("attractions/"+region.getId(), ThemeParkPlugin.getInstance()); + configs.put(region.getId(), config); + FileConfiguration fc = config.getConfig(); + if(fc == null) + continue; + + if(!fc.contains("attractions")) { + fc.set("attractions", new ArrayList<>()); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), config::save); + continue; + } + + ConfigurationSection section = fc.getConfigurationSection("attractions"); + if(section == null) + return; + + for(String id : section.getKeys(false)) { + if(API.isAttraction(id)) + continue; + + String path = "attractions."+id+"."; + String name = fc.getString(path+"name"); + Type type = Type.getType(fc.getString(path+"type")); + if(type == null) + continue; + + Status status = Status.getStatus(fc.getString(path+"status")); + if(!type.containsStatus(status)) { + status = type.getDefault(); + fc.set(path+"status", status.toString()); + } + + Location location = LocationSerializer.toLocation(fc.getString(path+".location")); + Attraction attraction = new Attraction(id, name, region.getId(), location, type, status); + API.addAttraction(attraction); + } + + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), config::save); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void loadStatusData() { + YamlConfig config = ThemeParkPlugin.getInstance().getSettings(); + for(Status status : Status.values()) { + String name = "UNKNOWN"; + if(config.getConfig().contains(status.toString() + ".name")) + name = config.getConfig().getString(status.toString() + ".name"); + + Material material = Material.STAINED_CLAY; + if(config.getConfig().contains(status.toString() + ".material")) { + material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material")); + if(material == null) + material = Material.STAINED_CLAY; + } + + short data = 0; + if(config.getConfig().contains(status.toString() + ".data")) { + String string = config.getConfig().getString(status.toString() + ".data"); + if (!string.isEmpty()) + data = Short.parseShort(string); + } + + boolean teleport = false; + if(config.getConfig().contains(status.toString() + ".teleport")) + teleport = config.getConfig().getBoolean(status.toString() + ".teleport"); + + StatusManager.addStatus(status, name, material, data, teleport); + } + } + + private static void loadDatabase() { + DB db = DBManager.getDatabase("public"); + if(db == null) + return; + + boolean b = false; + StringBuilder builder = new StringBuilder(); + for(Region region : API.getRegions().values()) { + if(b) { + builder.append(","); + } else { + b = true; + } + + builder.append("(?,?)"); + } + + + int i = 1; + HashMap obj = new HashMap<>(); + for(Region region : API.getRegions().values()) { + obj.put(i++, region.getId()); + obj.put(i++, region.getName()); + } + + db.execute("INSERT INTO region(id, name) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE name=VALUES(name)", obj); + b = false; + builder = new StringBuilder(); + for(Attraction attraction : API.getAttractions().values()) { + if(b) { + builder.append(","); + } else { + b = true; + } + + builder.append("(?, ?, ?, ?, ?)"); + } + + i = 1; + obj = new HashMap<>(); + for(Attraction attraction : API.getAttractions().values()) { + obj.put(i++, attraction.getId()); + obj.put(i++, attraction.getName()); + obj.put(i++, attraction.getRegionId()); + obj.put(i++, attraction.getType().toString()); + obj.put(i++, attraction.getStatus().toString()); + } + + + db.execute("INSERT INTO attraction(id, name, region_id, type, status) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE name=VALUES(name), region_id=VALUES(region_id), type=VALUES(type), status=VALUES(status)", obj); + b = false; + builder = new StringBuilder(); + for(Status status : Status.values()) { + if(b) { + builder.append(","); + } else { + b = true; + } + + builder.append("(?, ?)"); + } + + i = 1; + obj = new HashMap<>(); + for(Status status : Status.values()) { + obj.put(i++, status.toString()); + obj.put(i++, StatusManager.getName(status)); + } + + db.execute("INSERT INTO status(statusId, statusName) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE statusName=VALUES(statusName)", obj); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java b/src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java new file mode 100644 index 0000000..49bb8d6 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java @@ -0,0 +1,173 @@ +package nl.iobyte.themepark.menu; + +import com.google.common.collect.Iterables; +import nl.iobyte.menuapi.components.Types; +import nl.iobyte.menuapi.item.MenuItem; +import nl.iobyte.menuapi.multi.MenuPage; +import nl.iobyte.menuapi.multi.MultiMenu; +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.Region; +import nl.iobyte.themepark.api.attraction.manager.StatusManager; +import nl.iobyte.themepark.api.utils.ItemBuilder; +import nl.iobyte.themepark.menu.actions.PageAction; +import nl.iobyte.themepark.menu.actions.TPAction; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +public class AttractionMenu { + + private static MultiMenu menu; + private static HashMap reg_slots = new HashMap<>(); + private static HashMap att_slots = new HashMap<>(); + + public static void load() { + LinkedHashMap regions = new LinkedHashMap<>(); + LinkedHashMap> attractions = new LinkedHashMap<>(); + for(Region region : API.getRegions().values()) { + if(region.getAttractions().isEmpty()) { + regions.put(regions.size(), region); + continue; + } + + Iterable> iterable = Iterables.partition(region.getAttractions().values(), 8); + for(List list : iterable) { + regions.put(regions.size(), region); + attractions.put(attractions.size(), list); + } + } + + int region_size = regions.size(); + loadMenu(region_size); + for(int i = 0; i < region_size; i++) { + int start_index = i * 9; + if(region_size > 6) + start_index += (i / 5) * 9; + + int j = 1; + List list = attractions.get(i); + Region region = regions.get(i); + if(region == null) + continue; + + reg_slots.put(region.getId(), start_index); + menu.setItem(start_index, new MenuItem(getRegion(region), true)); + if(list == null) + continue; + + for(Attraction attraction : list) { + MenuItem item = new MenuItem(getAttraction(attraction), true); + item.addActions(Types.NORMAL.getTypesList(), new TPAction(attraction)); + + int slot = start_index + j; + att_slots.put(attraction.getId(), slot); + menu.setItem(slot, item); + j++; + } + } + + if(region_size > 6) { + int page_size = menu.getPageSizes().size(); + for (int i = 0; i < page_size; i++) { + MenuPage page = menu.getPage(i + 1); + int size = page.getSize(); + if (i > 0) + page.setItem(size - 6, getPrevious(i)); + + if (i < (page_size - 1)) + page.setItem(size - 4, getNext(i)); + + ItemBuilder builder = new ItemBuilder(Material.MINECART); + builder.setName("&6Page: &f"+(i + 1)); + page.setItem(size - 5, new MenuItem(builder.getItem(), true)); + } + } + + menu.build(); + } + + public static void updateRegion(Region region) { + if(region == null) + return; + + if(!reg_slots.containsKey(region.getId())) + return; + + int slot = reg_slots.get(region.getId()); + menu.setItem(slot, getRegion(region)); + menu.updateItem(slot); + } + + public static void updateAttraction(Attraction attraction) { + if(attraction == null) + return; + + if(!att_slots.containsKey(attraction.getId())) + return; + + int slot = att_slots.get(attraction.getId()); + menu.setItem(slot, getAttraction(attraction)); + menu.updateItem(slot); + } + + public static void open(Player player) { + open(player, 1); + } + + public static void open(Player player, int page) { + menu.open(player, page); + } + + private static void loadMenu(int regions) { + ArrayList page_sizes = new ArrayList<>(); + if(regions <= 6) { + page_sizes.add(regions * 9); + } else { + int pages = regions / 5; + for (int i = 0; i < pages; i++) + page_sizes.add(54); + + pages = regions % 5; + if (pages > 0) + page_sizes.add(pages * 9 + 9); + } + + menu = new MultiMenu(ThemeParkPlugin.getInstance().getSettings().getConfig().getString("menu-title"), page_sizes); + } + + private static ItemStack getRegion(Region region) { + ItemBuilder builder = new ItemBuilder(region.getMaterial(), 1, region.getData()); + builder.setName(region.getName()).setLore(region.getLore()); + return builder.getItem(); + } + + private static ItemStack getAttraction(Attraction attraction) { + ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus())); + builder.setName(attraction.getName()).setLore(StatusManager.getName(attraction.getStatus())); + return builder.getItem(); + } + + private static MenuItem getNext(int page) { + return getPage("&6&LNext \u23F5", page + 1); + } + + private static MenuItem getPrevious(int page) { + return getPage("&6&L\u23F4 Previous", page - 1); + } + + private static MenuItem getPage(String text, int page) { + ItemBuilder builder = new ItemBuilder(Material.ARROW); + builder.setName(text); + + MenuItem item = new MenuItem(builder.getItem(), true); + item.addActions(new PageAction(page + 1)); + return item; + } + +} diff --git a/src/main/java/nl/iobyte/themepark/menu/actions/PageAction.java b/src/main/java/nl/iobyte/themepark/menu/actions/PageAction.java new file mode 100644 index 0000000..96ef097 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/menu/actions/PageAction.java @@ -0,0 +1,20 @@ +package nl.iobyte.themepark.menu.actions; + +import nl.iobyte.menuapi.action.MenuAction; +import nl.iobyte.themepark.menu.AttractionMenu; +import org.bukkit.entity.Player; + +public class PageAction extends MenuAction { + + private int page; + + public PageAction(int page) { + this.page = page; + } + + @Override + public void execute(Player player) { + AttractionMenu.open(player, page); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java b/src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java new file mode 100644 index 0000000..11c7123 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java @@ -0,0 +1,39 @@ +package nl.iobyte.themepark.menu.actions; + +import nl.iobyte.menuapi.action.MenuAction; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.manager.StatusManager; +import nl.iobyte.themepark.util.Color; +import nl.iobyte.themepark.util.MessageUtil; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class TPAction extends MenuAction { + + private Attraction attraction; + + public TPAction(Attraction attraction) { + this.attraction = attraction; + } + + @Override + public void execute(Player player) { + Location location = attraction.getLocation(); + if(location == null) + return; + + if(!StatusManager.canTeleport(attraction.getStatus())) { + String message = MessageUtil.getMessage("attraction.teleport.status"); + message = message.replace("{name}", attraction.getName()); + message = message.replace("{status}", StatusManager.getName(attraction.getStatus())); + player.sendMessage(Color.color(message)); + return; + } + + player.teleport(location); + String message = MessageUtil.getMessage("attraction.teleport.success"); + message = message.replace("{name}", attraction.getName()); + player.sendMessage(Color.color(message)); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java b/src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java new file mode 100644 index 0000000..a45e8f6 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java @@ -0,0 +1,326 @@ +package nl.iobyte.themepark.ridecount; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import nl.iobyte.menuapi.map.WeakConcurrentHashMap; +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.ridecount.AttractionCount; +import nl.iobyte.themepark.api.ridecount.CountManager; +import nl.iobyte.themepark.database.DB; +import nl.iobyte.themepark.database.DBManager; +import nl.iobyte.workchain.components.Work; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.util.HashMap; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class RideCountAPI { + + private static WeakConcurrentHashMap data = new WeakConcurrentHashMap<>(5 * 60 * 1000); + + public static CompletableFuture getCount(String name, Attraction attraction) { + CompletableFuture fc = new CompletableFuture<>(); + if(name == null || name.isEmpty() || attraction == null) { + fc.complete(-1); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(-1); + return fc; + } + + getData(name).thenAccept(uuid -> { + if(uuid == null) { + fc.complete(-1); + return; + } + + getCount(uuid, attraction).thenAccept(fc::complete); + }); + return fc; + } + + public static CompletableFuture getCount(UUID uuid, Attraction attraction) { + CompletableFuture fc = new CompletableFuture<>(); + if(uuid == null || attraction == null) { + fc.complete(-1); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(-1); + return fc; + } + + AttractionCount count = CountManager.getCounter(attraction.getId()); + if(count != null && count.hasCount(uuid)) { + fc.complete(count.getCount(uuid).getCount()); + return fc; + } + + Work.firstTask(() -> { + DB db = DBManager.getDatabase("data"); + if(db == null) + return null; + + Connection connection = db.getConnection(); + if(connection == null || connection.isClosed()) + return null; + + PreparedStatement statement = connection.prepareStatement("SELECT points FROM counts WHERE uuid=? AND attraction_id=?"); + statement.setString(1, uuid.toString()); + statement.setString(2, attraction.getId()); + statement.closeOnCompletion(); + return statement.executeQuery(); + }).abortIfNull(() -> fc.complete(-1)).nextTask(result -> { + int i = -1; + while(result.next()) { + int points = result.getInt("points"); + if(points < 0) + continue; + + i = points; + } + + result.close(); + return i; + }).lastTask(fc::complete).setFullExecute(true).execute(); + return fc; + } + + public static CompletableFuture addCount(String name, Attraction attraction, int amount) { + CompletableFuture fc = new CompletableFuture<>(); + if(name == null || name.isEmpty() || attraction == null || amount < 0) { + fc.complete(false); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(false); + return fc; + } + + getData(name).thenAccept(uuid -> { + if(uuid == null) { + fc.complete(false); + return; + } + + addCount(uuid, attraction, amount).thenAccept(fc::complete); + }); + return fc; + } + + public static CompletableFuture addCount(UUID uuid, Attraction attraction, int amount) { + CompletableFuture fc = new CompletableFuture<>(); + if(uuid == null || attraction == null || amount < 0) { + fc.complete(false); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(false); + return fc; + } + + AttractionCount count = CountManager.getCounter(attraction.getId()); + if(count != null && count.hasCount(uuid)) + Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> count.addCount(uuid, amount)); + + Work.firstTask(() -> { + DB db = DBManager.getDatabase("data"); + if(db == null) + return null; + + Connection connection = db.getConnection(); + if(connection == null || connection.isClosed()) + return null; + + PreparedStatement statement = connection.prepareStatement("INSERT INTO counts(uuid, attraction_id, points) VALUES (?, ?, ?) ON CONFLICT(uuid, attraction_id) DO UPDATE SET points=points+?"); + statement.setString(1, uuid.toString()); + statement.setString(2, attraction.getId()); + statement.setInt(3, amount); + statement.setInt(4, amount); + statement.closeOnCompletion(); + return statement.executeUpdate() > 0; + }).abortIfNull(() -> fc.complete(false)).lastTask(fc::complete).setFullExecute(true).execute(); + return fc; + } + + private static CompletableFuture getData(String name) { + CompletableFuture fc = new CompletableFuture<>(); + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> { + if(data.containsKey(name)) { + fc.complete(UUID.fromString(data.get(name))); + return; + } + + Player player = Bukkit.getPlayerExact(name); + if(player != null) { + UUID uuid = player.getUniqueId(); + data.put(name, uuid.toString()); + fc.complete(uuid); + return; + } + + try { + JsonObject object = sendGETRequestJSON("https://api.mojang.com/users/profiles/minecraft/" + name); + if(object == null) { + data.put(name, null); + fc.complete(null); + return; + } + + String id = object.get("id").getAsString(); + if(id == null || id.isEmpty()) { + data.put(name, null); + fc.complete(null); + return; + } + + id = fixUUID(id); + UUID uuid = UUID.fromString(id); + data.put(name, id); + fc.complete(uuid); + } catch (Exception e) { + data.put(name, null); + fc.complete(null); + } + }); + + return fc; + } + + public static CompletableFuture> getTop(Attraction attraction, boolean week) { + CompletableFuture> fc = new CompletableFuture<>(); + if(attraction == null) { + fc.complete(null); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(null); + return fc; + } + + Work.firstTask(() -> { + DB db = DBManager.getDatabase("data"); + if(db == null) + return null; + + Connection connection = db.getConnection(); + if(connection == null || connection.isClosed()) + return null; + + String timeSort = week ? "YEARWEEK(created_at, 1)=YEARWEEK(CURDATE(), 1)" : "DAYOFYEAR(created_at)=DAYOFYEAR(CURDATE())"; + PreparedStatement statement = connection.prepareStatement("SELECT uuid, SUM(points) AS count FROM ridecount WHERE attraction_id=? AND "+timeSort+" AND YEAR(created_at)=YEAR(CURDATE()) GROUP BY uuid ORDER BY points DESC LIMIT 3"); + statement.setString(1, attraction.getId()); + statement.closeOnCompletion(); + return statement.executeQuery(); + }).abortIfNull(() -> fc.complete(null)).nextTask(result -> { + HashMap top = new HashMap<>(); + while(result.next()) { + UUID uuid = UUID.fromString(result.getString("uuid")); + int points = result.getInt("points"); + if(points < 0) + continue; + + top.put(uuid, points); + } + + result.close(); + return top; + }).lastTask(fc::complete).setFullExecute(true).execute(); + return fc; + } + + public static CompletableFuture> getTopTotal(Attraction attraction) { + CompletableFuture> fc = new CompletableFuture<>(); + if(attraction == null) { + fc.complete(null); + return fc; + } + + if(!API.isAttraction(attraction.getId())) { + fc.complete(null); + return fc; + } + + Work.firstTask(() -> { + DB db = DBManager.getDatabase("data"); + if(db == null) + return null; + + Connection connection = db.getConnection(); + if(connection == null || connection.isClosed()) + return null; + + PreparedStatement statement = connection.prepareStatement("SELECT uuid, SUM(points) AS count FROM ridecount WHERE attraction_id=? GROUP BY uuid ORDER BY points DESC LIMIT 3"); + statement.setString(1, attraction.getId()); + statement.closeOnCompletion(); + return statement.executeQuery(); + }).abortIfNull(() -> fc.complete(null)).nextTask(result -> { + HashMap top = new HashMap<>(); + while(result.next()) { + UUID uuid = UUID.fromString(result.getString("uuid")); + int points = result.getInt("points"); + if(points < 0) + continue; + + top.put(uuid, points); + } + + result.close(); + return top; + }).lastTask(fc::complete).setFullExecute(true).execute(); + return fc; + } + + private static String fixUUID(String uuid) { + if(uuid == null || uuid.isEmpty()) + return null; + + StringBuilder sb = new StringBuilder(uuid); + sb.insert(8, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(13, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(18, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(23, "-"); + + return sb.toString(); + } + + private static JsonObject sendGETRequestJSON(String uri) throws IOException { + URL url = new URL(uri); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + con.setRequestProperty("User-Agent", "Mozilla/5.0"); + int code = con.getResponseCode(); + if (code == 404) + return null; + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + response.append(inputLine); + + in.close(); + JsonParser parser = new JsonParser(); + return parser.parse(response.toString()).getAsJsonObject(); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/util/Color.java b/src/main/java/nl/iobyte/themepark/util/Color.java new file mode 100644 index 0000000..90583d3 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/util/Color.java @@ -0,0 +1,11 @@ +package nl.iobyte.themepark.util; + +import org.bukkit.ChatColor; + +public class Color { + + public static String color(String str) { + return ChatColor.translateAlternateColorCodes('&', str); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/util/MessageUtil.java b/src/main/java/nl/iobyte/themepark/util/MessageUtil.java new file mode 100644 index 0000000..4158283 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/util/MessageUtil.java @@ -0,0 +1,82 @@ +package nl.iobyte.themepark.util; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import nl.iobyte.themepark.ThemeParkPlugin; +import nl.iobyte.themepark.config.YamlConfig; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MessageUtil { + + private static YamlConfig config = ThemeParkPlugin.getInstance().getMessages(); + + public static boolean isMessage(String string) { + return config.getConfig().contains(string); + } + + public static String getMessage(String string) { + if(!isMessage(string)) + return ""; + + String message = config.getConfig().getString(string); + if(isMessage("prefix")) + message = message.replace("{prefix}", config.getConfig().getString("prefix")); + + return message; + } + + public static BaseComponent parseTP(String string, HashMap change, ClickEvent click, HoverEvent hover) { + String message = getMessage(string); + for(Map.Entry entrySet : change.entrySet()) + message = message.replace(entrySet.getKey(), entrySet.getValue()); + + message = Color.color(message); + if(click != null) { + String regex = "(.*)\\[TP\\](.*?)\\[/TP\\](.*)"; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(message); + while (m.find()) { + String first = m.group(1); + String middle = m.group(2); + String last = m.group(3); + + BaseComponent[] components = TextComponent.fromLegacyText(first); + BaseComponent component = components[0]; + for(int i = 1; i < components.length; i++) + component.addExtra(components[i]); + + components = TextComponent.fromLegacyText(middle); + BaseComponent compClick = components[0]; + for(int i = 1; i < components.length; i++) + compClick.addExtra(components[i]); + + compClick.setClickEvent(click); + if(hover != null) + compClick.setHoverEvent(hover); + + component.addExtra(compClick); + components = TextComponent.fromLegacyText(last); + BaseComponent compLast = components[0]; + for (BaseComponent baseComponent : components) component.addExtra(baseComponent); + + component.addExtra(compLast); + return component; + } + } + + BaseComponent[] components = TextComponent.fromLegacyText(message); + BaseComponent component = components[0]; + for(int i = 1; i < components.length; i++) + component.addExtra(components[i]); + + return component; + } + +} diff --git a/src/main/resources/attraction.yml b/src/main/resources/attraction.yml deleted file mode 100644 index 1eb28e1..0000000 --- a/src/main/resources/attraction.yml +++ /dev/null @@ -1,40 +0,0 @@ -region: - global: - name: "&5Global" - lore: - - "&5Global Locations" - fantasy: - name: "&aFantasy" - lore: - - "&aFantasy Themed rides" - multiple: - name: "&fMultiple" - lore: - - "&fYou can have" - - "&fMultiple lines" - - "&fWith Lore" - -attraction: - ride1: - name: "&aRide #1" - region_id: "fantasy" - type: RIDE - status: CLOSED - location: "world:0:0:0" - show1: - name: "&aFirst Show" - region_id: "fantasy" - type: SHOW - status: INACTIVE - location: "world:0:0:0" - global1: - name: "&aFirst Global" - region_id: "global" - type: GLOBAL - location: "world:0:0:0" - random: - name: "&fRandom" - type: RIDE - status: CLOSED - region_id: multiple - location: "world:0:0:0" \ No newline at end of file diff --git a/src/main/resources/message.yml b/src/main/resources/message.yml deleted file mode 100644 index 9bc27ca..0000000 --- a/src/main/resources/message.yml +++ /dev/null @@ -1,42 +0,0 @@ -prefix: "&6Themepark&f:" - -onlyplayers: "{prefix} &4Only players can use this command" -nopermission: "{prefix} &4You don't have permission to use this command" -noplayer: "{prefix} &4No player found with name: {name}" -nonumber: "&6Themepark&f: &4{number} &4is not a valid number" - -reloaded: "{prefix} &aThe plugin has been reloaded" - -menu: - item: - enabled: "&aENABLED" - disabled: "&4DISABLED" - toggle: "{prefix} &aMenu item has been {status}" - -region: - not: "{prefix} &4There is no region with ID: {id}" - changed: - name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}" - lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}" - -status: - not: "{prefix} &4There is no status named: {status}" - -attraction: - notfound: "&4No attractions found" - list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}" - not: "{prefix} &4There is no attraction with ID: {id}" - nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}" - changed: - status: - CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction" - OPEN: "{prefix} &fAttraction: {name} &fhas been &aOpened" - CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed" - MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance" - MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction" - ACTIVE: "{prefix} &fShow: {name} &fis now &aActive" - INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active" - location: "&6ThemePark&f: &aChanged locatation of attraction: {name} &ato your current location" - teleport: - status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}" - success: "{prefix} &ayou have been teleported to the attraction: {name}" \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..6890151 --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,47 @@ +prefix: "&6<hemePark&f:" +onlyplayers: "{prefix} &4Only players can use this command" +nopermission: "{prefix} &4You don't have permission to use this command" +noplayer: "{prefix} &4No player found with name: {name}" +nonumber: "&6Themepark&f: &4{number} &4is not a valid number" + +menu-item: + enabled: "&aENABLED" + disabled: "&4DISABLED" + toggle: "{prefix} &aMenu item has been {status}" + +no-type: "{prefix} &4There is no type named: {type}" +no-status: "{prefix} &4There is no status named: {status}" + +region: + not: "{prefix} &4There is no region with ID: {id}" + create: "{prefix} &aSuccessfully created region with name: &r{name}" + exists: "{prefix} &4There already is a region with ID: {id}" + name: "{prefix} &aChanged name of region to: &r{name}" + +ridecount: + count: "{prefix} &fplayer has a ridecount of: &6{count} &ffor attraction {name}" + set: "{prefix} &fChanged ridecount of player to: &6{count} &ffor attraction {name}" + add: "{prefix} &fAdded &6{count} &fto ridecount of player for attraction {name}" + message: "{prefix} &fYou have ridden the attraction {name} &6{amount}&Lx &r&ffor a total of &6{total}&Lx" + +attraction: + exists: "{prefix} &4There already is a region with ID: {id}" + create: "{prefix} &aSuccessfully created attraction with name: &r{name}" + notfound: "&4No attractions found" + list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}" + not: "{prefix} &4There is no attraction with ID: {id}" + nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}" + changed: + hover: "&6Click to Warp" + CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction" + OPEN: "{prefix} &fAttraction: [TP]{name}[/TP] &fhas been &aOpened" + CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed" + MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance" + MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction" + ACTIVE: "{prefix} &fShow: {name} &fis now &aActive" + INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active" + location: "{prefix} &aChanged locatation of attraction: {name} &ato your current location" + name: "{prefix} &aChanged name of attraction to: &r{name}" + teleport: + status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}" + success: "{prefix} &ayou have been teleported to the attraction: {name}" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6fd307e..2497e1c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,9 @@ name: ThemePark -version: 1.4.1 -main: me.paradoxpixel.themepark.ThemeParkPlugin -author: ParadoxPixel -softdepend: [PlaceholderAPI,dynmap] +version: 2.0 +main: nl.iobyte.themepark.ThemeParkPlugin +author: IOByte +website: "https://www.iobyte.nl/" +softdepend: [dynmap,Multiverse-Core,MultiWorld] commands: - status: \ No newline at end of file + status: + ridecount: \ No newline at end of file diff --git a/src/main/resources/regions.yml b/src/main/resources/regions.yml new file mode 100644 index 0000000..e6ce961 --- /dev/null +++ b/src/main/resources/regions.yml @@ -0,0 +1,12 @@ +regions: + region_1: + name: '&4First Region' + lore: + - '&fFirst line of Lore' + material: IRON_BLOCK + data: 0 + region_2: + name: '&4Second Region' + lore: + - '&fFirst line of Lore' + - '&fSecond line of Lore' \ No newline at end of file diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index f188b3d..4d51e3b 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -1,37 +1,27 @@ -command: 'themepark' - -sign: - name: "[ThemePark]" - title: "&f[&6ThemePark&f]" - -menu: - title: "&6StatusMenu" - -inventory: - clear: true +command: 'tp' +workers: 2 +menu-title: "&6StatusMenu" item: enabled: true - material: NETHER_STAR - display-name: 'Themepark' + material: 'NETHER_STAR' + data: 0 + display-name: '&6Themepark' slot: 4 + clear: true worlds: - world_nether - world_the_end mysql: enabled: false - host: 'localhost' + host: "localhost" port: 3306 - database: 'database' - user: 'username' - password: 'password' + database: "themepark" + user: "root" + pass: "" url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false' -region: - material: NAME_TAG - data: 0 - CONSTRUCTION: name: "&7Under Construction" material: STAINED_CLAY From 2bd9c305bb9f056e9d0135d052f42969463f1be5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 6 Jun 2021 14:16:41 +0200 Subject: [PATCH 24/25] Fixed some stuff --- .idea/ThemePark.iml | 53 +++++- .idea/compiler.xml | 1 - .idea/misc.xml | 3 + dependency-reduced-pom.xml | 58 +++++- pom.xml | 24 ++- .../nl/iobyte/themepark/ThemeParkPlugin.java | 35 +++- .../java/nl/iobyte/themepark/api/API.java | 34 ++++ .../themepark/api/attraction/Attraction.java | 2 +- .../themepark/api/attraction/Region.java | 3 +- .../attraction/CreateAttractionEvent.java | 29 +++ .../attraction/RemoveAttractionEvent.java | 29 +++ .../api/events/region/CreateRegionEvent.java | 29 +++ .../api/events/region/RemoveRegionEvent.java | 29 +++ .../ridecount/PreProcessCountEvent.java | 46 +++++ .../api/ridecount/AttractionCount.java | 11 +- .../iobyte/themepark/command/MainCommand.java | 64 ++++++- .../themepark/command/RidecountCommand.java | 65 +++++-- .../java/nl/iobyte/themepark/database/DB.java | 61 +++--- .../iobyte/themepark/database/DBManager.java | 9 +- .../nl/iobyte/themepark/database/MySQL.java | 29 +-- .../nl/iobyte/themepark/database/SQLite.java | 42 ++-- .../nl/iobyte/themepark/dynmap/MapMarker.java | 54 ++++++ .../listener/AttractionListener.java | 76 ++++++-- .../themepark/listener/PlayerListener.java | 107 ++++++----- .../themepark/listener/RegionListener.java | 60 +++++- .../themepark/listener/SignListener.java | 104 ++++++++++ .../themepark/menu/AttractionLoader.java | 91 +++++---- .../iobyte/themepark/menu/AttractionMenu.java | 40 ++-- .../themepark/ridecount/RideCountAPI.java | 161 +++++++++------- .../nl/iobyte/themepark/sign/SignManager.java | 180 ++++++++++++++++++ .../nl/iobyte/themepark/sign/StatusSign.java | 44 +++++ .../themepark/traincarts/TCRideCount.java | 115 +++++++++++ .../nl/iobyte/themepark/util/MessageUtil.java | 1 - .../themepark/util/SpigotPlayerSelector.java | 125 ++++++++++++ src/main/resources/messages.yml | 2 + src/main/resources/plugin.yml | 4 +- src/main/resources/settings.yml | 6 +- 37 files changed, 1511 insertions(+), 315 deletions(-) create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/CreateAttractionEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/attraction/RemoveAttractionEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/CreateRegionEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/region/RemoveRegionEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/api/events/ridecount/PreProcessCountEvent.java create mode 100644 src/main/java/nl/iobyte/themepark/dynmap/MapMarker.java create mode 100644 src/main/java/nl/iobyte/themepark/listener/SignListener.java create mode 100644 src/main/java/nl/iobyte/themepark/sign/SignManager.java create mode 100644 src/main/java/nl/iobyte/themepark/sign/StatusSign.java create mode 100644 src/main/java/nl/iobyte/themepark/traincarts/TCRideCount.java create mode 100644 src/main/java/nl/iobyte/themepark/util/SpigotPlayerSelector.java diff --git a/.idea/ThemePark.iml b/.idea/ThemePark.iml index f63550d..5721d0d 100644 --- a/.idea/ThemePark.iml +++ b/.idea/ThemePark.iml @@ -1,5 +1,5 @@ - + @@ -25,7 +25,56 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index eb0155b..4dc3212 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -7,7 +7,6 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b661a5..660162b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + +