- Debug mode for the several issue tickets
 - Permission via WEPIF
 - Sign Interact Priority-Fix
 - MultiInv compatibility disable
This commit is contained in:
Jascha Starke 2012-01-30 21:15:43 +01:00
parent 295a93b384
commit 4fc58c86aa
12 changed files with 168 additions and 45 deletions

View file

@ -2,6 +2,14 @@ basic:
loaded: loaded:
worldguard: Successfully loaded with WorldGuard-Integration worldguard: Successfully loaded with WorldGuard-Integration
no_worldguard: Successfully loaded (without WorldGuard) no_worldguard: Successfully loaded (without WorldGuard)
feature:
store: separated inventories
limit: creative restrictions
region: creative regions
conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
warning:
worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled
# double single-quote '' because of MessageFormater to insert {0}
command: command:
player: player player: player
switch: switch:

View file

@ -1,7 +1,7 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.8-beta version: 0.8.1-beta
softdepend: [WorldGuard] softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/ dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands: commands:
limitedcreative: limitedcreative:

View file

@ -26,6 +26,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import de.jaschastarke.minecraft.utils.Util;
import de.jaschastarke.minecraft.worldguard.CCommand; import de.jaschastarke.minecraft.worldguard.CCommand;
import static de.jaschastarke.minecraft.utils.Locale.L; import static de.jaschastarke.minecraft.utils.Locale.L;
@ -43,6 +44,7 @@ public class Commands {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
LimitedCreativeCore.debug(sender.getName() + ": /" + label + " " + Util.join(args));
if (args.length > 0) { if (args.length > 0) {
Action act = null; Action act = null;
try { try {
@ -74,6 +76,7 @@ public class Commands {
return true; return true;
} }
} catch (CommandException e) { } catch (CommandException e) {
LimitedCreativeCore.debug("CommandException: "+e.getMessage());
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage()); sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
return true; return true;
} }
@ -84,11 +87,11 @@ public class Commands {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n"); message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n");
message.append("/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n"); message.append("/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n");
if (sender.hasPermission("limitedcreative.config")) if (plugin.perm.hasPermission(sender, "limitedcreative.config"))
message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n"); message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n");
if (sender.hasPermission("limitedcreative.config")) if (plugin.perm.hasPermission(sender, "limitedcreative.config"))
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n"); message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
if (sender.hasPermission("limitedcreative.regions")) if (plugin.perm.hasPermission(sender, "limitedcreative.regions"))
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n"); message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
if (message.length() > 0) { if (message.length() > 0) {
sender.sendMessage("Usage:"); sender.sendMessage("Usage:");
@ -107,10 +110,11 @@ public class Commands {
BLOCKSIGN, BLOCKSIGN,
PERMISSIONS, PERMISSIONS,
PERM_KEEPINVENTORY, PERM_KEEPINVENTORY,
DEBUG,
}; };
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException { private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
if (sender instanceof Player && !sender.hasPermission("limitedcreative.config") && !sender.isOp()) { if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) {
throw new LackingPermissionException(); throw new LackingPermissionException();
} }
if (args.length > 2) if (args.length > 2)
@ -156,7 +160,7 @@ public class Commands {
if (target == null) { if (target == null) {
throw new InvalidCommandException("exception.command.playernotfound"); throw new InvalidCommandException("exception.command.playernotfound");
} else if (sender instanceof Player && sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) { } else if (sender instanceof Player && sender != target && !plugin.perm.hasPermission(sender, "limitedcreative.switch_gamemode.other")) {
throw new LackingPermissionException(); throw new LackingPermissionException();
} else if (target.getGameMode() != gm) { } else if (target.getGameMode() != gm) {
if (sender == target) { if (sender == target) {

View file

@ -51,7 +51,7 @@ public class Configuration {
} }
public boolean getStoreEnabled() { public boolean getStoreEnabled() {
return c.getBoolean("store.enabled", true); return getTempStoreEnabled() && c.getBoolean("store.enabled", true);
} }
public boolean getLimitEnabled() { public boolean getLimitEnabled() {
return c.getBoolean("limit.enabled", true); return c.getBoolean("limit.enabled", true);
@ -85,7 +85,12 @@ public class Configuration {
return c.getBoolean("region.optional", true); return c.getBoolean("region.optional", true);
} }
public void setDebug(boolean value) {
this.reload();
c.set("debug", value);
this.save();
}
public void setStoreCreative(boolean value) { public void setStoreCreative(boolean value) {
this.reload(); this.reload();
c.set("store.creative", value); c.set("store.creative", value);
@ -157,4 +162,12 @@ public class Configuration {
} }
return list; return list;
} }
private boolean _store_enabled = true;
public void setTempStoreEnabled(boolean b) {
_store_enabled = b;
}
public boolean getTempStoreEnabled() {
return _store_enabled;
}
} }

View file

@ -59,8 +59,10 @@ public class LCPlayer {
private LCPlayer(Player pplayer) { private LCPlayer(Player pplayer) {
player = pplayer; player = pplayer;
_isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE; _isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE;
if (player.getGameMode() == GameMode.CREATIVE && !this.isRegionCreative()) if (player.getGameMode() == GameMode.CREATIVE && !this.isRegionCreative()) {
LimitedCreativeCore.debug(player.getName() + " was already creative");
setPermanentCreative(true); setPermanentCreative(true);
}
} }
public Player getRaw() { public Player getRaw() {
@ -82,14 +84,16 @@ public class LCPlayer {
} }
public void changeGameMode(GameMode gm) throws LackingPermissionException { public void changeGameMode(GameMode gm) throws LackingPermissionException {
if (!isRegionCreative() && !getRaw().hasPermission("limitedcreative.switch_gamemode")) { if (!isRegionCreative() && !hasPermission("limitedcreative.switch_gamemode")) {
if (gm != GameMode.SURVIVAL || !getRaw().hasPermission("limitedcreative.switch_gamemode.backonly")) { if (gm != GameMode.SURVIVAL || !hasPermission("limitedcreative.switch_gamemode.backonly")) {
LimitedCreativeCore.debug(player.getName() + " lacking permission /lc [cs]");
throw new Commands.LackingPermissionException(); throw new Commands.LackingPermissionException();
} }
} }
getRaw().setGameMode(gm); getRaw().setGameMode(gm);
} }
public void setRegionCreative(boolean b) { public void setRegionCreative(boolean b) {
LimitedCreativeCore.debug(player.getName() + " region creative: " + b);
if (b) { if (b) {
store.set(player.getName()+".region_creative", true); store.set(player.getName()+".region_creative", true);
} else { } else {
@ -107,16 +111,18 @@ public class LCPlayer {
return _isPermanentCreative; return _isPermanentCreative;
} }
public void setPermanentCreative(boolean b) { public void setPermanentCreative(boolean b) {
LimitedCreativeCore.debug(player.getName() + " permanent creative: " + b);
_isPermanentCreative = b; _isPermanentCreative = b;
if (b) if (b)
setRegionCreative(false); setRegionCreative(false);
} }
public boolean onSetCreative() { public boolean onSetCreative() {
LimitedCreativeCore.debug(player.getName() + " going into creative");
if (!this.isRegionCreative()) if (!this.isRegionCreative())
setPermanentCreative(true); setPermanentCreative(true);
if (plugin.config.getStoreEnabled()) { if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory")) if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
return true; return true;
Inventory inv = new Inventory(player); Inventory inv = new Inventory(player);
inv.save(); inv.save();
@ -129,15 +135,17 @@ public class LCPlayer {
return true; return true;
} }
public boolean onSetSurvival() { public boolean onSetSurvival() {
LimitedCreativeCore.debug(player.getName() + " going into survival");
if (isRegionCreative()) { if (isRegionCreative()) {
if (!plugin.config.getRegionOptional()) { if (!plugin.config.getRegionOptional()) {
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival")); getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
LimitedCreativeCore.debug("... denied");
return false; return false;
} }
} }
setPermanentCreative(false); setPermanentCreative(false);
if (plugin.config.getStoreEnabled()) { if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory")) if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
return true; return true;
Inventory inv = new Inventory(player); Inventory inv = new Inventory(player);
if (plugin.config.getStoreCreative()) { if (plugin.config.getStoreCreative()) {
@ -150,14 +158,14 @@ public class LCPlayer {
} }
public void onDropItem(PlayerDropItemEvent event) { public void onDropItem(PlayerDropItemEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop")) if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.drop"))
return; return;
event.getItemDrop().remove(); event.getItemDrop().remove();
} }
} }
public void onPickupItem(PlayerPickupItemEvent event) { public void onPickupItem(PlayerPickupItemEvent event) {
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getBlockPickupInCreative()) { if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getBlockPickupInCreative()) {
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.pickup")) if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.pickup"))
return; return;
event.setCancelled(true); event.setCancelled(true);
} }
@ -165,7 +173,7 @@ public class LCPlayer {
public void onDie(EntityDeathEvent event) { public void onDie(EntityDeathEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.drop")) { if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
event.getDrops().clear(); event.getDrops().clear();
tempinv = Items.storeInventory(player.getInventory()); tempinv = Items.storeInventory(player.getInventory());
} }
@ -173,7 +181,7 @@ public class LCPlayer {
} }
public void onRespawn(PlayerRespawnEvent event) { public void onRespawn(PlayerRespawnEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.drop")) { if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
if (tempinv != null) { if (tempinv != null) {
Items.restoreInventory(player.getInventory(), tempinv); Items.restoreInventory(player.getInventory(), tempinv);
} }
@ -187,12 +195,13 @@ public class LCPlayer {
// its PVP // its PVP
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
if (attacker.getGameMode() == GameMode.CREATIVE) { if (attacker.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !attacker.hasPermission("limitedcreative.nolimit.pvp")) { if (!plugin.config.getPermissionsEnabled() || !get(attacker).hasPermission("limitedcreative.nolimit.pvp")) {
event.setCancelled(true); event.setCancelled(true);
return; // skip next check
} }
} }
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.pvp")) { if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.pvp")) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -201,7 +210,7 @@ public class LCPlayer {
public void onChestAccess(PlayerInteractEvent event) { public void onChestAccess(PlayerInteractEvent event) {
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE)
return; return;
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest")) if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
return; return;
event.getPlayer().sendMessage(L("blocked.chest")); event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true); event.setCancelled(true);
@ -209,7 +218,7 @@ public class LCPlayer {
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE)
return; return;
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest")) if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
return; return;
event.getPlayer().sendMessage(L("blocked.chest")); event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true); event.setCancelled(true);
@ -217,7 +226,7 @@ public class LCPlayer {
public void onSignAccess(PlayerInteractEvent event) { public void onSignAccess(PlayerInteractEvent event) {
if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE) if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE)
return; return;
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.sign")) if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.sign"))
return; return;
event.getPlayer().sendMessage(L("blocked.sign")); event.getPlayer().sendMessage(L("blocked.sign"));
event.setCancelled(true); event.setCancelled(true);
@ -274,4 +283,8 @@ public class LCPlayer {
player.getLocation().getZ())); player.getLocation().getZ()));
} }
} }
public boolean hasPermission(String permission) {
return plugin.perm.hasPermission(this.getRaw(), permission);
}
} }

