From f9100dd560e66c9ab3f30c8217bb1fa06bf7c4aa Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 17 Feb 2019 13:03:20 +0100 Subject: [PATCH] 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: