Skip to content

Commit

Permalink
update to v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iXanadu13 committed Dec 7, 2023
1 parent cc9d262 commit d2b0fa0
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 152 deletions.
36 changes: 18 additions & 18 deletions src/main/java/pers/xanadu/enderdragon/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}
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);
// entities.forEach(entity -> {
// if(entity instanceof org.bukkit.entity.EnderDragon){
// org.bukkit.entity.EnderDragon dragon = (org.bukkit.entity.EnderDragon) entity;
// //dragon.setPhase(CHARGE_PLAYER);
// //SkillManager.launchDragonFireball(dragon,p.getLocation());
// SkillManager.callEnderManReinforce(p,3);
// }
//
//
// 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);
//// entities.forEach(entity -> {
//// if(entity instanceof org.bukkit.entity.EnderDragon){
//// org.bukkit.entity.EnderDragon dragon = (org.bukkit.entity.EnderDragon) entity;
//// //dragon.setPhase(CHARGE_PLAYER);
//// //SkillManager.launchDragonFireball(dragon,p.getLocation());
//// SkillManager.callEnderManReinforce(p,3);
//// }
////
////
//// if(entity instanceof org.bukkit.entity.EnderDragon){
//// Bukkit.broadcastMessage(entity.getName());//1 Special Ender Dragon
//// }
Expand All @@ -53,10 +53,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
//// if(entity instanceof ComplexLivingEntity){
//// Bukkit.broadcastMessage(entity.getName());//8 EnderDragon
//// }
// });

