Compare commits

...
82 Commits
Author SHA1 Message Date
wizjany b707289284 [maven-release-plugin] prepare release 5.9 2014-02-28 20:03:35 -05:00
wizjany 43486bda63 Fix versioning error for release 2014-02-28 20:01:37 -05:00
sk89q 7086a1d0d2 Prepared release of v5.9. 2014-02-28 16:45:09 -08:00
TomyLobo 4dd13bd925 Merge pull request #310 from jmhertlein/master
Fixed ProtectedCuboidRegion::getPoints() returning points in wrong order

Fixes com.sk89q.worldguard.protection.regions.RegionIntersectTest.testIntersection.
2014-02-28 08:19:30 +01:00
TomyLobo 4ce97bca0e Added a unit test for ProtectedRegion.intersectsEdges. 2014-02-28 00:48:40 +01:00
Joshua M Hertlein ec9712f30e Fixed ProtectedCuboidRegion::getPoints() returning points in wrong order
ProtectedPolygonRegion returns points in an order such that you could play "connect the dots" and end up with the correct polygon. ProtectedCuboidRegion returns them in an order such that playing connect the dots gives you a Z shape. This breaks the intersectsEdges() function in ProtectedRegion when comparing cuboids. This commit causes ProtectedCuboidRegion::getPoints() to return them in an order consistent with ProtectedPolygonRegion, which makes intersectsEdges() work correctly.
2014-02-25 13:51:57 -06:00
Albert Pham 0162910964 Added <distributionManagement> to pom.xml 2014-02-23 22:26:36 -08:00
TomyLobo c252a79c1a Copied some .gitignore entries from WorldEdit. 2014-02-10 08:52:29 +01:00
wizjany 2df3290d38 Fixed snowman trails being treated as snow fall. 2014-01-11 16:08:26 -05:00
wizjany 4805df2f03 Fix being able to use bonemeal to turn tall grass into double plants. 2014-01-08 14:56:59 -05:00
wizjany 5bc670db8b Fixed CI link in readme. 2014-01-08 14:56:58 -05:00
Wizjany ffda88f193 Fix number of args for migratedb command. 2013-12-14 17:21:07 -05:00
Dark Arc 96a69aa2ef Resolved an issue where explosions of type OTHER_EXPLOSION were ignoring the world config settings 2013-12-11 00:53:49 -05:00
wizjany 2d90fddbee Check for entities and projectiles removing items from frames too. 2013-12-09 17:46:33 -05:00
wizjany bbd1a0ef10 Protect items in item frames in protected regions. 2013-12-09 08:40:28 -05:00
TomyLobo 6b16ed79b3 Merge pull request #298 from md-5/herd_u_like_ifs
Using checked exceptions for control flow is slow. Lets replace it with an isEmpty check.
2013-12-09 00:28:16 -08:00
md_5 73b9a7fb0d Using checked exceptions for control flow is slow. Lets replace it with an isEmpty check. 2013-12-09 19:22:48 +11:00
wizjany 4a0ae833f0 Revert WE dependency to 5.5.8.
WorldGuard didn't use any new API since then,
so depending on an unstable snapshot wasn't necessary.
2013-11-18 15:30:17 -05:00
wizjany 5f32ebe2de Fix compile-time error due to 23766f20 2013-11-17 21:16:51 -05:00
Albert Pham 723928d239 Merge pull request #289 from sk89q/develop
Tiny changes extracted from various branches.
2013-11-17 15:03:19 -08:00
TomyLobo d024ed7b81 typos, unused imports 2013-11-17 23:59:02 +01:00
TomyLobo ec4143d3dc Bumped WE dependency to 5.5.9-SNAPSHOT. 2013-11-17 23:48:19 +01:00
TomyLobo 071fdaabd3 Added *.iml and .idea to .gitignore. 2013-11-17 23:48:18 +01:00
TomyLobo 23766f20dd Transformed the BlockFadeEvent handler into a switch. 2013-11-16 17:35:35 +01:00
TomyLobo 31739c647b Dissolved a .* import.
Rationale: grepping for qualified class names
2013-11-16 17:35:35 +01:00
Dark Arc faa016180a Added a config option to allow explosion flags to only prevent block
damage
2013-09-22 15:39:10 -04:00
wizjany e26238e814 Added formatting codes, &k/l/m/n/o and &x (reset). 2013-08-31 10:07:46 -04:00
wizjany f8ed1a3e3e Make /rg list default to own regions if the player doesn't have permission otherwise. 2013-08-27 23:36:01 -04:00
Wizjany d47c255168 Check bypass perms for item-drop flag. 2013-08-20 17:03:00 -04:00
wizjany d1e7796f81 Added allow-tamed-spawns setting, on by default.
This will stop WorldGuard from culling tamed animals
in regions with mob-spawning deny when they log in
with their owner.
2013-08-20 14:58:46 -04:00
Wizjany 1095064c5e Update CommandBook dependency to 2.3. 2013-08-18 23:32:51 -04:00
wizjany a15c9d289b There have been bigger non-backwards-compatible changes since. 2013-08-18 18:48:31 -04:00
wizjany c0f95bebf0 Send item-use blacklist event when right-clicking entities. 2013-08-16 13:17:28 -04:00
wizjany 0a54779fc4 Added snow-fall-blocks option to config to restrict snow fall to certain blocks 2013-08-12 18:09:45 -04:00
wizjany ac525958c5 Added config option and flag to prevent soil from drying naturally. 2013-08-12 18:06:31 -04:00
wizjany 458cf64501 Fixed addowner/addmember commands adding command artifacts.
Specifically, "-w <world>" will no longer be added when using it.
This requires WorldEdit with commit cd5f832 or newer.
Additionally fixed a typo: DefaultDomain.removaAll -> removeAll.
2013-08-03 09:46:29 -04:00
wizjany 4acef77623 Fixed milking cows in protected areas.
It seems that Bukkit changed the return of the bucket/itemstack
methods in the event, causing WG to think a different bucket was used.
2013-07-30 11:14:59 -04:00
TomyLobo d38d7fc492 Changed entity report format slightly.
This makes it clearer to users what that floating point number means.
2013-07-30 12:15:28 +02:00
wizjany 2510c3eeb5 Allow players to add newlines (\n) via command, not just manually in yml. 2013-07-25 13:10:16 -04:00
wizjany 326d53fd09 Allow the console to load/save all region managers with one command. 2013-07-25 10:12:03 -04:00
sk89q 75b3082b12 [maven-release-plugin] prepare for next development iteration 2013-07-16 11:07:26 -07:00
sk89q 1f214aadee [maven-release-plugin] prepare release 5.8 2013-07-16 11:07:06 -07:00
sk89q 174b3fad15 Updated Maven release plugin to 2.4.1. 2013-07-16 10:45:44 -07:00
sk89q 07531f67d4 Updated org.bukkit:bukkit dependency to 1.6.2-R0.1-SNAPSHOT. 2013-07-16 10:35:30 -07:00
sk89q 291c45064a Bumped version to 5.8-SNAPSHOT, updated CHANGELOG.txt. 2013-07-07 12:28:57 -07:00
sk89q 6f56cb29a5 Fixed -w flag for /rg load and /rg save. 2013-07-07 12:14:41 -07:00
sk89q 977c7d2f29 Changed DoubleFlag and IntegerFlag to take java.lang.Number objects in unmarshal(). 2013-07-07 11:45:22 -07:00
sk89q ecb87efe8d Update Bukkit dependency to version 1.6.1-R0.1-SNAPSHOT. 2013-07-07 11:42:24 -07:00
sk89q a57c162cd8 Convert heal flags datatype from integer to double.
Existing data should be cast with no data loss.
2013-07-07 11:38:03 -07:00
wizjany 60c3ed4f6b Polish the fix from the last commit and straighten some other multiworld issues in the move handler. 2013-06-23 20:17:20 -04:00
wizjany 714e75eb95 Potential fix for broken multiworld states. 2013-06-23 16:35:57 -04:00
Wizjany 636819c801 Revert change to permissions node for flags.
region.flag.own/member/etc was region.flag.regions.own/member/etc
This shouldn't be changed in between, especially if we maintain compatibility with the other flag node (flag.flags).
2013-06-20 00:52:59 -03:00
wizjany 9a6c2e0685 Finish reverting changes from earlier 2013-06-10 23:12:06 -04:00
wizjany 736eecc13b Add config option to use player teleports for move events.
Additionally removed code duplication in Vehicle listener.
2013-06-08 12:04:58 -04:00
TomyLobo 4718c5dab0 Removed unused imports. 2013-06-07 14:06:07 +02:00
Albert Pham 7e9bd49da2 Added mobs.disable-snowman-trails. 2013-06-02 13:23:01 -07:00
wizjany a0d0ff0b92 Lighter changes in BlockIgnite as well 2013-06-02 11:19:12 -04:00
wizjany b41be0c319 Added a static WorldGuardPlugin instance and made the utility methods in RegionCommands static. 2013-06-01 18:14:59 -04:00
wizjany 17a466059e A few changes in the new region commands.
- Allow setting flags on the global region (bugfix)
- Don't throw permissions errors when listing available flags (bugfix)
- Info command defaults to global region if no others are present (enhancement)
- A few typo and spacing fixes (enhancement)
2013-06-01 17:39:49 -04:00
wizjany 2d9e95a63e Revert lighter changes for now. This brings back the odd behaviors between flint & steel and fire charges, but makes it more intuitive for protection. 2013-06-01 10:14:56 -04:00
Albert Pham 532a45f9e7 Offering a sacrifice to the gods of pedantry. canX() -> mayX() for permissions. 2013-05-31 22:06:37 -07:00
Albert Pham d61e32ebb5 Cleaned up RegionCommands, abstracted region permissions. 2013-05-31 21:56:32 -07:00
Albert Pham b7d38e94c8 Added -a flag to region remove owner/member commands to remove all. 2013-05-29 13:24:40 -07:00
wizjany ae158742f6 [maven-release-plugin] prepare for next development iteration 2013-05-26 17:20:00 -04:00
wizjany c35686f8d1 [maven-release-plugin] prepare release 5.7.5 2013-05-26 17:20:00 -04:00
wizjany a5b6651582 Update CHANGELOG for 5.7.4 and 5.7.5 2013-05-26 17:10:35 -04:00
wizjany 54973fdf82 Large patch with lots of changes and fixes.
- Unified movement checking. Teleporting is now handled by
  entry/exit flags. Additionally, a region movement event is
  much closer to being added.
