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
lever: To interact with levers is not allowed in creative mode
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_creative_break: You can not destroy blocks outside of the creative-area
inside_survival: You can not place blocks inside of the survival-area
inside_survival_break: You can not destroy blocks inside of the survival-area
outside_place: You can not place blocks outside of the gamemode-area
outside_break: You can not destroy blocks outside of the gamemode-area
inside_place: You can not place blocks inside of the gamemode-area
inside_break: You can not destroy blocks inside of the gamemode-area
use: You are not allowed to use this type of item
place: You are not allowed to place this type of block
break: You are not allowed to break this type of block

View file

@ -1,6 +1,6 @@
name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.Core
version: 1.0
version: 1.2.0-alpha
softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands:

View file

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

View file

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

View file

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

View file

@ -6,89 +6,41 @@ import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
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.
*/
public class GameModeFlag extends Flag<GameModeFlag.State> {
private State def;
private RegionGroupFlag groupFlag;
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;
public class GameModeFlag extends Flag<GameMode> {
public GameModeFlag(String name, RegionGroup defaultGroup) {
super(name, defaultGroup);
}
@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();
if (input.equalsIgnoreCase("creative")) {
return State.CREATIVE;
return GameMode.CREATIVE;
} else if (input.equalsIgnoreCase("survival")) {
return State.SURVIVAL;
return GameMode.SURVIVAL;
} else if (input.equalsIgnoreCase("none")) {
return null;
} else {
throw new InvalidFlagFormat("Expected none/allow/deny but got '" + input + "'");
throw new InvalidFlagFormat("Expected survival/creative/none but got '" + input + "'");
}
}
@Override
public State unmarshal(Object o) {
String input = o.toString();
if (input.equalsIgnoreCase("creative")) {
return State.CREATIVE;
} else if (input.equalsIgnoreCase("survival")) {
return State.SURVIVAL;
} else {
return null;
public GameMode unmarshal(Object o) {
GameMode gm = null;
if (o != null) {
gm = GameMode.valueOf((String) o);
}
return gm;
}
@Override
public Object marshal(State o) {
if (o == State.CREATIVE) {
return "allow";
} else if (o == State.SURVIVAL) {
return "deny";
} else {
return null;
}
public Object marshal(GameMode o) {
return o == null ? null : o.name();
}
}

View file

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

View file

@ -50,6 +50,20 @@ public class ApplicableRegions {
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")
private <T extends Flag<V>, V> void extendRegionFlags() {
for (ProtectedRegion pr : regions) {

View file

@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.worldguard;
import static de.jaschastarke.minecraft.utils.Locale.L;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
@ -136,8 +137,11 @@ public class CCommand implements CommandExecutor {
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();
for (FlagValue data : region.getFlags()) {
@ -157,15 +161,24 @@ public class CCommand implements CommandExecutor {
return;
}
String flagName = args[2];
String value = null;
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) {
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.unknown_flag") + ": " + flagName);
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.available_flags") + ": " + FlagList.getStringListAvailableFlags(sender));
return;
}
String value = null;
if (args.length > 3)
value = Util.join(args, 3);
try {
if (value != null) {

View file

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