Drop 1.8.0 support, since it doesn't have the new chat API

This commit is contained in:
filoghost 2020-04-13 21:14:39 +02:00
parent 09fd0d5f9e
commit 104d9abd6c
15 changed files with 5 additions and 1235 deletions

View File

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-parent</artifactId>
<version>2.4.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>holographicdisplays-nms-v1_8_r1</artifactId>
<name>HolographicDisplays NMS v1_8_R1</name>
<repositories>
<repository>
<id>nms-repo</id>
<url>https://repo.codemc.io/repository/nms/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-interfaces</artifactId>
<version>2.4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-utils</artifactId>
<version>2.4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-config</artifactId>
<version>2.4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,81 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import java.util.Collection;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
public class CraftNMSArmorStand extends CraftArmorStand {
public CraftNMSArmorStand(CraftServer server, EntityNMSArmorStand entity) {
super(server, entity);
}
// Disallow all the bukkit methods.
@Override
public void remove() {
// Cannot be removed, this is the most important to override.
}
// Methods from Armor stand class
@Override public void setArms(boolean arms) { }
@Override public void setBasePlate(boolean basePlate) { }
@Override public void setBodyPose(EulerAngle pose) { }
@Override public void setBoots(ItemStack item) { }
@Override public void setChestplate(ItemStack item) { }
@Override public void setGravity(boolean gravity) { }
@Override public void setHeadPose(EulerAngle pose) { }
@Override public void setHelmet(ItemStack item) { }
@Override public void setItemInHand(ItemStack item) { }
@Override public void setLeftArmPose(EulerAngle pose) { }
@Override public void setLeftLegPose(EulerAngle pose) { }
@Override public void setLeggings(ItemStack item) { }
@Override public void setRightArmPose(EulerAngle pose) { }
@Override public void setRightLegPose(EulerAngle pose) { }
@Override public void setSmall(boolean small) { }
@Override public void setVisible(boolean visible) { }
// Methods from LivingEntity class
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
@Override public void setRemoveWhenFarAway(boolean remove) { }
// Methods from Entity
@Override public void setVelocity(Vector vel) { }
@Override public boolean teleport(Location loc) { return false; }
@Override public boolean teleport(Entity entity) { return false; }
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
@Override public void setFireTicks(int ticks) { }
@Override public boolean setPassenger(Entity entity) { return false; }
@Override public boolean eject() { return false; }
@Override public boolean leaveVehicle() { return false; }
@Override public void playEffect(EntityEffect effect) { }
@Override public void setCustomName(String name) { }
@Override public void setCustomNameVisible(boolean flag) { }
}

View File

@ -1,56 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftItem;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class CraftNMSItem extends CraftItem {
public CraftNMSItem(CraftServer server, EntityNMSItem entity) {
super(server, entity);
}
// Disallow all the bukkit methods.
@Override
public void remove() {
// Cannot be removed, this is the most important to override.
}
// Methods from Entity
@Override public void setVelocity(Vector vel) { }
@Override public boolean teleport(Location loc) { return false; }
@Override public boolean teleport(Entity entity) { return false; }
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
@Override public void setFireTicks(int ticks) { }
@Override public boolean setPassenger(Entity entity) { return false; }
@Override public boolean eject() { return false; }
@Override public boolean leaveVehicle() { return false; }
@Override public void playEffect(EntityEffect effect) { }
@Override public void setCustomName(String name) { }
@Override public void setCustomNameVisible(boolean flag) { }
// Methods from Item
@Override public void setItemStack(ItemStack stack) { }
@Override public void setPickupDelay(int delay) { }
}

View File

@ -1,63 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import java.util.Collection;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftSlime;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
public class CraftNMSSlime extends CraftSlime {
public CraftNMSSlime(CraftServer server, EntityNMSSlime entity) {
super(server, entity);
}
// Disallow all the bukkit methods.
@Override
public void remove() {
// Cannot be removed, this is the most important to override.
}
// Methods from LivingEntity class
@Override public boolean addPotionEffect(PotionEffect effect) { return false; }
@Override public boolean addPotionEffect(PotionEffect effect, boolean param) { return false; }
@Override public boolean addPotionEffects(Collection<PotionEffect> effects) { return false; }
@Override public void setRemoveWhenFarAway(boolean remove) { }
// Methods from Entity
@Override public void setVelocity(Vector vel) { }
@Override public boolean teleport(Location loc) { return false; }
@Override public boolean teleport(Entity entity) { return false; }
@Override public boolean teleport(Location loc, TeleportCause cause) { return false; }
@Override public boolean teleport(Entity entity, TeleportCause cause) { return false; }
@Override public void setFireTicks(int ticks) { }
@Override public boolean setPassenger(Entity entity) { return false; }
@Override public boolean eject() { return false; }
@Override public boolean leaveVehicle() { return false; }
@Override public void playEffect(EntityEffect effect) { }
@Override public void setCustomName(String name) { }
@Override public void setCustomNameVisible(boolean flag) { }
// Methods from Slime
@Override public void setSize(int size) { }
}