- Fixed an issue with enderpearls and exit/entry flags conflicting.
- Fixed a null check issue in several commands.
- Fixed allowed and blocked command flags making false matches and
  improved support for blocking/allowing specific command args.
2013-05-26 17:08:51 -04:00
wizjany 0bee631385 Use getName instead of toString for displaying world name. 2013-05-15 07:56:04 -04:00
wizjany 6283382837 Fixed a few movement flag related issues.
WG no longer prefixes greeting/farewell flags with '**', allowing people to customize the message.
(Adding &c** to the beginning of the message will give previous behavior)
Removed the "game mode locked" message since it returns false gamemodes when being called inside a player move event.
2013-05-05 10:57:46 -04:00
Silthus 39bb522051 Fixes heal flag bugs when player.maxHealth > 20
With the new Bukkit Changes the Player Health can be above 20, this fixes the magic number by using the now built in Bukkit functionality.

Examples of this bug were Health jumping to 1/20 hearts when having a heal-amount: -1
2013-05-04 11:47:43 +03:00
wizjany bf80d57abe Add fishing to xp blocker. 2013-04-21 08:59:24 -04:00
wizjany 865b94006a Apply other-explosion flag to entity damage as well. 2013-04-09 17:23:56 -04:00
wizjany 874248f8b5 Fix other explosion flag only clearing blocklist 2013-04-09 12:25:05 -04:00
steffen cef7d5bb12 Fix explosion check order
If the explosion is blocked and the block damage is also blocked, it's necessary to block the explosion (which includes the damage) instead of just the block damage.
2013-04-01 18:34:11 -04:00
wizjany 2a8131780f Don't ignore canceled air right click events.
Apparently Bukkit pre-cancels them even if they would do something.
2013-03-31 19:13:05 -04:00
Wizjany 7094f70f4a Remove duplicate check. (derp) 2013-03-31 19:13:04 -04:00
wizjany df5af6129c Improved lighter handling. 2013-03-23 21:10:30 -04:00
wizjany a6888c3767 Respect LIGHTER flag for ignition build checks 2013-03-23 15:19:56 -04:00
wizjany 1bd367ddde Fix one last witherskull/fireball conflict 2013-03-22 19:28:18 -04:00
wizjany 0cf87ae561 Allow cow milking in no-build areas 2013-03-22 15:35:30 -04:00
wizjany fa80f5f67f Fix infinite durability.
For whatever reason, the Bukkit API thinks that 'Durability" and "Damage"
are synonymous.
2013-03-18 13:25:11 -04:00
sk89q 7f080f920d [maven-release-plugin] prepare for next development iteration 2013-03-16 22:17:14 -07:00
35 changed files with 2215 additions and 1449 deletions

No files matched your search

