Compare commits

..
31 Commits
Author SHA1 Message Date
sk89q 5f2f1c67f5 [maven-release-plugin] prepare release 5.5.4 2012-10-07 10:46:51 -07:00
sk89q c92b9c3d97 Updated CHANGELOG.txt. 2012-10-07 10:40:00 -07:00
sk89q 0951d00da3 Fixed permissions for region loading/saving. 2012-10-06 21:47:37 -07:00
zml2008 6df9c3660b Merge pull request #201 from eric-wieser/patch-1
Did `wcfg.useRegions` really need to be checked twice?
2012-09-16 12:31:17 -07:00
Alexander 19be2bf96e Updated fireball item blocking 2012-08-23 12:41:36 +02:00
Fletch to 99 e10ed6ac7a Report the amount of plugins loaded 2012-08-12 16:56:22 -03:00
sk89q 479ebf4d89 Copying and pasting is bad. Fixed references of worldedit -> worldguard in new pom.xml changes. 2012-08-11 00:28:02 -07:00
sk89q 1f1e36e9f7 Updated pom.xml for license, distributionManagement, maven-site-plugin. 2012-08-11 00:26:06 -07:00
TomyLobo 27e634ae03 Fixed a warning. 2012-08-11 04:37:49 +02:00
unknown e60b20b37b Add 'use' flag to cakes 2012-08-10 22:33:55 +02:00
zml2008 684214ff6a Update for async player chat stupidity 2012-08-04 19:56:48 -07:00
sk89q ba5be6071f Added regions.use-creature-spawn-event configuration setting. 2012-07-23 13:45:04 -07:00
TomyLobo 6c8d13690e Fixed eggs, snowballs and the likes being dupable with /stack. 2012-07-16 16:08:04 +02:00
TomyLobo 3e0b2ef3e4 Upped Bukkit dependency version to 1.2.4-R4.1. 2012-07-14 00:16:45 +02:00
sk89q c5304d2775 [maven-release-plugin] prepare for next development iteration 2012-07-07 10:55:58 -07:00
sk89q ca95ae04a5 [maven-release-plugin] prepare release 5.5.3 2012-07-07 10:55:45 -07:00
sk89q 1ab9f85ca6 Updated CHANGELOG. 2012-07-07 10:39:37 -07:00
sk89q 01ff1b2f8f Added host key check. 2012-07-07 10:33:18 -07:00
Zak Ford 9b17fe68e7 Added configuration option to allow plugin creature spawns 2012-07-01 16:02:24 -04:00
zml2008 0fed35a80f Add bypass handling to the gamemode flag
Set a player's previous gamemode when exiting a gamemode region to the server's default gamemode if there is not a previous gamemode already set
2012-06-15 14:14:13 -07:00
TomyLobo 25280c9fa9 Set Bukkit dependency to R2.1.
That's the current CraftBukkit++ version.
2012-06-11 03:31:50 +02:00
TomyLobo a98ebfdb21 Updated dependencies and added support for fireball item blocking (id 385). 2012-06-07 13:26:28 +02:00
Eric Wieser acb1d18654 Did wcfg.useRegions really need to be checked twice? 2012-04-28 18:18:51 +02:00
TomyLobo 18b5a4e106 Added @Ignore to TestPlayer.
Stupid old mavens...
2012-04-23 11:07:05 +02:00
md_5 bab420a359 Add item drop pickup flag for regions.
Closes #200
2012-04-20 20:25:25 -07:00
zml2008 4f14f1f736 Correctly convert \n to a newline for String flags 2012-04-16 17:00:41 -07:00
zml2008 166831447c Split the region greeting with \n
Improve input handling of EnumFlag
Don't block gamemode changing after the gamemode flag is no longer in
effect but while the move event is still firing
2012-04-15 21:19:02 -07:00
zml2008 f2bd5961d0 Add GameMode flag 2012-04-15 21:19:02 -07:00
zml2008 2cc990a530 Prevent commands in the allow commands list from being blocked and vice versa 2012-04-15 21:19:02 -07:00
TomyLobo f0e6008563 Updated bukkit dependency to 1.2.5-R1.2-SNAPSHOT. 2012-04-15 19:36:15 +02:00
zml2008 93f19cca0a [maven-release-plugin] prepare for next development iteration 2012-04-10 18:30:42 -07:00
18 changed files with 279 additions and 118 deletions

