Skip to content

Commit

Permalink
Merge pull request #8 from iXanadu13/v2.3.0
Browse files Browse the repository at this point in the history
V2.3.0
  • Loading branch information
iXanadu13 authored Dec 7, 2023
2 parents fc2bc77 + d2b0fa0 commit 33ab7ae
Show file tree
Hide file tree
Showing 34 changed files with 715 additions and 283 deletions.
13 changes: 4 additions & 9 deletions src/main/java/pers/xanadu/enderdragon/EnderDragon.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public final class EnderDragon extends JavaPlugin {
public static FileConfiguration data;
public static FileConfiguration lang;
private WorldManager worldManager;
private DragonManager dragonManager;
private NMSUtil nmsManager;
private I_BossBarManager i_bossBarManager;
private I_NMSItemManager i_nmsItemManager;
Expand All @@ -65,7 +64,6 @@ public void onEnable() {
Lang.info("Enabling plugin...");
Lang.info("Author: Xanadu13");
Version.init();
dragonManager = new DragonManager();
worldManager = new WorldManager();
nmsManager = new NMSUtil();
nmsManager.init();
Expand All @@ -77,7 +75,7 @@ public void onEnable() {
getInstance().getWorldManager().fixWorldEnvironment();
Lang.info(Lang.world_env_fix_enable);
}
if(Version.mcMainVersion == 12 || Version.mcMainVersion == 13){
if(Config.advanced_setting_save_bossbar){
fixWorldBossBar();
}
TimerManager.enable();
Expand Down Expand Up @@ -139,7 +137,7 @@ public void onDisable(){
Bukkit.getWorlds().forEach(world -> {
if(!Config.blacklist_worlds.contains(world.getName())){
char split = data.options().pathSeparator();
if(EnderDragon.getInstance().getDragonManager().isRespawnRunning(world)){
if(DragonManager.isRespawnRunning(world)){
data.set("respawn_fix"+split+world.getName(),true);
}
else data.set("respawn_fix"+split+world.getName(),false);
Expand All @@ -153,7 +151,7 @@ public void onDisable(){
Lang.error(Lang.plugin_file_save_error.replaceAll("\\{file_name}",dataF.getName()));
}
}
if(Version.mcMainVersion == 12 || Version.mcMainVersion == 13){
if(Config.advanced_setting_save_bossbar){
List<World> worlds = new ArrayList<>();
Bukkit.getWorlds().forEach(world -> {
if(world.getEnvironment()==World.Environment.THE_END&&!Config.blacklist_worlds.contains(world.getName())){
Expand Down Expand Up @@ -290,7 +288,7 @@ public void run(){
if(section != null){
section.getKeys(false).forEach(key->{
if(section.getBoolean(key)){
EnderDragon.getInstance().getDragonManager().refresh_respawn(Bukkit.getWorld(key));
DragonManager.refresh_respawn(Bukkit.getWorld(key));
Lang.info("DragonRespawn continues!");
}
});
Expand All @@ -299,9 +297,6 @@ public void run(){
}.runTaskLater(plugin,100L);
}

public DragonManager getDragonManager(){
return dragonManager;
}
public WorldManager getWorldManager(){
return worldManager;
}
Expand Down
57 changes: 41 additions & 16 deletions src/main/java/pers/xanadu/enderdragon/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pers.xanadu.enderdragon.config.Config;
import pers.xanadu.enderdragon.config.Lang;
import pers.xanadu.enderdragon.manager.*;
import pers.xanadu.enderdragon.EnderDragon;
import pers.xanadu.enderdragon.maven.DependencyManager;
import pers.xanadu.enderdragon.reward.Chance;
import pers.xanadu.enderdragon.config.FileUpdater;
Expand All @@ -33,7 +32,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
switch(args[0].toLowerCase()){
// case "parse" : {
// if(!sender.isOp()) return false;
//
// if(args.length == 2) GroovyManager.invoke("test.groovy", args[1]);
// else if(args.length == 3) GroovyManager.invoke("test.groovy",args[1],Bukkit.getPlayer(args[2]));
//// List<Entity> entities = p.getNearbyEntities(50,50,50);
Expand All @@ -46,15 +44,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
//// }
////
////
////// if(entity instanceof org.bukkit.entity.EnderDragon){
////// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
////// }
////// if(entity instanceof ComplexEntityPart){
////// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
////// }
////// if(entity instanceof ComplexLivingEntity){
////// Bukkit.broadcastMessage(entity.getName());//8 EnderDragon
////// }
//// if(entity instanceof org.bukkit.entity.EnderDragon){
//// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
//// }
//// if(entity instanceof ComplexEntityPart){
//// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
//// }
//// if(entity instanceof ComplexLivingEntity){
//// Bukkit.broadcastMessage(entity.getName());//8 EnderDragon
//// }
//// });
//
// return true;
Expand Down Expand Up @@ -109,7 +107,34 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
break;
}
case "respawn" : {//ed respawn [world_name]
case "spawn" : {//ed spawn [dragon] (world_name)
if(!sender.hasPermission("ed.respawn")){
Lang.sendFeedback(sender,Lang.command_no_permission);
return false;
}
if(args.length == 2){
if(!(sender instanceof Player)){
Lang.sendFeedback(sender,"§cConsole usage: /ed spawn [dragon] [world_name]");
return false;
}
Player player = (Player) sender;
DragonManager.initiateRespawn(player,args[1]);
return true;
}
else if(args.length == 3){
String world_name = args[2];
DragonManager.initiateRespawn(sender,world_name,args[1]);
return true;
}
else if(args.length > 3){//if world_name contains " "
int size = args.length;
StringBuilder builder = new StringBuilder(args[2]);
for(int i=3;i<size;i++) builder.append(" ").append(args[i]);
DragonManager.initiateRespawn(sender,builder.toString(),args[1]);
return true;
}
}
case "respawn" : {//ed respawn (world_name)
if(!sender.hasPermission("ed.respawn")){
Lang.sendFeedback(sender,Lang.command_no_permission);
return false;
Expand All @@ -120,19 +145,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}
Player player = (Player) sender;
EnderDragon.getInstance().getDragonManager().initiateRespawn(player);
DragonManager.initiateRespawn(player);
return true;
}
else if(args.length == 2){
String world_name = args[1];
EnderDragon.getInstance().getDragonManager().initiateRespawn(sender,world_name);
DragonManager.initiateRespawn(sender,world_name);
return true;
}
else {
else {//if world_name contains " "
int size = args.length;
StringBuilder builder = new StringBuilder(args[1]);
for(int i=2;i<size;i++) builder.append(" ").append(args[i]);
EnderDragon.getInstance().getDragonManager().initiateRespawn(sender,builder.toString());
DragonManager.initiateRespawn(sender,builder.toString());
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class TabCompleter implements org.bukkit.command.TabCompleter {

private static final List<String> arguments_ed = Arrays.asList("action", "drop", "reload", "respawn", "respawn_cd", "update");
private static final List<String> arguments_ed = Arrays.asList("action", "drop", "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_action = Arrays.asList("tell:","tell-colorless:","tell-raw:","groovy:");
private static final List<String> arguments_respawn_cd = Arrays.asList("get","remove","removeAll","set","start");
Expand All @@ -42,6 +42,9 @@ else if(args[0].equalsIgnoreCase("respawn_cd")){
else if(args[0].equalsIgnoreCase("reload")){
result.addAll(arguments_reload);
}
else if(args[0].equalsIgnoreCase("spawn")){
result.addAll(DragonManager.dragon_names);
}
else if(args[0].equalsIgnoreCase("action")){
Stream<String> stream = Bukkit.getOnlinePlayers().stream().map(Player::getName);
return filterResult(stream,Arrays.asList("me"),args[args.length-1]);
Expand All @@ -60,6 +63,9 @@ else if("respawn_cd".equals(args[0])){
result.addAll(WorldManager.worlds);
}
}
else if("spawn".equals(args[0])){
result.addAll(WorldManager.worlds);
}
else if("action".equals(args[0])){
result.addAll(arguments_action);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/pers/xanadu/enderdragon/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Config {
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_save_bossbar;
public static boolean advanced_setting_glowing_fix;
public static boolean advanced_setting_backslash_split_reward;
public static String damage_visible_mode;
Expand All @@ -34,6 +35,7 @@ public class Config {
public static String item_format_reward;
public static List<String> dragon_setting_file;
public static List<String> blacklist_worlds;
public static List<String> blacklist_spawn_reason;
private static final String pluginFilePath;

public static void reload(FileConfiguration file){
Expand Down
102 changes: 8 additions & 94 deletions src/main/java/pers/xanadu/enderdragon/config/FileUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import pers.xanadu.enderdragon.EnderDragon;

import java.io.*;

import static pers.xanadu.enderdragon.EnderDragon.*;

public class FileUpdater {
public static void update() throws IOException {
String respawn_world_name = null;

FileConfiguration config_old = plugin.getConfig();
if("2.1.0".equals(config_old.getString("version"))){
if("2.2.0".equals(config_old.getString("version"))){
Config.saveResource("config.yml","new/config.yml",true);
File config_new_F = new File(plugin.getDataFolder(),"new/config.yml");
FileConfiguration config_new = YamlConfiguration.loadConfiguration(config_new_F);
Expand All @@ -24,111 +23,26 @@ public static void update() throws IOException {
config_new.set("special_dragon_jude_mode",judge_mode);
config_new.set("dragon_setting_file",config_old.getStringList("dragon_setting_file"));
// auto_respawn
config_new.set("auto_respawn.task1.enable",config_old.getBoolean("auto_respawn.enable"));
respawn_world_name = config_old.getString("auto_respawn.world_the_end_name");
config_new.set("auto_respawn.task1.world_name",respawn_world_name);
config_new.set("auto_respawn.task1.respawn_time",config_old.getString("auto_respawn.respawn_time"));
config_new.set("crystal_invulnerable",config_old.getBoolean("auto_respawn.invulnerable"));
config_new.set("auto_respawn",config_old.getConfigurationSection("auto_respawn"));

config_new.set("respawn_cd.enable",config_old.getBoolean("respawn_cd.enable"));
config_new.set("crystal_invulnerable",config_old.getBoolean("crystal_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.set("blacklist_worlds",config_old.getStringList("blacklist_worlds"));
//item_format.data -> item_format.reward
config_new.set("item_format.reward",config_old.getString("item_format.data"));

config_new.set("item_format.reward",config_old.getString("item_format.reward"));
config_new.set("hook_plugins.MythicLib",config_old.getBoolean("hook_plugins.MythicLib"));
config_new.set("expansion.groovy",config_old.getBoolean("expansion.groovy"));
config_new.set("debug",config_old.getBoolean("debug"));
config_new.set("advanced_setting.world_env_fix",config_old.getBoolean("advanced_setting.world_env_fix"));
config_new.set("advanced_setting.save_respawn_status",config_old.getBoolean("advanced_setting.save_respawn_status"));
config_new.set("save_bossbar",config_old.getBoolean("save_bossbar"));
config_new.set("backslash_split.reward",config_old.getBoolean("backslash_split.reward"));
config_new.save(config_new_F);
}
else Lang.error("The version of config.yml is not supported!");
File folder = new File(plugin.getDataFolder(),"setting");
if(folder.exists()){
File[] files = folder.listFiles();
if(files != null){
for(File file : files){
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
String ver = config.getString("version");
if(!"2.1.0".equals(ver)) {
Lang.error("The version of setting/"+file.getName()+" is not supported!");
continue;
}
String name = file.getName();
Config.copyFile("setting/"+name,"new/setting/"+name,true);
}
File new_folder = new File(plugin.getDataFolder(),"new/setting/");
files = new_folder.listFiles();
if(files != null){
for(File file : files){
FileOutputStream out = new FileOutputStream(file,true);
out.write(("\n\n" +
"# the least interval time between injuries (unit:tick, 1tick=0.05s)\n" +
"# only supports integer value\n" +
"no_damage_tick: 10\n" +
"\n" +
"attack:\n" +
" #the damage modify when this dragon attacks player with body or limb (allow double and negative value)\n" +
" damage_modify: 0\n" +
"\n" +
" #the effect give to player when this ender dragon attacks player with body or limb\n" +
" #the format is the same as effect_cloud.potion\n" +
" potion_effect:\n" +
" - ''\n" +
" - ''\n" +
" - ''\n" +
"\n" +
" # the effect give to player when this ender dragon attacks player with body or limb\n" +
" # format: (<type>: seconds)\n" +
" extra_effect:\n" +
" fire: 0\n" +
" # \"freeze\" can only be used in server greater than or equal to version 1.17\n" +
" freeze: 0\n" +
"\n"
).getBytes());
out.close();
FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
fc.set("version","2.2.0");
fc.set("attack.damage_modify",fc.getDouble("attack_damage_modify"));
fc.set("attack_damage_modify",null);
fc.get("attack.potion_effect",fc.getStringList("attack_potion_effect"));
fc.set("attack_potion_effect",null);
fc.save(file);
}
}
}
}
String lang_name = config_old.getString("lang","English") + ".yml";
FileConfiguration lang_old = lang;
if("2.1.0".equals(lang_old.getString("version"))){
Config.saveResource("lang/"+lang_name,"new/lang/"+lang_name,true);
File lang_new_F = new File(plugin.getDataFolder(),"new/lang/"+lang_name);
FileConfiguration lang_new = YamlConfiguration.loadConfiguration(lang_new_F);
lang_old.getKeys(true).forEach(key->{
Object obj = lang_old.get(key);
lang_new.set(key,obj);
});
lang_new.set("version","2.2.0");
lang_new.save(lang_new_F);
}
else Lang.error("The version of "+lang_name+" is not supported!");

FileConfiguration data_old = EnderDragon.data;
if("2.1.0".equals(data_old.getString("version"))){
Config.copyFile("data.yml","new/data.yml",true);
File new_data_file = new File(plugin.getDataFolder(),"new/data.yml");
FileConfiguration new_data = YamlConfiguration.loadConfiguration(new_data_file);
String next_time = new_data.getString("auto_respawn.next_respawn_time");
new_data.set("version","2.2.0");
if(next_time!=null && respawn_world_name!=null){
new_data.set("auto_respawn.task1.world_name",respawn_world_name);
new_data.set("auto_respawn.task1.next_respawn_time",next_time);
}
new_data.save(new_data_file);
}
else Lang.error("The version of data.yml is not supported!");
Lang.info("New config files are generated in plugins/EnderDragon/new.");
Lang.warn("Attention: Please confirm the accuracy before using new config!");
}
Expand Down
Loading

0 comments on commit 33ab7ae

Please sign in to comment.