+7
View File
@@ -4,3 +4,10 @@
target
.DS_Store
*.iml
.idea
/bin
/dependency-reduced-pom.xml
*-private.sh
+61
View File
@@ -1,3 +1,64 @@
5.9
- Added a config option to allow explosion flags to only prevent block damage
- Added allow-tamed-spawns setting, on by default. This will stop WorldGuard
from culling tamed animals.
- Added config option and flag to prevent soil from drying naturally.
- Added formatting codes, &k/l/m/n/o and &x (reset).
- Added snow-fall-blocks option to config to restrict snow fall to certain blocks
- Allow players to add newlines (\n) via command, not just manually in yml.
- Allow the console to load/save all region managers with one command.
- Changed entity report format slightly.
- Check bypass perms for item-drop flag.
- Check for entities and projectiles removing items from frames too.
- Fix being able to use bonemeal to turn tall grass into double plants.
- Fix number of arguments for migratedb command.
- Fixed addowner/addmember commands adding command artifacts. Specifically,
"-w <world>" will no longer be added when using it.
- Fixed milking cows in protected areas due to changes in Bukkit.
- Fixed ProtectedCuboidRegion::getPoints() returning points in wrong order.
- Fixed snowman trails being treated as snow fall.
- Make /rg list default to own regions if the player doesn't have permission otherwise.
- Protected items in item frames in protected regions.
- Resolved an issue where explosions of type OTHER_EXPLOSION were ignoring the world
configuration settings.
- Send item-use blacklist event when right-clicking entities.
- Transformed the BlockFadeEvent handler into a switch.
5.8:
- BREAKING CHANGE: This version has been built for versions of Bukkit for MC 1.6.1 and
newer. Do not try to use this version of WG on an older Bukkit version.
- Added support for Minecraft 1.6+. Actual support of new 1.6 additions is dependant on
Bukkit. Please use a newer build of Bukkit if, for example, you seem to be unable to
add "Horses" to your lists of entities.
- Added mobs.disable-snowman-trails to disable the trails left by walking snowmen.
- Added -a flag to /region removeowner and /region removemember to remove all objects.
- Teleporting is now handled by entry/exit flags. If this is causing people to get
entirely stuck inside entry/exit deny regions, set the new setting
'use-player-teleports' to 'false' in your configuration.
- Updated formatting for region commands, especially /region info.
- Changed permissions checking for /region commands to be more consistent, checking for
region IDs as a sub-node. This means that if some permissions for some region
commands no longer work, add '.*' to the end of permission lines for WG in your
permission plugin.
5.7.5:
- Refixed a few issues from 5.7.4.
5.7.4:
- BREAKING CHANGE: Removed the cyan "**" in front of greeting
and farewell messages to allow more customizability. You can
re-add them by adding "&c**" to the flag.
- Fixed an issue enderpearling inside exit/entry deny regions.
- Added checks to players teleporting in and out of exit/entry regions.
- Fix bad matching in blocked and allowed command flags.
- Fixed heal flag bugs when player max health was increased.
- Add fishing to xp blocker.
- Applied other-explosion flag to entity damage as well.
- Fixed an issue with interaction that should allow blacklisting item use actions with no block involved (eg fishing rods, potions)
- Fix witherskull/fireball settings not being differentiated in one case
- Allow cow milking in no-build areas
- Fix infinite durability breaking items instantly.
5.7.3:
- Fixed the error caused by Bukkit's change of the TNT minecart API.
+2 -2
View File
@@ -34,5 +34,5 @@ Links
* [Mailing list](https://groups.google.com/d/forum/sk-dev-discuss)
* [IRC channel](http://skq.me/irc/irc.esper.net/sk89q/) (#sk89q on irc.esper.net)
* [Issue tracker](http://youtrack.sk89q.com/issues/WORLDGUARD)
* [Continuous integration](http://build.sk89q.com) [![Build Status](https://secure.travis-ci.org/sk89q/worldguard.png)](http://travis-ci.org/sk89q/worldguard)
* [End-user documentation](http://wiki.sk89q.com/wiki/WorldGuard)
* [Continuous integration](http://builds.enginehub.org) [![Build Status](https://secure.travis-ci.org/sk89q/worldguard.png)](http://travis-ci.org/sk89q/worldguard)
* [End-user documentation](http://wiki.sk89q.com/wiki/WorldGuard)
+14 -6
View File
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.7.3</version>
<version>5.9</version>
<packaging>jar</packaging>
<!-- Project information -->
@@ -31,7 +31,7 @@
<connection>scm:git:git://github.com/sk89q/worldguard.git</connection>
<developerConnection>scm:git:git@github.com:sk89q/worldguard.git</developerConnection>
<url>https://github.com/sk89q/worldguard</url>
<tag>master</tag>
<tag>5.9</tag>
</scm>
<mailingLists>
@@ -46,6 +46,14 @@
<id>sk89q-docs-upload</id>
<url>ftp://sk89q-maven-deploy/worldguard/</url>
</site>
<repository>
<id>maven.sk89q.com</id>
<url>http://maven.sk89q.com/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>maven.sk89q.com-snapshot</id>
<url>http://maven.sk89q.com/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
<properties> <!-- Fix encoding warnings -->
@@ -71,7 +79,7 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.5.3</version>
<version>5.5.8</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
@@ -79,7 +87,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.5-R0.1-SNAPSHOT</version>
<version>1.7.2-R0.3</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
@@ -87,7 +95,7 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>commandbook</artifactId>
<version>2.1</version>
<version>2.3</version>
<scope>compile</scope>
<type>jar</type>
<exclusions>
@@ -239,7 +247,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<version>2.4.1</version>
<configuration>
<preparationGoals>assembly:assembly</preparationGoals>
<goals>assembly:assembly</goals>
@@ -0,0 +1,46 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.command.CommandSender;
import org.enginehub.util.PermissionModel;
abstract class AbstractPermissionModel implements PermissionModel {
private final WorldGuardPlugin plugin;
private final CommandSender sender;
public AbstractPermissionModel(WorldGuardPlugin plugin, CommandSender sender) {
this.plugin = plugin;
this.sender = sender;
}
protected WorldGuardPlugin getPlugin() {
return plugin;
}
public CommandSender getSender() {
return sender;
}
protected boolean hasPluginPermission(String permission) {
return plugin.hasPermission(getSender(), "worldguard." + permission);
}
}
@@ -29,7 +29,14 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
@@ -242,6 +249,14 @@ public class BukkitUtil {
str = str.replace("&2", ChatColor.GRAY.toString());
str = str.replace("&w", ChatColor.WHITE.toString());
str = str.replace("&k", ChatColor.MAGIC.toString());
str = str.replace("&l", ChatColor.BOLD.toString());
str = str.replace("&m", ChatColor.STRIKETHROUGH.toString());
str = str.replace("&n", ChatColor.UNDERLINE.toString());
str = str.replace("&o", ChatColor.ITALIC.toString());
str = str.replace("&x", ChatColor.RESET.toString());
return str;
}
@@ -255,26 +270,12 @@ public class BukkitUtil {
return entity instanceof Item
|| entity instanceof TNTPrimed
|| entity instanceof ExperienceOrb
|| entity instanceof FallingSand
|| entity instanceof FallingBlock
|| (entity instanceof LivingEntity
&& !(entity instanceof Tameable)
&& !(entity instanceof Player));
}
/**
* Returns whether our running CraftBukkit already supports
* the HangingEvent instead of the PaintingEvent
*
* @return true if the hanging event is supported
*/
public static boolean hasHangingEvent() {
Class<?> tmp = null;
try {
tmp = Class.forName("org.bukkit.event.hanging.HangingEvent");
} catch (ClassNotFoundException ignored) { }
return (tmp != null);
}
/**
* Search an enum for a value, and return the first one found. Return null if the
* enum entry is not found.
@@ -99,6 +99,7 @@ public class ConfigurationManager {
public boolean activityHaltToggle = false;
public boolean autoGodMode;
public boolean usePlayerMove;
public boolean usePlayerTeleports;
public boolean deopOnJoin;
public boolean blockInGameOp;
public Map<String, String> hostKeys = new HashMap<String, String>();
@@ -144,6 +145,7 @@ public class ConfigurationManager {
autoGodMode = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean("use-player-move-event", true);
usePlayerTeleports = config.getBoolean("use-player-teleports", true);
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
@@ -19,18 +19,19 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.HashMap;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* This processes per-player state information and is also meant to be used
@@ -59,7 +60,8 @@ public class FlagStateManager implements Runnable {
/**
* Run the task.
*/
public void run() {
@Override
public void run() {
Player[] players = plugin.getServer().getOnlinePlayers();
ConfigurationManager config = plugin.getGlobalStateManager();
@@ -112,14 +114,18 @@ public class FlagStateManager implements Runnable {
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);
Double minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
Double maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
return;
}
if (minHealth == null) minHealth = 0;
if (maxHealth == null) maxHealth = 20;
if (minHealth == null) {
minHealth = 0.0;
}
if (maxHealth == null) {
maxHealth = player.getMaxHealth();
}
// Apply a cap to prevent possible exceptions
minHealth = Math.min(player.getMaxHealth(), minHealth);
@@ -159,8 +165,12 @@ public class FlagStateManager implements Runnable {
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
return;
}
if (minHunger == null) minHunger = 0;
if (maxHunger == null) maxHunger = 20;
if (minHunger == null) {
minHunger = 0;
}
if (maxHunger == null) {
maxHunger = 20;
}
// Apply a cap to prevent possible exceptions
minHunger = Math.min(20, minHunger);
@@ -0,0 +1,145 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
/**
* Used for querying region-related permissions.
*/
public class RegionPermissionModel extends AbstractPermissionModel {
public RegionPermissionModel(WorldGuardPlugin plugin, CommandSender sender) {
super(plugin, sender);
}
public boolean mayForceLoadRegions() {
return hasPluginPermission("region.load");
}
public boolean mayForceSaveRegions() {
return hasPluginPermission("region.save");
}
public boolean mayMigrateRegionStore() {
return hasPluginPermission("region.migratedb");
}
public boolean mayDefine() {
return hasPluginPermission("region.define");
}
public boolean mayRedefine(ProtectedRegion region) {
return hasPatternPermission("redefine", region);
}
public boolean mayClaim() {
return hasPluginPermission("region.claim");
}
public boolean mayClaimRegionsUnbounded() {
return hasPluginPermission("region.unlimited");
}
public boolean mayDelete(ProtectedRegion region) {
return hasPatternPermission("remove", region);
}
public boolean maySetPriority(ProtectedRegion region) {
return hasPatternPermission("setpriority", region);
}
public boolean maySetParent(ProtectedRegion child, ProtectedRegion parent) {
return hasPatternPermission("setparent", child) &&
(parent == null ||
hasPatternPermission("setparent", parent));
}
public boolean maySelect(ProtectedRegion region) {
return hasPatternPermission("select", region);
}
public boolean mayLookup(ProtectedRegion region) {
return hasPatternPermission("info", region);
}
public boolean mayTeleportTo(ProtectedRegion region) {
return hasPatternPermission("teleport", region);
}
public boolean mayList() {
return hasPluginPermission("region.list");
}
public boolean mayList(String targetPlayer) {
if (targetPlayer == null) {
return mayList();
}
if (targetPlayer.equalsIgnoreCase(getSender().getName())) {
return hasPluginPermission("region.list.own");
} else {
return mayList();
}
}
public boolean maySetFlag(ProtectedRegion region) {
return hasPatternPermission("flag.regions", region);
}
public boolean maySetFlag(ProtectedRegion region, Flag<?> flag) {
// This is a WTF permission
return hasPatternPermission(
"flag.flags." + flag.getName().toLowerCase(), region);
}
/**
* Checks to see if the given sender has permission to modify the given region
* using the region permission pattern.
*
* @param perm the name of the node
* @param region the region
*/
private boolean hasPatternPermission(String perm, ProtectedRegion region) {
if (!(getSender() instanceof Player)) {
return true; // Non-players (i.e. console, command blocks, etc.) have full power
}
LocalPlayer localPlayer = getPlugin().wrapPlayer((Player) getSender());
String idLower = region.getId().toLowerCase();
String effectivePerm;
if (region.isOwner(localPlayer)) {
return hasPluginPermission("region." + perm + ".own." + idLower) ||
hasPluginPermission("region." + perm + ".member." + idLower);
} else if (region.isMember(localPlayer)) {
return hasPluginPermission("region." + perm + ".member." + idLower);
} else {
effectivePerm = "region." + perm + "." + idLower;
}
return hasPluginPermission(effectivePerm);
}
}
@@ -231,7 +231,7 @@ public class ReportWriter {
for (Map.Entry<Class<? extends Entity>, Integer> entry
: entityCounts.entrySet()) {
entitiesLog.put(entry.getKey().getSimpleName(),
"%d [%f]",
"%d [%f/chunk]",
entry.getValue(),
(float) (entry.getValue() / (double) loadedChunkCount));
}
@@ -18,7 +18,6 @@
package com.sk89q.worldguard.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.World;
import com.sk89q.worldguard.protection.managers.RegionManager;
@@ -27,7 +26,6 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
* Helper class to get a reference to WorldGuard and its components.
*/
public class WGBukkit {
private static WorldGuardPlugin cachedPlugin = null;
private WGBukkit() {
}
@@ -43,17 +41,16 @@ public class WGBukkit {
* @return the WorldGuard plugin or null
*/
public static WorldGuardPlugin getPlugin() {
if (cachedPlugin == null) {
cachedPlugin = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
}
return cachedPlugin;
return WorldGuardPlugin.inst();
}
/**
* Set cache to null for reload WorldGuardPlugin
* @deprecated instance is now stored directly in {@link WorldGuardPlugin}
*/
@Deprecated
public static void cleanCache() {
cachedPlugin = null;
// do nothing - plugin instance is stored in plugin class now
}
/**
@@ -67,7 +64,7 @@ public class WGBukkit {
if (getPlugin() == null) {
return null;
}
return cachedPlugin.getRegionManager(world);
return WorldGuardPlugin.inst().getRegionManager(world);
}
}
@@ -130,6 +130,7 @@ public class WorldConfiguration {
public boolean highFreqFlags;
public int regionWand;
public Set<EntityType> blockCreatureSpawn;
public boolean allowTamedSpawns;
// public boolean useiConomy;
// public boolean buyOnClaim;
// public double buyOnClaimPrice;
@@ -161,12 +162,17 @@ public class WorldConfiguration {
public boolean disableMyceliumSpread;
public boolean disableVineGrowth;
public boolean disableEndermanGriefing;
public boolean disableSnowmanTrails;
public boolean disableSoilDehydration;
public Set<Integer> allowedSnowFallOver;
public boolean regionInvinciblityRemovesMobs;
public boolean explosionFlagCancellation;
public boolean disableDeathMessages;
public boolean disableObsidianGenerators;
private Map<String, Integer> maxRegionCounts;
/* Configuration data end */
/**
@@ -352,7 +358,9 @@ public class WorldConfiguration {
blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false);
blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false);
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
allowTamedSpawns = getBoolean("mobs.allow-tamed-spawns", true);
disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false);
disableSnowmanTrails = getBoolean("mobs.disable-snowman-trails", false);
blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false);
blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
@@ -398,9 +406,12 @@ public class WorldConfiguration {
disableGrassGrowth = getBoolean("dynamics.disable-grass-growth", false);
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
allowedSnowFallOver = new HashSet<Integer>(getIntList("dynamics.snow-fall-blocks", null));
useRegions = getBoolean("regions.enable", true);
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
explosionFlagCancellation = getBoolean("regions.explosion-flags-block-entity-damage", true);
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
regionWand = getInt("regions.wand", 334);
maxClaimVolume = getInt("regions.max-claim-volume", 30000);
@@ -583,7 +594,9 @@ public class WorldConfiguration {
for (String group : plugin.getGroups(player)) {
if (maxRegionCounts.containsKey(group)) {
int groupMax = maxRegionCounts.get(group);
if (max < groupMax) max = groupMax;
if (max < groupMax) {
max = groupMax;
}
}
}
if (max <= -1) {
@@ -18,7 +18,7 @@
*/
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -26,6 +26,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowman;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -45,6 +46,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.ItemStack;
@@ -140,7 +142,7 @@ public class WorldGuardBlockListener implements Listener {
if (held.getTypeId() > 0
&& !(ItemType.usesDamageValue(held.getTypeId())
|| BlockType.usesData(held.getTypeId()))) {
held.setDurability(Material.getMaterial(held.getTypeId()).getMaxDurability());
held.setDurability((short) 0);
player.setItemInHand(held);
}
}
@@ -339,12 +341,11 @@ public class WorldGuardBlockListener implements Listener {
if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
// this is preliminarily handled in the player listener under handleBlockRightClick
// why it's handled here too, no one knows
if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) {
if (!set.canBuild(localPlayer)) {
event.setCancelled(true);
return;
}
if (!set.allows(DefaultFlag.LIGHTER, localPlayer)
if (!set.allows(DefaultFlag.LIGHTER)
&& !set.canBuild(localPlayer)
&& !plugin.hasPermission(player, "worldguard.override.lighter")) {
event.setCancelled(true);
return;
@@ -684,6 +685,16 @@ public class WorldGuardBlockListener implements Listener {
int type = event.getNewState().getTypeId();
if (event instanceof EntityBlockFormEvent) {
if (((EntityBlockFormEvent) event).getEntity() instanceof Snowman) {
if (wcfg.disableSnowmanTrails) {
event.setCancelled(true);
return;
}
}
return;
}
if (type == BlockID.ICE) {
if (wcfg.disableIceFormation) {
event.setCancelled(true);
@@ -701,6 +712,14 @@ public class WorldGuardBlockListener implements Listener {
event.setCancelled(true);
return;
}
if (wcfg.allowedSnowFallOver.size() > 0) {
int targetId = event.getBlock().getRelative(0, -1, 0).getTypeId();
if (!wcfg.allowedSnowFallOver.contains(targetId)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
event.setCancelled(true);
@@ -786,31 +805,46 @@ public class WorldGuardBlockListener implements Listener {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
int type = event.getBlock().getTypeId();
if (type == BlockID.ICE) {
switch (event.getBlock().getTypeId()) {
case BlockID.ICE:
if (wcfg.disableIceMelting) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
DefaultFlag.ICE_MELT, event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
}
break;
if (type == BlockID.SNOW) {
case BlockID.SNOW:
if (wcfg.disableSnowMelting) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
DefaultFlag.SNOW_MELT, event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
break;
case BlockID.SOIL:
if (wcfg.disableSoilDehydration) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
DefaultFlag.SOIL_DRY, event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
break;
}
}
/*
@@ -26,7 +26,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.EnderPearl;
@@ -34,8 +33,8 @@ import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
@@ -44,6 +43,7 @@ import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Wither;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -90,8 +90,6 @@ public class WorldGuardEntityListener implements Listener {
private WorldGuardPlugin plugin;
private EntityType tntMinecartType;
/**
* Construct the object;
*
@@ -99,7 +97,6 @@ public class WorldGuardEntityListener implements Listener {
*/
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
tntMinecartType = BukkitUtil.tryEnum(EntityType.class, "MINECART_TNT");
}
/**
@@ -192,7 +189,21 @@ public class WorldGuardEntityListener implements Listener {
return;
}
if (wcfg.disableExplosionDamage && type == DamageCause.BLOCK_EXPLOSION) {
if (type == DamageCause.BLOCK_EXPLOSION
&& (wcfg.disableExplosionDamage || wcfg.blockOtherExplosions
|| (wcfg.explosionFlagCancellation
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.OTHER_EXPLOSION, player.getLocation())))) {
event.setCancelled(true);
return;
}
} else {
// for whatever reason, plugin-caused explosions with a null entity count as block explosions and aren't
// handled anywhere else
if (type == DamageCause.BLOCK_EXPLOSION
&& (wcfg.blockOtherExplosions
|| (wcfg.explosionFlagCancellation
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.OTHER_EXPLOSION, defender.getLocation())))) {
event.setCancelled(true);
return;
}
@@ -229,6 +240,13 @@ public class WorldGuardEntityListener implements Listener {
}
}
if (defender instanceof ItemFrame) {
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
event.setCancelled(true);
return;
}
}
if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
@@ -276,14 +294,14 @@ public class WorldGuardEntityListener implements Listener {
}
}
if (attacker instanceof TNTPrimed || attacker.getType() == tntMinecartType) {
if (attacker instanceof TNTPrimed || attacker instanceof ExplosiveMinecart) {
// The check for explosion damage should be handled already... But... What ever...
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
if (wcfg.useRegions && wcfg.explosionFlagCancellation) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
@@ -295,9 +313,16 @@ public class WorldGuardEntityListener implements Listener {
}
if (attacker instanceof Fireball) {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
if (attacker instanceof WitherSkull) {
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
} else {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
Fireball fireball = (Fireball) attacker;
@@ -312,7 +337,7 @@ public class WorldGuardEntityListener implements Listener {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, false);
}
} else {
if (!set.allows(DefaultFlag.GHAST_FIREBALL, localPlayer)) {
if (!set.allows(DefaultFlag.GHAST_FIREBALL, localPlayer) && wcfg.explosionFlagCancellation) {
event.setCancelled(true);
return;
}
@@ -343,7 +368,7 @@ public class WorldGuardEntityListener implements Listener {
}
if (attacker instanceof Creeper) {
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION, localPlayer)) {
if (!set.allows(DefaultFlag.CREEPER_EXPLOSION, localPlayer) && wcfg.explosionFlagCancellation) {
event.setCancelled(true);
return;
}
@@ -367,7 +392,6 @@ public class WorldGuardEntityListener implements Listener {
}
}
}
}
}
}
@@ -391,7 +415,7 @@ public class WorldGuardEntityListener implements Listener {
}
// Check Mob
if (attacker != null && attacker instanceof LivingEntity && !(attacker instanceof Player)) {
if (attacker != null && !(attacker instanceof Player)) {
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
@@ -423,6 +447,11 @@ public class WorldGuardEntityListener implements Listener {
}
}
}
} else if (defender instanceof ItemFrame) {
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
event.setCancelled(true);
return;
}
}
}
@@ -511,7 +540,7 @@ public class WorldGuardEntityListener implements Listener {
return;
}
if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
BukkitUtil.findFreePosition(player);
event.setCancelled(true);
return;
@@ -561,33 +590,29 @@ public class WorldGuardEntityListener implements Listener {
}
if (ent instanceof Creeper) {
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockCreeperBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
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.CREEPER_EXPLOSION)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof EnderDragon) {
if (wcfg.blockEnderDragonBlockDamage) {
event.blockList().clear();
event.setCancelled(true);
return;
}
@@ -597,21 +622,20 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
event.blockList().clear();
event.setCancelled(true);
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof TNTPrimed || (ent != null && ent.getType() == tntMinecartType)) {
if (wcfg.blockTNTBlockDamage) {
event.blockList().clear();
return;
}
} else if (ent instanceof TNTPrimed || ent instanceof ExplosiveMinecart) {
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockTNTBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
@@ -619,32 +643,30 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) {
event.blockList().clear();
event.setCancelled(true);
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Fireball) {
if (ent instanceof WitherSkull) {
if (wcfg.blockWitherSkullBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
} else {
if (wcfg.blockFireballBlockDamage) {
if (wcfg.blockWitherSkullBlockDamage) {
event.blockList().clear();
return;
}
} else {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockFireballBlockDamage) {
event.blockList().clear();
return;
}
}
// allow wither skull blocking since there is no dedicated flag atm
if (wcfg.useRegions) {
@@ -653,25 +675,23 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) {
event.blockList().clear();
event.setCancelled(true);
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Wither) {
if (wcfg.blockWitherBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockWitherBlockDamage) {
event.blockList().clear();
return;
}
} else {
// unhandled entity
if (wcfg.blockOtherExplosions) {
event.blockList().clear();
event.setCancelled(true);
return;
}
@@ -680,6 +700,7 @@ public class WorldGuardEntityListener implements Listener {
for (Block block : event.blockList()) {
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.OTHER_EXPLOSION)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
@@ -734,7 +755,7 @@ public class WorldGuardEntityListener implements Listener {
return;
}
} else if (event.getEntityType() == EntityType.PRIMED_TNT
|| event.getEntityType() == tntMinecartType) {
|| event.getEntityType() == EntityType.MINECART_TNT) {
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
@@ -754,8 +775,15 @@ 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)
if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
return;
}
if (wcfg.allowTamedSpawns
&& event.getEntity() instanceof Tameable // nullsafe check
&& ((Tameable) event.getEntity()).isTamed()) {
return;
}
EntityType entityType = event.getEntityType();
@@ -976,4 +1004,41 @@ public class WorldGuardEntityListener implements Listener {
event.setCancelled(true);
}
}
/**
* Checks regions and config settings to protect items from being knocked
* out of item frames.
* @param attacker attacking entity
* @param defender item frame being damaged
* @return true if the event should be cancelled
*/
private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
World world = attacker.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
// bukkit throws this event when a player attempts to remove an item from a frame
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
if (attacker instanceof Player) {
Player player = (Player) attacker;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !mgr.getApplicableRegions(defender.getLocation())
.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
return true;
}
} else {
if (!plugin.getGlobalRegionManager().allows(
DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, defender.getLocation())) {
return true;
}
}
}
if (wcfg.blockEntityItemFrameDestroy && !(attacker instanceof Player)) {
return true;
}
return false;
}
}
@@ -1,174 +0,0 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.ChatColor;
import org.bukkit.Warning;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
/**
* Listener for painting related events.
*
* @author sk89q
* @deprecated Use {@link com.sk89q.worldguard.bukkit.WorldGuardHangingListener} instead.
*/
@Deprecated
@Warning(reason="This listener has been replaced by WorldGuardHangingListener")
public class WorldGuardPaintingListener implements Listener {
private WorldGuardPlugin plugin;
/**
* Construct the object;
*
* @param plugin The plugin instance
*/
public WorldGuardPaintingListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
/**
* Register events.
*/
public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
return;
}
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
Painting painting = event.getPainting();
World world = painting.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (event.getRemover() instanceof Player) {
Player player = (Player) event.getRemover();
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, painting.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
} else {
if (event.getRemover() instanceof Creeper) {
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(DefaultFlag.CREEPER_EXPLOSION, painting.getLocation())) {
event.setCancelled(true);
return;
}
}
if (wcfg.blockEntityPaintingDestroy
|| (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(DefaultFlag.ENTITY_PAINTING_DESTROY, painting.getLocation()))) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPaintingPlace(PaintingPlaceEvent event) {
Block placedOn = event.getBlock();
Player player = event.getPlayer();
World world = placedOn.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()), ItemID.PAINTING), false, false)) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityInteract(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(entity.getWorld());
if (wcfg.useRegions && entity instanceof Painting) {
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
if (entity instanceof Painting
&& ((!plugin.getGlobalRegionManager().allows(
DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
event.setCancelled(true);
}
}
}
}
@@ -45,7 +45,9 @@ import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -107,6 +109,173 @@ public class WorldGuardPlayerListener implements Listener {
}
}
// unsure if anyone actually started using this yet, but just in case...
@Deprecated
public static boolean checkMove(WorldGuardPlugin plugin, Player player, World world, Location from, Location to) {
return checkMove(plugin, player, from, to); // drop world since it used to be mishandled
}
/**
* Handles movement related events, including changing gamemode, sending
* greeting/farewell messages, etc.
* A reference to WorldGuardPlugin is required to keep this method static
* although WGBukkit.getPlugin() may be used.
* @return true if the movement should not be allowed
*/
public static boolean checkMove(WorldGuardPlugin plugin, Player player, Location from, Location to) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
//Flush states in multiworld scenario
if (state.lastWorld != null && !state.lastWorld.equals(to.getWorld())) {
plugin.getFlagStateManager().forget(player);
state = plugin.getFlagStateManager().getState(player);
}
World world = from.getWorld();
World toWorld = to.getWorld();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
boolean hasRemoteBypass = plugin.getGlobalRegionManager().hasBypass(player, toWorld);
RegionManager mgr = plugin.getGlobalRegionManager().get(toWorld);
Vector pt = new Vector(to.getBlockX(), to.getBlockY(), to.getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
/*
// check if region is full
// get the lowest number of allowed members in any region
boolean regionFull = false;
String maxPlayerMessage = null;
if (!hasBypass) {
for (ProtectedRegion region : set) {
if (region instanceof GlobalProtectedRegion) {
continue; // global region can't have a max
}
// get the max for just this region
Integer maxPlayers = region.getFlag(DefaultFlag.MAX_PLAYERS);
if (maxPlayers == null) {
continue;
}
int occupantCount = 0;
for(Player occupant : world.getPlayers()) {
// each player in this region counts as one toward the max of just this region
// A person with bypass doesn't count as an occupant of the region
if (!occupant.equals(player) && !plugin.getGlobalRegionManager().hasBypass(occupant, world)) {
if (region.contains(BukkitUtil.toVector(occupant.getLocation()))) {
if (++occupantCount >= maxPlayers) {
regionFull = true;
maxPlayerMessage = region.getFlag(DefaultFlag.MAX_PLAYERS_MESSAGE);
// At least one region in the set is full, we are going to use this message because it
// was the first one we detected as full. In reality we should check them all and then
// resolve the message from full regions, but that is probably a lot laggier (and this
// is already pretty laggy. In practice, we can't really control which one we get first
// right here.
break;
}
}
}
}
}
}
*/
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasRemoteBypass && (!entryAllowed /*|| regionFull*/)) {
String message = /*maxPlayerMessage != null ? maxPlayerMessage :*/ "You are not permitted to enter this area.";
player.sendMessage(ChatColor.DARK_RED + message);
return true;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = plugin.getGlobalRegionManager().get(world)
.getApplicableRegions(toVector(from))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
return true;
}
// WorldGuardRegionMoveEvent event = new WorldGuardRegionMoveEvent(plugin, player, state, set, from, to);
// Bukkit.getPluginManager().callEvent(event);
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);//, localPlayer);
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(replacedFarewell.replaceAll("\\\\n", "\n").split("\\n"));
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(replacedGreeting.replaceAll("\\\\n", "\n").split("\\n"));
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ 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;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = to.getWorld();
state.lastBlockX = to.getBlockX();
state.lastBlockY = to.getBlockY();
state.lastBlockZ = to.getBlockZ();
return false;
}
class PlayerMoveHandler implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
@@ -124,164 +293,14 @@ public class WorldGuardPlayerListener implements Listener {
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
//Flush states in multiworld scenario
if (state.lastWorld != null && !state.lastWorld.equals(world)) {
plugin.getFlagStateManager().forget(player);
state = plugin.getFlagStateManager().getState(player);
}
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
/*
// check if region is full
// get the lowest number of allowed members in any region
boolean regionFull = false;
String maxPlayerMessage = null;
if (!hasBypass) {
for (ProtectedRegion region : set) {
if (region instanceof GlobalProtectedRegion) {
continue; // global region can't have a max
}
// get the max for just this region
Integer maxPlayers = region.getFlag(DefaultFlag.MAX_PLAYERS);
if (maxPlayers == null) {
continue;
}
int occupantCount = 0;
for(Player occupant : world.getPlayers()) {
// each player in this region counts as one toward the max of just this region
// A person with bypass doesn't count as an occupant of the region
if (!occupant.equals(player) && !plugin.getGlobalRegionManager().hasBypass(occupant, world)) {
if (region.contains(BukkitUtil.toVector(occupant.getLocation()))) {
if (++occupantCount >= maxPlayers) {
regionFull = true;
maxPlayerMessage = region.getFlag(DefaultFlag.MAX_PLAYERS_MESSAGE);
// At least one region in the set is full, we are going to use this message because it
// was the first one we detected as full. In reality we should check them all and then
// resolve the message from full regions, but that is probably a lot laggier (and this
// is already pretty laggy. In practice, we can't really control which one we get first
// right here.
break;
}
}
}
}
}
}
*/
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && (!entryAllowed /*|| regionFull*/)) {
String message = /*maxPlayerMessage != null ? maxPlayerMessage :*/ "You are not permitted to enter this area.";
player.sendMessage(ChatColor.DARK_RED + message);
boolean result = checkMove(plugin, player, event.getFrom(), event.getTo());
if (result) {
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
newLoc.setZ(newLoc.getBlockZ() + 0.5);
event.setTo(newLoc);
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);//, localPlayer);
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));
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));
for (String line : replacedGreeting.split("\n")) {
player.sendMessage(ChatColor.AQUA + " ** " + line);
}
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ 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;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
}
}
}
@@ -297,8 +316,6 @@ public class WorldGuardPlayerListener implements Listener {
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!");
}
}
}
@@ -446,6 +463,27 @@ public class WorldGuardPlayerListener implements Listener {
plugin.forgetPlayer(player);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
// TODO reduce duplication with right-click-air
Player player = event.getPlayer();
World world = player.getWorld();
ItemStack item = player.getItemInHand();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
toVector(player.getLocation()),
item.getTypeId()), false, false)) {
event.setCancelled(true);
return;
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
@@ -601,10 +639,6 @@ public class WorldGuardPlayerListener implements Listener {
* @param event Thrown event
*/
private void handleAirRightClick(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
World world = player.getWorld();
ItemStack item = player.getItemInHand();
@@ -776,7 +810,8 @@ public class WorldGuardPlayerListener implements Listener {
if (item.getTypeId() == ItemID.FIRE_CHARGE || item.getTypeId() == ItemID.FLINT_AND_TINDER) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !placedInSet.canBuild(localPlayer)) {
&& !plugin.canBuild(player, placedIn)
&& !placedInSet.allows(DefaultFlag.LIGHTER)) {
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
@@ -806,7 +841,8 @@ public class WorldGuardPlayerListener implements Listener {
|| type == BlockID.MELON_STEM
|| type == BlockID.POTATOES
|| type == BlockID.CARROTS
|| type == BlockID.COCOA_PLANT)) {
|| type == BlockID.COCOA_PLANT
|| type == BlockID.LONG_GRASS)) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.canBuild(localPlayer)) {
event.setCancelled(true);
@@ -1197,7 +1233,8 @@ public class WorldGuardPlayerListener implements Listener {
Player player = event.getPlayer();
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ITEM_DROP, player.getLocation())) {
if (!plugin.getGlobalRegionManager().hasBypass(player, player.getWorld())
&& !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.");
}
@@ -1242,7 +1279,8 @@ public class WorldGuardPlayerListener implements Listener {
WorldConfiguration wcfg = cfg.get(world);
if (!plugin.getGlobalRegionManager().canBuild(
player, event.getBlockClicked().getRelative(event.getBlockFace()))) {
player, event.getBlockClicked().getRelative(event.getBlockFace()))
&& !(event.getItemStack().getTypeId() == ItemID.MILK_BUCKET)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@@ -1258,6 +1296,16 @@ public class WorldGuardPlayerListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getPlayer().getWorld());
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
event.getPlayer().getLocation())) {
event.setExpToDrop(0);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
@@ -1352,21 +1400,22 @@ public class WorldGuardPlayerListener implements Listener {
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (event.getCause() == TeleportCause.ENDER_PEARL) {
RegionManager mgr = plugin.getGlobalRegionManager().get(event.getFrom().getWorld());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
Vector ptFrom = new Vector(event.getFrom().getBlockX(), event.getFrom().getBlockY(), event.getFrom().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ApplicableRegionSet setFrom = mgr.getApplicableRegions(ptFrom);
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
RegionManager mgr = plugin.getGlobalRegionManager().get(event.getFrom().getWorld());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
Vector ptFrom = new Vector(event.getFrom().getBlockX(), event.getFrom().getBlockY(), event.getFrom().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ApplicableRegionSet setFrom = mgr.getApplicableRegions(ptFrom);
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !(set.allows(DefaultFlag.ENTRY, localPlayer)
&& setFrom.allows(DefaultFlag.EXIT, localPlayer))) {
event.getPlayer().sendMessage(ChatColor.DARK_RED + "You're not allowed to go there.");
if (cfg.usePlayerTeleports) {
boolean result = checkMove(plugin, event.getPlayer(), event.getFrom(), event.getTo());
if (result) {
event.setCancelled(true);
return;
}
}
if (event.getCause() == TeleportCause.ENDER_PEARL) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
&& !(set.allows(DefaultFlag.ENDERPEARL, localPlayer)
&& setFrom.allows(DefaultFlag.ENDERPEARL, localPlayer))) {
@@ -1391,32 +1440,88 @@ public class WorldGuardPlayerListener implements Listener {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
String lowerCommand = event.getMessage().toLowerCase();
String usedCommand = event.getMessage().toLowerCase();
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS, localPlayer);
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
String blockedCommand = "";
if (blockedCommands != null){
for (String aCommand : blockedCommands) {
if (lowerCommand.startsWith(aCommand)) {
blockedCommand = aCommand;
break;
}
}
}
if (allowedCommands != null) {
if (blockedCommand.isEmpty()) blockedCommand = lowerCommand.split(" ")[0];
for (String aCommand : allowedCommands) {
if (lowerCommand.startsWith(aCommand)) {
blockedCommand = "";
break;
/*
* blocked used allow?
* x x no
* x x y no
* x y x yes
* x y x y no
*
* allowed used allow?
* x x yes
* x x y yes
* x y x no
* x y x y yes
*/
String result = "";
String[] usedParts = usedCommand.split(" ");
if (blockedCommands != null) {
blocked:
for (String blockedCommand : blockedCommands) {
String[] blockedParts = blockedCommand.split(" ");
for (int i = 0; i < blockedParts.length && i < usedParts.length; i++) {
if (blockedParts[i].equalsIgnoreCase(usedParts[i])) {
// first part matches - check if it's the whole thing
if (i + 1 == blockedParts.length) {
// consumed all blocked parts, block entire command
result = blockedCommand;
break blocked;
} else {
// more blocked parts to check, also check used length
if (i + 1 == usedParts.length) {
// all that was used, but there is more in blocked
// allow this, check next command in flag
continue blocked;
} else {
// more in both blocked and used, continue checking
continue;
}
}
}
}
}
}
if (!blockedCommand.isEmpty()) {
player.sendMessage(ChatColor.RED + blockedCommand + " is not allowed in this area.");
if (allowedCommands != null) {
allowed:
for (String allowedCommand : allowedCommands) {
String[] allowedParts = allowedCommand.split(" ");
for (int i = 0; i < allowedParts.length && i < usedParts.length; i++) {
if (allowedParts[i].equalsIgnoreCase(usedParts[i])) {
// this part matches - check if it's the whole thing
if (i + 1 == allowedParts.length) {
// consumed all allowed parts before reaching used length
// this command is definitely allowed
result = "";
break allowed;
} else {
// more allowed parts to check
if (i + 1 == usedParts.length) {
// all that was used, but there is more in allowed
// block for now, check next part of flag
result = usedCommand;
continue allowed;
} else {
// more in both allowed and used, continue checking for match
continue;
}
}
} else {
// doesn't match at all, block it, check next flag string
result = usedCommand;
continue allowed;
}
}
}
}
if (!result.isEmpty()) {
player.sendMessage(ChatColor.RED + result + " is not allowed in this area.");
event.setCancelled(true);
return;
}
@@ -19,8 +19,6 @@
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.hasHangingEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -72,6 +70,11 @@ import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
*/
public class WorldGuardPlugin extends JavaPlugin {
/**
* Current instance of this plugin.
*/
private static WorldGuardPlugin inst;
/**
* Manager for commands. This automatically handles nested commands,
* permissions checking, and a number of other fancy command things.
@@ -102,7 +105,7 @@ public class WorldGuardPlugin extends JavaPlugin {
configuration = new ConfigurationManager(this);
globalRegionManager = new GlobalRegionManager(this);
final WorldGuardPlugin plugin = this;
final WorldGuardPlugin plugin = inst = this;
commands = new CommandsManager<CommandSender>() {
@Override
public boolean hasPermission(CommandSender player, String perm) {
@@ -111,6 +114,14 @@ public class WorldGuardPlugin extends JavaPlugin {
};
}
/**
* Get the current instance of WorldGuard
* @return WorldGuardPlugin instance
*/
public static WorldGuardPlugin inst() {
return inst;
}
/**
* Called on plugin enable.
*/
@@ -170,11 +181,7 @@ public class WorldGuardPlugin extends JavaPlugin {
(new WorldGuardWeatherListener(this)).registerEvents();
(new WorldGuardVehicleListener(this)).registerEvents();
(new WorldGuardServerListener(this)).registerEvents();
if (hasHangingEvent()) {
(new WorldGuardHangingListener(this)).registerEvents();
} else {
(new WorldGuardPaintingListener(this)).registerEvents();
}
(new WorldGuardHangingListener(this)).registerEvents();
configuration.updateCommandBookGodMode();
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
@@ -18,11 +18,9 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class WorldGuardVehicleListener implements Listener {
@@ -82,96 +80,16 @@ public class WorldGuardVehicleListener implements Listener {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
// unfortunate code duplication
if (wcfg.useRegions) {
// Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
boolean result = WorldGuardPlayerListener.checkMove(plugin, player, event.getFrom(), event.getTo());
if (result) {
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
vehicle.teleport(event.getFrom());
return;
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
vehicle.teleport(event.getFrom());
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE, localPlayer);
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE, localPlayer);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER, localPlayer);
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE, localPlayer);
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ regionList);
}
state.lastGreeting = greeting;
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,58 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
/**
* Used for /rg list.
*/
class RegionListEntry implements Comparable<RegionListEntry> {
private final String id;
private final int index;
boolean isOwner;
boolean isMember;
public RegionListEntry(String id, int index) {
this.id = id;
this.index = index;
}
@Override
public int compareTo(RegionListEntry o) {
if (isOwner != o.isOwner) {
return isOwner ? 1 : -1;
}
if (isMember != o.isMember) {
return isMember ? 1 : -1;
}
return id.compareTo(o.id);
}
@Override
public String toString() {
if (isOwner) {
return (index + 1) + ". +" + id;
} else if (isMember) {
return (index + 1) + ". -" + id;
} else {
return (index + 1) + ". " + id;
}
}
}
@@ -52,14 +52,20 @@ public class RegionMemberCommands {
min = 2)
public void addMember(CommandContext args, CommandSender sender) throws CommandException {
final World world;
Player player;
Player player = null;
LocalPlayer localPlayer = null;
if (sender instanceof Player) {
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
}
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
if (player != null) {
world = player.getWorld();
} else {
throw new CommandException("No world specified. Use -w <worldname>.");
}
}
String id = args.getString(0);
@@ -83,7 +89,7 @@ public class RegionMemberCommands {
}
}
RegionDBUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.addToDomain(region.getMembers(), args.getParsedPaddedSlice(1, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@@ -105,12 +111,18 @@ public class RegionMemberCommands {
final World world;
Player player = null;
LocalPlayer localPlayer = null;
if (sender instanceof Player) {
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
}
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
if (player != null) {
world = player.getWorld();
} else {
throw new CommandException("No world specified. Use -w <worldname>.");
}
}
String id = args.getString(0);
@@ -147,7 +159,7 @@ public class RegionMemberCommands {
}
}
RegionDBUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.addToDomain(region.getOwners(), args.getParsedPaddedSlice(1, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@@ -162,19 +174,25 @@ public class RegionMemberCommands {
@Command(aliases = {"removemember", "remmember", "removemem", "remmem"},
usage = "<id> <owners...>",
flags = "w:",
flags = "aw:",
desc = "Remove an owner to a region",
min = 2)
min = 1)
public void removeMember(CommandContext args, CommandSender sender) throws CommandException {
final World world;
Player player;
Player player = null;
LocalPlayer localPlayer = null;
if (sender instanceof Player) {
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
}
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
if (player != null) {
world = player.getWorld();
} else {
throw new CommandException("No world specified. Use -w <worldname>.");
}
}
String id = args.getString(0);
@@ -198,7 +216,14 @@ public class RegionMemberCommands {
}
}
RegionDBUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
if (args.hasFlag('a')) {
region.getMembers().removeAll();
} else {
if (args.argsLength() < 2) {
throw new CommandException("List some names to remove, or use -a to remove all.");
}
RegionDBUtil.removeFromDomain(region.getMembers(), args.getParsedPaddedSlice(1, 0), 0);
}
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@@ -213,20 +238,26 @@ public class RegionMemberCommands {
@Command(aliases = {"removeowner", "remowner"},
usage = "<id> <owners...>",
flags = "w:",
flags = "aw:",
desc = "Remove an owner to a region",
min = 2)
min = 1)
public void removeOwner(CommandContext args,
CommandSender sender) throws CommandException {
final World world;
Player player;
Player player = null;
LocalPlayer localPlayer = null;
if (sender instanceof Player) {
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
}
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
if (player != null) {
world = player.getWorld();
} else {
throw new CommandException("No world specified. Use -w <worldname>.");
}
}
String id = args.getString(0);
@@ -250,7 +281,14 @@ public class RegionMemberCommands {
}
}
RegionDBUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
if (args.hasFlag('a')) {
region.getOwners().removeAll();
} else {
if (args.argsLength() < 2) {
throw new CommandException("List some names to remove, or use -a to remove all.");
}
RegionDBUtil.removeFromDomain(region.getOwners(), args.getParsedPaddedSlice(1, 0), 0);
}
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@@ -0,0 +1,334 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
/**
* Create a region printout, as used in /region info to show information about
* a region.
*/
public class RegionPrintoutBuilder {
private final ProtectedRegion region;
private final StringBuilder builder = new StringBuilder();
/**
* Create a new instance with a region to report on.
*
* @param region the region
*/
public RegionPrintoutBuilder(ProtectedRegion region) {
this.region = region;
}
/**
* Add a new line.
*/
private void newLine() {
builder.append("\n");
}
/**
* Add region name, type, and priority.
*/
public void appendBasics() {
builder.append(ChatColor.BLUE);
builder.append("Region: ");
builder.append(ChatColor.YELLOW);
builder.append(region.getId());
builder.append(ChatColor.GRAY);
builder.append(" (type=");
builder.append(region.getTypeName());
builder.append(ChatColor.GRAY);
builder.append(", priority=");
builder.append(region.getPriority());
builder.append(")");
newLine();
}
/**
* Add information about flags.
*/
public void appendFlags() {
builder.append(ChatColor.BLUE);
builder.append("Flags: ");
appendFlagsList(true);
newLine();
}
/**
* Append just the list of flags (without "Flags:"), including colors.
*
* @param useColors true to use colors
*/
public void appendFlagsList(boolean useColors) {
boolean hasFlags = false;
for (Flag<?> flag : DefaultFlag.getFlags()) {
Object val = region.getFlag(flag), group = null;
// No value
if (val == null) {
continue;
}
if (hasFlags) {
builder.append(", ");
} else {
if (useColors) {
builder.append(ChatColor.YELLOW);
}
}
RegionGroupFlag groupFlag = flag.getRegionGroupFlag();
if (groupFlag != null) {
group = region.getFlag(groupFlag);
}
if(group == null) {
builder.append(flag.getName()).append(": ")
.append(String.valueOf(val));
} else {
builder.append(flag.getName()).append(" -g ")
.append(String.valueOf(group)).append(": ")
.append(String.valueOf(val));
}
hasFlags = true;
}
if (!hasFlags) {
if (useColors) {
builder.append(ChatColor.RED);
}
builder.append("(none)");
}
}
/**
* Add information about parents.
*/
public void appendParents() {
appendParentTree(true);
}
/**
* Add information about parents.
*
* @param useColors true to use colors
*/
public void appendParentTree(boolean useColors) {
if (region.getParent() == null) {
return;
}
List<ProtectedRegion> inheritance = new ArrayList<ProtectedRegion>();
ProtectedRegion r = region;
inheritance.add(r);
while (r.getParent() != null) {
r = r.getParent();
inheritance.add(r);
}
ListIterator<ProtectedRegion> it = inheritance.listIterator(
inheritance.size());
int indent = 0;
while (it.hasPrevious()) {
ProtectedRegion cur = it.previous();
if (useColors) {
builder.append(ChatColor.GREEN);
}
// Put symbol for child
if (indent != 0) {
for (int i = 0; i < indent; i++) {
builder.append(" ");
}
builder.append("\u2517");
}
// Put name
builder.append(cur.getId());
// Put (parent)
if (!cur.equals(region)) {
if (useColors) {
builder.append(ChatColor.GRAY);
}
builder.append(" (parent, priority=" + cur.getPriority() + ")");
}
indent++;
newLine();
}
}
/**
* Add information about members.
*/
public void appendDomain() {
builder.append(ChatColor.BLUE);
builder.append("Owners: ");
DefaultDomain owners = region.getOwners();
if (owners.size() != 0) {
builder.append(ChatColor.YELLOW);
builder.append(owners.toUserFriendlyString());
} else {
builder.append(ChatColor.RED);
builder.append("(no owners)");
}
newLine();
builder.append(ChatColor.BLUE);
builder.append("Members: ");
DefaultDomain members = region.getMembers();
if (members.size() != 0) {
builder.append(ChatColor.YELLOW);
builder.append(members.toUserFriendlyString());
} else {
builder.append(ChatColor.RED);
builder.append("(no members)");
}
newLine();
}
/**
* Add information about coordinates.
*/
public void appendBounds() {
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
builder.append(ChatColor.BLUE);
builder.append("Bounds:");
builder.append(ChatColor.YELLOW);
builder.append(" (" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")");
builder.append(" -> (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")");
newLine();
}
/**
* Append all the default fields used for /rg info.
*/
public void appendRegionInfo() {
builder.append(ChatColor.GRAY);
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
builder.append(" Region Info ");
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
newLine();
appendBasics();
appendFlags();
appendParents();
appendDomain();
appendBounds();
}
/**
* Send the report to a {@link CommandSender}.
*
* @param sender the recepient
*/
public void send(CommandSender sender) {
sender.sendMessage(toString());
}
public StringBuilder append(boolean b) {
return builder.append(b);
}
public StringBuilder append(char c) {
return builder.append(c);
}
public StringBuilder append(char[] str, int offset, int len) {
return builder.append(str, offset, len);
}
public StringBuilder append(char[] str) {
return builder.append(str);
}
public StringBuilder append(CharSequence s, int start, int end) {
return builder.append(s, start, end);
}
public StringBuilder append(CharSequence s) {
return builder.append(s);
}
public StringBuilder append(double d) {
return builder.append(d);
}
public StringBuilder append(float f) {
return builder.append(f);
}
public StringBuilder append(int i) {
return builder.append(i);
}
public StringBuilder append(long lng) {
return builder.append(lng);
}
public StringBuilder append(Object obj) {
return builder.append(obj);
}
public StringBuilder append(String str) {
return builder.append(str);
}
public StringBuilder append(StringBuffer sb) {
return builder.append(sb);
}
public StringBuilder appendCodePoint(int codePoint) {
return builder.appendCodePoint(codePoint);
}
@Override
public String toString() {
return builder.toString().trim();
}
}
@@ -128,7 +128,7 @@ public class ToggleCommands {
if (removed > 10) {
sender.sendMessage("" + removed + " entities (>10) auto-removed from "
+ world.toString());
+ world.getName());
}
}
@@ -34,7 +34,6 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.ReportWriter;
import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.util.PastebinPoster;
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
@@ -73,7 +72,7 @@ public class WorldGuardCommands {
plugin.getGlobalRegionManager().unload();
plugin.getGlobalStateManager().load();
plugin.getGlobalRegionManager().preload();
WGBukkit.cleanCache();
// WGBukkit.cleanCache();
sender.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
sender.sendMessage("Error while reloading: "
@@ -30,8 +30,8 @@ import java.util.Set;
import com.sk89q.worldguard.LocalPlayer;
public class DefaultDomain implements Domain {
private Set<String> groups;
private Set<String> players;
private final Set<String> groups;
private final Set<String> players;
public DefaultDomain() {
this.groups = new LinkedHashSet<String>();
@@ -135,4 +135,9 @@ public class DefaultDomain implements Domain {
return str.toString();
}
public void removeAll() {
groups.clear();
players.clear();
}
}
@@ -55,7 +55,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
/**
* Checks if a player can build in an area.
*
* @param player The player to chec
* @param player The player to check
* @return build ability
*/
public boolean canBuild(LocalPlayer player) {
@@ -353,9 +353,9 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
lastPriority = region.getPriority();
}
try {
if (!needsClear.isEmpty()) {
return needsClear.values().iterator().next();
} catch (NoSuchElementException e) {
} else {
if (globalRegion != null) {
V gFlag = globalRegion.getFlag(flag);
if (gFlag != null) return gFlag;
@@ -40,7 +40,7 @@ public final class DefaultFlag {
public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true);
public static final StateFlag SLEEP = new StateFlag("sleep", true);
public static final StateFlag TNT = new StateFlag("tnt", true, RegionGroup.ALL);
public static final StateFlag LIGHTER = new StateFlag("lighter", true, RegionGroup.ALL);
public static final StateFlag LIGHTER = new StateFlag("lighter", true);
public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", true);
public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", true);
public static final StateFlag LIGHTNING = new StateFlag("lightning", true);
@@ -60,6 +60,7 @@ public final class DefaultFlag {
public static final StateFlag GRASS_SPREAD = new StateFlag("grass-growth", true);
public static final StateFlag MYCELIUM_SPREAD = new StateFlag("mycelium-spread", true);
public static final StateFlag VINE_GROWTH = new StateFlag("vine-growth", true);
public static final StateFlag SOIL_DRY = new StateFlag("soil-dry", true);
public static final StateFlag ENDER_BUILD = new StateFlag("enderman-grief", true);
public static final StateFlag INVINCIBILITY = new StateFlag("invincible", false, RegionGroup.ALL);
public static final StateFlag EXP_DROPS = new StateFlag("exp-drops", true, RegionGroup.ALL);
@@ -80,8 +81,8 @@ public final class DefaultFlag {
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);
public static final IntegerFlag MAX_HEAL = new IntegerFlag("heal-max-health", RegionGroup.ALL);
public static final DoubleFlag MIN_HEAL = new DoubleFlag("heal-min-health", RegionGroup.ALL);
public static final DoubleFlag MAX_HEAL = new DoubleFlag("heal-max-health", RegionGroup.ALL);
public static final IntegerFlag FEED_DELAY = new IntegerFlag("feed-delay", RegionGroup.ALL);
public static final IntegerFlag FEED_AMOUNT = new IntegerFlag("feed-amount", RegionGroup.ALL);
public static final IntegerFlag MIN_FOOD = new IntegerFlag("feed-min-hunger", RegionGroup.ALL);
@@ -106,7 +107,7 @@ public final class DefaultFlag {
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE,
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH,
SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
TELE_LOC, SPAWN_LOC, POTION_SPLASH,
@@ -119,4 +120,20 @@ public final class DefaultFlag {
public static Flag<?>[] getFlags() {
return flagsList;
}
/**
* Try to match the flag with the given ID using a fuzzy name match.
*
* @param id the flag ID
* @return a flag, or null
*/
public static Flag<?> fuzzyMatchFlag(String id) {
for (Flag<?> flag : DefaultFlag.getFlags()) {
if (flag.getName().replace("-", "").equalsIgnoreCase(id.replace("-", ""))) {
return flag;
}
}
return null;
}
}
@@ -52,6 +52,8 @@ public class DoubleFlag extends Flag<Double> {
public Double unmarshal(Object o) {
if (o instanceof Double) {
return (Double) o;
} else if (o instanceof Number) {
return ((Number) o).doubleValue();
} else {
return null;
}
@@ -52,6 +52,8 @@ public class IntegerFlag extends Flag<Integer> {
public Integer unmarshal(Object o) {
if (o instanceof Integer) {
return (Integer) o;
} else if (o instanceof Number) {
return ((Number) o).intValue();
} else {
return null;
}
@@ -76,6 +76,7 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
setMinMaxPoints(min, pt);
}
@Override
public List<BlockVector2D> getPoints() {
List<BlockVector2D> pts = new ArrayList<BlockVector2D>();
int x1 = min.getBlockX();
@@ -85,8 +86,8 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
pts.add(new BlockVector2D(x1, z1));
pts.add(new BlockVector2D(x2, z1));
pts.add(new BlockVector2D(x1, z2));
pts.add(new BlockVector2D(x2, z2));
pts.add(new BlockVector2D(x1, z2));
return pts;
}
@@ -0,0 +1,23 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.enginehub.util;
public interface PermissionModel {
}
@@ -19,26 +19,8 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class FlatRegionManagerTest extends RegionOverlapTest {
protected RegionManager createRegionManager() throws Exception {
@@ -19,26 +19,8 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.PRTreeRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PRTreeRegionManagerTest extends RegionOverlapTest {
protected RegionManager createRegionManager() throws Exception {
@@ -28,7 +28,6 @@ import com.sk89q.worldguard.TestPlayer;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.*;
import org.junit.Test;
@@ -1,14 +1,12 @@
package com.sk89q.worldguard.protection;
package com.sk89q.worldguard.protection.regions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class RegionIntersectTest {
@@ -79,4 +77,27 @@ public class RegionIntersectTest {
assertEquals("Check for '" + region2.getId() + "' region failed.", expected, actual);
}
private static final BlockVector2D[] polygon = {
new BlockVector2D(1, 0),
new BlockVector2D(4, 3),
new BlockVector2D(4, -3),
};
@Test
public void testIntersection() throws Exception {
final ProtectedCuboidRegion cuboidRegion = new ProtectedCuboidRegion("cuboidRegion", new BlockVector(-3, -3, -3), new BlockVector(3, 3, 3));
for (int angle = 0; angle < 360; angle += 90) {
final BlockVector2D[] rotatedPolygon = new BlockVector2D[polygon.length];
for (int i = 0; i < polygon.length; i++) {
final BlockVector2D vertex = polygon[i];
rotatedPolygon[i] = vertex.transform2D(angle, 0, 0, 0, 0).toBlockVector2D();
}
final ProtectedPolygonalRegion polygonalRegion = new ProtectedPolygonalRegion("polygonalRegion", Arrays.asList(rotatedPolygon), -3, 3);
assertTrue(String.format("%s does not intersect (cuboid.intersectsEdges(polygonal)", Arrays.asList(rotatedPolygon)), cuboidRegion.intersectsEdges(polygonalRegion));
assertTrue(String.format("%s does not intersect (polygonal.intersectsEdges(cuboid)", Arrays.asList(rotatedPolygon)), polygonalRegion.intersectsEdges(cuboidRegion));
}
}
}