Update to v1.7.10 and fix /hd near command.

This commit is contained in:
filoghost 2014-07-14 10:22:18 +02:00
parent 112a2a8f43
commit 239fa82a8c
21 changed files with 1108 additions and 66 deletions

View File

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

View File

@ -122,7 +122,6 @@ public class HolographicDisplays extends JavaPlugin {
version = null;
}
}
// It's simple, we don't need reflection.
if ("v1_6_R3".equals(version)) {
@ -133,6 +132,8 @@ public class HolographicDisplays extends JavaPlugin {
nmsManager = new com.gmail.filoghost.holograms.nms.v1_7_R2.NmsManagerImpl();
} else if ("v1_7_R3".equals(version)) {
nmsManager = new com.gmail.filoghost.holograms.nms.v1_7_R3.NmsManagerImpl();
} else if ("v1_7_R4".equals(version)) {
nmsManager = new com.gmail.filoghost.holograms.nms.v1_7_R4.NmsManagerImpl();
} else {
printWarnAndDisable(
"******************************************************",
@ -146,18 +147,14 @@ public class HolographicDisplays extends JavaPlugin {
}
try {
if (VersionUtils.isMCPC()) {
getLogger().info("Trying to enable MCPC+ support...");
} else if (VersionUtils.isCauldron()) {
getLogger().info("Trying to enable Cauldron support...");
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
getLogger().info("Trying to enable Cauldron/MCPC+ support...");
}
nmsManager.registerCustomEntities();
if (VersionUtils.isMCPC()) {
getLogger().info("Successfully added support for MCPC+!");
} else if (VersionUtils.isCauldron()) {
getLogger().info("Successfully added support for Cauldron!");
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
getLogger().info("Successfully added support for Cauldron/MCPC+!");
}
} catch (Exception e) {
@ -284,7 +281,7 @@ public class HolographicDisplays extends JavaPlugin {
}
String tempColor = ConfigNode.TRANSPARENCY_COLOR.getString(getConfig()).replace("&", "§");
String tempColor = ConfigNode.TRANSPARENCY_COLOR.getString(getConfig()).replace("&", "§");
boolean foundColor = false;
for (ChatColor chatColor : ChatColor.values()) {
if (chatColor.toString().equals(tempColor)) {

View File

@ -57,8 +57,7 @@ public class BungeeChannel implements PluginMessageListener {
}
} catch (EOFException e) {
//TODO
System.out.println("Not online!");
// Do nothing.
} catch (IOException e) {
// This should never happen.
e.printStackTrace();

View File

@ -57,9 +57,9 @@ public class HologramsCommandHandler implements CommandExecutor {
if (args.length == 0) {
sender.sendMessage("");
sender.sendMessage(Format.formatTitle("Holographic Displays"));
sender.sendMessage(Format.HIGHLIGHT + "Version: §7" + HolographicDisplays.getInstance().getDescription().getVersion());
sender.sendMessage(Format.HIGHLIGHT + "Developer: §7filoghost");
sender.sendMessage(Format.HIGHLIGHT + "Commands: §7/hd help");
sender.sendMessage(Format.HIGHLIGHT + "Version: §7" + HolographicDisplays.getInstance().getDescription().getVersion());
sender.sendMessage(Format.HIGHLIGHT + "Developer: §7filoghost");
sender.sendMessage(Format.HIGHLIGHT + "Commands: §7/hd help");
return true;
}
@ -67,7 +67,7 @@ public class HologramsCommandHandler implements CommandExecutor {
if (subCommand.isValidTrigger(args[0])) {
if (!subCommand.hasPermission(sender)) {
sender.sendMessage("§cYou don't have permission.");
sender.sendMessage(RED + "You don't have permission.");
return true;
}
@ -78,14 +78,14 @@ public class HologramsCommandHandler implements CommandExecutor {
sender.sendMessage(RED + e.getMessage());
}
} else {
sender.sendMessage("§cUsage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments());
sender.sendMessage(RED + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments());
}
return true;
}
}
sender.sendMessage("§cUnknown sub-command. Type \"/hd help\" for a list of commands.");
sender.sendMessage(RED + "Unknown sub-command. Type \"/hd help\" for a list of commands.");
return true;
}
}

View File

@ -3,7 +3,6 @@ package com.gmail.filoghost.holograms.commands.main.subs;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -13,7 +12,6 @@ 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.event.HologramMoveEvent;
import com.gmail.filoghost.holograms.exception.CommandException;
import com.gmail.filoghost.holograms.object.CraftHologram;
import com.gmail.filoghost.holograms.object.HologramManager;
@ -55,9 +53,6 @@ public class MovehereCommand extends HologramSubCommand {
to.setPitch(90);
player.teleport(to, TeleportCause.PLUGIN);
player.sendMessage(Format.HIGHLIGHT + "You moved the hologram '" + hologram.getName() + "' near to you.");
// Call the event.
Bukkit.getPluginManager().callEvent(new HologramMoveEvent(hologram));
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -38,11 +39,12 @@ public class NearCommand extends HologramSubCommand {
int radius = CommandValidator.getInteger(args[0]);
CommandValidator.isTrue(radius > 0, "Radius must be at least 1.");
World world = player.getWorld();
int radiusSquared = radius * radius;
List<CraftHologram> nearHolograms = new ArrayList<CraftHologram>();
for (CraftHologram hologram : HologramManager.getHolograms()) {
if (hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) {
if (hologram.getLocation().getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) {
nearHolograms.add(hologram);
}
}

View File

@ -1,33 +0,0 @@
package com.gmail.filoghost.holograms.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gmail.filoghost.holograms.api.Hologram;
/**
* Called after that a hologram is moved with /hd movehere <hologram>
*/
public class HologramMoveEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Hologram hologram;
public HologramMoveEvent(Hologram hologram) {
this.hologram = hologram;
}
public Hologram getHologram() {
return hologram;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -6,12 +6,17 @@ import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_6_R3.Block;
import net.minecraft.server.v1_6_R3.EntityItem;
import net.minecraft.server.v1_6_R3.NBTTagCompound;
import net.minecraft.server.v1_6_R3.World;
import net.minecraft.server.v1_6_R3.ItemStack;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Block.STONE, 0);
private boolean lockTick;
private CraftHologram parent;
@ -66,6 +71,11 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {
@ -103,7 +113,9 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@Override
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
setItemStack( CraftItemStack.asNMSCopy(stack) );
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
newItem.count = 0;
setItemStack(newItem);
}
@Override

View File

@ -1,18 +1,22 @@
package com.gmail.filoghost.holograms.nms.v1_7_R1;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R1.EntityItem;
import net.minecraft.server.v1_7_R1.ItemStack;
import net.minecraft.server.v1_7_R1.NBTTagCompound;
import net.minecraft.server.v1_7_R1.World;
import net.minecraft.server.v1_7_R1.Blocks;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private CraftHologram parent;
@ -67,6 +71,11 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {
@ -104,7 +113,9 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@Override
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
setItemStack( new ItemStack(CraftMagicNumbers.getItem(stack.getType()), 1, stack.getDurability()) );
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
newItem.count = 0;
setItemStack(newItem);
}
@Override

View File

@ -1,18 +1,22 @@
package com.gmail.filoghost.holograms.nms.v1_7_R2;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R2.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftItemStack;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R2.EntityItem;
import net.minecraft.server.v1_7_R2.ItemStack;
import net.minecraft.server.v1_7_R2.NBTTagCompound;
import net.minecraft.server.v1_7_R2.World;
import net.minecraft.server.v1_7_R2.Blocks;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private CraftHologram parent;
@ -67,6 +71,11 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {
@ -104,7 +113,9 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@Override
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
setItemStack( new ItemStack(CraftMagicNumbers.getItem(stack.getType()), 1, stack.getDurability()) );
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
newItem.count = 0;
setItemStack(newItem);
}
@Override

View File

@ -1,11 +1,13 @@
package com.gmail.filoghost.holograms.nms.v1_7_R3;
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.util.CraftMagicNumbers;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R3.Blocks;
import net.minecraft.server.v1_7_R3.EntityItem;
import net.minecraft.server.v1_7_R3.ItemStack;
import net.minecraft.server.v1_7_R3.NBTTagCompound;
@ -13,6 +15,8 @@ import net.minecraft.server.v1_7_R3.World;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private CraftHologram parent;
@ -73,6 +77,11 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
lockTick = lock;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void die() {
setLockTick(false);
@ -104,9 +113,10 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@Override
public void setItemStackNMS(org.bukkit.inventory.ItemStack stack) {
setItemStack( new ItemStack(CraftMagicNumbers.getItem(stack.getType()), 1, stack.getDurability()) );
ItemStack newItem = CraftItemStack.asNMSCopy(stack);
newItem.count = 0;
setItemStack(newItem);
}
@Override
public CraftHologram getParentHologram() {

View File

@ -0,0 +1,40 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.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 CraftCustomItem extends CraftItem {
public CraftCustomItem(CraftServer server, EntityCustomItem 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) { }
// Methods from Item
@Override public void setItemStack(ItemStack stack) { }
@Override public void setPickupDelay(int delay) { }
}

View File

@ -0,0 +1,64 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import java.util.Collection;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHorse;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
public class CraftHologramHorse extends CraftHorse {
public CraftHologramHorse(CraftServer server, EntityHologramHorse 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 Horse class
@Override public void setVariant(Variant variant) { }
@Override public void setColor(Color color) { }
@Override public void setStyle(Style style) { }
@Override public void setCarryingChest(boolean chest) { }
@Override public void setDomestication(int domestication) { }
@Override public void setJumpStrength(double jump) { }
// Methods form Ageable class
@Override public void setAge(int age) { }
@Override public void setAgeLock(boolean lock) { }
@Override public void setBreed(boolean breed) { }
@Override public void setAdult() { }
@Override public void setBaby() { }
// 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) { }
// Methods from Tameable
@Override public void setTamed(boolean tame) { }
@Override public void setOwner(AnimalTamer owner) { }
}

View File

@ -0,0 +1,45 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftWitherSkull;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.Vector;
public class CraftHologramWitherSkull extends CraftWitherSkull {
public CraftHologramWitherSkull(CraftServer server, EntityHologramWitherSkull entity) {
super(server, entity);
}
// Disallow all the bukkit methods.
@Override
public void remove() {
// Cannot be removed, this is the most important to override.
}
// Method from Fireball
@Override public void setDirection(Vector dir) { }
// Method from Projectile
@Override public void setBounce(boolean bounce) { }
// Methods from Explosive
@Override public void setYield(float yield) { }
@Override public void setIsIncendiary(boolean fire) { }
// 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) { }
}

View File

@ -0,0 +1,48 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import java.util.Collection;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.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 CraftTouchSlime extends CraftSlime {
public CraftTouchSlime(CraftServer server, EntityTouchSlime 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) { }
// Methods from Slime
@Override public void setSize(int size) { }
}

View File

@ -0,0 +1,131 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R4.Blocks;
import net.minecraft.server.v1_7_R4.EntityItem;
import net.minecraft.server.v1_7_R4.ItemStack;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.World;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private CraftHologram parent;
public EntityCustomItem(World world) {
super(world);
super.pickupDelay = Integer.MAX_VALUE;
}
@Override
public void h() {
// Checks every 20 ticks.
if (ticksLived % 20 == 0) {
// The item dies without a vehicle.
if (this.vehicle == null) {
die();
}
}
if (!lockTick) {
super.h();
}
}
@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() {
/*
* 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 setLockTick(boolean lock) {
lockTick = lock;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void die() {
setLockTick(false);
super.die();
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftCustomItem(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);
newItem.count = 0;
setItemStack(newItem);
}
@Override
public CraftHologram getParentHologram() {
return parent;
}
@Override
public void setParentHologram(CraftHologram hologram) {
this.parent = hologram;
}
}

View File

@ -0,0 +1,150 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import com.gmail.filoghost.holograms.nms.interfaces.HologramHorse;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R4.EntityHorse;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.World;
public class EntityHologramHorse extends EntityHorse implements HologramHorse {
private boolean lockTick;
private CraftHologram parent;
public EntityHologramHorse(World world) {
super(world);
super.ageLocked = true;
super.persistent = true;
super.boundingBox.a = 0.0;
super.boundingBox.b = 0.0;
super.boundingBox.c = 0.0;
super.boundingBox.d = 0.0;
super.boundingBox.e = 0.0;
super.boundingBox.f = 0.0;
a(0.0F, 0.0F);
setAge(-1700000); // This is a magic value. No one will see the real horse.
}
@Override
public void h() {
// Checks every 20 ticks.
if (ticksLived % 20 == 0) {
// The horse dies without a vehicle.
if (this.vehicle == null) {
die();
}
}
if (!lockTick) {
super.h();
}
}
@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() {
/*
* 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 void forceSetCustomName(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null);
}
@Override
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftHologramHorse(this.world.getServer(), this);
}
return this.bukkitEntity;
}
@Override
public boolean isDeadNMS() {
return this.dead;
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
}
@Override
public void killEntityNMS() {
die();
}
@Override
public void setLocationNMS(double x, double y, double z) {
super.setPosition(x, y, z);
}
@Override
public CraftHologram getParentHologram() {
return parent;
}
@Override
public void setParentHologram(CraftHologram hologram) {
this.parent = hologram;
}
}

View File

@ -0,0 +1,141 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.HologramWitherSkull;
import com.gmail.filoghost.holograms.object.CraftHologram;
import net.minecraft.server.v1_7_R4.Entity;
import net.minecraft.server.v1_7_R4.EntityWitherSkull;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.World;
public class EntityHologramWitherSkull extends EntityWitherSkull implements HologramWitherSkull {
private boolean lockTick;
private CraftHologram parent;
public EntityHologramWitherSkull(World world) {
super(world);
super.motX = 0.0;
super.motY = 0.0;
super.motZ = 0.0;
super.dirX = 0.0;
super.dirY = 0.0;
super.dirZ = 0.0;
super.boundingBox.a = 0.0;
super.boundingBox.b = 0.0;
super.boundingBox.c = 0.0;
super.boundingBox.d = 0.0;
super.boundingBox.e = 0.0;
super.boundingBox.f = 0.0;
a(0.0F, 0.0F);
}
@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() {
/*
* 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 h() {
if (!lockTick) {
super.h();
}
}
@Override
public void makeSound(String sound, float f1, float f2) {
// Remove sounds.
}
public void callSuperTick() {
super.h();
}
@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 CraftHologramWitherSkull(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);
}
@Override
public boolean isDeadNMS() {
return this.dead;
}
@Override
public void setPassengerNMS(BasicEntityNMS passenger) {
if (passenger instanceof Entity) {
((Entity) passenger).setPassengerOf(this);
}
}
@Override
public void setPassengerNMS(org.bukkit.entity.Entity bukkitEntity) {
((CraftEntity) bukkitEntity).getHandle().setPassengerOf(this);
}
@Override
public CraftHologram getParentHologram() {
return parent;
}
@Override
public void setParentHologram(CraftHologram hologram) {
this.parent = hologram;
}
}

View File

@ -0,0 +1,139 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import com.gmail.filoghost.holograms.nms.interfaces.TouchSlime;
import com.gmail.filoghost.holograms.object.CraftHologram;
import com.gmail.filoghost.holograms.object.HologramBase;
import net.minecraft.server.v1_7_R4.EntitySlime;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.World;
public class EntityTouchSlime extends EntitySlime implements TouchSlime {
private boolean lockTick;
private CraftHologram parent;
public EntityTouchSlime(World world) {
super(world);
super.persistent = true;
super.boundingBox.a = 0.0;
super.boundingBox.b = 0.0;
super.boundingBox.c = 0.0;
super.boundingBox.d = 0.0;
super.boundingBox.e = 0.0;
super.boundingBox.f = 0.0;
a(0.0F, 0.0F);
setSize(1);
setInvisible(true);
}
@Override
public void h() {
// Checks every 20 ticks.
if (ticksLived % 20 == 0) {
// The slime dies without a vehicle.
if (this.vehicle == null) {
die();
}
}
if (!lockTick) {
super.h();
}
}
@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() {
/*
* 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.
}
public void setLockTick(boolean lock) {
lockTick = lock;
}
public void die() {
setLockTick(false);
super.die();
}
public HologramBase getParent() {
return parent;
}
public CraftEntity getBukkitEntity() {
if (super.bukkitEntity == null) {
this.bukkitEntity = new CraftTouchSlime(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 CraftHologram getParentHologram() {
return parent;
}
@Override
public void setParentHologram(CraftHologram hologram) {
this.parent = hologram;
}
}

View File

@ -0,0 +1,152 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.json.JSONException;
import org.json.JSONStringer;
import com.gmail.filoghost.holograms.nms.interfaces.FancyMessage;
public class FancyMessageImpl implements FancyMessage {
private final List<MessagePart> messageParts;
public FancyMessageImpl(final String firstPartText) {
messageParts = new ArrayList<MessagePart>();
messageParts.add(new MessagePart(firstPartText));
}
public FancyMessageImpl color(final ChatColor color) {
if (!color.isColor()) {
throw new IllegalArgumentException(color.name() + " is not a color");
}
latest().color = color;
return this;
}
public FancyMessageImpl style(final ChatColor... styles) {
for (final ChatColor style : styles) {
if (!style.isFormat()) {
throw new IllegalArgumentException(style.name() + " is not a style");
}
}
latest().styles = styles;
return this;
}
public FancyMessageImpl file(final String path) {
onClick("open_file", path);
return this;
}
public FancyMessageImpl link(final String url) {
onClick("open_url", url);
return this;
}
public FancyMessageImpl suggest(final String command) {
onClick("suggest_command", command);
return this;
}
public FancyMessageImpl command(final String command) {
onClick("run_command", command);
return this;
}
public FancyMessageImpl achievementTooltip(final String name) {
onHover("show_achievement", "achievement." + name);
return this;
}
public FancyMessageImpl itemTooltip(final String itemJSON) {
onHover("show_item", itemJSON);
return this;
}
public FancyMessageImpl itemTooltip(final ItemStack itemStack) {
return itemTooltip(CraftItemStack.asNMSCopy(itemStack).save(new NBTTagCompound()).toString());
}
public FancyMessageImpl tooltip(final String text) {
final String[] lines = text.split("\\n");
if (lines.length <= 1) {
onHover("show_text", text);
} else {
itemTooltip(makeMultilineTooltip(lines));
}
return this;
}
public FancyMessageImpl then(final Object obj) {
messageParts.add(new MessagePart(obj.toString()));
return this;
}
public String toJSONString() {
final JSONStringer json = new JSONStringer();
try {
if (messageParts.size() == 1) {
latest().writeJson(json);
} else {
json.object().key("text").value("").key("extra").array();
for (final MessagePart part : messageParts) {
part.writeJson(json);
}
json.endArray().endObject();
}
} catch (final JSONException e) {
throw new RuntimeException("invalid message");
}
return json.toString();
}
public void send(Player player){
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(ChatSerializer.a(toJSONString())));
}
private MessagePart latest() {
return messageParts.get(messageParts.size() - 1);
}
private String makeMultilineTooltip(final String[] lines) {
final JSONStringer json = new JSONStringer();
try {
json.object().key("id").value(1);
json.key("tag").object().key("display").object();
json.key("Name").value("\\u00A7f" + lines[0].replace("\"", "\\\""));
json.key("Lore").array();
for (int i = 1; i < lines.length; i++) {
final String line = lines[i];
json.value(line.isEmpty() ? " " : line.replace("\"", "\\\""));
}
json.endArray().endObject().endObject().endObject();
} catch (final JSONException e) {
throw new RuntimeException("invalid tooltip");
}
return json.toString();
}
private void onClick(final String name, final String data) {
final MessagePart latest = latest();
latest.clickActionName = name;
latest.clickActionData = data;
}
private void onHover(final String name, final String data) {
final MessagePart latest = latest();
latest.hoverActionName = name;
latest.hoverActionData = data;
}
}

View File

@ -0,0 +1,128 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.ItemStack;
import com.gmail.filoghost.holograms.exception.SpawnFailedException;
import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.nms.interfaces.FancyMessage;
import com.gmail.filoghost.holograms.nms.interfaces.HologramHorse;
import com.gmail.filoghost.holograms.nms.interfaces.HologramWitherSkull;
import com.gmail.filoghost.holograms.nms.interfaces.HologramComponent;
import com.gmail.filoghost.holograms.nms.interfaces.NmsManager;
import com.gmail.filoghost.holograms.object.CraftHologram;
import com.gmail.filoghost.holograms.utils.ReflectionUtils;
import com.gmail.filoghost.holograms.utils.VersionUtils;
import net.minecraft.server.v1_7_R4.Entity;
import net.minecraft.server.v1_7_R4.EntityTypes;
import net.minecraft.server.v1_7_R4.WorldServer;
public class NmsManagerImpl implements NmsManager {
@Override
public void registerCustomEntities() throws Exception {
registerCustomEntity(EntityHologramHorse.class, "EntityHorse", 100);
registerCustomEntity(EntityHologramWitherSkull.class, "WitherSkull", 19);
registerCustomEntity(EntityCustomItem.class, "Item", 1);
registerCustomEntity(EntityTouchSlime.class, "Slime", 55);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
// MCPC+ / Cauldron entity registration.
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R4.EntityTypes");
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75624_e", entityClass, Integer.valueOf(id));
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
}
@Override
public HologramHorse spawnHologramHorse(org.bukkit.World world, double x, double y, double z) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
EntityHologramHorse invisibleHorse = new EntityHologramHorse(nmsWorld);
invisibleHorse.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(invisibleHorse, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
}
return invisibleHorse;
}
@Override
public HologramWitherSkull spawnHologramWitherSkull(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityHologramWitherSkull staticWitherSkull = new EntityHologramWitherSkull(nmsWorld);
staticWitherSkull.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(staticWitherSkull, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
}
return staticWitherSkull;
}
@Override
public CustomItem spawnCustomItem(org.bukkit.World bukkitWorld, double x, double y, double z, ItemStack stack) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityCustomItem customItem = new EntityCustomItem(nmsWorld);
customItem.setLocationNMS(x, y, z);
customItem.setItemStackNMS(stack);
if (!nmsWorld.addEntity(customItem, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
}
return customItem;
}
@Override
public EntityTouchSlime spawnTouchSlime(org.bukkit.World bukkitWorld, double x, double y, double z) throws SpawnFailedException {
WorldServer nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
EntityTouchSlime touchSlime = new EntityTouchSlime(nmsWorld);
touchSlime.setLocationNMS(x, y, z);
if (!nmsWorld.addEntity(touchSlime, SpawnReason.CUSTOM)) {
throw new SpawnFailedException();
}
return touchSlime;
}
@Override
public boolean isHologramComponent(org.bukkit.entity.Entity bukkitEntity) {
return ((CraftEntity) bukkitEntity).getHandle() instanceof HologramComponent;
}
@Override
public boolean isBasicEntityNMS(org.bukkit.entity.Entity bukkitEntity) {
return ((CraftEntity) bukkitEntity).getHandle() instanceof BasicEntityNMS;
}
@Override
public CraftHologram getParentHologram(org.bukkit.entity.Entity bukkitEntity) {
Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
if (nmsEntity instanceof HologramComponent) {
return ((HologramComponent) nmsEntity).getParentHologram();
}
return null;
}
@Override
public FancyMessage newFancyMessage(String text) {
return new FancyMessageImpl(text);
}
@Override
public boolean hasChatHoverFeature() {
return true;
}
}