Fix icons being picked up & add per command permissions.

This commit is contained in:
filoghost 2014-08-11 21:22:29 +02:00
parent 8ea4488028
commit 0b47982927
25 changed files with 91 additions and 65 deletions

View File

@ -139,13 +139,13 @@ public class HolographicDisplays extends JavaPlugin {
"******************************************************",
" This version of HolographicDisplays can",
" only work on these server versions:",
" 1.6.4, from 1.7.2 to 1.7.9.",
" 1.6.4, from 1.7.2 to 1.7.10.",
" The plugin will be disabled.",
"******************************************************"
);
return;
}
try {
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
getLogger().info("Trying to enable Cauldron/MCPC+ support...");

View File

@ -8,6 +8,6 @@ public class Messages {
public static final String NO_SUCH_HOLOGRAM = ChatColor.RED + "A hologram with that name doesn't exist.";
public static final String FAILED_TO_SPAWN_HERE = ChatColor.GRAY + "(The entities failed to spawn. You MUST allow mobs to spawn here.)";
public static final String MAIN_PERMISSION = "holograms.admin";
public static final String BASE_PERM = "holograms.";
}

View File

@ -19,7 +19,7 @@ public class AddlineCommand extends HologramSubCommand {
public AddlineCommand() {
super("addline");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "addline");
}
@Override

View File

@ -24,7 +24,7 @@ public class CreateCommand extends HologramSubCommand {
public CreateCommand() {
super("create");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "create");
}
@Override
@ -38,19 +38,27 @@ public class CreateCommand extends HologramSubCommand {
}
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) throws CommandException {
try {
Player player = CommandValidator.getPlayerSender(sender);
String name = StringUtils.validateName(args[0].toLowerCase());
CommandValidator.isTrue(!HologramManager.isExistingHologram(name), "A hologram with that name already exists.");
CraftHologram hologram = new CraftHologram(name, player.getLocation());
Location spawnLoc = player.getLocation();
boolean moveUp = player.isOnGround();
if (moveUp) {
spawnLoc.add(0.0, 1.2, 0.0);
}
CraftHologram hologram = new CraftHologram(name, spawnLoc);
HologramManager.addHologram(hologram);
if (args.length > 1) {
hologram.addLine(StringUtils.toReadableFormat(StringUtils.join(args, " ", 1, args.length)));
sender.sendMessage("§7(Change the lines with /hd edit " + hologram.getName() + ")");
player.sendMessage("§7(Change the lines with /hd edit " + hologram.getName() + ")");
} else {
hologram.addLine("Default hologram. Change it with " + Format.HIGHLIGHT + "/hd edit " + hologram.getName());
}
@ -66,6 +74,10 @@ public class CreateCommand extends HologramSubCommand {
player.teleport(look, TeleportCause.PLUGIN);
player.sendMessage(Format.HIGHLIGHT + "You created a hologram named '" + hologram.getName() + "'.");
if (moveUp) {
player.sendMessage("§7(You were on the ground, the hologram was automatically moved up. If you use /hd movehere " + hologram.getName() + ", the hologram will be moved to your feet)");
}
} catch (InvalidCharactersException ex) {
throw new CommandException("The hologram's name must be alphanumeric. '" + ex.getMessage() + "' is not allowed.");
}

View File

@ -18,7 +18,7 @@ public class DeleteCommand extends HologramSubCommand {
public DeleteCommand() {
super("delete", "remove");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "delete");
}
@Override

View File

@ -29,7 +29,7 @@ public class EditCommand extends HologramSubCommand {
public EditCommand() {
super("edit");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "edit");
}
@Override

View File

@ -18,7 +18,7 @@ public class FixCommand extends HologramSubCommand {
public FixCommand() {
super("fix", "light");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "fix");
}
@Override

View File

@ -21,7 +21,7 @@ public class HelpCommand extends HologramSubCommand {
public HelpCommand() {
super("help");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "help");
}
@Override

View File

@ -20,7 +20,7 @@ public class InsertlineCommand extends HologramSubCommand {
public InsertlineCommand() {
super("insertline");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "insertline");
}
@Override

View File

@ -19,7 +19,7 @@ public class ListCommand extends HologramSubCommand {
public ListCommand() {
super("list");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "list");
}
@Override

View File

@ -22,7 +22,7 @@ public class MovehereCommand extends HologramSubCommand {
public MovehereCommand() {
super("movehere");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "movehere");
}
@Override

View File

@ -20,7 +20,7 @@ public class NearCommand extends HologramSubCommand {
public NearCommand() {
super("near");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "near");
}
@Override

View File

@ -26,7 +26,7 @@ public class ReadimageCommand extends HologramSubCommand {
public ReadimageCommand() {
super("readimage", "image");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "readimage");
}
@Override

View File

@ -22,7 +22,7 @@ public class ReadtextCommand extends HologramSubCommand {
public ReadtextCommand() {
super("readtext", "readlines");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "readtext");
}
@Override

View File

@ -26,7 +26,7 @@ public class ReloadCommand extends HologramSubCommand {
public ReloadCommand() {
super("reload");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "reload");
}
@Override

View File

@ -18,7 +18,7 @@ public class RemovelineCommand extends HologramSubCommand {
public RemovelineCommand() {
super("removeline");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "removeline");
}
@Override

View File

@ -16,7 +16,7 @@ public class SaveCommand extends HologramSubCommand {
public SaveCommand() {
super("save");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "save");
}
@Override

View File

@ -19,7 +19,7 @@ public class SetlineCommand extends HologramSubCommand {
public SetlineCommand() {
super("setline");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "setline");
}
@Override

View File

@ -20,7 +20,7 @@ public class TeleportCommand extends HologramSubCommand {
public TeleportCommand() {
super("teleport", "tp");
setPermission(Messages.MAIN_PERMISSION);
setPermission(Messages.BASE_PERM + "teleport");
}
@Override

View File

@ -103,7 +103,7 @@ public class MainListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (Configuration.updateNotification && Configuration.newVersion != null) {
if (event.getPlayer().hasPermission(Messages.MAIN_PERMISSION)) {
if (event.getPlayer().hasPermission(Messages.BASE_PERM + "update")) {
event.getPlayer().sendMessage("§3[HolographicDisplays] §bFound an update: " + Configuration.newVersion + ". Download:");
event.getPlayer().sendMessage("§3>> §bhttp://dev.bukkit.org/bukkit-plugins/holographic-displays");
}

View File

@ -1,6 +1,5 @@
package com.gmail.filoghost.holograms.nms.v1_6_R3;
import net.minecraft.server.v1_6_R3.Block;
import net.minecraft.server.v1_6_R3.EntityItem;
import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.NBTTagCompound;
@ -19,8 +18,6 @@ import com.gmail.filoghost.holograms.object.HologramBase;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Block.STONE, 0);
private boolean lockTick;
private HologramBase parent;
@ -44,6 +41,17 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 2 && stacktrace[1].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void b_(EntityHuman human) {
@ -90,11 +98,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {

View File

@ -13,14 +13,11 @@ 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;
import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.EntityPlayer;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private HologramBase parent;
@ -44,6 +41,17 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 2 && stacktrace[1].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void b_(EntityHuman human) {
@ -90,11 +98,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {

View File

@ -13,14 +13,11 @@ 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;
import net.minecraft.server.v1_7_R2.EntityHuman;
import net.minecraft.server.v1_7_R2.EntityPlayer;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private HologramBase parent;
@ -44,6 +41,17 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 2 && stacktrace[1].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void b_(EntityHuman human) {
@ -90,11 +98,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
*/
return true;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void setLockTick(boolean lock) {

View File

@ -9,7 +9,6 @@ import com.gmail.filoghost.holograms.nms.interfaces.BasicEntityNMS;
import com.gmail.filoghost.holograms.nms.interfaces.CustomItem;
import com.gmail.filoghost.holograms.object.HologramBase;
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;
@ -19,8 +18,6 @@ import net.minecraft.server.v1_7_R3.EntityPlayer;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private HologramBase parent;
@ -31,7 +28,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
@Override
public void h() {
// Checks every 20 ticks.
if (ticksLived % 20 == 0) {
// The item dies without a vehicle.
if (this.vehicle == null) {
@ -44,6 +40,17 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 2 && stacktrace[1].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void b_(EntityHuman human) {
@ -96,11 +103,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
lockTick = lock;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void die() {
setLockTick(false);

View File

@ -1,6 +1,5 @@
package com.gmail.filoghost.holograms.nms.v1_7_R4;
import net.minecraft.server.v1_7_R4.Blocks;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.server.v1_7_R4.EntityItem;
import net.minecraft.server.v1_7_R4.EntityPlayer;
@ -19,8 +18,6 @@ import com.gmail.filoghost.holograms.object.HologramBase;
public class EntityCustomItem extends EntityItem implements CustomItem, BasicEntityNMS {
private static final ItemStack STONE = new ItemStack(Blocks.STONE, 0);
private boolean lockTick;
private HologramBase parent;
@ -44,6 +41,17 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
}
}
@Override
public ItemStack getItemStack() {
// Dirty method to check if the icon is being picked up
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
if (stacktrace.length >= 2 && stacktrace[1].getClassName().contains("EntityInsentient")) {
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
}
return super.getItemStack();
}
// Method called when a player is near.
@Override
public void b_(EntityHuman human) {
@ -96,11 +104,6 @@ public class EntityCustomItem extends EntityItem implements CustomItem, BasicEnt
lockTick = lock;
}
@Override
public ItemStack getItemStack() {
return STONE;
}
@Override
public void die() {
setLockTick(false);