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>
<artifactId>themepark</artifactId>
<version>1.1</version>
<version>1.2</version>
<dependencies>
<dependency>

View file

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

View file

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

View file

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

View file

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

View file

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