View File

@ -1,243 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
import com.gmail.filoghost.holographicdisplays.disk.Configuration;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
import com.gmail.filoghost.holographicdisplays.util.Utils;
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectField;
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectionUtils;
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.EntityPlayer;
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.MathHelper;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_8_R1.Vec3D;
import net.minecraft.server.v1_8_R1.World;
public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorStand {
private static final ReflectField<Integer> DISABLED_SLOTS_FIELD = new ReflectField<>(EntityArmorStand.class, "bg");
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
setInvisible(true);
setSmall(true);
setArms(false);
setGravity(true);
setBasePlate(true);
// There is no "Marker" tag in v1_8_R1
this.parentPiece = parentPiece;
try {
DISABLED_SLOTS_FIELD.set(this, Integer.MAX_VALUE);
} catch (Exception e) {
// There's still the overridden method.
}
forceSetBoundingBox(new NullBoundingBox());
}
@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!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public int getId() {
if (Configuration.preciseHologramMovement) {
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
// Then this method is being called when creating a new packet, we return a fake ID!
return -1;
}
}
return super.getId();
}
@Override
public void s_() {
if (!lockTick) {
super.s_();
}
}
@Override
public void makeSound(String sound, float f1, float f2) {
// Remove sounds.
}
@Override
public void setCustomNameNMS(String name) {
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return this.customName;
}
@Override
public void setLockTick(boolean lock) {
lockTick = lock;
}
@Override
public void die() {
setLockTick(false);
super.die();
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftNMSArmorStand(this.world.getServer(), this);
}
return this.bukkitEntity;
}
@Override
public void killEntityNMS() {
die();
}
@Override
public void setLocationNMS(double x, double y, double z) {
super.setPosition(x, y, z);
if (Configuration.preciseHologramMovement) {
// Send a packet near to update the position.
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(
getIdNMS(),
MathHelper.floor(this.locX * 32.0D),
MathHelper.floor(this.locY * 32.0D),
MathHelper.floor(this.locZ * 32.0D),
(byte) (int) (this.yaw * 256.0F / 360.0F),
(byte) (int) (this.pitch * 256.0F / 360.0F),
this.onGround
);
for (Object obj : this.world.players) {
if (obj instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) obj;
double distanceSquared = Utils.square(nmsPlayer.locX - this.locX) + Utils.square(nmsPlayer.locZ - this.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}
}
}
}
@Override
public boolean isDeadNMS() {
return this.dead;
}
@Override
public int getIdNMS() {
return super.getId(); // Return the real ID without checking the stack trace.
}
@Override
public HologramLine getHologramLine() {
return parentPiece;
}
@Override
public org.bukkit.entity.Entity getBukkitEntityNMS() {
return getBukkitEntity();
}
}

View File

@ -1,243 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import java.util.logging.Level;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.ConsoleLogger;
import com.gmail.filoghost.holographicdisplays.util.ItemUtils;
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectField;
import net.minecraft.server.v1_8_R1.Blocks;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.Entity;
import net.minecraft.server.v1_8_R1.EntityHuman;
import net.minecraft.server.v1_8_R1.EntityItem;
import net.minecraft.server.v1_8_R1.EntityPlayer;
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.NBTTagString;
import net.minecraft.server.v1_8_R1.World;
public class EntityNMSItem extends EntityItem implements NMSItem {
private static final ReflectField<Double> RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ap");
private static final ReflectField<Double> RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "aq");
private boolean lockTick;
private ItemLine parentPiece;
private ItemPickupManager itemPickupManager;
public EntityNMSItem(World world, ItemLine piece, ItemPickupManager itemPickupManager) {
super(world);
super.pickupDelay = Integer.MAX_VALUE;
this.parentPiece = piece;
this.itemPickupManager = itemPickupManager;
}
@Override
public void s_() {
// So it won't get removed.
ticksLived = 0;
if (!lockTick) {
super.s_();
}
}
// Method called when a player is near.
@Override
public void d(EntityHuman human) {
if (human.locY < this.locY - 1.5 || human.locY > this.locY + 1.0) {
// Too low or too high, it's a bit weird.
return;
}
if (parentPiece.getPickupHandler() != null && human instanceof EntityPlayer) {
itemPickupManager.handleItemLinePickup((Player) human.getBukkitEntity(), parentPiece.getPickupHandler(), parentPiece.getParent());
// It is never added to the inventory.
}
}
@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 inactiveTick() {
// Check inactive ticks.
if (!lockTick) {
super.inactiveTick();
}
}
@Override
public void setLockTick(boolean lock) {
lockTick = lock;
}
@Override
public void die() {
setLockTick(false);
super.die();
}
@Override
public boolean isAlive() {
// This override prevents items from being picked up by hoppers.
// Should have no side effects.
return false;
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftNMSItem(this.world.getServer(), this);
}
return this.bukkitEntity;
}
@Override
public boolean isDeadNMS() {
return this.dead;
}
@Override
public void killEntityNMS() {
die();
}
@Override
public void setLocationNMS(double x, double y, double z) {
super.setPosition(x, y, z);
}
@Override
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
if (newItem == null) {
newItem = new ItemStack(Blocks.BEDROCK);
}
if (newItem.getTag() == null) {
newItem.setTag(new NBTTagCompound());
}
NBTTagCompound display = newItem.getTag().getCompound("display");
if (!newItem.getTag().hasKey("display")) {
newItem.getTag().set("display", display);
}
NBTTagList tagList = new NBTTagList();
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
display.set("Lore", tagList);
setItemStack(newItem);
}
@Override
public int getIdNMS() {
return this.getId();
}
@Override
public ItemLine getHologramLine() {
return parentPiece;
}
@Override
public void allowPickup(boolean pickup) {
if (pickup) {
super.pickupDelay = 0;
} else {
super.pickupDelay = Integer.MAX_VALUE;
}
}
@Override
public org.bukkit.entity.Entity getBukkitEntityNMS() {
return getBukkitEntity();
}
@Override
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
if (vehicleBase == null || !(vehicleBase instanceof Entity)) {
// It should never dismount
return;
}
Entity entity = (Entity) vehicleBase;
try {
RIDER_PITCH_DELTA.set(this, 0.0);
RIDER_YAW_DELTA.set(this, 0.0);
} catch (Throwable t) {
ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t);
}
if (this.vehicle != null) {
this.vehicle.passenger = null;
}
this.vehicle = entity;
entity.passenger = this;
}
@Override
public Object getRawItemStack() {
return super.getItemStack();
}
}

View File

@ -1,210 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
import com.gmail.filoghost.holographicdisplays.util.ConsoleLogger;
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectField;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.Entity;
import net.minecraft.server.v1_8_R1.EntityDamageSource;
import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.EntitySlime;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.World;
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
private static final ReflectField<Double> RIDER_PITCH_DELTA = new ReflectField<>(Entity.class, "ap");
private static final ReflectField<Double> RIDER_YAW_DELTA = new ReflectField<>(Entity.class, "aq");
private boolean lockTick;
private HologramLine parentPiece;
public EntityNMSSlime(World world, HologramLine parentPiece) {
super(world);
super.persistent = true;
a(0.0F, 0.0F);
setSize(1);
setInvisible(true);
this.parentPiece = parentPiece;
forceSetBoundingBox(new NullBoundingBox());
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override
public void s_() {
// Checks every 20 ticks.
if (ticksLived % 20 == 0) {
// The slime dies without a vehicle.
if (this.vehicle == null) {
die();
}
}
if (!lockTick) {
super.s_();
}
}
@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 damageEntity(DamageSource damageSource, float amount) {
if (damageSource instanceof EntityDamageSource) {
EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource;
if (entityDamageSource.getEntity() instanceof EntityPlayer) {
Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity()));
}
}
return false;
}
@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 void makeSound(String sound, float volume, float pitch) {
// Remove sounds.
}
@Override
public void setLockTick(boolean lock) {
lockTick = lock;
}
@Override
public void die() {
setLockTick(false);
super.die();
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftNMSSlime(this.world.getServer(), this);
}
return this.bukkitEntity;
}
@Override
public boolean isDeadNMS() {
return super.dead;
}
@Override
public void killEntityNMS() {
die();
}
@Override
public void setLocationNMS(double x, double y, double z) {
super.setPosition(x, y, z);
}
@Override
public int getIdNMS() {
return this.getId();
}
@Override
public HologramLine getHologramLine() {
return parentPiece;
}
@Override
public org.bukkit.entity.Entity getBukkitEntityNMS() {
return getBukkitEntity();
}
@Override
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
if (vehicleBase == null || !(vehicleBase instanceof Entity)) {
// It should never dismount
return;
}
Entity entity = (Entity) vehicleBase;
try {
RIDER_PITCH_DELTA.set(this, 0.0);
RIDER_YAW_DELTA.set(this, 0.0);
} catch (Throwable t) {
ConsoleLogger.logDebug(Level.SEVERE, "Couldn't set rider pitch and yaw", t);
}
if (this.vehicle != null) {
this.vehicle.passenger = null;
}
this.vehicle = entity;
entity.passenger = this;
}
}

