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

9
.gitignore vendored
View file

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

View file

@ -1,11 +1,25 @@
# 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)
* which implies [Bukkit](https://github.com/Bukkit/Bukkit)
* Optional: [WorldGuard](https://github.com/sk89q/worldguard)
* which depends on [WorldEdit](https://github.com/sk89q/worldedit)
Dependencies for optional integrations
--------------------------------------
* [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.
# You also may add the special block "*" (better add quotes to don't break yml) which prevents the usage of ANY
# item/block.
# default: []
use: []
# default: [exp_bottle, bedrock]
use:
- EXP_BOTTLE
- bedrock
# BreakBlackList
# 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
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.1
version: 1.2.3-beta
softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
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) {
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
if (isPluginEnabled("Multiverse-Core"))
creative = MultiVerse.isCreative(world);
if (isMultiVerse()) {
GameMode tmp = MultiVerse.getGameMode(world);
if (tmp != null)
creative = tmp == GameMode.CREATIVE;
}
Core.debug("com: "+world.getName()+": is creative: "+creative);
return creative;
}
public GameMode getDefaultGameMode(World world) {
GameMode def = Bukkit.getServer().getDefaultGameMode();
if (isMultiVerse())
def = MultiVerse.getGameMode(world);
if (isMultiVerse()) {
GameMode tmp = MultiVerse.getGameMode(world);
if (tmp != null)
def = tmp;
}
Core.debug("com: "+world.getName()+": game mode: "+def);
return def;
}

View file

@ -22,19 +22,16 @@ import org.bukkit.GameMode;
import org.bukkit.World;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import de.jaschastarke.minecraft.limitedcreative.Core;
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) {
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);
return gm;
}

View file

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

View file

@ -62,8 +62,8 @@ public class LCPlayer {
//name = player.getName();
//touch();
if (!this.isRegionGameMode(player.getGameMode())) {
setPermanentGameMode(player.getGameMode());
if (!this.isActiveRegionGameMode(player.getGameMode())) {
setInPermanentGameMode(player.getGameMode());
}
}
@ -94,24 +94,24 @@ public class LCPlayer {
}*/
private Map<String, Object> options = new HashMap<String, Object>();
public void setRegionGameMode(final GameMode gm) {
public void storeActiveRegionGameMode(final GameMode gm) {
options.remove("region");
Core.debug(getName()+": set region game mode: " + gm);
Players.getOptions().setRegionGameMode(getName(), gm);
}
private GameMode getRegionGameMode() {
public GameMode getActiveRegionGameMode() {
if (!options.containsKey("region")) {
options.put("region", Players.getOptions().getRegionGameMode(getName()));
}
Core.debug(getName()+": get region game mode: " + options.get("region"));
return (GameMode) options.get("region");
}
public boolean isRegionGameMode(final GameMode gm) {
return gm.equals(getRegionGameMode());
public boolean isActiveRegionGameMode(final GameMode gm) {
return gm.equals(getActiveRegionGameMode());
}
public boolean isRegionGameMode() {
return getRegionGameMode() != null;
public boolean isActiveRegionGameMode() {
return getActiveRegionGameMode() != null;
}
public boolean isOptionalRegionGameMode() {
@ -149,26 +149,29 @@ public class LCPlayer {
Players.getOptions().setOptionalRegionGameMode(getName(), region, gm);
}
public void setPermanentGameMode(GameMode temp) {
public void setInPermanentGameMode(GameMode temp) {
Core.debug(getName()+": set permanent game mode: " + temp);
if (temp != null) {
if (temp.equals(plugin.com.getDefaultGameMode(getPlayer().getWorld()))) {
temp = null;
} else {
setRegionGameMode(null);
storeActiveRegionGameMode(null);
}
}
_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);
return temp.equals(_permanent_gamemode);
}
public boolean onSetGameMode(GameMode gm) {
Core.debug(getName() + " going into " + gm);
if (isRegionGameMode()) { // 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()) { // change to the other gamemode as the area defines
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))) {
getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
Core.debug("... denied");
@ -179,10 +182,10 @@ public class LCPlayer {
} else {
// we are changing to the mode the region defines, thats not permanent
setOptionalRegionGameMode(null);
setPermanentGameMode(null);
setInPermanentGameMode(null);
}
} 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.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY))
return true;
getPlayer().closeInventory();
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative())
getInv().save();
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".
*/
public void setRegionCreativeAllowed(boolean rcreative, PlayerAreaEvent area_event) {
Core.debug(getName()+": changed region: "+rcreative+": " + area_event);
public void setRegionGameMode(GameMode region_gamemode, PlayerAreaEvent area_event) {
Core.debug(getName()+": changed region: "+region_gamemode+": " + area_event);
PlayerMoveEvent event = null;
if (area_event instanceof PlayerChangedAreaEvent)
event = ((PlayerChangedAreaEvent) area_event).getMoveEvent();
GameMode CURRENT_GAMEMODE = getPlayer().getGameMode();
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");
// 1. the region allows "the other (temporary) gamemode"
// 2. but the player is not in that mode
@ -409,33 +412,29 @@ public class LCPlayer {
boolean isOptional = isOptionalRegionGameMode(area_event.getRegionHash(), CURRENT_GAMEMODE);
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) {
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");
// 1. the region doesn't allow "the other gamemode"
// 2. but the player is in that mode
// 3. and the player isn't global (permanent) in that mode
// result: change him back to default mode
if (checkSwitchFlight(area_event)) {
setRegionGameMode(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);
}
storeActiveRegionGameMode(null);
getPlayer().setGameMode(DEFAULT_GAMEMODE);
}
} else if (!rcreative && this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
} else if (region_gamemode == null && this.isActiveRegionGameMode()) {
Core.debug(getName()+": leaving creative area (while already in default gamemode)");
// 1. the region doesn't allow "the other gamemode"
// 2. but he thinks he is still allowed
// 3. (because of else) we are not longer in that mode
// 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
else if (this.isRegionGameMode()) {
@ -501,7 +500,7 @@ public class LCPlayer {
}
public boolean isGameModeAllowed(GameMode gm) {
if (plugin.config.getRegionOptional() && isRegionGameMode()) {
if (plugin.config.getRegionOptional() && isActiveRegionGameMode()) {
return true;
}
return false;

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,31 +38,31 @@ public class RegionListener implements Listener {
private ApplicableRegions regionSet(Block block) {
return rm.getRegionSet(block);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
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) {
if (player.isActiveRegionGameMode() && 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.getActiveRegionGameMode()) {
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);
}
}
@ -76,16 +76,16 @@ public class RegionListener implements Listener {
LCPlayer player = Players.get(event.getPlayer());
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
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.getActiveRegionGameMode()) {
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()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), event);
}
@EventHandler
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
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
@ -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,19 +139,19 @@ 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);
}
}
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
if (event.isCancelled())

View file

@ -49,6 +49,20 @@ public class ApplicableRegions {
contractRegionFlags();
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() {

View file

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

@ -42,10 +42,11 @@ public class CListener implements Listener {
public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled())
return;
//if (event.isCoarse()) { // next bukkit release will shortcut that
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| 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();
if (current_hash == null) {

View file

@ -122,7 +122,7 @@ 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) {
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));
}