View file

@ -26,11 +26,13 @@ import de.jaschastarke.minecraft.limitedcreative.listeners.LimitListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener; import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration; import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
import de.jaschastarke.minecraft.utils.Locale; import de.jaschastarke.minecraft.utils.Locale;
import de.jaschastarke.minecraft.utils.Permissions;
public class LimitedCreativeCore extends JavaPlugin { public class LimitedCreativeCore extends JavaPlugin {
public final Logger logger = Logger.getLogger("Minecraft"); public final Logger logger = Logger.getLogger("Minecraft");
public Configuration config; public Configuration config;
public Permissions perm;
public WorldGuardIntegration worldguard; public WorldGuardIntegration worldguard;
public static LimitedCreativeCore plugin; public static LimitedCreativeCore plugin;
public NoBlockItemSpawn spawnblock; public NoBlockItemSpawn spawnblock;
@ -41,29 +43,43 @@ public class LimitedCreativeCore extends JavaPlugin {
worldguard = null; worldguard = null;
config = null; config = null;
spawnblock = null; spawnblock = null;
Locale.unload(); try {
//info("cleanly unloaded."); Locale.unload();
} catch (NoClassDefFoundError e) {} // prevent unload issue
} }
@Override @Override
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
config = new Configuration(this); config = new Configuration(this);
perm = new Permissions(this);
new Locale(this); new Locale(this);
spawnblock = new NoBlockItemSpawn(); spawnblock = new NoBlockItemSpawn();
// 1st Feature: Separated Inventories Storage
if (config.getStoreEnabled() && getServer().getPluginManager().isPluginEnabled("MultiInv")) {
warn(L("basic.conflict", "MultiInv", L("basic.feature.store")));
config.setTempStoreEnabled(false);
}
getServer().getPluginManager().registerEvents(new MainListener(this), this); getServer().getPluginManager().registerEvents(new MainListener(this), this);
// 2nd Feature: Creative Limitations (Restrictions)
if (config.getLimitEnabled()) if (config.getLimitEnabled())
getServer().getPluginManager().registerEvents(new LimitListener(this), this); getServer().getPluginManager().registerEvents(new LimitListener(this), this);
if (config.getRegionEnabled() && WorldGuardIntegration.available()) { // 3rd Feature: WorldGuard Region-Support
if (config.getRegionEnabled() && getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
worldguard = new WorldGuardIntegration(this); worldguard = new WorldGuardIntegration(this);
} else if(config.getRegionEnabled()) { } else if(config.getRegionEnabled()) {
warn(L("warning.no_worldguard_found")); warn(L("basic.warning.worldguard_not_found", L("basic.feature.region")));
} }
debug("Store: " + config.getStoreEnabled());
debug("Limit: " + config.getLimitEnabled());
debug("Region: " + (worldguard != null));
Commands.register(this); Commands.register(this);
PluginDescriptionFile df = this.getDescription(); PluginDescriptionFile df = this.getDescription();

View file

@ -28,6 +28,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.StorageMinecart; import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@ -67,12 +68,13 @@ public class LimitListener implements Listener {
LCPlayer.get(event.getPlayer()).onPickupItem(event); LCPlayer.get(event.getPlayer()).onPickupItem(event);
} }
@EventHandler @EventHandler(priority=EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE) if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return; return;
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) { LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) { if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) {
event.setCancelled(true); event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY);
@ -87,19 +89,20 @@ public class LimitListener implements Listener {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (block.getState() instanceof ContainerBlock) { if (block.getState() instanceof ContainerBlock) {
LCPlayer.get(event.getPlayer()).onChestAccess(event); player.onChestAccess(event);
} }
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
LCPlayer.get(event.getPlayer()).onSignAccess(event); player.onSignAccess(event);
} }
} }
@EventHandler @EventHandler(priority=EventPriority.LOWEST)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE) if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return; return;
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) { LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) { if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.use")); event.getPlayer().sendMessage(L("blocked.use"));
@ -110,7 +113,7 @@ public class LimitListener implements Listener {
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
if (entity instanceof StorageMinecart) { if (entity instanceof StorageMinecart) {
LCPlayer.get(event.getPlayer()).onChestAccess(event); player.onChestAccess(event);
} }
} }
@ -124,7 +127,7 @@ public class LimitListener implements Listener {
} }
} }
@EventHandler @EventHandler(priority=EventPriority.LOW)
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
@ -137,14 +140,15 @@ public class LimitListener implements Listener {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.break")) { LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.break")) {
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) { if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.break")); event.getPlayer().sendMessage(L("blocked.break"));
} }
} }
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop")) if (plugin.config.getPermissionsEnabled() && player.hasPermission("limitedcreative.nolimit.drop"))
return; return;
// Prevent dropping of doors and beds when destroying the wrong part // Prevent dropping of doors and beds when destroying the wrong part
Block block = event.getBlock(); Block block = event.getBlock();
@ -175,7 +179,8 @@ public class LimitListener implements Listener {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) { LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) { if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.place")); event.getPlayer().sendMessage(L("blocked.place"));

View file

@ -42,10 +42,6 @@ public class WorldGuardIntegration {
plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin); plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin);
} }
public static boolean available() {
return LimitedCreativeCore.plugin.getServer().getPluginManager().getPlugin("WorldGuard") != null;
}
public CRegionManager getRegionManager() { public CRegionManager getRegionManager() {
return rm; return rm;
} }

View file

@ -0,0 +1,48 @@
package de.jaschastarke.minecraft.utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.worldedit.PermissionsBridge;
public class Permissions {
protected JavaPlugin plugin = null;
protected PermissionsBridge pif = null;
public Permissions(JavaPlugin plugin) {
this.plugin = plugin;
try {
// because worldedit may be not loaded as plugin, just as library, we check that way
Class.forName("com.sk89q.wepif.PermissionsResolverManager", false, plugin.getClass().getClassLoader());
pif = new PermissionsBridge(plugin);
} catch (ClassNotFoundException e) {}
}
public boolean hasPermission(Player player, String permission) {
boolean ret = false;
if (pif != null) {
ret = pif.hasPermission(player, permission);
} else {
// bukkit permission fallback
ret = player.hasPermission(permission);
}
debug(player, permission, ret);
return ret;
}
public boolean hasPermission(CommandSender sender, String permission) {
if (sender instanceof Player) {
return hasPermission((Player) sender, permission);
} else {
debug(sender, permission, true);
return true;
}
}
private void debug(CommandSender player, String permission, boolean result) {
if (plugin instanceof LimitedCreativeCore && ((LimitedCreativeCore) plugin).config.getDebug())
LimitedCreativeCore.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
}
}

View file

@ -78,6 +78,9 @@ final public class Util {
return join(list, " ", from, range); return join(list, " ", from, range);
} }
public static String join(String[] list, int from) { public static String join(String[] list, int from) {
return join(list, " ", from, from); return join(list, " ", from, list.length - from);
}
public static String join(String[] list) {
return join(list, " ", 0, list.length);
} }
} }

View file

@ -0,0 +1,17 @@
package de.jaschastarke.minecraft.worldedit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.wepif.PermissionsResolverManager;
public class PermissionsBridge {
protected com.sk89q.wepif.PermissionsResolverManager pif;
public PermissionsBridge(JavaPlugin plugin) {
PermissionsResolverManager.initialize(plugin);
pif = PermissionsResolverManager.getInstance();
}
public boolean hasPermission(OfflinePlayer sender, String permission) {
return pif.hasPermission(sender, permission);
}
}

View file

@ -62,7 +62,7 @@ public class CCommand implements CommandExecutor {
if (args.length < 2) { if (args.length < 2) {
return false; return false;
} }
if (!sender.hasPermission("limitedcreative.regions")) { if (!wg.hasPermission(sender, "limitedcreative.regions")) {
sender.sendMessage(ChatColor.DARK_RED + L("exception.command.lackingpermission")); sender.sendMessage(ChatColor.DARK_RED + L("exception.command.lackingpermission"));
return true; return true;
} }