From 256f1656228b8e2160b3d4ed306364be6a0296e3 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 11 May 2015 20:15:11 +0200 Subject: [PATCH] Spectator, chestOpen ^ Inventory * Support for Spectator-Mode (always gets creative Inventory) * Prevent Attack across Region borders * chestOpen now allows Inventory again, to make /inv addons possible * Placing into creative regions should now be handled again (survival regions may bugged? but no one uses them at all, or?) --- .../limitedcreative/ModInventories.java | 4 +++ .../inventories/Inventory.java | 3 +- .../limits/BlackListEntity.java | 29 ++++++++++++++-- .../limits/PlayerListener.java | 10 +++--- .../regions/BlockListener.java | 2 +- .../regions/PlayerListener.java | 34 +++++++++++++++++-- 6 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index dc17308..ae3869f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -90,8 +90,12 @@ public class ModInventories extends CoreModule { GameMode cgm = player.getGameMode(); if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure()) gm = GameMode.SURVIVAL; + else if (gm == GameMode.SPECTATOR) + gm = GameMode.CREATIVE; if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure()) cgm = GameMode.SURVIVAL; + else if (cgm == GameMode.SPECTATOR) + cgm = GameMode.CREATIVE; if (gm != cgm) { if (gm != GameMode.CREATIVE || config.getStoreCreative()) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java index 7a7dc75..615fe1c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java @@ -31,7 +31,8 @@ public class Inventory { public enum Target { SURVIVAL, CREATIVE, - ADVENTURE; + ADVENTURE, + SPECTATOR; public static Target getTarget(GameMode gm) { return Target.valueOf(gm.name()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java index d12a5fe..a25cedd 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete; +import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -11,9 +13,32 @@ import de.jaschastarke.bukkit.lib.configuration.ConfigurableList; import de.jaschastarke.bukkit.lib.configuration.IToGeneric; import de.jaschastarke.configuration.InvalidValueException; -public class BlackListEntity extends ArrayList implements ConfigurableList, IToGeneric { +public class BlackListEntity extends ArrayList implements ConfigurableList, IToGeneric, ITabComplete { private static final long serialVersionUID = 6150727863411513873L; + @Override + public List tabComplete(String[] args, String[] chain) { + if (args.length > 0 && chain.length > 0) { + List hints = new ArrayList(); + String action = chain[chain.length - 1]; + if (action.equalsIgnoreCase(ListConfigValue.ADD)) { + for (EntityType m : EntityType.values()) { + if (m.name().toLowerCase().startsWith(args[0].toLowerCase())) { + hints.add(m.name()); + } + } + } else if (action.equalsIgnoreCase(ListConfigValue.REMOVE)) { + for (Blacklisted bl : this) { + if (bl.toString().toLowerCase().startsWith(args[0].toLowerCase())) { + hints.add(bl.toString()); + } + } + } + return hints; + } + return null; + } + public static class Blacklisted { private String stringRep; private EntityType type; @@ -36,7 +61,7 @@ public class BlackListEntity extends ArrayList impl } if (type == null) - throw new InvalidValueException("Entity '" + stringRep + "' not found"); + throw new InvalidValueException("Entity '" + rep + "' not found"); stringRep = rep; } public Blacklisted(EntityType et) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 499b29d..4c3dc80 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -79,10 +79,12 @@ public class PlayerListener implements Listener { public void onInventoryOpen(InventoryOpenEvent event) { if (event.getPlayer() instanceof Player) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { - if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory()))) - return; - event.setCancelled(true); - ((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory")); + if (!mod.getConfig().getBlockChestInteraction()) { + if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory()))) + return; + event.setCancelled(true); + ((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory")); + } } } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java index 743e1ea..b99a173 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java @@ -82,7 +82,7 @@ public class BlockListener extends Listener { } } else if (diffrent_region) { // do not build inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { + if (/*getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && */getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_place")); event.setCancelled(true); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java index a415f7c..5152f4a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java @@ -10,7 +10,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.InventoryHolder; @@ -48,7 +50,7 @@ public class PlayerListener extends Listener { } } else if (diffrent_region) { // do not break inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { // TODO: Rework + if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_interact")); event.setCancelled(true); } @@ -69,12 +71,40 @@ public class PlayerListener extends Listener { } } else if (diffrent_region) { // do not break inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_interact_entity")); event.setCancelled(true); } } } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamange(EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Player) { + PlayerMeta pmeta = new PlayerMeta((Player) event.getDamager()); + Location loc = event.getEntity().getLocation(); + boolean diffrent_region = getRM().isDiffrentRegion((Player) event.getDamager(), loc); + + if (pmeta.isActiveRegionGameMode() && diffrent_region) { + // do not break outside of "gamemod-change-region" when in the region + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != pmeta.getActiveRegionGameMode()) { + event.getDamager().sendMessage(L("blocked.outside_interact_entity")); + event.setCancelled(true); + } + } else if (diffrent_region) { + // do not break inside of "survial-region in creative world" when outside + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != ((Player) event.getDamager()).getGameMode()) { + event.getDamager().sendMessage(L("blocked.inside_interact_entity")); + event.setCancelled(true); + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + onPlayerInteractEntity(event); + } private boolean isRegionOptional(Player player) { return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);