3
0
Fork 0

Small Change optimizing future updates

This commit is contained in:
BuildTools 2019-01-19 23:44:14 +01:00
parent 7a136e28d1
commit 317e33a542
5 changed files with 32 additions and 5 deletions

View file

@ -25,6 +25,9 @@ public class TPUtils extends GUIAction {
if(attraction == null) if(attraction == null)
return; return;
if(attraction.getLocation() == null)
return;
if(!StatusManager.canTeleport(attraction.getStatus())) { if(!StatusManager.canTeleport(attraction.getStatus())) {
String message = Message.getMessage("attraction.teleport.status"); String message = Message.getMessage("attraction.teleport.status");
message = message.replace("{name}", attraction.getName()); message = message.replace("{name}", attraction.getName());
@ -33,11 +36,11 @@ public class TPUtils extends GUIAction {
return; return;
} }
player.teleport(attraction.getLocation());
if(player.isInsideVehicle()) if(player.isInsideVehicle())
if(player.getVehicle() instanceof Minecart) if(player.getVehicle() instanceof Minecart)
return; return;
player.teleport(attraction.getLocation());
String message = Message.getMessage("attraction.teleport.success"); String message = Message.getMessage("attraction.teleport.success");
message = message.replace("{name}", attraction.getName()); message = message.replace("{name}", attraction.getName());
player.sendMessage(Utils.color(message)); player.sendMessage(Utils.color(message));

View file

@ -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.PreStatusChangeEvent;
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
import me.paradoxpixel.themepark.api.event.region.ChangeAttractionEvent; import me.paradoxpixel.themepark.api.event.region.ChangeAttractionEvent;
import me.paradoxpixel.themepark.utils.LocationUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -22,7 +23,7 @@ public class Attraction {
this.region_id = region_id; this.region_id = region_id;
this.location = location; this.location = location;
this.type = type; this.type = type;
this.status = type.containsStatus(status) ? status : type.getDefefault(); this.status = type.containsStatus(status) ? status : type.getDefault();
} }
public String getId() { public String getId() {
@ -34,6 +35,9 @@ public class Attraction {
} }
public void setName(String 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); ChangeAttractionEvent event = new ChangeAttractionEvent(this, this.name, name, region_id, region_id, location, location, type, type);
this.name = name; this.name = name;
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -44,6 +48,9 @@ public class Attraction {
} }
public void setRegion_id(String 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); ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, this.region_id, region_id, location, location, type, type);
this.region_id = region_id; this.region_id = region_id;
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -54,6 +61,13 @@ public class Attraction {
} }
public void setLocation(Location location) { 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); ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type);
this.location = location; this.location = location;
Bukkit.getPluginManager().callEvent(event); 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); ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, location, location, this.type, type);
this.type = type; this.type = type;
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if(!type.containsStatus(status))
setStatus(type.getDefault(), null);
} }
public Status getStatus() { public Status getStatus() {
@ -80,6 +96,9 @@ public class Attraction {
if(!type.containsStatus(status)) if(!type.containsStatus(status))
return; return;
if(this.status == status)
return;
PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status); PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) if(event.isCancelled())

View file

@ -3,7 +3,7 @@ package me.paradoxpixel.themepark.api.attraction.component;
public enum Type { public enum Type {
RIDE(true, Status.CLOSED, Status.CONSTRUCTION, Status.OPEN, Status.CLOSED, Status.MAINTENANCE, Status.MALFUNCTION), 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); GLOBAL(false, Status.GLOBAL);
private boolean status; private boolean status;
@ -20,7 +20,7 @@ public enum Type {
return status; return status;
} }
public Status getDefefault() { public Status getDefault() {
return def; return def;
} }

View file

@ -34,8 +34,8 @@ public class AttractionMenu {
gui = new GUI(settings.getConfig().getString("menu.title"), 9); gui = new GUI(settings.getConfig().getString("menu.title"), 9);
index = new HashMap<>(); index = new HashMap<>();
loadData(); loadData();
loadItems();
loading = false; loading = false;
loadItems();
} }
public static void reload() { public static void reload() {
@ -127,6 +127,10 @@ public class AttractionMenu {
attraction.setLocation(location); attraction.setLocation(location);
attraction.setType(type); attraction.setType(type);
attraction.setStatus(status, null); attraction.setStatus(status, null);
if(!type.containsStatus(status)) {
config.getConfig().set("attraction." + id + ".status", type.getDefault().toString());
config.save();
}
continue; continue;
} }

View file

@ -64,6 +64,7 @@ public class ThemeParkCommand extends BukkitCommand {
message = message.replace("{id}", attraction.getId()); message = message.replace("{id}", attraction.getId());
message = message.replace("{name}", attraction.getName()); message = message.replace("{name}", attraction.getName());
message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).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())); message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
sender.sendMessage(Utils.color(message)); sender.sendMessage(Utils.color(message));
} }