Delete src/main/java/xanadu/enderdragon directory
This commit is contained in:
@@ -1,192 +0,0 @@
|
||||
package xanadu.enderdragon;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.commands.MainCommand;
|
||||
import xanadu.enderdragon.commands.TabCompleter;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.gui.GUIHolder;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.listeners.*;
|
||||
import xanadu.enderdragon.listeners.mmoitems.MMOPlayerAttackListener;
|
||||
import xanadu.enderdragon.listeners.mythiclib.PlayerAttackListener;
|
||||
import xanadu.enderdragon.manager.DragonManager;
|
||||
import xanadu.enderdragon.manager.GuiManager;
|
||||
import xanadu.enderdragon.manager.TaskManager;
|
||||
import xanadu.enderdragon.metrics.Metrics;
|
||||
import xanadu.enderdragon.task.RespawnDragonRunnable;
|
||||
import xanadu.enderdragon.utils.Version;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Objects;
|
||||
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
import static xanadu.enderdragon.manager.GuiManager.loadGui;
|
||||
import static xanadu.enderdragon.utils.Updater.checkUpdate;
|
||||
|
||||
public final class EnderDragon extends JavaPlugin {
|
||||
|
||||
private static EnderDragon instance;
|
||||
public static Plugin plugin;
|
||||
public static Server server;
|
||||
public static PluginManager pm;
|
||||
public static File dataF;
|
||||
public static File langF;
|
||||
public static FileConfiguration data;
|
||||
public static FileConfiguration lang;
|
||||
public static int mcMainVersion;
|
||||
public static int mcPatchVersion;
|
||||
private DragonManager dragonManager;
|
||||
private static boolean finish;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
finish = false;
|
||||
info("Enabling plugin...");
|
||||
info("Author: Xanadu13");
|
||||
plugin = this;
|
||||
instance = this;
|
||||
dragonManager = new DragonManager();
|
||||
server = plugin.getServer();
|
||||
pm = Bukkit.getPluginManager();
|
||||
mcMainVersion = getMinecraftVersion();
|
||||
registerEvents();
|
||||
registerCommands();
|
||||
Metrics metrics = new Metrics(this,14850);
|
||||
reloadAll();
|
||||
Version.init();
|
||||
checkUpdate();
|
||||
if(!Lang.version.equals("2.0.0")){
|
||||
warn(Lang.plugin_wrong_file_version.replace("{file_name}",Config.lang + ".yml"));
|
||||
}
|
||||
if(!Config.version.equals("2.0.0")){
|
||||
warn(Lang.plugin_wrong_file_version.replace("{file_name}","config.yml"));
|
||||
}
|
||||
if(!"2.0.0".equals(data.getString("version"))){
|
||||
warn(Lang.plugin_wrong_file_version.replace("{file_name}","data.yml"));
|
||||
}
|
||||
finish = true;
|
||||
}
|
||||
public static void reloadAll(){
|
||||
EnderDragon.getInstance().loadFiles();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(!TaskManager.getCurrentTimeWithSpecialFormat().endsWith("0")) return;
|
||||
this.cancel();
|
||||
RespawnDragonRunnable.reload();
|
||||
}
|
||||
};
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!finish) return;
|
||||
this.cancel();
|
||||
DragonManager.reload();
|
||||
loadGui();
|
||||
if(Config.auto_respawn_enable){
|
||||
TaskManager.reload();
|
||||
runnable.runTaskTimer(plugin,0,1);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1, 5);
|
||||
}
|
||||
public static void disableAll(){
|
||||
closeAllInventory();
|
||||
Bukkit.getScheduler().cancelTasks(plugin);
|
||||
DragonManager.disable();
|
||||
GuiManager.disable();
|
||||
instance.unregisterCommands();
|
||||
HandlerList.unregisterAll(plugin);
|
||||
server.getScheduler().cancelTasks(plugin);
|
||||
server.getServicesManager().unregisterAll(plugin);
|
||||
warn(Lang.plugin_disable);
|
||||
System.gc();
|
||||
}
|
||||
private void registerEvents(){
|
||||
pm.registerEvents(new CreatureSpawnListener(),this);
|
||||
pm.registerEvents(new DragonDamageByPlayerListener(),this);
|
||||
pm.registerEvents(new DragonDeathListener(),this);
|
||||
pm.registerEvents(new DragonHealListener(),this);
|
||||
pm.registerEvents(new EntityDamageByEntityListener(),this);
|
||||
pm.registerEvents(new InventoryListener(),this);
|
||||
pm.registerEvents(new PluginDisableListener(),this);
|
||||
if(pm.getPlugin("MythicLib") != null){
|
||||
info("Hooking to MythicLib...");
|
||||
pm.registerEvents(new PlayerAttackListener(),this);
|
||||
}
|
||||
else{
|
||||
pm.registerEvents(new DragonBaseHurtListener(),this);
|
||||
}
|
||||
if(pm.getPlugin("MMOItems") != null){
|
||||
info("Hooking to MMOItems...");
|
||||
pm.registerEvents(new MMOPlayerAttackListener(),this);
|
||||
}
|
||||
}
|
||||
private void registerCommands(){
|
||||
Objects.requireNonNull(getCommand("enderdragon")).setExecutor(new MainCommand());
|
||||
Objects.requireNonNull(getCommand("enderdragon")).setTabCompleter(new TabCompleter());
|
||||
}
|
||||
private void unregisterCommands(){
|
||||
Objects.requireNonNull(getCommand("enderdragon")).setExecutor(null);
|
||||
Objects.requireNonNull(getCommand("enderdragon")).setTabCompleter(null);
|
||||
}
|
||||
private void loadFiles(){
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
Config.reload(getConfig());
|
||||
if (!new File(getDataFolder(), "data.yml").exists()) {
|
||||
this.saveResource("data.yml",false);
|
||||
}
|
||||
dataF = new File(getDataFolder(),"data.yml");
|
||||
data = YamlConfiguration.loadConfiguration(dataF);
|
||||
if(Config.lang.equals("")) {
|
||||
error("Key \"lang\" in config is missing, please check your config.yml.");
|
||||
Config.lang = "English";
|
||||
}
|
||||
String langPath = "lang/" + Config.lang + ".yml";
|
||||
if (!new File(getDataFolder(), langPath).exists()) {
|
||||
this.saveResource(langPath, false);
|
||||
}
|
||||
langF = new File(getDataFolder(), langPath);
|
||||
lang = YamlConfiguration.loadConfiguration(langF);
|
||||
info("Language: §6" + Config.lang);
|
||||
Lang.reload(lang);
|
||||
if (!new File(plugin.getDataFolder(), "gui/view.yml").exists()) {
|
||||
plugin.saveResource("gui/view.yml",false);
|
||||
}
|
||||
|
||||
}
|
||||
public static EnderDragon getInstance() {return instance;}
|
||||
private int getMinecraftVersion() {
|
||||
String[] version = getServer().getBukkitVersion().replace('-', '.').split("\\.");
|
||||
try {
|
||||
mcPatchVersion = Integer.parseInt(version[2]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
return Integer.parseInt(version[1]);
|
||||
}
|
||||
public static void closeAllInventory() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
if (!(inventory.getHolder() instanceof GUIHolder)) continue;
|
||||
player.closeInventory();
|
||||
}
|
||||
catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
public DragonManager getDragonManager(){
|
||||
return dragonManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
package xanadu.enderdragon.commands;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.EnderDragon;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.utils.Chance;
|
||||
import xanadu.enderdragon.utils.FileUpdater;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
import static xanadu.enderdragon.manager.DragonManager.*;
|
||||
import static xanadu.enderdragon.manager.GuiManager.openGui;
|
||||
import static xanadu.enderdragon.manager.RewardManager.addItem;
|
||||
import static xanadu.enderdragon.manager.RewardManager.clearItem;
|
||||
|
||||
public class MainCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendCommandTips(sender);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
switch (args[0].toLowerCase()){
|
||||
case "reload" : {
|
||||
if(!sender.hasPermission("ed.reload")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
closeAllInventory();
|
||||
reloadAll();
|
||||
sendFeedback(sender,Lang.command_reload_config);
|
||||
return true;
|
||||
}
|
||||
case "respawn" : {
|
||||
if(!sender.hasPermission("ed.respawn")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
if(!(sender instanceof Player)){
|
||||
sendFeedback(sender,Lang.command_only_player);
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
EnderDragon.getInstance().getDragonManager().initiateRespawn(player);
|
||||
return true;
|
||||
}
|
||||
case "update" : {
|
||||
if(!sender.hasPermission("ed.update")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
FileUpdater.update();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default : {
|
||||
sendCommandTips(sender);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("drop")) {
|
||||
if(!(sender instanceof Player)) {
|
||||
sendFeedback(sender,Lang.command_only_player);
|
||||
return false;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
switch (args[1].toLowerCase()){
|
||||
case "gui" : {
|
||||
if(!sender.hasPermission("ed.drop.gui")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
if(args.length == 2){
|
||||
openGui(p, Config.main_gui);
|
||||
return true;
|
||||
}
|
||||
if(args.length == 3){
|
||||
String key = args[2];
|
||||
MyDragon dragon = mp.get(key);
|
||||
if(dragon == null){
|
||||
sendFeedback(sender,dragon_not_found);
|
||||
return false;
|
||||
}
|
||||
openGui(p,dragon.drop_gui,key);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "clear" : {
|
||||
if(!sender.hasPermission("ed.drop.edit")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
if(args.length == 3) {
|
||||
String key = args[2];
|
||||
clearItem(key);
|
||||
sendFeedback(sender,Lang.command_drop_item_clear);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "add" : {
|
||||
if(!sender.hasPermission("ed.drop.edit")){
|
||||
sendFeedback(sender,Lang.command_no_permission);
|
||||
return false;
|
||||
}
|
||||
if(args.length == 4) {
|
||||
if(p.getInventory().getItemInMainHand().getType() == Material.AIR){
|
||||
sendFeedback(p, 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){
|
||||
sendFeedback(p,Lang.command_drop_item_add_invalid_chance + ChanceStr);
|
||||
return false;
|
||||
}
|
||||
if(chance <= 0) {
|
||||
sendFeedback(p,Lang.command_drop_item_add_invalid_chance + ChanceStr);
|
||||
return false;
|
||||
}
|
||||
if(chance > 100) chance = 100;
|
||||
ItemStack item = p.getItemInHand();
|
||||
addItem(key,item,new Chance(chance,ChanceStr));
|
||||
sendFeedback(p,Lang.command_drop_item_add_succeed.replaceAll("\\{chance}",ChanceStr));
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
sendCommandTips(sender);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
sendCommandTips(sender);
|
||||
return false;
|
||||
}
|
||||
private static void sendCommandTips(CommandSender sender){
|
||||
sender.sendMessage(CommandTips1);
|
||||
sender.sendMessage(CommandTips2);
|
||||
sender.sendMessage(CommandTips3);
|
||||
sender.sendMessage(CommandTips4);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package xanadu.enderdragon.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.manager.DragonManager.dragon_names;
|
||||
|
||||
public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||
|
||||
private static final List<String> arguments_1 = Arrays.asList("drop", "reload", "respawn", "update");
|
||||
private static final List<String> arguments_2 = Arrays.asList("add", "clear", "gui");
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
if (args.length == 1) {
|
||||
for (String s : arguments_1) {
|
||||
if (s.toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (args.length == 2){
|
||||
if(args[0].equalsIgnoreCase("drop")) {
|
||||
for (String s : arguments_2) {
|
||||
if (s.toLowerCase().startsWith(args[1].toLowerCase())) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if(args.length == 3){
|
||||
String str = args[1].toLowerCase();
|
||||
if("add".equals(str) || "clear".equals(str) || "gui".equals(str)){
|
||||
for (String s : dragon_names) {
|
||||
if (s.toLowerCase().startsWith(args[2].toLowerCase())) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package xanadu.enderdragon.config;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
import static xanadu.enderdragon.config.Lang.error;
|
||||
|
||||
public class Config {
|
||||
public static String version;
|
||||
public static String lang;
|
||||
public static String damage_visible_mode;
|
||||
public static String special_dragon_jude_mode;
|
||||
public static boolean auto_respawn_enable;
|
||||
public static String auto_respawn_world_the_end_name;
|
||||
public static String auto_respawn_respawn_time;
|
||||
public static boolean auto_respawn_invulnerable;
|
||||
public static boolean resist_player_respawn;
|
||||
public static boolean resist_dragon_breath_gather;
|
||||
public static String main_gui;
|
||||
public static List<String> dragon_setting_file;
|
||||
public static void reload(FileConfiguration file){
|
||||
Field[] fields = Config.class.getFields();
|
||||
for(Field field : fields){
|
||||
Type type = field.getType();
|
||||
if(type.equals(java.util.List.class) || type.equals(java.lang.String.class)){
|
||||
try{
|
||||
field.set(null,"");
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
}
|
||||
Iterator<String> it = file.getKeys(true).iterator();
|
||||
while (it.hasNext()){
|
||||
String str = it.next();
|
||||
try{
|
||||
if(file.isConfigurationSection(str)) continue;
|
||||
Config.class.getField(str.replace(".","_")).set(null, file.get(str));
|
||||
}catch (Exception e){
|
||||
error("Config loading error! Key: "+str);
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package xanadu.enderdragon.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import xanadu.enderdragon.utils.SpecialColor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.EnderDragon.server;
|
||||
|
||||
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 gui_default_title;
|
||||
public static String gui_not_found;
|
||||
public static String gui_item_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 CommandTips1;
|
||||
public static String CommandTips2;
|
||||
public static String CommandTips3;
|
||||
public static String CommandTips4;
|
||||
public static void reload(FileConfiguration file){
|
||||
Field[] fields = Lang.class.getFields();
|
||||
for(Field field : fields){
|
||||
try{
|
||||
field.set(null,"");
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
Iterator<String> it = file.getKeys(true).iterator();
|
||||
while (it.hasNext()){
|
||||
String str = it.next();
|
||||
try{
|
||||
if(!file.isString(str)) continue;
|
||||
Lang.class.getField(str.replace(".","_")).set(null,SpecialColor.transGradient(file.getString(str)));
|
||||
}catch (Exception e){
|
||||
error("Language loading error! Key: "+str);
|
||||
}
|
||||
}
|
||||
CommandTips1 = SpecialColor.transGradient(lang.getString("CommandTips1","§e/ed reload §a- reload the config"));
|
||||
CommandTips2 = SpecialColor.transGradient(lang.getString("CommandTips2","§e/ed respawn §a- respawn a dragon"));
|
||||
CommandTips3 = SpecialColor.transGradient(lang.getString("CommandTips3","§e/ed drop gui §a- view the drop_item"));
|
||||
CommandTips4 = SpecialColor.transGradient(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) {
|
||||
Bukkit.getConsoleSender().sendMessage(Lang.plugin_prefix + "null");
|
||||
return;
|
||||
}
|
||||
if(str.contains("\\n")){
|
||||
String[] strings = str.split("\\\\n");
|
||||
for(String s : strings){
|
||||
sendMessage(s);
|
||||
}
|
||||
}
|
||||
else Bukkit.getConsoleSender().sendMessage(Lang.plugin_prefix + str);
|
||||
}
|
||||
public static void info(String str){
|
||||
if(str == null) {
|
||||
Bukkit.getConsoleSender().sendMessage("§a[EnderDragon] " + "null");
|
||||
return;
|
||||
}
|
||||
if(str.contains("\\n")){
|
||||
String[] strings = str.split("\\\\n");
|
||||
for(String s : strings){
|
||||
info(s);
|
||||
}
|
||||
}
|
||||
else Bukkit.getConsoleSender().sendMessage("§a[EnderDragon] "+str);
|
||||
}
|
||||
public static void warn(String str){
|
||||
if(str == null) {
|
||||
Bukkit.getConsoleSender().sendMessage("§e[EnderDragon] " + "null");
|
||||
return;
|
||||
}
|
||||
if(str.contains("\\n")){
|
||||
String[] strings = str.split("\\\\n");
|
||||
for(String s : strings){
|
||||
warn(s);
|
||||
}
|
||||
}
|
||||
else Bukkit.getConsoleSender().sendMessage("§e[EnderDragon] "+str);
|
||||
}
|
||||
public static void error(String str){
|
||||
if(str == null) {
|
||||
Bukkit.getConsoleSender().sendMessage("§c[EnderDragon] " + "null");
|
||||
return;
|
||||
}
|
||||
if(str.contains("\\n")){
|
||||
String[] strings = str.split("\\\\n");
|
||||
for(String s : strings){
|
||||
error(s);
|
||||
}
|
||||
}
|
||||
else Bukkit.getConsoleSender().sendMessage("§c[EnderDragon] "+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%")) server.dispatchCommand(server.getConsoleSender(),cmd);
|
||||
else{
|
||||
if(p != null) server.dispatchCommand(server.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;
|
||||
server.dispatchCommand(server.getConsoleSender(),cmd);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import xanadu.enderdragon.lang.Message;
|
||||
import xanadu.enderdragon.tools.MyMath;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class CreatureHurt implements Listener {
|
||||
@EventHandler
|
||||
public void OnCreatureHurt(EntityDamageByEntityEvent e){
|
||||
int DamageVisual = plugin.getConfig().getInt("special-dragon.damage-visible");
|
||||
String MSG = Message.DamageDisplay;
|
||||
if(DamageVisual == 0){return;}
|
||||
if(e.getDamager().getType() != EntityType.PLAYER){return;}
|
||||
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
|
||||
Player p = (Player) e.getDamager();
|
||||
double damage = MyMath.div(e.getFinalDamage(),1,2);
|
||||
MSG = MSG.replaceAll("%damage%", String.valueOf(damage));
|
||||
if(DamageVisual == 1){
|
||||
if(mcMainVersion >= 11){p.sendTitle("",MSG,5,40,5);}
|
||||
else if(mcMainVersion >= 9){p.sendTitle("",MSG);}
|
||||
}
|
||||
if(DamageVisual == 2){p.sendMessage(MSG);}
|
||||
if(DamageVisual == 3){
|
||||
if(mcMainVersion >= 10){
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MSG));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class DragonAttack implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void OnDragonAttack(EntityDamageByEntityEvent e){
|
||||
if(e.getDamager().getType() != EntityType.ENDER_DRAGON){return;}
|
||||
if(!isSpecial(e.getDamager())){return;}
|
||||
double multiple = plugin.getConfig().getDouble("special-dragon.damage-multiply");
|
||||
double rate = plugin.getConfig().getDouble("special-dragon.suck-blood.rate") / 100;
|
||||
double BasicSuck = plugin.getConfig().getDouble("special-dragon.suck-blood.base-suck-blood");
|
||||
boolean SuckBlood = plugin.getConfig().getBoolean("special-dragon.suck-blood.enable");
|
||||
boolean OnlyPlayer = plugin.getConfig().getBoolean("special-dragon.suck-blood.only-player");
|
||||
List<String> effects = plugin.getConfig().getStringList("special-dragon.attack-effect");
|
||||
if(e.getEntity() instanceof Player) {
|
||||
Player p = (Player) e.getEntity();
|
||||
if (multiple > 0) {
|
||||
double damage = e.getDamage();
|
||||
e.setDamage(damage * multiple);
|
||||
}
|
||||
for (String str : effects) {
|
||||
if (str.length() > 0) {
|
||||
String type = str.substring(0, str.indexOf(" "));
|
||||
int time = Integer.parseInt(str.substring(str.indexOf(" ") + 1, str.lastIndexOf(" ")));
|
||||
int level = Integer.parseInt(str.substring(str.lastIndexOf(" ") + 1));
|
||||
PotionEffectType effectType = PotionEffectType.getByName(type.toUpperCase());
|
||||
if (effectType != null) {
|
||||
p.addPotionEffect(new PotionEffect(effectType, time * 20, level - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!SuckBlood){return;}
|
||||
double FinalDamage = e.getFinalDamage();
|
||||
EnderDragon dragon = (EnderDragon) e.getDamager();
|
||||
double health = dragon.getHealth()+FinalDamage*rate+BasicSuck;
|
||||
if(health > dragon.getMaxHealth()){health = dragon.getMaxHealth();}
|
||||
dragon.setHealth(health);
|
||||
|
||||
}
|
||||
else{
|
||||
if((!SuckBlood) || OnlyPlayer){return;}
|
||||
double FinalDamage = e.getFinalDamage();
|
||||
EnderDragon dragon = (EnderDragon) e.getDamager();
|
||||
double health = dragon.getHealth()+FinalDamage*rate+BasicSuck;
|
||||
if(health > dragon.getMaxHealth()){health = dragon.getMaxHealth();}
|
||||
dragon.setHealth(health);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.EnderDragon;
|
||||
import xanadu.enderdragon.lang.Message;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class DragonDeath implements Listener {
|
||||
@EventHandler
|
||||
public void OnDragonDeath(EntityDeathEvent e) throws IOException {
|
||||
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
|
||||
int times = data.getInt("times");
|
||||
data.set("times",times+1);
|
||||
data.save(dataF);
|
||||
Player p = e.getEntity().getKiller();
|
||||
int exp = plugin.getConfig().getInt("special-dragon.exp-drop");
|
||||
int x = plugin.getConfig().getInt("special-dragon.dragon-egg-spawn.x");
|
||||
int y = plugin.getConfig().getInt("special-dragon.dragon-egg-spawn.y");
|
||||
int z = plugin.getConfig().getInt("special-dragon.dragon-egg-spawn.z");
|
||||
long delay = plugin.getConfig().getInt("special-dragon.dragon-egg-spawn.delay");
|
||||
boolean UseCMD = plugin.getConfig().getBoolean("command.enable");
|
||||
boolean EggChance = plugin.getConfig().getInt("special-dragon.dragon-egg-spawn.chance") > ThreadLocalRandom.current().nextInt(0, 100);
|
||||
boolean AllBroadcast = !plugin.getConfig().getBoolean("only-special-death-remind");
|
||||
String skill = Message.KillerMessage;
|
||||
String KillMsg = Message.DragonKillingBroadcast;
|
||||
String nobody = Message.NobodyKill;
|
||||
String InvIsFull = Message.PlayerInvFull;
|
||||
if(KillMsg != null) {
|
||||
if(p != null) {
|
||||
if (isSpecial(e.getEntity()) || AllBroadcast) {
|
||||
Bukkit.broadcastMessage(prefix + KillMsg.replaceAll("%times%", String.valueOf(times)).replaceAll("%player%", p.getDisplayName()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (Entity entity : e.getEntity().getNearbyEntities(5,5,5)) {
|
||||
if (entity instanceof Player) {
|
||||
names.append(((Player) entity).getDisplayName()).append(",");
|
||||
}
|
||||
}
|
||||
String name = names.toString();
|
||||
if(name.equals("")){name = nobody;}
|
||||
if(name.endsWith(",")){name = name.substring(0,name.length()-1);}
|
||||
if (isSpecial(e.getEntity()) || AllBroadcast) {
|
||||
Bukkit.broadcastMessage(prefix + KillMsg.replaceAll("%times%", String.valueOf(times)).replaceAll("%player%", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(UseCMD) {
|
||||
if (isSpecial(e.getEntity())) {
|
||||
List<String> CMDList = plugin.getConfig().getStringList("command.special-dragon");
|
||||
for (String command : CMDList) {
|
||||
if (!(p == null && command.contains("%player%"))) {
|
||||
server.dispatchCommand(server.getConsoleSender(), command.replaceAll("%player%", p.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<String> CMDList = plugin.getConfig().getStringList("command.normal-dragon");
|
||||
for (String command : CMDList) {
|
||||
if (!(p == null && command.contains("%player%"))) {
|
||||
server.dispatchCommand(server.getConsoleSender(), command.replaceAll("%player%", p.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isSpecial(e.getEntity())){
|
||||
e.setDroppedExp(exp);
|
||||
if (EggChance) {
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Block block = e.getEntity().getWorld().getBlockAt(x, y, z);
|
||||
block.setType(Material.DRAGON_EGG);
|
||||
}
|
||||
};
|
||||
runnable.runTaskLater(EnderDragon.getPlugin(EnderDragon.class), delay );
|
||||
}
|
||||
if(p != null){p.sendMessage(prefix + skill);}
|
||||
|
||||
List<String> datum = data.getStringList("items");
|
||||
int max = datum.size() / 2 ;
|
||||
boolean warning = false;
|
||||
for(int i=0 ; i<max ; ){
|
||||
i = i + 1;
|
||||
double chance = Double.parseDouble(datum.get(i*2-1));
|
||||
boolean judge = chance > Math.random() * 100;
|
||||
if(judge){
|
||||
String str = datum.get(i*2-2);
|
||||
ItemStack item = StringToItemStack(str);
|
||||
if(p == null){
|
||||
e.getEntity().getWorld().dropItem(e.getEntity().getLocation(),item);
|
||||
}
|
||||
else{
|
||||
if (p.getInventory().firstEmpty() == -1) {
|
||||
warning = true;
|
||||
}
|
||||
PlayerInventory inv = p.getInventory();
|
||||
inv.addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(warning){p.sendMessage(prefix + InvIsFull);}
|
||||
if(mcMainVersion < 11) {
|
||||
List<String> special = data.getStringList("special");
|
||||
special.remove(e.getEntity().getUniqueId().toString());
|
||||
data.set("special", special);
|
||||
data.save(dataF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.isSpecial;
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
|
||||
public class DragonHeal implements Listener {
|
||||
@EventHandler
|
||||
public void OnDragonHeal(EntityRegainHealthEvent e){
|
||||
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
|
||||
if(!e.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL)){return;}
|
||||
double NormalHeal = plugin.getConfig().getDouble("normal-dragon.crystal-heal");
|
||||
double SpecialHeal = plugin.getConfig().getDouble("special-dragon.crystal-heal");
|
||||
if(isSpecial(e.getEntity())){
|
||||
e.setAmount(SpecialHeal / 2);
|
||||
}
|
||||
else{
|
||||
e.setAmount(NormalHeal / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package xanadu.enderdragon.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import xanadu.enderdragon.lang.Message;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class DragonSpawn implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void OnDragonSpawn(CreatureSpawnEvent e) throws IOException {
|
||||
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
|
||||
int times = data.getInt("times");
|
||||
double health = plugin.getConfig().getDouble("special-dragon.max-health");
|
||||
double SpawnHealth = plugin.getConfig().getDouble("special-dragon.spawn-health");
|
||||
int circle = plugin.getConfig().getInt("special-dragon.respawn-circle");
|
||||
if (circle == 0 ){circle = 999999999;}
|
||||
boolean chance = plugin.getConfig().getInt("special-dragon.chance") > ThreadLocalRandom.current().nextInt(0, 100);
|
||||
boolean SpecialMsg0 = plugin.getConfig().getBoolean("special-dragon.spawn-remind");
|
||||
String SpawnMsg = Message.DragonSpawnBroadcast;
|
||||
String SpecialMsg = Message.SpecialBroadcast;
|
||||
String Name = plugin.getConfig().getString("special-dragon.name");
|
||||
String NormalName = plugin.getConfig().getString("normal-dragon.name");
|
||||
String color = plugin.getConfig().getString("special-dragon.glow-color");
|
||||
if(SpawnMsg == null){SpawnMsg = "none";}
|
||||
if(!SpawnMsg.equals("none")){
|
||||
Bukkit.broadcastMessage(prefix + SpawnMsg.replaceAll("%times%", String.valueOf(times)));
|
||||
}
|
||||
if(times % circle == 0 && chance) {
|
||||
if(mcMainVersion >= 11){e.getEntity().addScoreboardTag("special");}
|
||||
else{
|
||||
List<String> special = data.getStringList("special");
|
||||
special.add(e.getEntity().getUniqueId().toString());
|
||||
data.set("special",special);
|
||||
data.save(dataF);
|
||||
}
|
||||
if(health > 0) {
|
||||
e.getEntity().setMaxHealth(health);
|
||||
}
|
||||
e.getEntity().setHealth(SpawnHealth);
|
||||
if (color != null && mcMainVersion >= 9) {
|
||||
if(!color.equalsIgnoreCase("disable")) {
|
||||
color = color.toUpperCase();
|
||||
if(server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow") == null) {
|
||||
server.getScoreboardManager().getMainScoreboard().registerNewTeam("enderdragon-glow");
|
||||
}
|
||||
Team team = server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow");
|
||||
if(mcMainVersion >= 12) {
|
||||
team.setColor(ChatColor.valueOf(color));
|
||||
}
|
||||
else{
|
||||
team.setPrefix(ChatColor.valueOf(color).toString());
|
||||
}
|
||||
team.addEntry(e.getEntity().getUniqueId().toString());
|
||||
e.getEntity().setGlowing(true);
|
||||
}
|
||||
}
|
||||
e.getEntity().setCustomName(Name);
|
||||
if(SpecialMsg0 && SpecialMsg != null){
|
||||
Bukkit.broadcastMessage(prefix + SpecialMsg);
|
||||
}
|
||||
}
|
||||
else{
|
||||
e.getEntity().setCustomName(NormalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package xanadu.enderdragon.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.gui.slots.DragonSlot;
|
||||
import xanadu.enderdragon.gui.slots.EmptySlot;
|
||||
import xanadu.enderdragon.gui.slots.ItemSlot;
|
||||
import xanadu.enderdragon.manager.ItemManager;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.manager.DragonManager.*;
|
||||
|
||||
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(int type, String key){
|
||||
this.pagedItems.clear();
|
||||
this.pagedData.clear();
|
||||
if(type == 1){
|
||||
resetPagedItem(key);
|
||||
}
|
||||
else if(type == 2){
|
||||
for(MyDragon myDragon : dragons){
|
||||
this.addDragon(myDragon.icon.clone(),myDragon.unique_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void resetPagedItem(String key){
|
||||
this.pagedItems.clear();
|
||||
MyDragon dragon = mp.get(key);
|
||||
if(dragon == null) return;
|
||||
for(Reward reward : dragon.datum){
|
||||
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());
|
||||
ItemManager.addLore(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package xanadu.enderdragon.gui;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package xanadu.enderdragon.gui;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.slots.*;
|
||||
|
||||
public abstract class GUISlot {
|
||||
private final GUISlotType guiSlotType;
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package 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,GUISlotType>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package xanadu.enderdragon.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import xanadu.enderdragon.gui.slots.EmptySlot;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class GUIWrapper extends GUI{
|
||||
private final String name;
|
||||
private int type;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public GUIWrapper(GUIWrapper a, String key) {
|
||||
super(a.title, a.size, a.maxPage);
|
||||
this.inv = Bukkit.createInventory(new GUIHolder(this), this.size, this.title);
|
||||
this.slots.addAll(a.slots);
|
||||
this.dynamics.addAll(a.dynamics);
|
||||
this.name = a.name;
|
||||
this.type = a.type;
|
||||
this.init();
|
||||
this.resetPagedItem(type,key);
|
||||
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.inv = Bukkit.createInventory(new GUIHolder(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int calcline(final int a) {
|
||||
if (a < 1) {
|
||||
return 1;
|
||||
}
|
||||
return Math.min(a, 6);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package xanadu.enderdragon.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xanadu.enderdragon.utils.Chance;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.getCurrentTimeWithSpecialFormat;
|
||||
|
||||
|
||||
public class Reward extends ItemStack {
|
||||
protected String name;
|
||||
protected Chance chance;
|
||||
private ItemStack item;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
if(name == null){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta != null) {
|
||||
String displayName = meta.getDisplayName();
|
||||
if("".equals(displayName) || displayName == null){
|
||||
name = item.getType().name().toLowerCase() + "(" + getCurrentTimeWithSpecialFormat() + ")";
|
||||
}
|
||||
else name = meta.getDisplayName();
|
||||
}
|
||||
else name = item.getType().name().toLowerCase() + "(" + getCurrentTimeWithSpecialFormat() + ")";
|
||||
}
|
||||
|
||||
|
||||
yaml.set(name + ".data", item);
|
||||
yaml.set(name + ".drop_chance.value",chance.getValue());
|
||||
yaml.set(name + ".drop_chance.format",chance.getStr());
|
||||
return yaml.saveToString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public int hashCode() {
|
||||
// return this.name.hashCode();
|
||||
// }
|
||||
|
||||
public ItemStack getItem() {
|
||||
if(item == null) return new ItemStack(Material.AIR);
|
||||
return item.clone();
|
||||
}
|
||||
public Chance getChance(){
|
||||
return this.chance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Reward(ItemStack item,String chance) {
|
||||
this.item = item;
|
||||
|
||||
}
|
||||
public Reward(ItemStack item, Chance chance){
|
||||
this.item = item;
|
||||
this.chance = chance;
|
||||
}
|
||||
public Reward(ItemStack item){
|
||||
this.item = item;
|
||||
this.chance = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package xanadu.enderdragon.gui.slots;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.GUISlot;
|
||||
import 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package xanadu.enderdragon.gui.slots;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.GUISlot;
|
||||
import 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);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package xanadu.enderdragon.gui.slots;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.GUISlot;
|
||||
import xanadu.enderdragon.gui.GUISlotType;
|
||||
|
||||
public class ItemSlot extends GUISlot{
|
||||
private int i;
|
||||
// private final LoreMap<Boolean> G;
|
||||
private boolean XXXxxx;
|
||||
private ItemStack item;
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemOnDisable(){
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public int getMaxAmount() {
|
||||
return this.i;
|
||||
}
|
||||
|
||||
// public boolean accept(String a) {
|
||||
// if (!this.XXXxxx) {
|
||||
// return true;
|
||||
// }
|
||||
// if (this.G.get(a) != null) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public ItemSlot() {
|
||||
// super(GUISlotType.ITEM_SLOT);
|
||||
// this.G = new LoreMap(false, false, false, false);
|
||||
// this.XXXxxx = false;
|
||||
// this.i = 64;
|
||||
// }
|
||||
|
||||
public boolean acceptAll() {
|
||||
if (!this.XXXxxx) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package xanadu.enderdragon.gui.slots;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.GUISlotType;
|
||||
|
||||
import static xanadu.enderdragon.manager.ItemManager.readAsItem;
|
||||
|
||||
public class PageJumpSlot extends TipSlot{
|
||||
private final String name;
|
||||
private ItemStack item;
|
||||
|
||||
public String getGuiName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public PageJumpSlot(ConfigurationSection section) {
|
||||
super(GUISlotType.PAGE_JUMP, section);
|
||||
this.name = section.getString("gui");
|
||||
this.item = readAsItem(section,"data");
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package xanadu.enderdragon.gui.slots;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xanadu.enderdragon.gui.GUISlot;
|
||||
import xanadu.enderdragon.gui.GUISlotType;
|
||||
|
||||
import static xanadu.enderdragon.manager.ItemManager.readAsItem;
|
||||
|
||||
public class TipSlot extends GUISlot {
|
||||
private ItemStack item;
|
||||
private 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);
|
||||
this.item = readAsItem(section,"data");
|
||||
if(slotType == GUISlotType.PAGE_PREV || slotType == GUISlotType.PAGE_NEXT){
|
||||
this.itemOnDisable = readAsItem(section,"data_disable");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemOnDisable(){
|
||||
return this.itemOnDisable;
|
||||
}
|
||||
|
||||
public TipSlot(GUISlotType a, ItemStack item) {
|
||||
super(a);
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.manager.DragonManager.*;
|
||||
|
||||
public class CreatureSpawnListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void OnDragonSpawn(CreatureSpawnEvent e){
|
||||
if(!(e.getEntity() instanceof EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) e.getEntity();
|
||||
MyDragon myDragon = judge();
|
||||
if(myDragon == null) {
|
||||
Lang.warn("special_dragon_jude_mode setting error!");
|
||||
return;
|
||||
}
|
||||
setSpecialKey(dragon, myDragon.unique_name);
|
||||
int times = data.getInt("times");
|
||||
Lang.runCommands(myDragon.spawn_cmd);
|
||||
for(String str : myDragon.spawn_broadcast_msg){
|
||||
Lang.broadcastMSG(str.replaceAll("%times%",String.valueOf(times)));
|
||||
}
|
||||
dragon.setCustomName(myDragon.display_name);
|
||||
modifyAttribute(dragon, Attribute.GENERIC_MAX_HEALTH, myDragon.max_health - 200);
|
||||
dragon.setHealth(myDragon.spawn_health);
|
||||
modifyAttribute(dragon, Attribute.GENERIC_MOVEMENT_SPEED, myDragon.move_speed_modify);
|
||||
modifyAttribute(dragon, Attribute.GENERIC_ARMOR, myDragon.armor_modify);
|
||||
modifyAttribute(dragon, Attribute.GENERIC_ARMOR_TOUGHNESS, myDragon.armor_toughness_modify);
|
||||
String color = myDragon.glow_color.toUpperCase();
|
||||
if(!color.equals("NONE")){
|
||||
ChatColor chatColor;
|
||||
if(color.equals("RANDOM")) chatColor = randomColor();
|
||||
else chatColor = ChatColor.valueOf(color);
|
||||
setGlowingColor(dragon,chatColor);
|
||||
}
|
||||
else dragon.setGlowing(false);
|
||||
if(mcMainVersion >= 14 || mcMainVersion >= 13 && mcPatchVersion >= 2){
|
||||
BossBar bossBar = dragon.getBossBar();
|
||||
if(bossBar != null){
|
||||
bossBar.setColor(BarColor.valueOf(myDragon.bossbar_color.toUpperCase()));
|
||||
bossBar.setStyle(BarStyle.valueOf(myDragon.bossbar_style.toUpperCase()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void OnCrystalPlaced(final PlayerInteractEvent e){
|
||||
if(!Config.resist_player_respawn) return;
|
||||
if(e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if(e.getMaterial() != Material.END_CRYSTAL) return;
|
||||
if(e.getClickedBlock() == null) return;
|
||||
Material blockType = e.getClickedBlock().getType();
|
||||
if(blockType != Material.OBSIDIAN && blockType != Material.BEDROCK) return;
|
||||
World world = e.getPlayer().getWorld();
|
||||
if(world.getEnvironment() != World.Environment.THE_END) return;
|
||||
Block block = e.getClickedBlock();
|
||||
int d0 = block.getX();
|
||||
int d1 = block.getY() + 1;
|
||||
int d2 = block.getZ();
|
||||
if(world.getBlockAt(d0, d1, d2).getType() != Material.AIR) return;
|
||||
Location cen = block.getLocation().clone().add(0.5,1,0.5);
|
||||
Collection<Entity> list = world.getNearbyEntities(cen,0.5,1,0.5);
|
||||
if(!list.isEmpty()) return;
|
||||
e.setCancelled(true);
|
||||
EnderCrystal crystal = (EnderCrystal) world.spawnEntity(cen,EntityType.ENDER_CRYSTAL);
|
||||
crystal.setShowingBottom(false);
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void OnEffectCloudSpawn(final EntitySpawnEvent e){
|
||||
if(!(e.getEntity() instanceof AreaEffectCloud)) return;
|
||||
AreaEffectCloud effectCloud = (AreaEffectCloud) e.getEntity();
|
||||
if(effectCloud.getSource() == null) return;
|
||||
if(!(effectCloud.getSource() instanceof EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) effectCloud.getSource();
|
||||
String unique_name = getSpecialKey(dragon);
|
||||
if(unique_name == null) return;
|
||||
MyDragon myDragon = mp.get(unique_name);
|
||||
if(myDragon == null) return;
|
||||
effectCloud.setRadius((float) myDragon.effect_cloud_original_radius);
|
||||
effectCloud.setRadiusPerTick((float) myDragon.effect_cloud_expand_speed/20f);
|
||||
effectCloud.setDuration(myDragon.effect_cloud_duration * 20);
|
||||
if(myDragon.effect_cloud_color_R != -1){
|
||||
effectCloud.setParticle(Particle.SPELL_MOB);
|
||||
effectCloud.setColor(Color.fromRGB(myDragon.effect_cloud_color_R,myDragon.effect_cloud_color_G,myDragon.effect_cloud_color_B));
|
||||
}
|
||||
effectCloud.clearCustomEffects();
|
||||
for(PotionEffect effect : myDragon.effect_cloud_potion){
|
||||
effectCloud.addCustomEffect(effect,true);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void OnDragonBreathGather(final PlayerInteractEvent e){
|
||||
if(!Config.resist_dragon_breath_gather) return;
|
||||
if(e.getMaterial() != Material.GLASS_BOTTLE) return;
|
||||
if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return;
|
||||
World world = e.getPlayer().getWorld();
|
||||
if(world.getEnvironment() != World.Environment.THE_END) return;
|
||||
Player p = e.getPlayer();
|
||||
Location cen = p.getLocation().clone().add(0d,0.9d,0d);
|
||||
Collection<Entity> list = world.getNearbyEntities(cen,2.3d,2.9d,2.3d);
|
||||
for(Entity entity : list){
|
||||
if(entity instanceof AreaEffectCloud) {
|
||||
AreaEffectCloud effectCloud = (AreaEffectCloud) entity;
|
||||
if(effectCloud.getSource() instanceof EnderDragon){
|
||||
e.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import xanadu.enderdragon.events.DragonDamageByPlayerEvent;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.pm;
|
||||
|
||||
public class DragonBaseHurtListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void BaseAttackToDragon(EntityDamageByEntityEvent e){
|
||||
if(e.isCancelled()) return;
|
||||
if(e.getDamage() <= 0.0) return;
|
||||
Entity victim = e.getEntity();
|
||||
Entity entity = e.getDamager();
|
||||
if(victim instanceof EnderDragon){
|
||||
EnderDragon dragon = (EnderDragon) victim;
|
||||
if(entity instanceof Player){
|
||||
Player player = (Player) entity;
|
||||
pm.callEvent(new DragonDamageByPlayerEvent(player,dragon,e.getCause(),e.getFinalDamage()));
|
||||
}
|
||||
else if(entity instanceof Projectile){
|
||||
Projectile projectile = (Projectile) entity;
|
||||
if(!(projectile.getShooter() instanceof Player)) return;
|
||||
Player damager = (Player) projectile.getShooter();
|
||||
pm.callEvent(new DragonDamageByPlayerEvent(damager,dragon,e.getCause(),e.getFinalDamage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.events.DragonDamageByPlayerEvent;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.utils.MathUtils;
|
||||
|
||||
public class DragonDamageByPlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void OnDragonDamageByPlayer(DragonDamageByPlayerEvent e){
|
||||
Player p = e.getDamager();
|
||||
double damage = e.getFinalDamage();
|
||||
EnderDragon dragon = e.getDragon();
|
||||
double max_health = dragon.getMaxHealth();
|
||||
double remain_health = Math.max(dragon.getHealth()-e.getFinalDamage(),0.0);
|
||||
String str = Lang.dragon_damage_display.replaceAll("%damage%", format(damage)).replaceAll("%remain_health%",format(remain_health)).replaceAll("%max_health%",format(max_health));
|
||||
switch (Config.damage_visible_mode.toLowerCase()){
|
||||
case "actionbar" : {
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(str));
|
||||
break;
|
||||
}
|
||||
case "chatbox" : {
|
||||
Lang.sendFeedback(p,str);
|
||||
break;
|
||||
}
|
||||
case "subtitle" : {
|
||||
p.sendTitle("",str,5,40,5);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private String format(double d0){
|
||||
return String.valueOf(MathUtils.div(d0,1,2));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.gui.Reward;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
import static xanadu.enderdragon.manager.DragonManager.getSpecialKey;
|
||||
import static xanadu.enderdragon.manager.DragonManager.mp;
|
||||
|
||||
public class DragonDeathListener implements Listener {
|
||||
@EventHandler
|
||||
public void OnDragonDeath(EntityDeathEvent e){
|
||||
if(!(e.getEntity() instanceof EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) e.getEntity();
|
||||
String unique_name = getSpecialKey(dragon);
|
||||
if(unique_name == null) return;
|
||||
MyDragon myDragon = mp.get(unique_name);
|
||||
if(myDragon == null) return;
|
||||
int times = data.getInt("times");
|
||||
data.set("times",times+1);
|
||||
try{
|
||||
data.save(dataF);
|
||||
}catch (IOException ex){
|
||||
error(plugin_file_save_error.replaceAll("\\{file_name}",dataF.getName()));
|
||||
}
|
||||
e.setDroppedExp(myDragon.exp_drop);
|
||||
if(myDragon.dragon_egg_spawn_chance > ThreadLocalRandom.current().nextDouble(100)){
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Block block = e.getEntity().getWorld().getBlockAt(myDragon.dragon_egg_spawn_x, myDragon.dragon_egg_spawn_y, myDragon.dragon_egg_spawn_z);
|
||||
block.setType(Material.DRAGON_EGG);
|
||||
}
|
||||
};
|
||||
runnable.runTaskLater(plugin, myDragon.dragon_egg_spawn_delay);
|
||||
}
|
||||
Player p = e.getEntity().getKiller();
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
for(Reward reward : myDragon.datum){
|
||||
double chance = reward.getChance().getValue();
|
||||
if(chance > ThreadLocalRandom.current().nextDouble(100)){
|
||||
list.add(reward.getItem());
|
||||
}
|
||||
}
|
||||
if(!list.isEmpty()){
|
||||
boolean warn = false;
|
||||
if(p == null){
|
||||
Location loc = dragon.getLocation();
|
||||
World world = dragon.getWorld();
|
||||
list.forEach(item -> world.dropItem(loc,item));
|
||||
}
|
||||
else{
|
||||
for(ItemStack item : list){
|
||||
if(p.getInventory().firstEmpty() == -1){
|
||||
p.getWorld().dropItem(p.getLocation(),item);
|
||||
warn = true;
|
||||
}
|
||||
else p.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
if(warn) sendFeedback(p, dragon_player_inv_full);
|
||||
}
|
||||
runCommands(myDragon.death_cmd,p);
|
||||
if(p != null){
|
||||
for(String str : myDragon.msg_to_killer){
|
||||
sendFeedback(p,str);
|
||||
}
|
||||
for(String str : myDragon.death_broadcast_msg){
|
||||
broadcastMSG(str.replaceAll("%times%",String.valueOf(times)).replaceAll("%player%",p.getDisplayName()));
|
||||
}
|
||||
}
|
||||
else{
|
||||
StringBuilder names = new StringBuilder();
|
||||
List<Entity> entities = dragon.getNearbyEntities(5,5,5);
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof Player) {
|
||||
names.append(((Player) entity).getDisplayName()).append(",");
|
||||
}
|
||||
}
|
||||
String name = names.toString();
|
||||
if(name.equals("")) name = dragon_no_killer;
|
||||
if(name.endsWith(",")) name = name.substring(0,name.length()-1);
|
||||
for(String str : myDragon.death_broadcast_msg){
|
||||
broadcastMSG(str.replaceAll("%times%",String.valueOf(times)).replaceAll("%player%", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import static xanadu.enderdragon.manager.DragonManager.getSpecialKey;
|
||||
import static xanadu.enderdragon.manager.DragonManager.mp;
|
||||
|
||||
public class DragonHealListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void OnDragonHeal(EntityRegainHealthEvent e){
|
||||
if(!(e.getEntity() instanceof EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) e.getEntity();
|
||||
if(!e.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL)) return;
|
||||
String unique_name = getSpecialKey(dragon);
|
||||
if(unique_name == null) return;
|
||||
MyDragon myDragon = mp.get(unique_name);
|
||||
if(myDragon == null) return;
|
||||
e.setAmount(myDragon.crystal_heal_speed / 2d);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import xanadu.enderdragon.events.DragonDamageByPlayerEvent;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.pm;
|
||||
import static xanadu.enderdragon.manager.DragonManager.getSpecialKey;
|
||||
import static xanadu.enderdragon.manager.DragonManager.mp;
|
||||
|
||||
public class EntityDamageByEntityListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void OnDragonAttack(EntityDamageByEntityEvent e){
|
||||
Entity victim = e.getEntity();
|
||||
Entity attack = e.getDamager();
|
||||
if(!(attack instanceof EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) attack;
|
||||
String unique_name = getSpecialKey(dragon);
|
||||
if(unique_name == null) return;
|
||||
MyDragon myDragon = mp.get(unique_name);
|
||||
if(myDragon == null) return;
|
||||
e.setDamage(Math.max(0.1, e.getDamage() + myDragon.attack_damage_modify));
|
||||
if(victim instanceof Player){
|
||||
Player player = (Player) victim;
|
||||
for(PotionEffect effect : myDragon.attack_potion_effect){
|
||||
player.addPotionEffect(effect);
|
||||
}
|
||||
if(!myDragon.suck_blood_enable) return;
|
||||
double suck = e.getFinalDamage() * myDragon.suck_blood_rate + myDragon.suck_blood_base_amount;
|
||||
dragon.setHealth(Math.min(dragon.getHealth()+suck,dragon.getMaxHealth()));
|
||||
}
|
||||
else{
|
||||
if(!myDragon.suck_blood_enable) return;
|
||||
if(myDragon.suck_blood_only_player) return;
|
||||
double suck = e.getFinalDamage() * myDragon.suck_blood_rate + myDragon.suck_blood_base_amount;
|
||||
dragon.setHealth(Math.min(dragon.getHealth()+suck,dragon.getMaxHealth()));
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void ExtraAttackToDragon(EntityDamageByEntityEvent e){
|
||||
if(e.isCancelled()) return;
|
||||
if(e.getDamage() <= 0.0) return;
|
||||
Entity victim = e.getEntity();
|
||||
Entity entity = e.getDamager();
|
||||
if(victim instanceof EnderDragon){
|
||||
EnderDragon dragon = (EnderDragon) victim;
|
||||
if(entity instanceof TNTPrimed){
|
||||
TNTPrimed tnt = (TNTPrimed) entity;
|
||||
if(!(tnt.getSource() instanceof Player)) return;
|
||||
Player damager = (Player) tnt.getSource();
|
||||
pm.callEvent(new DragonDamageByPlayerEvent(damager,dragon,e.getCause(),e.getFinalDamage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
|
||||
public class InventoryClick implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void OnInventoryClick(InventoryClickEvent e){
|
||||
String title = plugin.getConfig().getString("special-dragon.drop-gui-title");
|
||||
if(!e.getView().getTitle().contains(title)){return;}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import xanadu.enderdragon.gui.GUISlot;
|
||||
import xanadu.enderdragon.gui.GUISlotType;
|
||||
import xanadu.enderdragon.gui.GUIWrapper;
|
||||
import xanadu.enderdragon.gui.GUIHolder;
|
||||
import xanadu.enderdragon.gui.slots.PageJumpSlot;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.manager.GuiManager;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import static xanadu.enderdragon.manager.DragonManager.mp;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void OnInventoryClick(InventoryClickEvent e){
|
||||
InventoryHolder holder = e.getInventory().getHolder();
|
||||
if(!(holder instanceof GUIHolder)) return;
|
||||
e.setCancelled(true);
|
||||
GUIHolder guiHolder = (GUIHolder) holder;
|
||||
if(!(guiHolder.getGUI() instanceof GUIWrapper)) return;
|
||||
GUIWrapper guiWrapper = (GUIWrapper) guiHolder.getGUI();
|
||||
if(e.getClickedInventory() instanceof PlayerInventory){
|
||||
return;
|
||||
}
|
||||
if(e.getClick() != ClickType.LEFT && e.getClick() != ClickType.RIGHT){
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() >= 54 || e.getRawSlot() < 0){ //点击箱子以外界面会返回-999
|
||||
return;
|
||||
}
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
GUISlot slot = guiWrapper.getSlot(e.getRawSlot());
|
||||
GUISlotType type = slot.getType();
|
||||
if(type == GUISlotType.EMPTY || type == GUISlotType.TIP || type == GUISlotType.PAGE_TIP || type == GUISlotType.ITEM_SLOT){
|
||||
return;
|
||||
}
|
||||
if(type == GUISlotType.PAGE_PREV){
|
||||
guiWrapper.prev();
|
||||
p.updateInventory();
|
||||
return;
|
||||
}
|
||||
if(type == GUISlotType.PAGE_NEXT){
|
||||
guiWrapper.next();
|
||||
p.updateInventory();
|
||||
return;
|
||||
}
|
||||
if(type == GUISlotType.PAGE_JUMP){
|
||||
String name = ((PageJumpSlot)slot).getGuiName();
|
||||
GuiManager.openGui(p,name);
|
||||
return;
|
||||
}
|
||||
if(type == GUISlotType.DRAGON_SLOT){
|
||||
String unique_name = guiWrapper.getData(guiWrapper.getPage(),e.getRawSlot());
|
||||
MyDragon dragon = mp.get(unique_name);
|
||||
if(dragon == null){
|
||||
Lang.sendFeedback(p,Lang.gui_not_found);
|
||||
return;
|
||||
}
|
||||
GuiManager.openGui(p,dragon.drop_gui,dragon.unique_name);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void OnInventoryDrag(InventoryDragEvent e){
|
||||
InventoryHolder holder = e.getInventory().getHolder();
|
||||
if(!(holder instanceof GUIHolder)) return;
|
||||
GUIHolder guiHolder = (GUIHolder) holder;
|
||||
if(!(guiHolder.getGUI() instanceof GUIWrapper)) return;
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package xanadu.enderdragon.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class PluginDisableListener implements Listener {
|
||||
@EventHandler
|
||||
public void OnPluginDisable(PluginDisableEvent e){
|
||||
if(e.getPlugin().equals(plugin)){
|
||||
disableAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package xanadu.enderdragon.listeners.mmoitems;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.damage.MeleeAttackMetadata;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.TypeSet;
|
||||
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class MMOPlayerAttackListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void meleeAttacks(PlayerAttackEvent e) {
|
||||
if (!(e.getAttack() instanceof MeleeAttackMetadata)) {
|
||||
return;
|
||||
}
|
||||
MeleeAttackMetadata attackMetadata = (MeleeAttackMetadata) e.getAttack();
|
||||
Player player = e.getPlayer();
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
NBTItem nBTItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItem(attackMetadata.getHand().toBukkit()));
|
||||
if (nBTItem.hasType() && Type.get(nBTItem.getType()) != Type.BLOCK) {
|
||||
Weapon weapon = new Weapon(playerData, nBTItem);
|
||||
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
|
||||
e.setCancelled(true);
|
||||
} else if (!weapon.checkItemRequirements()) {
|
||||
e.setCancelled(true);
|
||||
} else if (!weapon.handleTargetedAttack(e.getAttack(), e.getEntity())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package xanadu.enderdragon.listeners.mythiclib;
|
||||
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import io.lumine.mythic.lib.damage.DamageMetadata;
|
||||
import io.lumine.mythic.lib.damage.DamageType;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import xanadu.enderdragon.events.DragonDamageByPlayerEvent;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.pm;
|
||||
|
||||
public class PlayerAttackListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerAttack(PlayerAttackEvent e){
|
||||
if(e.isCancelled()) return;
|
||||
if(!(e.getEntity() instanceof org.bukkit.entity.EnderDragon)) return;
|
||||
EnderDragon dragon = (EnderDragon) e.getEntity();
|
||||
DamageMetadata damage = e.getDamage();
|
||||
double weapon = damage.getDamage(DamageType.WEAPON) + damage.getDamage(DamageType.UNARMED);
|
||||
if(weapon > 0.0d) {
|
||||
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(e.getAttacker().getPlayer(),dragon, e.toBukkit().getCause(), weapon);
|
||||
pm.callEvent(event);
|
||||
return;
|
||||
}
|
||||
double skill = damage.getDamage(DamageType.SKILL);
|
||||
if(skill >= 0.0d){
|
||||
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(e.getAttacker().getPlayer(),dragon, e.toBukkit().getCause(), skill);
|
||||
pm.callEvent(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
package xanadu.enderdragon.manager;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.boss.DragonBattle;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
import xanadu.enderdragon.utils.Version;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
import static xanadu.enderdragon.manager.ItemManager.readAsItem;
|
||||
|
||||
public class DragonManager {
|
||||
public static ArrayList<MyDragon> dragons = new ArrayList<>();
|
||||
public static HashMap<String, MyDragon> mp = new HashMap<>();
|
||||
public static List<String> dragon_names = new ArrayList<>();
|
||||
private static int sum = 0;
|
||||
private static final int[][] nxt = {{3,0},{0,3},{-3,0},{0,-3}};
|
||||
private Method DragonBattle_e;
|
||||
private Method getX;
|
||||
private Method getY;
|
||||
private Method getZ;
|
||||
private Method getNMSWord;
|
||||
private Class<?> CraftWorldClass = null;
|
||||
private Class<?> WorldProviderTheEndClass = null;
|
||||
|
||||
public static void reload(){
|
||||
new BukkitRunnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
dragons.clear();
|
||||
mp.clear();
|
||||
dragon_names.clear();
|
||||
sum = 0;
|
||||
if(Config.dragon_setting_file == null){
|
||||
error("\"dragon_setting_file\" in config.yml is empty!");
|
||||
warn("Plugin will use the default config...");
|
||||
Config.dragon_setting_file = new ArrayList<>();
|
||||
Config.dragon_setting_file.add("default:5");
|
||||
Config.dragon_setting_file.add("special:5");
|
||||
}
|
||||
for(String str : Config.dragon_setting_file){
|
||||
String[] s = str.split(":");
|
||||
if(s.length != 2){
|
||||
error("\"dragon_setting_file\" in config.yml error! Key: " + str);
|
||||
continue;
|
||||
}
|
||||
String path = "setting/" + s[0] + ".yml";
|
||||
int edge = -1;
|
||||
try {
|
||||
edge = Integer.parseInt(s[1]);
|
||||
} catch (NumberFormatException ignored){}
|
||||
if(edge < 0) {
|
||||
error("\"dragon_setting_file\" in config.yml error! Key: " + str);
|
||||
continue;
|
||||
}
|
||||
File file = new File(plugin.getDataFolder(),path);
|
||||
if(!file.exists()) {
|
||||
try{
|
||||
plugin.saveResource("setting/"+file.getName(),false);
|
||||
file = new File(plugin.getDataFolder(),path);
|
||||
}catch (Exception ignored){
|
||||
error("Not Found setting/" + s[0] + ".yml ,skipped it.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
|
||||
readSettingFile(fc,edge);
|
||||
}
|
||||
dragons.sort((o1, o2) -> o2.priority - o1.priority);
|
||||
RewardManager.reload();
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
||||
}
|
||||
public static MyDragon judge(){
|
||||
if(Config.special_dragon_jude_mode.equalsIgnoreCase("weight")){
|
||||
int cnt = 0, random = ThreadLocalRandom.current().nextInt(0, sum);
|
||||
for(MyDragon cur : dragons){
|
||||
if(cnt <= random && cnt + cur.edge > random){
|
||||
return cur;
|
||||
}
|
||||
cnt += cur.edge;
|
||||
}
|
||||
}
|
||||
else if(Config.special_dragon_jude_mode.equalsIgnoreCase("pc")){
|
||||
Iterator<MyDragon> it = dragons.iterator();
|
||||
MyDragon cur = null;
|
||||
while (it.hasNext()){
|
||||
cur = it.next();
|
||||
boolean judge = cur.spawn_chance > ThreadLocalRandom.current().nextDouble(100);
|
||||
if(judge) return cur;
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
else if(Config.special_dragon_jude_mode.equalsIgnoreCase("edge")){
|
||||
int cnt = 0, random = ThreadLocalRandom.current().nextInt(0, sum);
|
||||
for(MyDragon cur : dragons){
|
||||
if(cnt <= random && cnt + cur.edge > random){
|
||||
return cur;
|
||||
}
|
||||
cnt += cur.edge;
|
||||
}
|
||||
error("\"edge\" in \"special_dragon_jude_mode\" of config.yml is deprecated!Please use \"weight\" instead.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void setSpecialKey(Entity e, String key){
|
||||
e.addScoreboardTag(key);
|
||||
}
|
||||
public static String getSpecialKey(Entity e){
|
||||
for(MyDragon a : dragons){
|
||||
if(e.getScoreboardTags().contains(a.unique_name)) return a.unique_name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void readSettingFile(FileConfiguration f,int edge){
|
||||
MyDragon myDragon = new MyDragon();
|
||||
myDragon.unique_name = f.getString("unique_name","default");
|
||||
if(mp.containsKey(myDragon.unique_name)){
|
||||
error("The unique_name conflict! Key: "+myDragon.unique_name);
|
||||
return;
|
||||
}
|
||||
myDragon.icon = readAsItem(f,"icon");
|
||||
myDragon.display_name = f.getString("display_name","Special Dragon");
|
||||
myDragon.drop_gui = f.getString("drop_gui");
|
||||
myDragon.edge = edge;
|
||||
myDragon.priority = f.getInt("priority",1);
|
||||
myDragon.spawn_chance = f.getDouble("spawn_chance",0);
|
||||
myDragon.max_health = f.getInt("max_health",200);
|
||||
myDragon.spawn_health = f.getInt("spawn_health",200);
|
||||
myDragon.exp_drop = f.getInt("exp_drop",500);
|
||||
myDragon.dragon_egg_spawn_delay = f.getInt("dragon_egg_spawn.delay",410);
|
||||
myDragon.dragon_egg_spawn_x = f.getInt("dragon_egg_spawn.x",0);
|
||||
myDragon.dragon_egg_spawn_y = f.getInt("dragon_egg_spawn.y",70);
|
||||
myDragon.dragon_egg_spawn_z = f.getInt("dragon_egg_spawn.z",0);
|
||||
myDragon.dragon_egg_spawn_chance = f.getDouble("dragon_egg_spawn.chance",0);
|
||||
myDragon.attack_damage_modify = f.getDouble("attack_damage_modify",0);
|
||||
myDragon.move_speed_modify = f.getDouble("move_speed_modify",0);
|
||||
myDragon.armor_modify = f.getDouble("armor_modify",0);
|
||||
myDragon.armor_toughness_modify = f.getDouble("armor_toughness_modify",0);
|
||||
myDragon.crystal_heal_speed = f.getDouble("crystal_heal_speed",2.0);
|
||||
myDragon.suck_blood_enable = f.getBoolean("suck_blood.enable",true);
|
||||
myDragon.suck_blood_rate = f.getDouble("suck_blood.rate",50) / 100d;
|
||||
myDragon.suck_blood_base_amount = f.getDouble("suck_blood.base_amount",1);
|
||||
myDragon.suck_blood_only_player = f.getBoolean("suck_blood.only_player",true);
|
||||
List<String> stringList = f.getStringList("attack_potion_effect");
|
||||
List<PotionEffect> potions = new ArrayList<>();
|
||||
for(String string : stringList){
|
||||
String[] s = string.split(" ");
|
||||
if(s.length != 3) continue;
|
||||
PotionEffectType type = PotionEffectType.getByName(s[0].toUpperCase());
|
||||
if(type == null){
|
||||
error("Unknown potion type: " + s[0]);
|
||||
continue;
|
||||
}
|
||||
int duration = -1;
|
||||
try {
|
||||
duration = Integer.parseInt(s[1]);
|
||||
} catch (NumberFormatException ex){
|
||||
error("Wrong number format: " + s[1]);
|
||||
}
|
||||
if(duration == -1) continue;
|
||||
int level = -1;
|
||||
try {
|
||||
level = Integer.parseInt(s[2]);
|
||||
} catch (NumberFormatException ex){
|
||||
error("Wrong number format: " + s[2]);
|
||||
}
|
||||
if(level == -1) continue;
|
||||
PotionEffect potionEffect = new PotionEffect(type,duration*20,level-1);
|
||||
potions.add(potionEffect);
|
||||
}
|
||||
myDragon.attack_potion_effect = potions;
|
||||
myDragon.spawn_cmd = f.getStringList("spawn_cmd");
|
||||
myDragon.death_cmd = f.getStringList("death_cmd");
|
||||
myDragon.spawn_broadcast_msg = f.getStringList("spawn_broadcast_msg");
|
||||
myDragon.death_broadcast_msg = f.getStringList("death_broadcast_msg");
|
||||
myDragon.msg_to_killer = f.getStringList("msg_to_killer");
|
||||
myDragon.glow_color = f.getString("glow_color","random");
|
||||
myDragon.bossbar_color = f.getString("bossbar.color","WHITE");
|
||||
myDragon.bossbar_style = f.getString("bossbar.style","SOLID");
|
||||
myDragon.effect_cloud_original_radius = f.getDouble("effect_cloud.original_radius",3);
|
||||
myDragon.effect_cloud_expand_speed = f.getDouble("effect_cloud.expand_speed",0.1333333);
|
||||
myDragon.effect_cloud_duration = f.getInt("effect_cloud.duration",60);
|
||||
String effect_cloud_color = f.getString("effect_cloud.color","none");
|
||||
String[] s0 = effect_cloud_color.split(":");
|
||||
if(s0.length != 3) myDragon.effect_cloud_color_R = -1;
|
||||
else{
|
||||
try{
|
||||
myDragon.effect_cloud_color_R = Integer.parseInt(s0[0]);
|
||||
myDragon.effect_cloud_color_G = Integer.parseInt(s0[1]);
|
||||
myDragon.effect_cloud_color_B = Integer.parseInt(s0[2]);
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
error("Wrong effect_cloud_color format!");
|
||||
myDragon.effect_cloud_color_R = -1;
|
||||
}
|
||||
}
|
||||
List<String> stringList2 = f.getStringList("effect_cloud.potion");
|
||||
List<PotionEffect> effectCloudPotions = new ArrayList<>();
|
||||
for(String string : stringList2){
|
||||
String[] s = string.split(" ");
|
||||
if(s.length != 3) continue;
|
||||
PotionEffectType type = PotionEffectType.getByName(s[0].toUpperCase());
|
||||
if(type == null){
|
||||
error("Unknown potion type: " + s[0]);
|
||||
continue;
|
||||
}
|
||||
int duration = -1;
|
||||
try {
|
||||
duration = Integer.parseInt(s[1]);
|
||||
} catch (NumberFormatException ex){
|
||||
error("Wrong number format: " + s[1]);
|
||||
}
|
||||
if(duration == -1) continue;
|
||||
int level = -1;
|
||||
try {
|
||||
level = Integer.parseInt(s[2]);
|
||||
} catch (NumberFormatException ex){
|
||||
error("Wrong number format: " + s[2]);
|
||||
}
|
||||
if(level == -1) continue;
|
||||
PotionEffect potionEffect = new PotionEffect(type,duration*20,level-1);
|
||||
effectCloudPotions.add(potionEffect);
|
||||
}
|
||||
myDragon.effect_cloud_potion = effectCloudPotions;
|
||||
dragons.add(myDragon);
|
||||
mp.put(myDragon.unique_name,myDragon);
|
||||
dragon_names.add(myDragon.unique_name);
|
||||
sum += edge;
|
||||
}
|
||||
public static void disable(){
|
||||
dragons.clear();
|
||||
mp.clear();
|
||||
dragon_names.clear();
|
||||
}
|
||||
|
||||
public static void setAttribute(EnderDragon dragon, Attribute attribute, double amount){
|
||||
AttributeInstance instance = dragon.getAttribute(attribute);
|
||||
assert instance != null;
|
||||
instance.setBaseValue(amount);
|
||||
}
|
||||
public static void modifyAttribute(EnderDragon dragon, Attribute attribute, double amount){
|
||||
AttributeInstance instance = dragon.getAttribute(attribute);
|
||||
assert instance != null;
|
||||
instance.addModifier(new AttributeModifier("EnderDragon",amount,AttributeModifier.Operation.ADD_NUMBER));
|
||||
}
|
||||
public static ChatColor randomColor(){
|
||||
return ChatColor.values()[ThreadLocalRandom.current().nextInt(16)];
|
||||
}
|
||||
public static void setGlowingColor(Entity entity,ChatColor color){
|
||||
if(server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow") == null) {
|
||||
server.getScoreboardManager().getMainScoreboard().registerNewTeam("enderdragon-glow");
|
||||
}
|
||||
Team team = server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow");
|
||||
assert team != null;
|
||||
if(mcMainVersion >= 13) team.setColor(color);
|
||||
else team.setPrefix(color.toString());
|
||||
team.addEntry(entity.getUniqueId().toString());
|
||||
entity.setGlowing(true);
|
||||
}
|
||||
public void initiateRespawn(Player p){
|
||||
boolean f = initiateRespawn(p.getWorld());
|
||||
if(!f) sendFeedback(p,"§cThere is already a dragon here or respawning has started.");
|
||||
else Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||
}
|
||||
public boolean initiateRespawn(World world){
|
||||
if(world == null) return false;
|
||||
if(world.getEnvironment() != World.Environment.THE_END) return false;
|
||||
if(mcMainVersion >= 16){
|
||||
DragonBattle battle = world.getEnderDragonBattle();
|
||||
assert battle != null;
|
||||
if(battle.getEnderDragon() != null){
|
||||
error("There is already a dragon here.");
|
||||
return false;
|
||||
}
|
||||
if(battle.getRespawnPhase() == DragonBattle.RespawnPhase.NONE){
|
||||
Location cen = battle.getEndPortalLocation();
|
||||
if(cen == null) {
|
||||
battle.initiateRespawn();
|
||||
cen = battle.getEndPortalLocation();
|
||||
if(cen == null){
|
||||
error("The world_the_end is unloaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
placeEndCrystals(world,cen);
|
||||
battle.initiateRespawn();
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
error("The respawning has already started.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object battle = getEnderDragonBattle(world);
|
||||
assert battle != null;
|
||||
Field k = battle.getClass().getDeclaredField("k");
|
||||
k.setAccessible(true);
|
||||
Object isAlive = k.get(battle);
|
||||
if(!((boolean) isAlive)) {
|
||||
error("There is already a dragon here.");
|
||||
return false;
|
||||
}
|
||||
Field p = battle.getClass().getDeclaredField("p");
|
||||
p.setAccessible(true);
|
||||
Object phase = p.get(battle);
|
||||
if(phase != null) {
|
||||
error("The respawning has already started.");
|
||||
return false;
|
||||
}
|
||||
Field field = battle.getClass().getDeclaredField("o");
|
||||
field.setAccessible(true);
|
||||
Object BlockPosition = field.get(battle);
|
||||
if(BlockPosition == null){
|
||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
||||
this.DragonBattle_e.invoke(battle);
|
||||
BlockPosition = field.get(battle);
|
||||
if(BlockPosition == null){
|
||||
error("The world_the_end is unloaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(this.getX == null) this.getX = BlockPosition.getClass().getMethod("getX");
|
||||
if(this.getY == null) this.getY = BlockPosition.getClass().getMethod("getY");
|
||||
if(this.getZ == null) this.getZ = BlockPosition.getClass().getMethod("getZ");
|
||||
Location loc = new Location(world,(int)getX.invoke(BlockPosition),(int)this.getY.invoke(BlockPosition),(int)this.getZ.invoke(BlockPosition));
|
||||
placeEndCrystals(world, loc);
|
||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
||||
this.DragonBattle_e.invoke(battle);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
warn("Your server version (" + Version.getVersion() + ") is not supported!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void placeEndCrystals(World world, Location cen){
|
||||
cen.add(0.5,1,0.5);
|
||||
for(int i = 0; i < 4; i++){
|
||||
EnderCrystal crystal = (EnderCrystal) world.spawnEntity(cen.clone().add(nxt[i][0],0,nxt[i][1]), EntityType.ENDER_CRYSTAL);
|
||||
if(Config.auto_respawn_invulnerable) crystal.setInvulnerable(true);
|
||||
crystal.setShowingBottom(false);
|
||||
}
|
||||
}
|
||||
private Object getEnderDragonBattle(World world){
|
||||
String version = Version.getVersion();
|
||||
if (mcMainVersion >= 12) {
|
||||
try {
|
||||
Object worldServer = getWorldServer(world);
|
||||
assert worldServer != null;
|
||||
Field field = worldServer.getClass().getField("worldProvider");
|
||||
Object worldProvider = field.get(worldServer);
|
||||
if(this.WorldProviderTheEndClass == null){
|
||||
WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
||||
}
|
||||
Object WorldProviderTheEnd = WorldProviderTheEndClass.cast(worldProvider);
|
||||
String method_name;
|
||||
switch (version) {
|
||||
case "v1_12_R1" : {
|
||||
method_name = "t";
|
||||
break;
|
||||
}
|
||||
case "v1_13_R1" :
|
||||
case "v1_13_R2" : {
|
||||
method_name = "r";
|
||||
break;
|
||||
}
|
||||
case "v1_14_R1" : {
|
||||
method_name = "q";
|
||||
break;
|
||||
}
|
||||
case "v1_15_R1" : {
|
||||
method_name = "o";
|
||||
break;
|
||||
}
|
||||
default : method_name = null;
|
||||
}
|
||||
if(method_name == null) return null;
|
||||
Method method = WorldProviderTheEnd.getClass().getDeclaredMethod(method_name);
|
||||
return method.invoke(WorldProviderTheEnd);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
warn("Your server version (" + Version.getVersion() + ") is not supported!");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
warn("Your server version (" + Version.getVersion() + ") is not supported!");
|
||||
return null;
|
||||
}
|
||||
private Object getWorldServer(World ThisWorld) {
|
||||
try {
|
||||
Object castClass = getCraftWorld(ThisWorld);
|
||||
return this.CraftWorldClass.getDeclaredMethod("getHandle").invoke(castClass);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private Object getCraftWorld(World ThisWorld) {
|
||||
try {
|
||||
if (this.CraftWorldClass == null) {
|
||||
this.CraftWorldClass = Class.forName("org.bukkit.craftbukkit." + Version.getVersion() + ".CraftWorld");
|
||||
}
|
||||
if (this.CraftWorldClass.isInstance(ThisWorld)) {
|
||||
return this.CraftWorldClass.cast(ThisWorld);
|
||||
}
|
||||
return null;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private Object getWorld_e(World world){
|
||||
try {
|
||||
Object world_c = getCraftWorld(world);
|
||||
if(this.getNMSWord == null){
|
||||
this.getNMSWord = this.CraftWorldClass.getDeclaredMethod("getHandle");
|
||||
}
|
||||
return this.getNMSWord.invoke(world_c);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package xanadu.enderdragon.manager;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.gui.GUIWrapper;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
import static xanadu.enderdragon.config.Lang.info;
|
||||
import static xanadu.enderdragon.config.Lang.sendFeedback;
|
||||
|
||||
public class GuiManager {
|
||||
private static HashMap<String, GUIWrapper> f = new HashMap<>();
|
||||
public static void loadGui(){
|
||||
new BukkitRunnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
File folder = new File(plugin.getDataFolder(),"gui");
|
||||
if(!folder.exists()) return;
|
||||
File[] files = folder.listFiles();
|
||||
if(files == null) return;
|
||||
for(File file : files){
|
||||
if(!file.getName().endsWith(".yml")) continue;
|
||||
info(Lang.plugin_read_file + file.getName());
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
Iterator it = fileConfiguration.getKeys(false).iterator();
|
||||
while (it.hasNext()){
|
||||
String name = (String) it.next();
|
||||
ConfigurationSection section = fileConfiguration.getConfigurationSection(name);
|
||||
GUIWrapper guiWrapper = new GUIWrapper(section);
|
||||
f.put(name, guiWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
public static void disable(){
|
||||
f.clear();
|
||||
}
|
||||
public static void openGui(Player player, String name) {
|
||||
if (!f.containsKey(name)) {
|
||||
sendFeedback(player,Lang.gui_not_found);
|
||||
return;
|
||||
}
|
||||
player.openInventory(new GUIWrapper(f.get(name),name).current());
|
||||
}
|
||||
public static void openGui(Player player,String name,String key){
|
||||
if (!f.containsKey(name)) {
|
||||
sendFeedback(player,Lang.gui_not_found);
|
||||
return;
|
||||
}
|
||||
player.openInventory(new GUIWrapper(f.get(name),key).current());
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package xanadu.enderdragon.manager;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xanadu.enderdragon.gui.Reward;
|
||||
import xanadu.enderdragon.utils.Chance;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemManager {
|
||||
public static ConfigurationSection write(Reward reward){
|
||||
Chance chance = reward.getChance();
|
||||
return write(reward.getItem(),chance.getValue(),chance.getStr(),reward.getName());
|
||||
}
|
||||
public static ConfigurationSection write(ItemStack item,double value,String str,String name){
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
if(name == null){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta != null) name = meta.getDisplayName();
|
||||
else name = item.getType().name() + System.currentTimeMillis();
|
||||
}
|
||||
yaml.set(name + ".data", item);
|
||||
yaml.set(name + ".drop_chance.value",value);
|
||||
yaml.set(name + ".drop_chance.format",str);
|
||||
return yaml;
|
||||
}
|
||||
public static Reward readAsReward(ConfigurationSection section){
|
||||
Set<String> strings = section.getKeys(false);
|
||||
String name = strings.iterator().next();
|
||||
ConfigurationSection section0 = section.getConfigurationSection(name);
|
||||
if(section0 == null) return null;
|
||||
ItemStack item;
|
||||
String nbt = section0.getString("data");
|
||||
if (nbt == null) item = new ItemStack(Material.AIR);
|
||||
else item = section0.getItemStack("data");
|
||||
double d0 = section0.getDouble("drop_chance.value");
|
||||
String str = section0.getString("drop_chance.format");
|
||||
return new Reward(item,new Chance(d0, str));
|
||||
}
|
||||
public static ItemStack readAsItem(ConfigurationSection section, String path){
|
||||
// if(!isValid(section)) {
|
||||
// Bukkit.getServer().shutdown();
|
||||
// return new ItemStack(Material.AIR);
|
||||
// }
|
||||
String nbt = section.getString(path);
|
||||
if (nbt == null) return new ItemStack(Material.AIR);
|
||||
// if (!isValid(nbt)) return new ItemStack(Material.AIR);
|
||||
return section.getItemStack(path);
|
||||
}
|
||||
public static void addLore(ItemStack item, String lore){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta != null) {
|
||||
List<String> lores = meta.getLore();
|
||||
if (lores != null) {
|
||||
lores.add(0,lore);
|
||||
meta.setLore(lores);
|
||||
}
|
||||
else {
|
||||
meta.setLore(Collections.singletonList(lore));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
public static boolean isEmpty(ItemStack item){
|
||||
if(item == null) return true;
|
||||
if(item.getType() == Material.AIR) return true;
|
||||
return false;
|
||||
}
|
||||
// public static ItemStack StringToItemStack(String str) {
|
||||
// YamlConfiguration yml = new YamlConfiguration();
|
||||
// ItemStack item;
|
||||
// try {
|
||||
// yml.loadFromString(str);
|
||||
// item = yml.getItemStack("item");
|
||||
// } catch (InvalidConfigurationException ex) {
|
||||
// item = new ItemStack(Material.AIR, 1);
|
||||
// }
|
||||
// return item;
|
||||
// }
|
||||
// public Reward loadFromFile(ConfigurationSection section){
|
||||
// ItemStack item;
|
||||
// if(section.getString("item.data") == null || section.getString("item.drop_chance") == null){
|
||||
// return new Reward(new ItemStack(Material.AIR),);
|
||||
// }
|
||||
// try {
|
||||
// yamlManager.loadFromString(section.getString("item."));
|
||||
// }
|
||||
// }
|
||||
public static ItemStack read(ConfigurationSection section, String str, String str2, Material material){
|
||||
if(material == null) return new ItemStack(Material.AIR);
|
||||
return new ItemStack(material,1);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package xanadu.enderdragon.manager;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.gui.Reward;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.utils.Chance;
|
||||
import xanadu.enderdragon.utils.MyDragon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.data;
|
||||
import static xanadu.enderdragon.EnderDragon.dataF;
|
||||
import static xanadu.enderdragon.manager.DragonManager.dragons;
|
||||
import static xanadu.enderdragon.manager.DragonManager.mp;
|
||||
import static xanadu.enderdragon.manager.ItemManager.readAsReward;
|
||||
|
||||
public class RewardManager {
|
||||
public static void reload(){
|
||||
for(MyDragon dragon : dragons){
|
||||
dragon.datum.clear();
|
||||
String path = dragon.unique_name;
|
||||
List<String> list = data.getStringList(path);
|
||||
for(String str : list){
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
try{
|
||||
yml.loadFromString(str);
|
||||
Reward reward = readAsReward(yml);
|
||||
dragon.datum.add(reward);
|
||||
}catch (InvalidConfigurationException e){
|
||||
Lang.error(Lang.plugin_item_read_error + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void addItem(String key,Reward reward){
|
||||
addItem(key,reward.getItem(),reward.getChance());
|
||||
}
|
||||
public static void addItem(String key, ItemStack item, Chance chance){
|
||||
MyDragon dragon = mp.get(key);
|
||||
if(dragon == null) return;
|
||||
String path = dragon.unique_name;
|
||||
List<String> list = data.getStringList(path);
|
||||
Reward reward = new Reward(item,chance);
|
||||
list.add(reward.toString());
|
||||
data.set(path,list);
|
||||
try {
|
||||
data.save(dataF);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
data = YamlConfiguration.loadConfiguration(dataF);
|
||||
dragon.datum.add(reward);
|
||||
}
|
||||
public static void clearItem(String key){
|
||||
MyDragon dragon = mp.get(key);
|
||||
if(dragon == null) return;
|
||||
String path = dragon.unique_name;
|
||||
data.set(path,"");
|
||||
try {
|
||||
data.save(dataF);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
data = YamlConfiguration.loadConfiguration(dataF);
|
||||
dragon.datum.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package xanadu.enderdragon.manager;
|
||||
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
import xanadu.enderdragon.task.types.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.config.Lang.error;
|
||||
import static xanadu.enderdragon.config.Lang.plugin_file_save_error;
|
||||
|
||||
public class TaskManager {
|
||||
public static String path = "auto_respawn.next_respawn_time";
|
||||
public static Task task = null;
|
||||
public static Task parse(String string){
|
||||
String[] str = string.split(":",2);
|
||||
TaskType taskType = TaskType.getByName(str[0]);
|
||||
switch (taskType){
|
||||
case minute : {
|
||||
return new Minute(TaskType.minute,str[1]);
|
||||
}
|
||||
case hour : {
|
||||
return new Hour(TaskType.hour,str[1]);
|
||||
}
|
||||
case day : {
|
||||
return new Day(TaskType.day,str[1]);
|
||||
}
|
||||
case week : {
|
||||
return new Week(TaskType.week,str[1]);
|
||||
}
|
||||
case month : {
|
||||
return new Month(TaskType.month,str[1]);
|
||||
}
|
||||
case year : {
|
||||
return new Year(TaskType.year,str[1]);
|
||||
}
|
||||
default : {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void reload(){
|
||||
task = parse(Config.auto_respawn_respawn_time);
|
||||
}
|
||||
public static LocalTime getRoundTime(String str){
|
||||
try {
|
||||
return LocalTime.parse(str, DateTimeFormatter.ofPattern("HH:mm"));
|
||||
}catch (DateTimeParseException e){
|
||||
Lang.error("\"respawn_time\" in config.yml error!The format of time should be HH:mm.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String getRoundTimeStr(LocalDateTime time){
|
||||
return time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||
}
|
||||
public static LocalDateTime getLocalDateTime(String str){
|
||||
if(isValidTime(str)) return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||
return null;
|
||||
}
|
||||
public static boolean isValidTime(String str){
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
try{
|
||||
df.parse(str);
|
||||
} catch (ParseException e) {
|
||||
Lang.error("\"next_respawn_time\" in data.yml error!The format of time should be HH:mm.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static void saveFile(LocalDateTime nextTime){
|
||||
data.set(TaskManager.path,getRoundTimeStr(nextTime));
|
||||
try{
|
||||
data.save(dataF);
|
||||
}catch (IOException ex){
|
||||
error(plugin_file_save_error.replaceAll("\\{file_name}",dataF.getName()));
|
||||
}
|
||||
}
|
||||
public static String getCurrentTimeWithSpecialFormat(){
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH∶mm∶ss");
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,849 +0,0 @@
|
||||
package xanadu.enderdragon.metrics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Metrics {
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
private final MetricsBase metricsBase;
|
||||
|
||||
/**
|
||||
* Creates a new Metrics instance.
|
||||
*
|
||||
* @param plugin Your plugin instance.
|
||||
* @param serviceId The id of the service. It can be found at <a
|
||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
public Metrics(JavaPlugin plugin, int serviceId) {
|
||||
this.plugin = plugin;
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
if (!config.isSet("serverUuid")) {
|
||||
config.addDefault("enabled", true);
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
config.addDefault("logFailedRequests", false);
|
||||
config.addDefault("logSentData", false);
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
// Inform the server owners about bStats
|
||||
config
|
||||
.options()
|
||||
.header(
|
||||
"bStats (https://bStats.org) collects some basic information for plugin authors, like how\n"
|
||||
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
||||
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
||||
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
||||
+ "anonymous.")
|
||||
.copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
// Load the data
|
||||
boolean enabled = config.getBoolean("enabled", true);
|
||||
String serverUUID = config.getString("serverUuid");
|
||||
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||
boolean logSentData = config.getBoolean("logSentData", false);
|
||||
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
metricsBase =
|
||||
new MetricsBase(
|
||||
"bukkit",
|
||||
serverUUID,
|
||||
serviceId,
|
||||
enabled,
|
||||
this::appendPlatformData,
|
||||
this::appendServiceData,
|
||||
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||
plugin::isEnabled,
|
||||
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||
logErrors,
|
||||
logSentData,
|
||||
logResponseStatusText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
metricsBase.addCustomChart(chart);
|
||||
}
|
||||
|
||||
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||
builder.appendField("playerAmount", getPlayerAmount());
|
||||
builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0);
|
||||
builder.appendField("bukkitVersion", Bukkit.getVersion());
|
||||
builder.appendField("bukkitName", Bukkit.getName());
|
||||
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||
builder.appendField("osName", System.getProperty("os.name"));
|
||||
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
private void appendServiceData(JsonObjectBuilder builder) {
|
||||
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
private int getPlayerAmount() {
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||
// This fixes java.lang.NoSuchMethodError:
|
||||
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
// Just use the new method if the reflection failed
|
||||
return Bukkit.getOnlinePlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetricsBase {
|
||||
|
||||
/** The version of the Metrics class. */
|
||||
public static final String METRICS_VERSION = "3.0.0";
|
||||
|
||||
private static final ScheduledExecutorService scheduler =
|
||||
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
|
||||
|
||||
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||
|
||||
private final String platform;
|
||||
|
||||
private final String serverUuid;
|
||||
|
||||
private final int serviceId;
|
||||
|
||||
private final Consumer<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||
|
||||
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||
|
||||
private final Consumer<Runnable> submitTaskConsumer;
|
||||
|
||||
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||
|
||||
private final BiConsumer<String, Throwable> errorLogger;
|
||||
|
||||
private final Consumer<String> infoLogger;
|
||||
|
||||
private final boolean logErrors;
|
||||
|
||||
private final boolean logSentData;
|
||||
|
||||
private final boolean logResponseStatusText;
|
||||
|
||||
private final Set<CustomChart> customCharts = new HashSet<>();
|
||||
|
||||
private final boolean enabled;
|
||||
|
||||
/**
|
||||
* Creates a new MetricsBase class instance.
|
||||
*
|
||||
* @param platform The platform of the service.
|
||||
* @param serviceId The id of the service.
|
||||
* @param serverUuid The server uuid.
|
||||
* @param enabled Whether or not data sending is enabled.
|
||||
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||
* appends all platform-specific data.
|
||||
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||
* appends all service-specific data.
|
||||
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
|
||||
* used to delegate the data collection to a another thread to prevent errors caused by
|
||||
* concurrency. Can be {@code null}.
|
||||
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
|
||||
* @param errorLogger A consumer that accepts log message and an error.
|
||||
* @param infoLogger A consumer that accepts info log messages.
|
||||
* @param logErrors Whether or not errors should be logged.
|
||||
* @param logSentData Whether or not the sent data should be logged.
|
||||
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||
*/
|
||||
public MetricsBase(
|
||||
String platform,
|
||||
String serverUuid,
|
||||
int serviceId,
|
||||
boolean enabled,
|
||||
Consumer<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||
Consumer<Runnable> submitTaskConsumer,
|
||||
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||
BiConsumer<String, Throwable> errorLogger,
|
||||
Consumer<String> infoLogger,
|
||||
boolean logErrors,
|
||||
boolean logSentData,
|
||||
boolean logResponseStatusText) {
|
||||
this.platform = platform;
|
||||
this.serverUuid = serverUuid;
|
||||
this.serviceId = serviceId;
|
||||
this.enabled = enabled;
|
||||
this.appendPlatformDataConsumer = appendPlatformDataConsumer;
|
||||
this.appendServiceDataConsumer = appendServiceDataConsumer;
|
||||
this.submitTaskConsumer = submitTaskConsumer;
|
||||
this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
|
||||
this.errorLogger = errorLogger;
|
||||
this.infoLogger = infoLogger;
|
||||
this.logErrors = logErrors;
|
||||
this.logSentData = logSentData;
|
||||
this.logResponseStatusText = logResponseStatusText;
|
||||
checkRelocation();
|
||||
if (enabled) {
|
||||
// WARNING: Removing the option to opt-out will get your plugin banned from bStats
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
this.customCharts.add(chart);
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
final Runnable submitTask =
|
||||
() -> {
|
||||
if (!enabled || !checkServiceEnabledSupplier.get()) {
|
||||
// Submitting data or service is disabled
|
||||
scheduler.shutdown();
|
||||
return;
|
||||
}
|
||||
if (submitTaskConsumer != null) {
|
||||
submitTaskConsumer.accept(this::submitData);
|
||||
} else {
|
||||
this.submitData();
|
||||
}
|
||||
};
|
||||
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution
|
||||
// of requests on the
|
||||
// bStats backend. To circumvent this problem, we introduce some randomness into the initial
|
||||
// and second delay.
|
||||
// WARNING: You must not modify and part of this Metrics class, including the submit delay or
|
||||
// frequency!
|
||||
// WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
|
||||
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
|
||||
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
|
||||
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
|
||||
scheduler.scheduleAtFixedRate(
|
||||
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void submitData() {
|
||||
final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
|
||||
appendPlatformDataConsumer.accept(baseJsonBuilder);
|
||||
final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
|
||||
appendServiceDataConsumer.accept(serviceJsonBuilder);
|
||||
JsonObjectBuilder.JsonObject[] chartData =
|
||||
customCharts.stream()
|
||||
.map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
|
||||
.filter(Objects::nonNull)
|
||||
.toArray(JsonObjectBuilder.JsonObject[]::new);
|
||||
serviceJsonBuilder.appendField("id", serviceId);
|
||||
serviceJsonBuilder.appendField("customCharts", chartData);
|
||||
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
|
||||
baseJsonBuilder.appendField("serverUUID", serverUuid);
|
||||
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
|
||||
JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
|
||||
scheduler.execute(
|
||||
() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logErrors) {
|
||||
errorLogger.accept("Could not submit bStats metrics data", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
|
||||
if (logSentData) {
|
||||
infoLogger.accept("Sent bStats metrics data: " + data.toString());
|
||||
}
|
||||
String url = String.format(REPORT_URL, platform);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
if (logResponseStatusText) {
|
||||
infoLogger.accept("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks that the class was properly relocated. */
|
||||
private void checkRelocation() {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null
|
||||
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little
|
||||
// "trick" ... :D
|
||||
final String defaultPackage =
|
||||
new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||
final String examplePackage =
|
||||
new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure no one just copy & pastes the example and uses the wrong package
|
||||
// names
|
||||
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
|
||||
|| MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given string.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped string.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class CustomChart {
|
||||
|
||||
private final String chartId;
|
||||
|
||||
protected CustomChart(String chartId) {
|
||||
if (chartId == null) {
|
||||
throw new IllegalArgumentException("chartId must not be null");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||
builder.appendField("chartId", chartId);
|
||||
try {
|
||||
JsonObjectBuilder.JsonObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
builder.appendField("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logErrors) {
|
||||
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||
}
|
||||
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("value", value).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("value", value).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An extremely simple JSON builder.
|
||||
*
|
||||
* <p>While this class is neither feature-rich nor the most performant one, it's sufficient enough
|
||||
* for its use-case.
|
||||
*/
|
||||
public static class JsonObjectBuilder {
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
|
||||
private boolean hasAtLeastOneField = false;
|
||||
|
||||
public JsonObjectBuilder() {
|
||||
builder.append("{");
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a null field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendNull(String key) {
|
||||
appendFieldUnescaped(key, "null");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param value The value of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("JSON value must not be null");
|
||||
}
|
||||
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an integer field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param value The value of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, int value) {
|
||||
appendFieldUnescaped(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an object to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param object The object.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, JsonObject object) {
|
||||
if (object == null) {
|
||||
throw new IllegalArgumentException("JSON object must not be null");
|
||||
}
|
||||
appendFieldUnescaped(key, object.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The string array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, String[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values)
|
||||
.map(value -> "\"" + escape(value) + "\"")
|
||||
.collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an integer array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The integer array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, int[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an object array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The integer array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, JsonObject[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a field to the object.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param escapedValue The escaped value of the field.
|
||||
*/
|
||||
private void appendFieldUnescaped(String key, String escapedValue) {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("JSON key must not be null");
|
||||
}
|
||||
if (hasAtLeastOneField) {
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
|
||||
hasAtLeastOneField = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the JSON string and invalidates this builder.
|
||||
*
|
||||
* @return The built JSON string.
|
||||
*/
|
||||
public JsonObject build() {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||
builder = null;
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||
*
|
||||
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||
*
|
||||
* @param value The value to escape.
|
||||
* @return The escaped value.
|
||||
*/
|
||||
private static String escape(String value) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '"') {
|
||||
builder.append("\\\"");
|
||||
} else if (c == '\\') {
|
||||
builder.append("\\\\");
|
||||
} else if (c <= '\u000F') {
|
||||
builder.append("\\u000").append(Integer.toHexString(c));
|
||||
} else if (c <= '\u001F') {
|
||||
builder.append("\\u00").append(Integer.toHexString(c));
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A super simple representation of a JSON object.
|
||||
*
|
||||
* <p>This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
|
||||
* allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
|
||||
* JsonObject)}.
|
||||
*/
|
||||
public static class JsonObject {
|
||||
|
||||
private final String value;
|
||||
|
||||
private JsonObject(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package xanadu.enderdragon.task;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.EnderDragon;
|
||||
import xanadu.enderdragon.config.Config;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.manager.TaskManager;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
|
||||
public class RespawnDragonRunnable extends BukkitRunnable {
|
||||
private static RespawnDragonRunnable runnable = null;
|
||||
@Override
|
||||
public void run(){
|
||||
if(TaskManager.task == null) {
|
||||
this.cancel();
|
||||
runnable = null;
|
||||
error("The config of auto-respawn errors!Task has been disabled...");
|
||||
return;
|
||||
}
|
||||
if(TaskManager.task.isTimeUp()){
|
||||
new BukkitRunnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
boolean f = EnderDragon.getInstance().getDragonManager().initiateRespawn(Bukkit.getWorld(Config.auto_respawn_world_the_end_name));
|
||||
if(f) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||
}
|
||||
}.runTask(plugin);
|
||||
TaskManager.task.updateTime();
|
||||
}
|
||||
}
|
||||
public static void reload(){
|
||||
if(runnable != null){
|
||||
runnable.cancel();
|
||||
runnable = null;
|
||||
}
|
||||
runnable = new RespawnDragonRunnable();
|
||||
runnable.runTaskTimerAsynchronously(plugin,0,200L);
|
||||
info("The task has started to run...");
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package xanadu.enderdragon.task;
|
||||
|
||||
import xanadu.enderdragon.manager.TaskManager;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.data;
|
||||
import static xanadu.enderdragon.manager.TaskManager.*;
|
||||
|
||||
public abstract class Task {
|
||||
protected int period;
|
||||
protected int day;
|
||||
private final TaskType type;
|
||||
public abstract LocalDateTime getNextTime(LocalDateTime cur);
|
||||
public abstract void updateTime();
|
||||
protected LocalDateTime nextTime;
|
||||
protected Task(TaskType type,String str){
|
||||
this.type = type;
|
||||
switch (type){
|
||||
case minute :
|
||||
case hour : {
|
||||
this.period = Integer.parseInt(str);
|
||||
break;
|
||||
}
|
||||
case day : {
|
||||
this.period = Integer.parseInt(str.split(",")[0]);
|
||||
break;
|
||||
}
|
||||
case week :
|
||||
case month :
|
||||
case year : {
|
||||
this.day = Integer.parseInt(str.split(",")[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(data.getString(path) == null){
|
||||
switch (type){
|
||||
case minute :
|
||||
case hour : {
|
||||
this.nextTime = this.getNextTime(LocalDateTime.now());
|
||||
break;
|
||||
}
|
||||
case day :
|
||||
case week :
|
||||
case month :
|
||||
case year : {
|
||||
calcNextTime(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveFile(nextTime);
|
||||
}
|
||||
else this.nextTime = TaskManager.getLocalDateTime(data.getString(path));
|
||||
}
|
||||
private void calcNextTime(String str){
|
||||
LocalTime time = getRoundTime(str.split(",")[1]);
|
||||
if(time != null) this.nextTime = this.getNextTime(LocalDateTime.now().with(time));
|
||||
else this.nextTime = this.getNextTime(LocalDateTime.now());
|
||||
}
|
||||
public boolean isTimeUp(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if(now.isEqual(nextTime) || now.isAfter(nextTime)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public TaskType getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package xanadu.enderdragon.task;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public enum TaskType {
|
||||
minute,
|
||||
hour,
|
||||
day,
|
||||
week,
|
||||
month,
|
||||
year,
|
||||
unknown;
|
||||
private static final Map<String,TaskType> mp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
public static TaskType getByName(String str){
|
||||
if(str == null) return unknown;
|
||||
return mp.getOrDefault(str,unknown);
|
||||
}
|
||||
static{
|
||||
TaskType[] values = values();
|
||||
for (TaskType taskType : values) {
|
||||
String name = taskType.name();
|
||||
mp.put(name, taskType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Day extends Task {
|
||||
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.plusDays(period);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusDays(period);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
public Day(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Hour extends Task {
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.plusHours(period);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusHours(period);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
public Hour(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Minute extends Task {
|
||||
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.plusMinutes(period);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusMinutes(period);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
|
||||
public Minute(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Month extends Task {
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.plusMonths(1).withDayOfMonth(day);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusMonths(1).withDayOfMonth(day);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
public Month(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Week extends Task {
|
||||
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.with(DayOfWeek.of(day)).plusDays(7);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusDays(7);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
public Week(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package xanadu.enderdragon.task.types;
|
||||
|
||||
import xanadu.enderdragon.task.Task;
|
||||
import xanadu.enderdragon.task.TaskType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static xanadu.enderdragon.manager.TaskManager.saveFile;
|
||||
|
||||
public class Year extends Task {
|
||||
@Override
|
||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
||||
return cur.plusYears(1).withDayOfMonth(day);
|
||||
}
|
||||
@Override
|
||||
public void updateTime(){
|
||||
this.nextTime = LocalDateTime.now().plusYears(1);
|
||||
saveFile(nextTime);
|
||||
}
|
||||
public Year(TaskType type, String str){
|
||||
super(type,str);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
|
||||
public class Chance {
|
||||
private double value;
|
||||
private String str;
|
||||
public Chance(Chance chance){
|
||||
str = chance.str;
|
||||
value = chance.value;
|
||||
}
|
||||
public Chance(double d0,String str){
|
||||
this.str = str;
|
||||
this.value = d0;
|
||||
}
|
||||
public double getValue(){
|
||||
return value;
|
||||
}
|
||||
public String getStr(){
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.plugin.EventExecutor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
import static xanadu.enderdragon.EnderDragon.pm;
|
||||
|
||||
public class Events<T extends Event> implements Listener, EventExecutor {
|
||||
private final Consumer<T> consumer;
|
||||
private final Class<T> clazz;
|
||||
private boolean G;
|
||||
private final AtomicLong atomicLong;
|
||||
|
||||
public Events<T> withTime(final long a) {
|
||||
this.atomicLong.set(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
if (this.G) return;
|
||||
try {
|
||||
HandlerList list = (HandlerList)this.clazz.getMethod("getHandlerList").invoke(null, new Object[0]);
|
||||
if (Bukkit.isPrimaryThread()) list.unregister(this);
|
||||
else Bukkit.getScheduler().runTask(plugin, () -> list.unregister(this));
|
||||
}
|
||||
catch (final Exception ignored) {}
|
||||
this.G = true;
|
||||
}
|
||||
|
||||
public static <T extends Event> Events<T> subscribe(Class<T> a, EventPriority a2, boolean a3, Consumer<T> a4) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
pm.registerEvent(a, (Listener) a4, a2, (EventExecutor) a4, plugin, a3);
|
||||
return (Events<T>) a4;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin,()->pm.registerEvent(a, (Listener)a4, a2, (EventExecutor)a4, plugin, a3));
|
||||
return (Events<T>) a4;
|
||||
}
|
||||
|
||||
public static <T extends Event> Events<T> subscribe(Class<T> clazz, Consumer<T> consumer) {
|
||||
return Events.subscribe(clazz, EventPriority.HIGHEST, true, consumer);
|
||||
}
|
||||
|
||||
public Events(Class<T> clazz, Consumer<T> consumer) {
|
||||
this.atomicLong = new AtomicLong(-1L);
|
||||
this.G = false;
|
||||
this.consumer = consumer;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public void execute(Listener listener, Event event) {
|
||||
if (listener == null) iIIiii(0);
|
||||
if (event == null) iIIiii(1);
|
||||
if (this.atomicLong.get() > 0L && System.currentTimeMillis() > this.atomicLong.get()) {
|
||||
Bukkit.getScheduler().runTask(plugin, this::unregister);
|
||||
return;
|
||||
}
|
||||
if (!this.clazz.isInstance(event)) return;
|
||||
this.consumer.accept((T) event);
|
||||
}
|
||||
|
||||
public boolean releaseIfExpired() {
|
||||
if (this.atomicLong.get() > 0L && System.currentTimeMillis() > this.atomicLong.get()) {
|
||||
boolean b = true;
|
||||
this.unregister();
|
||||
return b;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static /* synthetic */ void iIIiii(final int a) {
|
||||
final String format = "Argument for @NotNull parameter '%s' of %s.%s must not be null";
|
||||
final Object[] args = new Object[3];
|
||||
if (a == 1) args[0] = "event";
|
||||
else args[0] = "listener";
|
||||
args[1] = "xanadu/enderdragon/utils/Events";
|
||||
args[2] = "execute";
|
||||
throw new IllegalArgumentException(String.format(format, args));
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xanadu.enderdragon.EnderDragon;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
import xanadu.enderdragon.gui.Reward;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.*;
|
||||
import static xanadu.enderdragon.config.Config.saveResource;
|
||||
import static xanadu.enderdragon.config.Lang.error;
|
||||
import static xanadu.enderdragon.config.Lang.info;
|
||||
import static xanadu.enderdragon.manager.ItemManager.readAsItem;
|
||||
|
||||
public class FileUpdater {
|
||||
public static void update() throws IOException {
|
||||
FileConfiguration config_old = plugin.getConfig();
|
||||
FileConfiguration data_old = EnderDragon.data;
|
||||
info("New setting files will be generated in plugins/EnderDragon/new.");
|
||||
if("1.8.3".equals(config_old.getString("version"))){
|
||||
File base_F = new File(plugin.getDataFolder(),"setting/default.yml");
|
||||
File default_F = new File(plugin.getDataFolder(),"new/setting/default.yml");
|
||||
FileConfiguration default_ = YamlConfiguration.loadConfiguration(base_F);
|
||||
default_.set("display_name",config_old.getString("normal-dragon.name","Ender Dragon"));
|
||||
default_.set("crystal_heal_speed",config_old.getDouble("normal-dragon.crystal-heal",2.0d));
|
||||
if(config_old.getBoolean("command.enable")){
|
||||
default_.set("death_cmd",config_old.getStringList("command.normal-dragon"));
|
||||
}
|
||||
default_.save(default_F);
|
||||
File base2_F = new File(plugin.getDataFolder(),"setting/special.yml");
|
||||
File special_F = new File(plugin.getDataFolder(),"new/setting/special.yml");
|
||||
FileConfiguration special = YamlConfiguration.loadConfiguration(base2_F);
|
||||
String pre = "special-dragon.";
|
||||
special.set("display_name",config_old.getString(pre+"name"));
|
||||
special.set("spawn_chance",config_old.getString(pre+"chance"));
|
||||
special.set("max_health",config_old.getDouble(pre+"max-health"));
|
||||
special.set("spawn_health",config_old.getDouble(pre+"spawn-health"));
|
||||
special.set("attack_potion_effect",config_old.getStringList(pre+"attack-effect"));
|
||||
special.set("exp_drop",config_old.getInt(pre+"exp-drop"));
|
||||
special.set("dragon_egg_spawn.chance",config_old.getDouble(pre+"dragon-egg-spawn.chance"));
|
||||
special.set("dragon_egg_spawn.delay",config_old.getInt(pre+"dragon-egg-spawn.delay"));
|
||||
special.set("dragon_egg_spawn.x",config_old.getInt(pre+"dragon-egg-spawn.x"));
|
||||
special.set("dragon_egg_spawn.y",config_old.getInt(pre+"dragon-egg-spawn.y"));
|
||||
special.set("dragon_egg_spawn.z",config_old.getInt(pre+"dragon-egg-spawn.z"));
|
||||
String color = config_old.getString(pre+"glow-color");
|
||||
if("disable".equalsIgnoreCase(color)) color = "none";
|
||||
special.set("glow_color",color);
|
||||
special.set("crystal_heal_speed",config_old.getDouble(pre+"crystal-heal"));
|
||||
special.set("suck_blood.enable",config_old.getBoolean(pre+"suck-blood.enable"));
|
||||
special.set("suck_blood.rate",config_old.getDouble(pre+"suck-blood.rate"));
|
||||
special.set("suck_blood.base_amount",config_old.getDouble(pre+"suck-blood.base-suck-blood"));
|
||||
special.set("suck_blood.only_player",config_old.getBoolean(pre+"suck-blood.only-player"));
|
||||
if(config_old.getBoolean("command.enable")){
|
||||
special.set("death_cmd",config_old.getStringList(pre+"special-dragon"));
|
||||
}
|
||||
special.save(special_F);
|
||||
}
|
||||
else Lang.error("Your config.yml version is not supported!");
|
||||
if("1.8.4".equals(data_old.getString("version"))){
|
||||
saveResource("data.yml","new/data.yml",true);
|
||||
File data_new_F = new File(plugin.getDataFolder(),"new/data.yml");
|
||||
FileConfiguration data_new = YamlConfiguration.loadConfiguration(data_new_F);
|
||||
data_new.set("version","2.0.0");
|
||||
data_new.set("times",data_old.getInt("times"));
|
||||
List<String> items_old = data_old.getStringList("items");
|
||||
try{
|
||||
File base2_F = new File(plugin.getDataFolder(),"setting/special.yml");
|
||||
FileConfiguration special = YamlConfiguration.loadConfiguration(base2_F);
|
||||
String special_key = special.getString("unique_name");
|
||||
List<String> list = new ArrayList<>();
|
||||
for(int i=0;i+1<items_old.size();i+=2){
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
yml.loadFromString(items_old.get(i));
|
||||
ItemStack item = readAsItem(yml,"item");
|
||||
String str = items_old.get(i+1);
|
||||
double d0 = Double.parseDouble(str);
|
||||
Reward reward = new Reward(item,new Chance(d0,str));
|
||||
list.add(reward.toString());
|
||||
}
|
||||
if(special_key == null){
|
||||
error("\"unique_name\" in setting/special.yml is missing.Update data.yml failed!");
|
||||
return;
|
||||
}
|
||||
data_new.set(special_key,list);
|
||||
data_new.save(data_new_F);
|
||||
}catch (InvalidConfigurationException | NumberFormatException | IOException e){
|
||||
error("The format of data.yml is invalid!");
|
||||
}
|
||||
}
|
||||
else Lang.error("Your data.yml version is not supported!");
|
||||
if("1.8.3".equals(config_old.getString("version"))){
|
||||
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.save(config_new_F);
|
||||
}
|
||||
String lang_name = config_old.getString("lang","English") + ".yml";
|
||||
FileConfiguration lang_old = lang;
|
||||
if("1.8.3".equals(lang_old.getString("version"))){
|
||||
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_new.set("plugin.prefix",lang_old.getString("prefix"));
|
||||
lang_new.set("command.no_permission",lang_old.getString("NoCommandPermission"));
|
||||
lang_new.set("command.reload_config",lang_old.getString("configReloaded"));
|
||||
lang_new.set("command.only_player",lang_old.getString("PlayerCommand"));
|
||||
lang_new.set("command.drop_item.clear",lang_old.getString("ClearDropItemConfig"));
|
||||
lang_new.set("dragon.player_inv_full",lang_old.getString("player-inv-full"));
|
||||
lang_new.set("dragon.no_killer",lang_old.getString("nobody-kill"));
|
||||
lang_new.save(lang_new_F);
|
||||
}
|
||||
else error("Your "+lang_name+" version is not supported!");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.server;
|
||||
|
||||
public class MathUtils {
|
||||
public static double div(double d1,double d2,int len){
|
||||
BigDecimal b1 = new BigDecimal(d1);
|
||||
BigDecimal b2 = new BigDecimal(d2);
|
||||
return b1.divide(b2,len, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
public static int[] hexToInt(String hex){
|
||||
int[] result = new int[3];
|
||||
String s1 = hex.substring(0,2);
|
||||
String s2 = hex.substring(2,4);
|
||||
String s3 = hex.substring(4,6);
|
||||
result[0] = Integer.parseInt(s1,16);
|
||||
result[1] = Integer.parseInt(s2,16);
|
||||
result[2] = Integer.parseInt(s3,16);
|
||||
return result;
|
||||
}
|
||||
public static String locationToString(Location loc){
|
||||
if (loc.getWorld() == null) return "";
|
||||
return loc.getWorld().getName()+";"+loc.getX()+";"+loc.getY()+";"+loc.getZ();
|
||||
}
|
||||
public static Location stringToLocation(String str){
|
||||
final String[] parts = str.split(";");
|
||||
if(parts.length != 4) return null;
|
||||
final World world = server.getWorld(parts[0]);
|
||||
final double x = Double.parseDouble(parts[1]);
|
||||
final double y = Double.parseDouble(parts[2]);
|
||||
final double z = Double.parseDouble(parts[3]);
|
||||
return new Location(world,x,y,z);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import xanadu.enderdragon.gui.Reward;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MyDragon implements Comparable<MyDragon>{
|
||||
public ItemStack icon;
|
||||
public String unique_name;
|
||||
public String display_name;
|
||||
public String drop_gui;
|
||||
public int edge;
|
||||
public int priority;
|
||||
public double spawn_chance;
|
||||
public int max_health;
|
||||
public int spawn_health;
|
||||
public int exp_drop;
|
||||
public int dragon_egg_spawn_delay;
|
||||
public int dragon_egg_spawn_x;
|
||||
public int dragon_egg_spawn_y;
|
||||
public int dragon_egg_spawn_z;
|
||||
public double dragon_egg_spawn_chance;
|
||||
public double attack_damage_modify;
|
||||
public double move_speed_modify;
|
||||
public double armor_modify;
|
||||
public double armor_toughness_modify;
|
||||
public double crystal_heal_speed;
|
||||
public boolean suck_blood_enable;
|
||||
public double suck_blood_rate;
|
||||
public double suck_blood_base_amount;
|
||||
public boolean suck_blood_only_player;
|
||||
public List<PotionEffect> attack_potion_effect;
|
||||
public List<String> spawn_cmd;
|
||||
public List<String> death_cmd;
|
||||
public List<String> spawn_broadcast_msg;
|
||||
public List<String> death_broadcast_msg;
|
||||
public List<String> msg_to_killer;
|
||||
public String glow_color;
|
||||
public String bossbar_color;
|
||||
public String bossbar_style;
|
||||
public double effect_cloud_original_radius;
|
||||
public double effect_cloud_expand_speed;
|
||||
public int effect_cloud_duration;
|
||||
public int effect_cloud_color_R;
|
||||
public int effect_cloud_color_G;
|
||||
public int effect_cloud_color_B;
|
||||
public List<PotionEffect> effect_cloud_potion;
|
||||
public List<Reward> datum = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int compareTo(MyDragon o) {
|
||||
return o.priority - this.priority;//降序
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import xanadu.enderdragon.EnderDragon;
|
||||
|
||||
public class Papi extends PlaceholderExpansion {
|
||||
private final EnderDragon plugin;
|
||||
|
||||
public Papi(EnderDragon plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Xanadu13";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "ed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
// if(!Config.BossBar_Enable) return null;
|
||||
// if(params.equalsIgnoreCase("bossbar_progress")) {
|
||||
// if(player.isOnline() && groups.get(player.getUniqueId())!=null){
|
||||
// double progress = groups.get(player.getUniqueId()).getProgress();
|
||||
// return String.valueOf(div(progress,1,3));
|
||||
// }
|
||||
// return String.valueOf(0);
|
||||
// }
|
||||
// else if(params.equalsIgnoreCase("remain_time")){
|
||||
// if(player.isOnline() && groups.get(player.getUniqueId())!=null){
|
||||
// return String.valueOf(groups.get(player.getUniqueId()).getRemainTime());
|
||||
// }
|
||||
// return String.valueOf(0);
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.mcMainVersion;
|
||||
import static xanadu.enderdragon.utils.MathUtils.hexToInt;
|
||||
|
||||
public class SpecialColor {
|
||||
|
||||
public static Pattern hex_code = Pattern.compile("&#([0-9A-Fa-f]{6})");
|
||||
public static Pattern gradient = Pattern.compile("&\\[#([0-9a-fA-F]{6})-#([0-9a-fA-F]{6})(.+)]");
|
||||
public static String translateHexCodes (String str) {
|
||||
if(mcMainVersion < 16) return str;
|
||||
Matcher matcher = hex_code.matcher(str);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while(matcher.find()) {
|
||||
matcher.appendReplacement(buffer, ChatColor.of("#" + matcher.group(1)).toString());
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
|
||||
}
|
||||
public static String transGradient(String str) {
|
||||
if(mcMainVersion < 16) return str;
|
||||
if (str.contains("&[#")&&str.contains("]")) {
|
||||
Matcher matcher = gradient.matcher(str);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String text = matcher.group(3);
|
||||
int[] colors = gradient(matcher.group(1),matcher.group(2),text.length());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
Color c = new Color(colors[i]);
|
||||
builder.append(ChatColor.of(c)).append(text.charAt(i));
|
||||
}
|
||||
matcher.appendReplacement(buffer, builder.toString());
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
return translateHexCodes(str);
|
||||
}
|
||||
private static int[] gradient(String start,String end,int length){
|
||||
int[] color = new int[length];
|
||||
int[] rgb1 = hexToInt(start);
|
||||
int[] rgb2 = hexToInt(end);
|
||||
if(length==0){return color;}
|
||||
if(length==1){
|
||||
for(int j=0;j<3;j++){
|
||||
color[0] = color[0]*256+rgb1[j];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
for(int i=0;i<length;i++){
|
||||
for(int j=0;j<3;j++){
|
||||
color[i] = color[i]*256+rgb1[j]+(rgb2[j]-rgb1[j])*i/(length-1);
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xanadu.enderdragon.config.Lang;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import static xanadu.enderdragon.EnderDragon.plugin;
|
||||
import static xanadu.enderdragon.config.Lang.*;
|
||||
|
||||
public class Updater {
|
||||
public static void checkUpdate(){
|
||||
new BukkitRunnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
try {
|
||||
URLConnection conn = new URL("https://api.github.com/repos/iXanadu13/EnderDragon/releases/latest").openConnection();
|
||||
conn.setConnectTimeout(20000);
|
||||
conn.setReadTimeout(60000);
|
||||
InputStream is = conn.getInputStream();
|
||||
String line = new BufferedReader(new InputStreamReader(is)).readLine();
|
||||
is.close();
|
||||
String newVer = line.substring(line.indexOf("\"tag_name\"") + 13, line.indexOf("\"target_commitish\"") - 2);
|
||||
String localVer = plugin.getDescription().getVersion();
|
||||
if (!localVer.equals(newVer)) {
|
||||
warn(Lang.plugin_out_of_date.replace("{0}",localVer).replace("{1}",newVer));
|
||||
}
|
||||
else{
|
||||
info(Lang.plugin_up_to_date.replace("{1}",newVer));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
warn(plugin_check_update_fail);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
info(Lang.plugin_checking_update);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package xanadu.enderdragon.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import static xanadu.enderdragon.config.Lang.info;
|
||||
import static xanadu.enderdragon.config.Lang.warn;
|
||||
|
||||
public class Version {
|
||||
private static String version = "no version found";
|
||||
public static void init(){
|
||||
try {
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
} catch (ArrayIndexOutOfBoundsException exception) {
|
||||
warn("ArrayIndexOutOfBoundsExceptions, please make sure the path is correct and exists!");
|
||||
}
|
||||
info("Found version: " + version);
|
||||
}
|
||||
public static String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user