v1.2.0-alpha:

- initial worldguard 5.5.2-snapshot
This commit is contained in:
Jascha Starke 2012-03-02 20:40:10 +01:00
parent 296278d3ed
commit 69786772f7
10 changed files with 92 additions and 109 deletions

View file

@ -54,10 +54,10 @@ blocked:
button: To interact with buttons is not allowed in creative mode button: To interact with buttons is not allowed in creative mode
lever: To interact with levers is not allowed in creative mode lever: To interact with levers is not allowed in creative mode
survival_flying: You should stay on ground, when leaving a creative-area survival_flying: You should stay on ground, when leaving a creative-area
outside_creative: You can not place blocks outside of the creative-area outside_place: You can not place blocks outside of the gamemode-area
outside_creative_break: You can not destroy blocks outside of the creative-area outside_break: You can not destroy blocks outside of the gamemode-area
inside_survival: You can not place blocks inside of the survival-area inside_place: You can not place blocks inside of the gamemode-area
inside_survival_break: You can not destroy blocks inside of the survival-area inside_break: You can not destroy blocks inside of the gamemode-area
use: You are not allowed to use this type of item use: You are not allowed to use this type of item
place: You are not allowed to place this type of block place: You are not allowed to place this type of block
break: You are not allowed to break this type of block break: You are not allowed to break this type of block

View file

@ -1,6 +1,6 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.Core main: de.jaschastarke.minecraft.limitedcreative.Core
version: 1.0 version: 1.2.0-alpha
softdepend: [WorldGuard, WorldEdit, MultiInv] 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:

View file

