338 lines
13 KiB
Java
338 lines
13 KiB
Java
package me.paradoxpixel.themepark.command;
|
|
|
|
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
import me.paradoxpixel.themepark.api.API;
|
|
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
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.Material;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.defaults.BukkitCommand;
|
|
import org.bukkit.entity.Minecart;
|
|
import org.bukkit.entity.Player;
|
|
import java.util.Scanner;
|
|
import java.util.UUID;
|
|
|
|
public class ThemeParkCommand extends BukkitCommand {
|
|
|
|
private String name;
|
|
|
|
public ThemeParkCommand(String name) {
|
|
super(name);
|
|
|
|
this.name = name;
|
|
}
|
|
|
|
public boolean execute(CommandSender sender,String label, String[] args) {
|
|
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
|
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " help"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " list"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " warp [id]"));
|
|
if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) {
|
|
sender.sendMessage(Utils.color("&f/" + name + " toggleitem"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " getitem"));
|
|
}
|
|
|
|
if(sender.hasPermission("themepark.admin")) {
|
|
sender.sendMessage(Utils.color("&f/" + name + " reload"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " regionname [id] [name]"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]"));
|
|
sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]"));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("list")) {
|
|
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
|
|
if (API.getAttractions().size() == 0) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("attraction.notfound")));
|
|
return true;
|
|
}
|
|
|
|
for (Attraction attraction : API.getAttractions().values()) {
|
|
String message = Message.getMessage("attraction.list");
|
|
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("{status}", StatusManager.getName(attraction.getStatus()));
|
|
sender.sendMessage(Utils.color(message));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
if(args[0].equalsIgnoreCase("warp")) {
|
|
if(args.length < 2) {
|
|
sender.sendMessage(Utils.color( "&6Themepark&f: &4/" + name + " warp [id]"));
|
|
return true;
|
|
}
|
|
|
|
String id = args[1];
|
|
if(!API.isAttraction(id)) {
|
|
String message = Message.getMessage("attraction.no");
|
|
message = message.replace("{id}", id);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if(sender instanceof Player) {
|
|
Attraction attraction = API.getAttraction(id);
|
|
Player player = (Player) sender;
|
|
if(!StatusManager.canTeleport(attraction.getStatus())) {
|
|
String message = Message.getMessage("attraction.teleport.status");
|
|
message = message.replace("{name}", attraction.getName());
|
|
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
|
player.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
player.teleport(attraction.getLocation());
|
|
if(player.isInsideVehicle())
|
|
if(player.getVehicle() instanceof Minecart)
|
|
return true;
|
|
|
|
player.sendMessage(Utils.color(Message.getMessage("attraction.teleport.success").replace("{name}", attraction.getName())));
|
|
return true;
|
|
} else {
|
|
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
|
|
return true;
|
|
}
|
|
|
|
if(args[0].equalsIgnoreCase("toggleitem")) {
|
|
if(!(sender instanceof Player)) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
return true;
|
|
}
|
|
|
|
Player player = (Player) sender;
|
|
UUID uuid = player.getUniqueId();
|
|
|
|
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
|
boolean b = config.getConfig().getBoolean(uuid.toString() + ".item");
|
|
b = !b;
|
|
|
|
config.getConfig().set(uuid.toString() + ".item", b);
|
|
config.save();
|
|
|
|
String message = Message.getMessage("menu.item.toggle");
|
|
message = message.replace("{status}", b ? Message.getMessage("enabled") : Message.getMessage("disabled"));
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if(args[0].equalsIgnoreCase("getitem")) {
|
|
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
|
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
|
|
String name = Utils.color(settings.getConfig().getString("item.display-name"));
|
|
if(material == null || name.isEmpty())
|
|
return true;
|
|
|
|
Player player;
|
|
if(args.length >= 2) {
|
|
String string = args[1];
|
|
if(Bukkit.getPlayerExact(string) == null) {
|
|
String message = Message.getMessage("noplayer");
|
|
message = message.replace("{name}", string);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
player = Bukkit.getPlayerExact(string);
|
|
} else {
|
|
if(!(sender instanceof Player)) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
return true;
|
|
}
|
|
|
|
player = (Player) sender;
|
|
}
|
|
|
|
|
|
ItemBuilder builder = new ItemBuilder(material);
|
|
builder.setName(name);
|
|
player.getInventory().addItem(builder.getItem());
|
|
}
|
|
|
|
if(!sender.hasPermission("themepark.admin")) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
|
|
return true;
|
|
}
|
|
|
|
if(args[0].equalsIgnoreCase("reload")) {
|
|
ThemeParkPlugin.getInstance().getData().reload();
|
|
ThemeParkPlugin.getInstance().getAttraction().reload();
|
|
ThemeParkPlugin.getInstance().getSigns().reload();
|
|
ThemeParkPlugin.getInstance().getSettings().reload();
|
|
ThemeParkPlugin.getInstance().getMessage().reload();
|
|
|
|
StatusManager.load();
|
|
AttractionMenu.load();
|
|
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(),() -> {
|
|
ThemeParkPlugin.getInstance().getDatabaseHandler().load();
|
|
});
|
|
sender.sendMessage(Utils.color(Message.getMessage("reloaded")));
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("regionname")) {
|
|
if (args.length < 3) {
|
|
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionname [id] [name]"));
|
|
return true;
|
|
}
|
|
|
|
String id = args[1];
|
|
if (!API.isRegion(id)) {
|
|
String message = Message.getMessage("region.no");
|
|
message = message.replace("{id}", id);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
String name = args[2];
|
|
name = name.replaceAll("_", " ");
|
|
|
|
Region region = API.getRegion(id);
|
|
if(region.getName().equals(name))
|
|
return true;
|
|
|
|
region.setName(name);
|
|
|
|
String message = Message.getMessage("region.changed.name");
|
|
message = message.replace("{id}", id);
|
|
message = message.replace("{name}", name);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("regionlore")) {
|
|
if (args.length < 4) {
|
|
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionlore[id] [index] [lore]"));
|
|
return true;
|
|
}
|
|
|
|
String id = args[1];
|
|
if (!API.isRegion(id)) {
|
|
String message = Message.getMessage("region.no");
|
|
message = message.replace("{id}", id);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
String string = args[2];
|
|
if(!isInteger(string)) {
|
|
sender.sendMessage(Message.getMessage("nonumber").replace("{number}", string));
|
|
return true;
|
|
}
|
|
|
|
int i = Integer.parseInt(string);
|
|
|
|
String lore = args[3];
|
|
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);
|
|
|
|
String message = Message.getMessage("region.changed.lore");
|
|
message = message.replace("{id}", id);
|
|
message = message.replace("{index}", "" + i);
|
|
message = message.replace("{lore}", lore);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("setlocation")) {
|
|
if (args.length < 2 ) {
|
|
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " setlocation [id]"));
|
|
return true;
|
|
}
|
|
|
|
String id = args[1];
|
|
if(!API.isAttraction(id)) {
|
|
String message = Message.getMessage("attraction.no");
|
|
message = message.replace("{id}", id);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if(!(sender instanceof Player)) {
|
|
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
return true;
|
|
}
|
|
|
|
Attraction attraction = API.getAttraction(id);
|
|
attraction.setLocation(((Player) sender).getLocation().clone());
|
|
sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName())));
|
|
return true;
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("attraction")) {
|
|
if (args.length < 3 ) {
|
|
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " attraction [id] [status]"));
|
|
return true;
|
|
}
|
|
|
|
String id = args[1];
|
|
if (!API.isAttraction(id)) {
|
|
String message = Message.getMessage("attraction.no");
|
|
message = message.replace("{id}", id);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
Status status = Status.getStatus(args[2]);
|
|
if (status == null) {
|
|
String message = Message.getMessage("status.no");
|
|
message = message.replace("{status}", args[2]);
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
Attraction attraction = API.getAttraction(id);
|
|
if(!attraction.getType().containsStatus(status)) {
|
|
String message = Message.getMessage("attraction.nostatus");
|
|
message = message.replace("{name}", attraction.getName());
|
|
message = message.replace("{status}", status.toString());
|
|
sender.sendMessage(Utils.color(message));
|
|
return true;
|
|
}
|
|
|
|
if(attraction.getStatus() == status)
|
|
return true;
|
|
|
|
Player player = (sender instanceof Player) ? (Player) sender : null;
|
|
|
|
attraction.setStatus(status, player);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private boolean isInteger(String s) {
|
|
int radix = 10;
|
|
Scanner sc = new Scanner(s.trim());
|
|
if(!sc.hasNextInt(radix)) return false;
|
|
sc.nextInt(radix);
|
|
return !sc.hasNext();
|
|
}
|
|
|
|
}
|