View File

@ -1,156 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import java.lang.reflect.Method;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.ItemStack;
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.ConsoleLogger;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectField;
import net.minecraft.server.v1_8_R1.Entity;
import net.minecraft.server.v1_8_R1.EntityTypes;
import net.minecraft.server.v1_8_R1.MathHelper;
import net.minecraft.server.v1_8_R1.World;
import net.minecraft.server.v1_8_R1.WorldServer;
public class NmsManagerImpl implements NMSManager {
private static final ReflectField<Map<Class<?>, String>> ENTITY_NAMES_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "d");
private static final ReflectField<Map<Class<?>, Integer>> ENTITY_IDS_BY_CLASS_FIELD = new ReflectField<>(EntityTypes.class, "f");
private Method validateEntityMethod;
@Override
public void setup() throws Exception {
registerCustomEntity(EntityNMSArmorStand.class, "ArmorStand", 30);
registerCustomEntity(EntityNMSItem.class, "Item", 1);
registerCustomEntity(EntityNMSSlime.class, "Slime", 55);
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ENTITY_NAMES_BY_CLASS_FIELD.getStatic().put(entityClass, name);
ENTITY_IDS_BY_CLASS_FIELD.getStatic().put(entityClass, Integer.valueOf(id));
}
@Override
public NMSItem spawnNMSItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemLine parentPiece, ItemStack stack, ItemPickupManager itemPickupManager) {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityNMSItem customItem = new EntityNMSItem(nmsWorld, parentPiece, itemPickupManager);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!addEntityToWorld(nmsWorld, customItem)) {
ConsoleLogger.handleSpawnFail(parentPiece);
}
return customItem;
}
@Override
public EntityNMSSlime spawnNMSSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramLine parentPiece) {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityNMSSlime touchSlime = new EntityNMSSlime(nmsWorld, parentPiece);
touchSlime.setLocationNMS(x, y, z);
if (!addEntityToWorld(nmsWorld, touchSlime)) {
ConsoleLogger.handleSpawnFail(parentPiece);
}
return touchSlime;
}
@Override
public NMSArmorStand spawnNMSArmorStand(org.bukkit.World world, double x, double y, double z, HologramLine parentPiece) {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityNMSArmorStand invisibleArmorStand = new EntityNMSArmorStand(nmsWorld, parentPiece);
invisibleArmorStand.setLocationNMS(x, y, z);
if (!addEntityToWorld(nmsWorld, invisibleArmorStand)) {
ConsoleLogger.handleSpawnFail(parentPiece);
}
return invisibleArmorStand;
}
@SuppressWarnings("unchecked")
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add");
if (validateEntityMethod == null) {
return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
}
final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0);
if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
// This should never happen
nmsEntity.dead = true;
return false;
}
nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
nmsWorld.entityList.add(nmsEntity);
try {
validateEntityMethod.invoke(nmsWorld, nmsEntity);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
return ((CraftEntity) bukkitEntity).getHandle() instanceof NMSEntityBase;
}
@Override
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity) {
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
if (nmsEntity instanceof NMSEntityBase) {
return ((NMSEntityBase) nmsEntity);
}
return null;
}
@Override
public org.bukkit.entity.Entity getEntityFromID(org.bukkit.World bukkitWorld, int entityID) {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
Entity nmsEntity = nmsWorld.a(entityID);
if (nmsEntity == null) {
return null;
}
return nmsEntity.getBukkitEntity();
}
}

View File

