3
0
Fork 0
This commit is contained in:
BuildTools 2019-02-17 13:03:20 +01:00
parent d9c80259c5
commit f9100dd560
6 changed files with 58 additions and 14 deletions

View file

@ -11,7 +11,7 @@
<groupId>me.paradoxpixel</groupId> <groupId>me.paradoxpixel</groupId>
<artifactId>themepark</artifactId> <artifactId>themepark</artifactId>
<version>1.1</version> <version>1.2</version>
<dependencies> <dependencies>
<dependency> <dependency>

View file

@ -32,6 +32,9 @@ public class API {
} }
public static boolean isRegion(String id) { public static boolean isRegion(String id) {
if(id == null || id.isEmpty())
return false;
return regions.containsKey(id.toLowerCase()); return regions.containsKey(id.toLowerCase());
} }
@ -43,6 +46,9 @@ public class API {
} }
public static Region getRegion(String id) { public static Region getRegion(String id) {
if(id == null || id.isEmpty())
return null;
return regions.get(id.toLowerCase()); return regions.get(id.toLowerCase());
} }
@ -87,14 +93,23 @@ public class API {
} }
public static boolean isAttraction(String id) { public static boolean isAttraction(String id) {
if(id == null || id.isEmpty())
return false;
return attractions.containsKey(id.toLowerCase()); return attractions.containsKey(id.toLowerCase());
} }
public static Attraction getAttraction(String id) { public static Attraction getAttraction(String id) {
if(id == null || id.isEmpty())
return null;
return attractions.get(id.toLowerCase()); return attractions.get(id.toLowerCase());
} }
public static Attraction getAttractionFromName(String name) { public static Attraction getAttractionFromName(String name) {
if(name == null || name.isEmpty())
return null;
for(Attraction attraction : attractions.values()) { for(Attraction attraction : attractions.values()) {
if(!color(attraction.getName()).equals(name)) if(!color(attraction.getName()).equals(name))
continue; continue;

View file

@ -2,6 +2,7 @@ package me.paradoxpixel.themepark.command;
import me.paradoxpixel.themepark.ThemeParkPlugin; import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.API; 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.Attraction;
import me.paradoxpixel.themepark.api.attraction.Region; import me.paradoxpixel.themepark.api.attraction.Region;
import me.paradoxpixel.themepark.api.attraction.component.Status; 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.Message;
import me.paradoxpixel.themepark.utils.Utils; import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.command.defaults.BukkitCommand;
@ -23,6 +25,7 @@ import java.util.UUID;
public class ThemeParkCommand extends BukkitCommand { public class ThemeParkCommand extends BukkitCommand {
private String name; private String name;
private YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
public ThemeParkCommand(String name) { public ThemeParkCommand(String name) {
super(name); super(name);
@ -132,7 +135,7 @@ public class ThemeParkCommand extends BukkitCommand {
config.save(); config.save();
String message = Message.getMessage("menu.item.toggle"); 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)); sender.sendMessage(Utils.color(message));
return true; return true;
} }
@ -197,8 +200,8 @@ public class ThemeParkCommand extends BukkitCommand {
} }
String id = args[1]; String id = args[1];
if (!API.isRegion(id)) { if(!API.isRegion(id)) {
String message = Message.getMessage("region.no"); String message = Message.getMessage("region.not");
message = message.replace("{id}", id); message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message)); sender.sendMessage(Utils.color(message));
return true; return true;
@ -208,10 +211,11 @@ public class ThemeParkCommand extends BukkitCommand {
name = name.replaceAll("_", " "); name = name.replaceAll("_", " ");
Region region = API.getRegion(id); Region region = API.getRegion(id);
if(region.getName().equals(name)) if(!region.getName().equals(name))
return true; region.setName(name);
region.setName(name); config.getConfig().set("region." + id + ".name", name);
config.save();
String message = Message.getMessage("region.changed.name"); String message = Message.getMessage("region.changed.name");
message = message.replace("{id}", id); message = message.replace("{id}", id);
@ -228,7 +232,7 @@ public class ThemeParkCommand extends BukkitCommand {
String id = args[1]; String id = args[1];
if (!API.isRegion(id)) { if (!API.isRegion(id)) {
String message = Message.getMessage("region.no"); String message = Message.getMessage("region.not");
message = message.replace("{id}", id); message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message)); sender.sendMessage(Utils.color(message));
return true; return true;
@ -246,11 +250,12 @@ public class ThemeParkCommand extends BukkitCommand {
lore = lore.replaceAll("_", " "); lore = lore.replaceAll("_", " ");
Region region = API.getRegion(id); Region region = API.getRegion(id);
if(region.getLore().size() > i && region.getLore().get(i).equals(lore)) if(region.getLore().size() > i && region.getLore().get(i).equals(lore))
return true; return true;
region.setLore(i, lore); region.setLore(i, lore);
config.getConfig().set("region." + id + ".lore", region.getLore());
config.save();
String message = Message.getMessage("region.changed.lore"); String message = Message.getMessage("region.changed.lore");
message = message.replace("{id}", id); message = message.replace("{id}", id);
@ -279,8 +284,12 @@ public class ThemeParkCommand extends BukkitCommand {
return true; return true;
} }
Location location = ((Player) sender).getLocation();
config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location));
config.save();
Attraction attraction = API.getAttraction(id); 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()))); sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName())));
return true; return true;
} }
@ -301,7 +310,7 @@ public class ThemeParkCommand extends BukkitCommand {
Status status = Status.getStatus(args[2]); Status status = Status.getStatus(args[2]);
if (status == null) { if (status == null) {
String message = Message.getMessage("status.no"); String message = Message.getMessage("status.not");
message = message.replace("{status}", args[2]); message = message.replace("{status}", args[2]);
sender.sendMessage(Utils.color(message)); sender.sendMessage(Utils.color(message));
return true; return true;
@ -322,6 +331,8 @@ public class ThemeParkCommand extends BukkitCommand {
Player player = (sender instanceof Player) ? (Player) sender : null; Player player = (sender instanceof Player) ? (Player) sender : null;
attraction.setStatus(status, player); attraction.setStatus(status, player);
config.getConfig().set("attraction." + id + ".status", status.toString());
config.save();
return true; return true;
} }

View file

@ -23,6 +23,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(StatusChangeEvent e) { public void onChange(StatusChangeEvent e) {
if(e.getAttraction() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
SignManager.update(e.getAttraction()); SignManager.update(e.getAttraction());
@ -43,6 +46,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(AddAttractionEvent e) { public void onChange(AddAttractionEvent e) {
if(e.getAttraction() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
SignManager.loadSigns(e.getAttraction()); SignManager.loadSigns(e.getAttraction());
@ -56,6 +62,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(RemoveAttractionEvent e) { public void onChange(RemoveAttractionEvent e) {
if(e.getAttraction() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
SignManager.remove(e.getAttraction()); SignManager.remove(e.getAttraction());
@ -73,6 +82,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(AddRegionEvent e) { public void onChange(AddRegionEvent e) {
if(e.getRegion() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@ -85,6 +97,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(ChangeRegionEvent e) { public void onChange(ChangeRegionEvent e) {
if(e.getRegion() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@ -97,6 +112,9 @@ public class ChangeListener implements Listener {
@EventHandler @EventHandler
public void onChange(RemoveRegionEvent e) { public void onChange(RemoveRegionEvent e) {
if(e.getRegion() == null)
return;
AttractionMenu.reload(); AttractionMenu.reload();
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction(); YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();

View file

@ -14,13 +14,13 @@ menu:
toggle: "{prefix} &aMenu item has been {status}" toggle: "{prefix} &aMenu item has been {status}"
region: region:
no: "{prefix} &4There is no region with ID: {id}" not: "{prefix} &4There is no region with ID: {id}"
changed: changed:
name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}" 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}" lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}"
status: status:
no: "{prefix} &4There is no status named: {status}" not: "{prefix} &4There is no status named: {status}"
attraction: attraction:
notfound: "&4No attractions found" notfound: "&4No attractions found"

View file

@ -1,5 +1,5 @@
name: ThemePark name: ThemePark
version: 1.1 version: 1.2
main: me.paradoxpixel.themepark.ThemeParkPlugin main: me.paradoxpixel.themepark.ThemeParkPlugin
author: ParadoxPixel author: ParadoxPixel
commands: commands: