diff --git a/src/de/steamwar/spectatesystem/elements/RArrow.java b/src/de/steamwar/spectatesystem/elements/RArrow.java new file mode 100644 index 0000000..2d07b93 --- /dev/null +++ b/src/de/steamwar/spectatesystem/elements/RArrow.java @@ -0,0 +1,19 @@ +package de.steamwar.spectatesystem.elements; + +import net.minecraft.server.v1_15_R1.*; + +public class RArrow extends REntity { + + public RArrow(int internalId) { + super(internalId, createArrow()); + } + + @Override + protected void spawnEntity(PlayerConnection connection) { + connection.sendPacket(new PacketPlayOutSpawnEntity(entity)); + } + + private static EntityTippedArrow createArrow() { + return new EntityTippedArrow(world, 0, 0, 0); + } +} diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index 0b7ad86..8d0e879 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -2,6 +2,7 @@ package de.steamwar.spectatesystem.elements; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -10,6 +11,8 @@ import java.util.Map; public abstract class REntity { + protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); + private static Map entities = new HashMap<>(); private final int internalId; diff --git a/src/de/steamwar/spectatesystem/elements/RPlayer.java b/src/de/steamwar/spectatesystem/elements/RPlayer.java index 4a8cdef..8457257 100644 --- a/src/de/steamwar/spectatesystem/elements/RPlayer.java +++ b/src/de/steamwar/spectatesystem/elements/RPlayer.java @@ -5,7 +5,6 @@ import com.mojang.authlib.properties.Property; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.enchantments.CraftEnchantment; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -41,7 +40,6 @@ public class RPlayer extends REntity { private static EntityPlayer createPlayer(UUID uuid, String name){ MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); - WorldServer nmsWorld = ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle(); // Change "world" to the world the NPC should be spawned in. GameProfile gameProfile = new GameProfile(uuid, name); // Change "playername" to the name the NPC should have, max 16 characters. try { HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format("https://api.ashcon.app/mojang/v2/user/%s", name)).openConnection(); @@ -64,7 +62,7 @@ public class RPlayer extends REntity { Bukkit.getLogger().log(Level.SEVERE, "Player skin could not be fetched"); } - EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld)); // This will be the EntityPlayer (NPC) we send with the sendNPCPacket method. + EntityPlayer npc = new EntityPlayer(nmsServer, world, gameProfile, new PlayerInteractManager(world)); // This will be the EntityPlayer (NPC) we send with the sendNPCPacket method. npc.getDataWatcher().set(new DataWatcherObject<>(15, DataWatcherRegistry.a), (byte)127); return npc; } diff --git a/src/de/steamwar/spectatesystem/elements/RTnT.java b/src/de/steamwar/spectatesystem/elements/RTnT.java index 61c5ae0..3c6756a 100644 --- a/src/de/steamwar/spectatesystem/elements/RTnT.java +++ b/src/de/steamwar/spectatesystem/elements/RTnT.java @@ -1,14 +1,11 @@ package de.steamwar.spectatesystem.elements; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import net.minecraft.server.v1_15_R1.EntityTNTPrimed; +import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; +import net.minecraft.server.v1_15_R1.PlayerConnection; public class RTnT extends REntity { - private static World world = null; - public RTnT(int internalId) { super(internalId, createTnT()); } @@ -19,10 +16,6 @@ public class RTnT extends REntity { } private static EntityTNTPrimed createTnT() { - if (world == null) { - MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); - world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); - } return new EntityTNTPrimed(world, 0, 0, 0, null); }