Small Change optimizing future updates
This commit is contained in:
parent
a4425949e6
commit
7a136e28d1
5 changed files with 132 additions and 7 deletions
|
@ -68,11 +68,6 @@ public class API {
|
||||||
regions.remove(id.toLowerCase());
|
regions.remove(id.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearRegions() {
|
|
||||||
regions.clear();
|
|
||||||
attractions.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addAttraction(Attraction attraction) {
|
public static void addAttraction(Attraction attraction) {
|
||||||
if(!isRegion(attraction.getRegion_id()))
|
if(!isRegion(attraction.getRegion_id()))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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.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 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;
|
||||||
|
@ -32,22 +33,42 @@ public class Attraction {
|
||||||
return name;
|
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() {
|
public String getRegion_id() {
|
||||||
return region_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() {
|
public Location getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Location 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;
|
this.location = location;
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return type;
|
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() {
|
public Status getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -25,14 +25,17 @@ public class AttractionMenu {
|
||||||
private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
||||||
private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
||||||
private static GUI gui;
|
private static GUI gui;
|
||||||
|
private static boolean loading = false;
|
||||||
|
|
||||||
private static HashMap<String, Integer> index;
|
private static HashMap<String, Integer> index;
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
|
loading = true;
|
||||||
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();
|
loadItems();
|
||||||
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
|
@ -67,6 +70,7 @@ public class AttractionMenu {
|
||||||
if(section.getKeys(false).isEmpty())
|
if(section.getKeys(false).isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
HashMap<String, Region> regions = API.getRegions();
|
||||||
for(String id : section.getKeys(false)) {
|
for(String id : section.getKeys(false)) {
|
||||||
if(API.getRegions().size() >= 6) {
|
if(API.getRegions().size() >= 6) {
|
||||||
config.getConfig().set("regions." + id, null);
|
config.getConfig().set("regions." + id, null);
|
||||||
|
@ -77,10 +81,20 @@ public class AttractionMenu {
|
||||||
String name = config.getConfig().getString("region." + id + ".name");
|
String name = config.getConfig().getString("region." + id + ".name");
|
||||||
List<String> lore = config.getConfig().getStringList("region." + id + ".lore");
|
List<String> 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);
|
Region region = new Region(id, name, lore);
|
||||||
API.addRegion(region);
|
API.addRegion(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(String string : regions.keySet())
|
||||||
|
API.removeRegion(string);
|
||||||
|
|
||||||
if(!config.getConfig().contains("attraction"))
|
if(!config.getConfig().contains("attraction"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -91,6 +105,7 @@ public class AttractionMenu {
|
||||||
if(section.getKeys(false).isEmpty())
|
if(section.getKeys(false).isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
HashMap<String, Attraction> attractions = API.getAttractions();
|
||||||
for(String id : section.getKeys(false)) {
|
for(String id : section.getKeys(false)) {
|
||||||
String region_id = config.getConfig().getString("attraction." + id + ".region_id");
|
String region_id = config.getConfig().getString("attraction." + id + ".region_id");
|
||||||
if(!API.isRegion(region_id))
|
if(!API.isRegion(region_id))
|
||||||
|
@ -104,12 +119,29 @@ public class AttractionMenu {
|
||||||
Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type"));
|
Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type"));
|
||||||
Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status"));
|
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);
|
Attraction attraction = new Attraction(id, name, region_id, location, type, status);
|
||||||
API.addAttraction(attraction);
|
API.addAttraction(attraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(String string : attractions.keySet())
|
||||||
|
API.removeAttraction(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadItems() {
|
private static void loadItems() {
|
||||||
|
if(loading)
|
||||||
|
return;
|
||||||
|
|
||||||
if(API.getRegions().values().size() == 0)
|
if(API.getRegions().values().size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -147,7 +179,6 @@ public class AttractionMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!b) {
|
if(!b) {
|
||||||
API.getRegion(attraction.getRegion_id()).removeAttraction(attraction);
|
|
||||||
API.removeAttraction(attraction.getId());
|
API.removeAttraction(attraction.getId());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,6 @@ public class ThemeParkCommand extends BukkitCommand {
|
||||||
ThemeParkPlugin.getInstance().getSigns().reload();
|
ThemeParkPlugin.getInstance().getSigns().reload();
|
||||||
ThemeParkPlugin.getInstance().getSettings().reload();
|
ThemeParkPlugin.getInstance().getSettings().reload();
|
||||||
ThemeParkPlugin.getInstance().getMessage().reload();
|
ThemeParkPlugin.getInstance().getMessage().reload();
|
||||||
API.clearRegions();
|
|
||||||
|
|
||||||
StatusManager.load();
|
StatusManager.load();
|
||||||
AttractionMenu.load();
|
AttractionMenu.load();
|
||||||
|
|
Reference in a new issue