Dropped support for unused versions

This commit is contained in:
OmerBenGera 2021-10-15 17:56:52 +03:00
parent 96856729a7
commit cebeae9690
47 changed files with 0 additions and 7182 deletions

View File

@ -1,7 +0,0 @@
group 'v1_10_R1'
dependencies {
compileOnly "org.spigotmc:v1_10_R1:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_10_R1.DamageSource;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.EnumGamemode;
import net.minecraft.server.v1_10_R1.EnumProtocolDirection;
import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.NetworkManager;
import net.minecraft.server.v1_10_R1.Packet;
import net.minecraft.server.v1_10_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_10_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_10_R1.PacketPlayInChat;
import net.minecraft.server.v1_10_R1.PacketPlayInFlying;
import net.minecraft.server.v1_10_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_10_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_10_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_10_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_10_R1.PlayerConnection;
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import net.minecraft.server.v1_10_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_10_R1 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_10_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,173 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.DamageSource;
import net.minecraft.server.v1_10_R1.EntityArmorStand;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.EnumHand;
import net.minecraft.server.v1_10_R1.EnumInteractionResult;
import net.minecraft.server.v1_10_R1.EnumItemSlot;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.SoundEffect;
import net.minecraft.server.v1_10_R1.Vec3D;
import net.minecraft.server.v1_10_R1.World;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_10_R1 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_10_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void m() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,289 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.Chunk;
import net.minecraft.server.v1_10_R1.ITickable;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.NBTTagList;
import net.minecraft.server.v1_10_R1.NBTTagLong;
import net.minecraft.server.v1_10_R1.NBTTagString;
import net.minecraft.server.v1_10_R1.TileEntity;
import net.minecraft.server.v1_10_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_10_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_10_R1.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings({"ConstantConditions", "unused"})
public final class NMSAdapter_v1_10_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_10_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
tileEntity.a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_10_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_10_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount = 0, minutesAmount = 0, secondsAmount = 0;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
setPosition(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_10_R1 hologram = new EntityHolograms_v1_10_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void E_() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_10_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed && daysAmount != -1) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_10_R1 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_11_R1'
dependencies {
compileOnly "org.spigotmc:v1_11_R1:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_11_R1.DamageSource;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.EnumGamemode;
import net.minecraft.server.v1_11_R1.EnumProtocolDirection;
import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.NetworkManager;
import net.minecraft.server.v1_11_R1.Packet;
import net.minecraft.server.v1_11_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_11_R1.PacketPlayInChat;
import net.minecraft.server.v1_11_R1.PacketPlayInFlying;
import net.minecraft.server.v1_11_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_11_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_11_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_11_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_11_R1.PlayerConnection;
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import net.minecraft.server.v1_11_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_11_R1 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_11_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,173 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.DamageSource;
import net.minecraft.server.v1_11_R1.EntityArmorStand;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.EnumHand;
import net.minecraft.server.v1_11_R1.EnumInteractionResult;
import net.minecraft.server.v1_11_R1.EnumItemSlot;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.SoundEffect;
import net.minecraft.server.v1_11_R1.Vec3D;
import net.minecraft.server.v1_11_R1.World;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_11_R1 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_11_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void A_() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,289 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.Chunk;
import net.minecraft.server.v1_11_R1.ITickable;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.NBTTagList;
import net.minecraft.server.v1_11_R1.NBTTagLong;
import net.minecraft.server.v1_11_R1.NBTTagString;
import net.minecraft.server.v1_11_R1.TileEntity;
import net.minecraft.server.v1_11_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_11_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_11_R1.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings({"ConstantConditions", "unused"})
public final class NMSAdapter_v1_11_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_11_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
tileEntity.a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_11_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_11_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
setPosition(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_11_R1 hologram = new EntityHolograms_v1_11_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void F_() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_11_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_11_R1 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_13_R1'
dependencies {
compileOnly "org.spigotmc:v1_13_R1:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,148 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_13_R1.DamageSource;
import net.minecraft.server.v1_13_R1.EntityPlayer;
import net.minecraft.server.v1_13_R1.EnumGamemode;
import net.minecraft.server.v1_13_R1.EnumProtocolDirection;
import net.minecraft.server.v1_13_R1.MinecraftServer;
import net.minecraft.server.v1_13_R1.NetworkManager;
import net.minecraft.server.v1_13_R1.Packet;
import net.minecraft.server.v1_13_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_13_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_13_R1.PacketPlayInChat;
import net.minecraft.server.v1_13_R1.PacketPlayInFlying;
import net.minecraft.server.v1_13_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_13_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_13_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_13_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_13_R1.PlayerConnection;
import net.minecraft.server.v1_13_R1.PlayerInteractManager;
import net.minecraft.server.v1_13_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R1.CraftServer;
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_13_R1 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_13_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
MinecraftServer minecraftServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
playerConnection = new DummyPlayerConnection(minecraftServer, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fauxSleeping = true;
spawnIn(worldServer);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.players.add(this);
worldServer.getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,177 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
import net.minecraft.server.v1_13_R1.DamageSource;
import net.minecraft.server.v1_13_R1.EntityArmorStand;
import net.minecraft.server.v1_13_R1.EntityHuman;
import net.minecraft.server.v1_13_R1.EnumHand;
import net.minecraft.server.v1_13_R1.EnumInteractionResult;
import net.minecraft.server.v1_13_R1.EnumItemSlot;
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
import net.minecraft.server.v1_13_R1.ItemStack;
import net.minecraft.server.v1_13_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R1.SoundEffect;
import net.minecraft.server.v1_13_R1.Vec3D;
import net.minecraft.server.v1_13_R1.World;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_13_R1 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_13_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(CraftChatMessage.fromString(name)[0]);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void tick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(@Nullable IChatBaseComponent ichatbasecomponent) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean flag) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,284 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_13_R1.Block;
import net.minecraft.server.v1_13_R1.BlockPosition;
import net.minecraft.server.v1_13_R1.Chunk;
import net.minecraft.server.v1_13_R1.ITickable;
import net.minecraft.server.v1_13_R1.ItemStack;
import net.minecraft.server.v1_13_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R1.NBTTagList;
import net.minecraft.server.v1_13_R1.NBTTagLong;
import net.minecraft.server.v1_13_R1.NBTTagString;
import net.minecraft.server.v1_13_R1.TileEntity;
import net.minecraft.server.v1_13_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_13_R1.TileEntityTypes;
import net.minecraft.server.v1_13_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_13_R1.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_13_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.getOrCreateTag();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_13_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_13_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16);
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
if(mobSpawner == null)
return;
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_13_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
super(TileEntityTypes.w);
this.chunkLoader = (WChunkLoader) chunkLoader;
setPosition(blockPosition);
setWorld(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_13_R1 hologram = new EntityHolograms_v1_13_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void Y_() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_13_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_13_R1 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_13_R2'
dependencies {
compileOnly "org.spigotmc:v1_13_R2:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_13_R2.DamageSource;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.EnumGamemode;
import net.minecraft.server.v1_13_R2.EnumProtocolDirection;
import net.minecraft.server.v1_13_R2.MinecraftServer;
import net.minecraft.server.v1_13_R2.NetworkManager;
import net.minecraft.server.v1_13_R2.Packet;
import net.minecraft.server.v1_13_R2.PacketPlayInBlockDig;
import net.minecraft.server.v1_13_R2.PacketPlayInBlockPlace;
import net.minecraft.server.v1_13_R2.PacketPlayInChat;
import net.minecraft.server.v1_13_R2.PacketPlayInFlying;
import net.minecraft.server.v1_13_R2.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_13_R2.PacketPlayInTransaction;
import net.minecraft.server.v1_13_R2.PacketPlayInUpdateSign;
import net.minecraft.server.v1_13_R2.PacketPlayInWindowClick;
import net.minecraft.server.v1_13_R2.PlayerConnection;
import net.minecraft.server.v1_13_R2.PlayerInteractManager;
import net.minecraft.server.v1_13_R2.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_13_R2 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_13_R2(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
clientViewDistance = 1;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,177 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
import net.minecraft.server.v1_13_R2.DamageSource;
import net.minecraft.server.v1_13_R2.EntityArmorStand;
import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EnumHand;
import net.minecraft.server.v1_13_R2.EnumInteractionResult;
import net.minecraft.server.v1_13_R2.EnumItemSlot;
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.SoundEffect;
import net.minecraft.server.v1_13_R2.Vec3D;
import net.minecraft.server.v1_13_R2.World;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_13_R2 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_13_R2(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(CraftChatMessage.fromString(name)[0]);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void tick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(@Nullable IChatBaseComponent ichatbasecomponent) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean flag) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,284 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_13_R2.Block;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.Chunk;
import net.minecraft.server.v1_13_R2.ITickable;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagList;
import net.minecraft.server.v1_13_R2.NBTTagLong;
import net.minecraft.server.v1_13_R2.NBTTagString;
import net.minecraft.server.v1_13_R2.TileEntity;
import net.minecraft.server.v1_13_R2.TileEntityMobSpawner;
import net.minecraft.server.v1_13_R2.TileEntityTypes;
import net.minecraft.server.v1_13_R2.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_13_R2.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_13_R2 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.getOrCreateTag();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_13_R2(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_13_R2::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16);
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
if(mobSpawner == null)
return;
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_13_R2> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
super(TileEntityTypes.COMMAND_BLOCK);
this.chunkLoader = (WChunkLoader) chunkLoader;
setPosition(blockPosition);
setWorld(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_13_R2 hologram = new EntityHolograms_v1_13_R2(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void tick() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_13_R2 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_13_R2 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_14_R1'
dependencies {
compileOnly "org.spigotmc:v1_14_R1-Paper:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.EnumGamemode;
import net.minecraft.server.v1_14_R1.EnumProtocolDirection;
import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.NetworkManager;
import net.minecraft.server.v1_14_R1.Packet;
import net.minecraft.server.v1_14_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_14_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_14_R1.PacketPlayInChat;
import net.minecraft.server.v1_14_R1.PacketPlayInFlying;
import net.minecraft.server.v1_14_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_14_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_14_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_14_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_14_R1.PlayerConnection;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_14_R1 extends EntityPlayer implements ChunkLoaderNPC {
private boolean dieCall = false;
public ChunkLoaderNPC_v1_14_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
clientViewDistance = 1;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
((WorldServer) world).addPlayerJoin(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
if(!dieCall) {
dieCall = true;
getWorldServer().removePlayer(this);
dieCall = false;
}
else {
super.die();
}
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,179 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
import net.minecraft.server.v1_14_R1.DamageSource;
import net.minecraft.server.v1_14_R1.EntityArmorStand;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EnumHand;
import net.minecraft.server.v1_14_R1.EnumInteractionResult;
import net.minecraft.server.v1_14_R1.EnumItemSlot;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.SoundEffect;
import net.minecraft.server.v1_14_R1.Vec3D;
import net.minecraft.server.v1_14_R1.World;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_14_R1 extends EntityArmorStand implements Hologram {
private CraftEntity bukkitEntity;
EntityHolograms_v1_14_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(CraftChatMessage.fromString(name)[0]);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void tick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(@Nullable IChatBaseComponent ichatbasecomponent) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean flag) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean a_(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (bukkitEntity == null) {
bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return bukkitEntity;
}
}

View File

@ -1,304 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_14_R1.ITickable;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.NBTTagList;
import net.minecraft.server.v1_14_R1.NBTTagLong;
import net.minecraft.server.v1_14_R1.NBTTagString;
import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_14_R1.TileEntityTypes;
import net.minecraft.server.v1_14_R1.World;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_14_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.getOrCreateTag();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_14_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true);
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_14_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false);
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
assert location.getWorld() != null;
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
if(mobSpawner == null)
return;
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_14_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
super(TileEntityTypes.COMMAND_BLOCK);
this.chunkLoader = (WChunkLoader) chunkLoader;
setPosition(blockPosition);
setWorld(world);
loaderBlock = world.getType(blockPosition).getBlock();
try {
// Not a method of Spigot - fixes https://github.com/OmerBenGera/WildLoaders/issues/2
setCurrentChunk(world.getChunkAtWorldCoords(blockPosition));
}catch (Throwable ignored){}
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_14_R1 hologram = new EntityHolograms_v1_14_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void r() {
tick();
}
@Override
public void tick() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
assert world != null;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_14_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_14_R1 hologram, String line){
assert chunkLoader.getWhoPlaced().getName() != null;
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_16_R1'
dependencies {
compileOnly "org.spigotmc:v1_16_R1-Paper:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_16_R1.EntityPlayer;
import net.minecraft.server.v1_16_R1.EnumGamemode;
import net.minecraft.server.v1_16_R1.EnumProtocolDirection;
import net.minecraft.server.v1_16_R1.MinecraftServer;
import net.minecraft.server.v1_16_R1.NetworkManager;
import net.minecraft.server.v1_16_R1.Packet;
import net.minecraft.server.v1_16_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_16_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_16_R1.PacketPlayInChat;
import net.minecraft.server.v1_16_R1.PacketPlayInFlying;
import net.minecraft.server.v1_16_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_16_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_16_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_16_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_16_R1.PlayerConnection;
import net.minecraft.server.v1_16_R1.PlayerInteractManager;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_16_R1 extends EntityPlayer implements ChunkLoaderNPC {
private boolean dieCall = false;
public ChunkLoaderNPC_v1_16_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
clientViewDistance = 1;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
((WorldServer) world).addPlayerJoin(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
if(!dieCall) {
dieCall = true;
getWorldServer().removePlayer(this);
dieCall = false;
}
else {
super.die();
}
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,179 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_16_R1.AxisAlignedBB;
import net.minecraft.server.v1_16_R1.DamageSource;
import net.minecraft.server.v1_16_R1.EntityArmorStand;
import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.EnumHand;
import net.minecraft.server.v1_16_R1.EnumInteractionResult;
import net.minecraft.server.v1_16_R1.EnumItemSlot;
import net.minecraft.server.v1_16_R1.IChatBaseComponent;
import net.minecraft.server.v1_16_R1.ItemStack;
import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.SoundEffect;
import net.minecraft.server.v1_16_R1.Vec3D;
import net.minecraft.server.v1_16_R1.World;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_16_R1.util.CraftChatMessage;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_16_R1 extends EntityArmorStand implements Hologram {
private CraftEntity bukkitEntity;
EntityHolograms_v1_16_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(CraftChatMessage.fromString(name)[0]);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void tick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void saveData(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean a_(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void load(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void loadData(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(@Nullable IChatBaseComponent ichatbasecomponent) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean flag) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean a_(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void playSound(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (bukkitEntity == null) {
bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return bukkitEntity;
}
}

View File

@ -1,305 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.Chunk;
import net.minecraft.server.v1_16_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.ITickable;
import net.minecraft.server.v1_16_R1.ItemStack;
import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.NBTTagList;
import net.minecraft.server.v1_16_R1.NBTTagLong;
import net.minecraft.server.v1_16_R1.NBTTagString;
import net.minecraft.server.v1_16_R1.TileEntity;
import net.minecraft.server.v1_16_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_16_R1.TileEntityTypes;
import net.minecraft.server.v1_16_R1.World;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_16_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, NBTTagString.a(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, NBTTagLong.a(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.getOrCreateTag();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_16_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true);
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_16_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false);
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
assert location.getWorld() != null;
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
IBlockData blockData = world.getType(blockPosition);
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
if(mobSpawner == null)
return;
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_16_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
super(TileEntityTypes.COMMAND_BLOCK);
this.chunkLoader = (WChunkLoader) chunkLoader;
setLocation(world, blockPosition);
loaderBlock = world.getType(blockPosition).getBlock();
try {
// Not a method of Spigot - fixes https://github.com/OmerBenGera/WildLoaders/issues/2
setCurrentChunk(world.getChunkAtWorldCoords(blockPosition));
}catch (Throwable ignored){}
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_16_R1 hologram = new EntityHolograms_v1_16_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void w() {
tick();
}
@Override
public void tick() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
assert world != null;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_16_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_16_R1 hologram, String line){
assert chunkLoader.getWhoPlaced().getName() != null;
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_16_R2'
dependencies {
compileOnly "org.spigotmc:v1_16_R2-Tuinity:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_16_R2.EntityPlayer;
import net.minecraft.server.v1_16_R2.EnumGamemode;
import net.minecraft.server.v1_16_R2.EnumProtocolDirection;
import net.minecraft.server.v1_16_R2.MinecraftServer;
import net.minecraft.server.v1_16_R2.NetworkManager;
import net.minecraft.server.v1_16_R2.Packet;
import net.minecraft.server.v1_16_R2.PacketPlayInBlockDig;
import net.minecraft.server.v1_16_R2.PacketPlayInBlockPlace;
import net.minecraft.server.v1_16_R2.PacketPlayInChat;
import net.minecraft.server.v1_16_R2.PacketPlayInFlying;
import net.minecraft.server.v1_16_R2.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_16_R2.PacketPlayInTransaction;
import net.minecraft.server.v1_16_R2.PacketPlayInUpdateSign;
import net.minecraft.server.v1_16_R2.PacketPlayInWindowClick;
import net.minecraft.server.v1_16_R2.PlayerConnection;
import net.minecraft.server.v1_16_R2.PlayerInteractManager;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_16_R2 extends EntityPlayer implements ChunkLoaderNPC {
private boolean dieCall = false;
public ChunkLoaderNPC_v1_16_R2(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
clientViewDistance = 1;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
((WorldServer) world).addPlayerJoin(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
if(!dieCall) {
dieCall = true;
getWorldServer().removePlayer(this);
dieCall = false;
}
else {
super.die();
}
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,179 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_16_R2.AxisAlignedBB;
import net.minecraft.server.v1_16_R2.DamageSource;
import net.minecraft.server.v1_16_R2.EntityArmorStand;
import net.minecraft.server.v1_16_R2.EntityHuman;
import net.minecraft.server.v1_16_R2.EnumHand;
import net.minecraft.server.v1_16_R2.EnumInteractionResult;
import net.minecraft.server.v1_16_R2.EnumItemSlot;
import net.minecraft.server.v1_16_R2.IChatBaseComponent;
import net.minecraft.server.v1_16_R2.ItemStack;
import net.minecraft.server.v1_16_R2.NBTTagCompound;
import net.minecraft.server.v1_16_R2.SoundEffect;
import net.minecraft.server.v1_16_R2.Vec3D;
import net.minecraft.server.v1_16_R2.World;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_16_R2.util.CraftChatMessage;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_16_R2 extends EntityArmorStand implements Hologram {
private CraftEntity bukkitEntity;
EntityHolograms_v1_16_R2(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setNoGravity(true);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(CraftChatMessage.fromString(name)[0]);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void tick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void saveData(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean a_(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void load(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void loadData(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(@Nullable IChatBaseComponent ichatbasecomponent) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean flag) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean a_(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void playSound(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (bukkitEntity == null) {
bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return bukkitEntity;
}
}

View File

@ -1,305 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_16_R2.Block;
import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.Chunk;
import net.minecraft.server.v1_16_R2.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.ITickable;
import net.minecraft.server.v1_16_R2.ItemStack;
import net.minecraft.server.v1_16_R2.NBTTagCompound;
import net.minecraft.server.v1_16_R2.NBTTagList;
import net.minecraft.server.v1_16_R2.NBTTagLong;
import net.minecraft.server.v1_16_R2.NBTTagString;
import net.minecraft.server.v1_16_R2.TileEntity;
import net.minecraft.server.v1_16_R2.TileEntityMobSpawner;
import net.minecraft.server.v1_16_R2.TileEntityTypes;
import net.minecraft.server.v1_16_R2.World;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_16_R2 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, NBTTagString.a(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.set(key, NBTTagLong.a(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.getOrCreateTag();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_16_R2(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true);
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_16_R2::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner)
.forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false);
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
assert location.getWorld() != null;
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
IBlockData blockData = world.getType(blockPosition);
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
if(mobSpawner == null)
return;
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_16_R2> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
super(TileEntityTypes.COMMAND_BLOCK);
this.chunkLoader = (WChunkLoader) chunkLoader;
setLocation(world, blockPosition);
loaderBlock = world.getType(blockPosition).getBlock();
try {
// Not a method of Spigot - fixes https://github.com/OmerBenGera/WildLoaders/issues/2
setCurrentChunk(world.getChunkAtWorldCoords(blockPosition));
}catch (Throwable ignored){}
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_16_R2 hologram = new EntityHolograms_v1_16_R2(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void w() {
tick();
}
@Override
public void tick() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
assert world != null;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_16_R2 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_16_R2 hologram, String line){
assert chunkLoader.getWhoPlaced().getName() != null;
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_7_R3'
dependencies {
compileOnly "org.spigotmc:v1_7_R3:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,148 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import net.minecraft.server.v1_7_R3.DamageSource;
import net.minecraft.server.v1_7_R3.EntityPlayer;
import net.minecraft.server.v1_7_R3.EnumGamemode;
import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.NetworkManager;
import net.minecraft.server.v1_7_R3.Packet;
import net.minecraft.server.v1_7_R3.PacketPlayInBlockDig;
import net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace;
import net.minecraft.server.v1_7_R3.PacketPlayInChat;
import net.minecraft.server.v1_7_R3.PacketPlayInFlying;
import net.minecraft.server.v1_7_R3.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_7_R3.PacketPlayInTransaction;
import net.minecraft.server.v1_7_R3.PacketPlayInUpdateSign;
import net.minecraft.server.v1_7_R3.PacketPlayInWindowClick;
import net.minecraft.server.v1_7_R3.PlayerConnection;
import net.minecraft.server.v1_7_R3.PlayerInteractManager;
import net.minecraft.server.v1_7_R3.WorldServer;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_7_R3 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_7_R3(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
//noinspection unchecked
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(false);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("m");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("n");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,227 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_7_R3.Block;
import net.minecraft.server.v1_7_R3.Chunk;
import net.minecraft.server.v1_7_R3.IUpdatePlayerListBox;
import net.minecraft.server.v1_7_R3.ItemStack;
import net.minecraft.server.v1_7_R3.NBTTagCompound;
import net.minecraft.server.v1_7_R3.NBTTagList;
import net.minecraft.server.v1_7_R3.NBTTagLong;
import net.minecraft.server.v1_7_R3.NBTTagString;
import net.minecraft.server.v1_7_R3.TileEntity;
import net.minecraft.server.v1_7_R3.TileEntityMobSpawner;
import net.minecraft.server.v1_7_R3.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_7_R3.util.LongHash;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_7_R3 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_7_R3(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, x, y, z);
//noinspection unchecked
world.tileEntityList.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()){
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
//noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
long tileEntityLong = LongHash.toLong(x >> 4, z >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.removed = true;
world.tileEntityList.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, x, y, z, Block.b(world.getType(x, y, z)) + (world.getData(x, y, z) << 12));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()){
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
//noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner)
world.getTileEntity(location.getBlockX(), location.getBlockY(), location.getBlockZ());
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader {
private static final Collection<Hologram> EMPTY_CONTAINER = Collections.emptyList();
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, int x, int y, int z){
this.chunkLoader = (WChunkLoader) chunkLoader;
this.x = x;
this.y = y;
this.z = z;
a(world);
loaderBlock = world.getType(x, y, z);
tileEntityChunkLoaderMap.put(LongHash.toLong(x >> 4, z >> 4), this);
}
@Override
public void a() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(x, y, z) != loaderBlock){
chunkLoader.remove();
return;
}
chunkLoader.tick();
}
@Override
public Collection<Hologram> getHolograms() {
return EMPTY_CONTAINER;
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_8_R1'
dependencies {
compileOnly "org.spigotmc:v1_8_R1:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,148 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.EnumGamemode;
import net.minecraft.server.v1_8_R1.EnumProtocolDirection;
import net.minecraft.server.v1_8_R1.MinecraftServer;
import net.minecraft.server.v1_8_R1.NetworkManager;
import net.minecraft.server.v1_8_R1.Packet;
import net.minecraft.server.v1_8_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_8_R1.PacketPlayInChat;
import net.minecraft.server.v1_8_R1.PacketPlayInFlying;
import net.minecraft.server.v1_8_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_8_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_8_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_8_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_8_R1.PlayerConnection;
import net.minecraft.server.v1_8_R1.PlayerInteractManager;
import net.minecraft.server.v1_8_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_8_R1 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_8_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
//noinspection unchecked
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("i");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("j");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,148 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.EntityArmorStand;
import net.minecraft.server.v1_8_R1.EntityHuman;
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.Vec3D;
import net.minecraft.server.v1_8_R1.World;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_8_R1 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_8_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setGravity(false);
setBasePlate(true);
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void s_() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public void e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public boolean a(EntityHuman human, Vec3D vec3d) {
// Prevent stand being equipped
return true;
}
@Override
public boolean d(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setEquipment(int i, ItemStack item) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
@Override
public void makeSound(String sound, float f1, float f2) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftArmorStand(this.world.getServer(), this);
}
return this.bukkitEntity;
}
}

View File

@ -1,292 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.Chunk;
import net.minecraft.server.v1_8_R1.IUpdatePlayerListBox;
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.NBTTagList;
import net.minecraft.server.v1_8_R1.NBTTagLong;
import net.minecraft.server.v1_8_R1.NBTTagString;
import net.minecraft.server.v1_8_R1.TileEntity;
import net.minecraft.server.v1_8_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_8_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R1.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_8_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_8_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
//noinspection unchecked
world.tileEntityList.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
//noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityList.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
//noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_8_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
a(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for (int i = hologramLines.size(); i > 0; i--) {
EntityHolograms_v1_8_R1 hologram = new EntityHolograms_v1_8_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void c() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_8_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_8_R1 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_8_R2'
dependencies {
compileOnly "org.spigotmc:v1_8_R2:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_8_R2.DamageSource;
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.EnumProtocolDirection;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.NetworkManager;
import net.minecraft.server.v1_8_R2.Packet;
import net.minecraft.server.v1_8_R2.PacketPlayInBlockDig;
import net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace;
import net.minecraft.server.v1_8_R2.PacketPlayInChat;
import net.minecraft.server.v1_8_R2.PacketPlayInFlying;
import net.minecraft.server.v1_8_R2.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_8_R2.PacketPlayInTransaction;
import net.minecraft.server.v1_8_R2.PacketPlayInUpdateSign;
import net.minecraft.server.v1_8_R2.PacketPlayInWindowClick;
import net.minecraft.server.v1_8_R2.PlayerConnection;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import net.minecraft.server.v1_8_R2.WorldServer;
import net.minecraft.server.v1_8_R2.WorldSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R2.CraftServer;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_8_R2 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_8_R2(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(WorldSettings.EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("k");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,155 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
import net.minecraft.server.v1_8_R2.DamageSource;
import net.minecraft.server.v1_8_R2.EntityArmorStand;
import net.minecraft.server.v1_8_R2.EntityHuman;
import net.minecraft.server.v1_8_R2.ItemStack;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
import net.minecraft.server.v1_8_R2.Vec3D;
import net.minecraft.server.v1_8_R2.World;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_8_R2 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_8_R2(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setGravity(false);
setBasePlate(true);
setMarker();
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void t_() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public void e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public boolean a(EntityHuman human, Vec3D vec3d) {
// Prevent stand being equipped
return true;
}
@Override
public boolean d(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setEquipment(int i, ItemStack item) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
@Override
public void makeSound(String sound, float f1, float f2) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftArmorStand(this.world.getServer(), this);
}
return this.bukkitEntity;
}
private void setMarker(){
byte b0 = this.datawatcher.getByte(10);
b0 = (byte)(b0 | 16);
this.datawatcher.watch(10, b0);
}
}

View File

@ -1,289 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.Chunk;
import net.minecraft.server.v1_8_R2.IUpdatePlayerListBox;
import net.minecraft.server.v1_8_R2.ItemStack;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
import net.minecraft.server.v1_8_R2.NBTTagList;
import net.minecraft.server.v1_8_R2.NBTTagLong;
import net.minecraft.server.v1_8_R2.NBTTagString;
import net.minecraft.server.v1_8_R2.TileEntity;
import net.minecraft.server.v1_8_R2.TileEntityMobSpawner;
import net.minecraft.server.v1_8_R2.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R2.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_8_R2 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_8_R2(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityList.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
tileEntity.a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R2::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityList.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_8_R2> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
a(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_8_R2 hologram = new EntityHolograms_v1_8_R2(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void c() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_8_R2 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_8_R2 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_9_R1'
dependencies {
compileOnly "org.spigotmc:v1_9_R1:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_9_R1.DamageSource;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.EnumProtocolDirection;
import net.minecraft.server.v1_9_R1.MinecraftServer;
import net.minecraft.server.v1_9_R1.NetworkManager;
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.PacketPlayInBlockDig;
import net.minecraft.server.v1_9_R1.PacketPlayInBlockPlace;
import net.minecraft.server.v1_9_R1.PacketPlayInChat;
import net.minecraft.server.v1_9_R1.PacketPlayInFlying;
import net.minecraft.server.v1_9_R1.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_9_R1.PacketPlayInTransaction;
import net.minecraft.server.v1_9_R1.PacketPlayInUpdateSign;
import net.minecraft.server.v1_9_R1.PacketPlayInWindowClick;
import net.minecraft.server.v1_9_R1.PlayerConnection;
import net.minecraft.server.v1_9_R1.PlayerInteractManager;
import net.minecraft.server.v1_9_R1.WorldServer;
import net.minecraft.server.v1_9_R1.WorldSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_9_R1 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_9_R1(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(WorldSettings.EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,172 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
import net.minecraft.server.v1_9_R1.DamageSource;
import net.minecraft.server.v1_9_R1.EntityArmorStand;
import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.EnumHand;
import net.minecraft.server.v1_9_R1.EnumInteractionResult;
import net.minecraft.server.v1_9_R1.EnumItemSlot;
import net.minecraft.server.v1_9_R1.ItemStack;
import net.minecraft.server.v1_9_R1.NBTTagCompound;
import net.minecraft.server.v1_9_R1.SoundEffect;
import net.minecraft.server.v1_9_R1.Vec3D;
import net.minecraft.server.v1_9_R1.World;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_9_R1 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_9_R1(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setGravity(false);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void m() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public void e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,289 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.Chunk;
import net.minecraft.server.v1_9_R1.ITickable;
import net.minecraft.server.v1_9_R1.ItemStack;
import net.minecraft.server.v1_9_R1.NBTTagCompound;
import net.minecraft.server.v1_9_R1.NBTTagList;
import net.minecraft.server.v1_9_R1.NBTTagLong;
import net.minecraft.server.v1_9_R1.NBTTagString;
import net.minecraft.server.v1_9_R1.TileEntity;
import net.minecraft.server.v1_9_R1.TileEntityMobSpawner;
import net.minecraft.server.v1_9_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_9_R1.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unused")
public final class NMSAdapter_v1_9_R1 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_9_R1(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
tileEntity.a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_9_R1::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_9_R1> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
a(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_9_R1 hologram = new EntityHolograms_v1_9_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void c() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_9_R1 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_9_R1 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}

View File

@ -1,7 +0,0 @@
group 'v1_9_R2'
dependencies {
compileOnly "org.spigotmc:v1_9_R2:latest"
compileOnly project(":API")
compileOnly parent
}

View File

@ -1,147 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.npc.DummyChannel;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_9_R2.DamageSource;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.EnumProtocolDirection;
import net.minecraft.server.v1_9_R2.MinecraftServer;
import net.minecraft.server.v1_9_R2.NetworkManager;
import net.minecraft.server.v1_9_R2.Packet;
import net.minecraft.server.v1_9_R2.PacketPlayInBlockDig;
import net.minecraft.server.v1_9_R2.PacketPlayInBlockPlace;
import net.minecraft.server.v1_9_R2.PacketPlayInChat;
import net.minecraft.server.v1_9_R2.PacketPlayInFlying;
import net.minecraft.server.v1_9_R2.PacketPlayInHeldItemSlot;
import net.minecraft.server.v1_9_R2.PacketPlayInTransaction;
import net.minecraft.server.v1_9_R2.PacketPlayInUpdateSign;
import net.minecraft.server.v1_9_R2.PacketPlayInWindowClick;
import net.minecraft.server.v1_9_R2.PlayerConnection;
import net.minecraft.server.v1_9_R2.PlayerInteractManager;
import net.minecraft.server.v1_9_R2.WorldServer;
import net.minecraft.server.v1_9_R2.WorldSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R2.CraftServer;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_9_R2 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_9_R2(Location location, UUID uuid){
super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, "Loader-" + location.getWorld().getName()), new PlayerInteractManager(((CraftWorld) location.getWorld()).getHandle()));
playerConnection = new DummyPlayerConnection(server, this);
playerInteractManager.setGameMode(WorldSettings.EnumGamemode.CREATIVE);
fallDistance = 0.0F;
fauxSleeping = true;
spawnIn(world);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.players.add(this);
((WorldServer) world).getPlayerChunkMap().addPlayer(this);
}
@Override
public UUID getUniqueId() {
return super.getUniqueID();
}
@Override
public void die() {
super.die();
world.players.remove(this);
((WorldServer) world).getPlayerChunkMap().removePlayer(this);
}
@Override
public Location getLocation() {
return getBukkitEntity().getLocation();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;
}
private static class DummyNetworkManager extends NetworkManager{
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);
}
public void a(PacketPlayInWindowClick packetPlayInWindowClick) {
}
public void a(PacketPlayInTransaction packetPlayInTransaction) {
}
public void a(PacketPlayInFlying packetPlayInFlying) {
}
public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) {
}
public void a(PacketPlayInBlockDig packetPlayInBlockDig) {
}
public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) {
}
public void disconnect(String s) {
}
public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) {
}
public void a(PacketPlayInChat packetPlayInChat) {
}
public void sendPacket(Packet packet) {
}
}
}

View File

@ -1,173 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
import net.minecraft.server.v1_9_R2.DamageSource;
import net.minecraft.server.v1_9_R2.EntityArmorStand;
import net.minecraft.server.v1_9_R2.EntityHuman;
import net.minecraft.server.v1_9_R2.EnumHand;
import net.minecraft.server.v1_9_R2.EnumInteractionResult;
import net.minecraft.server.v1_9_R2.EnumItemSlot;
import net.minecraft.server.v1_9_R2.ItemStack;
import net.minecraft.server.v1_9_R2.NBTTagCompound;
import net.minecraft.server.v1_9_R2.SoundEffect;
import net.minecraft.server.v1_9_R2.Vec3D;
import net.minecraft.server.v1_9_R2.World;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity;
import org.bukkit.entity.Entity;
@SuppressWarnings("unused")
public final class EntityHolograms_v1_9_R2 extends EntityArmorStand implements Hologram {
EntityHolograms_v1_9_R2(World world, double x, double y, double z){
super(world, x, y, z);
setInvisible(true);
setSmall(true);
setArms(false);
setGravity(false);
setBasePlate(true);
setMarker(true);
super.collides = false;
super.setCustomNameVisible(true);
super.a(new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D));
}
@Override
public void setHologramName(String name) {
super.setCustomName(name);
}
@Override
public void removeHologram() {
super.die();
}
@Override
public Entity getEntity() {
return getBukkitEntity();
}
@Override
public void m() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void inactiveTick() {
// Disable normal ticking for this entity.
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
if (this.onGround) {
this.onGround = false;
}
}
@Override
public void b(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean c(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public boolean d(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return false;
}
@Override
public NBTTagCompound e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
return nbttagcompound;
}
@Override
public void f(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public void a(NBTTagCompound nbttagcompound) {
// Do not load NBT.
}
@Override
public boolean isInvulnerable(DamageSource source) {
/*
* The field Entity.invulnerable is private.
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
}
@Override
public boolean isCollidable() {
return false;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, ItemStack itemstack, EnumHand enumhand) {
// Prevent stand being equipped
return EnumInteractionResult.PASS;
}
@Override
public boolean c(int i, ItemStack item) {
// Prevent stand being equipped
return false;
}
@Override
public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
// Prevent stand being equipped
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void a(SoundEffect soundeffect, float f, float f1) {
// Remove sounds.
}
@Override
public void die() {
// Prevent being killed.
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
super.bukkitEntity = new CraftArmorStand(super.world.getServer(), this);
}
return super.bukkitEntity;
}
}

View File

@ -1,289 +0,0 @@
package com.bgsoftware.wildloaders.nms;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
import com.bgsoftware.wildloaders.loaders.WChunkLoader;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.Chunk;
import net.minecraft.server.v1_9_R2.ITickable;
import net.minecraft.server.v1_9_R2.ItemStack;
import net.minecraft.server.v1_9_R2.NBTTagCompound;
import net.minecraft.server.v1_9_R2.NBTTagList;
import net.minecraft.server.v1_9_R2.NBTTagLong;
import net.minecraft.server.v1_9_R2.NBTTagString;
import net.minecraft.server.v1_9_R2.TileEntity;
import net.minecraft.server.v1_9_R2.TileEntityMobSpawner;
import net.minecraft.server.v1_9_R2.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_9_R2.util.LongHash;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings({"ConstantConditions", "unused"})
public final class NMSAdapter_v1_9_R2 implements NMSAdapter {
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 8))
return def;
return tagCompound.getString(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagString(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
if(!tagCompound.hasKeyOfType(key, 4))
return def;
return tagCompound.getLong(key);
}
@Override
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
tagCompound.set(key, new NBTTagLong(value));
nmsItem.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
NBTTagCompound properties = new NBTTagCompound();
NBTTagList textures = new NBTTagList();
NBTTagCompound signature = new NBTTagCompound();
signature.setString("Value", texture);
textures.add(signature);
properties.set("textures", textures);
skullOwner.set("Properties", properties);
skullOwner.setString("Id", UUID.randomUUID().toString());
nbtTagCompound.set("SkullOwner", skullOwner);
nmsItem.setTag(nbtTagCompound);
return CraftItemStack.asBukkitCopy(nmsItem);
}
@Override
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
return new ChunkLoaderNPC_v1_9_R2(location, uuid);
}
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
tileEntity.a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
if(tileEntityChunkLoader != null) {
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_9_R2::removeHologram);
tileEntityChunkLoader.removed = true;
world.tileEntityListTick.remove(tileEntityChunkLoader);
}
if(spawnParticle)
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
tileEntity.a(nbtTagCompound);
});
}
}
@Override
public void updateSpawner(Location location, boolean reset) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
mobSpawner.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
mobSpawner.a(nbtTagCompound);
}
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
private final List<EntityHolograms_v1_9_R2> holograms = new ArrayList<>();
private final WChunkLoader chunkLoader;
private final Block loaderBlock;
private short currentTick = 20;
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
private boolean removed = false;
TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){
this.chunkLoader = (WChunkLoader) chunkLoader;
a(blockPosition);
a(world);
loaderBlock = world.getType(blockPosition).getBlock();
if(!this.chunkLoader.isInfinite()) {
long timeLeft = chunkLoader.getTimeLeft();
daysAmount = (short) (timeLeft / 86400);
timeLeft = timeLeft % 86400;
hoursAmount = (short) (timeLeft / 3600);
timeLeft = timeLeft % 3600;
minutesAmount = (short) (timeLeft / 60);
timeLeft = timeLeft % 60;
secondsAmount = (short) timeLeft;
}
tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this);
List<String> hologramLines = this.chunkLoader.getHologramLines();
double currentY = position.getY() + 1;
for(int i = hologramLines.size(); i > 0; i--){
EntityHolograms_v1_9_R2 hologram = new EntityHolograms_v1_9_R2(world, position.getX() + 0.5, currentY, position.getZ() + 0.5);
updateName(hologram, hologramLines.get(i - 1));
world.addEntity(hologram);
currentY += 0.23;
holograms.add(hologram);
}
}
@Override
public void c() {
if(removed || ++currentTick <= 20)
return;
currentTick = 0;
if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){
chunkLoader.remove();
return;
}
if(chunkLoader.isInfinite())
return;
List<String> hologramLines = chunkLoader.getHologramLines();
int hologramsAmount = holograms.size();
for (int i = hologramsAmount; i > 0; i--) {
EntityHolograms_v1_9_R2 hologram = holograms.get(hologramsAmount - i);
updateName(hologram, hologramLines.get(i - 1));
}
chunkLoader.tick();
if(!removed) {
secondsAmount--;
if (secondsAmount < 0) {
secondsAmount = 59;
minutesAmount--;
if (minutesAmount < 0) {
minutesAmount = 59;
hoursAmount--;
if (hoursAmount < 0) {
hoursAmount = 23;
daysAmount--;
}
}
}
}
}
@Override
public Collection<Hologram> getHolograms() {
return Collections.unmodifiableList(holograms);
}
private void updateName(EntityHolograms_v1_9_R2 hologram, String line){
hologram.setHologramName(line
.replace("{0}", chunkLoader.getWhoPlaced().getName())
.replace("{1}", daysAmount + "")
.replace("{2}", hoursAmount + "")
.replace("{3}", minutesAmount + "")
.replace("{4}", secondsAmount + "")
);
}
}
}