From cf9449aae55c84b4999adf90ea6f294fec487db0 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sun, 10 Feb 2013 22:12:31 +0100 Subject: [PATCH] base region general working --- TODO.txt | 5 +++ .../FeatureSwitchGameMode.java | 2 +- .../minecraft/limitedcreative/ModRegions.java | 11 +++++- .../regions/RegionsCommand.java | 36 ++++++++++++------- ...istener.java => PlayerRegionListener.java} | 5 +-- ...erties => disabled.messages_de.properties} | 0 6 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 TODO.txt rename src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/{PlayerListener.java => PlayerRegionListener.java} (94%) rename src/main/resources/lang/{messages_de.properties => disabled.messages_de.properties} (100%) diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..a51cb2e --- /dev/null +++ b/TODO.txt @@ -0,0 +1,5 @@ + - Region-Config? Where are the missing options? + - Region: permanent gamemode storage? (safemode, if not permanent: region!) maybe only if regionsset empty? + - remove config.yml and plugin.yml + - cleanup localize-messages + - rework german localization \ No newline at end of file diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java index db52a9a..5e05d89 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java @@ -82,7 +82,7 @@ public class FeatureSwitchGameMode extends CoreModule { GameMode wgm = Hooks.DefaultWorldGameMode.get(target.getWorld()); - if (!context.checkPermission(permission) && !(wgm != tgm || !context.checkPermission(SwitchGameModePermissions.BACKONLY))) + if (!context.checkPermission(permission) && (wgm != tgm || !context.checkPermission(SwitchGameModePermissions.BACKONLY))) throw new MissingPermissionCommandException(permission); target.setGameMode(tgm); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java index c983830..95b343f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java @@ -8,12 +8,16 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; +import de.jaschastarke.minecraft.limitedcreative.regions.BlockListener; import de.jaschastarke.minecraft.limitedcreative.regions.Flags; import de.jaschastarke.minecraft.limitedcreative.regions.PlayerData; +import de.jaschastarke.minecraft.limitedcreative.regions.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.regions.RegionConfig; +import de.jaschastarke.minecraft.limitedcreative.regions.RegionListener; import de.jaschastarke.minecraft.limitedcreative.regions.RegionsCommand; import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager; import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList; +import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry.ModuleState; @@ -42,7 +46,12 @@ public class ModRegions extends CoreModule { command = new RegionsCommand(this); plugin.getCommandHandler().registerCommand(command); - plugin.getMainCommand().registerCommand(new AliasHelpedCommand(command, "region")); + plugin.getMainCommand().registerCommand(new AliasHelpedCommand(command, "region", new String[]{"r"})); + + listeners.registerEvents(new PlayerListener(this)); + listeners.registerEvents(new BlockListener(this)); + listeners.registerEvents(new RegionListener(this)); + listeners.registerEvents(new PlayerRegionListener(this)); FlagList.addFlags(Flags.getList()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java index f42bd72..d64d57c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java @@ -4,6 +4,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.World; +import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; import com.sk89q.worldguard.protection.managers.RegionManager; @@ -147,12 +148,14 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { public boolean getInfo(CommandContext context, String... args) throws CommandException { DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"s"}, 1); - /* - * WorldEdits intercepting Servers privates commandMap via Reflections realy sucks! - * Just because they are to lazy to add all the lines commands to plugin.yml - */ - String orgCmd = ("region info " + StringUtils.join(args)).trim(); - mod.getPlugin().getServer().dispatchCommand(context.getSender(), orgCmd); + if (context.isPlayer()) { + /* + * WorldEdits intercepting Servers privates commandMap via Reflections realy sucks! + * Just because they are to lazy to add all the lines commands to plugin.yml + */ + String orgCmd = ("region info " + StringUtils.join(args)).trim(); + mod.getPlugin().getServer().dispatchCommand(context.getSender(), orgCmd); + } World w = context.isPlayer() ? context.getPlayer().getWorld() : null; if (params.getArgumentCount() > 1) @@ -160,12 +163,21 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (w == null) throw new CommandException(L("command.worldguard.world_not_found")); - int rpc = params.getArgumentCount() > 1 ? 2 : 1; - RegionManager mgr = mod.getWorldGuard().getGlobalRegionManager().get(w); - ProtectedRegion region = mgr.getRegion(params.getArgument(rpc)); - if (region == null && params.getArgument(rpc).equalsIgnoreCase("__global__")) { - region = new GlobalProtectedRegion(params.getArgument(rpc)); - mgr.addRegion(region); + ProtectedRegion region = null; + if (params.getArgumentCount() == 0 && context.isPlayer()) { + RegionManager mgr = mod.getWorldGuard().getGlobalRegionManager().get(context.getPlayer().getWorld()); + ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation()); + if (set.size() > 0) { + region = set.iterator().next(); + } + } else { + int rpc = params.getArgumentCount() > 1 ? 1 : 0; + RegionManager mgr = mod.getWorldGuard().getGlobalRegionManager().get(w); + region = mgr.getRegion(params.getArgument(rpc)); + if (region == null && params.getArgument(rpc).equalsIgnoreCase("__global__")) { + region = new GlobalProtectedRegion(params.getArgument(rpc)); + mgr.addRegion(region); + } } if (region == null) throw new CommandException(L("command.worldguard.region_not_found")); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerRegionListener.java similarity index 94% rename from src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerListener.java rename to src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerRegionListener.java index b81dd96..c9c3d8f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/PlayerRegionListener.java @@ -32,10 +32,10 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events.Playe import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events.PlayerNewLocationAreaEvent; import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events.PlayerSetAreaEvent; -public class PlayerListener implements Listener { +public class PlayerRegionListener implements Listener { private ModRegions mod; - public PlayerListener(ModRegions mod) { + public PlayerRegionListener(ModRegions mod) { this.mod = mod; } @@ -50,6 +50,7 @@ public class PlayerListener implements Listener { || !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // he really moved, and not just looked around String current_hash = mod.getPlayerData(event.getPlayer()).getHash(); + mod.getLog().debug(event.getPlayer().getName()+" "+current_hash); if (current_hash == null) { String new_hash = mod.getRegionManager().getRegionsHash(event.getTo()); Bukkit.getServer().getPluginManager().callEvent(new PlayerSetAreaEvent(mod.getRegionManager(), event.getPlayer(), new_hash, event.getTo())); diff --git a/src/main/resources/lang/messages_de.properties b/src/main/resources/lang/disabled.messages_de.properties similarity index 100% rename from src/main/resources/lang/messages_de.properties rename to src/main/resources/lang/disabled.messages_de.properties