Small Change optimizing future updates
This commit is contained in:
parent
7a136e28d1
commit
317e33a542
5 changed files with 32 additions and 5 deletions
|
@ -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));
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Reference in a new issue