mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-09-07 21:18:14 +02:00
Fix item stacking and handle exceptions in touch & pickup handlers.
This commit is contained in:
parent
10bfead9e4
commit
6e86a803dc
@ -196,7 +196,7 @@ public class HolographicDisplays extends JavaPlugin {
|
|||||||
ServerInfoTimer.setRefreshSeconds(Configuration.bungeeRefreshSeconds);
|
ServerInfoTimer.setRefreshSeconds(Configuration.bungeeRefreshSeconds);
|
||||||
ServerInfoTimer.startTask();
|
ServerInfoTimer.startTask();
|
||||||
BungeeCleanupTask.start();
|
BungeeCleanupTask.start();
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 3 * 20L, 3 * 20L);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20L);
|
||||||
|
|
||||||
Set<String> savedHolograms = HologramDatabase.getHolograms();
|
Set<String> savedHolograms = HologramDatabase.getHolograms();
|
||||||
if (savedHolograms != null && savedHolograms.size() > 0) {
|
if (savedHolograms != null && savedHolograms.size() > 0) {
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
|||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
|
||||||
import com.gmail.filoghost.holograms.Configuration;
|
import com.gmail.filoghost.holograms.Configuration;
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.api.Hologram;
|
import com.gmail.filoghost.holograms.api.Hologram;
|
||||||
import com.gmail.filoghost.holograms.commands.Messages;
|
import com.gmail.filoghost.holograms.commands.Messages;
|
||||||
@ -89,7 +90,12 @@ public class MainListener implements Listener {
|
|||||||
if (base instanceof Hologram) {
|
if (base instanceof Hologram) {
|
||||||
Hologram textHologram = (Hologram) base;
|
Hologram textHologram = (Hologram) base;
|
||||||
if (textHologram.hasTouchHandler()) {
|
if (textHologram.hasTouchHandler()) {
|
||||||
|
try {
|
||||||
textHologram.getTouchHandler().onTouch(textHologram, event.getPlayer());
|
textHologram.getTouchHandler().onTouch(textHologram, event.getPlayer());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
HolographicDisplays.getInstance().getLogger().warning("An exception occured while a player was touching a hologram. It's probably caused by another plugin using Holographic Displays as library.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (base instanceof FloatingItem) {
|
} else if (base instanceof FloatingItem) {
|
||||||
FloatingItem floatingItem = (FloatingItem) base;
|
FloatingItem floatingItem = (FloatingItem) base;
|
||||||
|
@ -6,15 +6,19 @@ import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
|||||||
import net.minecraft.server.v1_6_R3.World;
|
import net.minecraft.server.v1_6_R3.World;
|
||||||
import net.minecraft.server.v1_6_R3.EntityHuman;
|
import net.minecraft.server.v1_6_R3.EntityHuman;
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagString;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
||||||
import com.gmail.filoghost.holograms.object.HologramBase;
|
import com.gmail.filoghost.holograms.object.HologramBase;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
|
|
||||||
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
||||||
|
|
||||||
@ -60,7 +64,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
|
|
||||||
FloatingItem floatingItemParent = (FloatingItem) parent;
|
FloatingItem floatingItemParent = (FloatingItem) parent;
|
||||||
if (floatingItemParent.hasPickupHandler()) {
|
if (floatingItemParent.hasPickupHandler()) {
|
||||||
|
try {
|
||||||
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
HolographicDisplays.getInstance().getLogger().warning("An exception occurred while a player was picking up a floating item. It's probably caused by another plugin using Holographic Displays as library.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is never added to the inventory.
|
// It is never added to the inventory.
|
||||||
@ -136,6 +145,20 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
@Override
|
@Override
|
||||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
|
if (newItem.tag == null) {
|
||||||
|
newItem.tag = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound display = newItem.tag.getCompound("display");
|
||||||
|
|
||||||
|
if (!newItem.tag.hasKey("display")) {
|
||||||
|
newItem.tag.set("display", display);
|
||||||
|
}
|
||||||
|
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
|
||||||
|
|
||||||
|
display.set("Lore", tagList);
|
||||||
newItem.count = 0;
|
newItem.count = 0;
|
||||||
setItemStack(newItem);
|
setItemStack(newItem);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@ import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
|
|||||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
||||||
import com.gmail.filoghost.holograms.object.HologramBase;
|
import com.gmail.filoghost.holograms.object.HologramBase;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R1.EntityItem;
|
import net.minecraft.server.v1_7_R1.EntityItem;
|
||||||
import net.minecraft.server.v1_7_R1.ItemStack;
|
import net.minecraft.server.v1_7_R1.ItemStack;
|
||||||
@ -15,6 +17,8 @@ import net.minecraft.server.v1_7_R1.NBTTagCompound;
|
|||||||
import net.minecraft.server.v1_7_R1.World;
|
import net.minecraft.server.v1_7_R1.World;
|
||||||
import net.minecraft.server.v1_7_R1.EntityHuman;
|
import net.minecraft.server.v1_7_R1.EntityHuman;
|
||||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_7_R1.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_7_R1.NBTTagString;
|
||||||
|
|
||||||
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
||||||
|
|
||||||
@ -60,7 +64,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
|
|
||||||
FloatingItem floatingItemParent = (FloatingItem) parent;
|
FloatingItem floatingItemParent = (FloatingItem) parent;
|
||||||
if (floatingItemParent.hasPickupHandler()) {
|
if (floatingItemParent.hasPickupHandler()) {
|
||||||
|
try {
|
||||||
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
HolographicDisplays.getInstance().getLogger().warning("An exception occurred while a player was picking up a floating item. It's probably caused by another plugin using Holographic Displays as library.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is never added to the inventory.
|
// It is never added to the inventory.
|
||||||
@ -136,6 +145,20 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
@Override
|
@Override
|
||||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
|
if (newItem.tag == null) {
|
||||||
|
newItem.tag = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound display = newItem.tag.getCompound("display");
|
||||||
|
|
||||||
|
if (!newItem.tag.hasKey("display")) {
|
||||||
|
newItem.tag.set("display", display);
|
||||||
|
}
|
||||||
|
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
|
||||||
|
|
||||||
|
display.set("Lore", tagList);
|
||||||
newItem.count = 0;
|
newItem.count = 0;
|
||||||
setItemStack(newItem);
|
setItemStack(newItem);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@ import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
|
|||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
||||||
import com.gmail.filoghost.holograms.object.HologramBase;
|
import com.gmail.filoghost.holograms.object.HologramBase;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityItem;
|
import net.minecraft.server.v1_7_R2.EntityItem;
|
||||||
import net.minecraft.server.v1_7_R2.ItemStack;
|
import net.minecraft.server.v1_7_R2.ItemStack;
|
||||||
@ -15,6 +17,8 @@ import net.minecraft.server.v1_7_R2.NBTTagCompound;
|
|||||||
import net.minecraft.server.v1_7_R2.World;
|
import net.minecraft.server.v1_7_R2.World;
|
||||||
import net.minecraft.server.v1_7_R2.EntityHuman;
|
import net.minecraft.server.v1_7_R2.EntityHuman;
|
||||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_7_R2.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_7_R2.NBTTagString;
|
||||||
|
|
||||||
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
||||||
|
|
||||||
@ -60,7 +64,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
|
|
||||||
FloatingItem floatingItemParent = (FloatingItem) parent;
|
FloatingItem floatingItemParent = (FloatingItem) parent;
|
||||||
if (floatingItemParent.hasPickupHandler()) {
|
if (floatingItemParent.hasPickupHandler()) {
|
||||||
|
try {
|
||||||
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
HolographicDisplays.getInstance().getLogger().warning("An exception occurred while a player was picking up a floating item. It's probably caused by another plugin using Holographic Displays as library.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is never added to the inventory.
|
// It is never added to the inventory.
|
||||||
@ -136,6 +145,20 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
@Override
|
@Override
|
||||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
|
if (newItem.tag == null) {
|
||||||
|
newItem.tag = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound display = newItem.tag.getCompound("display");
|
||||||
|
|
||||||
|
if (!newItem.tag.hasKey("display")) {
|
||||||
|
newItem.tag.set("display", display);
|
||||||
|
}
|
||||||
|
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
|
||||||
|
|
||||||
|
display.set("Lore", tagList);
|
||||||
newItem.count = 0;
|
newItem.count = 0;
|
||||||
setItemStack(newItem);
|
setItemStack(newItem);
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,18 @@ import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack;
|
|||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
||||||
import com.gmail.filoghost.holograms.object.HologramBase;
|
import com.gmail.filoghost.holograms.object.HologramBase;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_7_R3.NBTTagList;
|
||||||
import net.minecraft.server.v1_7_R3.EntityItem;
|
import net.minecraft.server.v1_7_R3.EntityItem;
|
||||||
import net.minecraft.server.v1_7_R3.ItemStack;
|
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||||
import net.minecraft.server.v1_7_R3.NBTTagCompound;
|
import net.minecraft.server.v1_7_R3.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_7_R3.NBTTagString;
|
||||||
import net.minecraft.server.v1_7_R3.World;
|
import net.minecraft.server.v1_7_R3.World;
|
||||||
import net.minecraft.server.v1_7_R3.EntityHuman;
|
import net.minecraft.server.v1_7_R3.EntityHuman;
|
||||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||||
@ -59,7 +63,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
|
|
||||||
FloatingItem floatingItemParent = (FloatingItem) parent;
|
FloatingItem floatingItemParent = (FloatingItem) parent;
|
||||||
if (floatingItemParent.hasPickupHandler()) {
|
if (floatingItemParent.hasPickupHandler()) {
|
||||||
|
try {
|
||||||
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
HolographicDisplays.getInstance().getLogger().warning("An exception occurred while a player was picking up a floating item. It's probably caused by another plugin using Holographic Displays as library.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is never added to the inventory.
|
// It is never added to the inventory.
|
||||||
@ -135,6 +144,20 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
@Override
|
@Override
|
||||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
|
if (newItem.tag == null) {
|
||||||
|
newItem.tag = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound display = newItem.tag.getCompound("display");
|
||||||
|
|
||||||
|
if (!newItem.tag.hasKey("display")) {
|
||||||
|
newItem.tag.set("display", display);
|
||||||
|
}
|
||||||
|
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
|
||||||
|
|
||||||
|
display.set("Lore", tagList);
|
||||||
newItem.count = 0;
|
newItem.count = 0;
|
||||||
setItemStack(newItem);
|
setItemStack(newItem);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.gmail.filoghost.holograms.nms.v1_7_R4;
|
package com.gmail.filoghost.holograms.nms.v1_7_R4;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_7_R4.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_7_R4.NBTTagString;
|
||||||
import net.minecraft.server.v1_7_R4.EntityHuman;
|
import net.minecraft.server.v1_7_R4.EntityHuman;
|
||||||
import net.minecraft.server.v1_7_R4.EntityItem;
|
import net.minecraft.server.v1_7_R4.EntityItem;
|
||||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
||||||
@ -11,10 +13,12 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
|
|||||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
import com.gmail.filoghost.holograms.api.FloatingItem;
|
import com.gmail.filoghost.holograms.api.FloatingItem;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
|
||||||
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
|
||||||
import com.gmail.filoghost.holograms.object.HologramBase;
|
import com.gmail.filoghost.holograms.object.HologramBase;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
|
|
||||||
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
|
||||||
|
|
||||||
@ -60,7 +64,12 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
|
|
||||||
FloatingItem floatingItemParent = (FloatingItem) parent;
|
FloatingItem floatingItemParent = (FloatingItem) parent;
|
||||||
if (floatingItemParent.hasPickupHandler()) {
|
if (floatingItemParent.hasPickupHandler()) {
|
||||||
|
try {
|
||||||
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
floatingItemParent.getPickupHandler().onPickup(floatingItemParent, (Player) human.getBukkitEntity());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
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.
|
// It is never added to the inventory.
|
||||||
@ -136,6 +145,20 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
|
|||||||
@Override
|
@Override
|
||||||
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
|
||||||
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
|
if (newItem.tag == null) {
|
||||||
|
newItem.tag = new NBTTagCompound();
|
||||||
|
}
|
||||||
|
NBTTagCompound display = newItem.tag.getCompound("display");
|
||||||
|
|
||||||
|
if (!newItem.tag.hasKey("display")) {
|
||||||
|
newItem.tag.set("display", display);
|
||||||
|
}
|
||||||
|
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
tagList.add(new NBTTagString(ItemUtils.ANTISTACK_LORE)); // Antistack lore
|
||||||
|
|
||||||
|
display.set("Lore", tagList);
|
||||||
newItem.count = 0;
|
newItem.count = 0;
|
||||||
setItemStack(newItem);
|
setItemStack(newItem);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class ProtocolLibHook {
|
|||||||
|
|
||||||
HolographicDisplays.getInstance().getLogger().info("Found ProtocolLib, adding support for player relative variables.");
|
HolographicDisplays.getInstance().getLogger().info("Found ProtocolLib, adding support for player relative variables.");
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HolographicDisplays.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SPAWN_ENTITY_LIVING, PacketType.Play.Server.ENTITY_METADATA) {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HolographicDisplays.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SPAWN_ENTITY_LIVING, PacketType.Play.Server.SPAWN_ENTITY, PacketType.Play.Server.ENTITY_METADATA) {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,8 +74,16 @@ public class ProtocolLibHook {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entity metadata packet
|
} else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) {
|
||||||
} else {
|
|
||||||
|
WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet);
|
||||||
|
|
||||||
|
if (spawnEntityPacket.getType() == WrapperPlayServerSpawnEntity.ObjectTypes.ITEM_STACK) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else { // Entity metadata packet
|
||||||
|
|
||||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||||
Entity entity = entityMetadataPacket.getEntity(event);
|
Entity entity = entityMetadataPacket.getEntity(event);
|
||||||
|
@ -22,6 +22,6 @@ public class WorldPlayerCounterTask implements Runnable {
|
|||||||
|
|
||||||
public static String getCount(String world) {
|
public static String getCount(String world) {
|
||||||
Integer count = worlds.get(world);
|
Integer count = worlds.get(world);
|
||||||
return count != null ? count.toString() : "world not found";
|
return count != null ? count.toString() : "[World \"" + world + "\" not found]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
public class ItemUtils {
|
public class ItemUtils {
|
||||||
|
|
||||||
|
public static final String ANTISTACK_LORE = ChatColor.BLACK + "" + Math.random();
|
||||||
|
|
||||||
public static ItemStack getStone(String title, List<String> lore, ChatColor defaultLoreColor) {
|
public static ItemStack getStone(String title, List<String> lore, ChatColor defaultLoreColor) {
|
||||||
return getItem(Material.STONE, title, lore, defaultLoreColor);
|
return getItem(Material.STONE, title, lore, defaultLoreColor);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user