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?)
This commit is contained in:
Jascha Starke 2015-05-11 20:15:11 +02:00
parent d010249107
commit 256f165622
6 changed files with 72 additions and 10 deletions

View file

@ -90,8 +90,12 @@ public class ModInventories extends CoreModule<LimitedCreative> {
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()) {

View file

@ -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());

View file

@ -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<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric {
public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric, ITabComplete {
private static final long serialVersionUID = 6150727863411513873L;
@Override
public List<String> tabComplete(String[] args, String[] chain) {
if (args.length > 0 && chain.length > 0) {
List<String> hints = new ArrayList<String>();
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<BlackListEntity.Blacklisted> impl
}
if (type == null)
throw new InvalidValueException("Entity '" + stringRep + "' not found");
throw new InvalidValueException("Entity '" + rep + "' not found");
stringRep = rep;
}
public Blacklisted(EntityType et) {

View file

@ -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"));
}
}
}
}

View file

@ -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);
}

View file

@ -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);