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:
parent
d010249107
commit
256f165622
6 changed files with 72 additions and 10 deletions
|
@ -90,8 +90,12 @@ public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
GameMode cgm = player.getGameMode();
|
GameMode cgm = player.getGameMode();
|
||||||
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||||
gm = GameMode.SURVIVAL;
|
gm = GameMode.SURVIVAL;
|
||||||
|
else if (gm == GameMode.SPECTATOR)
|
||||||
|
gm = GameMode.CREATIVE;
|
||||||
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||||
cgm = GameMode.SURVIVAL;
|
cgm = GameMode.SURVIVAL;
|
||||||
|
else if (cgm == GameMode.SPECTATOR)
|
||||||
|
cgm = GameMode.CREATIVE;
|
||||||
|
|
||||||
if (gm != cgm) {
|
if (gm != cgm) {
|
||||||
if (gm != GameMode.CREATIVE || config.getStoreCreative()) {
|
if (gm != GameMode.CREATIVE || config.getStoreCreative()) {
|
||||||
|
|
|
@ -31,7 +31,8 @@ public class Inventory {
|
||||||
public enum Target {
|
public enum Target {
|
||||||
SURVIVAL,
|
SURVIVAL,
|
||||||
CREATIVE,
|
CREATIVE,
|
||||||
ADVENTURE;
|
ADVENTURE,
|
||||||
|
SPECTATOR;
|
||||||
|
|
||||||
public static Target getTarget(GameMode gm) {
|
public static Target getTarget(GameMode gm) {
|
||||||
return Target.valueOf(gm.name());
|
return Target.valueOf(gm.name());
|
||||||
|
|
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
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.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
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.bukkit.lib.configuration.IToGeneric;
|
||||||
import de.jaschastarke.configuration.InvalidValueException;
|
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;
|
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 {
|
public static class Blacklisted {
|
||||||
private String stringRep;
|
private String stringRep;
|
||||||
private EntityType type;
|
private EntityType type;
|
||||||
|
@ -36,7 +61,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
throw new InvalidValueException("Entity '" + stringRep + "' not found");
|
throw new InvalidValueException("Entity '" + rep + "' not found");
|
||||||
stringRep = rep;
|
stringRep = rep;
|
||||||
}
|
}
|
||||||
public Blacklisted(EntityType et) {
|
public Blacklisted(EntityType et) {
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class PlayerListener implements Listener {
|
||||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||||
if (event.getPlayer() instanceof Player) {
|
if (event.getPlayer() instanceof Player) {
|
||||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
|
if (!mod.getConfig().getBlockChestInteraction()) {
|
||||||
if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory())))
|
if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory())))
|
||||||
return;
|
return;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -86,6 +87,7 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class BlockListener extends Listener {
|
||||||
}
|
}
|
||||||
} else if (diffrent_region) {
|
} else if (diffrent_region) {
|
||||||
// do not build inside of "survial-region in creative world" when outside
|
// 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.getPlayer().sendMessage(L("blocked.inside_place"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
@ -48,7 +50,7 @@ public class PlayerListener extends Listener {
|
||||||
}
|
}
|
||||||
} else if (diffrent_region) {
|
} else if (diffrent_region) {
|
||||||
// do not break inside of "survial-region in creative world" when outside
|
// 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.getPlayer().sendMessage(L("blocked.inside_interact"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -69,13 +71,41 @@ public class PlayerListener extends Listener {
|
||||||
}
|
}
|
||||||
} else if (diffrent_region) {
|
} else if (diffrent_region) {
|
||||||
// do not break inside of "survial-region in creative world" when outside
|
// 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.getPlayer().sendMessage(L("blocked.inside_interact_entity"));
|
||||||
event.setCancelled(true);
|
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) {
|
private boolean isRegionOptional(Player player) {
|
||||||
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);
|
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue