From 01178ef9dcb7e152a85bb13a4d76c49ed87c78db Mon Sep 17 00:00:00 2001 From: NucWin Date: Thu, 26 Mar 2015 22:43:25 +0000 Subject: [PATCH] Added 1.8.3 Support; --- .../mgmobescape/IArena.java | 8 + .../comze_instancelabs/mgmobescape/Main.java | 8 + .../mgmobescape/mobtools/Tools.java | 8 + .../mgmobescape/v1_8/_R2/MEDragon.java | 175 ++++++++++++++++++ .../mgmobescape/v1_8/_R2/MEWither.java | 162 ++++++++++++++++ .../mgmobescape/v1_8/_R2/V1_8_3Dragon.java | 163 ++++++++++++++++ .../mgmobescape/v1_8/_R2/V1_8_3Wither.java | 96 ++++++++++ 7 files changed, 620 insertions(+) create mode 100644 src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEDragon.java create mode 100644 src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEWither.java create mode 100644 src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Dragon.java create mode 100644 src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Wither.java diff --git a/src/com/comze_instancelabs/mgmobescape/IArena.java b/src/com/comze_instancelabs/mgmobescape/IArena.java index 234252e..c538e99 100644 --- a/src/com/comze_instancelabs/mgmobescape/IArena.java +++ b/src/com/comze_instancelabs/mgmobescape/IArena.java @@ -19,6 +19,8 @@ import com.comze_instancelabs.mgmobescape.v1_7._R4.V1_7_10Wither; import com.comze_instancelabs.mgmobescape.v1_8._R1.V1_8Dragon; import com.comze_instancelabs.mgmobescape.v1_8._R1.V1_8Wither; +import com.comze_instancelabs.mgmobescape.v1_8._R2.V1_8_3Dragon; +import com.comze_instancelabs.mgmobescape.v1_8._R2.V1_8_3Wither; import com.comze_instancelabs.minigamesapi.Arena; import com.comze_instancelabs.minigamesapi.ArenaType; import com.comze_instancelabs.minigamesapi.MinigamesAPI; @@ -83,6 +85,9 @@ public void started() { } else if (m.mode1_8) { ad = new V1_8Dragon(); setDragon(V1_8Dragon.spawnEnderdragon(m, arena, a.getDragonSpawn())); + } else if (m.mode1_8_3) { + ad = new V1_8_3Dragon(); + setDragon(V1_8_3Dragon.spawnEnderdragon(m, arena, a.getDragonSpawn())); } else { ad = new V1_7Dragon(); setDragon(V1_7Dragon.spawnEnderdragon(m, arena, a.getDragonSpawn())); @@ -103,6 +108,9 @@ public void started() { } else if (m.mode1_8) { aw = new V1_8Wither(); setWither(V1_8Wither.spawnWither(m, arena, a.getDragonSpawn())); + } else if (m.mode1_8_3) { + aw = new V1_8_3Wither(); + setWither(V1_8_3Wither.spawnWither(m, arena, a.getDragonSpawn())); } else { aw = new V1_7Wither(); setWither(V1_7Wither.spawnWither(m, arena, a.getDragonSpawn())); diff --git a/src/com/comze_instancelabs/mgmobescape/Main.java b/src/com/comze_instancelabs/mgmobescape/Main.java index a9f071d..6d618e7 100644 --- a/src/com/comze_instancelabs/mgmobescape/Main.java +++ b/src/com/comze_instancelabs/mgmobescape/Main.java @@ -38,6 +38,7 @@ import com.comze_instancelabs.mgmobescape.v1_7._R3.V1_7_8Dragon; import com.comze_instancelabs.mgmobescape.v1_7._R4.V1_7_10Dragon; import com.comze_instancelabs.mgmobescape.v1_8._R1.V1_8Dragon; +import com.comze_instancelabs.mgmobescape.v1_8._R2.V1_8_3Dragon; import com.comze_instancelabs.minigamesapi.Arena; import com.comze_instancelabs.minigamesapi.ArenaSetup; import com.comze_instancelabs.minigamesapi.ArenaState; @@ -71,9 +72,11 @@ public class Main extends JavaPlugin implements Listener { public static boolean mode1_7_8 = false; public static boolean mode1_7_10 = false; public static boolean mode1_8 = false; + public static boolean mode1_8_3 = false; public HashMap ppoint = new HashMap(); public ArrayList p_used_kit = new ArrayList(); + public void onEnable() { cmdhandler = new ICommandHandler(); @@ -99,6 +102,9 @@ public void onEnable() { } else if (version.contains("1_8_R1")) { mode1_8 = true; getLogger().info("Turned on 1.8 mode."); + } else if (version.contains("1_8_R2")) { + mode1_8_3 = true; + getLogger().info("Turned on 1.8.3 mode."); } registerEntities(); @@ -165,6 +171,8 @@ private boolean registerEntities() { return V1_7_10Dragon.registerEntities(); } else if (mode1_8) { return V1_8Dragon.registerEntities(); + } else if (mode1_8_3) { + return V1_8_3Dragon.registerEntities(); } return V1_7Dragon.registerEntities(); } diff --git a/src/com/comze_instancelabs/mgmobescape/mobtools/Tools.java b/src/com/comze_instancelabs/mgmobescape/mobtools/Tools.java index 3224753..3dd2bad 100644 --- a/src/com/comze_instancelabs/mgmobescape/mobtools/Tools.java +++ b/src/com/comze_instancelabs/mgmobescape/mobtools/Tools.java @@ -27,6 +27,8 @@ import com.comze_instancelabs.mgmobescape.v1_7._R4.V1_7_10Wither; import com.comze_instancelabs.mgmobescape.v1_8._R1.V1_8Dragon; import com.comze_instancelabs.mgmobescape.v1_8._R1.V1_8Wither; +import com.comze_instancelabs.mgmobescape.v1_8._R2.V1_8_3Dragon; +import com.comze_instancelabs.mgmobescape.v1_8._R2.V1_8_3Wither; public class Tools { @@ -55,6 +57,9 @@ public void run() { } else if (m.mode1_8) { V1_8Dragon v = new V1_8Dragon(); v.removeEnderdragon(arena); + } else if (m.mode1_8_3) { + V1_8_3Dragon v = new V1_8_3Dragon(); + v.removeEnderdragon(arena); } else { V1_7Dragon v = new V1_7Dragon(); v.removeEnderdragon(arena); @@ -75,6 +80,9 @@ public void run() { } else if (m.mode1_8) { V1_8Wither v = new V1_8Wither(); v.removeWither(arena); + } else if (m.mode1_8_3) { + V1_8_3Wither v = new V1_8_3Wither(); + v.removeWither(arena); } else { V1_7Wither v = new V1_7Wither(); v.removeWither(arena); diff --git a/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEDragon.java b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEDragon.java new file mode 100644 index 0000000..a38599e --- /dev/null +++ b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEDragon.java @@ -0,0 +1,175 @@ +package com.comze_instancelabs.mgmobescape.v1_8._R2; + +import java.util.ArrayList; + +import net.minecraft.server.v1_8_R2.DamageSource; +import net.minecraft.server.v1_8_R2.EntityComplexPart; +import net.minecraft.server.v1_8_R2.EntityEnderDragon; +import net.minecraft.server.v1_8_R2.World; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import com.comze_instancelabs.mgmobescape.AbstractMEDragon; +import com.comze_instancelabs.mgmobescape.IArena; +import com.comze_instancelabs.mgmobescape.Main; +import com.comze_instancelabs.mgmobescape.mobtools.Tools; +import com.comze_instancelabs.minigamesapi.MinigamesAPI; + +public class MEDragon extends EntityEnderDragon implements AbstractMEDragon { + + private boolean onGround = false; + private ArrayList points = new ArrayList(); + private int currentid; + private double X; + private double Y; + private double Z; + private Main m; + private IArena arena; + + public MEDragon(Main m, String arena, Location loc, World world, ArrayList p) { + super(world); + this.m = m; + this.arena = (IArena) MinigamesAPI.getAPI().pinstances.get(m).getArenaByName(arena); + currentid = 0; + this.points = p; + setPosition(loc.getX(), loc.getY(), loc.getZ()); + yaw = loc.getYaw() + 180; + while (yaw > 360) { + yaw -= 360; + } + while (yaw < 0) { + yaw += 360; + } + if (yaw < 45 || yaw > 315) { + yaw = 0F; + } else if (yaw < 135) { + yaw = 90F; + } else if (yaw < 225) { + yaw = 180F; + } else { + yaw = 270F; + } + + double disX = (this.locX - points.get(currentid).getX()); + double disY = (this.locY - points.get(currentid).getY()); + double disZ = (this.locZ - points.get(currentid).getZ()); + + double tick = Math.sqrt(disX * disX + disY * disY + disZ * disZ) * 2 / m.mob_speed * Math.pow(0.98, currentid); + + this.X = (Math.abs(disX) / tick); + this.Y = (Math.abs(disY) / tick); + this.Z = (Math.abs(disZ) / tick); + } + + @Override + public void m() { + return; + } + + public boolean damageEntity(DamageSource damagesource, int i) { + return false; + } + + @Override + public int getExpReward() { + return 0; + } + + public boolean a(EntityComplexPart entitycomplexpart, DamageSource damagesource, int i) { + return false; + } + + public Vector getCurrentPosition() { + return points.get(currentid); + } + + public Vector getCurrentPositionNext() { + if (currentid + 1 < points.size() - 1) { + return points.get(currentid + 1); + } + return points.get(currentid); + } + + public Vector getNextPosition() { + + double tempx = this.locX; + double tempy = this.locY; + double tempz = this.locZ; + + if (((Math.abs((int) tempx - points.get(currentid).getX()) <= 1) && (Math.abs((int) tempz - points.get(currentid).getZ()) <= 3) && (Math.abs((int) tempy - points.get(currentid).getY()) <= 5)) || ((Math.abs((int) tempz - points.get(currentid).getZ()) <= 0) && (Math.abs((int) tempx - points.get(currentid).getX()) <= 3) && (Math.abs((int) tempy - points.get(currentid).getY()) <= 5))) { + if (currentid < points.size() - 1) { + currentid += 1; + } else { + // finish + arena.stop(); + } + + ArrayList temp = arena.getAllPlayers(); + for (String p : temp) { + if (m.ppoint.containsKey(p)) { + System.out.println("p:" + m.ppoint.get(p) + " d:" + currentid); + if (m.ppoint.get(p) < currentid - 1) { + // player fell behind mob + arena.spectate(p); + } + } + } + + double disX = (this.locX - points.get(currentid).getX()); + double disY = (this.locY - points.get(currentid).getY()); + double disZ = (this.locZ - points.get(currentid).getZ()); + + double tick_ = Math.sqrt(disX * disX + disY * disY + disZ * disZ) * 2 / m.mob_speed * Math.pow(0.98, currentid); + + this.X = (Math.abs(disX) / tick_); + this.Y = (Math.abs(disY) / tick_); + this.Z = (Math.abs(disZ) / tick_); + + Tools.setYawPitchDragon(arena.getDragon(), new Vector(this.locX, this.locY, this.locZ), points.get(currentid)); + + } + + Tools.setYawPitchDragon(arena.getDragon(), new Vector(this.locX, this.locY, this.locZ), points.get(currentid)); + + if (tempx < points.get(currentid).getX()) + tempx += this.X; + else { + tempx -= this.X; + } + + if ((int) tempy < points.get(currentid).getY()) { + tempy += this.Y; + } else { + tempy -= this.Y; + } + + if (tempz < points.get(currentid).getZ()) + tempz += this.Z; + else { + tempz -= this.Z; + } + + return new Vector(tempx, tempy, tempz); + } + + @Override + public void setYawPitch(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; + } + + /* + * public void setYawPitch(Vector l) { double dx = l.getX() - this.locX; double dy = l.getY() - this.locY; double dz = l.getZ() - this.locZ; + * + * if (dx != 0) { if (dx < 0) { this.yaw = (float) (1.5 * Math.PI); } else { this.yaw = (float) (0.5 * Math.PI); } this.yaw = (float) this.yaw - + * (float) Math.atan(dz / dx); } else if (dz < 0) { this.yaw = (float) Math.PI; } + * + * double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2)); + * + * pitch = (float) -Math.atan(dy / dxz); + * + * this.yaw = -yaw * 180F / (float) Math.PI - 180F; this.pitch = pitch * 180F / (float) Math.PI - 180F; } + */ + +} \ No newline at end of file diff --git a/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEWither.java b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEWither.java new file mode 100644 index 0000000..fff75b7 --- /dev/null +++ b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/MEWither.java @@ -0,0 +1,162 @@ +package com.comze_instancelabs.mgmobescape.v1_8._R2; + +import java.util.ArrayList; + +import net.minecraft.server.v1_8_R2.DamageSource; +import net.minecraft.server.v1_8_R2.EntityComplexPart; +import net.minecraft.server.v1_8_R2.EntityWither; +import net.minecraft.server.v1_8_R2.World; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import com.comze_instancelabs.mgmobescape.AbstractMEWither; +import com.comze_instancelabs.mgmobescape.IArena; +import com.comze_instancelabs.mgmobescape.Main; +import com.comze_instancelabs.mgmobescape.mobtools.Tools; +import com.comze_instancelabs.minigamesapi.MinigamesAPI; + +public class MEWither extends EntityWither implements AbstractMEWither { + + private boolean onGround = false; + private ArrayList points = new ArrayList(); + private int currentid; + private double X; + private double Y; + private double Z; + private Main m; + private IArena arena; + + public MEWither(Main m, String arena, Location loc, World world, ArrayList p) { + super(world); + this.m = m; + this.arena = (IArena) MinigamesAPI.getAPI().pinstances.get(m).getArenaByName(arena); + currentid = 0; + this.points = p; + setPosition(loc.getX(), loc.getY(), loc.getZ()); + yaw = loc.getYaw() + 180; + while (yaw > 360) { + yaw -= 360; + } + while (yaw < 0) { + yaw += 360; + } + if (yaw < 45 || yaw > 315) { + yaw = 0F; + } else if (yaw < 135) { + yaw = 90F; + } else if (yaw < 225) { + yaw = 180F; + } else { + yaw = 270F; + } + + double disX = (this.locX - points.get(currentid).getX()); + double disY = (this.locY - points.get(currentid).getY()); + double disZ = (this.locZ - points.get(currentid).getZ()); + + double tick = Math.sqrt(disX * disX + disY * disY + disZ * disZ) * 2 / m.mob_speed * Math.pow(0.98, currentid); + + this.X = (Math.abs(disX) / tick); + this.Y = (Math.abs(disY) / tick); + this.Z = (Math.abs(disZ) / tick); + } + + @Override + public void m() { + return; + } + + public boolean damageEntity(DamageSource damagesource, int i) { + return false; + } + + @Override + public int getExpReward() { + return 0; + } + + public boolean a(EntityComplexPart entitycomplexpart, DamageSource damagesource, int i) { + return false; + } + + public Vector getCurrentPosition() { + return points.get(currentid); + } + + public Vector getCurrentPositionNext() { + if (currentid + 1 < points.size() - 1) { + return points.get(currentid + 1); + } + return points.get(currentid); + } + + public Vector getNextPosition() { + + double tempx = this.locX; + double tempy = this.locY; + double tempz = this.locZ; + + if (((Math.abs((int) tempx - points.get(currentid).getX()) <= 1) && (Math.abs((int) tempz - points.get(currentid).getZ()) <= 3) && (Math.abs((int) tempy - points.get(currentid).getY()) <= 5)) || ((Math.abs((int) tempz - points.get(currentid).getZ()) <= 0) && (Math.abs((int) tempx - points.get(currentid).getX()) <= 3) && (Math.abs((int) tempy - points.get(currentid).getY()) <= 5))) { + if (currentid < points.size() - 1) { + currentid += 1; + } else { + // finish + arena.stop(); + } + + ArrayList temp = arena.getAllPlayers(); + for (String p : temp) { + if (m.ppoint.containsKey(p)) { + System.out.println("p:" + m.ppoint.get(p) + " d:" + currentid); + if (m.ppoint.get(p) < currentid - 1) { + // player fell behind mob + arena.spectate(p); + } + } + } + + double disX = (this.locX - points.get(currentid).getX()); + double disY = (this.locY - points.get(currentid).getY()); + double disZ = (this.locZ - points.get(currentid).getZ()); + + double tick_ = Math.sqrt(disX * disX + disY * disY + disZ * disZ) * 2 / m.mob_speed * Math.pow(0.98, currentid); + + this.X = (Math.abs(disX) / tick_); + this.Y = (Math.abs(disY) / tick_); + this.Z = (Math.abs(disZ) / tick_); + + Tools.setYawPitchWither(arena.getWither(), new Vector(this.locX, this.locY, this.locZ), points.get(currentid)); + + } + + Tools.setYawPitchWither(arena.getWither(), new Vector(this.locX, this.locY, this.locZ), points.get(currentid)); + + if (tempx < points.get(currentid).getX()) + tempx += this.X; + else { + tempx -= this.X; + } + + if ((int) tempy < points.get(currentid).getY()) { + tempy += this.Y; + } else { + tempy -= this.Y; + } + + if (tempz < points.get(currentid).getZ()) + tempz += this.Z; + else { + tempz -= this.Z; + } + + return new Vector(tempx, tempy, tempz); + } + + @Override + public void setYawPitch(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; + } + +} \ No newline at end of file diff --git a/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Dragon.java b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Dragon.java new file mode 100644 index 0000000..03c91b2 --- /dev/null +++ b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Dragon.java @@ -0,0 +1,163 @@ +package com.comze_instancelabs.mgmobescape.v1_8._R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; + +import net.minecraft.server.v1_8_R2.BlockPosition; +import net.minecraft.server.v1_8_R2.EntityTypes; +import net.minecraft.server.v1_8_R2.PacketPlayOutWorldEvent; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; + +import com.comze_instancelabs.mgmobescape.AbstractDragon; +import com.comze_instancelabs.mgmobescape.IArena; +import com.comze_instancelabs.mgmobescape.Main; +import com.comze_instancelabs.mgmobescape.mobtools.Tools; +import com.comze_instancelabs.minigamesapi.MinigamesAPI; + +public class V1_8_3Dragon implements AbstractDragon { + + public static HashMap dragons = new HashMap(); + + public static boolean registerEntities() { + try { + Class entityTypeClass = EntityTypes.class; + + Field c = entityTypeClass.getDeclaredField("c"); + c.setAccessible(true); + HashMap c_map = (HashMap) c.get(null); + c_map.put("MEWither", MEWither.class); + + Field d = entityTypeClass.getDeclaredField("d"); + d.setAccessible(true); + HashMap d_map = (HashMap) d.get(null); + d_map.put(MEWither.class, "MEWither"); + + Field e = entityTypeClass.getDeclaredField("e"); + e.setAccessible(true); + HashMap e_map = (HashMap) e.get(null); + e_map.put(Integer.valueOf(64), MEWither.class); + + Field f = entityTypeClass.getDeclaredField("f"); + f.setAccessible(true); + HashMap f_map = (HashMap) f.get(null); + f_map.put(MEWither.class, Integer.valueOf(64)); + + Field g = entityTypeClass.getDeclaredField("g"); + g.setAccessible(true); + HashMap g_map = (HashMap) g.get(null); + g_map.put("MEWither", Integer.valueOf(64)); + } catch (Exception ex) { + ex.printStackTrace(); + return false; + } + + try { + Class entityTypeClass = EntityTypes.class; + + Field c = entityTypeClass.getDeclaredField("c"); + c.setAccessible(true); + HashMap c_map = (HashMap) c.get(null); + c_map.put("MEDragon", MEDragon.class); + + Field d = entityTypeClass.getDeclaredField("d"); + d.setAccessible(true); + HashMap d_map = (HashMap) d.get(null); + d_map.put(MEDragon.class, "MEDragon"); + + Field e = entityTypeClass.getDeclaredField("e"); + e.setAccessible(true); + HashMap e_map = (HashMap) e.get(null); + e_map.put(Integer.valueOf(63), MEDragon.class); + + Field f = entityTypeClass.getDeclaredField("f"); + f.setAccessible(true); + HashMap f_map = (HashMap) f.get(null); + f_map.put(MEDragon.class, Integer.valueOf(63)); + + Field g = entityTypeClass.getDeclaredField("g"); + g.setAccessible(true); + HashMap g_map = (HashMap) g.get(null); + g_map.put("MEDragon", Integer.valueOf(63)); + + return true; + } catch (Exception ex) { + ex.printStackTrace(); + return false; + } + } + + public void playBlockBreakParticles(final Location loc, final Material m, final Player... players) { + @SuppressWarnings("deprecation") + PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(2001, new BlockPosition(loc.getX(), loc.getY(), loc.getZ()), m.getId(), false); + for (final Player p : players) { + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + } + } + + public static MEDragon spawnEnderdragon(Main m, String arena, Location t) { + m.getLogger().info("DRAGON SPAWNED " + arena + " " + t.toString()); + Object w = ((CraftWorld) t.getWorld()).getHandle(); + ArrayList temp = ((IArena) MinigamesAPI.getAPI().pinstances.get(m).getArenaByName(arena)).getDragonWayPoints(arena); + if (temp == null) { + m.getLogger().severe("You forgot to set any FlyPoints! You need to have min. 2 and one of them has to be at finish."); + return null; + } + MEDragon t_ = new MEDragon(m, arena, t, (net.minecraft.server.v1_8_R2.World) ((CraftWorld) t.getWorld()).getHandle(), temp); + ((net.minecraft.server.v1_8_R2.World) w).addEntity(t_, CreatureSpawnEvent.SpawnReason.CUSTOM); + System.out.println(((net.minecraft.server.v1_8_R2.World) w).entityList.contains(t_)); + t_.setCustomName(m.dragon_name); + dragons.put(arena, t_); + return t_; + } + + public void removeEnderdragon(String arena) { + try { + removeEnderdragon(dragons.get(arena)); + dragons.put(arena, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stop(final Main m, BukkitTask t, final String arena) { + if (t != null) { + t.cancel(); + } + removeEnderdragon(dragons.get(arena)); + } + + public void removeEnderdragon(MEDragon t) { + if (t != null) { + t.getBukkitEntity().remove(); + } + } + + public Block[] getLoc(Main m, final Location l, String arena, int i, int j, Location l2) { + Block[] b = new Block[4]; + b[0] = l.getWorld().getBlockAt(new Location(l.getWorld(), dragons.get(arena).locX + (m.destroy_radius / 2) - i, dragons.get(arena).locY + j - 1, dragons.get(arena).locZ + 3)); + b[1] = l.getWorld().getBlockAt(new Location(l.getWorld(), dragons.get(arena).locX + (m.destroy_radius / 2) - i, dragons.get(arena).locY + j - 1, dragons.get(arena).locZ - 3)); + b[2] = l.getWorld().getBlockAt(new Location(l.getWorld(), dragons.get(arena).locX + 3, dragons.get(arena).locY + j - 1, dragons.get(arena).locZ + (m.destroy_radius / 2) - i)); + b[3] = l.getWorld().getBlockAt(new Location(l.getWorld(), dragons.get(arena).locX - 3, dragons.get(arena).locY + j - 1, dragons.get(arena).locZ + (m.destroy_radius / 2) - i)); + + return b; + } + + public static void destroyStatic(final Main m, final Location l, final Location l2, String arena, int length2) { + Tools.destroy(m, l, l2, arena, length2, "dragon", false, true); + } + + public void destroy(final Main m, final Location l, final Location l2, String arena, int length2) { + Tools.destroy(m, l, l2, arena, length2, "dragon", false, true); + } + +} diff --git a/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Wither.java b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Wither.java new file mode 100644 index 0000000..1106485 --- /dev/null +++ b/src/com/comze_instancelabs/mgmobescape/v1_8/_R2/V1_8_3Wither.java @@ -0,0 +1,96 @@ +package com.comze_instancelabs.mgmobescape.v1_8._R2; + +import java.util.ArrayList; +import java.util.HashMap; + +import net.minecraft.server.v1_8_R2.BlockPosition; +import net.minecraft.server.v1_8_R2.PacketPlayOutWorldEvent; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; + +import com.comze_instancelabs.mgmobescape.AbstractWither; +import com.comze_instancelabs.mgmobescape.IArena; +import com.comze_instancelabs.mgmobescape.Main; +import com.comze_instancelabs.mgmobescape.mobtools.Tools; +import com.comze_instancelabs.minigamesapi.MinigamesAPI; + +public class V1_8_3Wither implements AbstractWither { + + public static HashMap wither = new HashMap(); + + public void playBlockBreakParticles(final Location loc, final Material m, final Player... players) { + @SuppressWarnings("deprecation") + PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(2001, new BlockPosition(loc.getX(), loc.getY(), loc.getZ()), m.getId(), false); + for (final Player p : players) { + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + } + } + + public static MEWither spawnWither(Main m, String arena, Location t) { + /* + * if(dragons.containsKey(arena)){ return wither.get(arena); } + */ + m.getLogger().info("WITHER SPAWNED " + arena + " " + t.toString()); + Object w = ((CraftWorld) t.getWorld()).getHandle(); + ArrayList temp = ((IArena) MinigamesAPI.getAPI().pinstances.get(m).getArenaByName(arena)).getDragonWayPoints(arena); + if (temp == null) { + m.getLogger().severe("You forgot to set any FlyPoints! You need to have min. 2 and one of them has to be at finish."); + return null; + } + MEWither t_ = new MEWither(m, arena, t, (net.minecraft.server.v1_8_R2.World) ((CraftWorld) t.getWorld()).getHandle(), temp); + ((net.minecraft.server.v1_8_R2.World) w).addEntity(t_, CreatureSpawnEvent.SpawnReason.CUSTOM); + t_.setCustomName(m.dragon_name); + wither.put(arena, t_); + t_.move(0.1D, 0.1D, 0.1D); + return t_; + } + + public void removeWither(String arena) { + try { + removeWither(wither.get(arena)); + wither.put(arena, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Block[] getLoc(Main m, final Location l, String arena, int i, int j, Location l2) { + Block[] b = new Block[4]; + b[0] = l.getWorld().getBlockAt(new Location(l.getWorld(), wither.get(arena).locX + (m.destroy_radius / 2) - i, wither.get(arena).locY + j - 1, wither.get(arena).locZ + 3)); + b[1] = l.getWorld().getBlockAt(new Location(l.getWorld(), wither.get(arena).locX + (m.destroy_radius / 2) - i, wither.get(arena).locY + j - 1, wither.get(arena).locZ - 3)); + b[2] = l.getWorld().getBlockAt(new Location(l.getWorld(), wither.get(arena).locX + 3, wither.get(arena).locY + j - 1, wither.get(arena).locZ + (m.destroy_radius / 2) - i)); + b[3] = l.getWorld().getBlockAt(new Location(l.getWorld(), wither.get(arena).locX - 3, wither.get(arena).locY + j - 1, wither.get(arena).locZ + (m.destroy_radius / 2) - i)); + + return b; + } + + public void stop(final Main m, BukkitTask t, final String arena) { + if (t != null) { + t.cancel(); + } + removeWither(wither.get(arena)); + } + + public void removeWither(MEWither t) { + if (t != null) { + t.getBukkitEntity().remove(); + } + } + + public static void destroyStatic(final Main m, final Location l, final Location l2, String arena, int length2) { + Tools.destroy(m, l, l2, arena, length2, "wither", false, true); + } + + public void destroy(final Main m, final Location l, final Location l2, String arena, int length2) { + Tools.destroy(m, l, l2, arena, length2, "wither", false, true); + } + +}