preparation for compatibility with version 1.20.5
This commit is contained in:
@@ -21,11 +21,12 @@ import pers.xanadu.enderdragon.listener.*;
|
|||||||
import pers.xanadu.enderdragon.listener.mythiclib.PlayerAttackListener;
|
import pers.xanadu.enderdragon.listener.mythiclib.PlayerAttackListener;
|
||||||
import pers.xanadu.enderdragon.manager.*;
|
import pers.xanadu.enderdragon.manager.*;
|
||||||
import pers.xanadu.enderdragon.maven.DependencyManager;
|
import pers.xanadu.enderdragon.maven.DependencyManager;
|
||||||
|
import pers.xanadu.enderdragon.metadata.DragonInfo;
|
||||||
import pers.xanadu.enderdragon.metrics.Metrics;
|
import pers.xanadu.enderdragon.metrics.Metrics;
|
||||||
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
import pers.xanadu.enderdragon.nms.BossBar.IBossBarManager;
|
||||||
import pers.xanadu.enderdragon.nms.NMSItem.I_NMSItemManager;
|
import pers.xanadu.enderdragon.nms.NMSItem.INMSItemManager;
|
||||||
import pers.xanadu.enderdragon.nms.RespawnAnchor.I_RespawnAnchorManager;
|
import pers.xanadu.enderdragon.nms.RespawnAnchor.IRespawnAnchorManager;
|
||||||
import pers.xanadu.enderdragon.nms.WorldData.I_WorldDataManager;
|
import pers.xanadu.enderdragon.nms.WorldData.IWorldDataManager;
|
||||||
import pers.xanadu.enderdragon.util.NMSUtil;
|
import pers.xanadu.enderdragon.util.NMSUtil;
|
||||||
import pers.xanadu.enderdragon.util.Version;
|
import pers.xanadu.enderdragon.util.Version;
|
||||||
|
|
||||||
@@ -46,10 +47,10 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
public static FileConfiguration lang;
|
public static FileConfiguration lang;
|
||||||
private WorldManager worldManager;
|
private WorldManager worldManager;
|
||||||
private NMSUtil nmsManager;
|
private NMSUtil nmsManager;
|
||||||
private I_BossBarManager i_bossBarManager;
|
private IBossBarManager iBossBarManager;
|
||||||
private I_NMSItemManager i_nmsItemManager;
|
private INMSItemManager iNmsItemManager;
|
||||||
private I_WorldDataManager i_worldDataManager;
|
private IWorldDataManager iWorldDataManager;
|
||||||
private I_RespawnAnchorManager i_respawnAnchorManager;
|
private IRespawnAnchorManager iRespawnAnchorManager;
|
||||||
private static boolean finish = false;
|
private static boolean finish = false;
|
||||||
@Override
|
@Override
|
||||||
public void onLoad(){
|
public void onLoad(){
|
||||||
@@ -67,23 +68,24 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
worldManager = new WorldManager();
|
worldManager = new WorldManager();
|
||||||
nmsManager = new NMSUtil();
|
nmsManager = new NMSUtil();
|
||||||
nmsManager.init();
|
nmsManager.init();
|
||||||
i_bossBarManager = Version.getBossBarManager();
|
iBossBarManager = Version.getBossBarManager();
|
||||||
i_nmsItemManager = Version.getNMSItemManager();
|
iNmsItemManager = Version.getNMSItemManager();
|
||||||
i_worldDataManager = Version.getWorldDataManager();
|
iWorldDataManager = Version.getWorldDataManager();
|
||||||
i_respawnAnchorManager = Version.getRespawnAnchorManager();
|
iRespawnAnchorManager = Version.getRespawnAnchorManager();
|
||||||
if(Config.advanced_setting_world_env_fix) {
|
if(Config.advanced_setting_world_env_fix) {
|
||||||
getInstance().getWorldManager().fixWorldEnvironment();
|
getInstance().getWorldManager().fixWorldEnvironment();
|
||||||
Lang.info(Lang.world_env_fix_enable);
|
Lang.info(Lang.world_env_fix_enable);
|
||||||
}
|
}
|
||||||
if(Config.advanced_setting_save_bossbar){
|
|
||||||
fixWorldBossBar();
|
|
||||||
}
|
|
||||||
TimerManager.enable();
|
TimerManager.enable();
|
||||||
registerEvents();
|
registerEvents();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
HookManager.init();
|
HookManager.init();
|
||||||
reloadAll();
|
reloadAll();
|
||||||
|
if(Config.advanced_setting_save_bossbar){
|
||||||
|
fixWorldBossBar();
|
||||||
|
}
|
||||||
if(Config.advanced_setting_save_respawn_status) setRespawnStatus();
|
if(Config.advanced_setting_save_respawn_status) setRespawnStatus();
|
||||||
|
scanExistingDragons();
|
||||||
// if(Config.advanced_setting_glowing_fix) fixGlowing();
|
// if(Config.advanced_setting_glowing_fix) fixGlowing();
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
new Metrics(this,14850);
|
new Metrics(this,14850);
|
||||||
@@ -135,7 +137,7 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
TimerManager.save();
|
TimerManager.save();
|
||||||
if(Config.advanced_setting_save_respawn_status){
|
if(Config.advanced_setting_save_respawn_status){
|
||||||
Bukkit.getWorlds().forEach(world -> {
|
Bukkit.getWorlds().forEach(world -> {
|
||||||
if(!Config.blacklist_worlds.contains(world.getName())){
|
if(WorldManager.enable_worlds.contains(world.getName())){
|
||||||
char split = data.options().pathSeparator();
|
char split = data.options().pathSeparator();
|
||||||
if(DragonManager.isRespawnRunning(world)){
|
if(DragonManager.isRespawnRunning(world)){
|
||||||
data.set("respawn_fix"+split+world.getName(),true);
|
data.set("respawn_fix"+split+world.getName(),true);
|
||||||
@@ -154,7 +156,7 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
if(Config.advanced_setting_save_bossbar){
|
if(Config.advanced_setting_save_bossbar){
|
||||||
List<World> worlds = new ArrayList<>();
|
List<World> worlds = new ArrayList<>();
|
||||||
Bukkit.getWorlds().forEach(world -> {
|
Bukkit.getWorlds().forEach(world -> {
|
||||||
if(world.getEnvironment()==World.Environment.THE_END&&!Config.blacklist_worlds.contains(world.getName())){
|
if(world.getEnvironment()==World.Environment.THE_END&&WorldManager.enable_worlds.contains(world.getName())){
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -253,7 +255,7 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
public void run(){
|
public void run(){
|
||||||
List<World> worlds = new ArrayList<>();
|
List<World> worlds = new ArrayList<>();
|
||||||
Bukkit.getWorlds().forEach(world -> {
|
Bukkit.getWorlds().forEach(world -> {
|
||||||
if(world.getEnvironment()==World.Environment.THE_END&&!Config.blacklist_worlds.contains(world.getName())){
|
if(world.getEnvironment()==World.Environment.THE_END&&WorldManager.enable_worlds.contains(world.getName())){
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -297,6 +299,23 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}.runTaskLater(plugin,100L);
|
}.runTaskLater(plugin,100L);
|
||||||
}
|
}
|
||||||
|
private void scanExistingDragons(){
|
||||||
|
new BukkitRunnable(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
Bukkit.getWorlds().forEach(world -> {
|
||||||
|
if(WorldManager.enable_worlds.contains(world.getName())){
|
||||||
|
org.bukkit.entity.EnderDragon dragon = DragonManager.getEnderDragon(world);
|
||||||
|
if(dragon != null){
|
||||||
|
String unique_name = DragonManager.getSpecialKey(dragon);
|
||||||
|
DragonManager.existing_dragon.put(dragon.getUniqueId(),new DragonInfo(dragon,unique_name));
|
||||||
|
DragonManager.main_dragon.put(world.getName(),new DragonInfo(dragon,unique_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin,80L);
|
||||||
|
}
|
||||||
|
|
||||||
public WorldManager getWorldManager(){
|
public WorldManager getWorldManager(){
|
||||||
return worldManager;
|
return worldManager;
|
||||||
@@ -304,17 +323,17 @@ public final class EnderDragon extends JavaPlugin {
|
|||||||
public NMSUtil getNMSManager(){
|
public NMSUtil getNMSManager(){
|
||||||
return nmsManager;
|
return nmsManager;
|
||||||
}
|
}
|
||||||
public I_BossBarManager getBossBarManager(){
|
public IBossBarManager getBossBarManager(){
|
||||||
return i_bossBarManager;
|
return iBossBarManager;
|
||||||
}
|
}
|
||||||
public I_NMSItemManager getNMSItemManager(){
|
public INMSItemManager getNMSItemManager(){
|
||||||
return i_nmsItemManager;
|
return iNmsItemManager;
|
||||||
}
|
}
|
||||||
public I_WorldDataManager getWorldDataManager(){
|
public IWorldDataManager getWorldDataManager(){
|
||||||
return i_worldDataManager;
|
return iWorldDataManager;
|
||||||
}
|
}
|
||||||
public I_RespawnAnchorManager getRespawnAnchorManager(){
|
public IRespawnAnchorManager getRespawnAnchorManager(){
|
||||||
return i_respawnAnchorManager;
|
return iRespawnAnchorManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class TabCompleter implements org.bukkit.command.TabCompleter {
|
public class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||||
|
|
||||||
private static final List<String> arguments_ed = Arrays.asList("action", "drop", "reload", "respawn", "respawn_cd", "spawn", "update");
|
private static final List<String> arguments_ed = Arrays.asList("action", "drop", "migrate", "reload", "respawn", "respawn_cd", "spawn", "update");
|
||||||
private static final List<String> arguments_drop = Arrays.asList("add", "clear", "edit", "remove", "gui");
|
private static final List<String> arguments_drop = Arrays.asList("add", "clear", "edit", "remove", "gui");
|
||||||
private static final List<String> arguments_action = Arrays.asList("tell:","tell-colorless:","tell-raw:","groovy:");
|
private static final List<String> arguments_action = Arrays.asList("tell:","tell-colorless:","tell-raw:","groovy:");
|
||||||
private static final List<String> arguments_respawn_cd = Arrays.asList("get","remove","removeAll","set","start");
|
private static final List<String> arguments_respawn_cd = Arrays.asList("get","remove","removeAll","set","start");
|
||||||
|
|||||||
@@ -1,113 +1,198 @@
|
|||||||
package pers.xanadu.enderdragon.config;
|
package pers.xanadu.enderdragon.config;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
import pers.xanadu.enderdragon.manager.ItemManager;
|
||||||
|
import pers.xanadu.enderdragon.manager.TaskManager;
|
||||||
|
import pers.xanadu.enderdragon.reward.Chance;
|
||||||
|
import pers.xanadu.enderdragon.reward.Reward;
|
||||||
|
import pers.xanadu.enderdragon.util.Version;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.*;
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
public class FileUpdater {
|
public class FileUpdater {
|
||||||
public static void update() throws IOException {
|
public static void update() throws IOException {
|
||||||
FileConfiguration config_old = plugin.getConfig();
|
Lang.warn("Nothing to update. Maybe you need '/ed migrate'?");
|
||||||
boolean chinese = "Chinese".equals(config_old.getString("lang"));
|
// FileConfiguration config_old = plugin.getConfig();
|
||||||
File folder = new File(plugin.getDataFolder(),"setting");
|
// boolean chinese = "Chinese".equals(config_old.getString("lang"));
|
||||||
if(folder.exists()){
|
// File folder = new File(plugin.getDataFolder(),"setting");
|
||||||
File[] files = folder.listFiles();
|
// if(folder.exists()){
|
||||||
if(files != null){
|
// File[] files = folder.listFiles();
|
||||||
for(File file : files){
|
// if(files != null){
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
// for(File file : files){
|
||||||
String ver = config.getString("version");
|
// FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
if(!"2.2.0".equals(ver)) {
|
// String ver = config.getString("version");
|
||||||
Lang.error("The version of setting/"+file.getName()+" is not supported!");
|
// if(!"2.2.0".equals(ver)) {
|
||||||
continue;
|
// 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);
|
||||||
|
// if (chinese){
|
||||||
|
// out.write(("\n\n" +
|
||||||
|
// "# 一些特殊的战利品\n" +
|
||||||
|
// "special_loot:\n" +
|
||||||
|
// " # 你可以按格式添加更多条目,但是名称不能重复\n" +
|
||||||
|
// " # 如果找不到执行目标(target),所在战利品条目会被忽略\n" +
|
||||||
|
// " # 目前支持的type: exp(经验), command(执行指令,可解析伤害排名)\n" +
|
||||||
|
// " loot1:\n" +
|
||||||
|
// " # [true/false]\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: command\n" +
|
||||||
|
// " # %attacker% -> 所有参与屠龙的玩家\n" +
|
||||||
|
// " target: \"%attacker%\"\n" +
|
||||||
|
// " # %player% -> 目标, %damage% -> 该玩家造成的总伤害\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " - 'give %player% stone 1'\n" +
|
||||||
|
// " - 'ed action %player% tell: 你获得了保底奖励.'\n" +
|
||||||
|
// " loot2:\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: command\n" +
|
||||||
|
// " # %attacker_top_<rank>% -> 在屠龙中取得此排名的玩家\n" +
|
||||||
|
// " target: \"%attacker_top_1%\"\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " - 'ed action %player% tell: 你的伤害占比是最高的!'\n" +
|
||||||
|
// " - 'ed action %player% tell: 你造成的伤害: %damage%'\n" +
|
||||||
|
// " loot_exp1:\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: exp\n" +
|
||||||
|
// " target: \"%attacker_top_2%\"\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " # 给予排名第二的玩家20点经验\n" +
|
||||||
|
// " amount: 20\n" +
|
||||||
|
// "\n\n"
|
||||||
|
// ).getBytes());
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// out.write(("\n\n" +
|
||||||
|
// "special_loot:\n" +
|
||||||
|
// " # You can add more entries with DIFFERENT name according to the format.\n" +
|
||||||
|
// " # If such target not exists, this option will be ignored.\n" +
|
||||||
|
// " # type: exp, command\n" +
|
||||||
|
// " loot1:\n" +
|
||||||
|
// " # [true/false]\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: command\n" +
|
||||||
|
// " # %attacker% -> all participants in dragon slaying\n" +
|
||||||
|
// " target: \"%attacker%\"\n" +
|
||||||
|
// " # %player% -> target, %damage% -> this player's damage to EnderDragon\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " - 'give %player% stone 1'\n" +
|
||||||
|
// " - 'ed action %player% tell: This is a guaranteed reward.'\n" +
|
||||||
|
// " loot2:\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: command\n" +
|
||||||
|
// " # %attacker_top_<rank>% -> the player with exactly this rank\n" +
|
||||||
|
// " target: \"%attacker_top_1%\"\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " - 'ed action %player% tell: You are the one who causes the highest damage!'\n" +
|
||||||
|
// " - 'ed action %player% tell: Your damage: %damage%'\n" +
|
||||||
|
// " loot_exp1:\n" +
|
||||||
|
// " enable: false\n" +
|
||||||
|
// " type: exp\n" +
|
||||||
|
// " target: \"%attacker_top_2%\"\n" +
|
||||||
|
// " data:\n" +
|
||||||
|
// " # add 20 exp for the rank_2 player\n" +
|
||||||
|
// " amount: 20\n" +
|
||||||
|
// "\n\n"
|
||||||
|
// ).getBytes());
|
||||||
|
// }
|
||||||
|
// out.close();
|
||||||
|
// FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
|
||||||
|
// fc.set("version","2.4.0");
|
||||||
|
// fc.save(file);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Lang.info("New config files are generated in plugins/EnderDragon/new.");
|
||||||
|
// Lang.warn("Attention: Please confirm the accuracy before using new config!");
|
||||||
|
}
|
||||||
|
public static void migrate(){
|
||||||
|
File folder = new File(plugin.getDataFolder(),"reward");
|
||||||
|
if (folder.exists()){
|
||||||
|
File[] files = folder.listFiles(f -> f.getName().endsWith(".yml"));
|
||||||
|
if (files == null || files.length == 0) {
|
||||||
|
Lang.warn("No files need to be migrated!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (File file : files){
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
Config.copyFile(file,"new/reward/"+file.getName(),true);
|
||||||
|
File gen_file = new File(plugin.getDataFolder(),"new/reward/"+file.getName());
|
||||||
|
YamlConfiguration new_cfg = YamlConfiguration.loadConfiguration(gen_file);
|
||||||
|
if(Config.advanced_setting_backslash_split_reward) new_cfg.options().pathSeparator('\\');
|
||||||
|
List<String> gen = new ArrayList<>();
|
||||||
|
List<String> list = config.getStringList("list");
|
||||||
|
for(String str : list){
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
|
||||||
|
try{
|
||||||
|
yml.loadFromString(str);
|
||||||
|
Reward reward = ItemManager.readAsReward(yml);
|
||||||
|
if (reward == null) continue;
|
||||||
|
gen.add(saveReward(reward));
|
||||||
|
}catch (InvalidConfigurationException e){
|
||||||
|
Lang.error(Lang.plugin_item_read_error + str);
|
||||||
}
|
}
|
||||||
String name = file.getName();
|
|
||||||
Config.copyFile("setting/"+name,"new/setting/"+name,true);
|
|
||||||
}
|
}
|
||||||
File new_folder = new File(plugin.getDataFolder(),"new/setting/");
|
new_cfg.set("list",gen);
|
||||||
files = new_folder.listFiles();
|
try{
|
||||||
if(files != null){
|
new_cfg.save(gen_file);
|
||||||
for(File file : files){
|
}catch (IOException e){
|
||||||
FileOutputStream out = new FileOutputStream(file,true);
|
e.printStackTrace();
|
||||||
if (chinese){
|
|
||||||
out.write(("\n\n" +
|
|
||||||
"# 一些特殊的战利品\n" +
|
|
||||||
"special_loot:\n" +
|
|
||||||
" # 你可以按格式添加更多条目,但是名称不能重复\n" +
|
|
||||||
" # 如果找不到执行目标(target),所在战利品条目会被忽略\n" +
|
|
||||||
" # 目前支持的type: exp(经验), command(执行指令,可解析伤害排名)\n" +
|
|
||||||
" loot1:\n" +
|
|
||||||
" # [true/false]\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: command\n" +
|
|
||||||
" # %attacker% -> 所有参与屠龙的玩家\n" +
|
|
||||||
" target: \"%attacker%\"\n" +
|
|
||||||
" # %player% -> 目标, %damage% -> 该玩家造成的总伤害\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" - 'give %player% stone 1'\n" +
|
|
||||||
" - 'ed action %player% tell: 你获得了保底奖励.'\n" +
|
|
||||||
" loot2:\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: command\n" +
|
|
||||||
" # %attacker_top_<rank>% -> 在屠龙中取得此排名的玩家\n" +
|
|
||||||
" target: \"%attacker_top_1%\"\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" - 'ed action %player% tell: 你的伤害占比是最高的!'\n" +
|
|
||||||
" - 'ed action %player% tell: 你造成的伤害: %damage%'\n" +
|
|
||||||
" loot_exp1:\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: exp\n" +
|
|
||||||
" target: \"%attacker_top_2%\"\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" # 给予排名第二的玩家20点经验\n" +
|
|
||||||
" amount: 20\n" +
|
|
||||||
"\n\n"
|
|
||||||
).getBytes());
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
out.write(("\n\n" +
|
|
||||||
"special_loot:\n" +
|
|
||||||
" # You can add more entries with DIFFERENT name according to the format.\n" +
|
|
||||||
" # If such target not exists, this option will be ignored.\n" +
|
|
||||||
" # type: exp, command\n" +
|
|
||||||
" loot1:\n" +
|
|
||||||
" # [true/false]\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: command\n" +
|
|
||||||
" # %attacker% -> all participants in dragon slaying\n" +
|
|
||||||
" target: \"%attacker%\"\n" +
|
|
||||||
" # %player% -> target, %damage% -> this player's damage to EnderDragon\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" - 'give %player% stone 1'\n" +
|
|
||||||
" - 'ed action %player% tell: This is a guaranteed reward.'\n" +
|
|
||||||
" loot2:\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: command\n" +
|
|
||||||
" # %attacker_top_<rank>% -> the player with exactly this rank\n" +
|
|
||||||
" target: \"%attacker_top_1%\"\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" - 'ed action %player% tell: You are the one who causes the highest damage!'\n" +
|
|
||||||
" - 'ed action %player% tell: Your damage: %damage%'\n" +
|
|
||||||
" loot_exp1:\n" +
|
|
||||||
" enable: false\n" +
|
|
||||||
" type: exp\n" +
|
|
||||||
" target: \"%attacker_top_2%\"\n" +
|
|
||||||
" data:\n" +
|
|
||||||
" # add 20 exp for the rank_2 player\n" +
|
|
||||||
" amount: 20\n" +
|
|
||||||
"\n\n"
|
|
||||||
).getBytes());
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
|
|
||||||
fc.set("version","2.4.0");
|
|
||||||
fc.save(file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Lang.info("New reward config files are generated in plugins/EnderDragon/migrate.");
|
||||||
}
|
}
|
||||||
Lang.info("New config files are generated in plugins/EnderDragon/new.");
|
else Lang.warn("No files need to be migrated!");
|
||||||
Lang.warn("Attention: Please confirm the accuracy before using new config!");
|
}
|
||||||
|
public static String saveReward(Reward reward){
|
||||||
|
Chance chance = reward.getChance();
|
||||||
|
ItemStack item = reward.getItem();
|
||||||
|
double value = chance.getValue();
|
||||||
|
String str = chance.getStr();
|
||||||
|
String name = reward.getName();
|
||||||
|
YamlConfiguration yaml = new YamlConfiguration();
|
||||||
|
if(Config.advanced_setting_backslash_split_reward) yaml.options().pathSeparator('\\');
|
||||||
|
if(name == null){
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if(meta != null) {
|
||||||
|
String displayName = meta.getDisplayName();
|
||||||
|
if("".equals(displayName) || displayName == null){
|
||||||
|
name = item.getType().name().toLowerCase() + "(" + TaskManager.getCurrentTimeWithSpecialFormat() + ")";
|
||||||
|
}
|
||||||
|
else name = meta.getDisplayName();
|
||||||
|
}
|
||||||
|
else name = item.getType().name().toLowerCase() + "(" + TaskManager.getCurrentTimeWithSpecialFormat() + ")";
|
||||||
|
}
|
||||||
|
ConfigurationSection section = yaml.createSection(name);
|
||||||
|
section.set("data_type", "default");
|
||||||
|
section.set("data", item);
|
||||||
|
ConfigurationSection drop_section = section.createSection("drop_chance");
|
||||||
|
drop_section.set("value",value);
|
||||||
|
drop_section.set("format",str);
|
||||||
|
return yaml.saveToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package pers.xanadu.enderdragon.manager;
|
package pers.xanadu.enderdragon.manager;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.attribute.AttributeModifier;
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
@@ -13,6 +14,7 @@ import org.bukkit.inventory.meta.Repairable;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
import pers.xanadu.enderdragon.config.Config;
|
import pers.xanadu.enderdragon.config.Config;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
import pers.xanadu.enderdragon.reward.Reward;
|
import pers.xanadu.enderdragon.reward.Reward;
|
||||||
import pers.xanadu.enderdragon.reward.Chance;
|
import pers.xanadu.enderdragon.reward.Chance;
|
||||||
import pers.xanadu.enderdragon.util.Version;
|
import pers.xanadu.enderdragon.util.Version;
|
||||||
@@ -20,6 +22,8 @@ import pers.xanadu.enderdragon.util.Version;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ItemManager {
|
public class ItemManager {
|
||||||
|
@Getter
|
||||||
|
private static boolean legacy = false;
|
||||||
public static String write(Reward reward){
|
public static String write(Reward reward){
|
||||||
Chance chance = reward.getChance();
|
Chance chance = reward.getChance();
|
||||||
return write(reward.getItem(),chance.getValue(),chance.getStr(),reward.getName());
|
return write(reward.getItem(),chance.getValue(),chance.getStr(),reward.getName());
|
||||||
@@ -40,12 +44,12 @@ public class ItemManager {
|
|||||||
}
|
}
|
||||||
ConfigurationSection section = yaml.createSection(name);
|
ConfigurationSection section = yaml.createSection(name);
|
||||||
switch(Config.item_format_reward){
|
switch(Config.item_format_reward){
|
||||||
case "nbt" : {
|
case "_nbt" : {
|
||||||
section.set("data_type","nbt");
|
section.set("data_type","nbt");
|
||||||
section.set("data",EnderDragon.getInstance().getNMSManager().getNBT(item));
|
section.set("data",EnderDragon.getInstance().getNMSManager().getNBT(item));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "advanced" : {
|
case "_advanced" : {
|
||||||
section.set("data_type","advanced");
|
section.set("data_type","advanced");
|
||||||
ConfigurationSection section_data = section.createSection("data");
|
ConfigurationSection section_data = section.createSection("data");
|
||||||
//type
|
//type
|
||||||
@@ -145,14 +149,13 @@ public class ItemManager {
|
|||||||
internal.set("data_type","nbt");
|
internal.set("data_type","nbt");
|
||||||
internal.set("data",new_cpd.toString());
|
internal.set("data",new_cpd.toString());
|
||||||
}
|
}
|
||||||
// Map<String,Object> mp = EnderDragon.getInstance().getNMSManager().getUnhandledTags(meta);
|
|
||||||
// if(mp != null){
|
|
||||||
// ConfigurationSection internal = section_data.createSection("internal");
|
|
||||||
// saveUnhandledTags(internal,mp);
|
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "nbt":
|
||||||
|
case "advanced": {
|
||||||
|
Lang.warn("Data_type 'nbt' and 'advanced' has been disabled temporarily for compatibility with 1.20.5+");
|
||||||
|
//no break, go ahead to default block.
|
||||||
|
}
|
||||||
default : {
|
default : {
|
||||||
section.set("data_type","default");
|
section.set("data_type","default");
|
||||||
section.set("data", item);
|
section.set("data", item);
|
||||||
@@ -171,9 +174,17 @@ public class ItemManager {
|
|||||||
String data_type = section0.getString("data_type");
|
String data_type = section0.getString("data_type");
|
||||||
//data_type may be null
|
//data_type may be null
|
||||||
ItemStack item;
|
ItemStack item;
|
||||||
if("nbt".equals(data_type)) item = readFromNBT(section0,"data");
|
if("nbt".equals(data_type)) {
|
||||||
else if("advanced".equals(data_type)) item = readFromAdvData(section0, "data");
|
legacy = true;
|
||||||
else item = readFromBukkit(section0,"data");
|
item = readFromNBT(section0,"data");
|
||||||
|
}
|
||||||
|
else if("advanced".equals(data_type)) {
|
||||||
|
legacy = true;
|
||||||
|
item = readFromAdvData(section0, "data");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item = readFromBukkit(section0,"data");
|
||||||
|
}
|
||||||
ConfigurationSection chance_section = section0.getConfigurationSection("drop_chance");
|
ConfigurationSection chance_section = section0.getConfigurationSection("drop_chance");
|
||||||
if(chance_section == null) return null;
|
if(chance_section == null) return null;
|
||||||
double d0 = chance_section.getDouble("value");
|
double d0 = chance_section.getDouble("value");
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import pers.xanadu.enderdragon.config.Lang;
|
|||||||
import pers.xanadu.enderdragon.reward.Reward;
|
import pers.xanadu.enderdragon.reward.Reward;
|
||||||
import pers.xanadu.enderdragon.reward.Chance;
|
import pers.xanadu.enderdragon.reward.Chance;
|
||||||
import pers.xanadu.enderdragon.metadata.MyDragon;
|
import pers.xanadu.enderdragon.metadata.MyDragon;
|
||||||
|
import pers.xanadu.enderdragon.util.Version;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -30,7 +31,6 @@ public class RewardManager {
|
|||||||
FileConfiguration data = loadConfiguration(file);
|
FileConfiguration data = loadConfiguration(file);
|
||||||
String path = "list";
|
String path = "list";
|
||||||
List<String> list = data.getStringList(path);
|
List<String> list = data.getStringList(path);
|
||||||
// if list == null ?
|
|
||||||
for(String str : list){
|
for(String str : list){
|
||||||
YamlConfiguration yml = new YamlConfiguration();
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
|
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
|
||||||
@@ -43,6 +43,11 @@ public class RewardManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ItemManager.isLegacy()){
|
||||||
|
Lang.error("I'm sorry that data_type 'nbt' and 'advanced' probably will be disabled in 1.20.5+");
|
||||||
|
Lang.error("It is recommended to migrate item configuration to bukkit format for compatibility.");
|
||||||
|
Lang.error("You can use /ed migrate to generate new config.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void addItem(String key,Reward reward){
|
public static void addItem(String key,Reward reward){
|
||||||
addItem(key,reward.getItem(),reward.getChance());
|
addItem(key,reward.getItem(),reward.getChance());
|
||||||
@@ -118,7 +123,7 @@ public class RewardManager {
|
|||||||
try{
|
try{
|
||||||
YamlConfiguration yml = new YamlConfiguration();
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
|
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
|
||||||
yml.set("version","2.1.0");
|
yml.set("version", Version.reward);
|
||||||
yml.set("list","");
|
yml.set("list","");
|
||||||
yml.save(file);
|
yml.save(file);
|
||||||
}catch (IOException e){
|
}catch (IOException e){
|
||||||
|
|||||||
Reference in New Issue
Block a user