Merge branch 'Bukkit-1.2'

This commit is contained in:
Jascha Starke 2012-04-13 19:04:33 +02:00
commit 41fe092ac9
17 changed files with 253 additions and 161 deletions

7
.gitignore vendored
View file

@ -1,5 +1,10 @@
/bin
# Eclipse stuff
/.project /.project
/.classpath /.classpath
/bin
/.settings /.settings
/.buildpath
# maven
/target /target

View file

@ -1,11 +1,25 @@
# Limited Creative # Limited Creative
http://dev.bukkit.org/server-mods/limited-creative/ http://dev.bukkit.org/server-mods/limited-creative/
There is no automated building yet, so just use "Export..." -> "JAR file" in Eclipse Required dependencies
---------------------
Dependencies: * [Bukkit](https://github.com/Bukkit/Bukkit)
* [Craftbukkit](https://github.com/Bukkit/CraftBukkit) Dependencies for optional integrations
* which implies [Bukkit](https://github.com/Bukkit/Bukkit) --------------------------------------
* Optional: [WorldGuard](https://github.com/sk89q/worldguard)
* which depends on [WorldEdit](https://github.com/sk89q/worldedit) * [WorldGuard](https://github.com/sk89q/worldguard)
* [WorldEdit](https://github.com/sk89q/worldedit)
* [xAuth](http://dev.bukkit.org/server-mods/xauth/)
* [AuthMe](http://dev.bukkit.org/server-mods/authme-reloaded/)
* [Multiverse-Core](http://dev.bukkit.org/server-mods/multiverse-core/)
----
To use Maven packaging
----------------------
For required development snapshots, that aren't found by maven, you have to clone the project and do:
$ mvn install
in the directory of the project

View file

@ -105,8 +105,10 @@ limit:
# data-value, all items/blocks of this material are blocked. # data-value, all items/blocks of this material are blocked.
# You also may add the special block "*" (better add quotes to don't break yml) which prevents the usage of ANY # You also may add the special block "*" (better add quotes to don't break yml) which prevents the usage of ANY
# item/block. # item/block.
# default: [] # default: [exp_bottle, bedrock]
use: [] use:
- EXP_BOTTLE
- bedrock
# BreakBlackList # BreakBlackList
# Prevents destroying of the given blocks in creative mode (and only in creative). # Prevents destroying of the given blocks in creative mode (and only in creative).

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.1 version: 1.2.3-beta
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:

97
pom.xml Normal file
View file

@ -0,0 +1,97 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.jaschastarke</groupId>
<artifactId>LimitedCreative</artifactId>
<name>LimitedCreative</name>
<version>1.2.0-SNAPSHOT</version>
<url>https://github.com/possi/LimitedCreative</url>
<scm>
<connection>scm:git:git://github.com/possi/LimitedCreative.git</connection>
<developerConnection>scm:git:git@github.com:possi/LimitedCreative.git</developerConnection>
<url>https://github.com/possi/LimitedCreative/tree/master</url>
</scm>
<repositories>
<!-- Required dependencies for optional integrations, that aren't hosted yet -->
<repository>
<id>opt-dep</id>
<url>http://dl.dropbox.com/u/5023975/mvn-repo</url>
</repository>
<!-- Official (Craft-)Bukkit repository -->
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<!-- Official WorldGuard and WorldEdit repository -->
<repository>
<id>sk89q-mvn2</id>
<url>http://mvn2.sk89q.com/repo</url>
</repository>
<!-- Official Multiverse repository -->
<repository>
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
</repository>
</repositories>
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>
<targetPath>lang/</targetPath>
<directory>${basedir}/lang/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.2.5-R1.0</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>uk.org.whoami</groupId>
<artifactId>authme</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.cypherx</groupId>
<artifactId>xauth</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View file

@ -40,15 +40,21 @@ public class Communicator extends AbstractCommunicator {
public boolean isCreative(World world) { public boolean isCreative(World world) {
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE; boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
if (isPluginEnabled("Multiverse-Core")) if (isMultiVerse()) {
creative = MultiVerse.isCreative(world); GameMode tmp = MultiVerse.getGameMode(world);
if (tmp != null)
creative = tmp == GameMode.CREATIVE;
}
Core.debug("com: "+world.getName()+": is creative: "+creative); Core.debug("com: "+world.getName()+": is creative: "+creative);
return creative; return creative;
} }
public GameMode getDefaultGameMode(World world) { public GameMode getDefaultGameMode(World world) {
GameMode def = Bukkit.getServer().getDefaultGameMode(); GameMode def = Bukkit.getServer().getDefaultGameMode();
if (isMultiVerse()) if (isMultiVerse()) {
def = MultiVerse.getGameMode(world); GameMode tmp = MultiVerse.getGameMode(world);
if (tmp != null)
def = tmp;
}
Core.debug("com: "+world.getName()+": game mode: "+def); Core.debug("com: "+world.getName()+": game mode: "+def);
return def; return def;
} }

View file

@ -22,19 +22,16 @@ import org.bukkit.GameMode;
import org.bukkit.World; import org.bukkit.World;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.Core;
public class MultiVerse implements CommunicationBridge { public class MultiVerse implements CommunicationBridge {
public static boolean isCreative(World world) {
boolean ic = getMV().getMVWorldManager().getMVWorld(world).getGameMode() == GameMode.CREATIVE;
Core.debug("Multiverse: "+world.getName()+": is creative: "+ic);
return ic;
}
public static GameMode getGameMode(World world) { public static GameMode getGameMode(World world) {
GameMode gm = getMV().getMVWorldManager().getMVWorld(world).getGameMode(); MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world);
if (mvWorld == null)
return null;
GameMode gm = mvWorld.getGameMode();
Core.debug("Multiverse: "+world.getName()+": game mode: "+gm); Core.debug("Multiverse: "+world.getName()+": game mode: "+gm);
return gm; return gm;
} }

View file

@ -26,7 +26,7 @@ import de.jaschastarke.minecraft.limitedcreative.Core;
public class xAuth implements CommunicationBridge { public class xAuth implements CommunicationBridge {
public static boolean isLoggedInNotGuest(Player player) { public static boolean isLoggedInNotGuest(Player player) {
xAuthPlayer xpl = getAuth().getPlayer(player.getName()); xAuthPlayer xpl = getAuth().getPlyrMngr().getPlayer(player.getName());
boolean li = true; boolean li = true;
if (!xpl.isAuthenticated()) if (!xpl.isAuthenticated())
li = false; li = false;

View file

@ -62,8 +62,8 @@ public class LCPlayer {
//name = player.getName(); //name = player.getName();
//touch(); //touch();
if (!this.isRegionGameMode(player.getGameMode())) { if (!this.isActiveRegionGameMode(player.getGameMode())) {
setPermanentGameMode(player.getGameMode()); setInPermanentGameMode(player.getGameMode());
} }
} }
@ -94,24 +94,24 @@ public class LCPlayer {
}*/ }*/
private Map<String, Object> options = new HashMap<String, Object>(); private Map<String, Object> options = new HashMap<String, Object>();
public void setRegionGameMode(final GameMode gm) { public void storeActiveRegionGameMode(final GameMode gm) {
options.remove("region"); options.remove("region");
Core.debug(getName()+": set region game mode: " + gm); Core.debug(getName()+": set region game mode: " + gm);
Players.getOptions().setRegionGameMode(getName(), gm); Players.getOptions().setRegionGameMode(getName(), gm);
} }
private GameMode getRegionGameMode() { public GameMode getActiveRegionGameMode() {
if (!options.containsKey("region")) { if (!options.containsKey("region")) {
options.put("region", Players.getOptions().getRegionGameMode(getName())); options.put("region", Players.getOptions().getRegionGameMode(getName()));
} }
Core.debug(getName()+": get region game mode: " + options.get("region")); Core.debug(getName()+": get region game mode: " + options.get("region"));
return (GameMode) options.get("region"); return (GameMode) options.get("region");
} }
public boolean isRegionGameMode(final GameMode gm) { public boolean isActiveRegionGameMode(final GameMode gm) {
return gm.equals(getRegionGameMode()); return gm.equals(getActiveRegionGameMode());
} }
public boolean isRegionGameMode() { public boolean isActiveRegionGameMode() {
return getRegionGameMode() != null; return getActiveRegionGameMode() != null;
} }
public boolean isOptionalRegionGameMode() { public boolean isOptionalRegionGameMode() {
@ -149,26 +149,29 @@ public class LCPlayer {
Players.getOptions().setOptionalRegionGameMode(getName(), region, gm); Players.getOptions().setOptionalRegionGameMode(getName(), region, gm);
} }
public void setPermanentGameMode(GameMode temp) { public void setInPermanentGameMode(GameMode temp) {
Core.debug(getName()+": set permanent game mode: " + temp); Core.debug(getName()+": set permanent game mode: " + temp);
if (temp != null) { if (temp != null) {
if (temp.equals(plugin.com.getDefaultGameMode(getPlayer().getWorld()))) { if (temp.equals(plugin.com.getDefaultGameMode(getPlayer().getWorld()))) {
temp = null; temp = null;
} else { } else {
setRegionGameMode(null); storeActiveRegionGameMode(null);
} }
} }
_permanent_gamemode = temp; _permanent_gamemode = temp;
} }
public boolean isPermanentGameMode(GameMode temp) { public boolean isInPermanentGameMode() {
return isInPermanentGameMode(getPlayer().getGameMode());
}
public boolean isInPermanentGameMode(GameMode temp) {
Core.debug(getName()+": get permanent game mode: " + _permanent_gamemode); Core.debug(getName()+": get permanent game mode: " + _permanent_gamemode);
return temp.equals(_permanent_gamemode); return temp.equals(_permanent_gamemode);
} }
public boolean onSetGameMode(GameMode gm) { public boolean onSetGameMode(GameMode gm) {
Core.debug(getName() + " going into " + gm); Core.debug(getName() + " going into " + gm);
if (isRegionGameMode()) { // change to the other gamemode as the area defines if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines
if (!isRegionGameMode(gm)) { // only when we are not switching to the mode the region allows if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
if (!plugin.config.getRegionOptional() && (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.REGIONS_BYPASS))) { if (!plugin.config.getRegionOptional() && (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.REGIONS_BYPASS))) {
getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase())); getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
Core.debug("... denied"); Core.debug("... denied");
@ -179,10 +182,10 @@ public class LCPlayer {
} else { } else {
// we are changing to the mode the region defines, thats not permanent // we are changing to the mode the region defines, thats not permanent
setOptionalRegionGameMode(null); setOptionalRegionGameMode(null);
setPermanentGameMode(null); setInPermanentGameMode(null);
} }
} else { } else {
setPermanentGameMode(gm); // we are not in a region, so the mode change is permanent setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent
} }
/* /*
@ -191,6 +194,7 @@ public class LCPlayer {
if (plugin.config.getStoreEnabled()) { if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY)) if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY))
return true; return true;
getPlayer().closeInventory();
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative())
getInv().save(); getInv().save();
if (gm == GameMode.CREATIVE) { if (gm == GameMode.CREATIVE) {
@ -389,17 +393,16 @@ public class LCPlayer {
/* /*
* Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world". * Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world".
*/ */
public void setRegionCreativeAllowed(boolean rcreative, PlayerAreaEvent area_event) { public void setRegionGameMode(GameMode region_gamemode, PlayerAreaEvent area_event) {
Core.debug(getName()+": changed region: "+rcreative+": " + area_event); Core.debug(getName()+": changed region: "+region_gamemode+": " + area_event);
PlayerMoveEvent event = null; PlayerMoveEvent event = null;
if (area_event instanceof PlayerChangedAreaEvent) if (area_event instanceof PlayerChangedAreaEvent)
event = ((PlayerChangedAreaEvent) area_event).getMoveEvent(); event = ((PlayerChangedAreaEvent) area_event).getMoveEvent();
GameMode CURRENT_GAMEMODE = getPlayer().getGameMode(); GameMode CURRENT_GAMEMODE = getPlayer().getGameMode();
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event != null ? event.getTo().getWorld() : getPlayer().getWorld()); GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event != null ? event.getTo().getWorld() : getPlayer().getWorld());
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL; // the opposite
if (rcreative && CURRENT_GAMEMODE != TEMPORARY_GAMEMODE && !this.isRegionGameMode(TEMPORARY_GAMEMODE)) { if (region_gamemode != null && CURRENT_GAMEMODE != region_gamemode && !this.isActiveRegionGameMode(region_gamemode)) {
Core.debug(getName()+": entering creative area"); Core.debug(getName()+": entering creative area");
// 1. the region allows "the other (temporary) gamemode" // 1. the region allows "the other (temporary) gamemode"
// 2. but the player is not in that mode // 2. but the player is not in that mode
@ -409,33 +412,29 @@ public class LCPlayer {
boolean isOptional = isOptionalRegionGameMode(area_event.getRegionHash(), CURRENT_GAMEMODE); boolean isOptional = isOptionalRegionGameMode(area_event.getRegionHash(), CURRENT_GAMEMODE);
if (isOptional || checkSwitchFlight(area_event)) { if (isOptional || checkSwitchFlight(area_event)) {
setRegionGameMode(TEMPORARY_GAMEMODE); // have to be set, before setGameMode storeActiveRegionGameMode(region_gamemode); // have to be set, before setGameMode
if (!isOptional) { if (!isOptional) {
getPlayer().setGameMode(TEMPORARY_GAMEMODE); getPlayer().setGameMode(region_gamemode);
} }
} }
} else if (!rcreative && getPlayer().getGameMode() == TEMPORARY_GAMEMODE && !isPermanentGameMode(TEMPORARY_GAMEMODE)) { } else if (region_gamemode == null && getPlayer().getGameMode() != DEFAULT_GAMEMODE && !isInPermanentGameMode(CURRENT_GAMEMODE)) {
Core.debug(getName()+": leaving creative area"); Core.debug(getName()+": leaving creative area");
// 1. the region doesn't allow "the other gamemode" // 1. the region doesn't allow "the other gamemode"
// 2. but the player is in that mode // 2. but the player is in that mode
// 3. and the player isn't global (permanent) in that mode // 3. and the player isn't global (permanent) in that mode
// result: change him back to default mode // result: change him back to default mode
if (checkSwitchFlight(area_event)) { if (checkSwitchFlight(area_event)) {
setRegionGameMode(null); storeActiveRegionGameMode(null);
if (event == null || event.getTo().getWorld() == event.getFrom().getWorld() || !plugin.com.isMultiVerse()) {
// do not enforce the game mode change, on world teleport, as multiverse may cancel the event afterwards
// the world-change game-mode change is done by multiworld
getPlayer().setGameMode(DEFAULT_GAMEMODE); getPlayer().setGameMode(DEFAULT_GAMEMODE);
} }
} } else if (region_gamemode == null && this.isActiveRegionGameMode()) {
} else if (!rcreative && this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
Core.debug(getName()+": leaving creative area (while already in default gamemode)"); Core.debug(getName()+": leaving creative area (while already in default gamemode)");
// 1. the region doesn't allow "the other gamemode" // 1. the region doesn't allow "the other gamemode"
// 2. but he thinks he is still allowed // 2. but he thinks he is still allowed
// 3. (because of else) we are not longer in that mode // 3. (because of else) we are not longer in that mode
// result: advise him to not longer allowed to that region // result: advise him to not longer allowed to that region
setRegionGameMode(null); storeActiveRegionGameMode(null);
} }
/** At the moment, in permanent game mode, it ignores all regions /** At the moment, in permanent game mode, it ignores all regions
else if (this.isRegionGameMode()) { else if (this.isRegionGameMode()) {
@ -501,7 +500,7 @@ public class LCPlayer {
} }
public boolean isGameModeAllowed(GameMode gm) { public boolean isGameModeAllowed(GameMode gm) {
if (plugin.config.getRegionOptional() && isRegionGameMode()) { if (plugin.config.getRegionOptional() && isActiveRegionGameMode()) {
return true; return true;
} }
return false; return false;

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,6 +38,7 @@ 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())
@ -45,24 +46,23 @@ public class RegionListener implements Listener {
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.isActiveRegionGameMode() && 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.getActiveRegionGameMode()) {
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);
} }
} }
@ -76,16 +76,16 @@ public class RegionListener implements Listener {
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());
if (player.isRegionGameMode() && diffrent_region) { if (player.isActiveRegionGameMode() && 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.getActiveRegionGameMode()) {
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()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), 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()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), 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()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), 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,12 +139,12 @@ 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);

View file

@ -50,6 +50,20 @@ public class ApplicableRegions {
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() {
for (ProtectedRegion pr : regions) { for (ProtectedRegion pr : regions) {

View file

@ -161,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

@ -42,10 +42,11 @@ public class CListener implements Listener {
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
//if (event.isCoarse()) { // next bukkit release will shortcut that
if (event.getFrom().getBlockX() != event.getTo().getBlockX() if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around || event.getFrom().getBlockZ() != event.getTo().getBlockZ()
|| !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // he really moved, and not just looked around
String current_hash = CPlayer.get(event.getPlayer()).getHash(); String current_hash = CPlayer.get(event.getPlayer()).getHash();
if (current_hash == null) { if (current_hash == null) {

View file

@ -122,7 +122,7 @@ 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());
if (flag != null) { if (flag != null) { // the flag doesn't exists anymore. just ignore it without error
Object value = flag.unmarshal(data.getValue()); Object value = flag.unmarshal(data.getValue());
list.add(new FlagValue(flag, value)); list.add(new FlagValue(flag, value));
} }