v0.8.1:
- Debug mode for the several issue tickets - Permission via WEPIF - Sign Interact Priority-Fix - MultiInv compatibility disable
This commit is contained in:
parent
295a93b384
commit
4fc58c86aa
12 changed files with 168 additions and 45 deletions
|
@ -2,6 +2,14 @@ basic:
|
|||
loaded:
|
||||
worldguard: Successfully loaded with WorldGuard-Integration
|
||||
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:
|
||||
player: player
|
||||
switch:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
name: LimitedCreative
|
||||
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
||||
version: 0.8-beta
|
||||
softdepend: [WorldGuard]
|
||||
version: 0.8.1-beta
|
||||
softdepend: [WorldGuard, WorldEdit, MultiInv]
|
||||
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
||||
commands:
|
||||
limitedcreative:
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.bukkit.command.CommandExecutor;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.minecraft.utils.Util;
|
||||
import de.jaschastarke.minecraft.worldguard.CCommand;
|
||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
|
@ -43,6 +44,7 @@ public class Commands {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
LimitedCreativeCore.debug(sender.getName() + ": /" + label + " " + Util.join(args));
|
||||
if (args.length > 0) {
|
||||
Action act = null;
|
||||
try {
|
||||
|
@ -74,6 +76,7 @@ public class Commands {
|
|||
return true;
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
LimitedCreativeCore.debug("CommandException: "+e.getMessage());
|
||||
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
||||
return true;
|
||||
}
|
||||
|
@ -84,11 +87,11 @@ public class Commands {
|
|||
StringBuilder message = new StringBuilder();
|
||||
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");
|
||||
if (sender.hasPermission("limitedcreative.config"))
|
||||
if (plugin.perm.hasPermission(sender, "limitedcreative.config"))
|
||||
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");
|
||||
if (sender.hasPermission("limitedcreative.regions"))
|
||||
if (plugin.perm.hasPermission(sender, "limitedcreative.regions"))
|
||||
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
|
||||
if (message.length() > 0) {
|
||||
sender.sendMessage("Usage:");
|
||||
|
@ -107,10 +110,11 @@ public class Commands {
|
|||
BLOCKSIGN,
|
||||
PERMISSIONS,
|
||||
PERM_KEEPINVENTORY,
|
||||
DEBUG,
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
if (args.length > 2)
|
||||
|
@ -156,7 +160,7 @@ public class Commands {
|
|||
|
||||
if (target == null) {
|
||||
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();
|
||||
} else if (target.getGameMode() != gm) {
|
||||
if (sender == target) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class Configuration {
|
|||
}
|
||||
|
||||
public boolean getStoreEnabled() {
|
||||
return c.getBoolean("store.enabled", true);
|
||||
return getTempStoreEnabled() && c.getBoolean("store.enabled", true);
|
||||
}
|
||||
public boolean getLimitEnabled() {
|
||||
return c.getBoolean("limit.enabled", true);
|
||||
|
@ -85,7 +85,12 @@ public class Configuration {
|
|||
return c.getBoolean("region.optional", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDebug(boolean value) {
|
||||
this.reload();
|
||||
c.set("debug", value);
|
||||
this.save();
|
||||
}
|
||||
public void setStoreCreative(boolean value) {
|
||||
this.reload();
|
||||
c.set("store.creative", value);
|
||||
|
@ -157,4 +162,12 @@ public class Configuration {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private boolean _store_enabled = true;
|
||||
public void setTempStoreEnabled(boolean b) {
|
||||
_store_enabled = b;
|
||||
}
|
||||
public boolean getTempStoreEnabled() {
|
||||
return _store_enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,8 +59,10 @@ public class LCPlayer {
|
|||
private LCPlayer(Player pplayer) {
|
||||
player = pplayer;
|
||||
_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);
|
||||
}
|
||||
}
|
||||
|
||||
public Player getRaw() {
|
||||
|
@ -82,14 +84,16 @@ public class LCPlayer {
|
|||
}
|
||||
|
||||
public void changeGameMode(GameMode gm) throws LackingPermissionException {
|
||||
if (!isRegionCreative() && !getRaw().hasPermission("limitedcreative.switch_gamemode")) {
|
||||
if (gm != GameMode.SURVIVAL || !getRaw().hasPermission("limitedcreative.switch_gamemode.backonly")) {
|
||||
if (!isRegionCreative() && !hasPermission("limitedcreative.switch_gamemode")) {
|
||||
if (gm != GameMode.SURVIVAL || !hasPermission("limitedcreative.switch_gamemode.backonly")) {
|
||||
LimitedCreativeCore.debug(player.getName() + " lacking permission /lc [cs]");
|
||||
throw new Commands.LackingPermissionException();
|
||||
}
|
||||
}
|
||||
getRaw().setGameMode(gm);
|
||||
}
|
||||
public void setRegionCreative(boolean b) {
|
||||
LimitedCreativeCore.debug(player.getName() + " region creative: " + b);
|
||||
if (b) {
|
||||
store.set(player.getName()+".region_creative", true);
|
||||
} else {
|
||||
|
@ -107,16 +111,18 @@ public class LCPlayer {
|
|||
return _isPermanentCreative;
|
||||
}
|
||||
public void setPermanentCreative(boolean b) {
|
||||
LimitedCreativeCore.debug(player.getName() + " permanent creative: " + b);
|
||||
_isPermanentCreative = b;
|
||||
if (b)
|
||||
setRegionCreative(false);
|
||||
}
|
||||
|
||||
public boolean onSetCreative() {
|
||||
LimitedCreativeCore.debug(player.getName() + " going into creative");
|
||||
if (!this.isRegionCreative())
|
||||
setPermanentCreative(true);
|
||||
if (plugin.config.getStoreEnabled()) {
|
||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
|
||||
return true;
|
||||
Inventory inv = new Inventory(player);
|
||||
inv.save();
|
||||
|
@ -129,15 +135,17 @@ public class LCPlayer {
|
|||
return true;
|
||||
}
|
||||
public boolean onSetSurvival() {
|
||||
LimitedCreativeCore.debug(player.getName() + " going into survival");
|
||||
if (isRegionCreative()) {
|
||||
if (!plugin.config.getRegionOptional()) {
|
||||
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
|
||||
LimitedCreativeCore.debug("... denied");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
setPermanentCreative(false);
|
||||
if (plugin.config.getStoreEnabled()) {
|
||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
|
||||
return true;
|
||||
Inventory inv = new Inventory(player);
|
||||
if (plugin.config.getStoreCreative()) {
|
||||
|
@ -150,14 +158,14 @@ public class LCPlayer {
|
|||
}
|
||||
public void onDropItem(PlayerDropItemEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
|
||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.drop"))
|
||||
return;
|
||||
event.getItemDrop().remove();
|
||||
}
|
||||
}
|
||||
public void onPickupItem(PlayerPickupItemEvent event) {
|
||||
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;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -165,7 +173,7 @@ public class LCPlayer {
|
|||
|
||||
public void onDie(EntityDeathEvent event) {
|
||||
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();
|
||||
tempinv = Items.storeInventory(player.getInventory());
|
||||
}
|
||||
|
@ -173,7 +181,7 @@ public class LCPlayer {
|
|||
}
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
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) {
|
||||
Items.restoreInventory(player.getInventory(), tempinv);
|
||||
}
|
||||
|
@ -187,12 +195,13 @@ public class LCPlayer {
|
|||
// its PVP
|
||||
Player attacker = (Player) event.getDamager();
|
||||
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);
|
||||
return; // skip next check
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +210,7 @@ public class LCPlayer {
|
|||
public void onChestAccess(PlayerInteractEvent event) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest"))
|
||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
|
@ -209,7 +218,7 @@ public class LCPlayer {
|
|||
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest"))
|
||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
|
@ -217,7 +226,7 @@ public class LCPlayer {
|
|||
public void onSignAccess(PlayerInteractEvent event) {
|
||||
if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.sign"))
|
||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.sign"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.sign"));
|
||||
event.setCancelled(true);
|
||||
|
@ -274,4 +283,8 @@ public class LCPlayer {
|
|||
player.getLocation().getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return plugin.perm.hasPermission(this.getRaw(), permission);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,13 @@ import de.jaschastarke.minecraft.limitedcreative.listeners.LimitListener;
|
|||
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||
import de.jaschastarke.minecraft.utils.Locale;
|
||||
import de.jaschastarke.minecraft.utils.Permissions;
|
||||
|
||||
|
||||
public class LimitedCreativeCore extends JavaPlugin {
|
||||
public final Logger logger = Logger.getLogger("Minecraft");
|
||||
public Configuration config;
|
||||
public Permissions perm;
|
||||
public WorldGuardIntegration worldguard;
|
||||
public static LimitedCreativeCore plugin;
|
||||
public NoBlockItemSpawn spawnblock;
|
||||
|
@ -41,29 +43,43 @@ public class LimitedCreativeCore extends JavaPlugin {
|
|||
worldguard = null;
|
||||
config = null;
|
||||
spawnblock = null;
|
||||
Locale.unload();
|
||||
//info("cleanly unloaded.");
|
||||
try {
|
||||
Locale.unload();
|
||||
} catch (NoClassDefFoundError e) {} // prevent unload issue
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
config = new Configuration(this);
|
||||
perm = new Permissions(this);
|
||||
|
||||
new Locale(this);
|
||||
|
||||
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);
|
||||
|
||||
// 2nd Feature: Creative Limitations (Restrictions)
|
||||
if (config.getLimitEnabled())
|
||||
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);
|
||||
} 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);
|
||||
|
||||
PluginDescriptionFile df = this.getDescription();
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.entity.StorageMinecart;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
@ -67,12 +68,13 @@ public class LimitListener implements Listener {
|
|||
LCPlayer.get(event.getPlayer()).onPickupItem(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
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())) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
|
@ -87,19 +89,20 @@ public class LimitListener implements Listener {
|
|||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block.getState() instanceof ContainerBlock) {
|
||||
LCPlayer.get(event.getPlayer()).onChestAccess(event);
|
||||
player.onChestAccess(event);
|
||||
}
|
||||
if (block.getState() instanceof Sign) {
|
||||
LCPlayer.get(event.getPlayer()).onSignAccess(event);
|
||||
player.onSignAccess(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
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())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
|
@ -110,7 +113,7 @@ public class LimitListener implements Listener {
|
|||
Entity entity = event.getRightClicked();
|
||||
|
||||
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) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
|
@ -137,14 +140,15 @@ public class LimitListener implements Listener {
|
|||
if (event.isCancelled())
|
||||
return;
|
||||
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())) {
|
||||
event.setCancelled(true);
|
||||
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;
|
||||
// Prevent dropping of doors and beds when destroying the wrong part
|
||||
Block block = event.getBlock();
|
||||
|
@ -175,7 +179,8 @@ public class LimitListener implements Listener {
|
|||
if (event.isCancelled())
|
||||
return;
|
||||
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())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.place"));
|
||||
|
|
|
@ -42,10 +42,6 @@ public class WorldGuardIntegration {
|
|||
plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin);
|
||||
}
|
||||
|
||||
public static boolean available() {
|
||||
return LimitedCreativeCore.plugin.getServer().getPluginManager().getPlugin("WorldGuard") != null;
|
||||
}
|
||||
|
||||
public CRegionManager getRegionManager() {
|
||||
return rm;
|
||||
}
|
||||
|
|
48
src/de/jaschastarke/minecraft/utils/Permissions.java
Normal file
48
src/de/jaschastarke/minecraft/utils/Permissions.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -78,6 +78,9 @@ final public class Util {
|
|||
return join(list, " ", from, range);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ public class CCommand implements CommandExecutor {
|
|||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
if (!sender.hasPermission("limitedcreative.regions")) {
|
||||
if (!wg.hasPermission(sender, "limitedcreative.regions")) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("exception.command.lackingpermission"));
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue