From 317e33a542bfef8bed1e96ff48acf281db1f4a2f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 19 Jan 2019 23:44:14 +0100 Subject: [PATCH] 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)); }