Other small fixes.

This commit is contained in:
filoghost 2014-12-06 18:52:01 +01:00
parent 2f1a8bde28
commit 493ea07880
8 changed files with 77 additions and 56 deletions

View File

@ -1,6 +1,6 @@
name: HolographicDisplays
main: com.gmail.filoghost.holograms.HolographicDisplays
version: 1.8.11
version: 1.8.12
softdepend: [Multiverse-Core, MultiWorld, My Worlds, My_Worlds, ProtocolLib]

View File

@ -23,15 +23,18 @@ import com.gmail.filoghost.holograms.object.HologramBase;
import com.gmail.filoghost.holograms.utils.ItemUtils;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private boolean lockTick;
private HologramBase parent;
public EntityCustomItem(World world) {
super(world);
super.pickupDelay = Integer.MAX_VALUE;
// To fix the bounding box
a(0.05f, 1.2f);
}
@Override
public void s_() {
// Checks every 20 ticks.
@ -41,12 +44,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
die();
}
}
if (!lockTick) {
super.s_();
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
@ -54,14 +57,19 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
if (stacktrace.length > 2 && stacktrace[2].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void d(EntityHuman human) {
if (human.locY < this.locY + 0.5) {
// Too low, it's a bit weird.
return;
}
if (parent instanceof FloatingItem && human instanceof EntityPlayer) {
FloatingItem floatingItemParent = (FloatingItem) parent;
@ -73,16 +81,16 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
HolographicDisplays.getInstance().getLogger().warning("An exception occurred while a player picking up a floating item. It's probably caused by another plugin using Holographic Displays as library.");
}
}
// 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.
@ -94,12 +102,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
// Do not save NBT.
return false;
}
@Override
public void e(NBTTagCompound nbttagcompound) {
// Do not save NBT.
}
@Override
public boolean isInvulnerable(DamageSource damagesource) {
/*
@ -107,24 +115,24 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
* It's only used while saving NBTTags, but since the entity would be killed
* on chunk unload, we prefer to override isInvulnerable().
*/
return true;
return true;
}
@Override
public void setLockTick(boolean lock) {
lockTick = lock;
}
@Override
public void setCustomName(String customName) {
// Locks the custom name.
}
@Override
public void setCustomNameVisible(boolean visible) {
// Locks the custom name.
}
@Override
public void die() {
setLockTick(false);
@ -135,7 +143,7 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftCustomItem(this.world.getServer(), this);
}
}
return this.bukkitEntity;
}
@ -143,12 +151,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
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);
@ -157,29 +165,28 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@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);
newItem.getTag().set("display", display);
}
NBTTagList tagList = new NBTTagList();
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
display.set("Lore", tagList);
newItem.count = 0;
setItemStack(newItem);
}
@Override
public HologramBase getParentHologram() {
return parent;

View File

@ -1,5 +1,6 @@
package com.gmail.filoghost.holograms.nms.v1_8_R1;
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.EntityArmorStand;
@ -33,7 +34,7 @@ public class EntityHologramArmorStand extends EntityArmorStand implements Hologr
} catch (Exception e) {
// There's still the overridden method.
}
a(0.0F, 0.0F);
forceSetBoundingBox(new NullBoundingBox());
}
@ -96,7 +97,15 @@ public class EntityHologramArmorStand extends EntityArmorStand implements Hologr
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 void s_() {

View File

@ -5,6 +5,7 @@ import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import com.gmail.filoghost.holograms.nms.interfaces.TouchSlime;
import com.gmail.filoghost.holograms.object.HologramBase;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.EntitySlime;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
@ -18,9 +19,18 @@ public class EntityTouchSlime extends EntitySlime implements TouchSlime {
public EntityTouchSlime(World world) {
super(world);
super.persistent = true;
a(0.0F, 0.0F);
setSize(1);
setInvisible(true);
forceSetBoundingBox(new NullBoundingBox());
}
@Override
public void a(AxisAlignedBB boundingBox) {
// Do not change it!
}
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
super.a(boundingBox);
}
@Override

View File

@ -11,7 +11,6 @@ import com.gmail.filoghost.holograms.exception.SpawnFailedException;
import com.gmail.filoghost.holograms.object.pieces.FloatingItemDoubleEntity;
import com.gmail.filoghost.holograms.object.pieces.FloatingTouchSlimeDoubleEntity;
import com.gmail.filoghost.holograms.utils.Validator;
import com.gmail.filoghost.holograms.utils.VisibilityManager;
/**
* This class is only used by the plugin itself. Other plugins should just use the API.
@ -20,7 +19,6 @@ import com.gmail.filoghost.holograms.utils.VisibilityManager;
public class CraftFloatingItem extends HologramBase implements FloatingItem {
protected FloatingItemDoubleEntity floatingItemDoubleEntity;
protected VisibilityManager visibilityManager;
protected long creationTimestamp;
@ -39,18 +37,6 @@ public class CraftFloatingItem extends HologramBase implements FloatingItem {
public long getCreationTimestamp() {
return creationTimestamp;
}
public void setVisibilityManager(VisibilityManager visibilityManager) {
this.visibilityManager = visibilityManager;
}
public boolean hasVisibilityManager() {
return visibilityManager != null;
}
public VisibilityManager getVisibilityManager() {
return visibilityManager;
}
@Override
public void setTouchHandler(ItemTouchHandler touchHandler) {

View File

@ -9,18 +9,20 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import com.gmail.filoghost.holograms.Configuration;
import com.gmail.filoghost.holograms.utils.GenericUtils;
public class PlaceholdersList {
// Each 2 tenths of second
private static final Placeholder RAINBOW_TEXT = new AnimatedPlaceholder("&u", 2, new String[] {
ChatColor.RED + "",
ChatColor.GOLD + "",
ChatColor.YELLOW + "",
ChatColor.GREEN + "",
ChatColor.AQUA + "",
ChatColor.LIGHT_PURPLE + ""
});
private static final Placeholder RAINBOW_TEXT = new AnimatedPlaceholder("&u", 2, GenericUtils.arrayToStrings(
ChatColor.RED,
ChatColor.GOLD,
ChatColor.YELLOW,
ChatColor.GREEN,
ChatColor.AQUA,
ChatColor.LIGHT_PURPLE
));
// Each second
private static final Placeholder ONLINE_PLAYERS = new Placeholder("{online}", "{o}", 10) {

View File

@ -2,6 +2,15 @@ package com.gmail.filoghost.holograms.utils;
public class GenericUtils {
public static <T> String[] arrayToStrings(T... array) {
String[] result = new String[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i] != null ? array[i].toString() : null;
}
return result;
}
public static double square(double d) {
return d * d;
}

View File

@ -3,19 +3,17 @@ package com.gmail.filoghost.holograms.utils;
import java.lang.reflect.Field;
import java.util.Map;
import net.minecraft.server.v1_8_R1.EntityArmorStand;
public class ReflectionUtils {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void putInPrivateStaticMap(Class clazz, String fieldName, Object key, Object value) throws Exception {
public static void putInPrivateStaticMap(Class<?> clazz, String fieldName, Object key, Object value) throws Exception {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
Map map = (Map) field.get(null);
map.put(key, value);
}
public static void setPrivateField(Class<EntityArmorStand> clazz, Object handle, String fieldName, Object value) throws Exception {
public static void setPrivateField(Class<?> clazz, Object handle, String fieldName, Object value) throws Exception {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(handle, value);