@ -1,89 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.MovingObjectPosition;
import net.minecraft.server.v1_8_R1.Vec3D;
public class NullBoundingBox extends AxisAlignedBB {
public NullBoundingBox() {
super(0, 0, 0, 0, 0, 0);
}
@Override
public double a() {
return 0.0;
}
@Override
public double a(AxisAlignedBB arg0, double arg1) {
return 0.0;
}
@Override
public AxisAlignedBB a(AxisAlignedBB arg0) {
return this;
}
@Override
public AxisAlignedBB a(double arg0, double arg1, double arg2) {
return this;
}
@Override
public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) {
return super.a(arg0, arg1);
}
@Override
public boolean a(Vec3D arg0) {
return false;
}
@Override
public double b(AxisAlignedBB arg0, double arg1) {
return 0.0;
}
@Override
public boolean b(AxisAlignedBB arg0) {
return false;
}
@Override
public double c(AxisAlignedBB arg0, double arg1) {
return 0.0;
}
@Override
public AxisAlignedBB c(double arg0, double arg1, double arg2) {
return this;
}
@Override
public AxisAlignedBB grow(double arg0, double arg1, double arg2) {
return this;
}
@Override
public AxisAlignedBB shrink(double arg0, double arg1, double arg2) {
return this;
}
}

View File

@ -54,12 +54,6 @@
<version>2.4.2-SNAPSHOT</version> <version>2.4.2-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r1</artifactId>
<version>2.4.2-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r2</artifactId> <artifactId>holographicdisplays-nms-v1_8_r2</artifactId>

View File

@ -109,7 +109,7 @@ public class HolographicDisplays extends JavaPlugin {
if (!NMSVersion.isValid()) { if (!NMSVersion.isValid()) {
criticalShutdown( criticalShutdown(
"Holographic Displays does not support this server version.", "Holographic Displays does not support this server version.",
"Supported Spigot versions: from 1.8 to 1.15."); "Supported Spigot versions: from 1.8.3 to 1.15.");
return; return;
} }

View File

@ -19,7 +19,6 @@ package com.gmail.filoghost.holographicdisplays.util;
*/ */
public enum NMSVersion { public enum NMSVersion {
v1_8_R1,
v1_8_R2, v1_8_R2,
v1_8_R3, v1_8_R3,
v1_9_R1, v1_9_R1,

View File

@ -23,43 +23,12 @@ public class Offsets {
public static final double public static final double
// A single armor stand. // A single armor stand.
ARMOR_STAND_ALONE = getArmorStandAloneOffset(), ARMOR_STAND_ALONE = -0.29,
// An armor stand holding an item. // An armor stand holding an item.
ARMOR_STAND_WITH_ITEM = getArmorStandWithItemOffset(), ARMOR_STAND_WITH_ITEM = 0,
// An armor stand holding a slime. // An armor stand holding a slime.
ARMOR_STAND_WITH_SLIME = getArmorStandWithSlimeOffset(); ARMOR_STAND_WITH_SLIME = 0;
private static double getArmorStandAloneOffset() {
if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) {
// When the NBT tag "Marker" was not implemented
return -1.25;
} else {
return -0.29;
}
}
private static double getArmorStandWithItemOffset() {
if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) {
// When the NBT tag "Marker" was not implemented
return -1.48;
} else {
return 0;
}
}
private static double getArmorStandWithSlimeOffset() {
if (NMSVersion.getCurrent() == NMSVersion.v1_8_R1) {
// When the NBT tag "Marker" was not implemented
return -1.48;
} else {
return 0;
}
}
} }

View File

@ -34,7 +34,7 @@ public class VersionUtils {
/** /**
* This method uses a regex to get the NMS package part that changes with every update. * This method uses a regex to get the NMS package part that changes with every update.
* Example: v1_8_R1 * Example: v1_13_R2
* @return the NMS package part or null if not found. * @return the NMS package part or null if not found.
*/ */
public static String extractNMSVersion() { public static String extractNMSVersion() {

View File

@ -34,7 +34,6 @@
<module>Utils</module> <module>Utils</module>
<module>Config</module> <module>Config</module>
<module>NMS/Interfaces</module> <module>NMS/Interfaces</module>
<module>NMS/v1_8_R1</module>
<module>NMS/v1_8_R2</module> <module>NMS/v1_8_R2</module>
<module>NMS/v1_8_R3</module> <module>NMS/v1_8_R3</module>
<module>NMS/v1_9_R1</module> <module>NMS/v1_9_R1</module>