Delete src/main/java/pers/xanadu/enderdragon/config directory

This commit is contained in:
Xanadu13
2023-08-25 21:49:13 +08:00
committed by GitHub
parent d41e0653a2
commit 15299d0a6c
3 changed files with 0 additions and 460 deletions
@@ -1,122 +0,0 @@
package pers.xanadu.enderdragon.config;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.util.*;
import static pers.xanadu.enderdragon.EnderDragon.plugin;
import static pers.xanadu.enderdragon.config.Lang.error;
public class Config {
public static String version;
public static String lang;
public static boolean debug;
public static boolean advanced_setting_world_env_fix;
public static boolean advanced_setting_save_respawn_status;
public static boolean advanced_setting_glowing_fix;
public static String damage_visible_mode;
public static int damage_statistics_limit;
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 respawn_cd_enable;
public static boolean resist_player_respawn;
public static boolean resist_dragon_breath_gather;
public static boolean hook_plugins_MythicLib;
public static String main_gui;
public static String item_format_data;
public static List<String> dragon_setting_file;
public static List<String> blacklist_worlds;
public static void reload(FileConfiguration file){
Field[] fields = Config.class.getFields();
for(Field field : fields){
Type type = field.getType();
if(type.equals(java.lang.String.class)){
try{
field.set(null,"");
}catch (Exception ignored){}
}
else if(type.equals(java.util.List.class)){
try{
field.set(null,new ArrayList());
}catch (Exception ignored){}
}
}
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);
}
}
switch (special_dragon_jude_mode.toLowerCase()){
case "pc" :
case "weight" : break;
default: {
error("Wrong special_dragon_jude_mode type in config.yml! Only \"weight\" or \"pc\" is valid.");
}
}
}
public static void saveResource(String source,String to,boolean replace){
if (source == null || source.equals("")) return;
source = source.replace('\\', '/');
InputStream in = plugin.getResource(source);
if (in == null) return;
File outFile = new File("plugins/EnderDragon", to);
int lastIndex = to.lastIndexOf('/');
File outDir = new File("plugins/EnderDragon", to.substring(0, Math.max(lastIndex, 0)));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (!outFile.exists() || replace) {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException ignored) {}
}
public static void copyFile(String source, String dest,boolean replace) {
if (source == null || source.equals("")) return;
source = source.replace('\\', '/');
File inFile = new File("plugins/EnderDragon", source);
File outFile = new File("plugins/EnderDragon", dest);
int lastIndex = dest.lastIndexOf('/');
File outDir = new File("plugins/EnderDragon", dest.substring(0, Math.max(lastIndex, 0)));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (!outFile.exists() || replace) {
InputStream in = new FileInputStream(inFile);
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException ignored) {
Lang.error("Failed to copy file: "+inFile.getPath()+" -> "+outFile.getPath());
}
}
}
@@ -1,123 +0,0 @@
package pers.xanadu.enderdragon.config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import pers.xanadu.enderdragon.manager.DragonManager;
import pers.xanadu.enderdragon.EnderDragon;
import pers.xanadu.enderdragon.util.MyDragon;
import java.io.*;
import java.util.List;
import static pers.xanadu.enderdragon.EnderDragon.*;
public class FileUpdater {
public static void update() throws IOException {
FileConfiguration config_old = plugin.getConfig();
if("2.0.4".equals(config_old.getString("version"))){
Config.saveResource("config.yml","new/config.yml",true);
File config_new_F = new File(plugin.getDataFolder(),"new/config.yml");
FileConfiguration config_new = YamlConfiguration.loadConfiguration(config_new_F);
config_new.set("lang",config_old.getString("lang"));
config_new.set("damage_visible_mode",config_old.getString("damage_visible_mode"));
String judge_mode = config_old.getString("special_dragon_jude_mode");
if("edge".equals(judge_mode)) judge_mode = "weight";//"edge" is deprecated
config_new.set("special_dragon_jude_mode",judge_mode);
config_new.set("dragon_setting_file",config_old.getStringList("dragon_setting_file"));
config_new.set("auto_respawn.enable",config_old.getBoolean("auto_respawn.enable"));
config_new.set("auto_respawn.world_the_end_name",config_old.getString("auto_respawn.world_the_end_name"));
config_new.set("auto_respawn.respawn_time",config_old.getString("auto_respawn.respawn_time"));
config_new.set("auto_respawn.invulnerable",config_old.getBoolean("auto_respawn.invulnerable"));
config_new.set("resist_player_respawn",config_old.getBoolean("resist_player_respawn"));
config_new.set("resist_dragon_breath_gather",config_old.getBoolean("resist_dragon_breath_gather"));
config_new.set("main_gui",config_old.getString("main_gui"));
config_new.save(config_new_F);
}
else Lang.error("The version of config.yml is not supported!");
File folder = new File(plugin.getDataFolder(),"setting");
if(folder.exists()){
File[] files = folder.listFiles();
if(files != null){
for(File file : files){
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
String ver = config.getString("version");
if(!"2.0.1".equals(ver)) {
Lang.error("The version of setting/"+file.getName()+" is not supported!");
continue;
}
String name = file.getName();
Config.copyFile("setting/"+name,"new/setting/"+name,true);
}
File new_folder = new File(plugin.getDataFolder(),"new/setting/");
files = new_folder.listFiles();
if(files != null){
for(File file : files){
FileOutputStream out = new FileOutputStream(file,true);
out.write(("\n\n" +
"reward_dist:\n" +
" # enable: [all,drop,killer,pack,rank,termwise]\n" +
" # all: Give to all participants in dragon slaying.\n" +
" # drop: Dropped item, players can grab it casually.\n" +
" # killer: Only give to the final killer.\n" +
" # pack: Pack all items that trigger drop and distribute them to players weighted based on their damage percentage.\n" +
" # rank: Strictly based on player damage ranking, give the top few players with the highest damage.\n" +
" # termwise: Assign the items that trigger the drop ONE BY ONE to the player based on the weighted proportion of damage.\n" +
" type: killer\n" +
" drop:\n" +
" # Whether the dropped item glows.\n" +
" # Refer to the previous 'glow_color' for configuration method\n" +
" glow: green\n" +
" pack:\n" +
" # the number of player(s) can be selected at most\n" +
" max_num: 1\n" +
" rank:\n" +
" # Top few can receive rewards\n" +
" max_num: 1\n" +
"\n"
).getBytes());
out.close();
FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
fc.set("version","2.1.0");
fc.set("move_speed_modify",null);
fc.save(file);
}
}
}
}
String lang_name = config_old.getString("lang","English") + ".yml";
FileConfiguration lang_old = lang;
if("2.0.0".equals(lang_old.getString("version"))){
Config.saveResource("lang/"+lang_name,"new/lang/"+lang_name,true);
File lang_new_F = new File(plugin.getDataFolder(),"new/lang/"+lang_name);
FileConfiguration lang_new = YamlConfiguration.loadConfiguration(lang_new_F);
lang_old.getKeys(true).forEach(key->{
Object obj = lang_old.get(key);
if(obj instanceof String){
lang_new.set(key,obj);
}
});
lang_new.set("version","2.1.0");
lang_new.save(lang_new_F);
}
else Lang.error("The version of "+lang_name+" is not supported!");
FileConfiguration data_old = EnderDragon.data;
if("2.0.0".equals(data_old.getString("version"))){
File new_folder = new File(plugin.getDataFolder(),"new/reward");
for (MyDragon myDragon : DragonManager.dragons) {
String key = myDragon.unique_name;
List<String> list = data.getStringList(key);
File new_data = new File(new_folder,key+".yml");
FileConfiguration fc = YamlConfiguration.loadConfiguration(new_data);
fc.set("version","2.1.0");
fc.set("list",list);
fc.save(new_data);
data_old.set(key,null);
}
data_old.set("version","2.1.0");
data_old.save(new File(plugin.getDataFolder(),"new/data.yml"));
}
else Lang.error("The version of data.yml is not supported!");
Lang.info("New config files are generated in plugins/EnderDragon/new.");
Lang.error("Attention: Please confirm the accuracy before using new config!");
}
}
@@ -1,215 +0,0 @@
package pers.xanadu.enderdragon.config;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import pers.xanadu.enderdragon.util.ColorUtil;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static pers.xanadu.enderdragon.EnderDragon.*;
import static pers.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 command_drop_item_remove_invalid_num;
public static String command_drop_item_remove_fail;
public static String command_drop_item_remove_succeed;
public static String command_respawn_cd_disable;
public static String command_respawn_cd_remove;
public static String command_respawn_cd_removeAll;
public static String command_respawn_cd_retry;
public static String command_respawn_cd_set;
public static String command_respawn_cd_start_already_started;
public static String command_respawn_cd_start_none;
public static String command_respawn_cd_start_succeed;
public static String gui_default_title;
public static String gui_not_found;
public static String gui_item_lore;
public static String gui_item_cmd_lore;
public static String dragon_damage_display;
public static String dragon_player_inv_full;
public static String dragon_no_killer;
public static String dragon_auto_respawn;
public static String dragon_not_found;
public static String dragon_damage_statistics_text;
public static List<String> dragon_damage_statistics_hover_prefix;
public static String dragon_damage_statistics_hover_mt;
public static List<String> dragon_damage_statistics_hover_suffix;
public static String dragon_damage_statistics_hover_exceeds_limit;
public static String world_env_fix_enable;
public static String 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){
Type type = field.getType();
if(type.equals(java.lang.String.class)){
try{
field.set(null,"");
}catch (Exception ignored){}
}
else if(type.equals(java.util.List.class)){
try{
field.set(null,new ArrayList());
}catch (Exception ignored){}
}
}
Iterator<String> it = file.getKeys(true).iterator();
while (it.hasNext()){
String str = it.next();
try{
if(file.isConfigurationSection(str)) continue;
if(file.isString(str)) Lang.class.getField(str.replace(".","_")).set(null, ColorUtil.transGradient(file.getString(str)));
else if(file.isList(str)){
List<String> list = file.getStringList(str);
list.forEach(s-> s = ColorUtil.transGradient(s));
Lang.class.getField(str.replace(".","_")).set(null, list);
}
}catch (Exception e){
error("Language loading error! Key: "+str);
}
}
CommandTips1 = ColorUtil.transGradient(lang.getString("CommandTips1","§e/ed reload §a- reload the config"));
CommandTips2 = ColorUtil.transGradient(lang.getString("CommandTips2","§e/ed respawn §a- respawn a dragon"));
CommandTips3 = ColorUtil.transGradient(lang.getString("CommandTips3","§e/ed drop gui §a- view the drop_item"));
CommandTips4 = ColorUtil.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 debug(String str){
if(Config.debug) Bukkit.getLogger().info(str);
}
public static void sendFeedback(CommandSender sender,String str){
if(str == null) {
sender.sendMessage(Lang.plugin_prefix + "null");
return;
}
if(str.contains("\\n")){
String[] strings = str.split("\\\\n");
for(String s : strings){
sender.sendMessage(Lang.plugin_prefix + s);
}
}
else sender.sendMessage(Lang.plugin_prefix + str);
}
public static void broadcastMSG(String str){
if(str == null) {
Bukkit.broadcastMessage(Lang.plugin_prefix + "null");
return;
}
if(str.contains("\\n")){
String[] strings = str.split("\\\\n");
for(String s : strings){
broadcastMSG(s);
}
}
else Bukkit.broadcastMessage(Lang.plugin_prefix + str);
}
public static void broadcastMSG(List<String> list){
if(list == null) return;
for(String str : list){
Bukkit.broadcastMessage(Lang.plugin_prefix + str);
}
}
public static void runCommands(List<String> list, Player p){
if(list == null) return;
for (String cmd : list) {
if(cmd.equals("")) continue;
if(!cmd.contains("%player%")) 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);
}
}
}