No files matched your search

+20
View File
@@ -1,3 +1,23 @@
5.5.4:
- Minecraft 1.3 support.
- Fixed /stack dupe bugs.
- Added regions.use-creature-spawn-event.
- Update for Async chat issue.
- Add use flag to cakes.
- Report number of plugins loaded in report writer.
- Updated fireblal item blocking.
- Fixed permissions for /region reload.
5.5.3:
- Added game mode flag.
- Added item drop pickup flag to regions.
- Added support for fireball item blocking (385).
- Added configuration option to allow creature spawns from plugins.
- Added host key check.
- Added a new line split feature to region greetings.
- Prevented commands in the allow commands list from being blocked and
vice versa.
5.5.2:
- Added potion-splash flag to block splash potions
- Add entity-painting-destroy which can be used to prevent entities from destroying paintings (skeletons firing arrows)
+57 -29
View File
@@ -1,53 +1,53 @@
<!--
Maven build file for WorldGuard
Copyright (c) 2011 sk89q <http://www.sk89q.com>
WorldGuard is available under the GNU General Public License v3
-->
<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>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.5.2</version>
<version>5.5.4</version>
<name>WorldGuard</name>
<description>WorldGuard protects your Minecraft servers</description>
<description>WorldGuard protects your Minecraft servers.</description>
<licenses>
<license>
<name>GNU General Public License 2.0</name>
<url>LICENSE.txt</url>
<distribution>repo</distribution>
<comments>License on all contributions</comments>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/sk89q/worldguard.git</connection>
<url>https://github.com/sk89q/worldguard</url>
<tag>master</tag>
<developerConnection>scm:git:git@github.com:sk89q/worldguard.git</developerConnection>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<!-- Repository for zml's stuff -->
<repository>
<id>zml-repo</id>
<url>http://files.zachsthings.com/repo</url>
</repository>
<!-- Repository for other dependencies of SK's -->
<repository>
<id>sk89q-mvn2</id>
<url>http://mvn2.sk89q.com/repo</url>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<!-- Repository for Bukkit -->
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<!-- Required component -->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.3</version>
<version>5.4</version>
</dependency>
<!-- Bukkit -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.2.5-R1.0</version>
<version>1.3.2-R1.0</version>
</dependency>
<!-- CommandBook -->
@@ -80,9 +80,22 @@
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<site>
<id>sk89q-docs-upload</id>
<url>ftp://sk89q-maven-deploy/worldguard/</url>
</site>
</distributionManagement>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
<!-- Resources -->
<resources>
@@ -190,20 +203,35 @@
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- Javadocs -->
<!-- TODO: Get Doclava working -->
<!-- Site generation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.5</version>
<reportSets>
<reportSet>
<reports>
<report>license</report>
<report>index</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</reporting>
</build>
</project>
@@ -24,6 +24,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.GodComponent;
@@ -73,7 +75,7 @@ public class ConfigurationManager {
/**
* Holds configurations for different worlds.
*/
private Map<String, WorldConfiguration> worlds;
private ConcurrentMap<String, WorldConfiguration> worlds;
/**
* The global configuration for use when loading worlds
@@ -94,9 +96,11 @@ public class ConfigurationManager {
private boolean hasCommandBookGodMode = false;
public boolean useRegionsScheduler;
public boolean useRegionsCreatureSpawnEvent;
public boolean activityHaltToggle = false;
public boolean autoGodMode;
public boolean usePlayerMove;
public Map<String, String> hostKeys = new HashMap<String, String>();
/**
* Region Storage Configuration method, and config values
@@ -113,12 +117,13 @@ public class ConfigurationManager {
*/
public ConfigurationManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
this.worlds = new HashMap<String, WorldConfiguration>();
this.worlds = new ConcurrentHashMap<String, WorldConfiguration>();
}
/**
* Load the configuration.
*/
@SuppressWarnings("unchecked")
public void load() {
// Create the default configuration file
plugin.createDefaultConfiguration(
@@ -135,12 +140,26 @@ public class ConfigurationManager {
config.removeProperty("suppress-tick-sync-warnings");
useRegionsScheduler = config.getBoolean(
"regions.use-scheduler", true);
useRegionsCreatureSpawnEvent = config.getBoolean(
"regions.use-creature-spawn-event", true);
autoGodMode = config.getBoolean(
"auto-invincible", config.getBoolean("auto-invincible-permission", false));
config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean(
"use-player-move-event", true);
hostKeys = new HashMap<String, String>();
Object hostKeysRaw = config.getProperty("host-keys");
if (hostKeysRaw == null || !(hostKeysRaw instanceof Map)) {
config.setProperty("host-keys", new HashMap<String, String>());
} else {
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
hostKeys.put(key.toLowerCase(), value);
}
}
useSqlDatabase = config.getBoolean(
"regions.sql.use", false);
@@ -176,10 +195,14 @@ public class ConfigurationManager {
public WorldConfiguration get(World world) {
String worldName = world.getName();
WorldConfiguration config = worlds.get(worldName);
WorldConfiguration newConfig = null;
if (config == null) {
config = new WorldConfiguration(plugin, worldName, this.config);
worlds.put(worldName, config);
while (config == null) {
if (newConfig == null) {
newConfig = new WorldConfiguration(plugin, worldName, this.config);
}
worlds.putIfAbsent(world.getName(), newConfig);
config = worlds.get(world.getName());
}
return config;
@@ -36,24 +36,24 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* This processes per-player state information and is also meant to be used
* as a scheduled task.
*
*
* @author sk89q
*/
public class FlagStateManager implements Runnable {
public static final int RUN_DELAY = 20;
private WorldGuardPlugin plugin;
private Map<String, PlayerFlagState> states;
/**
* Construct the object.
*
*
* @param plugin The plugin instance
*/
public FlagStateManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
states = new HashMap<String, PlayerFlagState>();
}
@@ -66,16 +66,16 @@ public class FlagStateManager implements Runnable {
for (Player player : players) {
WorldConfiguration worldConfig = config.get(player.getWorld());
if (!worldConfig.useRegions) {
continue;
}
PlayerFlagState state;
synchronized (this) {
state = states.get(player.getName());
if (state == null) {
state = new PlayerFlagState();
states.put(player.getName(), state);
@@ -87,7 +87,7 @@ public class FlagStateManager implements Runnable {
.get(player.getWorld());
ApplicableRegionSet applicable = regionManager
.getApplicableRegions(playerLocation);
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
&& !plugin.getGlobalStateManager().hasGodMode(player)
&& !(player.getGameMode() == GameMode.CREATIVE)) {
@@ -96,7 +96,7 @@ public class FlagStateManager implements Runnable {
}
}
}
/**
* Process healing for a player.
*
@@ -106,18 +106,18 @@ public class FlagStateManager implements Runnable {
*/
private void processHeal(ApplicableRegionSet applicable, Player player,
PlayerFlagState state) {
if (player.getHealth() <= 0) {
return;
}
long now = System.currentTimeMillis();
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
Integer minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
Integer maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
return;
}
@@ -127,7 +127,7 @@ public class FlagStateManager implements Runnable {
if (player.getHealth() >= maxHealth && healAmount > 0) {
return;
}
if (healDelay <= 0) {
player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
state.lastHeal = now;
@@ -137,10 +137,10 @@ public class FlagStateManager implements Runnable {
state.lastHeal = now;
}
}
/**
* Process restoring hunger for a player.
*
*
* @param applicable The set of applicable regions
* @param player The player to process hunger flags on
* @param state The player's state
@@ -154,7 +154,7 @@ public class FlagStateManager implements Runnable {
Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY);
Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD);
Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD);
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
return;
}
@@ -177,7 +177,7 @@ public class FlagStateManager implements Runnable {
/**
* Forget a player.
*
*
* @param player The player to forget
*/
public synchronized void forget(Player player) {
@@ -194,21 +194,21 @@ public class FlagStateManager implements Runnable {
/**
* Get a player's flag state. A new state will be created if there is no existing
* state for the player.
*
*
* @param player The player to get a state for
* @return The {@code player}'s state
*/
public synchronized PlayerFlagState getState(Player player) {
PlayerFlagState state = states.get(player.getName());
if (state == null) {
state = new PlayerFlagState();
states.put(player.getName(), state);
}
return state;
}
/**
* Keeps state per player.
*/
@@ -220,6 +220,7 @@ public class FlagStateManager implements Runnable {
public Boolean lastExitAllowed = null;
public Boolean notifiedForLeave = false;
public Boolean notifiedForEnter = false;
public GameMode lastGameMode;
public World lastWorld;
public int lastBlockX;
public int lastBlockY;
@@ -166,7 +166,7 @@ public class ReportWriter {
}
private void appendPluginInformation(Plugin[] plugins) {
appendHeader("Plugins");
appendHeader("Plugins (" + plugins.length + ")");
LogListBlock log = new LogListBlock();
@@ -98,6 +98,7 @@ public class WorldConfiguration {
public boolean blockFireballExplosions;
public boolean blockFireballBlockDamage;
public boolean blockEntityPaintingDestroy;
public boolean blockPluginSpawning;
public boolean disableContactDamage;
public boolean disableFallDamage;
public boolean disableLavaDamage;
@@ -315,6 +316,7 @@ public class WorldConfiguration {
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false);
blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
disableFallDamage = getBoolean("player-damage.disable-fall-damage", false);
disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false);
@@ -297,7 +297,7 @@ public class WorldGuardBlockListener implements Listener {
return;
}
if (wcfg.blockLighter && cause == IgniteCause.FLINT_AND_STEEL
if (wcfg.blockLighter && (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL)
&& event.getPlayer() != null
&& !plugin.hasPermission(event.getPlayer(), "worldguard.override.lighter")) {
event.setCancelled(true);
@@ -333,7 +333,7 @@ public class WorldGuardBlockListener implements Listener {
if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (cause == IgniteCause.FLINT_AND_STEEL) {
if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) {
if (!set.canBuild(localPlayer)) {
event.setCancelled(true);
return;
@@ -518,14 +518,12 @@ public class WorldGuardEntityListener implements Listener {
}
if (wcfg.useRegions) {
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
event.blockList().clear();
return;
}
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
event.blockList().clear();
return;
}
}
}
@@ -610,6 +608,11 @@ public class WorldGuardEntityListener implements Listener {
}
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
// allow spawning of creatures from plugins
if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM)
return;
EntityType entityType = event.getEntityType();
if (wcfg.blockCreatureSpawn.contains(entityType)) {
@@ -619,7 +622,7 @@ public class WorldGuardEntityListener implements Listener {
Location eventLoc = event.getLocation();
if (wcfg.useRegions) {
if (wcfg.useRegions && cfg.useRegionsCreatureSpawnEvent) {
Vector pt = toVector(eventLoc);
RegionManager mgr = plugin.getGlobalRegionManager().get(eventLoc.getWorld());
// @TODO get victims' stacktraces and find out why it's null anyway
@@ -25,6 +25,7 @@ import java.util.Set;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemID;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
@@ -36,15 +37,17 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@@ -159,19 +162,24 @@ public class WorldGuardPlayerListener implements Listener {
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);//, localPlayer);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);//, localPlayer);
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE);//, localPlayer);
GameMode gameMode = set.getFlag(DefaultFlag.GAME_MODE);
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
for (String line : replacedFarewell.split("\n")) {
player.sendMessage(ChatColor.AQUA + " ** " + line);
}
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
for (String line : replacedGreeting.split("\n")) {
player.sendMessage(ChatColor.AQUA + " ** " + line);
}
}
if ((notifyLeave == null || !notifyLeave)
@@ -199,6 +207,21 @@ public class WorldGuardPlayerListener implements Listener {
+ regionList);
}
if (!hasBypass && gameMode != null) {
if (player.getGameMode() != gameMode) {
state.lastGameMode = player.getGameMode();
player.setGameMode(gameMode);
} else if (state.lastGameMode == null) {
state.lastGameMode = player.getServer().getDefaultGameMode();
}
} else {
if (state.lastGameMode != null) {
GameMode mode = state.lastGameMode;
state.lastGameMode = null;
player.setGameMode(mode);
}
}
state.lastGreeting = greeting;
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
@@ -213,6 +236,22 @@ public class WorldGuardPlayerListener implements Listener {
}
}
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
GameMode gameMode = plugin.getGlobalRegionManager().get(player.getWorld())
.getApplicableRegions(player.getLocation()).getFlag(DefaultFlag.GAME_MODE);
if (plugin.getFlagStateManager().getState(player).lastGameMode != null
&& gameMode != null && event.getNewGameMode() != gameMode) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "Your game mode is locked to "
+ gameMode + "in this region!");
}
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
@@ -265,7 +304,7 @@ public class WorldGuardPlayerListener implements Listener {
}
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
if (wcfg.useRegions) {
@@ -286,6 +325,30 @@ public class WorldGuardPlayerListener implements Listener {
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalStateManager();
String hostKey = cfg.hostKeys.get(player.getName().toLowerCase());
if (hostKey != null) {
String hostname = event.getHostname();
int colonIndex = hostname.indexOf(':');
if (colonIndex != -1) {
hostname = hostname.substring(0, colonIndex);
}
if (!hostname.equals(hostKey)) {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
"You did not join with the valid host key!");
plugin.getLogger().warning("WorldGuard host key check: " +
player.getName() + " joined with '" + hostname +
"' but '" + hostKey + "' was expected. Kicked!");
return;
}
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
@@ -604,7 +667,8 @@ public class WorldGuardPlayerListener implements Listener {
if (type == BlockID.CAKE_BLOCK) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
&& !set.canBuild(localPlayer)
&& !set.allows(DefaultFlag.USE, localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
@@ -848,6 +912,14 @@ public class WorldGuardPlayerListener implements Listener {
public void onPlayerDropItem(PlayerDropItemEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
Player player = event.getPlayer();
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ITEM_DROP, player.getLocation())) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You don't have permission to do that in this area.");
}
}
if (wcfg.getBlacklist() != null) {
Item ci = event.getItemDrop();
@@ -1003,27 +1075,23 @@ public class WorldGuardPlayerListener implements Listener {
Vector pt = toVector(player.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ProtectedRegion globalRegion = mgr.getRegion("__global__");
String[] parts = event.getMessage().split(" ");
String lowerCommand = parts[0].toLowerCase();
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS, localPlayer);
if (allowedCommands == null && globalRegion != null) {
allowedCommands = globalRegion.getFlag(DefaultFlag.ALLOWED_CMDS);
}
if (allowedCommands != null && !allowedCommands.contains(parts[0].toLowerCase())) {
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is not allowed in this area.");
if (allowedCommands != null && !allowedCommands.contains(lowerCommand)
&& (blockedCommands == null || blockedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is not allowed in this area.");
event.setCancelled(true);
return;
}
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
if (blockedCommands == null && globalRegion != null) {
blockedCommands = globalRegion.getFlag(DefaultFlag.BLOCKED_CMDS);
}
if (blockedCommands != null && blockedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is blocked in this area.");
if (blockedCommands != null && blockedCommands.contains(lowerCommand)
&& (allowedCommands == null || !allowedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is blocked in this area.");
event.setCancelled(true);
return;
}
@@ -278,14 +278,14 @@ public class GeneralCommands {
item.getEnchantments().equals(item2.getEnchantments())) {
// This stack won't fit in the parent stack
if (item2.getAmount() > needed) {
item.setAmount(64);
item.setAmount(max);
item2.setAmount(item2.getAmount() - needed);
break;
// This stack will
} else {
items[j] = null;
item.setAmount(item.getAmount() + item2.getAmount());
needed = 64 - item.getAmount();
needed = max - item.getAmount();
}
affected++;
@@ -955,6 +955,7 @@ public class RegionCommands {
@Command(aliases = {"load", "reload"}, usage = "[world]",
desc = "Reload regions from file", max = 1)
@CommandPermissions({"worldguard.region.load"})
public void load(CommandContext args, CommandSender sender) throws CommandException {
World world = null;
@@ -993,6 +994,7 @@ public class RegionCommands {
@Command(aliases = {"save", "write"}, usage = "[world]",
desc = "Re-save regions to file", max = 1)
@CommandPermissions({"worldguard.region.save"})
public void save(CommandContext args, CommandSender sender) throws CommandException {
World world = null;
@@ -23,6 +23,7 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import org.bukkit.Location;
@@ -65,7 +66,7 @@ public class GlobalRegionManager {
/**
* Map of managers per-world.
*/
private HashMap<String, RegionManager> managers;
private ConcurrentHashMap<String, RegionManager> managers;
/**
* Stores the list of modification dates for the world files. This allows
@@ -81,7 +82,7 @@ public class GlobalRegionManager {
public GlobalRegionManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
config = plugin.getGlobalStateManager();
managers = new HashMap<String, RegionManager>();
managers = new ConcurrentHashMap<String, RegionManager>();
lastModified = new HashMap<String, Long>();
}
@@ -125,19 +126,26 @@ public class GlobalRegionManager {
lastModified.clear();
}
public RegionManager load(World world) {
RegionManager manager = create(world);
managers.put(world.getName(), manager);
return manager;
}
/**
* Load region information for a world.
*
* @param world The world to load a RegionManager for
* @return the loaded RegionManager
*/
public RegionManager load(World world) {
public RegionManager create(World world) {
String name = world.getName();
boolean sql = config.useSqlDatabase;
ProtectionDatabase database;
File file = null;
try {
if (!config.useSqlDatabase) {
if (!sql) {
file = getPath(name);
database = new YAMLDatabase(file, plugin.getLogger());
@@ -149,8 +157,6 @@ public class GlobalRegionManager {
// Create a manager
RegionManager manager = new FlatRegionManager(database);
managers.put(name, manager);
manager.load();
plugin.getLogger().info(manager.getRegions().size()
@@ -159,7 +165,7 @@ public class GlobalRegionManager {
return manager;
} catch (ProtectionDatabaseException e) {
String logStr = "Failed to load regions from ";
if (config.useSqlDatabase) {
if (sql) {
logStr += "SQL Database <" + config.sqlDsn + "> ";
} else {
logStr += "file \"" + file + "\" ";
@@ -224,9 +230,14 @@ public class GlobalRegionManager {
*/
public RegionManager get(World world) {
RegionManager manager = managers.get(world.getName());
RegionManager newManager = null;
if (manager == null) {
manager = load(world);
while (manager == null) {
if (newManager == null) {
newManager = create(world);
}
managers.putIfAbsent(world.getName(), newManager);
manager = managers.get(world.getName());
}
return manager;
@@ -353,7 +364,7 @@ public class GlobalRegionManager {
return true;
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
RegionManager mgr = get(world);
return mgr.getApplicableRegions(toVector(loc)).allows(flag, player);
}
}
@@ -70,7 +70,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
try {
connect();
try {
// Test if the database is up to date, if not throw a critical error
PreparedStatement verTest = this.conn.prepareStatement(
@@ -132,7 +132,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
} catch (SQLException ex) {
// Test if the dummy query failed because the connection is dead,
// and if it is mark the connection as closed (the MySQL Driver
// does not ensure that the connection is marked as closed unless
// does not ensure that the connection is marked as closed unless
// the close() method has been called.
if ("08S01".equals(ex.getSQLState())) {
conn.close();
@@ -148,7 +148,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
// @TODO: Iterate _ONCE_
try {
PreparedStatement flagsStatement = this.conn.prepareStatement(
"SELECT " +
"SELECT " +
"`region_flag`.`flag`, " +
"`region_flag`.`value` " +
"FROM `region_flag` " +
@@ -463,7 +463,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
parentSets = new HashMap<ProtectedRegion,String>();
// We load the cuboid regions first, as this is likely to be the
// largest dataset. This should save time in regards to the putAll()s
// largest dataset. This should save time in regards to the putAll()s
this.loadCuboid();
Map<String,ProtectedRegion> regions = this.cuboidRegions;
this.cuboidRegions = null;
@@ -625,10 +625,10 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
* b) If the region is not in the database, we insert it
* 3) We iterate over what remains of the in-database list and remove
* them from the database
*
*
* TODO: Look at adding/removing/updating the database when the in
* memory region is created/remove/updated
*
*
* @see com.sk89q.worldguard.protection.databases.ProtectionDatabase#save()
*/
public void save() throws ProtectionDatabaseException {
@@ -19,6 +19,7 @@
package com.sk89q.worldguard.protection.flags;
import org.bukkit.GameMode;
import org.bukkit.entity.EntityType;
/**
@@ -63,6 +64,7 @@ public final class DefaultFlag {
public static final StateFlag RECEIVE_CHAT = new StateFlag("receive-chat", true);
public static final StateFlag ENTRY = new StateFlag("entry", true);
public static final StateFlag EXIT = new StateFlag("exit", true);
public static final StateFlag ITEM_DROP = new StateFlag("item-drop", true);
public static final StateFlag ENTITY_PAINTING_DESTROY = new StateFlag("entity-painting-destroy", true);
public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true);
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting", RegionGroup.ALL);
@@ -70,6 +72,7 @@ public final class DefaultFlag {
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL);
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL);
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null));
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class, RegionGroup.ALL);
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay", RegionGroup.ALL);
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount", RegionGroup.ALL);
public static final IntegerFlag MIN_HEAL = new IntegerFlag("heal-min-health", RegionGroup.ALL);
@@ -91,10 +94,10 @@ public final class DefaultFlag {
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ITEM_DROP,
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE,
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, SEND_CHAT, RECEIVE_CHAT,
FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
TELE_LOC, SPAWN_LOC, POTION_SPLASH,
@@ -41,6 +41,10 @@ public class EnumFlag<T extends Enum<T>> extends Flag<T> {
}
private T findValue(String input) throws IllegalArgumentException {
if (input != null) {
input = input.toUpperCase();
}
try {
return Enum.valueOf(enumClass, input);
} catch (IllegalArgumentException e) {
@@ -88,5 +92,5 @@ public class EnumFlag<T extends Enum<T>> extends Flag<T> {
public Object marshal(T o) {
return o.name();
}
}
@@ -38,7 +38,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
* @author sk89q
*/
public class LocationFlag extends Flag<Location> {
public LocationFlag(String name, RegionGroup defaultGroup) {
super(name, defaultGroup);
}
@@ -139,16 +139,11 @@ public class LocationFlag extends Flag<Location> {
}
private double toNumber(Object o) {
if (o instanceof Integer) {
return (Integer) o;
} else if (o instanceof Long) {
return (Long) o;
} else if (o instanceof Float) {
return (Float) o;
} else if (o instanceof Double) {
return (Double) o;
if (o instanceof Number) {
return ((Number) o).doubleValue();
} else {
return 0;
}
}
}
@@ -39,7 +39,7 @@ public class StringFlag extends Flag<String> {
@Override
public String parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat {
return input;
return input.replaceAll("(?!\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\n");
}
@Override
@@ -24,6 +24,7 @@ import java.util.HashSet;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
@org.junit.Ignore
public class TestPlayer extends LocalPlayer {
private String name;
private Set<String> groups = new HashSet<String>();