return true;
}
//// });
//
// return true;
// }
case "action" : {
if(!sender.isOp()){
Lang.sendFeedback(sender,Lang.command_no_permission);
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

/**
* Called when a dragon is damaged by a player, including block_explosion.
*/
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;
}

Expand All @@ -29,15 +29,15 @@ public static HandlerList getHandlerList() {
public HandlerList getHandlers() {
return handlers;
}

@Override
public void setCancelled(final boolean cancel) {
this.cancel = cancel;
}

@Override
public boolean isCancelled() {
return cancel;
}

@Override
public Player getDamager() {
return damager;
}
Expand All @@ -46,9 +46,6 @@ public EnderDragon getDragon() {
return dragon;
}

public DamageCause getDamagerCause() {
return cause;
}
@Override
public double getDamage() {
return finalDamage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
import org.bukkit.event.entity.CreatureSpawnEvent;
import pers.xanadu.enderdragon.manager.DragonManager;
import pers.xanadu.enderdragon.util.MyDragon;

public final class DragonRespawnEvent extends CreatureSpawnEvent {
/**
* Called when a dragon is spawned, filtered through blacklist.
* <p>
* Cancelling this event make no changes.
*/
public final class DragonRespawnPostEvent extends CreatureSpawnEvent {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final World world;
private final MyDragon myDragon;
public DragonRespawnEvent(final EnderDragon dragon,final SpawnReason reason,final MyDragon myDragon) {
public DragonRespawnPostEvent(final EnderDragon dragon, final SpawnReason reason, final MyDragon myDragon) {
super(dragon,reason);
world = dragon.getWorld();
this.myDragon = myDragon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public void BaseAttackToDragon(EntityDamageByEntityEvent e){
EnderDragon dragon = (EnderDragon) victim;
if(entity instanceof Player){
Player player = (Player) entity;
pm.callEvent(new DragonDamageByPlayerEvent(player,dragon,e.getCause(),e.getFinalDamage()));
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(player,dragon,e.getCause(),e.getFinalDamage());
pm.callEvent(event);
if(event.isCancelled()) e.setCancelled(true);
}
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()));
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(damager,dragon,e.getCause(),e.getFinalDamage());
pm.callEvent(event);
if(event.isCancelled()) e.setCancelled(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DragonDamageByPlayerListener implements Listener {

@EventHandler(priority = EventPriority.HIGHEST)
public void OnDragonDamageByPlayer(final DragonDamageByPlayerEvent e){
if(e.isCancelled()) return;
Player p = e.getDamager();
EnderDragon dragon = e.getDragon();
double health = dragon.getHealth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public void OnDragonDamageByTNT(final EntityDamageByEntityEvent e){
TNTPrimed tnt = (TNTPrimed) entity;
if(!(tnt.getSource() instanceof Player)) return;
Player damager = (Player) tnt.getSource();
pers.xanadu.enderdragon.EnderDragon.pm.callEvent(new DragonDamageByPlayerEvent(damager,dragon,e.getCause(),e.getFinalDamage()));
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(damager,dragon,e.getCause(),e.getFinalDamage());
pm.callEvent(event);
if(event.isCancelled()) e.setCancelled(true);
}
}
}
Expand All @@ -54,16 +56,15 @@ public void OnDragonDamageByExplode(final EntityDamageByBlockEvent e){
if(e.getCause() != EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) return;
Entity entity = e.getEntity();
if(entity instanceof EnderDragon){
//Bukkit.broadcastMessage(e.getFinalDamage()+"awa");
EnderDragon dragon = (EnderDragon) entity;
for(UUID uuid : mp.keySet()){
PlayerExplodeDragonEvent ped = mp.get(uuid);
if(ped == null) continue;
if(ped.getTime() != time) continue;
if(ped.getEnderDragon().getUniqueId() != dragon.getUniqueId()) continue;
//mp.remove(uuid);
pm.callEvent(new DragonDamageByPlayerEvent(ped.getPlayer(),dragon,cause,e.getFinalDamage()));
//Bukkit.broadcastMessage("final: "+e.getFinalDamage());
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(ped.getPlayer(),dragon,cause,e.getFinalDamage());
pm.callEvent(event);
if(event.isCancelled()) e.setCancelled(true);
break;
}
}
Expand All @@ -82,7 +83,6 @@ public void OnPlayerClickBed(final PlayerBedEnterEvent e){
}
}


public static void clearUID(final UUID uuid){
mp.remove(uuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import org.bukkit.event.entity.CreatureSpawnEvent;
import pers.xanadu.enderdragon.config.Config;
import pers.xanadu.enderdragon.config.Lang;
import pers.xanadu.enderdragon.event.DragonRespawnEvent;
import pers.xanadu.enderdragon.event.DragonRespawnPostEvent;
import pers.xanadu.enderdragon.manager.DamageManager;
import pers.xanadu.enderdragon.util.MyDragon;
import pers.xanadu.enderdragon.util.Version;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import static pers.xanadu.enderdragon.EnderDragon.*;
Expand Down Expand Up @@ -72,7 +73,10 @@ public void OnDragonSpawn(final CreatureSpawnEvent e){
else if(Version.mcMainVersion >= 12){
getInstance().getBossBarManager().setBossBar(dragon.getWorld(),myDragon.display_name,bossBar_color,bossBar_style);
}
Bukkit.getPluginManager().callEvent(new DragonRespawnEvent(dragon,e.getSpawnReason(),myDragon));
Bukkit.getPluginManager().callEvent(new DragonRespawnPostEvent(dragon,e.getSpawnReason(),myDragon));
if(Config.advanced_setting_save_bossbar){
getInstance().getBossBarManager().saveBossBarData(Collections.singletonList(dragon.getWorld()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void onPlayerAttack(final PlayerAttackEvent e){
if(final_damage > 0.0d){
DragonDamageByPlayerEvent event = new DragonDamageByPlayerEvent(e.getAttacker().getPlayer(),dragon, e.toBukkit().getCause(), final_damage);
pm.callEvent(event);
if(event.isCancelled()) e.setCancelled(true);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/pers/xanadu/enderdragon/script/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public static <T extends Event> Events<T> register(Class<T> clazz, EventPriority
GroovyManager.event_set.add(tmp);
return tmp;
}
// private static <T extends Event> void register(Class<T> clazz, Events<T> event, EventPriority priority, boolean ignoreCancelled) {
// Bukkit.getPluginManager().registerEvent(clazz,event,priority,event,plugin,ignoreCancelled);
// }

@Override
public void execute(@NotNull Listener listener, @NotNull Event event) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pers/xanadu/enderdragon/util/ColorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ private static String transGradient(String str) {
}
private static int[] gradient(String start,String end,int length){
int[] color = new int[length];
int[] rgb1 = MathUtil.hexToInt(start);
int[] rgb2 = MathUtil.hexToInt(end);
int[] rgb1 = MathUtil.hex2Int(start);
int[] rgb2 = MathUtil.hex2Int(end);
if(length==0){return color;}
if(length==1){
for(int j=0;j<3;j++){
Expand Down
Loading

0 comments on commit d2b0fa0

Please sign in to comment.