update to v2.2.0
This commit is contained in:
@@ -0,0 +1,402 @@
|
|||||||
|
package pers.xanadu.enderdragon.command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.config.Config;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.*;
|
||||||
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
import pers.xanadu.enderdragon.maven.DependencyManager;
|
||||||
|
import pers.xanadu.enderdragon.reward.Chance;
|
||||||
|
import pers.xanadu.enderdragon.config.FileUpdater;
|
||||||
|
import pers.xanadu.enderdragon.task.DragonRespawnTimer;
|
||||||
|
import pers.xanadu.enderdragon.util.MyDragon;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
|
public class MainCommand implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
sendCommandTips(sender);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()){
|
||||||
|
case "parse" : {
|
||||||
|
// if(!(sender instanceof Player)) {
|
||||||
|
// Lang.sendFeedback(sender,Lang.command_only_player);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(sender.isOp()){
|
||||||
|
if(args.length == 2) GroovyManager.invoke("test.groovy", args[1]);
|
||||||
|
else if(args.length == 3) GroovyManager.invoke("test.groovy",args[1],Bukkit.getPlayer(args[2]));
|
||||||
|
// List<Entity> entities = p.getNearbyEntities(50,50,50);
|
||||||
|
// entities.forEach(entity -> {
|
||||||
|
// if(entity instanceof org.bukkit.entity.EnderDragon){
|
||||||
|
// org.bukkit.entity.EnderDragon dragon = (org.bukkit.entity.EnderDragon) entity;
|
||||||
|
// //dragon.setPhase(CHARGE_PLAYER);
|
||||||
|
// //SkillManager.launchDragonFireball(dragon,p.getLocation());
|
||||||
|
// SkillManager.callEnderManReinforce(p,3);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// if(entity instanceof org.bukkit.entity.EnderDragon){
|
||||||
|
//// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
|
||||||
|
//// }
|
||||||
|
//// if(entity instanceof ComplexEntityPart){
|
||||||
|
//// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
|
||||||
|
//// }
|
||||||
|
//// if(entity instanceof ComplexLivingEntity){
|
||||||
|
//// Bukkit.broadcastMessage(entity.getName());//8 EnderDragon
|
||||||
|
//// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case "action" : {
|
||||||
|
if(!sender.isOp()){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length < 4) break;
|
||||||
|
Player p = Bukkit.getPlayerExact(args[1]);
|
||||||
|
if(p==null && "me".equals(args[1]) || "!me".equals(args[1])){
|
||||||
|
if(sender instanceof Player) p = (Player) sender;
|
||||||
|
else p = null;
|
||||||
|
}
|
||||||
|
if(p == null) return false;
|
||||||
|
ActionManager.executeAction(p,args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case "reload" : {
|
||||||
|
if(!sender.hasPermission("ed.reload")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 1){
|
||||||
|
closeAllInventory();
|
||||||
|
reloadAll();
|
||||||
|
Lang.sendFeedback(sender,Lang.command_reload_config);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 2){
|
||||||
|
if(args[1].equalsIgnoreCase("script")){
|
||||||
|
if(DependencyManager.isGroovyLoaded()) GroovyManager.reload();
|
||||||
|
else Lang.sendFeedback(sender,Lang.expansion_groovy_disable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "update" : {
|
||||||
|
if(!sender.hasPermission("ed.update")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 1){
|
||||||
|
try {
|
||||||
|
FileUpdater.update();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "respawn" : {//ed respawn [world_name]
|
||||||
|
if(!sender.hasPermission("ed.respawn")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 1){
|
||||||
|
if(!(sender instanceof Player)){
|
||||||
|
Lang.sendFeedback(sender,"§cConsole usage: /ed respawn [world_name]");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player player = (Player) sender;
|
||||||
|
EnderDragon.getInstance().getDragonManager().initiateRespawn(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(args.length == 2){
|
||||||
|
String world_name = args[1];
|
||||||
|
EnderDragon.getInstance().getDragonManager().initiateRespawn(sender,world_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int size = args.length;
|
||||||
|
StringBuilder builder = new StringBuilder(args[1]);
|
||||||
|
for(int i=2;i<size;i++) builder.append(" ").append(args[i]);
|
||||||
|
EnderDragon.getInstance().getDragonManager().initiateRespawn(sender,builder.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "respawn_cd" : {
|
||||||
|
if(!sender.hasPermission("ed.respawn")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!Config.respawn_cd_enable){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_disable);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//ed respawn_cd get <world_name>
|
||||||
|
if(args.length == 3 && args[1].equalsIgnoreCase("get")){
|
||||||
|
String world_name = args[2];
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(world_name);
|
||||||
|
String value = timer!=null?timer.toString():world_name+": null";
|
||||||
|
Lang.sendFeedback(sender,value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//ed respawn_cd set <world_name> <delay:second>
|
||||||
|
else if(args.length == 4 && args[1].equalsIgnoreCase("set")){
|
||||||
|
String world_name = args[2];
|
||||||
|
World world = Bukkit.getWorld(world_name);
|
||||||
|
if(world == null){
|
||||||
|
Lang.sendFeedback(sender,"§c"+DragonManager.DragonRespawnResult.world_not_found.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(world.getEnvironment() != World.Environment.THE_END){
|
||||||
|
Lang.sendFeedback(sender,"§c"+DragonManager.DragonRespawnResult.world_wrong_env.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int delay = Integer.parseInt(args[3]);
|
||||||
|
TimerManager.setTimer(world_name,new DragonRespawnTimer(world_name,delay));
|
||||||
|
TimerManager.save();
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_set.replaceAll("\\{second}",args[3]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//ed respawn_cd removeAll
|
||||||
|
else if(args.length == 2 && args[1].equalsIgnoreCase("removeAll")){
|
||||||
|
TimerManager.removeAll();
|
||||||
|
TimerManager.save();
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_removeAll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//ed respawn_cd remove <world_name>
|
||||||
|
else if(args.length == 3 && args[1].equalsIgnoreCase("remove")){
|
||||||
|
String world_name = args[2];
|
||||||
|
TimerManager.removeTimer(world_name);
|
||||||
|
TimerManager.save();
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_remove.replaceAll("\\{world}",world_name));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//ed respawn_cd start <world_name>
|
||||||
|
else if(args.length == 3 && args[1].equalsIgnoreCase("start")){
|
||||||
|
String world_name = args[2];
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(world_name);
|
||||||
|
if(timer == null){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_start_none);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(timer.isRunning()){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_start_already_started);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TimerManager.startTimer(world_name);
|
||||||
|
Lang.sendFeedback(sender,Lang.command_respawn_cd_start_succeed);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "drop" : {
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
Lang.sendFeedback(sender,Lang.command_only_player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length < 2) break;
|
||||||
|
Player p = (Player) sender;
|
||||||
|
switch (args[1].toLowerCase()){
|
||||||
|
case "gui" : {
|
||||||
|
if(!sender.hasPermission("ed.drop.gui")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 2){
|
||||||
|
GuiManager.openGui(p, Config.main_gui,false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 3){
|
||||||
|
String key = args[2];
|
||||||
|
MyDragon dragon = DragonManager.mp.get(key);
|
||||||
|
if(dragon == null){
|
||||||
|
Lang.sendFeedback(sender, Lang.dragon_not_found);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
GuiManager.openGui(p,dragon.drop_gui,key,false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "clear" : {
|
||||||
|
if(!sender.hasPermission("ed.drop.edit")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 3) {
|
||||||
|
String key = args[2];
|
||||||
|
RewardManager.clearItem(key);
|
||||||
|
Lang.sendFeedback(sender,Lang.command_drop_item_clear);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "add" : {
|
||||||
|
if(!sender.hasPermission("ed.drop.edit")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 4) {
|
||||||
|
if(p.getInventory().getItemInMainHand().getType() == Material.AIR){
|
||||||
|
Lang.sendFeedback(p, Lang.command_drop_item_add_empty);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String ChanceStr = args[3];
|
||||||
|
String key = args[2];
|
||||||
|
double chance = -1;
|
||||||
|
try {
|
||||||
|
chance = Double.parseDouble(ChanceStr);
|
||||||
|
} catch (NumberFormatException ex){
|
||||||
|
Lang.sendFeedback(p,Lang.command_drop_item_add_invalid_chance + ChanceStr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(chance <= 0) {
|
||||||
|
Lang.sendFeedback(p,Lang.command_drop_item_add_invalid_chance + ChanceStr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(chance > 100) chance = 100;
|
||||||
|
ItemStack item = p.getItemInHand().clone();
|
||||||
|
RewardManager.addItem(key,item,new Chance(chance,ChanceStr));
|
||||||
|
Lang.sendFeedback(p,Lang.command_drop_item_add_succeed.replaceAll("\\{chance}",ChanceStr));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "edit" : {
|
||||||
|
if(!sender.hasPermission("ed.drop.edit")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 2){
|
||||||
|
GuiManager.openGui(p, Config.main_gui,true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "remove" : {
|
||||||
|
if(!sender.hasPermission("ed.drop.edit")){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_no_permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.length == 4) {
|
||||||
|
try{
|
||||||
|
int idx = Integer.parseInt(args[3]);
|
||||||
|
boolean b = RewardManager.removeItem(args[2],idx);
|
||||||
|
if(b) Lang.sendFeedback(sender,Lang.command_drop_item_remove_succeed);
|
||||||
|
else Lang.sendFeedback(sender,Lang.command_drop_item_remove_fail);
|
||||||
|
return true;
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
Lang.sendFeedback(sender,Lang.command_drop_item_remove_invalid_num+args[3]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default : break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendCommandTips(sender);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void sendCommandTips(CommandSender sender){
|
||||||
|
sender.sendMessage(Lang.CommandTips1);
|
||||||
|
sender.sendMessage(Lang.CommandTips2);
|
||||||
|
sender.sendMessage(Lang.CommandTips3);
|
||||||
|
sender.sendMessage(Lang.CommandTips4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// long st=System.currentTimeMillis(),ed;
|
||||||
|
// for(int i=0;i<1;i++) {
|
||||||
|
// try {
|
||||||
|
// ItemStack item = p.getItemInHand();
|
||||||
|
// Class<?> CraftItemStackClass = Class.forName("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack");
|
||||||
|
// Object ci = CraftItemStackClass.cast(item);
|
||||||
|
// Method asNMSCopy = CraftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||||
|
// Object ei = asNMSCopy.invoke(ci, item);
|
||||||
|
// Class<?> NBTTagCompoundClass = Class.forName("net.minecraft.server.v1_13_R1.NBTTagCompound");
|
||||||
|
// Method save = ei.getClass().getDeclaredMethod("save", NBTTagCompoundClass);
|
||||||
|
// Object cpd = save.invoke(ei, NBTTagCompoundClass.newInstance());
|
||||||
|
// String str = cpd.toString();
|
||||||
|
// p.sendMessage(cpd.toString());
|
||||||
|
// } catch (ReflectiveOperationException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ed=System.currentTimeMillis();
|
||||||
|
// Bukkit.broadcastMessage("test #1: "+(ed-st)+"ms");
|
||||||
|
// st=System.currentTimeMillis();
|
||||||
|
// for(int i=0;i<1e5;i++) {
|
||||||
|
// ItemStack item = p.getItemInHand();
|
||||||
|
// net.minecraft.server.v1_13_R1.ItemStack ni = CraftItemStack.asNMSCopy(item);
|
||||||
|
// NBTTagCompound cpd = ni.save(new NBTTagCompound());
|
||||||
|
// String str = cpd.toString();
|
||||||
|
// }
|
||||||
|
// ed=System.currentTimeMillis();
|
||||||
|
// Bukkit.broadcastMessage("test #2: "+(ed-st)+"ms");
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// CraftItemStackClass=Class.forName("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack");
|
||||||
|
// asNMSCopy = CraftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||||
|
// NBTTagCompoundClass = Class.forName("net.minecraft.server.v1_13_R1.NBTTagCompound");
|
||||||
|
// ItemStackClass_e = Class.forName("net.minecraft.server.v1_13_R1.ItemStack");
|
||||||
|
// save = ItemStackClass_e.getDeclaredMethod("save", NBTTagCompoundClass);
|
||||||
|
// } catch (ReflectiveOperationException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// for(int i=0;i<1e5;i++) {
|
||||||
|
// try {
|
||||||
|
// ItemStack item = p.getItemInHand();
|
||||||
|
// Object ci = CraftItemStackClass.cast(item);
|
||||||
|
// Object ei = asNMSCopy.invoke(ci, item);
|
||||||
|
// Object cpd = save.invoke(ei, NBTTagCompoundClass.newInstance());
|
||||||
|
// String str = cpd.toString();
|
||||||
|
// //p.sendMessage(cpd.toString());
|
||||||
|
// } catch (ReflectiveOperationException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ed=System.currentTimeMillis();
|
||||||
|
// Bukkit.broadcastMessage("test #3: "+(ed-st)+"ms");
|
||||||
|
|
||||||
|
|
||||||
|
// st=System.currentTimeMillis();
|
||||||
|
//
|
||||||
|
// for(int i=0;i<1;i++) {
|
||||||
|
// ItemStack item = p.getItemInHand();
|
||||||
|
// String str = new NbtItemStack(item).getOrCreateTag().toString();
|
||||||
|
// //Bukkit.broadcastMessage(str);
|
||||||
|
// p.sendMessage(str);
|
||||||
|
// }
|
||||||
|
// ed=System.currentTimeMillis();
|
||||||
|
// Bukkit.broadcastMessage("test #3: "+(ed-st)+"ms");
|
||||||
|
|
||||||
|
// net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||||
|
// NBTTagCompound cpd = nmsItem.save(new NBTTagCompound());
|
||||||
|
|
||||||
|
// net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||||
|
// NBTTagCompound cpd = nmsItem.b(new NBTTagCompound());
|
||||||
|
// p.sendMessage(cpd.toString());
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package pers.xanadu.enderdragon.command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
|
import pers.xanadu.enderdragon.manager.WorldManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||||
|
|
||||||
|
private static final List<String> arguments_ed = Arrays.asList("action", "drop", "reload", "respawn", "respawn_cd", "update");
|
||||||
|
private static final List<String> arguments_drop = Arrays.asList("add", "clear", "edit", "remove", "gui");
|
||||||
|
private static final List<String> arguments_action = Arrays.asList("tell:","tell-colorless:","tell-raw:","groovy:");
|
||||||
|
private static final List<String> arguments_respawn_cd = Arrays.asList("get","remove","removeAll","set","start");
|
||||||
|
private static final List<String> arguments_reload = Arrays.asList("script");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
if (args.length == 1) {
|
||||||
|
result.addAll(arguments_ed);
|
||||||
|
}
|
||||||
|
else if (args.length == 2){
|
||||||
|
if(args[0].equalsIgnoreCase("drop")) {
|
||||||
|
result.addAll(arguments_drop);
|
||||||
|
}
|
||||||
|
else if(args[0].equalsIgnoreCase("respawn")){
|
||||||
|
result.addAll(WorldManager.worlds);
|
||||||
|
}
|
||||||
|
else if(args[0].equalsIgnoreCase("respawn_cd")){
|
||||||
|
result.addAll(arguments_respawn_cd);
|
||||||
|
}
|
||||||
|
else if(args[0].equalsIgnoreCase("reload")){
|
||||||
|
result.addAll(arguments_reload);
|
||||||
|
}
|
||||||
|
else if(args[0].equalsIgnoreCase("action")){
|
||||||
|
Stream<String> stream = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||||
|
return filterResult(stream,Arrays.asList("me"),args[args.length-1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(args.length == 3){
|
||||||
|
if("drop".equals(args[0])){
|
||||||
|
String str = args[1].toLowerCase();
|
||||||
|
if("add".equals(str) || "clear".equals(str) || "gui".equals(str) || "remove".equals(str)){
|
||||||
|
result.addAll(DragonManager.dragon_names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if("respawn_cd".equals(args[0])){
|
||||||
|
String str = args[1].toLowerCase();
|
||||||
|
if("get".equals(str) || "remove".equals(str) || "removeAll".equals(str) || "set".equals(str) || "start".equals(str)){
|
||||||
|
result.addAll(WorldManager.worlds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if("action".equals(args[0])){
|
||||||
|
result.addAll(arguments_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filterResult(result.stream(),args[args.length-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> filterResult(Stream<String> possible, List<String> res, final String arg){
|
||||||
|
List<String> list = new ArrayList<>(res);
|
||||||
|
if(arg == null) {
|
||||||
|
possible.forEach(list::add);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
String cur = arg.toLowerCase(Locale.ROOT);
|
||||||
|
possible.filter(suggestion-> suggestion.startsWith(cur)).forEach(list::add);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
private static List<String> filterResult(Stream<String> possible, final String arg){
|
||||||
|
if(arg == null) return possible.collect(Collectors.toList());
|
||||||
|
String cur = arg.toLowerCase(Locale.ROOT);
|
||||||
|
return possible.filter(suggestion-> suggestion.startsWith(cur)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package pers.xanadu.enderdragon.config;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
import static pers.xanadu.enderdragon.config.Lang.error;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
public static String version;
|
||||||
|
public static String lang;
|
||||||
|
public static boolean debug;
|
||||||
|
public static boolean advanced_setting_world_env_fix;
|
||||||
|
public static boolean advanced_setting_save_respawn_status;
|
||||||
|
public static boolean advanced_setting_glowing_fix;
|
||||||
|
public static boolean advanced_setting_backslash_split_reward;
|
||||||
|
public static String damage_visible_mode;
|
||||||
|
public static int damage_statistics_limit;
|
||||||
|
public static String special_dragon_jude_mode;
|
||||||
|
public static boolean crystal_invulnerable;
|
||||||
|
public static boolean respawn_cd_enable;
|
||||||
|
public static boolean resist_player_respawn;
|
||||||
|
public static boolean resist_dragon_breath_gather;
|
||||||
|
public static boolean hook_plugins_MythicLib;
|
||||||
|
public static boolean expansion_groovy;
|
||||||
|
public static String main_gui;
|
||||||
|
public static String item_format_reward;
|
||||||
|
public static List<String> dragon_setting_file;
|
||||||
|
public static List<String> blacklist_worlds;
|
||||||
|
private static final String pluginFilePath;
|
||||||
|
|
||||||
|
public static void reload(FileConfiguration file){
|
||||||
|
Field[] fields = Config.class.getFields();
|
||||||
|
for(Field field : fields){
|
||||||
|
Type type = field.getType();
|
||||||
|
if(type.equals(java.lang.String.class)){
|
||||||
|
try{
|
||||||
|
field.set(null,"");
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
}
|
||||||
|
else if(type.equals(java.util.List.class)){
|
||||||
|
try{
|
||||||
|
field.set(null,new ArrayList());
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char split = file.options().pathSeparator();
|
||||||
|
Iterator<String> it = file.getKeys(true).iterator();
|
||||||
|
while (it.hasNext()){
|
||||||
|
String str = it.next();
|
||||||
|
try{
|
||||||
|
if(file.isConfigurationSection(str)) continue;
|
||||||
|
if(str.startsWith("auto_respawn")) continue;
|
||||||
|
Config.class.getField(str.replace(split, '_')).set(null, file.get(str));
|
||||||
|
}catch (Exception e){
|
||||||
|
error("Config loading error! Key: "+str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (special_dragon_jude_mode.toLowerCase()){
|
||||||
|
case "pc" :
|
||||||
|
case "weight" : break;
|
||||||
|
default: {
|
||||||
|
error("Wrong special_dragon_jude_mode type in config.yml! Only \"weight\" or \"pc\" is valid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveResource(String source,String to,boolean replace){
|
||||||
|
if (source == null || source.equals("")) return;
|
||||||
|
source = source.replace('\\', '/');
|
||||||
|
InputStream in = plugin.getResource(source);
|
||||||
|
if (in == null) return;
|
||||||
|
File outFile = new File("plugins/EnderDragon", to);
|
||||||
|
int lastIndex = to.lastIndexOf('/');
|
||||||
|
File outDir = new File("plugins/EnderDragon", to.substring(0, Math.max(lastIndex, 0)));
|
||||||
|
if (!outDir.exists()) {
|
||||||
|
outDir.mkdirs();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (!outFile.exists() || replace) {
|
||||||
|
OutputStream out = new FileOutputStream(outFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {}
|
||||||
|
}
|
||||||
|
public static void copyFile(String source, String dest,boolean replace) {
|
||||||
|
if (source == null || source.equals("")) return;
|
||||||
|
source = source.replace('\\', '/');
|
||||||
|
File inFile = new File("plugins/EnderDragon", source);
|
||||||
|
File outFile = new File("plugins/EnderDragon", dest);
|
||||||
|
int lastIndex = dest.lastIndexOf('/');
|
||||||
|
File outDir = new File("plugins/EnderDragon", dest.substring(0, Math.max(lastIndex, 0)));
|
||||||
|
if (!outDir.exists()) {
|
||||||
|
outDir.mkdirs();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (!outFile.exists() || replace) {
|
||||||
|
InputStream in = new FileInputStream(inFile);
|
||||||
|
OutputStream out = new FileOutputStream(outFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
Lang.error("Failed to copy file: "+inFile.getPath()+" -> "+outFile.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void saveDirectoryResource(String srcDirectory,boolean replace) {
|
||||||
|
String destDirectory = new File(plugin.getDataFolder(),srcDirectory).getPath();
|
||||||
|
try {
|
||||||
|
JarFile jarFile = new JarFile(pluginFilePath);
|
||||||
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = entries.nextElement();
|
||||||
|
if (!entry.isDirectory() && entry.getName().startsWith(srcDirectory)) {
|
||||||
|
String relativePath = entry.getName().substring(srcDirectory.length());
|
||||||
|
File destinationFile = new File(destDirectory, relativePath);
|
||||||
|
if(!destinationFile.exists() || replace){
|
||||||
|
destinationFile.getParentFile().mkdirs();
|
||||||
|
//plugin.saveResource(entry.getName(),false);
|
||||||
|
try (InputStream input = jarFile.getInputStream(entry);
|
||||||
|
FileOutputStream output = new FileOutputStream(destinationFile)
|
||||||
|
) {
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = input.read(buffer)) != -1) {
|
||||||
|
output.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jarFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String convertInputStreamToString(InputStream inputStream) {
|
||||||
|
if(inputStream==null) return null;
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
stringBuilder.append(line).append('\n');
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
static {
|
||||||
|
pluginFilePath = new File(Config.class.getProtectionDomain().getCodeSource().getLocation().getFile()).getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package pers.xanadu.enderdragon.config;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
|
public class FileUpdater {
|
||||||
|
public static void update() throws IOException {
|
||||||
|
String respawn_world_name = null;
|
||||||
|
FileConfiguration config_old = plugin.getConfig();
|
||||||
|
if("2.1.0".equals(config_old.getString("version"))){
|
||||||
|
Config.saveResource("config.yml","new/config.yml",true);
|
||||||
|
File config_new_F = new File(plugin.getDataFolder(),"new/config.yml");
|
||||||
|
FileConfiguration config_new = YamlConfiguration.loadConfiguration(config_new_F);
|
||||||
|
config_new.set("lang",config_old.getString("lang"));
|
||||||
|
config_new.set("damage_visible_mode",config_old.getString("damage_visible_mode"));
|
||||||
|
config_new.set("damage_statistics.limit",config_old.getInt("damage_statistics.limit"));
|
||||||
|
String judge_mode = config_old.getString("special_dragon_jude_mode");
|
||||||
|
if("edge".equals(judge_mode)) judge_mode = "weight";//"edge" is deprecated
|
||||||
|
config_new.set("special_dragon_jude_mode",judge_mode);
|
||||||
|
config_new.set("dragon_setting_file",config_old.getStringList("dragon_setting_file"));
|
||||||
|
// auto_respawn
|
||||||
|
config_new.set("auto_respawn.task1.enable",config_old.getBoolean("auto_respawn.enable"));
|
||||||
|
respawn_world_name = config_old.getString("auto_respawn.world_the_end_name");
|
||||||
|
config_new.set("auto_respawn.task1.world_name",respawn_world_name);
|
||||||
|
config_new.set("auto_respawn.task1.respawn_time",config_old.getString("auto_respawn.respawn_time"));
|
||||||
|
config_new.set("crystal_invulnerable",config_old.getBoolean("auto_respawn.invulnerable"));
|
||||||
|
|
||||||
|
config_new.set("respawn_cd.enable",config_old.getBoolean("respawn_cd.enable"));
|
||||||
|
config_new.set("resist_player_respawn",config_old.getBoolean("resist_player_respawn"));
|
||||||
|
config_new.set("resist_dragon_breath_gather",config_old.getBoolean("resist_dragon_breath_gather"));
|
||||||
|
config_new.set("main_gui",config_old.getString("main_gui"));
|
||||||
|
config_new.set("blacklist_worlds",config_old.getStringList("blacklist_worlds"));
|
||||||
|
//item_format.data -> item_format.reward
|
||||||
|
config_new.set("item_format.reward",config_old.getString("item_format.data"));
|
||||||
|
|
||||||
|
config_new.set("hook_plugins.MythicLib",config_old.getBoolean("hook_plugins.MythicLib"));
|
||||||
|
config_new.set("debug",config_old.getBoolean("debug"));
|
||||||
|
config_new.set("advanced_setting.world_env_fix",config_old.getBoolean("advanced_setting.world_env_fix"));
|
||||||
|
config_new.set("advanced_setting.save_respawn_status",config_old.getBoolean("advanced_setting.save_respawn_status"));
|
||||||
|
config_new.save(config_new_F);
|
||||||
|
}
|
||||||
|
else Lang.error("The version of config.yml is not supported!");
|
||||||
|
File folder = new File(plugin.getDataFolder(),"setting");
|
||||||
|
if(folder.exists()){
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
if(files != null){
|
||||||
|
for(File file : files){
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
String ver = config.getString("version");
|
||||||
|
if(!"2.1.0".equals(ver)) {
|
||||||
|
Lang.error("The version of setting/"+file.getName()+" is not supported!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String name = file.getName();
|
||||||
|
Config.copyFile("setting/"+name,"new/setting/"+name,true);
|
||||||
|
}
|
||||||
|
File new_folder = new File(plugin.getDataFolder(),"new/setting/");
|
||||||
|
files = new_folder.listFiles();
|
||||||
|
if(files != null){
|
||||||
|
for(File file : files){
|
||||||
|
FileOutputStream out = new FileOutputStream(file,true);
|
||||||
|
out.write(("\n\n" +
|
||||||
|
"# the least interval time between injuries (unit:tick, 1tick=0.05s)\n" +
|
||||||
|
"# only supports integer value\n" +
|
||||||
|
"no_damage_tick: 10\n" +
|
||||||
|
"\n" +
|
||||||
|
"attack:\n" +
|
||||||
|
" #the damage modify when this dragon attacks player with body or limb (allow double and negative value)\n" +
|
||||||
|
" damage_modify: 0\n" +
|
||||||
|
"\n" +
|
||||||
|
" #the effect give to player when this ender dragon attacks player with body or limb\n" +
|
||||||
|
" #the format is the same as effect_cloud.potion\n" +
|
||||||
|
" potion_effect:\n" +
|
||||||
|
" - ''\n" +
|
||||||
|
" - ''\n" +
|
||||||
|
" - ''\n" +
|
||||||
|
"\n" +
|
||||||
|
" # the effect give to player when this ender dragon attacks player with body or limb\n" +
|
||||||
|
" # format: (<type>: seconds)\n" +
|
||||||
|
" extra_effect:\n" +
|
||||||
|
" fire: 0\n" +
|
||||||
|
" # \"freeze\" can only be used in server greater than or equal to version 1.17\n" +
|
||||||
|
" freeze: 0\n" +
|
||||||
|
"\n"
|
||||||
|
).getBytes());
|
||||||
|
out.close();
|
||||||
|
FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
|
||||||
|
fc.set("version","2.2.0");
|
||||||
|
fc.set("attack.damage_modify",fc.getDouble("attack_damage_modify"));
|
||||||
|
fc.set("attack_damage_modify",null);
|
||||||
|
fc.get("attack.potion_effect",fc.getStringList("attack_potion_effect"));
|
||||||
|
fc.set("attack_potion_effect",null);
|
||||||
|
fc.save(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String lang_name = config_old.getString("lang","English") + ".yml";
|
||||||
|
FileConfiguration lang_old = lang;
|
||||||
|
if("2.1.0".equals(lang_old.getString("version"))){
|
||||||
|
Config.saveResource("lang/"+lang_name,"new/lang/"+lang_name,true);
|
||||||
|
File lang_new_F = new File(plugin.getDataFolder(),"new/lang/"+lang_name);
|
||||||
|
FileConfiguration lang_new = YamlConfiguration.loadConfiguration(lang_new_F);
|
||||||
|
lang_old.getKeys(true).forEach(key->{
|
||||||
|
Object obj = lang_old.get(key);
|
||||||
|
lang_new.set(key,obj);
|
||||||
|
});
|
||||||
|
lang_new.set("version","2.2.0");
|
||||||
|
lang_new.save(lang_new_F);
|
||||||
|
}
|
||||||
|
else Lang.error("The version of "+lang_name+" is not supported!");
|
||||||
|
|
||||||
|
FileConfiguration data_old = EnderDragon.data;
|
||||||
|
if("2.1.0".equals(data_old.getString("version"))){
|
||||||
|
Config.copyFile("data.yml","new/data.yml",true);
|
||||||
|
File new_data_file = new File(plugin.getDataFolder(),"new/data.yml");
|
||||||
|
FileConfiguration new_data = YamlConfiguration.loadConfiguration(new_data_file);
|
||||||
|
String next_time = new_data.getString("auto_respawn.next_respawn_time");
|
||||||
|
if(next_time!=null && respawn_world_name!=null){
|
||||||
|
new_data.set("version","2.2.0");
|
||||||
|
new_data.set("auto_respawn.task1.world_name",respawn_world_name);
|
||||||
|
new_data.set("auto_respawn.task1.next_respawn_time",next_time);
|
||||||
|
new_data.save(new_data_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else Lang.error("The version of data.yml is not supported!");
|
||||||
|
Lang.info("New config files are generated in plugins/EnderDragon/new.");
|
||||||
|
Lang.warn("Attention: Please confirm the accuracy before using new config!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
package pers.xanadu.enderdragon.config;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import pers.xanadu.enderdragon.util.ColorUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
|
public class Lang {
|
||||||
|
public static String version;
|
||||||
|
public static String plugin_prefix;
|
||||||
|
public static String plugin_wrong_file_version;
|
||||||
|
public static String plugin_read_file;
|
||||||
|
public static String plugin_item_read_error;
|
||||||
|
public static String plugin_checking_update;
|
||||||
|
public static String plugin_check_update_fail;
|
||||||
|
public static String plugin_out_of_date;
|
||||||
|
public static String plugin_up_to_date;
|
||||||
|
public static String plugin_disable;
|
||||||
|
public static String plugin_file_save_error;
|
||||||
|
public static String command_no_permission;
|
||||||
|
public static String command_reload_config;
|
||||||
|
public static String command_only_player;
|
||||||
|
public static String command_drop_item_add_empty;
|
||||||
|
public static String command_drop_item_add_invalid_chance;
|
||||||
|
public static String command_drop_item_add_succeed;
|
||||||
|
public static String command_drop_item_clear;
|
||||||
|
public static String command_drop_item_remove_invalid_num;
|
||||||
|
public static String command_drop_item_remove_fail;
|
||||||
|
public static String command_drop_item_remove_succeed;
|
||||||
|
public static String command_respawn_cd_disable;
|
||||||
|
public static String command_respawn_cd_remove;
|
||||||
|
public static String command_respawn_cd_removeAll;
|
||||||
|
public static String command_respawn_cd_retry;
|
||||||
|
public static String command_respawn_cd_set;
|
||||||
|
public static String command_respawn_cd_start_already_started;
|
||||||
|
public static String command_respawn_cd_start_none;
|
||||||
|
public static String command_respawn_cd_start_succeed;
|
||||||
|
public static String gui_default_title;
|
||||||
|
public static String gui_not_found;
|
||||||
|
public static String gui_item_lore;
|
||||||
|
public static String gui_item_cmd_lore;
|
||||||
|
public static String dragon_damage_display;
|
||||||
|
public static String dragon_player_inv_full;
|
||||||
|
public static String dragon_no_killer;
|
||||||
|
public static String dragon_auto_respawn;
|
||||||
|
public static String dragon_not_found;
|
||||||
|
public static String dragon_damage_statistics_text;
|
||||||
|
public static List<String> dragon_damage_statistics_hover_prefix;
|
||||||
|
public static String dragon_damage_statistics_hover_mt;
|
||||||
|
public static List<String> dragon_damage_statistics_hover_suffix;
|
||||||
|
public static String dragon_damage_statistics_hover_exceeds_limit;
|
||||||
|
public static String world_env_fix_enable;
|
||||||
|
public static String expansion_groovy_disable;
|
||||||
|
|
||||||
|
public static String CommandTips1;
|
||||||
|
public static String CommandTips2;
|
||||||
|
public static String CommandTips3;
|
||||||
|
public static String CommandTips4;
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Bukkit.getLogger();
|
||||||
|
private static final ConsoleCommandSender console = Bukkit.getConsoleSender();
|
||||||
|
public static void reload(FileConfiguration file){
|
||||||
|
Field[] fields = Lang.class.getFields();
|
||||||
|
for(Field field : fields){
|
||||||
|
Type type = field.getType();
|
||||||
|
if(type.equals(java.lang.String.class)){
|
||||||
|
try{
|
||||||
|
field.set(null,"");
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
}
|
||||||
|
else if(type.equals(java.util.List.class)){
|
||||||
|
try{
|
||||||
|
field.set(null,new ArrayList());
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char split = file.options().pathSeparator();
|
||||||
|
Iterator<String> it = file.getKeys(true).iterator();
|
||||||
|
while (it.hasNext()){
|
||||||
|
String str = it.next();
|
||||||
|
try{
|
||||||
|
if(file.isConfigurationSection(str)) continue;
|
||||||
|
if(file.isString(str)) Lang.class.getField(str.replace(split, '_')).set(null, ColorUtil.parse(file.getString(str)));
|
||||||
|
else if(file.isList(str)){
|
||||||
|
List<String> list = file.getStringList(str);
|
||||||
|
list.forEach(s-> s = ColorUtil.parse(s));
|
||||||
|
Lang.class.getField(str.replace(split, '_')).set(null, list);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
error("Language loading error! Key: "+str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CommandTips1 = ColorUtil.parse(lang.getString("CommandTips1","§e/ed reload §a- reload the config"));
|
||||||
|
CommandTips2 = ColorUtil.parse(lang.getString("CommandTips2","§e/ed respawn §a- respawn a dragon"));
|
||||||
|
CommandTips3 = ColorUtil.parse(lang.getString("CommandTips3","§e/ed drop gui §a- view the drop_item"));
|
||||||
|
CommandTips4 = ColorUtil.parse(lang.getString("CommandTips4","§e/ed drop add <name> <chance> §a- add drop_item to one dragon"));
|
||||||
|
}
|
||||||
|
public static void sendMessage(String str) {
|
||||||
|
if(str == null) {
|
||||||
|
console.sendMessage(Lang.plugin_prefix + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
sendMessage(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else console.sendMessage(Lang.plugin_prefix + str);
|
||||||
|
}
|
||||||
|
public static void info(String str){
|
||||||
|
if(str == null) {
|
||||||
|
console.sendMessage("§a[EnderDragon] " + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
info(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else console.sendMessage("§a[EnderDragon] "+str);
|
||||||
|
}
|
||||||
|
public static void warn(String str){
|
||||||
|
if(str == null) {
|
||||||
|
console.sendMessage("§e[EnderDragon] " + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
warn(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else console.sendMessage("§e[EnderDragon] "+str);
|
||||||
|
}
|
||||||
|
public static void error(String str){
|
||||||
|
if(str == null) {
|
||||||
|
console.sendMessage("§c[EnderDragon] " + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
error(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else console.sendMessage("§c[EnderDragon] "+str);
|
||||||
|
}
|
||||||
|
public static void debug(String str){
|
||||||
|
if(Config.debug) LOGGER.info(str);
|
||||||
|
}
|
||||||
|
public static void sendFeedback(CommandSender sender,String str){
|
||||||
|
if(str == null) {
|
||||||
|
sender.sendMessage(Lang.plugin_prefix + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
sender.sendMessage(Lang.plugin_prefix + s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else sender.sendMessage(Lang.plugin_prefix + str);
|
||||||
|
}
|
||||||
|
public static void broadcastMSG(String str){
|
||||||
|
if(str == null) {
|
||||||
|
Bukkit.broadcastMessage(Lang.plugin_prefix + "null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(str.contains("\\n")){
|
||||||
|
String[] strings = str.split("\\\\n");
|
||||||
|
for(String s : strings){
|
||||||
|
broadcastMSG(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else Bukkit.broadcastMessage(Lang.plugin_prefix + str);
|
||||||
|
}
|
||||||
|
public static void broadcastMSG(List<String> list){
|
||||||
|
if(list == null) return;
|
||||||
|
for(String str : list){
|
||||||
|
Bukkit.broadcastMessage(Lang.plugin_prefix + str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void runCommands(List<String> list, Player p){
|
||||||
|
if(list == null) return;
|
||||||
|
for (String cmd : list) {
|
||||||
|
if(cmd.equals("")) continue;
|
||||||
|
if(!cmd.contains("%player%")) plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),cmd);
|
||||||
|
else{
|
||||||
|
if(p != null) plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),cmd.replaceAll("%player%",p.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void runCommands(List<String> list){
|
||||||
|
if(list == null) return;
|
||||||
|
for(String cmd : list){
|
||||||
|
if(cmd.equals("")) continue;
|
||||||
|
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package pers.xanadu.enderdragon.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.EnderDragon;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
|
public final class DragonDamageByPlayerEvent extends EntityDamageByEntityEvent {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final Player damager;
|
||||||
|
private final EnderDragon dragon;
|
||||||
|
private final DamageCause cause;
|
||||||
|
private final double finalDamage;
|
||||||
|
|
||||||
|
public DragonDamageByPlayerEvent(final Player damager, final EnderDragon dragon, final DamageCause cause, final double finalDamage) {
|
||||||
|
super(damager, dragon, cause, finalDamage);
|
||||||
|
this.damager = damager;
|
||||||
|
this.dragon = dragon;
|
||||||
|
this.cause = cause;
|
||||||
|
this.finalDamage = finalDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(final boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getDamager() {
|
||||||
|
return damager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnderDragon getDragon() {
|
||||||
|
return dragon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DamageCause getDamagerCause() {
|
||||||
|
return cause;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public double getDamage() {
|
||||||
|
return finalDamage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package pers.xanadu.enderdragon.event;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.EnderDragon;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public final class PlayerExplodeDragonEvent {
|
||||||
|
long _time;
|
||||||
|
Player _player;
|
||||||
|
EnderDragon _dragon;
|
||||||
|
Location _loc;
|
||||||
|
public PlayerExplodeDragonEvent(long time,Player player,EnderDragon dragon,Location loc){
|
||||||
|
_time = time;
|
||||||
|
_player = player;
|
||||||
|
_dragon = dragon;
|
||||||
|
_loc = loc;
|
||||||
|
}
|
||||||
|
public long getTime(){
|
||||||
|
return _time;
|
||||||
|
}
|
||||||
|
public Player getPlayer(){
|
||||||
|
return _player;
|
||||||
|
}
|
||||||
|
public EnderDragon getEnderDragon(){
|
||||||
|
return _dragon;
|
||||||
|
}
|
||||||
|
public Location getLocation(){
|
||||||
|
return _loc;
|
||||||
|
}
|
||||||
|
// private static final class MyComparator implements Comparator<PlayerExplodeDragonEvent>{
|
||||||
|
// @Override
|
||||||
|
// public int compare(final PlayerExplodeDragonEvent e1,final PlayerExplodeDragonEvent e2){
|
||||||
|
// if(e2._time>e1._time) return 1;
|
||||||
|
// else if(e2._time==e1._time) return 0;
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import pers.xanadu.enderdragon.config.Config;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.gui.slot.DragonSlot;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
|
import pers.xanadu.enderdragon.manager.ItemManager;
|
||||||
|
import pers.xanadu.enderdragon.gui.slot.EmptySlot;
|
||||||
|
import pers.xanadu.enderdragon.gui.slot.ItemSlot;
|
||||||
|
import pers.xanadu.enderdragon.reward.Reward;
|
||||||
|
import pers.xanadu.enderdragon.util.MyDragon;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GUI {
|
||||||
|
protected String title;
|
||||||
|
protected int maxPage;
|
||||||
|
protected int page;
|
||||||
|
protected int size;
|
||||||
|
protected ArrayList<ItemStack[]> pagedItems;
|
||||||
|
protected ArrayList<String[]> pagedData;
|
||||||
|
protected List<GUISlot> slots;
|
||||||
|
protected Inventory inv;
|
||||||
|
protected HashSet<Integer> dynamics;
|
||||||
|
|
||||||
|
protected GUI(String str,int size,int maxPage){
|
||||||
|
this.slots = new ArrayList<>();
|
||||||
|
this.pagedItems = new ArrayList<>();
|
||||||
|
this.pagedData = new ArrayList<>();
|
||||||
|
this.dynamics = new HashSet<>();
|
||||||
|
this.title = str;
|
||||||
|
this.size = size;
|
||||||
|
this.maxPage = maxPage;
|
||||||
|
this.page = 0;
|
||||||
|
}
|
||||||
|
public GUISlot getSlot(int index){
|
||||||
|
GUISlot slot = this.slots.get(index);
|
||||||
|
if(slot == null) return new EmptySlot();
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
public void setPage(int a) {
|
||||||
|
this.page = a;
|
||||||
|
for(int i=0;i<this.slots.size();i++){
|
||||||
|
GUISlot slot = this.slots.get(i);
|
||||||
|
if (slot instanceof ItemSlot) {
|
||||||
|
this.inv.setItem(i, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.pagedItems.isEmpty()) {
|
||||||
|
this.pagedItems.add(new ItemStack[this.size]);
|
||||||
|
}
|
||||||
|
if (this.pagedData.isEmpty()) {
|
||||||
|
this.pagedData.add(new String[this.size]);
|
||||||
|
}
|
||||||
|
ItemStack[] array = this.pagedItems.get(a);
|
||||||
|
for(int i=0 ; i<array.length ; i++){
|
||||||
|
ItemStack itemStack = array[i];
|
||||||
|
if (itemStack != null) {
|
||||||
|
this.inv.setItem(i, itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Integer n2 : this.dynamics){
|
||||||
|
GUISlotType type = this.getSlot(n2).getType();
|
||||||
|
ItemStack clone;
|
||||||
|
if(type == GUISlotType.PAGE_PREV){
|
||||||
|
if(a == 0) clone = this.slots.get(n2).getItemOnDisable();
|
||||||
|
else clone = this.slots.get(n2).getItem();
|
||||||
|
this.inv.setItem(n2,clone);
|
||||||
|
}
|
||||||
|
else if(type == GUISlotType.PAGE_NEXT){
|
||||||
|
if(a == this.pagedItems.size()-1) clone = this.slots.get(n2).getItemOnDisable();
|
||||||
|
else clone = this.slots.get(n2).getItem();
|
||||||
|
this.inv.setItem(n2,clone);
|
||||||
|
}
|
||||||
|
else if(type == GUISlotType.PAGE_TIP){
|
||||||
|
clone = this.slots.get(n2).getItem().clone();
|
||||||
|
ItemMeta itemMeta = clone.getItemMeta();
|
||||||
|
if (itemMeta != null) {
|
||||||
|
itemMeta.setDisplayName(String.format("§r%d/" + this.pagedItems.size(),a+1));
|
||||||
|
clone.setItemMeta(itemMeta);
|
||||||
|
this.inv.setItem(n2, clone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else if(type == GUISlotType.PAGE_JUMP){
|
||||||
|
// clone = this.slots.get(n2).getItem().clone();
|
||||||
|
// this.inv.setItem(n2,clone);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Inventory current() {
|
||||||
|
return this.inv;
|
||||||
|
}
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return this.inv;
|
||||||
|
}
|
||||||
|
protected void init() {
|
||||||
|
for(int i=0;i<this.slots.size();i++){
|
||||||
|
GUISlot slot = slots.get(i);
|
||||||
|
inv.setItem(i, slot.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void resetPagedItem(ItemStack item){
|
||||||
|
this.pagedItems.clear();
|
||||||
|
this.pagedItems.add(new ItemStack[]{item});
|
||||||
|
}
|
||||||
|
public void resetPagedItem(int type, String key,boolean cmd){
|
||||||
|
this.pagedItems.clear();
|
||||||
|
this.pagedData.clear();
|
||||||
|
if(type == 1){
|
||||||
|
resetPagedItem(key,cmd);
|
||||||
|
}
|
||||||
|
else if(type == 2){
|
||||||
|
for(MyDragon myDragon : DragonManager.dragons){
|
||||||
|
this.addDragon(myDragon.icon.clone(),myDragon.unique_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void resetPagedItem(String key,boolean cmd){
|
||||||
|
this.pagedItems.clear();
|
||||||
|
MyDragon dragon = DragonManager.mp.get(key);
|
||||||
|
if(dragon == null) return;
|
||||||
|
for(Reward reward : dragon.datum){
|
||||||
|
if(Config.debug) Bukkit.getLogger().info(reward.toString());
|
||||||
|
//if(ItemManager.isEmpty(reward.getItem())) continue;
|
||||||
|
ItemStack item = reward.getItem().clone();
|
||||||
|
if("".equals(Lang.gui_item_lore)) Lang.gui_item_lore = "§6(chance: {drop_chance}%)§r";
|
||||||
|
String lore = Lang.gui_item_lore.replaceAll("\\{drop_chance}",reward.getChance().getStr());
|
||||||
|
if(cmd) {
|
||||||
|
if("".equals(Lang.gui_item_cmd_lore)) Lang.gui_item_cmd_lore = "§6Shift+RightClick§f to remove§r";
|
||||||
|
ItemManager.addLoreFront(item,Lang.gui_item_cmd_lore);
|
||||||
|
}
|
||||||
|
ItemManager.addLoreFront(item,lore);
|
||||||
|
this.addItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void addItem(ItemStack item) {
|
||||||
|
for(int i = 0 ; i < this.maxPage ; i++){
|
||||||
|
if (i >= this.pagedItems.size()) {
|
||||||
|
this.pagedItems.add(new ItemStack[this.size]);
|
||||||
|
}
|
||||||
|
for(int j = 0 ; j < this.slots.size() ; j++){
|
||||||
|
GUISlot slot = this.slots.get(j);
|
||||||
|
if (slot instanceof ItemSlot) {
|
||||||
|
ItemStack itemStack = this.pagedItems.get(i)[j];
|
||||||
|
if (itemStack == null) {
|
||||||
|
this.pagedItems.get(i)[j] = item;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void addDragon(ItemStack item,String unique_name) {
|
||||||
|
for(int i = 0 ; i < this.maxPage ; i++){
|
||||||
|
if (i >= this.pagedItems.size()) {
|
||||||
|
this.pagedItems.add(new ItemStack[this.size]);
|
||||||
|
this.pagedData.add(new String[this.size]);
|
||||||
|
}
|
||||||
|
for(int j = 0 ; j < this.slots.size() ; j++){
|
||||||
|
if (this.slots.get(j) instanceof DragonSlot) {
|
||||||
|
ItemStack itemStack = this.pagedItems.get(i)[j];
|
||||||
|
if (itemStack == null) {
|
||||||
|
//itemStack = item;(可以吗?)
|
||||||
|
this.pagedItems.get(i)[j] = item;
|
||||||
|
this.pagedData.get(i)[j] = unique_name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public String getData(int page,int index){
|
||||||
|
return this.pagedData.get(page)[index];
|
||||||
|
}
|
||||||
|
public int getSize() {
|
||||||
|
return this.size;
|
||||||
|
}
|
||||||
|
public int getPage(){
|
||||||
|
return this.page;
|
||||||
|
}
|
||||||
|
public void prev() {
|
||||||
|
if (this.page > 0) {
|
||||||
|
this.setPage(this.page - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPage() {
|
||||||
|
if (this.pagedItems.size() >= this.maxPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.pagedItems.add(new ItemStack[this.size]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void next() {
|
||||||
|
if (this.page < this.pagedItems.size() - 1) {
|
||||||
|
this.setPage(this.page + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
|
public abstract class GUIHolder implements InventoryHolder {
|
||||||
|
private final GUI gui;
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return this.gui.getInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUI getGUI() {
|
||||||
|
return this.gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUIHolder(GUI gui) {
|
||||||
|
this.gui = gui;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.gui.slot.*;
|
||||||
|
|
||||||
|
public abstract class GUISlot {
|
||||||
|
private final GUISlotType guiSlotType;
|
||||||
|
protected DataType data_type;
|
||||||
|
public abstract ItemStack getItem();
|
||||||
|
public abstract ItemStack getItemOnDisable();
|
||||||
|
protected GUISlot(GUISlotType type){
|
||||||
|
this.guiSlotType = type;
|
||||||
|
}
|
||||||
|
public final GUISlotType getType(){
|
||||||
|
return this.guiSlotType;
|
||||||
|
}
|
||||||
|
public static GUISlot parse(ConfigurationSection section){
|
||||||
|
if(section == null) return new EmptySlot();
|
||||||
|
GUISlotType guiSlotType = GUISlotType.getByName(section.getString("type"));
|
||||||
|
switch (guiSlotType) {
|
||||||
|
case ITEM_SLOT : {
|
||||||
|
return new ItemSlot(section);
|
||||||
|
}
|
||||||
|
case DRAGON_SLOT : {
|
||||||
|
return new DragonSlot(section);
|
||||||
|
}
|
||||||
|
case PAGE_PREV :
|
||||||
|
case PAGE_NEXT :
|
||||||
|
case PAGE_TIP :
|
||||||
|
case TIP : {
|
||||||
|
return new TipSlot(guiSlotType, section);
|
||||||
|
}
|
||||||
|
case PAGE_JUMP : {
|
||||||
|
return new PageJumpSlot(section);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EmptySlot();
|
||||||
|
}
|
||||||
|
protected enum DataType{
|
||||||
|
DEFAULT,NBT,ADVANCED
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
public enum GUISlotType {
|
||||||
|
TIP,
|
||||||
|
PAGE_TIP,
|
||||||
|
PAGE_PREV,
|
||||||
|
PAGE_NEXT,
|
||||||
|
PAGE_JUMP,
|
||||||
|
EMPTY,
|
||||||
|
ITEM_SLOT,
|
||||||
|
DRAGON_SLOT;
|
||||||
|
private static final Map<String,GUISlotType> mp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
public static GUISlotType getByName(String str){
|
||||||
|
if(str == null) return EMPTY;
|
||||||
|
return mp.getOrDefault(str.replaceAll("_",""),EMPTY);
|
||||||
|
}
|
||||||
|
static{
|
||||||
|
GUISlotType[] values = values();
|
||||||
|
for (GUISlotType guiSlotType : values) {
|
||||||
|
String name = guiSlotType.name();
|
||||||
|
String target = "_";
|
||||||
|
String replacement = "";
|
||||||
|
mp.put(name.replaceAll(target, replacement), guiSlotType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.gui.holder.MenuEditor;
|
||||||
|
import pers.xanadu.enderdragon.gui.holder.Menu;
|
||||||
|
import pers.xanadu.enderdragon.gui.holder.RewardEditor;
|
||||||
|
import pers.xanadu.enderdragon.gui.slot.EmptySlot;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GUIWrapper extends GUI{
|
||||||
|
private final String name;
|
||||||
|
private final String key;
|
||||||
|
private int type;
|
||||||
|
private int[] item_idx;
|
||||||
|
private int item_size;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
public GUIWrapper(GUIWrapper a, String key, boolean editor){
|
||||||
|
super(a.title, a.size, a.maxPage);
|
||||||
|
if(editor) this.inv = Bukkit.createInventory(new MenuEditor(this,key), this.size, this.title);
|
||||||
|
else this.inv = Bukkit.createInventory(new Menu(this), this.size, this.title);
|
||||||
|
this.slots.addAll(a.slots);
|
||||||
|
this.dynamics.addAll(a.dynamics);
|
||||||
|
this.name = a.name;
|
||||||
|
this.key = key;
|
||||||
|
this.type = a.type;
|
||||||
|
this.item_idx = a.item_idx;
|
||||||
|
this.item_size = a.item_size;
|
||||||
|
this.init();
|
||||||
|
this.resetPagedItem(type,key,editor);
|
||||||
|
this.setPage(0);
|
||||||
|
}
|
||||||
|
public GUIWrapper(GUIWrapper a, ItemStack item) {
|
||||||
|
super(a.title, a.size, a.maxPage);
|
||||||
|
this.inv = Bukkit.createInventory(new RewardEditor(this), this.size, this.title);
|
||||||
|
this.slots.addAll(a.slots);
|
||||||
|
this.dynamics.addAll(a.dynamics);
|
||||||
|
this.name = a.name;
|
||||||
|
this.key = null;
|
||||||
|
this.type = a.type;
|
||||||
|
this.item_idx = a.item_idx;
|
||||||
|
this.item_size = a.item_size;
|
||||||
|
this.init();
|
||||||
|
this.resetPagedItem(item);
|
||||||
|
this.setPage(0);
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public GUIWrapper(GUIWrapper a, String key) {
|
||||||
|
super(a.title, a.size, a.maxPage);
|
||||||
|
this.inv = Bukkit.createInventory(new Menu(this), this.size, this.title);
|
||||||
|
this.slots.addAll(a.slots);
|
||||||
|
this.dynamics.addAll(a.dynamics);
|
||||||
|
this.name = a.name;
|
||||||
|
this.key = key;
|
||||||
|
this.type = a.type;
|
||||||
|
this.item_idx = a.item_idx;
|
||||||
|
this.item_size = a.item_size;
|
||||||
|
this.init();
|
||||||
|
this.resetPagedItem(type,key,false);
|
||||||
|
this.setPage(0);
|
||||||
|
}
|
||||||
|
public GUIWrapper(ConfigurationSection config) {
|
||||||
|
super(config.getString("Title", Lang.gui_default_title).replaceAll("&", "§"), calcline(config.getStringList("Slots").size()) * 9, config.getInt("Page", 1000));
|
||||||
|
this.type = 0;
|
||||||
|
this.name = config.getName();
|
||||||
|
this.key = null;
|
||||||
|
this.inv = Bukkit.createInventory(new Menu(this), this.size, this.title);
|
||||||
|
for(int i = 0 ; i < this.size ; i++){
|
||||||
|
slots.add(new EmptySlot());
|
||||||
|
}
|
||||||
|
ConfigurationSection section = config.getConfigurationSection("Items");
|
||||||
|
HashMap<Character,GUISlot> hash = new HashMap<>();
|
||||||
|
if (section == null) return;
|
||||||
|
for (String s : section.getKeys(false)) {
|
||||||
|
GUISlot slot = GUISlot.parse(section.getConfigurationSection(s));
|
||||||
|
hash.put(s.charAt(0), slot);
|
||||||
|
}
|
||||||
|
int n2 = 0;
|
||||||
|
List<String> stringList = config.getStringList("Slots");
|
||||||
|
for (String line : stringList) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < line.length() && i < 9; ++i) {
|
||||||
|
char value = line.charAt(i);
|
||||||
|
this.slots.set(n2++, (hash.getOrDefault(value, new EmptySlot())));
|
||||||
|
}
|
||||||
|
while(i ++ < 9){
|
||||||
|
this.slots.set(n2++, new EmptySlot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean b = false;
|
||||||
|
for(int i = 0 ; i < slots.size(); i++){
|
||||||
|
GUISlotType type = this.slots.get(i).getType();
|
||||||
|
if(type == GUISlotType.PAGE_PREV || type == GUISlotType.PAGE_NEXT || type == GUISlotType.PAGE_TIP){
|
||||||
|
this.dynamics.add(i);
|
||||||
|
}
|
||||||
|
else if(type == GUISlotType.ITEM_SLOT){
|
||||||
|
this.type = 1;
|
||||||
|
}
|
||||||
|
else if(type == GUISlotType.DRAGON_SLOT){
|
||||||
|
this.type = 2;
|
||||||
|
}
|
||||||
|
else if (type == GUISlotType.PAGE_JUMP) {
|
||||||
|
b = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.item_idx = new int[size];
|
||||||
|
int cur = -1;
|
||||||
|
for(int i=0;i<size;i++){
|
||||||
|
if(this.slots.get(i).getType()==GUISlotType.ITEM_SLOT) cur++;
|
||||||
|
this.item_idx[i] = cur;
|
||||||
|
}
|
||||||
|
this.item_size = cur+1;
|
||||||
|
}
|
||||||
|
public int getItemSlotIdx(int cur){
|
||||||
|
return this.item_idx[cur];
|
||||||
|
}
|
||||||
|
public int getItemSize(){
|
||||||
|
return this.item_size;
|
||||||
|
}
|
||||||
|
public void updateItemChanges(boolean cmd){
|
||||||
|
this.resetPagedItem(type,key,cmd);
|
||||||
|
this.setPage(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int calcline(final int a) {
|
||||||
|
if (a < 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return Math.min(a, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.holder;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUI;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUIHolder;
|
||||||
|
|
||||||
|
public class Menu extends GUIHolder implements InventoryHolder {
|
||||||
|
|
||||||
|
public Menu(GUI gui) {
|
||||||
|
super(gui);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.holder;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUI;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUIHolder;
|
||||||
|
|
||||||
|
public class MenuEditor extends GUIHolder implements InventoryHolder {
|
||||||
|
private final String dragon_key;
|
||||||
|
public String getDragon_key(){
|
||||||
|
return this.dragon_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuEditor(GUI gui, String key) {
|
||||||
|
super(gui);
|
||||||
|
this.dragon_key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.holder;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUI;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUIHolder;
|
||||||
|
|
||||||
|
public class RewardEditor extends GUIHolder implements InventoryHolder {
|
||||||
|
public RewardEditor(GUI gui){
|
||||||
|
super(gui);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.slot;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlot;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlotType;
|
||||||
|
|
||||||
|
public class DragonSlot extends GUISlot {
|
||||||
|
private String unique_name;
|
||||||
|
private ItemStack item;
|
||||||
|
|
||||||
|
public DragonSlot(ConfigurationSection section) {
|
||||||
|
super(GUISlotType.DRAGON_SLOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem() {
|
||||||
|
return new ItemStack(Material.AIR);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemOnDisable(){
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
public void setUnique_name(String str){
|
||||||
|
this.unique_name = str;
|
||||||
|
}
|
||||||
|
public String getUnique_name(){
|
||||||
|
return this.unique_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DragonSlot(GUISlotType a, ItemStack item) {
|
||||||
|
super(a);
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.slot;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlot;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlotType;
|
||||||
|
|
||||||
|
public class EmptySlot extends GUISlot {
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(){
|
||||||
|
return new ItemStack(Material.AIR);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemOnDisable(){
|
||||||
|
return new ItemStack(Material.AIR);
|
||||||
|
}
|
||||||
|
public EmptySlot(){
|
||||||
|
super(GUISlotType.EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.slot;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlot;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlotType;
|
||||||
|
|
||||||
|
public class ItemSlot extends GUISlot {
|
||||||
|
private ItemStack item;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem() {
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemOnDisable(){
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemSlot(ConfigurationSection section) {
|
||||||
|
super(GUISlotType.ITEM_SLOT);
|
||||||
|
String str = section.getString("Item");
|
||||||
|
if(str == null){
|
||||||
|
this.item = new ItemStack(Material.AIR);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// this.item = EnderDragon.getInstance().getItemManager().stringToItemStack(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.slot;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlotType;
|
||||||
|
|
||||||
|
public class PageJumpSlot extends TipSlot{
|
||||||
|
private final String name;
|
||||||
|
public String getGuiName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
public PageJumpSlot(ConfigurationSection section) {
|
||||||
|
super(GUISlotType.PAGE_JUMP, section);
|
||||||
|
this.name = section.getString("gui");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemOnDisable(){
|
||||||
|
return this.itemOnDisable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package pers.xanadu.enderdragon.gui.slot;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlot;
|
||||||
|
import pers.xanadu.enderdragon.gui.GUISlotType;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.manager.ItemManager.*;
|
||||||
|
|
||||||
|
public class TipSlot extends GUISlot {
|
||||||
|
private ItemStack item;
|
||||||
|
protected boolean hasDisableMode;
|
||||||
|
protected ItemStack itemOnDisable;
|
||||||
|
|
||||||
|
public TipSlot(GUISlotType slotType, Material material, String str) {
|
||||||
|
super(slotType);
|
||||||
|
this.item = new ItemStack(material);
|
||||||
|
ItemMeta meta = this.item.getItemMeta();
|
||||||
|
meta.setDisplayName(str);
|
||||||
|
this.item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TipSlot(GUISlotType slotType, ConfigurationSection section) {
|
||||||
|
super(slotType);
|
||||||
|
if(slotType == GUISlotType.PAGE_PREV || slotType == GUISlotType.PAGE_NEXT){
|
||||||
|
this.hasDisableMode = true;
|
||||||
|
}
|
||||||
|
else this.hasDisableMode = false;
|
||||||
|
if(hasDisableMode){
|
||||||
|
if(data_type == DataType.NBT) this.itemOnDisable = readFromNBT(section,"data_disable");
|
||||||
|
else this.itemOnDisable = readFromBukkit(section,"data_disable");
|
||||||
|
}
|
||||||
|
String data_type = section.getString("data_type");
|
||||||
|
if("nbt".equals(data_type)) {
|
||||||
|
this.data_type = DataType.NBT;
|
||||||
|
this.item = readFromNBT(section,"data");
|
||||||
|
}
|
||||||
|
else if("advanced".equals(data_type)){
|
||||||
|
this.data_type = DataType.ADVANCED;
|
||||||
|
this.item = readFromAdvData(section,"data");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.data_type = DataType.DEFAULT;
|
||||||
|
this.item = readFromBukkit(section,"data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem() {
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemOnDisable(){
|
||||||
|
if(hasDisableMode) return this.itemOnDisable;
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TipSlot(GUISlotType a, ItemStack item) {
|
||||||
|
super(a);
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package pers.xanadu.enderdragon.hook;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.hook.placeholderapi.Papi;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
|
public class HookManager {
|
||||||
|
private static boolean papi = false;
|
||||||
|
public static void init(){
|
||||||
|
if(pm.getPlugin("PlaceholderAPI") != null){
|
||||||
|
Lang.info("Hooking to PlaceholderAPI...");
|
||||||
|
new Papi(getInstance());
|
||||||
|
papi = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static boolean isPlaceholderAPILoaded(){
|
||||||
|
return papi;
|
||||||
|
}
|
||||||
|
public static String parsePapi(final OfflinePlayer p, String str){
|
||||||
|
if(papi) return PlaceholderAPI.setPlaceholders(p,str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package pers.xanadu.enderdragon.hook.placeholderapi;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
import pers.xanadu.enderdragon.manager.TimerManager;
|
||||||
|
import pers.xanadu.enderdragon.task.DragonRespawnTimer;
|
||||||
|
import pers.xanadu.enderdragon.util.MathUtil;
|
||||||
|
|
||||||
|
public class Papi extends PlaceholderExpansion {
|
||||||
|
private final EnderDragon plugin;
|
||||||
|
|
||||||
|
public Papi(EnderDragon plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
register();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getAuthor() {
|
||||||
|
return "Xanadu13";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getIdentifier() {
|
||||||
|
return "ed";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getVersion() {
|
||||||
|
return this.plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean persist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean canRegister(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String onPlaceholderRequest(final Player player, final @NotNull String params){
|
||||||
|
if(params.equals("can_respawn")){
|
||||||
|
if(player == null) return String.valueOf(false);
|
||||||
|
boolean res = EnderDragon.getInstance().getDragonManager().canRespawn(player.getWorld());
|
||||||
|
return String.valueOf(res);
|
||||||
|
}
|
||||||
|
if(params.equals("respawn_cd_progress")){
|
||||||
|
if(player == null) return null;
|
||||||
|
World world = player.getWorld();
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(world.getName());
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getProgress());
|
||||||
|
}
|
||||||
|
if(params.equals("respawn_cd_remainTime")){
|
||||||
|
if(player == null) return null;
|
||||||
|
World world = player.getWorld();
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(world.getName());
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getRestTime());
|
||||||
|
}
|
||||||
|
if(params.equals("respawn_cd_setTime")){
|
||||||
|
if(player == null) return null;
|
||||||
|
World world = player.getWorld();
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(world.getName());
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getSetTime());
|
||||||
|
}
|
||||||
|
if(params.startsWith("can_respawn_")){
|
||||||
|
String name = params.substring("can_respawn_".length());
|
||||||
|
World world = Bukkit.getWorld(name);
|
||||||
|
boolean res = EnderDragon.getInstance().getDragonManager().canRespawn(world);
|
||||||
|
return String.valueOf(res);
|
||||||
|
}
|
||||||
|
if(params.startsWith("respawn_cd_progress_")){
|
||||||
|
String name = params.substring("respawn_cd_progress_".length());
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(name);
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getProgress());
|
||||||
|
}
|
||||||
|
if(params.startsWith("respawn_cd_remainTime_")){
|
||||||
|
String name = params.substring("respawn_cd_remainTime_".length());
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(name);
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getRestTime());
|
||||||
|
}
|
||||||
|
if(params.startsWith("respawn_cd_setTime_")){
|
||||||
|
String name = params.substring("respawn_cd_setTime_".length());
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(name);
|
||||||
|
if(timer == null) return "null";
|
||||||
|
return String.valueOf(timer.getSetTime());
|
||||||
|
}
|
||||||
|
if(params.startsWith("respawn_cd_remain_")){
|
||||||
|
String sub = params.substring("respawn_cd_remain_".length());
|
||||||
|
String[] splits = sub.split("\\$",5);
|
||||||
|
DragonRespawnTimer timer = TimerManager.getTimer(splits[0]);
|
||||||
|
if(timer == null) return "null";
|
||||||
|
if(splits.length==1) return MathUtil.formatDuration(timer.getRestTime());
|
||||||
|
if(splits.length==5){
|
||||||
|
int[] values = MathUtil.getDate(timer.getRestTime());
|
||||||
|
return values[0]+splits[1]+values[1]+splits[2]+values[2]+splits[3]+values[3]+splits[4];
|
||||||
|
}
|
||||||
|
return "wrong format";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String onRequest(final OfflinePlayer player, final @NotNull String params) {
|
||||||
|
if(player == null) return onPlaceholderRequest(null,params);
|
||||||
|
return onPlaceholderRequest(player.getPlayer(),params);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user