make method to be static for easy calling of users
This commit is contained in:
@@ -7,6 +7,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
import pers.xanadu.enderdragon.manager.TimerManager;
|
import pers.xanadu.enderdragon.manager.TimerManager;
|
||||||
import pers.xanadu.enderdragon.task.DragonRespawnTimer;
|
import pers.xanadu.enderdragon.task.DragonRespawnTimer;
|
||||||
import pers.xanadu.enderdragon.util.MathUtil;
|
import pers.xanadu.enderdragon.util.MathUtil;
|
||||||
@@ -46,8 +47,7 @@ public class Papi extends PlaceholderExpansion {
|
|||||||
public String onPlaceholderRequest(final Player player, final @NotNull String params){
|
public String onPlaceholderRequest(final Player player, final @NotNull String params){
|
||||||
if(params.equals("can_respawn")){
|
if(params.equals("can_respawn")){
|
||||||
if(player == null) return String.valueOf(false);
|
if(player == null) return String.valueOf(false);
|
||||||
boolean res = EnderDragon.getInstance().getDragonManager().canRespawn(player.getWorld());
|
return String.valueOf(DragonManager.canRespawn(player.getWorld()));
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
}
|
||||||
if(params.equals("respawn_cd_progress")){
|
if(params.equals("respawn_cd_progress")){
|
||||||
if(player == null) return null;
|
if(player == null) return null;
|
||||||
@@ -73,8 +73,7 @@ public class Papi extends PlaceholderExpansion {
|
|||||||
if(params.startsWith("can_respawn_")){
|
if(params.startsWith("can_respawn_")){
|
||||||
String name = params.substring("can_respawn_".length());
|
String name = params.substring("can_respawn_".length());
|
||||||
World world = Bukkit.getWorld(name);
|
World world = Bukkit.getWorld(name);
|
||||||
boolean res = EnderDragon.getInstance().getDragonManager().canRespawn(world);
|
return String.valueOf(DragonManager.canRespawn(world));
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
}
|
||||||
if(params.startsWith("respawn_cd_progress_")){
|
if(params.startsWith("respawn_cd_progress_")){
|
||||||
String name = params.substring("respawn_cd_progress_".length());
|
String name = params.substring("respawn_cd_progress_".length());
|
||||||
|
|||||||
@@ -33,10 +33,15 @@ public class DragonManager {
|
|||||||
public static List<String> dragon_names = new ArrayList<>();
|
public static List<String> dragon_names = new ArrayList<>();
|
||||||
private static int sum = 0;
|
private static int sum = 0;
|
||||||
private static final int[][] nxt = {{3,0},{0,3},{-3,0},{0,-3}};
|
private static final int[][] nxt = {{3,0},{0,3},{-3,0},{0,-3}};
|
||||||
private Method DragonBattle_e;
|
private static final int[][] nxt_2 = {{2,0},{0,2},{-2,0},{0,-2}};
|
||||||
private Method getX;
|
private static final String getEDB_base;
|
||||||
private Method getY;
|
private static Class<?> CraftWorldClass;
|
||||||
private Method getZ;
|
private static Class<?> WorldProviderTheEndClass;
|
||||||
|
private static Class<?> EnderDragonBattleClass;
|
||||||
|
private static Method DragonBattle_e;
|
||||||
|
private static Method getX;
|
||||||
|
private static Method getY;
|
||||||
|
private static Method getZ;
|
||||||
|
|
||||||
public static void reload(){
|
public static void reload(){
|
||||||
new BukkitRunnable(){
|
new BukkitRunnable(){
|
||||||
@@ -278,25 +283,77 @@ public class DragonManager {
|
|||||||
instance.addModifier(new AttributeModifier("EnderDragon",amount,AttributeModifier.Operation.ADD_NUMBER));
|
instance.addModifier(new AttributeModifier("EnderDragon",amount,AttributeModifier.Operation.ADD_NUMBER));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initiateRespawn(final Player p){
|
public static void initiateRespawn(final Player p,final String uniqueId){
|
||||||
DragonRespawnResult res = initiateRespawn(p.getWorld());
|
DragonRespawnResult res = initiateRespawn(p.getWorld(),uniqueId);
|
||||||
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
else Lang.sendFeedback(p,"§c"+res.getMessage());
|
else Lang.sendFeedback(p,"§c"+res.getMessage());
|
||||||
}
|
}
|
||||||
public void initiateRespawn(final CommandSender sender,final String world_name){
|
public static void initiateRespawn(final CommandSender sender,final String world_name,final String uniqueId){
|
||||||
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name));
|
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name),uniqueId);
|
||||||
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
else Lang.sendFeedback(sender,"§c"+res.getMessage());
|
else Lang.sendFeedback(sender,"§c"+res.getMessage());
|
||||||
}
|
}
|
||||||
public void initiateRespawn(final String world_name){
|
public static void initiateRespawn(final String world_name,final String uniqueId){
|
||||||
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name));
|
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name),uniqueId);
|
||||||
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
else Lang.error(res.getMessage());
|
else Lang.error(res.getMessage());
|
||||||
}
|
}
|
||||||
public boolean canRespawn(final String world_name){
|
public static DragonRespawnResult initiateRespawn(final World world,final String uniqueId){
|
||||||
|
if(world == null) return DragonRespawnResult.world_not_found;
|
||||||
|
if(world.getEnvironment() != World.Environment.THE_END) return DragonRespawnResult.world_wrong_env;
|
||||||
|
if(Version.mcMainVersion >= 16){
|
||||||
|
DragonBattle battle = world.getEnderDragonBattle();
|
||||||
|
assert battle != null;
|
||||||
|
if(battle.getEnderDragon() != null) return DragonRespawnResult.dragon_has_existed;
|
||||||
|
if(battle.getRespawnPhase() != DragonBattle.RespawnPhase.NONE) return DragonRespawnResult.respawn_has_started;
|
||||||
|
Location cen = battle.getEndPortalLocation();
|
||||||
|
if(cen == null) {
|
||||||
|
battle.initiateRespawn();
|
||||||
|
cen = battle.getEndPortalLocation();
|
||||||
|
if(cen == null){
|
||||||
|
return DragonRespawnResult.world_unloaded;//也可尝试chunk.load()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(uniqueId == null) placeEndCrystals(cen);
|
||||||
|
else placeEndCrystals(cen,uniqueId);
|
||||||
|
battle.initiateRespawn();
|
||||||
|
return DragonRespawnResult.success;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Object battle = getEnderDragonBattle(world);
|
||||||
|
assert battle != null;
|
||||||
|
Field k = EnderDragonBattleClass.getDeclaredField("k");
|
||||||
|
k.setAccessible(true);
|
||||||
|
Object isAlive = k.get(battle);
|
||||||
|
if(!((boolean) isAlive)) return DragonRespawnResult.dragon_has_existed;
|
||||||
|
Field p = EnderDragonBattleClass.getDeclaredField("p");
|
||||||
|
p.setAccessible(true);
|
||||||
|
Object phase = p.get(battle);
|
||||||
|
if(phase != null) return DragonRespawnResult.respawn_has_started;
|
||||||
|
Field field = EnderDragonBattleClass.getDeclaredField("o");
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object BlockPosition = field.get(battle);
|
||||||
|
if(BlockPosition == null){
|
||||||
|
DragonBattle_e.invoke(battle);
|
||||||
|
BlockPosition = field.get(battle);
|
||||||
|
if(BlockPosition == null) return DragonRespawnResult.world_unloaded;
|
||||||
|
}
|
||||||
|
if(getX == null) getX = BlockPosition.getClass().getMethod("getX");
|
||||||
|
if(getY == null) getY = BlockPosition.getClass().getMethod("getY");
|
||||||
|
if(getZ == null) getZ = BlockPosition.getClass().getMethod("getZ");
|
||||||
|
Location loc = new Location(world,(int)getX.invoke(BlockPosition),(int)getY.invoke(BlockPosition),(int)getZ.invoke(BlockPosition));
|
||||||
|
if(uniqueId == null) placeEndCrystals(loc);
|
||||||
|
else placeEndCrystals(loc,uniqueId);
|
||||||
|
DragonBattle_e.invoke(battle);
|
||||||
|
return DragonRespawnResult.success;
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
return DragonRespawnResult.version_not_support;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static boolean canRespawn(final String world_name){
|
||||||
return canRespawn(Bukkit.getWorld(world_name));
|
return canRespawn(Bukkit.getWorld(world_name));
|
||||||
}
|
}
|
||||||
public boolean canRespawn(final World world){
|
public static boolean canRespawn(final World world){
|
||||||
if(world == null) return false;
|
if(world == null) return false;
|
||||||
if(world.getEnvironment() != World.Environment.THE_END) return false;
|
if(world.getEnvironment() != World.Environment.THE_END) return false;
|
||||||
if(Version.mcMainVersion >= 16){//executes 1e5 times within 27ms
|
if(Version.mcMainVersion >= 16){//executes 1e5 times within 27ms
|
||||||
@@ -315,22 +372,21 @@ public class DragonManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {//executes 1e5 times within 76ms
|
try {//executes 1e5 times within 76ms
|
||||||
Object battle = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object battle = getEnderDragonBattle(world);
|
||||||
if(battle == null) return false;
|
if(battle == null) return false;
|
||||||
Field k = battle.getClass().getDeclaredField("k");
|
Field k = EnderDragonBattleClass.getDeclaredField("k");
|
||||||
k.setAccessible(true);
|
k.setAccessible(true);
|
||||||
Object isAlive = k.get(battle);
|
Object isAlive = k.get(battle);
|
||||||
if(!((boolean) isAlive)) return false;
|
if(!((boolean) isAlive)) return false;
|
||||||
Field p = battle.getClass().getDeclaredField("p");
|
Field p = EnderDragonBattleClass.getDeclaredField("p");
|
||||||
p.setAccessible(true);
|
p.setAccessible(true);
|
||||||
Object phase = p.get(battle);
|
Object phase = p.get(battle);
|
||||||
if(phase != null) return false;
|
if(phase != null) return false;
|
||||||
Field field = battle.getClass().getDeclaredField("o");
|
Field field = EnderDragonBattleClass.getDeclaredField("o");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object BlockPosition = field.get(battle);
|
Object BlockPosition = field.get(battle);
|
||||||
if(BlockPosition == null){
|
if(BlockPosition == null){
|
||||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
DragonBattle_e.invoke(battle);
|
||||||
this.DragonBattle_e.invoke(battle);
|
|
||||||
BlockPosition = field.get(battle);
|
BlockPosition = field.get(battle);
|
||||||
if(BlockPosition == null) return false;
|
if(BlockPosition == null) return false;
|
||||||
}
|
}
|
||||||
@@ -339,7 +395,39 @@ public class DragonManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean isRespawnRunning(final World world){
|
public static Location getEndPortalLocation(final World world){
|
||||||
|
if(world == null) return null;
|
||||||
|
if(world.getEnvironment() != World.Environment.THE_END) return null;
|
||||||
|
if(Version.mcMainVersion >= 16){
|
||||||
|
DragonBattle battle = world.getEnderDragonBattle();
|
||||||
|
if(battle == null) return null;
|
||||||
|
Location cen = battle.getEndPortalLocation();
|
||||||
|
if(cen == null) {
|
||||||
|
battle.initiateRespawn();
|
||||||
|
cen = battle.getEndPortalLocation();
|
||||||
|
}
|
||||||
|
return cen;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Object battle = getEnderDragonBattle(world);
|
||||||
|
if(battle == null) return null;
|
||||||
|
Field field = EnderDragonBattleClass.getDeclaredField("o");
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object BlockPosition = field.get(battle);
|
||||||
|
if(BlockPosition == null){
|
||||||
|
DragonBattle_e.invoke(battle);
|
||||||
|
BlockPosition = field.get(battle);
|
||||||
|
if(BlockPosition == null) return null;
|
||||||
|
}
|
||||||
|
if(getX == null) getX = BlockPosition.getClass().getMethod("getX");
|
||||||
|
if(getY == null) getY = BlockPosition.getClass().getMethod("getY");
|
||||||
|
if(getZ == null) getZ = BlockPosition.getClass().getMethod("getZ");
|
||||||
|
return new Location(world,(int)getX.invoke(BlockPosition),(int)getY.invoke(BlockPosition),(int)getZ.invoke(BlockPosition));
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static boolean isRespawnRunning(final World world){
|
||||||
if(world == null) return false;
|
if(world == null) return false;
|
||||||
if(world.getEnvironment() != World.Environment.THE_END) return false;
|
if(world.getEnvironment() != World.Environment.THE_END) return false;
|
||||||
if(Version.mcMainVersion >= 16){
|
if(Version.mcMainVersion >= 16){
|
||||||
@@ -348,9 +436,9 @@ public class DragonManager {
|
|||||||
return battle.getRespawnPhase() != DragonBattle.RespawnPhase.NONE;
|
return battle.getRespawnPhase() != DragonBattle.RespawnPhase.NONE;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object battle = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object battle = getEnderDragonBattle(world);
|
||||||
assert battle != null;
|
assert battle != null;
|
||||||
Field p = battle.getClass().getDeclaredField("p");
|
Field p = EnderDragonBattleClass.getDeclaredField("p");
|
||||||
p.setAccessible(true);
|
p.setAccessible(true);
|
||||||
Object phase = p.get(battle);
|
Object phase = p.get(battle);
|
||||||
return phase != null;
|
return phase != null;
|
||||||
@@ -359,7 +447,7 @@ public class DragonManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void refresh_respawn(final World world){
|
public static void refresh_respawn(final World world){
|
||||||
if(world == null) return;
|
if(world == null) return;
|
||||||
if(world.getEnvironment() != World.Environment.THE_END) return;
|
if(world.getEnvironment() != World.Environment.THE_END) return;
|
||||||
if(Version.mcMainVersion >= 16){
|
if(Version.mcMainVersion >= 16){
|
||||||
@@ -369,16 +457,113 @@ public class DragonManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object battle = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object battle = getEnderDragonBattle(world);
|
||||||
assert battle != null;
|
assert battle != null;
|
||||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
DragonBattle_e.invoke(battle);
|
||||||
this.DragonBattle_e.invoke(battle);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static void placeEndCrystals(final Location cen){
|
||||||
private DragonRespawnResult initiateRespawn(final World world){
|
World world = cen.getWorld();
|
||||||
|
if(world == null) return;
|
||||||
|
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.crystal_invulnerable) crystal.setInvulnerable(true);
|
||||||
|
crystal.setShowingBottom(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void placeEndCrystals(final Location cen,final String uniqueId){
|
||||||
|
World world = cen.getWorld();
|
||||||
|
if(world == null) return;
|
||||||
|
cen.add(0.5,1,0.5);
|
||||||
|
for(int i=0;i<4;i++){
|
||||||
|
Location loc = cen.clone().add(nxt_2[i][0],0,nxt_2[i][1]);
|
||||||
|
world.getNearbyEntities(loc,0.5,0.5,0.5).forEach(entity -> {
|
||||||
|
if(entity instanceof EnderCrystal) entity.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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.crystal_invulnerable) crystal.setInvulnerable(true);
|
||||||
|
crystal.setShowingBottom(false);
|
||||||
|
crystal.addScoreboardTag("ed_spe_"+uniqueId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static MyDragon getDesignatedDragon(final World world){
|
||||||
|
List<EnderCrystal> list = new ArrayList<>();
|
||||||
|
Location cen = DragonManager.getEndPortalLocation(world).add(0.5,1,0.5);
|
||||||
|
for(int i=0;i<4;i++){
|
||||||
|
Location loc = cen.clone().add(nxt_2[i][0],0,nxt_2[i][1]);
|
||||||
|
world.getNearbyEntities(loc,0.5,0.5,0.5).forEach(entity -> {
|
||||||
|
if(entity instanceof EnderCrystal) list.add((EnderCrystal) entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for(EnderCrystal crystal : list) {
|
||||||
|
Set<String> tags = crystal.getScoreboardTags();
|
||||||
|
for(MyDragon a : dragons){
|
||||||
|
if(tags.contains("ed_spe_"+a.unique_name)) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static Object getEnderDragonBattle(final World world){
|
||||||
|
String version = Version.getVersion();
|
||||||
|
if (Version.mcMainVersion>=12 && Version.mcMainVersion<16) {
|
||||||
|
try {
|
||||||
|
Object worldServer = getWorldServer(world);
|
||||||
|
assert worldServer != null;
|
||||||
|
Field field = worldServer.getClass().getField("worldProvider");
|
||||||
|
Object worldProvider = field.get(worldServer);
|
||||||
|
Object WorldProviderTheEnd = WorldProviderTheEndClass.cast(worldProvider);
|
||||||
|
String method_name = getEDB_base;
|
||||||
|
if(method_name == null) return null;
|
||||||
|
Method method = WorldProviderTheEnd.getClass().getDeclaredMethod(method_name);
|
||||||
|
return method.invoke(WorldProviderTheEnd);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
Lang.warn("Your server version (" + version + ") is not supported!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Lang.warn("Your server version (" + version + ") is not supported!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private static Object getWorldServer(final World world) {
|
||||||
|
try {
|
||||||
|
Object castClass = getCraftWorld(world);
|
||||||
|
return CraftWorldClass.getDeclaredMethod("getHandle").invoke(castClass);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private static Object getCraftWorld(final World world) {
|
||||||
|
if (CraftWorldClass.isInstance(world)) return CraftWorldClass.cast(world);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public static void initiateRespawn(final Player p){
|
||||||
|
DragonRespawnResult res = initiateRespawn(p.getWorld());
|
||||||
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
|
else Lang.sendFeedback(p,"§c"+res.getMessage());
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public static void initiateRespawn(final CommandSender sender,final String world_name){
|
||||||
|
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name));
|
||||||
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
|
else Lang.sendFeedback(sender,"§c"+res.getMessage());
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public static void initiateRespawn(final String world_name){
|
||||||
|
DragonRespawnResult res = initiateRespawn(Bukkit.getWorld(world_name));
|
||||||
|
if(res == DragonRespawnResult.success) Lang.broadcastMSG(Lang.dragon_auto_respawn);
|
||||||
|
else Lang.error(res.getMessage());
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public static DragonRespawnResult initiateRespawn(final World world){
|
||||||
if(world == null) return DragonRespawnResult.world_not_found;
|
if(world == null) return DragonRespawnResult.world_not_found;
|
||||||
if(world.getEnvironment() != World.Environment.THE_END) return DragonRespawnResult.world_wrong_env;
|
if(world.getEnvironment() != World.Environment.THE_END) return DragonRespawnResult.world_wrong_env;
|
||||||
if(Version.mcMainVersion >= 16){
|
if(Version.mcMainVersion >= 16){
|
||||||
@@ -391,53 +576,42 @@ public class DragonManager {
|
|||||||
battle.initiateRespawn();
|
battle.initiateRespawn();
|
||||||
cen = battle.getEndPortalLocation();
|
cen = battle.getEndPortalLocation();
|
||||||
if(cen == null){
|
if(cen == null){
|
||||||
return DragonRespawnResult.world_unloaded;//也可尝试chunk.load()
|
return DragonRespawnResult.world_unloaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
placeEndCrystals(world,cen);
|
placeEndCrystals(cen);
|
||||||
battle.initiateRespawn();
|
battle.initiateRespawn();
|
||||||
return DragonRespawnResult.success;
|
return DragonRespawnResult.success;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object battle = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object battle = getEnderDragonBattle(world);
|
||||||
assert battle != null;
|
assert battle != null;
|
||||||
Field k = battle.getClass().getDeclaredField("k");
|
Field k = EnderDragonBattleClass.getDeclaredField("k");
|
||||||
k.setAccessible(true);
|
k.setAccessible(true);
|
||||||
Object isAlive = k.get(battle);
|
Object isAlive = k.get(battle);
|
||||||
if(!((boolean) isAlive)) return DragonRespawnResult.dragon_has_existed;
|
if(!((boolean) isAlive)) return DragonRespawnResult.dragon_has_existed;
|
||||||
Field p = battle.getClass().getDeclaredField("p");
|
Field p = EnderDragonBattleClass.getDeclaredField("p");
|
||||||
p.setAccessible(true);
|
p.setAccessible(true);
|
||||||
Object phase = p.get(battle);
|
Object phase = p.get(battle);
|
||||||
if(phase != null) return DragonRespawnResult.respawn_has_started;
|
if(phase != null) return DragonRespawnResult.respawn_has_started;
|
||||||
Field field = battle.getClass().getDeclaredField("o");
|
Field field = EnderDragonBattleClass.getDeclaredField("o");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object BlockPosition = field.get(battle);
|
Object BlockPosition = field.get(battle);
|
||||||
if(BlockPosition == null){
|
if(BlockPosition == null){
|
||||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
DragonBattle_e.invoke(battle);
|
||||||
this.DragonBattle_e.invoke(battle);
|
|
||||||
BlockPosition = field.get(battle);
|
BlockPosition = field.get(battle);
|
||||||
if(BlockPosition == null) return DragonRespawnResult.world_unloaded;
|
if(BlockPosition == null) return DragonRespawnResult.world_unloaded;
|
||||||
}
|
}
|
||||||
if(this.getX == null) this.getX = BlockPosition.getClass().getMethod("getX");
|
if(getX == null) getX = BlockPosition.getClass().getMethod("getX");
|
||||||
if(this.getY == null) this.getY = BlockPosition.getClass().getMethod("getY");
|
if(getY == null) getY = BlockPosition.getClass().getMethod("getY");
|
||||||
if(this.getZ == null) this.getZ = BlockPosition.getClass().getMethod("getZ");
|
if(getZ == null) getZ = BlockPosition.getClass().getMethod("getZ");
|
||||||
Location loc = new Location(world,(int)getX.invoke(BlockPosition),(int)this.getY.invoke(BlockPosition),(int)this.getZ.invoke(BlockPosition));
|
Location loc = new Location(world,(int)getX.invoke(BlockPosition),(int)getY.invoke(BlockPosition),(int)getZ.invoke(BlockPosition));
|
||||||
placeEndCrystals(world, loc);
|
placeEndCrystals(loc);
|
||||||
if (this.DragonBattle_e == null) this.DragonBattle_e = battle.getClass().getMethod("e");
|
DragonBattle_e.invoke(battle);
|
||||||
this.DragonBattle_e.invoke(battle);
|
|
||||||
return DragonRespawnResult.success;
|
return DragonRespawnResult.success;
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
return DragonRespawnResult.version_not_support;
|
return DragonRespawnResult.version_not_support;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
private void placeEndCrystals(final World world,final 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.crystal_invulnerable) crystal.setInvulnerable(true);
|
|
||||||
crystal.setShowingBottom(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public enum DragonRespawnResult{
|
public enum DragonRespawnResult{
|
||||||
success,
|
success,
|
||||||
@@ -461,4 +635,37 @@ public class DragonManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static{
|
||||||
|
String version = Version.getVersion();
|
||||||
|
switch (version) {
|
||||||
|
case "v1_12_R1" : {
|
||||||
|
getEDB_base = "t";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "v1_13_R1" :
|
||||||
|
case "v1_13_R2" : {
|
||||||
|
getEDB_base = "r";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "v1_14_R1" : {
|
||||||
|
getEDB_base = "q";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "v1_15_R1" : {
|
||||||
|
getEDB_base = "o";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default : getEDB_base = null;
|
||||||
|
}
|
||||||
|
if(Version.mcMainVersion>=12 && Version.mcMainVersion<16){
|
||||||
|
try{
|
||||||
|
CraftWorldClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
|
||||||
|
WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
||||||
|
EnderDragonBattleClass = Class.forName("net.minecraft.server."+version+".EnderDragonBattle");
|
||||||
|
DragonBattle_e = EnderDragonBattleClass.getMethod("e");
|
||||||
|
}catch (ReflectiveOperationException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
|
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -14,7 +15,6 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.getInstance;
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
public class BossBarManager implements I_BossBarManager {
|
public class BossBarManager implements I_BossBarManager {
|
||||||
@@ -24,7 +24,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
YamlConfiguration yml = new YamlConfiguration();
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -56,7 +57,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
}
|
}
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -79,7 +81,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
bbs.setDarkenSky(true);
|
bbs.setDarkenSky(true);
|
||||||
bbs.setPlayMusic(true);
|
bbs.setPlayMusic(true);
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer.set(edb,bbs);
|
BossBattleServer.set(edb,bbs);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
|
import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -14,7 +15,6 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.getInstance;
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
public class BossBarManager implements I_BossBarManager {
|
public class BossBarManager implements I_BossBarManager {
|
||||||
@@ -24,7 +24,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
YamlConfiguration yml = new YamlConfiguration();
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -56,7 +57,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
}
|
}
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -79,7 +81,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
bbs.setDarkenSky(true);
|
bbs.setDarkenSky(true);
|
||||||
bbs.setPlayMusic(true);
|
bbs.setPlayMusic(true);
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("c");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer.set(edb,bbs);
|
BossBattleServer.set(edb,bbs);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
|
import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -14,7 +15,6 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.getInstance;
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
public class BossBarManager implements I_BossBarManager {
|
public class BossBarManager implements I_BossBarManager {
|
||||||
@@ -24,7 +24,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
YamlConfiguration yml = new YamlConfiguration();
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -56,7 +57,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
}
|
}
|
||||||
worlds.forEach(world -> {
|
worlds.forEach(world -> {
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
@@ -79,7 +81,8 @@ public class BossBarManager implements I_BossBarManager {
|
|||||||
bbs.setDarkenSky(true);
|
bbs.setDarkenSky(true);
|
||||||
bbs.setPlayMusic(true);
|
bbs.setPlayMusic(true);
|
||||||
try{
|
try{
|
||||||
Object edb = getInstance().getNMSManager().getEnderDragonBattle(world);
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
if(BossBattleServer == null) BossBattleServer = edb.getClass().getField("bossBattle");
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getField("bossBattle");
|
||||||
BossBattleServer.setAccessible(true);
|
BossBattleServer.setAccessible(true);
|
||||||
BossBattleServer.set(edb,bbs);
|
BossBattleServer.set(edb,bbs);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package pers.xanadu.enderdragon.task;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.*;
|
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ public class DragonRespawnRunnable extends BukkitRunnable {
|
|||||||
new BukkitRunnable(){
|
new BukkitRunnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
EnderDragon.getInstance().getDragonManager().initiateRespawn(task.world_name);
|
DragonManager.initiateRespawn(task.world_name);
|
||||||
task.updateTime();
|
task.updateTime();
|
||||||
task.saveFile();
|
task.saveFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
import pers.xanadu.enderdragon.EnderDragon;
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
import pers.xanadu.enderdragon.util.MathUtil;
|
import pers.xanadu.enderdragon.util.MathUtil;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
@@ -65,8 +66,8 @@ public class DragonRespawnTimer {
|
|||||||
remainSecond--;
|
remainSecond--;
|
||||||
if(remainSecond <= 0){
|
if(remainSecond <= 0){
|
||||||
Bukkit.getScheduler().runTask(plugin,() -> {
|
Bukkit.getScheduler().runTask(plugin,() -> {
|
||||||
if(EnderDragon.getInstance().getDragonManager().canRespawn(world_name)){
|
if(DragonManager.canRespawn(world_name)){
|
||||||
EnderDragon.getInstance().getDragonManager().initiateRespawn(world_name);
|
DragonManager.initiateRespawn(world_name);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
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 java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.getInstance;
|
|
||||||
|
|
||||||
public class NMSUtil {
|
public class NMSUtil {
|
||||||
private String getEDB_base;
|
|
||||||
private Method getNMSWord;
|
private Method getNMSWord;
|
||||||
private Method asNMSCopy;
|
private Method asNMSCopy;
|
||||||
private Method copyNMSStack;
|
private Method copyNMSStack;
|
||||||
@@ -42,7 +38,7 @@ public class NMSUtil {
|
|||||||
private Class<?> WorldClass;
|
private Class<?> WorldClass;
|
||||||
private Class<?> CraftWorldClass;
|
private Class<?> CraftWorldClass;
|
||||||
private Class<?> WorldProviderClass;
|
private Class<?> WorldProviderClass;
|
||||||
private Class<?> WorldProviderTheEndClass;
|
//private Class<?> WorldProviderTheEndClass;
|
||||||
private Class<?> CraftItemStackClass;
|
private Class<?> CraftItemStackClass;
|
||||||
private Class<?> CraftMetaItemClass;
|
private Class<?> CraftMetaItemClass;
|
||||||
private Class<?> NMSItemStackClass;
|
private Class<?> NMSItemStackClass;
|
||||||
@@ -63,7 +59,7 @@ public class NMSUtil {
|
|||||||
this.world_c_environment.setAccessible(true);
|
this.world_c_environment.setAccessible(true);
|
||||||
if(Version.mcMainVersion>=12 && Version.mcMainVersion<16){
|
if(Version.mcMainVersion>=12 && Version.mcMainVersion<16){
|
||||||
this.WorldProviderClass = Class.forName("net.minecraft.server."+version+".WorldProvider");
|
this.WorldProviderClass = Class.forName("net.minecraft.server."+version+".WorldProvider");
|
||||||
this.WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
//this.WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
||||||
}
|
}
|
||||||
this.CraftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
this.CraftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
||||||
this.CraftMetaItemClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaItem");
|
this.CraftMetaItemClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaItem");
|
||||||
@@ -110,26 +106,6 @@ public class NMSUtil {
|
|||||||
}catch(ReflectiveOperationException e){
|
}catch(ReflectiveOperationException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
switch (version) {
|
|
||||||
case "v1_12_R1" : {
|
|
||||||
getEDB_base = "t";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "v1_13_R1" :
|
|
||||||
case "v1_13_R2" : {
|
|
||||||
getEDB_base = "r";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "v1_14_R1" : {
|
|
||||||
getEDB_base = "q";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "v1_15_R1" : {
|
|
||||||
getEDB_base = "o";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default : getEDB_base = null;
|
|
||||||
}
|
|
||||||
if(Config.debug) check();
|
if(Config.debug) check();
|
||||||
}
|
}
|
||||||
public void check(){
|
public void check(){
|
||||||
@@ -329,27 +305,7 @@ public class NMSUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Object getEnderDragonBattle(final World world){
|
|
||||||
String version = Version.getVersion();
|
|
||||||
if (Version.mcMainVersion>=12 && Version.mcMainVersion<16) {
|
|
||||||
try {
|
|
||||||
Object worldServer = getInstance().getNMSManager().getWorldServer(world);
|
|
||||||
assert worldServer != null;
|
|
||||||
Field field = worldServer.getClass().getField("worldProvider");
|
|
||||||
Object worldProvider = field.get(worldServer);
|
|
||||||
Object WorldProviderTheEnd = WorldProviderTheEndClass.cast(worldProvider);
|
|
||||||
String method_name = getInstance().getNMSManager().getEDB_base;
|
|
||||||
if(method_name == null) return null;
|
|
||||||
Method method = WorldProviderTheEnd.getClass().getDeclaredMethod(method_name);
|
|
||||||
return method.invoke(WorldProviderTheEnd);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
Lang.warn("Your server version (" + version + ") is not supported!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Lang.warn("Your server version (" + version + ") is not supported!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public Object getWorldServer(final World ThisWorld) {
|
public Object getWorldServer(final World ThisWorld) {
|
||||||
try {
|
try {
|
||||||
Object castClass = getCraftWorld(ThisWorld);
|
Object castClass = getCraftWorld(ThisWorld);
|
||||||
|
|||||||
Reference in New Issue
Block a user