Add individual floating items, bug fix with Protocol Lib.

This commit is contained in:
filoghost 2014-08-30 14:25:41 +02:00
parent 7ca30a1f2f
commit 9023427635
17 changed files with 544 additions and 77 deletions

View File

@ -121,7 +121,52 @@ public class HolographicDisplaysAPI {
return hologram;
}
//TODO individual floating item
/**
* Creates a floating item at given location that only a player can see. If the provided player is null, no one will be able to see it.
* IMPORTANT NOTE: Requires ProtocolLib.
* @param plugin - the plugin that creates it.
* @param source - the location where it will appear.
* @param whoCanSee - the player who can see it.
* @param itemstack - the floating item that will appear.
* @return the new hologram created.
*/
public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, Player whoCanSee, ItemStack itemstack) {
return createIndividualFloatingItem(plugin, source, GenericUtils.createList(whoCanSee), itemstack);
}
/**
* Creates a floating item at given location that only a list of players can see. If the provided list is null, no one will be able to see it.
* IMPORTANT NOTE: Requires ProtocolLib.
* @param plugin - the plugin that creates it.
* @param source - the location where it will appear.
* @param whoCanSee - a list of players who can see it.
* @param itemstack - the floating item that will appear.
* @return the new hologram created.
*/
public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, List<Player> whoCanSee, ItemStack itemstack) {
Validator.notNull(plugin, "plugin cannot be null");
Validator.notNull(source, "source cannot be null");
Validator.notNull(source.getWorld(), "source's world cannot be null");
Validator.notNull(itemstack, "itemstack cannot be null");
Validator.checkArgument(itemstack.getType() != Material.AIR, "itemstack cannot be AIR");
CraftFloatingItem floatingItem = new CraftFloatingItem(source, itemstack);
VisibilityManager visibilityManager = new VisibilityManager();
floatingItem.setVisibilityManager(visibilityManager);
if (whoCanSee != null) {
for (Player player : whoCanSee) {
floatingItem.getVisibilityManager().showTo(player);
}
}
APIFloatingItemManager.addFloatingItem(plugin, floatingItem);
floatingItem.update();
return floatingItem;
}
/**
* @return a copy of all the holograms created with the API by a plugin.

View File

@ -30,6 +30,7 @@ public class HologramsCommandHandler implements CommandExecutor {
registerSubCommand(new NearCommand());
registerSubCommand(new TeleportCommand());
registerSubCommand(new MovehereCommand());
registerSubCommand(new AlignCommand());
registerSubCommand(new FixCommand());
registerSubCommand(new SaveCommand());
registerSubCommand(new ReloadCommand());

View File

@ -0,0 +1,69 @@
package com.gmail.filoghost.holograms.commands.main.subs;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import com.gmail.filoghost.holograms.commands.CommandValidator;
import com.gmail.filoghost.holograms.commands.Messages;
import com.gmail.filoghost.holograms.commands.main.HologramSubCommand;
import com.gmail.filoghost.holograms.database.HologramDatabase;
import com.gmail.filoghost.holograms.exception.CommandException;
import com.gmail.filoghost.holograms.object.CraftHologram;
import com.gmail.filoghost.holograms.object.HologramManager;
import com.gmail.filoghost.holograms.utils.Format;
public class AlignCommand extends HologramSubCommand {
public AlignCommand() {
super("align");
setPermission(Messages.BASE_PERM + "align");
}
@Override
public String getPossibleArguments() {
return "<hologramToAlign> <referenceHologram>";
}
@Override
public int getMinimumArguments() {
return 2;
}
@Override
public void execute(CommandSender sender, String[] args) throws CommandException {
CraftHologram hologram = HologramManager.getHologram(args[0].toLowerCase());
CraftHologram referenceHologram = HologramManager.getHologram(args[1].toLowerCase());
CommandValidator.notNull(hologram, Messages.NO_SUCH_HOLOGRAM + " (hologram to align)");
CommandValidator.notNull(referenceHologram, Messages.NO_SUCH_HOLOGRAM + " (reference hologram)");
CommandValidator.isTrue(hologram != referenceHologram, "The hologram must not be the same!");
Location loc = hologram.getLocation();
loc.setY(referenceHologram.getY());
hologram.setLocation(loc);
if (!hologram.update()) {
sender.sendMessage(Messages.FAILED_TO_SPAWN_HERE);
}
HologramDatabase.saveHologram(hologram);
HologramDatabase.trySaveToDisk();
sender.sendMessage(Format.HIGHLIGHT + "Hologram \"" + hologram.getName() + "\" vertically aligned to the hologram \"" + referenceHologram.getName() + "\".");
}
@Override
public List<String> getTutorial() {
return Arrays.asList("Vertically aligns the first hologram to the second.");
}
@Override
public SubCommandType getType() {
return SubCommandType.GENERIC;
}
}

View File

@ -50,7 +50,7 @@ public class SaveCommand extends HologramSubCommand {
@Override
public SubCommandType getType() {
return SubCommandType.GENERIC;
return SubCommandType.HIDDEN;
}
}

View File

@ -9,13 +9,13 @@ public interface NmsManager {
public void registerCustomEntities() throws Exception;
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException;
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException;
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException;
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException;
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException;
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException;
public TouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException;
public TouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException;
public boolean isHologramComponent(org.bukkit.entity.Entity bukkitEntity);

View File

@ -46,9 +46,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setParentHologram(parent);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -57,9 +58,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setParentHologram(parent);
staticWitherSkull.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -68,9 +70,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setParentHologram(parent);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
@ -80,9 +83,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setParentHologram(parent);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();

View File

@ -46,9 +46,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setParentHologram(parent);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -57,9 +58,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setParentHologram(parent);
staticWitherSkull.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -68,9 +70,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setParentHologram(parent);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
@ -80,9 +83,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setParentHologram(parent);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();

View File

@ -46,9 +46,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setParentHologram(parent);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -57,9 +58,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setParentHologram(parent);
staticWitherSkull.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -69,9 +71,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setParentHologram(parent);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
@ -82,9 +85,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setParentHologram(parent);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();

View File

@ -46,9 +46,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setParentHologram(parent);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -57,9 +58,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setParentHologram(parent);;
staticWitherSkull.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -69,9 +71,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setParentHologram(parent);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
@ -82,9 +85,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setParentHologram(parent);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -111,7 +115,7 @@ public class NmsManagerImpl implements NmsManager {
if (nmsEntity instanceof HologramComponent) {
return ((HologramComponent) nmsEntity).getParentHologram();
}
return null;
}

View File

@ -46,9 +46,10 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setParentHologram(parent);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
@ -57,10 +58,11 @@ public class NmsManagerImpl implements NmsManager {
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setLocationNMS(x, y, z);
staticWitherSkull.setParentHologram(parent);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
}
@ -69,9 +71,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setParentHologram(parent);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
@ -82,9 +85,10 @@ public class NmsManagerImpl implements NmsManager {
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z, HologramBase parent) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setParentHologram(parent);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();

View File

@ -19,7 +19,6 @@ import com.gmail.filoghost.holograms.object.pieces.FloatingItemDoubleEntity;
import com.gmail.filoghost.holograms.object.pieces.FloatingTouchSlimeDoubleEntity;
import com.gmail.filoghost.holograms.object.pieces.HologramLine;
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.
@ -30,8 +29,6 @@ public class CraftHologram extends HologramBase implements Hologram {
protected List<FloatingDoubleEntity> linesEntities;
protected List<String> textLines;
protected VisibilityManager visibilityManager;
protected long creationTimestamp;
protected FloatingTouchSlimeDoubleEntity touchSlimeEntity;
@ -89,18 +86,6 @@ public class CraftHologram extends HologramBase implements Hologram {
public long getCreationTimestamp() {
return creationTimestamp;
}
public void setVisibilityManager(VisibilityManager visibilityManager) {
this.visibilityManager = visibilityManager;
}
public boolean hasVisibilityManager() {
return visibilityManager != null;
}
public VisibilityManager getVisibilityManager() {
return visibilityManager;
}
public void setTouchHandler(TouchHandler touchHandler) {
this.touchHandler = touchHandler;

View File

@ -5,6 +5,7 @@ import org.bukkit.Location;
import org.bukkit.World;
import com.gmail.filoghost.holograms.utils.Validator;
import com.gmail.filoghost.holograms.utils.VisibilityManager;
public abstract class HologramBase {
@ -17,6 +18,8 @@ public abstract class HologramBase {
protected int chunkX;
protected int chunkZ;
protected VisibilityManager visibilityManager;
private boolean deleted;
protected HologramBase(String name, Location source) {
@ -81,6 +84,18 @@ public abstract class HologramBase {
return bukkitWorld.isChunkLoaded(chunkX, chunkZ);
}
public void setVisibilityManager(VisibilityManager visibilityManager) {
this.visibilityManager = visibilityManager;
}
public boolean hasVisibilityManager() {
return visibilityManager != null;
}
public VisibilityManager getVisibilityManager() {
return visibilityManager;
}
public final void delete() {
deleted = true;
onDeleteEvent();

View File

@ -28,14 +28,11 @@ public class FloatingItemDoubleEntity extends FloatingDoubleEntity {
public void spawn(HologramBase parent, World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
despawn();
item = nmsManager.spawnCustomItem(bukkitWorld, x, y + VERTICAL_OFFSET, z, itemStack);
item.setParentHologram(parent);
item = nmsManager.spawnCustomItem(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent, itemStack);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent);
item.allowPickup(allowPickup);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z);
skull.setParentHologram(parent);
// Let the item ride the wither skull.
skull.setPassengerNMS(item);

View File

@ -23,11 +23,8 @@ public class FloatingTouchSlimeDoubleEntity extends FloatingDoubleEntity {
public void spawn(HologramBase parent, World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
despawn();
slime = nmsManager.spawnTouchSlime(bukkitWorld, x, y + VERTICAL_OFFSET, z);
slime.setParentHologram(parent);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z);
skull.setParentHologram(parent);
slime = nmsManager.spawnTouchSlime(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent);
// Let the slime ride the wither skull.
skull.setPassengerNMS(slime);

View File

@ -29,12 +29,9 @@ public class HologramLine extends FloatingDoubleEntity {
public void spawn(HologramBase parent, World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
despawn();
horse = nmsManager.spawnHologramHorse(bukkitWorld, x, y + VERTICAL_OFFSET, z);
horse.setParentHologram(parent);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z);
skull.setParentHologram(parent);
horse = nmsManager.spawnHologramHorse(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent);
skull = nmsManager.spawnHologramWitherSkull(bukkitWorld, x, y + VERTICAL_OFFSET, z, parent);
// Let the horse ride the wither skull.
skull.setPassengerNMS(horse);

View File

@ -1,5 +1,7 @@
package com.gmail.filoghost.holograms.protocol;
import static com.gmail.filoghost.holograms.HolographicDisplays.nmsManager;
import java.util.List;
import org.bukkit.Bukkit;
@ -16,11 +18,8 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.gmail.filoghost.holograms.HolographicDisplays;
import com.gmail.filoghost.holograms.object.CraftHologram;
import com.gmail.filoghost.holograms.object.HologramBase;
import static com.gmail.filoghost.holograms.HolographicDisplays.nmsManager;
public class ProtocolLibHook {
public static void initialize() {
@ -46,13 +45,13 @@ public class ProtocolLibHook {
return;
}
CraftHologram hologram = getHologram(entity);
if (hologram == null) {
HologramBase hologramBase = getHologram(entity);
if (hologramBase == null) {
return;
}
Player player = event.getPlayer();
if (hologram.hasVisibilityManager() && !hologram.getVisibilityManager().isVisibleTo(player)) {
if (hologramBase.hasVisibilityManager() && !hologramBase.getVisibilityManager().isVisibleTo(player)) {
event.setCancelled(true);
return;
}
@ -77,11 +76,25 @@ public class ProtocolLibHook {
} else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) {
WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet);
if (spawnEntityPacket.getType() == WrapperPlayServerSpawnEntity.ObjectTypes.ITEM_STACK) {
//TODO
if (spawnEntityPacket.getType() != WrapperPlayServerSpawnEntity.ObjectTypes.ITEM_STACK) {
return;
}
Entity entity = spawnEntityPacket.getEntity(event);
if (entity == null) {
return;
}
HologramBase hologramBase = getHologram(entity);
if (hologramBase == null) {
return;
}
Player player = event.getPlayer();
if (hologramBase.hasVisibilityManager() && !hologramBase.getVisibilityManager().isVisibleTo(player)) {
event.setCancelled(true);
return;
}
} else { // Entity metadata packet
@ -92,13 +105,13 @@ public class ProtocolLibHook {
return;
}
CraftHologram hologram = getHologram(entity);
if (hologram == null) {
HologramBase hologramBase = getHologram(entity);
if (hologramBase == null) {
return;
}
Player player = event.getPlayer();
if (hologram.hasVisibilityManager() && !hologram.getVisibilityManager().isVisibleTo(player)) {
if (hologramBase.hasVisibilityManager() && !hologramBase.getVisibilityManager().isVisibleTo(player)) {
event.setCancelled(true);
return;
}
@ -145,12 +158,7 @@ public class ProtocolLibHook {
}
// Horses are always part of a CraftHologram
private static CraftHologram getHologram(Entity bukkitEntity) {
HologramBase base = nmsManager.getParentHologram(bukkitEntity);
if (base instanceof CraftHologram) {
return (CraftHologram) base;
} else {
return null;
}
private static HologramBase getHologram(Entity bukkitEntity) {
return nmsManager.getParentHologram(bukkitEntity);
}
}

View File

@ -0,0 +1,333 @@
/*
* PacketWrapper - Contains wrappers for each packet in Minecraft.
* Copyright (C) 2012 Kristian S. Stangeland
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
package com.gmail.filoghost.holograms.protocol;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.IntEnum;
public class WrapperPlayServerSpawnEntity extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
private static PacketConstructor entityConstructor;
/**
* Represents the different object types.
*
* @author Kristian
*/
public static class ObjectTypes extends IntEnum {
public static final int BOAT = 1;
public static final int ITEM_STACK = 2;
public static final int MINECART = 10;
public static final int MINECART_STORAGE = 11;
public static final int MINECART_POWERED = 12;
public static final int ACTIVATED_TNT = 50;
public static final int ENDER_CRYSTAL = 51;
public static final int ARROW_PROJECTILE = 60;
public static final int SNOWBALL_PROJECTILE = 61;
public static final int EGG_PROJECTILE = 62;
public static final int FIRE_BALL_GHAST = 63;
public static final int FIRE_BALL_BLAZE = 64;
public static final int THROWN_ENDERPEARL = 65;
public static final int WITHER_SKULL = 66;
public static final int FALLING_BLOCK = 70;
public static final int ITEM_FRAME = 71;
public static final int EYE_OF_ENDER = 72;
public static final int THROWN_POTION = 73;
public static final int FALLING_DRAGON_EGG = 74;
public static final int THROWN_EXP_BOTTLE = 75;
public static final int FIREWORK = 76;
public static final int FISHING_FLOAT = 90;
/**
* The singleton instance. Can also be retrieved from the parent class.
*/
private static ObjectTypes INSTANCE = new ObjectTypes();
/**
* Retrieve an instance of the object types enum.
* @return Object type enum.
*/
public static ObjectTypes getInstance() {
return INSTANCE;
}
}
public WrapperPlayServerSpawnEntity() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerSpawnEntity(PacketContainer packet) {
super(packet, TYPE);
}
public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) {
super(fromEntity(entity, type, objectData), TYPE);
}
// Useful constructor
private static PacketContainer fromEntity(Entity entity, int type, int objectData) {
if (entityConstructor == null)
entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, type, objectData);
return entityConstructor.createPacket(entity, type, objectData);
}
/**
* Retrieve entity ID of the Object.
* @return The current EID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
/**
* Retrieve the entity that will be spawned.
* @param world - the current world of the entity.
* @return The spawned entity.
*/
public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0);
}
/**
* Retrieve the entity that will be spawned.
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
/**
* Set entity ID of the Object.
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve the type of object. See {@link ObjectTypes}
* @return The current Type
*/
public int getType() {
return handle.getIntegers().read(9);
}
/**
* Set the type of object. See {@link ObjectTypes}.
* @param value - new value.
*/
public void setType(int value) {
handle.getIntegers().write(9, value);
}
/**
* Retrieve the x position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* @return The current X
*/
public double getX() {
return handle.getIntegers().read(1) / 32.0D;
}
/**
* Set the x position of the object.
* @param value - new value.
*/
public void setX(double value) {
handle.getIntegers().write(1, (int) Math.floor(value * 32.0D));
}
/**
* Retrieve the y position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* @return The current y
*/
public double getY() {
return handle.getIntegers().read(2) / 32.0D;
}
/**
* Set the y position of the object.
* @param value - new value.
*/
public void setY(double value) {
handle.getIntegers().write(2, (int) Math.floor(value * 32.0D));
}
/**
* Retrieve the z position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
* @return The current z
*/
public double getZ() {
return handle.getIntegers().read(3) / 32.0D;
}
/**
* Set the z position of the object.
* @param value - new value.
*/
public void setZ(double value) {
handle.getIntegers().write(3, (int) Math.floor(value * 32.0D));
}
/**
* Retrieve the optional speed x.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
* @return The optional speed x.
*/
public double getOptionalSpeedX() {
return handle.getIntegers().read(4) / 8000.0D;
}
/**
* Set the optional speed x.
* @param value - new value.
*/
public void setOptionalSpeedX(double value) {
handle.getIntegers().write(4, (int) (value * 8000.0D));
}
/**
* Retrieve the optional speed y.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
* @return The optional speed y.
*/
public double getOptionalSpeedY() {
return handle.getIntegers().read(5) / 8000.0D;
}
/**
* Set the optional speed y.
* @param value - new value.
*/
public void setOptionalSpeedY(double value) {
handle.getIntegers().write(5, (int) (value * 8000.0D));
}
/**
* Retrieve the optional speed z.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
* @return The optional speed z.
*/
public double getOptionalSpeedZ() {
return handle.getIntegers().read(6) / 8000.0D;
}
/**
* Set the optional speed z.
* @param value - new value.
*/
public void setOptionalSpeedZ(double value) {
handle.getIntegers().write(6, (int) (value * 8000.0D));
}
/**
* Retrieve the yaw.
* @return The current Yaw
*/
public float getYaw() {
return (handle.getIntegers().read(7) * 360.F) / 256.0F;
}
/**
* Set the yaw of the object spawned.
* @param value - new yaw.
*/
public void setYaw(float value) {
handle.getIntegers().write(7, (int) (value * 256.0F / 360.0F));
}
/**
* Retrieve the pitch.
* @return The current pitch.
*/
public float getPitch() {
return (handle.getIntegers().read(8) * 360.F) / 256.0F;
}
/**
* Set the pitch.
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getIntegers().write(8, (int) (value * 256.0F / 360.0F));
}
/**
* Retrieve object data.
* <p>
* The content depends on the object type:
* <table border="1" cellpadding="4">
* <tr>
* <th>Object Type:</th>
* <th>Name:</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>ITEM_FRAME</td>
* <td>Orientation</td>
* <td>0-3: South, West, North, East</td>
* </tr>
* <tr>
* <td>FALLING_BLOCK</td>
* <td>Block Type</td>
* <td>BlockID | (Metadata << 0xC)</td>
* </tr>
* <tr>
* <td>Projectiles</td>
* <td>Entity ID</td>
* <td>The entity ID of the thrower</td>
* </tr>
* <tr>
* <td>Splash Potions</td>
* <td>Data Value</td>
* <td>Potion data value.</td>
* </tr>
* </table>
* @return The current object Data
*/
public int getObjectData() {
return handle.getIntegers().read(10);
}
/**
* Set object Data.
* <p>
* The content depends on the object type. See {@link #getObjectData()} for more information.
* @param value - new object data.
*/
public void setObjectData(int value) {
handle.getIntegers().write(10, value);
}
}