@ -44,8 +44,9 @@ public class Core extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
plugin.getServer().getScheduler().cancelTasks(this); plugin.getServer().getScheduler().cancelTasks(this);
try { if (worldguard != null)
worldguard.unload(); worldguard.unload();
try {
Locale.unload(); Locale.unload();
} catch (NoClassDefFoundError e) {} // prevent unload issue } catch (NoClassDefFoundError e) {} // prevent unload issue

View file

@ -100,7 +100,7 @@ public class LCPlayer {
Players.getOptions().setRegionGameMode(getName(), gm); Players.getOptions().setRegionGameMode(getName(), gm);
} }
private GameMode getRegionGameMode() { public GameMode getRegionGameMode() {
if (!options.containsKey("region")) { if (!options.containsKey("region")) {
options.put("region", Players.getOptions().getRegionGameMode(getName())); options.put("region", Players.getOptions().getRegionGameMode(getName()));
} }

View file

@ -4,21 +4,17 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
public final class Flags { public final class Flags {
public static final StateFlag SPAWNDROPS = new StateFlag("spawndrops", true); public static final StateFlag SPAWNDROPS = new StateFlag("spawndrops", true);
public static final StateFlag CREATIVE = new StateFlag("creative", false); public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode", RegionGroup.MEMBERS);
public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS);
static {
CREATIVE.setGroupFlag(CREATIVE_GROUP);
}
public static List<Flag<?>> getList() { public static List<Flag<?>> getList() {
return Arrays.asList(new Flag<?>[]{ return Arrays.asList(new Flag<?>[]{
SPAWNDROPS, SPAWNDROPS,
CREATIVE, GAMEMODE,
CREATIVE_GROUP
}); });
} }
} }

View file

@ -6,89 +6,41 @@ import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.RegionGroup;
/** /**
* Well, that was an interesting idea, but it doesn't work. * Well, that was an interesting idea, but it doesn't work.
*/ */
public class GameModeFlag extends Flag<GameModeFlag.State> { public class GameModeFlag extends Flag<GameMode> {
private State def; public GameModeFlag(String name, RegionGroup defaultGroup) {
private RegionGroupFlag groupFlag; super(name, defaultGroup);
public enum State {
CREATIVE,
SURVIVAL,
NONE;
public GameMode getGameMode() {
return getBukkitGameMode(this);
}
public boolean equals (GameMode gm) {
return gm == this.getGameMode();
}
public static GameMode getBukkitGameMode(State gm) {
switch (gm) {
case CREATIVE:
return GameMode.CREATIVE;
case SURVIVAL:
return GameMode.SURVIVAL;
default:
return null;
}
}
}
public GameModeFlag(String name, State def) {
super(name);
this.def = def;
}
public State getDefault() {
return def;
}
public RegionGroupFlag getGroupFlag() {
return groupFlag;
}
public void setGroupFlag(RegionGroupFlag groupFlag) {
this.groupFlag = groupFlag;
} }
@Override @Override
public State parseInput(WorldGuardPlugin plugin, CommandSender sender, String input) throws InvalidFlagFormat { public GameMode parseInput(WorldGuardPlugin plugin, CommandSender sender, String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
if (input.equalsIgnoreCase("creative")) { if (input.equalsIgnoreCase("creative")) {
return State.CREATIVE; return GameMode.CREATIVE;
} else if (input.equalsIgnoreCase("survival")) { } else if (input.equalsIgnoreCase("survival")) {
return State.SURVIVAL; return GameMode.SURVIVAL;
} else if (input.equalsIgnoreCase("none")) { } else if (input.equalsIgnoreCase("none")) {
return null; return null;
} else { } else {
throw new InvalidFlagFormat("Expected none/allow/deny but got '" + input + "'"); throw new InvalidFlagFormat("Expected survival/creative/none but got '" + input + "'");
} }
} }
@Override @Override
public State unmarshal(Object o) { public GameMode unmarshal(Object o) {
String input = o.toString(); GameMode gm = null;
if (input.equalsIgnoreCase("creative")) { if (o != null) {
return State.CREATIVE; gm = GameMode.valueOf((String) o);
} else if (input.equalsIgnoreCase("survival")) {
return State.SURVIVAL;
} else {
return null;
} }
return gm;
} }
@Override @Override
public Object marshal(State o) { public Object marshal(GameMode o) {
if (o == State.CREATIVE) { return o == null ? null : o.name();
return "allow";
} else if (o == State.SURVIVAL) {
return "deny";
} else {
return null;
}
} }
} }

View file

@ -38,31 +38,31 @@ public class RegionListener implements Listener {
private ApplicableRegions regionSet(Block block) { private ApplicableRegions regionSet(Block block) {
return rm.getRegionSet(block); return rm.getRegionSet(block);
} }
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
LCPlayer player = Players.get(event.getPlayer()); LCPlayer player = Players.get(event.getPlayer());
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation()); boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
boolean creative_world = plugin.com.isCreative(event.getBlock().getWorld());
if (player.isRegionGameMode() && diffrent_region) { if (player.isRegionGameMode() && diffrent_region) {
// do not break outside of "gamemod-change-region" when in the region // do not break outside of "gamemod-change-region" when in the region
if (!rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE, event.getPlayer())) { if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != player.getRegionGameMode()) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break")); event.getPlayer().sendMessage(L("blocked.outside_break"));
event.setCancelled(true); event.setCancelled(true);
} }
} 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 (rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) { if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null) {
event.getPlayer().sendMessage(L("blocked.inside_survival_break")); event.getPlayer().sendMessage(L("blocked.inside_break"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
if (!creative_world) { // in survival world if (!event.isCancelled()) {
// prevent any drops for survival players in creative regions in survival worlds // prevent any drops for survival players in creative regions
if (event.getPlayer().getGameMode() != GameMode.CREATIVE && rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) { if (event.getPlayer().getGameMode() != GameMode.CREATIVE && rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
plugin.spawnblock.block(event.getBlock(), player); plugin.spawnblock.block(event.getBlock(), player);
} }
} }
@ -78,14 +78,14 @@ public class RegionListener implements Listener {
if (player.isRegionGameMode() && diffrent_region) { if (player.isRegionGameMode() && diffrent_region) {
// do not build outside of "gamemod-change-region" when in the region // do not build outside of "gamemod-change-region" when in the region
if (!rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE, event.getPlayer())) { if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != player.getRegionGameMode()) {
event.getPlayer().sendMessage(L("blocked.outside_creative")); event.getPlayer().sendMessage(L("blocked.outside_place"));
event.setCancelled(true); event.setCancelled(true);
} }
} 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 (rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) { if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null) {
event.getPlayer().sendMessage(L("blocked.inside_survival")); event.getPlayer().sendMessage(L("blocked.inside_place"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -93,17 +93,17 @@ public class RegionListener implements Listener {
@EventHandler @EventHandler
public void onPlayerChangedArea(PlayerNewLocationAreaEvent event) { public void onPlayerChangedArea(PlayerNewLocationAreaEvent event) {
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event); Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()) != null, event);
} }
@EventHandler @EventHandler
public void onPlayerSetArea(PlayerSetAreaEvent event) { public void onPlayerSetArea(PlayerSetAreaEvent event) {
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event); Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()) != null, event);
} }
@EventHandler @EventHandler
public void onPlayerUpdateArea(PlayerUpdateAreaEvent event) { public void onPlayerUpdateArea(PlayerUpdateAreaEvent event) {
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event); Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()) != null, event);
} }
@EventHandler @EventHandler
@ -114,11 +114,11 @@ public class RegionListener implements Listener {
Block source = event.getBlock().getRelative(event.getDirection()); Block source = event.getBlock().getRelative(event.getDirection());
Core.debug("PistonExtend "+source.getType()+" "+event.getDirection()); Core.debug("PistonExtend "+source.getType()+" "+event.getDirection());
if (source.getType() != Material.AIR) { if (source.getType() != Material.AIR) {
if (regionSet(source).allows(Flags.CREATIVE)) { if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
for (int i = 1; i <= 12; i++) { for (int i = 1; i <= 12; i++) {
Block dest = source.getRelative(event.getDirection(), i); Block dest = source.getRelative(event.getDirection(), i);
Core.debug("dest "+i+": "+dest.getType()); Core.debug("dest "+i+": "+dest.getType());
if (!regionSet(dest).allows(Flags.CREATIVE)) { if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) {
plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation()))); plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true); event.setCancelled(true);
break; break;
@ -139,19 +139,19 @@ public class RegionListener implements Listener {
Core.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky()); Core.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
if (event.isSticky() && source.getType() != Material.AIR) { if (event.isSticky() && source.getType() != Material.AIR) {
Core.debug("dest "+dest.getType()); Core.debug("dest "+dest.getType());
if (regionSet(source).allows(Flags.CREATIVE)) { if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
if (!regionSet(dest).allows(Flags.CREATIVE)) { if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) {
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation()))); plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true); event.setCancelled(true);
} }
} else if (regionSet(dest).allows(Flags.CREATIVE)) { } else if (regionSet(dest).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
// source isn't creative // source isn't creative
plugin.logger.warning(L("blocked.piston_in", source.getType().toString(), Util.toString(source.getLocation()))); plugin.logger.warning(L("blocked.piston_in", source.getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
@EventHandler @EventHandler
public void onItemSpawn(ItemSpawnEvent event) { public void onItemSpawn(ItemSpawnEvent event) {
if (event.isCancelled()) if (event.isCancelled())

View file

@ -49,6 +49,20 @@ public class ApplicableRegions {
contractRegionFlags(); contractRegionFlags();
return r; return r;
} }
public <T extends Flag<V>, V> V getFlag(T flag) {
extendRegionFlags();
V r = regions.getFlag(flag);
contractRegionFlags();
return r;
}
public <T extends Flag<V>, V> V getFlag(T flag, Player player) {
extendRegionFlags();
V r = regions.getFlag(flag, WorldGuardIntegration.wg.wrapPlayer(player));
contractRegionFlags();
return r;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends Flag<V>, V> void extendRegionFlags() { private <T extends Flag<V>, V> void extendRegionFlags() {

View file

@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.worldguard;
import static de.jaschastarke.minecraft.utils.Locale.L; import static de.jaschastarke.minecraft.utils.Locale.L;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -136,8 +137,11 @@ public class CCommand implements CommandExecutor {
hasPermission(sender, Perms.INFO); hasPermission(sender, Perms.INFO);
}*/ }*/
String[] args = new String[]{"info", region.getWorld().getName(), region.getProtectedRegion().getId()}; /*
wg.onCommand(sender, wg.getCommand("region"), "region", args); * WorldEdits intercepting Servers privates commandMap via Reflections realy sucks!
* Just because they are to lazy to add all the lines commands to plugin.yml
*/
Bukkit.getServer().dispatchCommand(sender, "region info "+region.getWorld().getName()+ " "+region.getProtectedRegion().getId());
StringBuilder list = new StringBuilder(); StringBuilder list = new StringBuilder();
for (FlagValue data : region.getFlags()) { for (FlagValue data : region.getFlags()) {
@ -157,15 +161,24 @@ public class CCommand implements CommandExecutor {
return; return;
} }
String flagName = args[2]; String flagName = args[2];
String value = null;
Flag<?> flag = FlagList.getFlag(flagName); Flag<?> flag = FlagList.getFlag(flagName);
if (args.length > 3 && args[3].equalsIgnoreCase("-g")) {
flag = flag.getRegionGroupFlag();
if (args.length > 4)
value = Util.join(args, 4);
} else {
if (args.length > 3)
value = Util.join(args, 3);
}
if (flag == null) { if (flag == null) {
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.unknown_flag") + ": " + flagName); sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.unknown_flag") + ": " + flagName);
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.available_flags") + ": " + FlagList.getStringListAvailableFlags(sender)); sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.available_flags") + ": " + FlagList.getStringListAvailableFlags(sender));
return; return;
} }
String value = null;
if (args.length > 3)
value = Util.join(args, 3);
try { try {
if (value != null) { if (value != null) {

View file

@ -103,7 +103,12 @@ public class CRegionManager {
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags"); ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
fs.set(flag.getName(), flag.marshal((V) value));
Object o = null;
if (value != null)
o = flag.marshal((V) value);
fs.set(flag.getName(), o);
try { try {
c.save(file); c.save(file);
@ -122,8 +127,10 @@ public class CRegionManager {
ConfigurationSection fs = rs.getConfigurationSection("flags"); ConfigurationSection fs = rs.getConfigurationSection("flags");
for (Map.Entry<String, Object> data : fs.getValues(false).entrySet()) { for (Map.Entry<String, Object> data : fs.getValues(false).entrySet()) {
Flag<?> flag = FlagList.getFlag(data.getKey()); Flag<?> flag = FlagList.getFlag(data.getKey());
Object value = flag.unmarshal(data.getValue()); if (flag != null) { // the flag doesn't exists anymore. just ignore it without error
list.add(new FlagValue(flag, value)); Object value = flag.unmarshal(data.getValue());
list.add(new FlagValue(flag, value));
}
} }
} }
} }