Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca7967085b |
No files matched your search
@@ -1 +0,0 @@
|
||||
github: enginehub
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a way in which WorldGuard is not working as intended
|
||||
title: ''
|
||||
labels: type:bug, status:pending
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Versions**
|
||||
<!-- Please include the full version of WorldEdit, WorldGuard and the platform (Bukkit/Spigot/Paper) you are running, e.g. output from `/we version`, `/wg version` `/version` commands. Please ensure you are running up to date software before making a bug report. Old versions will receive little to no support. -->
|
||||
WorldEdit version:
|
||||
|
||||
WorldGuard version:
|
||||
|
||||
Platform version:
|
||||
|
||||
|
||||
**Describe the bug**
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
|
||||
**To Reproduce**
|
||||
<!-- Steps to reproduce the behavior: -->
|
||||
1. ...
|
||||
2. ...
|
||||
|
||||
**Expected behavior**
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
**Screenshots**
|
||||
<!-- If applicable, add screenshots to help explain your problem. Screenshots of `/rg info` for any applicable regions (or simply the link from `/wg report -p`) are good to include. -->
|
||||
|
||||
**Additional context**
|
||||
<!-- Add any other context about the problem here. -->
|
||||
@@ -1,5 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: EngineHub Discord
|
||||
url: https://discord.gg/EngineHub
|
||||
about: Please ask and answer questions here.
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for WorldGuard
|
||||
title: ''
|
||||
labels: type:feature-request, status:pending
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
||||
|
||||
**Describe the solution you'd like**
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
**Additional context**
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
||||
@@ -15,5 +15,3 @@ dependency-reduced-pom.xml
|
||||
.gradle/
|
||||
**/build/
|
||||
out/
|
||||
|
||||
scripts/
|
||||
@@ -1,80 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 7.0.5
|
||||
|
||||
* Add a use-anvil flag and exclude it from the use flag (since they can break on use.)
|
||||
* Expand crop-related options (crop-growth, etc) to sweet berry bushes, nether wart, and bamboo.
|
||||
* Add a config option (`mobs.block-vehicle-entry`) to prevent non-players from entering vehicles.
|
||||
* Add a UUID flag (for developers/API usage).
|
||||
* Add map query methods with fallback flag (for developers/API usage).
|
||||
* Add `on` and `off` optional arguments for `/rg toggle-bypass` command.
|
||||
* Add additional timings info for session handlers.
|
||||
* Fix sponge-simulation clearing NBT from blocks. Note that if you are using sponge simulation you should switch to something like CraftBook as the feature will be removed from WorldGuard in a future (major) version.
|
||||
* Fix the `/rg` command showing up as unknown client-side to players without bypass perms.
|
||||
* Fix error propagation from third-party flag loading causing WG to error.
|
||||
* Fix a (harmless) exception that occurred when swapping armor slots to the offhand slot.
|
||||
* Fix empty lines being sent on enderpearl/chorus-fruit teleport if the deny messages were empty.
|
||||
* Fix an issue with falling blocks when using max-priority-association.
|
||||
* Fix performance issues with third-party plugins querying protection for offline players.
|
||||
* Fix dispensing shulkers over region boundaries.
|
||||
* Fix iron door interaction being denied as if it were a regular door.
|
||||
* Fix being able to enter/exit regions with the flag denied by using entity mounting functions in other plugins.
|
||||
|
||||
## 7.0.4 (including beta1)
|
||||
|
||||
* Add support for MC 1.16. Dropped support for previous versions.
|
||||
* Add respawn-anchors flag mirroring the sleep flag (e.g. to prevent using respawn anchors to cause explosions in the overworld)
|
||||
* Add nether vines to vine-growth flag.
|
||||
* Add config option to disable the bypass permission cache.
|
||||
* Fix water-flow flags not checking waterlogged blocks.
|
||||
* Add config option to consider non-player causes (e.g. pistons, flowing water) to only be members of the highest priority region. This should be enabled for plots-within-city-like setups to prevent things in plots from modifying the city.
|
||||
* Fix items dropping from falling blocks that were suppressed by other plugins.
|
||||
* Add config option to block turtle egg trampling.
|
||||
* Fix ride flag being checked on striders that didn't have saddles.
|
||||
* Add config option to have /rg bypass toggled off on login.
|
||||
* Developer changes: Methods taking names in Domains are now explicitly deprecated (was previously just a javadoc comment.); These will eventually be removed: there is no reason to use names over UUIDs. Offline players and NPCs alike have stable UUIDs.
|
||||
* Also for developers; The new `com.sk89q.worldguard.protection.util.WorldEditRegionConverter` class has some useful static methods to convert to and from WorldEdit's Region and WorldGuard's ProtectedRegion classes.
|
||||
|
||||
|
||||
## 7.0.3
|
||||
|
||||
* This is the last release supporting MC 1.14 and 1.15.
|
||||
* Decouple chest-access flag from interact flag. IMPORTANT: If you relied on allowing players to access chests via setting
|
||||
the interact flag to allow, you will now need to set the chest-access flag to allow instead (or as well). This does not
|
||||
affect any setups where users were *not* supposed to be able to access chests and other inventories.
|
||||
* Add natural-health-regen and natural-hunger-drain flags. Unlike the heal/feed flags, these can not restore or deplete health/hunger.
|
||||
* Fix the interact flag allowing breaking of turtle eggs (now tied directly to block-trampling flag).
|
||||
* Fix a memory leak that could occur with many many explosives.
|
||||
* Add regions.titles-always-use-default-times config option. Set this to true if you use greeting/farewell titles and another plugin
|
||||
makes the titles disappear too quickly.
|
||||
* Add protection for cauldrons water level changing.
|
||||
* Improve diagnostic hints and information, such as spawn protection warnings, flag colors in region info, etc.
|
||||
* Fix waterlogged blocks bypassing water-flow flag.
|
||||
* Workaround for a CraftBukkit change that made no-physics-sand/gravel non-functional.
|
||||
* Workaround for CraftBukkit throttling move events.
|
||||
* Track projectiles shot by dispensers.
|
||||
* Allowed setting passthrough allow on global to unprotect it if members/owners are added.
|
||||
* Add support for newer forge clients (FML2) in host keys.
|
||||
* Allow using WorldEdit's `//world <worldname>` command to select a world for region commands. This removes the need to
|
||||
use `-w <worldname>` in every command when running commands from console.
|
||||
* Add a teleport-message flag, shown when using `/rg tp`.
|
||||
* Add coral-fade flag, which prevents corals from drying when out of water.
|
||||
* Fix spammy deny-message when walking over redstone ore with certain flag setups.
|
||||
* Improve handling of interacting with various tools in hand that didn't modify blocks. (eg opening a chest with an axe in hand)
|
||||
* Fix allow-all-interact option not being read from per-world configs.
|
||||
* Fix misattribution of pets (eg wolves) in PvP.
|
||||
* Improve performance of hopper checks when on recent builds of Paper.
|
||||
* Add event-handling.break-hoppers-on-denied-move config option to prevent hoppers from being broken (but items still won't be moved).
|
||||
* Note to developers using the WorldGuard API: If you specifically relied on flags such as greeting/farewell, deny-message, etc being
|
||||
StringFlags, be warned that this will change in a future version to support JSON text components. Please plan accordingly.
|
||||
|
||||
|
||||
## 7.0.2
|
||||
* Update to MC 1.15. Still compatible with 1.14, and incompatible with 1.13, as before.
|
||||
* Add an informational message when defining a region that overlaps vanilla spawn protection.
|
||||
* Protect against pushing a piston with another piston on a region border.
|
||||
* Protect against buckets in dispensers on region borders.
|
||||
|
||||
## 7.0.1
|
||||
* Add `/rg toggle-bypass` command which temporarily turns off region bypassing until used again.
|
||||
* More improvements to `/rg flag` and `/rg flags` commands.
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ ask that you make note of the following guidelines.
|
||||
* **Follow the [Oracle coding conventions](https://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html).**
|
||||
We can't stress this enough; if your code has notable issues, it may delay
|
||||
the process significantly.
|
||||
* **Target Java 8 for source and compilation.** Make sure to mark methods with
|
||||
* **Target Java 6 for source and compilation.** Make sure to mark methods with
|
||||
` @Override` that override methods of parent classes, or that implement
|
||||
methods of interfaces.
|
||||
methods of interfaces (Java 6+).
|
||||
* **Use only spaces for indentation.** Our indents are 4-spaces long, and tabs
|
||||
are unacceptable.
|
||||
* **Wrap code to a 89 column limit.** We do this to make side by side diffs
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
<h1>
|
||||
<img src="worldguard-logo.svg" alt="WorldGuard" width="400" />
|
||||
</h1>
|
||||
# 
|
||||
|
||||
WorldGuard lets you and players guard areas of land against griefers and undesirables, as well as tweak and disable various gameplay features of Minecraft.
|
||||
|
||||
* Block creeper and wither block damage, falling damage, etc.
|
||||
* Disable fire spread, lava fire spread, ice formation, Endermen picking up blocks, etc.
|
||||
* Blacklist certain items and blocks so they can't be used
|
||||
* Warn moderators when certain items and blocks are used
|
||||
* Protect areas of your world so only certain people can build in them
|
||||
* Set areas where PVP, TNT, mob damage, and other features are disabled
|
||||
* Protect your server from various 'exploits' like magical obsidian creation machines
|
||||
* Disable, or enable, various Minecraft features, like sponges from classic
|
||||
* Add useful commands like an immediate "STOP ALL FIRE SPREAD" command
|
||||
* Enable only features you want! Everything is off by default
|
||||
* Block creeper and wither block damage, falling damage, etc.;
|
||||
* Disable fire spread, lava fire spread, ice formation, Endermen picking up blocks, etc.;
|
||||
* Blacklist certain items and blocks so they can't be used;
|
||||
* Warn moderators when certain items and blocks are used;
|
||||
* Protect areas of your world so only certain people can build in them;
|
||||
* Set areas where PVP, TNT, mob damage, and other features are disabled;
|
||||
* Protect your server from various 'exploits' like magical obsidian creation machines;
|
||||
* Disable, or enable, various Minecraft features, like sponges from classic;
|
||||
* Add useful commands like an immediate "STOP ALL FIRE SPREAD" command.
|
||||
* Enable only features you want! Everything is off by default.
|
||||
|
||||
WorldGuard is open source and is available under the GNU Lesser
|
||||
General Public License v3.
|
||||
|
||||
A Bukkit server implementation (such as [Paper](https://papermc.io)) and the [WorldEdit plugin](https://dev.bukkit.org/projects/worldedit) are required to use WorldGuard. You can get a release copy of WorldGuard from the [BukkitDev site](https://dev.bukkit.org/projects/worldguard).
|
||||
Currently, Bukkit is required to use WorldGuard. You can get a release copy of WorldGuard from the [BukkitDev site](http://dev.bukkit.org/bukkit-plugins/worldguard/).
|
||||
|
||||
Compiling
|
||||
---------
|
||||
@@ -42,6 +40,7 @@ Links
|
||||
|
||||
* [Homepage](http://enginehub.org/worldguard)
|
||||
* [Discord](https://discord.gg/enginehub)
|
||||
* [Issue tracker](https://github.com/EngineHub/WorldGuard/issues)
|
||||
* [IRC channel](https://webchat.esper.net/?join=sk89q) (#sk89q on irc.esper.net)
|
||||
* [Issue tracker](https://dev.enginehub.org/issues/WORLDGUARD)
|
||||
* [Continuous integration](http://builds.enginehub.org) [](http://ci.enginehub.org/viewType.html?buildTypeId=bt11&guest=1)
|
||||
* [End-user documentation](https://worldguard.enginehub.org/en/latest/)
|
||||
+1
-1
@@ -21,6 +21,6 @@ if (!project.hasProperty("gitCommitHash")) {
|
||||
} catch (e: Exception) {
|
||||
logger.warn("Error getting commit hash", e)
|
||||
|
||||
"no.git.id"
|
||||
"no_git_id"
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ fun Project.applyRootArtifactoryConfig() {
|
||||
}
|
||||
|
||||
fun Project.applyCommonArtifactoryConfig() {
|
||||
tasks.named<ArtifactoryTask>("artifactoryPublish") {
|
||||
val named = tasks.named<ArtifactoryTask>("artifactoryPublish") {
|
||||
publishConfigs("archives")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ fun Project.applyCommonConfiguration() {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://maven.enginehub.org/repo/") }
|
||||
maven { url = uri("https://maven.sk89q.com/repo/") }
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
|
||||
}
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
cacheChangingModulesFor(5, "MINUTES")
|
||||
cacheChangingModulesFor(5, "minutes")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
|
||||
apply(plugin = "com.jfrog.artifactory")
|
||||
apply(plugin = "net.minecrell.licenser")
|
||||
|
||||
ext["internalVersion"] = "$version+${rootProject.ext["gitCommitHash"]}"
|
||||
ext["internalVersion"] = "$version;${rootProject.ext["gitCommitHash"]}"
|
||||
|
||||
configure<JavaPluginConvention> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
object Versions {
|
||||
// const val PISTON = "0.4.3"
|
||||
// const val AUTO_VALUE = "1.6.5"
|
||||
const val WORLDEDIT = "7.2.0-SNAPSHOT"
|
||||
const val WORLDEDIT = "7.1.0-SNAPSHOT"
|
||||
const val JUNIT = "4.11"
|
||||
const val SQUIRRELID = "0.2.0"
|
||||
const val GUAVA = "21.0"
|
||||
}
|
||||
@@ -29,8 +29,6 @@
|
||||
<allow pkg="org.bstats.bukkit"/>
|
||||
<allow pkg="io.papermc.lib"/>
|
||||
<allow pkg="com.destroystokyo.paper"/>
|
||||
<allow pkg="co.aikar.timings.lib" />
|
||||
<allow pkg="org.spigotmc" />
|
||||
</subpackage>
|
||||
|
||||
</subpackage>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
group=com.sk89q.worldguard
|
||||
version=7.0.5
|
||||
version=7.0.2-SNAPSHOT
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,21 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
@@ -44,7 +28,7 @@ APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
Vendored
+1
-17
@@ -1,19 +1,3 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@@ -19,26 +19,16 @@ repositories {
|
||||
name = "bstats"
|
||||
url = uri("https://repo.codemc.org/repository/maven-public")
|
||||
}
|
||||
maven {
|
||||
name = "aikar-timings"
|
||||
url = uri("http://repo.aikar.co/nexus/content/groups/aikar/")
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
compileClasspath.extendsFrom(create("shade"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
"compile"(project(":worldguard-core"))
|
||||
//"compile"(project(":worldguard-libs:bukkit"))
|
||||
"api"("com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT")
|
||||
"shade"("io.papermc:paperlib:1.0.4")
|
||||
"api"("com.destroystokyo.paper:paper-api:1.15-R0.1-SNAPSHOT")
|
||||
"implementation"("io.papermc:paperlib:1.0.2")
|
||||
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
|
||||
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
|
||||
"implementation"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
||||
"shade"("org.bstats:bstats-bukkit:1.7")
|
||||
"shade"("co.aikar:minecraft-timings:1.0.4")
|
||||
"implementation"("org.bstats:bstats-bukkit:1.5")
|
||||
}
|
||||
|
||||
tasks.named<Upload>("install") {
|
||||
@@ -49,45 +39,36 @@ tasks.named<Upload>("install") {
|
||||
getProperty("groupId") == "com.destroystokyo.paper" && getProperty("artifactId") == "paper-api"
|
||||
}
|
||||
}?.withGroovyBuilder {
|
||||
setProperty("groupId", "org.spigotmc")
|
||||
setProperty("artifactId", "spigot-api")
|
||||
setProperty("groupId", "org.bukkit")
|
||||
setProperty("artifactId", "bukkit")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Copy>("processResources") {
|
||||
val internalVersion = project.ext["internalVersion"]
|
||||
inputs.property("internalVersion", internalVersion)
|
||||
filesMatching("plugin.yml") {
|
||||
expand("internalVersion" to internalVersion)
|
||||
expand("internalVersion" to project.ext["internalVersion"])
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
val projectVersion = project.version
|
||||
inputs.property("projectVersion", projectVersion)
|
||||
manifest {
|
||||
attributes("Implementation-Version" to projectVersion)
|
||||
attributes("Implementation-Version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
configurations = listOf(project.configurations["shade"], project.configurations["runtimeClasspath"])
|
||||
|
||||
dependencies {
|
||||
relocate("org.bstats", "com.sk89q.worldguard.bukkit.bstats") {
|
||||
include(dependency("org.bstats:bstats-bukkit"))
|
||||
include(dependency("org.bstats:bstats-bukkit:1.5"))
|
||||
}
|
||||
relocate ("io.papermc.lib", "com.sk89q.worldguard.bukkit.paperlib") {
|
||||
include(dependency("io.papermc:paperlib"))
|
||||
}
|
||||
relocate ("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") {
|
||||
include(dependency("co.aikar:minecraft-timings"))
|
||||
include(dependency("io.papermc:paperlib:1.0.2"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("assemble").configure {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
}
|
||||
-2
@@ -37,7 +37,6 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {
|
||||
|
||||
private boolean hasCommandBookGodMode;
|
||||
boolean extraStats;
|
||||
boolean timedSessionHandlers;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
@@ -57,7 +56,6 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {
|
||||
public void load() {
|
||||
super.load();
|
||||
this.extraStats = getConfig().getBoolean("custom-metrics-charts", true);
|
||||
this.timedSessionHandlers = getConfig().getBoolean("extra-timings.session-handlers", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.util.MessagingUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.BanList.Type;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -56,6 +55,16 @@ public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implem
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultNamespace() {
|
||||
// TODO: Add a per player override
|
||||
boolean useNamespaces = WorldGuard.getInstance().getPlatform().getGlobalStateManager().useNamespaces;
|
||||
if (useNamespaces) {
|
||||
return getUniqueId().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(String group) {
|
||||
return plugin.inGroup(getPlayer(), group);
|
||||
@@ -174,11 +183,7 @@ public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implem
|
||||
|
||||
@Override
|
||||
public void sendTitle(String title, String subtitle) {
|
||||
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(getWorld()).forceDefaultTitleTimes) {
|
||||
getPlayer().sendTitle(title, subtitle, 10, 70, 20);
|
||||
} else {
|
||||
getPlayer().sendTitle(title, subtitle, -1, -1, -1);
|
||||
}
|
||||
getPlayer().sendTitle(title, subtitle, -1, -1, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,10 +196,7 @@ public class BukkitPlayer extends com.sk89q.worldedit.bukkit.BukkitPlayer implem
|
||||
PaperLib.teleportAsync(getPlayer(), BukkitAdapter.adapt(location))
|
||||
.thenApply(success -> {
|
||||
if (success) {
|
||||
// The success message can be cleared via flag
|
||||
if (!successMessage.isEmpty()) {
|
||||
MessagingUtil.sendStringToChat(this, successMessage);
|
||||
}
|
||||
print(successMessage);
|
||||
} else {
|
||||
printError(failMessage);
|
||||
}
|
||||
|
||||
+3
-19
@@ -40,7 +40,7 @@ import com.sk89q.worldguard.chest.ChestProtection;
|
||||
import com.sk89q.worldguard.commands.CommandUtils;
|
||||
import com.sk89q.worldguard.config.YamlWorldConfiguration;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.parser.ParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -105,13 +105,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
|
||||
if (inputs == null || inputs.isEmpty()) {
|
||||
parentConfig.setProperty(node, new ArrayList<String>());
|
||||
}
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
inputs = config.getStringList(node, null);
|
||||
}
|
||||
|
||||
if (inputs == null || inputs.isEmpty()) {
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -135,7 +128,7 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
config.load();
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "Error reading configuration for world " + worldName + ": ", e);
|
||||
} catch (YAMLException e) {
|
||||
} catch (ParserException e) {
|
||||
log.severe("Error parsing configuration for world " + worldName + ". ");
|
||||
throw e;
|
||||
}
|
||||
@@ -151,7 +144,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
allowAllInteract = getTargetMatchers("event-handling.interaction-whitelist");
|
||||
blockUseAtFeet = getTargetMatchers("event-handling.emit-block-use-at-feet");
|
||||
ignoreHopperMoveEvents = getBoolean("event-handling.ignore-hopper-item-move-events", false);
|
||||
breakDeniedHoppers = getBoolean("event-handling.break-hoppers-on-denied-move", true);
|
||||
|
||||
usePaperEntityOrigin = getBoolean("regions.use-paper-entity-origin", false);
|
||||
|
||||
@@ -160,8 +152,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
|
||||
disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
|
||||
|
||||
useMaxPriorityAssociation = getBoolean("protection.use-max-priority-association", false);
|
||||
|
||||
blockPotions = new HashSet<>();
|
||||
for (String potionName : getStringList("gameplay.block-potions", null)) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(potionName);
|
||||
@@ -218,7 +208,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false);
|
||||
blockOtherExplosions = getBoolean("mobs.block-other-explosions", false);
|
||||
blockZombieDoorDestruction = getBoolean("mobs.block-zombie-door-destruction", false);
|
||||
blockEntityVehicleEntry = getBoolean("mobs.block-vehicle-entry", false);
|
||||
|
||||
disableFallDamage = getBoolean("player-damage.disable-fall-damage", false);
|
||||
disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false);
|
||||
@@ -241,9 +230,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false);
|
||||
disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false);
|
||||
|
||||
disableCreatureTurtleEggTrampling = getBoolean("turtle-egg.disable-creature-trampling", false);
|
||||
disablePlayerTurtleEggTrampling = getBoolean("turtle-egg.disable-player-trampling", false);
|
||||
|
||||
disallowedLightningBlocks = new HashSet<>(convertLegacyBlocks(getStringList("weather.prevent-lightning-strike-blocks", null)));
|
||||
preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false);
|
||||
disableThunder = getBoolean("weather.disable-thunderstorm", false);
|
||||
@@ -265,14 +251,12 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
||||
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
|
||||
disableCropGrowth = getBoolean("dynamics.disable-crop-growth", false);
|
||||
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
|
||||
disableCoralBlockFade = getBoolean("dynamics.disable-coral-block-fade", false);
|
||||
allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null)));
|
||||
|
||||
useRegions = getBoolean("regions.enable", true);
|
||||
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
|
||||
regionCancelEmptyChatEvents = getBoolean("regions.cancel-chat-without-recipients", true);
|
||||
regionNetherPortalProtection = getBoolean("regions.nether-portal-protection", true);
|
||||
forceDefaultTitleTimes = config.getBoolean("regions.titles-always-use-default-times", true); // note: technically not region-specific, but we only use it for the title flags
|
||||
regionNetherPortalProtection = getBoolean("regions.nether-portal-protection", false);
|
||||
fakePlayerBuildOverride = getBoolean("regions.fake-player-build-override", true);
|
||||
explosionFlagCancellation = getBoolean("regions.explosion-flags-block-entity-damage", true);
|
||||
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
|
||||
|
||||
+1
-2
@@ -67,7 +67,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
|
||||
|
||||
private BukkitSessionManager sessionManager;
|
||||
private SessionManager sessionManager;
|
||||
private BukkitConfigurationManager configuration;
|
||||
private BukkitRegionContainer regionContainer;
|
||||
private BukkitDebugHandler debugHandler;
|
||||
@@ -138,7 +138,6 @@ public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
|
||||
sessionManager = new BukkitSessionManager();
|
||||
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
|
||||
configuration.load();
|
||||
sessionManager.setUsingTimings(configuration.timedSessionHandlers);
|
||||
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
|
||||
regionContainer.initialize();
|
||||
debugHandler = new BukkitDebugHandler(WorldGuardPlugin.inst());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.sk89q.bukkit.util.CommandsManagerRegistration;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
@@ -92,8 +93,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
/**
|
||||
* The main class for WorldGuard as a Bukkit plugin.
|
||||
@@ -212,7 +214,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true);
|
||||
|
||||
// Enable metrics
|
||||
final Metrics metrics = new Metrics(this, 3283); // bStats plugin id
|
||||
final Metrics metrics = new Metrics(this);
|
||||
if (metrics.isEnabled() && platform.getGlobalStateManager().extraStats) {
|
||||
setupCustomCharts(metrics);
|
||||
}
|
||||
@@ -385,8 +387,6 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
Plugin worldEdit = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit == null) {
|
||||
throw new CommandException("WorldEdit does not appear to be installed.");
|
||||
} else if (!worldEdit.isEnabled()) {
|
||||
throw new CommandException("WorldEdit does not appear to be enabled.");
|
||||
}
|
||||
|
||||
if (worldEdit instanceof WorldEditPlugin) {
|
||||
@@ -488,25 +488,44 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream stream = getResource("defaults/" + defaultName)){
|
||||
if (stream == null) throw new FileNotFoundException();
|
||||
copyDefaultConfig(stream, actual, defaultName);
|
||||
InputStream input = null;
|
||||
try {
|
||||
JarFile file = new JarFile(getFile());
|
||||
ZipEntry copy = file.getEntry("defaults/" + defaultName);
|
||||
if (copy == null) throw new FileNotFoundException();
|
||||
input = file.getInputStream(copy);
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Unable to read default configuration: " + defaultName);
|
||||
WorldGuard.logger.severe("Unable to read default configuration: " + defaultName);
|
||||
}
|
||||
|
||||
}
|
||||
if (input != null) {
|
||||
FileOutputStream output = null;
|
||||
|
||||
private void copyDefaultConfig(InputStream input, File actual, String name) {
|
||||
try (FileOutputStream output = new FileOutputStream(actual)) {
|
||||
byte[] buf = new byte[8192];
|
||||
int length;
|
||||
while ((length = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, length);
|
||||
try {
|
||||
output = new FileOutputStream(actual);
|
||||
byte[] buf = new byte[8192];
|
||||
int length = 0;
|
||||
while ((length = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, length);
|
||||
}
|
||||
|
||||
WorldGuard.logger.info("Default configuration file written: "
|
||||
+ actual.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (output != null) {
|
||||
output.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
getLogger().info("Default configuration file written: " + name);
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.WARNING, "Failed to write default config file", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
@@ -90,15 +88,26 @@ public final class Cause {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether a cause is known. This method will return false if
|
||||
* the list of causes is empty or the root cause is really not known
|
||||
* (e.g. primed TNT).
|
||||
* Return whether a cause is known. This method will return true if
|
||||
* the list of causes is empty or the list of causes only contains
|
||||
* objects that really are not root causes (i.e primed TNT).
|
||||
*
|
||||
* @return true if known
|
||||
*/
|
||||
public boolean isKnown() {
|
||||
Object object = getRootCause();
|
||||
return !(object == null || object instanceof TNTPrimed || object instanceof Vehicle);
|
||||
if (causes.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
for (Object object : causes) {
|
||||
if (!(object instanceof TNTPrimed) && !(object instanceof Vehicle)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -227,15 +236,6 @@ public final class Cause {
|
||||
WGMetadata.put(target, CAUSE_KEY, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a parent cause from a {@code Metadatable} object.
|
||||
*
|
||||
* @param target the target
|
||||
*/
|
||||
public static void untrackParentCause(Metadatable target) {
|
||||
WGMetadata.remove(target, CAUSE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds causes.
|
||||
*/
|
||||
@@ -260,15 +260,13 @@ public final class Cause {
|
||||
if (o instanceof TNTPrimed) {
|
||||
addAll(((TNTPrimed) o).getSource());
|
||||
} else if (o instanceof Projectile) {
|
||||
ProjectileSource shooter = ((Projectile) o).getShooter();
|
||||
addAll(shooter);
|
||||
if (shooter == null && o instanceof Firework && PaperLib.isPaper()) {
|
||||
UUID spawningUUID = ((Firework) o).getSpawningEntity();
|
||||
if (spawningUUID != null) {
|
||||
Entity spawningEntity = Bukkit.getEntity(spawningUUID);
|
||||
if (spawningEntity != null) {
|
||||
addAll(spawningEntity);
|
||||
}
|
||||
addAll(((Projectile) o).getShooter());
|
||||
} else if (o instanceof Firework && PaperLib.isPaper()) {
|
||||
UUID spawningUUID = ((Firework) o).getSpawningEntity();
|
||||
if (spawningUUID != null) {
|
||||
Entity spawningEntity = Bukkit.getEntity(spawningUUID);
|
||||
if (spawningEntity != null) {
|
||||
addAll(spawningEntity);
|
||||
}
|
||||
}
|
||||
} else if (o instanceof Vehicle) {
|
||||
@@ -276,14 +274,12 @@ public final class Cause {
|
||||
} else if (o instanceof AreaEffectCloud) {
|
||||
indirect = true;
|
||||
addAll(((AreaEffectCloud) o).getSource());
|
||||
} else if (o instanceof Tameable) {
|
||||
indirect = true;
|
||||
addAll(((Tameable) o).getOwner());
|
||||
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
|
||||
indirect = true;
|
||||
addAll(((Creature) o).getTarget());
|
||||
} else if (o instanceof BlockProjectileSource) {
|
||||
addAll(((BlockProjectileSource) o).getBlock());
|
||||
} else if (o instanceof Tameable) {
|
||||
indirect = true;
|
||||
addAll(((Tameable) o).getOwner());
|
||||
}
|
||||
|
||||
// Add manually tracked parent causes
|
||||
|
||||
@@ -75,13 +75,4 @@ public final class WGMetadata {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes metadata from the target.
|
||||
*
|
||||
* @param target the target
|
||||
* @param key the key
|
||||
*/
|
||||
public static void remove(Metadatable target, String key) {
|
||||
target.removeMetadata(key, WorldGuardPlugin.inst());
|
||||
}
|
||||
}
|
||||
+5
-9
@@ -31,7 +31,7 @@ import com.sk89q.worldguard.bukkit.cause.Cause;
|
||||
import com.sk89q.worldguard.config.ConfigurationManager;
|
||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation;
|
||||
import com.sk89q.worldguard.protection.DelayedRegionOverlapAssociation;
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
@@ -127,10 +127,9 @@ class AbstractListener implements Listener {
|
||||
} else if (rootCause instanceof Entity) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
final Entity entity = (Entity) rootCause;
|
||||
BukkitWorldConfiguration config =
|
||||
(BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(entity.getWorld()));
|
||||
Location loc;
|
||||
if (PaperLib.isPaper() && config.usePaperEntityOrigin) {
|
||||
if (PaperLib.isPaper()
|
||||
&& ((BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(entity.getWorld()))).usePaperEntityOrigin) {
|
||||
loc = entity.getOrigin();
|
||||
if (loc == null) {
|
||||
loc = entity.getLocation();
|
||||
@@ -138,13 +137,10 @@ class AbstractListener implements Listener {
|
||||
} else {
|
||||
loc = entity.getLocation();
|
||||
}
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
|
||||
config.useMaxPriorityAssociation);
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc));
|
||||
} else if (rootCause instanceof Block) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
Location loc = ((Block) rootCause).getLocation();
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
|
||||
getWorldConfig(BukkitAdapter.adapt(loc.getWorld())).useMaxPriorityAssociation);
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(((Block) rootCause).getLocation()));
|
||||
} else {
|
||||
return Associables.constant(Association.NON_MEMBER);
|
||||
}
|
||||
|
||||
-5
@@ -49,7 +49,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockDispenseArmorEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
@@ -59,7 +58,6 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget;
|
||||
|
||||
@@ -332,9 +330,6 @@ public class BlacklistListener extends AbstractListener {
|
||||
return cursor;
|
||||
}
|
||||
case HOTBAR_SWAP:
|
||||
if (event.getClick() == ClickType.SWAP_OFFHAND) {
|
||||
return clickedInventory == null ? null : ((PlayerInventory) clickedInventory).getItemInOffHand();
|
||||
}
|
||||
return clickedInventory == null ? null : clickedInventory.getItem(event.getHotbarButton());
|
||||
default:
|
||||
break;
|
||||
|
||||
+54
-151
@@ -61,7 +61,6 @@ import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Dispenser;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
@@ -73,10 +72,8 @@ import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.entity.minecart.HopperMinecart;
|
||||
import org.bukkit.event.Cancellable;
|
||||
@@ -97,7 +94,6 @@ import org.bukkit.event.block.BlockMultiPlaceEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.CauldronLevelChangeEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||
@@ -139,7 +135,6 @@ import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
@@ -159,17 +154,6 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
private final EventDebounce<BlockPistonRetractKey> pistonRetractDebounce = EventDebounce.create(5000);
|
||||
private final EventDebounce<BlockPistonExtendKey> pistonExtendDebounce = EventDebounce.create(5000);
|
||||
|
||||
private static final boolean HAS_SNAPSHOT_INVHOLDER;
|
||||
static {
|
||||
boolean temp;
|
||||
try {
|
||||
Inventory.class.getMethod("getHolder", boolean.class);
|
||||
temp = true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
temp = false;
|
||||
}
|
||||
HAS_SNAPSHOT_INVHOLDER = temp;
|
||||
}
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
@@ -244,7 +228,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
boolean allowed = false;
|
||||
|
||||
for (Block source : adjacent) {
|
||||
if (Materials.isFire(source.getType())) {
|
||||
if (source.getType() == Material.FIRE) {
|
||||
found++;
|
||||
if (Events.fireAndTestCancel(new BreakBlockEvent(event, create(source), target))) {
|
||||
source.setType(Material.AIR);
|
||||
@@ -273,30 +257,6 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFallingBlock(EntityChangeBlockEvent event, boolean dropItem) {
|
||||
Entity entity = event.getEntity();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (entity instanceof FallingBlock) {
|
||||
try {
|
||||
if (dropItem) {
|
||||
FallingBlock fallingBlock = (FallingBlock) entity;
|
||||
if (!fallingBlock.getDropItem()) return;
|
||||
final Material material = fallingBlock.getBlockData().getMaterial();
|
||||
if (!material.isItem()) return;
|
||||
ItemStack itemStack = new ItemStack(material, 1);
|
||||
Item item = block.getWorld().dropItem(fallingBlock.getLocation(), itemStack);
|
||||
item.setVelocity(new Vector());
|
||||
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(block, entity), item))) {
|
||||
item.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Cause.untrackParentCause(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
Block block = event.getBlock();
|
||||
@@ -310,52 +270,51 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
boolean trample = fromType == Material.FARMLAND && toType == Material.DIRT;
|
||||
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block);
|
||||
if (trample) {
|
||||
breakDelagate.setSilent(true);
|
||||
breakDelagate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
} else if (fromType == Material.REDSTONE_ORE) {
|
||||
breakDelagate.setSilent(true);
|
||||
}
|
||||
boolean denied;
|
||||
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
|
||||
if (!Events.fireToCancel(event, breakDelagate)) {
|
||||
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType);
|
||||
if (trample) {
|
||||
placeDelegate.setSilent(true);
|
||||
placeDelegate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
} else if (fromType == Material.REDSTONE_ORE) {
|
||||
placeDelegate.setSilent(true);
|
||||
}
|
||||
denied = Events.fireToCancel(event, placeDelegate);
|
||||
}
|
||||
if (denied && entity instanceof Player) {
|
||||
playDenyEffect((Player) entity, block.getLocation());
|
||||
Events.fireToCancel(event, placeDelegate);
|
||||
}
|
||||
} else {
|
||||
if (toType == Material.AIR) {
|
||||
// Track the source so later we can create a proper chain of causes
|
||||
if (entity instanceof FallingBlock) {
|
||||
Cause.trackParentCause(entity, block);
|
||||
|
||||
handleFallingBlock(event, denied);
|
||||
} else if (toType == Material.AIR) {
|
||||
// Track the source so later we can create a proper chain of causes
|
||||
if (entity instanceof FallingBlock) {
|
||||
Cause.trackParentCause(entity, block);
|
||||
|
||||
// Switch around the event
|
||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
|
||||
// Switch around the event
|
||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
|
||||
} else {
|
||||
entityBreakBlockDebounce.debounce(
|
||||
block, event.getEntity(), event, new BreakBlockEvent(event, cause, block));
|
||||
}
|
||||
} else {
|
||||
entityBreakBlockDebounce.debounce(
|
||||
block, event.getEntity(), event, new BreakBlockEvent(event, cause, block));
|
||||
}
|
||||
} else { // toType != Material.AIR && fromType == Material.AIR
|
||||
boolean denied = Events.fireToCancel(event, new PlaceBlockEvent(event, cause, block.getLocation(), toType));
|
||||
handleFallingBlock(event, denied);
|
||||
}
|
||||
boolean wasCancelled = event.isCancelled();
|
||||
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, block.getLocation(), toType));
|
||||
|
||||
if (event.isCancelled() && !wasCancelled && entity instanceof FallingBlock) {
|
||||
FallingBlock fallingBlock = (FallingBlock) entity;
|
||||
final Material material = fallingBlock.getBlockData().getMaterial();
|
||||
if (!material.isItem()) return;
|
||||
ItemStack itemStack = new ItemStack(material, 1);
|
||||
Item item = block.getWorld().dropItem(fallingBlock.getLocation(), itemStack);
|
||||
item.setVelocity(new Vector());
|
||||
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(block, entity), item))) {
|
||||
item.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));
|
||||
if (entity instanceof Creeper) {
|
||||
Cause.untrackParentCause(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@@ -373,7 +332,6 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
|
||||
if (originalSize != blocks.size()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (Block b : blocks) {
|
||||
Location loc = b.getRelative(direction).getLocation();
|
||||
@@ -393,14 +351,8 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event);
|
||||
if (entry != null) {
|
||||
Cause cause = create(event.getBlock());
|
||||
List<Block> blocks = new ArrayList<>(event.getBlocks());
|
||||
int originalLength = blocks.size();
|
||||
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
|
||||
if (originalLength != blocks.size()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
BlockFace dir = event.getDirection();
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
Block existing = blocks.get(i);
|
||||
@@ -410,7 +362,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
blocks.set(i, existing.getRelative(dir));
|
||||
}
|
||||
}
|
||||
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.STONE));
|
||||
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, create(event.getBlock()), event.getBlock().getWorld(), blocks, Material.STONE));
|
||||
if (blocks.size() != originalLength) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -443,37 +395,23 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
@Nullable ItemStack item = event.getItem();
|
||||
Block clicked = event.getClickedBlock();
|
||||
Block placed;
|
||||
boolean silent = false;
|
||||
boolean modifiesWorld;
|
||||
Cause cause = create(player);
|
||||
|
||||
switch (event.getAction()) {
|
||||
case PHYSICAL:
|
||||
if (event.useInteractedBlock() != Result.DENY) {
|
||||
if (clicked.getType() == Material.FARMLAND || clicked.getType() == Material.TURTLE_EGG) {
|
||||
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, clicked);
|
||||
breakDelagate.setSilent(true);
|
||||
breakDelagate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
boolean denied;
|
||||
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
|
||||
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, clicked.getLocation(),
|
||||
clicked.getType() == Material.FARMLAND ? Material.DIRT : clicked.getType());
|
||||
placeDelegate.setSilent(true);
|
||||
placeDelegate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
denied = Events.fireToCancel(event, placeDelegate);
|
||||
}
|
||||
if (denied) {
|
||||
playDenyEffect(player, clicked.getLocation());
|
||||
}
|
||||
return;
|
||||
}
|
||||
DelegateEvent firedEvent = new UseBlockEvent(event, cause, clicked).setAllowed(hasInteractBypass(clicked));
|
||||
if (clicked.getType() == Material.REDSTONE_ORE) {
|
||||
firedEvent.setSilent(true);
|
||||
silent = true;
|
||||
}
|
||||
if (clicked.getType() == Material.FARMLAND || clicked.getType() == Material.TURTLE_EGG) {
|
||||
silent = true;
|
||||
firedEvent.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
}
|
||||
firedEvent.setSilent(silent);
|
||||
interactDebounce.debounce(clicked, event.getPlayer(), event, firedEvent);
|
||||
if (event.useInteractedBlock() == Result.DENY) {
|
||||
playDenyEffect(player, clicked.getLocation().add(0, 1, 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -515,7 +453,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
}
|
||||
|
||||
// Special handling of putting out fires
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK && Materials.isFire(placed.getType())) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK && placed.getType() == Material.FIRE) {
|
||||
if (Events.fireAndTestCancel(new BreakBlockEvent(event, create(event.getPlayer()), placed))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
break;
|
||||
@@ -565,7 +503,6 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockFertilize(BlockFertilizeEvent event) {
|
||||
if (event.getBlocks().isEmpty()) return;
|
||||
Cause cause = create(event.getPlayer(), event.getBlock());
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getWorld(), event.getBlocks()));
|
||||
}
|
||||
@@ -767,7 +704,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getState() == PlayerFishEvent.State.CAUGHT_FISH) {
|
||||
if (event.getExpToDrop() > 0 && Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getPlayer(), event.getHook()), event.getHook().getLocation(), EntityType.EXPERIENCE_ORB))) {
|
||||
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getPlayer(), event.getHook()), event.getHook().getLocation(), EntityType.EXPERIENCE_ORB))) {
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
} else if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) {
|
||||
@@ -856,11 +793,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
} else if (damager instanceof Creeper) {
|
||||
eventToFire.getRelevantFlags().add(Flags.CREEPER_EXPLOSION);
|
||||
}
|
||||
if (Events.fireToCancel(event, eventToFire)) {
|
||||
if (damager instanceof Tameable && damager instanceof Mob) {
|
||||
((Mob) damager).setTarget(null);
|
||||
}
|
||||
}
|
||||
Events.fireToCancel(event, eventToFire);
|
||||
|
||||
// Item use event with the item in hand
|
||||
// Older blacklist handler code used this, although it suffers from
|
||||
@@ -941,35 +874,21 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryMoveItem(InventoryMoveItemEvent event) {
|
||||
InventoryHolder causeHolder;
|
||||
if (HAS_SNAPSHOT_INVHOLDER) {
|
||||
causeHolder = event.getInitiator().getHolder(false);
|
||||
} else {
|
||||
causeHolder = event.getInitiator().getHolder();
|
||||
}
|
||||
final InventoryHolder causeHolder = event.getInitiator().getHolder();
|
||||
|
||||
WorldConfiguration wcfg = null;
|
||||
if (causeHolder instanceof Hopper
|
||||
&& (wcfg = getWorldConfig(BukkitAdapter.adapt((((Hopper) causeHolder).getWorld())))).ignoreHopperMoveEvents) {
|
||||
&& getWorldConfig(BukkitAdapter.adapt((((Hopper) causeHolder).getWorld()))).ignoreHopperMoveEvents) {
|
||||
return;
|
||||
} else if (causeHolder instanceof HopperMinecart
|
||||
&& (wcfg = getWorldConfig(BukkitAdapter.adapt((((HopperMinecart) causeHolder).getWorld())))).ignoreHopperMoveEvents) {
|
||||
&& getWorldConfig(BukkitAdapter.adapt((((HopperMinecart) causeHolder).getWorld()))).ignoreHopperMoveEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entry entry;
|
||||
|
||||
if ((entry = moveItemDebounce.tryDebounce(event)) != null) {
|
||||
InventoryHolder sourceHolder;
|
||||
InventoryHolder targetHolder;
|
||||
if (HAS_SNAPSHOT_INVHOLDER) {
|
||||
sourceHolder = event.getSource().getHolder(false);
|
||||
targetHolder = event.getDestination().getHolder(false);
|
||||
} else {
|
||||
sourceHolder = event.getSource().getHolder();
|
||||
targetHolder = event.getDestination().getHolder();
|
||||
}
|
||||
|
||||
InventoryHolder sourceHolder = event.getSource().getHolder();
|
||||
InventoryHolder targetHolder = event.getDestination().getHolder();
|
||||
Cause cause;
|
||||
|
||||
if (causeHolder instanceof Entity) {
|
||||
@@ -986,7 +905,7 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
|
||||
handleInventoryHolderUse(event, cause, targetHolder);
|
||||
|
||||
if (event.isCancelled() && causeHolder instanceof Hopper && wcfg.breakDeniedHoppers) {
|
||||
if (event.isCancelled() && causeHolder instanceof Hopper) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(),
|
||||
() -> ((Hopper) causeHolder).getBlock().breakNaturally());
|
||||
} else {
|
||||
@@ -1033,27 +952,18 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
Cause cause = create(event.getBlock());
|
||||
Block dispenserBlock = event.getBlock();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
Events.fireToCancel(event, new UseItemEvent(event, cause, dispenserBlock.getWorld(), item));
|
||||
|
||||
// Simulate right click event as players have it
|
||||
if (dispenserBlock.getType() == Material.DISPENSER) {
|
||||
Cause cause = create(event.getBlock());
|
||||
ItemStack item = event.getItem();
|
||||
if (Events.fireToCancel(event, new UseItemEvent(event, cause, dispenserBlock.getWorld(), item))) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockData blockData = dispenserBlock.getBlockData();
|
||||
Dispenser dispenser = (Dispenser) blockData; // if this ClassCastExceptions it's a bukkit bug
|
||||
if (dispenserBlock.getBlockData() instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) dispenserBlock.getBlockData();
|
||||
Block placed = dispenserBlock.getRelative(dispenser.getFacing());
|
||||
Block clicked = placed.getRelative(dispenser.getFacing());
|
||||
handleBlockRightClick(event, cause, item, clicked, placed);
|
||||
|
||||
// handle special dispenser behavior
|
||||
if (item != null && Materials.isShulkerBox(item.getType())) {
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), item.getType()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,17 +1010,10 @@ public class EventAbstractionListener extends AbstractListener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onTakeLecternBook(PlayerTakeLecternBookEvent event) {
|
||||
final UseBlockEvent useEvent = new UseBlockEvent(event, create(event.getPlayer()), event.getLectern().getBlock());
|
||||
useEvent.getRelevantFlags().add(Flags.CHEST_ACCESS);
|
||||
Events.fireToCancel(event, useEvent);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCauldronLevelChange(CauldronLevelChangeEvent event) {
|
||||
if (event.getEntity() == null) return;
|
||||
interactDebounce.debounce(event.getBlock(), event.getEntity(), event,
|
||||
new UseBlockEvent(event, create(event.getEntity()),
|
||||
event.getBlock()).setAllowed(hasInteractBypass(event.getBlock())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the right click of a block while an item is held.
|
||||
*
|
||||
|
||||
+3
-43
@@ -25,7 +25,6 @@ import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -36,12 +35,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
|
||||
public class PlayerMoveListener implements Listener {
|
||||
|
||||
@@ -55,9 +52,6 @@ public class PlayerMoveListener implements Listener {
|
||||
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().usePlayerMove) {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvents(this, plugin);
|
||||
if (PaperLib.isSpigot()) {
|
||||
pm.registerEvents(new EntityMountListener(), plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,14 +77,6 @@ public class PlayerMoveListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
if (from.getBlockX() == to.getBlockX()
|
||||
&& from.getBlockY() == to.getBlockY()
|
||||
&& from.getBlockZ() == to.getBlockZ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
@@ -103,15 +89,15 @@ public class PlayerMoveListener implements Listener {
|
||||
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Horse) {
|
||||
moveType = MoveType.RIDE;
|
||||
}
|
||||
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
|
||||
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), moveType);
|
||||
|
||||
if (weLocation != null) {
|
||||
final Location override = BukkitAdapter.adapt(weLocation);
|
||||
override.setX(override.getBlockX() + 0.5);
|
||||
override.setY(override.getBlockY());
|
||||
override.setZ(override.getBlockZ() + 0.5);
|
||||
override.setPitch(to.getPitch());
|
||||
override.setYaw(to.getYaw());
|
||||
override.setPitch(event.getTo().getPitch());
|
||||
override.setYaw(event.getTo().getYaw());
|
||||
|
||||
event.setTo(override.clone());
|
||||
|
||||
@@ -138,30 +124,4 @@ public class PlayerMoveListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer);
|
||||
com.sk89q.worldedit.util.Location loc = session.testMoveTo(localPlayer,
|
||||
BukkitAdapter.adapt(event.getPlayer().getLocation()), MoveType.OTHER_CANCELLABLE); // white lie
|
||||
if (loc != null) {
|
||||
player.teleport(BukkitAdapter.adapt(loc));
|
||||
}
|
||||
}
|
||||
|
||||
private class EntityMountListener implements Listener {
|
||||
@EventHandler
|
||||
public void onEntityMount(EntityMountEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
LocalPlayer player = plugin.wrapPlayer((Player) entity);
|
||||
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
|
||||
if (null != session.testMoveTo(player, BukkitAdapter.adapt(event.getMount().getLocation()), MoveType.EMBARK, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-31
@@ -41,6 +41,7 @@ import com.sk89q.worldguard.bukkit.util.InteropUtils;
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.commands.CommandUtils;
|
||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
@@ -58,10 +59,8 @@ import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -172,9 +171,9 @@ public class RegionProtectionListener extends AbstractListener {
|
||||
String what;
|
||||
|
||||
/* Flint and steel, fire charge, etc. */
|
||||
if (Materials.isFire(type)) {
|
||||
if (type == Material.FIRE) {
|
||||
Block block = event.getCause().getFirstBlock();
|
||||
boolean fire = block != null && Materials.isFire(type);
|
||||
boolean fire = block != null && block.getType() == Material.FIRE;
|
||||
boolean lava = block != null && Materials.isLava(block.getType());
|
||||
List<StateFlag> flags = new ArrayList<>();
|
||||
flags.add(Flags.BLOCK_PLACE);
|
||||
@@ -260,29 +259,14 @@ public class RegionProtectionListener extends AbstractListener {
|
||||
|
||||
/* Inventory */
|
||||
} else if (Materials.isInventoryBlock(type)) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS));
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.CHEST_ACCESS));
|
||||
what = "open that";
|
||||
|
||||
/* Inventory for blocks with the possibility to be only use, e.g. lectern */
|
||||
} else if (handleAsInventoryUsage(event.getOriginalEvent())) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS));
|
||||
what = "take that";
|
||||
|
||||
/* Anvils */
|
||||
} else if (Materials.isAnvil(type)) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.USE_ANVIL));
|
||||
what = "use that";
|
||||
|
||||
/* Beds */
|
||||
} else if (Materials.isBed(type)) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.SLEEP));
|
||||
what = "sleep";
|
||||
|
||||
/* Respawn Anchors */
|
||||
} else if(type == Material.RESPAWN_ANCHOR) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.RESPAWN_ANCHORS));
|
||||
what = "use anchors";
|
||||
|
||||
/* TNT */
|
||||
} else if (type == Material.TNT) {
|
||||
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.TNT));
|
||||
@@ -345,7 +329,12 @@ public class RegionProtectionListener extends AbstractListener {
|
||||
/* Everything else */
|
||||
} else {
|
||||
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
|
||||
what = "place things";
|
||||
|
||||
if (event.getEntity() instanceof Item) {
|
||||
what = "drop items";
|
||||
} else {
|
||||
what = "place things";
|
||||
}
|
||||
}
|
||||
|
||||
if (!canSpawn) {
|
||||
@@ -564,14 +553,4 @@ public class RegionProtectionListener extends AbstractListener {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if that event should be handled as inventory usage, e.g. if a player takes a book from a lectern
|
||||
*
|
||||
* @param event the event to handle
|
||||
* @return whether it should be handled as inventory usage
|
||||
*/
|
||||
private static boolean handleAsInventoryUsage(Event event) {
|
||||
return event instanceof PlayerTakeLecternBookEvent;
|
||||
}
|
||||
|
||||
}
|
||||
+26
-40
@@ -31,14 +31,11 @@ import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.util.SpongeUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -134,10 +131,9 @@ public class WorldGuardBlockListener implements Listener {
|
||||
Block blockFrom = event.getBlock();
|
||||
Block blockTo = event.getToBlock();
|
||||
|
||||
Material fromType = blockFrom.getType();
|
||||
boolean isWater = Materials.isWater(fromType);
|
||||
boolean isLava = fromType == Material.LAVA;
|
||||
boolean isAir = fromType == Material.AIR;
|
||||
boolean isWater = blockFrom.getType() == Material.WATER;
|
||||
boolean isLava = blockFrom.getType() == Material.LAVA;
|
||||
boolean isAir = blockFrom.getType() == Material.AIR;
|
||||
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
@@ -198,7 +194,7 @@ public class WorldGuardBlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && (isWater || blockFrom.getBlockData() instanceof Waterlogged)
|
||||
if (wcfg.highFreqFlags && isWater
|
||||
&& WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(blockFrom.getLocation()), (RegionAssociable) null, Flags.WATER_FLOW) == StateFlag.State.DENY) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -209,6 +205,13 @@ public class WorldGuardBlockListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.disableObsidianGenerators && (isAir || isLava)
|
||||
&& (blockTo.getType() == Material.REDSTONE_WIRE
|
||||
|| blockTo.getType() == Material.TRIPWIRE)) {
|
||||
blockTo.setType(Material.AIR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -323,7 +326,7 @@ public class WorldGuardBlockListener implements Listener {
|
||||
if (wcfg.fireSpreadDisableToggle) {
|
||||
Block block = event.getBlock();
|
||||
event.setCancelled(true);
|
||||
checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), Material.FIRE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -332,7 +335,7 @@ public class WorldGuardBlockListener implements Listener {
|
||||
|
||||
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
|
||||
event.setCancelled(true);
|
||||
checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), Material.FIRE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -351,24 +354,24 @@ public class WorldGuardBlockListener implements Listener {
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
|
||||
|
||||
if (!set.testState(null, Flags.FIRE_SPREAD)) {
|
||||
checkAndDestroyFireAround(block.getWorld(), x, y, z);
|
||||
checkAndDestroyAround(block.getWorld(), x, y, z, Material.FIRE);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndDestroyFireAround(World world, int x, int y, int z) {
|
||||
checkAndDestroyFire(world, x, y, z + 1);
|
||||
checkAndDestroyFire(world, x, y, z - 1);
|
||||
checkAndDestroyFire(world, x, y + 1, z);
|
||||
checkAndDestroyFire(world, x, y - 1, z);
|
||||
checkAndDestroyFire(world, x + 1, y, z);
|
||||
checkAndDestroyFire(world, x - 1, y, z);
|
||||
private void checkAndDestroyAround(World world, int x, int y, int z, Material required) {
|
||||
checkAndDestroy(world, x, y, z + 1, required);
|
||||
checkAndDestroy(world, x, y, z - 1, required);
|
||||
checkAndDestroy(world, x, y + 1, z, required);
|
||||
checkAndDestroy(world, x, y - 1, z, required);
|
||||
checkAndDestroy(world, x + 1, y, z, required);
|
||||
checkAndDestroy(world, x - 1, y, z, required);
|
||||
}
|
||||
|
||||
private void checkAndDestroyFire(World world, int x, int y, int z) {
|
||||
if (Materials.isFire(world.getBlockAt(x, y, z).getType())) {
|
||||
private void checkAndDestroy(World world, int x, int y, int z, Material required) {
|
||||
if (world.getBlockAt(x, y, z).getType() == required) {
|
||||
world.getBlockAt(x, y, z).setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -600,7 +603,7 @@ public class WorldGuardBlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (Materials.isVine(newType)) {
|
||||
if (newType == Material.VINE || newType == Material.KELP) {
|
||||
if (wcfg.disableVineGrowth) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -612,20 +615,13 @@ public class WorldGuardBlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handleGrow(event, event.getBlock().getLocation(), newType);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockGrow(BlockGrowEvent event) {
|
||||
Location loc = event.getBlock().getLocation();
|
||||
WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
final Material type = event.getNewState().getType();
|
||||
|
||||
handleGrow(event, loc, type);
|
||||
}
|
||||
|
||||
private void handleGrow(Cancellable event, Location loc, Material type) {
|
||||
WorldConfiguration wcfg = getWorldConfig(loc.getWorld());
|
||||
if (Materials.isCrop(type)) {
|
||||
if (wcfg.disableCropGrowth) {
|
||||
event.setCancelled(false);
|
||||
@@ -633,7 +629,7 @@ public class WorldGuardBlockListener implements Listener {
|
||||
}
|
||||
|
||||
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||
.queryState(BukkitAdapter.adapt(loc), (RegionAssociable) null, Flags.CROP_GROWTH))) {
|
||||
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.CROP_GROWTH))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -686,16 +682,6 @@ public class WorldGuardBlockListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (Materials.isCoral(event.getBlock().getType())) {
|
||||
if (wcfg.disableCoralBlockFade) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.CORAL_FADE))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-64
@@ -47,9 +47,7 @@ import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -76,13 +74,10 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.EntityTransformEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PigZapEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
@@ -122,13 +117,11 @@ public class WorldGuardEntityListener implements Listener {
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
|
||||
|
||||
if (block.getType() == Material.FARMLAND && wcfg.disableCreatureCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (block.getType() == Material.TURTLE_EGG && wcfg.disableCreatureTurtleEggTrampling) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
if (block.getType() == Material.FARMLAND) {
|
||||
if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */
|
||||
wcfg.disableCreatureCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,10 +748,6 @@ public class WorldGuardEntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
RegainReason regainReason = event.getRegainReason();
|
||||
if (regainReason != RegainReason.REGEN && regainReason != RegainReason.SATIATED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity ent = event.getEntity();
|
||||
World world = ent.getWorld();
|
||||
@@ -770,31 +759,6 @@ public class WorldGuardEntityListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions && ent instanceof Player
|
||||
&& !WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testState(
|
||||
BukkitAdapter.adapt(ent.getLocation()),
|
||||
WorldGuardPlugin.inst().wrapPlayer((Player) ent),
|
||||
Flags.HEALTH_REGEN)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onFoodChange(FoodLevelChangeEvent event) {
|
||||
if (event.getItem() != null) return;
|
||||
HumanEntity ent = event.getEntity();
|
||||
if (!(ent instanceof Player)) return;
|
||||
LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer((Player) ent);
|
||||
if (event.getFoodLevel() > player.getFoodLevel()) return;
|
||||
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (wcfg.useRegions
|
||||
&& !WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testState(
|
||||
player.getLocation(), player, Flags.HUNGER_DRAIN)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -810,19 +774,7 @@ public class WorldGuardEntityListener implements Listener {
|
||||
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(ent.getWorld()));
|
||||
if (ent instanceof FallingBlock) {
|
||||
Material id = event.getBlock().getType();
|
||||
|
||||
if (id == Material.GRAVEL && wcfg.noPhysicsGravel) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == Material.SAND && wcfg.noPhysicsSand) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (ent instanceof Enderman) {
|
||||
if (ent instanceof Enderman) {
|
||||
if (wcfg.disableEndermanGriefing) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -846,16 +798,6 @@ public class WorldGuardEntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntered().getWorld()));
|
||||
|
||||
if (wcfg.blockEntityVehicleEntry && !(event.getEntered() instanceof Player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks regions and config settings to protect items from being knocked
|
||||
* out of item frames.
|
||||
|
||||
+5
-13
@@ -38,7 +38,6 @@ import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.GameModeFlag;
|
||||
import com.sk89q.worldguard.util.Entities;
|
||||
import com.sk89q.worldguard.util.command.CommandFilter;
|
||||
import com.sk89q.worldguard.util.profile.Profile;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -148,8 +147,6 @@ public class WorldGuardPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
Events.fire(new ProcessPlayerEvent(player));
|
||||
WorldGuard.getInstance().getExecutorService().submit(() ->
|
||||
WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@@ -202,8 +199,7 @@ public class WorldGuardPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
if (!hostname.equals(hostKey)
|
||||
&& !(cfg.hostKeysAllowFMLClients &&
|
||||
(hostname.equals(hostKey + "\u0000FML\u0000") || hostname.equals(hostKey + "\u0000FML2\u0000")))) {
|
||||
&& !(cfg.hostKeysAllowFMLClients && hostname.equals(hostKey + "\u0000FML\u0000"))) {
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||
"You did not join with the valid host key!");
|
||||
log.warning("WorldGuard host key check: " +
|
||||
@@ -314,17 +310,13 @@ public class WorldGuardPlayerListener implements Listener {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock(); //not actually clicked but whatever
|
||||
Material type = block.getType();
|
||||
//int type = block.getTypeId();
|
||||
World world = player.getWorld();
|
||||
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
|
||||
|
||||
if (type == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (type == Material.TURTLE_EGG && wcfg.disablePlayerTurtleEggTrampling) {
|
||||
if (block.getType() == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -393,7 +385,7 @@ public class WorldGuardPlayerListener implements Listener {
|
||||
message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
|
||||
}
|
||||
if (cancel) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
if (message != null) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@@ -412,7 +404,7 @@ public class WorldGuardPlayerListener implements Listener {
|
||||
message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
|
||||
}
|
||||
if (cancel) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
if (message != null) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
+4
-17
@@ -27,7 +27,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent;
|
||||
import com.sk89q.worldguard.session.AbstractSessionManager;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.Handler;
|
||||
import com.sk89q.worldguard.util.profile.Profile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -41,13 +41,6 @@ import java.util.Collection;
|
||||
*/
|
||||
public class BukkitSessionManager extends AbstractSessionManager implements Runnable, Listener {
|
||||
|
||||
private boolean useTimings;
|
||||
|
||||
@Override
|
||||
protected Handler.Factory<? extends Handler> wrapForRegistration(Handler.Factory<? extends Handler> factory) {
|
||||
return useTimings ? new TimedHandlerFactory(factory) : factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-initialize handlers and clear "last position," "last state," etc.
|
||||
* information for all players.
|
||||
@@ -69,6 +62,8 @@ public class BukkitSessionManager extends AbstractSessionManager implements Runn
|
||||
// Pre-load a session
|
||||
LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(event.getPlayer());
|
||||
get(player).initialize(player);
|
||||
WorldGuard.getInstance().getExecutorService().submit(() ->
|
||||
WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,17 +78,9 @@ public class BukkitSessionManager extends AbstractSessionManager implements Runn
|
||||
public boolean hasBypass(LocalPlayer player, World world) {
|
||||
if (player instanceof BukkitPlayer) {
|
||||
if (((BukkitPlayer) player).getPlayer().hasMetadata("NPC")
|
||||
&& WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).fakePlayerBuildOverride)
|
||||
&& WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).fakePlayerBuildOverride)
|
||||
return true;
|
||||
}
|
||||
return super.hasBypass(player, world);
|
||||
}
|
||||
|
||||
public boolean isUsingTimings() {
|
||||
return useTimings;
|
||||
}
|
||||
|
||||
public void setUsingTimings(boolean useTimings) {
|
||||
this.useTimings = useTimings;
|
||||
}
|
||||
}
|
||||
-132
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.session;
|
||||
|
||||
import co.aikar.timings.lib.MCTiming;
|
||||
import co.aikar.timings.lib.TimingManager;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.Handler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.security.CodeSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
class TimedHandlerFactory extends Handler.Factory<Handler> {
|
||||
|
||||
private static final TimingManager TIMINGS = TimingManager.of(WorldGuardPlugin.inst());
|
||||
private static final MCTiming UNKNOWN_SOURCE = TIMINGS.of("Third-Party Session Handlers");
|
||||
private static final Map<CodeSource, TimingManager> PLUGIN_SOURCES = new HashMap<>();
|
||||
|
||||
private final Handler.Factory<?> factory;
|
||||
private final MCTiming timing;
|
||||
|
||||
TimedHandlerFactory(Handler.Factory<?> factory) {
|
||||
this.factory = factory;
|
||||
this.timing = makeTiming();
|
||||
}
|
||||
|
||||
private MCTiming makeTiming() {
|
||||
CodeSource codeSource = factory.getClass().getProtectionDomain().getCodeSource();
|
||||
TimingManager owner = PLUGIN_SOURCES.computeIfAbsent(codeSource, source -> {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
CodeSource pluginSource = plugin.getClass().getProtectionDomain().getCodeSource();
|
||||
if (Objects.equals(pluginSource, source)) {
|
||||
return TimingManager.of(plugin);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
String handlerName = factory.getClass().getEnclosingClass().getSimpleName();
|
||||
return owner == null
|
||||
? TIMINGS.of(handlerName, UNKNOWN_SOURCE)
|
||||
: owner.of(handlerName, owner.of("Session Handlers"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler create(Session session) {
|
||||
return new TimedHandler(factory.create(session), session, timing);
|
||||
}
|
||||
|
||||
static class TimedHandler extends Handler {
|
||||
private final Handler handler;
|
||||
private final MCTiming timing;
|
||||
|
||||
TimedHandler(Handler innerHandler, Session session, MCTiming timing) {
|
||||
super(session);
|
||||
this.handler = innerHandler;
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
|
||||
try (MCTiming ignored = timing.startTiming()) {
|
||||
handler.initialize(player, current, set);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testMoveTo(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType) {
|
||||
try (MCTiming ignored = timing.startTiming()) {
|
||||
return handler.testMoveTo(player, from, to, toSet, moveType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
||||
try (MCTiming ignored = timing.startTiming()) {
|
||||
return handler.onCrossBoundary(player, from, to, toSet, entered, exited, moveType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(LocalPlayer player, ApplicableRegionSet set) {
|
||||
try (MCTiming ignored = timing.startTiming()) {
|
||||
handler.tick(player, set);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public StateFlag.State getInvincibility(LocalPlayer player) {
|
||||
try (MCTiming ignored = timing.startTiming()) {
|
||||
return handler.getInvincibility(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler getWrappedHandler() {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,12 +33,12 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.NPC;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Shulker;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.SpectralArrow;
|
||||
import org.bukkit.entity.Steerable;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
@@ -91,7 +91,7 @@ public final class Entities {
|
||||
* @return true if the entity can be ridden
|
||||
*/
|
||||
public static boolean isRiddenOnUse(Entity entity) {
|
||||
return entity instanceof Steerable ? ((Steerable) entity).hasSaddle() : entity instanceof Vehicle;
|
||||
return entity instanceof Pig ? ((Pig) entity).hasSaddle() : entity instanceof Vehicle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,27 @@ public final class Materials {
|
||||
private static final Map<Material, Integer> MATERIAL_FLAGS = new EnumMap<>(Material.class);
|
||||
private static final Set<PotionEffectType> DAMAGE_EFFECTS = new HashSet<>();
|
||||
|
||||
private static Set<Material> shulkerBoxes = new HashSet<>();
|
||||
|
||||
static {
|
||||
shulkerBoxes.add(Material.SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.WHITE_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.ORANGE_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.MAGENTA_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.LIGHT_BLUE_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.YELLOW_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.LIME_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.PINK_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.GRAY_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.LIGHT_GRAY_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.CYAN_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.PURPLE_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.BLUE_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.BROWN_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.GREEN_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.RED_SHULKER_BOX);
|
||||
shulkerBoxes.add(Material.BLACK_SHULKER_BOX);
|
||||
|
||||
ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);
|
||||
ENTITY_ITEMS.put(EntityType.ARROW, Material.ARROW);
|
||||
ENTITY_ITEMS.put(EntityType.SNOWBALL, Material.SNOWBALL);
|
||||
@@ -120,7 +140,7 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.FIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPAWNER, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.CHEST, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_WIRE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_WIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRAFTING_TABLE, 0);
|
||||
@@ -141,6 +161,7 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.CACTUS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUKEBOX, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.OAK_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERRACK, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_SAND, 0);
|
||||
@@ -174,10 +195,17 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.VINE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPRUCE_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.ACACIA_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BIRCH_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.DARK_OAK_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.JUNGLE_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.OAK_FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MYCELIUM, 0);
|
||||
MATERIAL_FLAGS.put(Material.LILY_PAD, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENCHANTING_TABLE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BREWING_STAND, MODIFIED_ON_RIGHT);
|
||||
@@ -229,6 +257,11 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.IRON_TRAPDOOR, 0);
|
||||
MATERIAL_FLAGS.put(Material.RED_SANDSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.RED_SANDSTONE_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPRUCE_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BIRCH_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUNGLE_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DARK_OAK_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.ACACIA_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPRUCE_DOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BIRCH_DOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.JUNGLE_DOOR, MODIFIED_ON_RIGHT);
|
||||
@@ -421,9 +454,9 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.STONECUTTER, 0);
|
||||
MATERIAL_FLAGS.put(Material.SWEET_BERRY_BUSH, MODIFIED_ON_RIGHT);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.IRON_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_SHOVEL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.IRON_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_AXE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.FLINT_AND_STEEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.APPLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOW, 0);
|
||||
@@ -434,32 +467,32 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.GOLD_INGOT, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_SHOVEL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_AXE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STONE_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_SHOVEL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STONE_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_AXE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_SHOVEL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_AXE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOWL, 0);
|
||||
MATERIAL_FLAGS.put(Material.MUSHROOM_STEW, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_SHOVEL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_AXE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STRING, 0);
|
||||
MATERIAL_FLAGS.put(Material.FEATHER, 0);
|
||||
MATERIAL_FLAGS.put(Material.GUNPOWDER, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STONE_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.IRON_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.WHEAT_SEEDS, 0);
|
||||
MATERIAL_FLAGS.put(Material.BREAD, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER_HELMET, 0);
|
||||
@@ -514,29 +547,29 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.COD, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKED_COD, 0);
|
||||
MATERIAL_FLAGS.put(Material.INK_SAC, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLACK_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLUE_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BROWN_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.CYAN_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GRAY_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GREEN_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LIGHT_BLUE_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LIGHT_GRAY_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LIME_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.MAGENTA_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.ORANGE_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PINK_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PURPLE_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.RED_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WHITE_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.YELLOW_DYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLACK_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.BLUE_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.BROWN_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.CYAN_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.GRAY_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.GREEN_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.LIGHT_BLUE_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.LIGHT_GRAY_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.LIME_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.MAGENTA_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.ORANGE_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.PINK_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.PURPLE_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.RED_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.WHITE_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.YELLOW_DYE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.COCOA_BEANS, 0);
|
||||
MATERIAL_FLAGS.put(Material.BONE_MEAL, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.BONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SUGAR, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKIE, 0);
|
||||
MATERIAL_FLAGS.put(Material.MAP, 0);
|
||||
MATERIAL_FLAGS.put(Material.SHEARS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SHEARS, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.MELON_SLICE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_SEEDS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_SEEDS, 0);
|
||||
@@ -660,82 +693,24 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.SWEET_BERRIES, 0);
|
||||
|
||||
// 1.15
|
||||
MATERIAL_FLAGS.put(Material.BEEHIVE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BEE_NEST, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.HONEY_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEYCOMB_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEY_BOTTLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEYCOMB, 0);
|
||||
|
||||
// 1.16
|
||||
MATERIAL_FLAGS.put(Material.ANCIENT_DEBRIS, 0);
|
||||
MATERIAL_FLAGS.put(Material.BASALT, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLACKSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHAIN, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHISELED_NETHER_BRICKS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHISELED_POLISHED_BLACKSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRACKED_NETHER_BRICKS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRACKED_POLISHED_BLACKSTONE_BRICKS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRIMSON_FUNGUS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRIMSON_NYLIUM, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRIMSON_ROOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CRIMSON_TRAPDOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.CRYING_OBSIDIAN, 0);
|
||||
MATERIAL_FLAGS.put(Material.GILDED_BLACKSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LODESTONE, 0);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_HOE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_INGOT, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_SCRAP, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_SHOVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERITE_SWORD, 0);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.NETHER_GOLD_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_SPROUTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.PIGLIN_BANNER_PATTERN, 0);
|
||||
MATERIAL_FLAGS.put(Material.POLISHED_BASALT, 0);
|
||||
MATERIAL_FLAGS.put(Material.POLISHED_BLACKSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.POLISHED_BLACKSTONE_BRICKS, 0);
|
||||
MATERIAL_FLAGS.put(Material.POLISHED_BLACKSTONE_PRESSURE_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_BRICKS, 0);
|
||||
MATERIAL_FLAGS.put(Material.RESPAWN_ANCHOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SHROOMLIGHT, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_CAMPFIRE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_FIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_LANTERN, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_SOIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_TORCH, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_WALL_TORCH, 0);
|
||||
MATERIAL_FLAGS.put(Material.TARGET, 0);
|
||||
MATERIAL_FLAGS.put(Material.TWISTING_VINES, 0);
|
||||
MATERIAL_FLAGS.put(Material.TWISTING_VINES_PLANT, 0);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.WARPED_FUNGUS, 0);
|
||||
MATERIAL_FLAGS.put(Material.WARPED_FUNGUS_ON_A_STICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WARPED_NYLIUM, 0);
|
||||
MATERIAL_FLAGS.put(Material.WARPED_ROOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.WARPED_TRAPDOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.WARPED_WART_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WEEPING_VINES, 0);
|
||||
MATERIAL_FLAGS.put(Material.WEEPING_VINES_PLANT, 0);
|
||||
try {
|
||||
MATERIAL_FLAGS.put(Material.BEEHIVE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BEE_NEST, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.HONEY_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEYCOMB_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEY_BOTTLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.HONEYCOMB, 0);
|
||||
} catch (NoSuchFieldError ignored) {
|
||||
}
|
||||
|
||||
// Fake tags
|
||||
for (Material m : shulkerBoxes) {
|
||||
MATERIAL_FLAGS.put(m, MODIFIED_ON_RIGHT);
|
||||
}
|
||||
|
||||
// Generated via tag
|
||||
for (Material woodenDoor : Tag.WOODEN_DOORS.getValues()) {
|
||||
MATERIAL_FLAGS.put(woodenDoor, MODIFIED_ON_RIGHT);
|
||||
}
|
||||
for (Material woodenTrapdoor : Tag.WOODEN_TRAPDOORS.getValues()) {
|
||||
MATERIAL_FLAGS.put(woodenTrapdoor, MODIFIED_ON_RIGHT);
|
||||
}
|
||||
for (Material shulkerBox : Tag.SHULKER_BOXES.getValues()) {
|
||||
MATERIAL_FLAGS.put(shulkerBox, MODIFIED_ON_RIGHT);
|
||||
for (Material door : Tag.DOORS.getValues()) {
|
||||
MATERIAL_FLAGS.put(door, MODIFIED_ON_RIGHT);
|
||||
}
|
||||
for (Material boat : Tag.ITEMS_BOATS.getValues()) {
|
||||
MATERIAL_FLAGS.put(boat, 0);
|
||||
@@ -794,12 +769,6 @@ public final class Materials {
|
||||
for (Material bannerPat : Tag.ITEMS_BANNERS.getValues()) {
|
||||
MATERIAL_FLAGS.put(bannerPat, 0);
|
||||
}
|
||||
for (Material fenceGate : Tag.FENCE_GATES.getValues()) {
|
||||
MATERIAL_FLAGS.put(fenceGate, MODIFIED_ON_RIGHT);
|
||||
}
|
||||
for (Material fence : Tag.FENCES.getValues()) {
|
||||
MATERIAL_FLAGS.put(fence, 0);
|
||||
}
|
||||
Stream.concat(Stream.concat(
|
||||
Tag.CORAL_BLOCKS.getValues().stream(),
|
||||
Tag.CORALS.getValues().stream()),
|
||||
@@ -943,8 +912,7 @@ public final class Materials {
|
||||
* @return true if a water block
|
||||
*/
|
||||
public static boolean isWater(Material material) {
|
||||
return material == Material.WATER || material == Material.BUBBLE_COLUMN
|
||||
|| material == Material.KELP_PLANT || material == Material.SEAGRASS || material == Material.TALL_SEAGRASS;
|
||||
return material == Material.WATER || material == Material.BUBBLE_COLUMN;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1015,16 +983,6 @@ public final class Materials {
|
||||
return Tag.ITEMS_BOATS.isTagged(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a Shulker Box.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a Shulker Box block
|
||||
*/
|
||||
public static boolean isShulkerBox(Material material) {
|
||||
return Tag.SHULKER_BOXES.isTagged(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is an inventory block.
|
||||
*
|
||||
@@ -1043,7 +1001,7 @@ public final class Materials {
|
||||
|| material == Material.BARREL
|
||||
|| material == Material.BLAST_FURNACE
|
||||
|| material == Material.SMOKER
|
||||
|| Tag.SHULKER_BOXES.isTagged(material);
|
||||
|| shulkerBoxes.contains(material);
|
||||
}
|
||||
|
||||
public static boolean isSpawnEgg(Material material) {
|
||||
@@ -1068,7 +1026,6 @@ public final class Materials {
|
||||
case FOX_SPAWN_EGG:
|
||||
case GHAST_SPAWN_EGG:
|
||||
case GUARDIAN_SPAWN_EGG:
|
||||
case HOGLIN_SPAWN_EGG:
|
||||
case HORSE_SPAWN_EGG:
|
||||
case HUSK_SPAWN_EGG:
|
||||
case LLAMA_SPAWN_EGG:
|
||||
@@ -1079,8 +1036,6 @@ public final class Materials {
|
||||
case PANDA_SPAWN_EGG:
|
||||
case PARROT_SPAWN_EGG:
|
||||
case PHANTOM_SPAWN_EGG:
|
||||
case PIGLIN_BRUTE_SPAWN_EGG:
|
||||
case PIGLIN_SPAWN_EGG:
|
||||
case PIG_SPAWN_EGG:
|
||||
case PILLAGER_SPAWN_EGG:
|
||||
case POLAR_BEAR_SPAWN_EGG:
|
||||
@@ -1096,7 +1051,6 @@ public final class Materials {
|
||||
case SLIME_SPAWN_EGG:
|
||||
case SQUID_SPAWN_EGG:
|
||||
case STRAY_SPAWN_EGG:
|
||||
case STRIDER_SPAWN_EGG:
|
||||
case TRADER_LLAMA_SPAWN_EGG:
|
||||
case TROPICAL_FISH_SPAWN_EGG:
|
||||
case TURTLE_SPAWN_EGG:
|
||||
@@ -1107,9 +1061,8 @@ public final class Materials {
|
||||
case WITCH_SPAWN_EGG:
|
||||
case WITHER_SKELETON_SPAWN_EGG:
|
||||
case WOLF_SPAWN_EGG:
|
||||
case ZOGLIN_SPAWN_EGG:
|
||||
case ZOMBIE_HORSE_SPAWN_EGG:
|
||||
case ZOMBIFIED_PIGLIN_SPAWN_EGG:
|
||||
case ZOMBIE_PIGMAN_SPAWN_EGG:
|
||||
case ZOMBIE_SPAWN_EGG:
|
||||
case ZOMBIE_VILLAGER_SPAWN_EGG:
|
||||
return true;
|
||||
@@ -1160,8 +1113,6 @@ public final class Materials {
|
||||
return EntityType.GHAST;
|
||||
case GUARDIAN_SPAWN_EGG:
|
||||
return EntityType.GUARDIAN;
|
||||
case HOGLIN_SPAWN_EGG:
|
||||
return EntityType.HOGLIN;
|
||||
case HORSE_SPAWN_EGG:
|
||||
return EntityType.HORSE;
|
||||
case HUSK_SPAWN_EGG:
|
||||
@@ -1182,10 +1133,6 @@ public final class Materials {
|
||||
return EntityType.PARROT;
|
||||
case PHANTOM_SPAWN_EGG:
|
||||
return EntityType.PHANTOM;
|
||||
case PIGLIN_BRUTE_SPAWN_EGG:
|
||||
return EntityType.PIGLIN_BRUTE;
|
||||
case PIGLIN_SPAWN_EGG:
|
||||
return EntityType.PIGLIN;
|
||||
case PILLAGER_SPAWN_EGG:
|
||||
return EntityType.PILLAGER;
|
||||
case POLAR_BEAR_SPAWN_EGG:
|
||||
@@ -1214,8 +1161,6 @@ public final class Materials {
|
||||
return EntityType.SQUID;
|
||||
case STRAY_SPAWN_EGG:
|
||||
return EntityType.STRAY;
|
||||
case STRIDER_SPAWN_EGG:
|
||||
return EntityType.STRIDER;
|
||||
case TRADER_LLAMA_SPAWN_EGG:
|
||||
return EntityType.TRADER_LLAMA;
|
||||
case TROPICAL_FISH_SPAWN_EGG:
|
||||
@@ -1238,8 +1183,8 @@ public final class Materials {
|
||||
return EntityType.WOLF;
|
||||
case ZOMBIE_HORSE_SPAWN_EGG:
|
||||
return EntityType.ZOMBIE_HORSE;
|
||||
case ZOMBIFIED_PIGLIN_SPAWN_EGG:
|
||||
return EntityType.ZOMBIFIED_PIGLIN;
|
||||
case ZOMBIE_PIGMAN_SPAWN_EGG:
|
||||
return EntityType.PIG_ZOMBIE;
|
||||
case ZOMBIE_SPAWN_EGG:
|
||||
return EntityType.ZOMBIE;
|
||||
case ZOMBIE_VILLAGER_SPAWN_EGG:
|
||||
@@ -1254,17 +1199,6 @@ public final class Materials {
|
||||
return Tag.BEDS.isTagged(material);
|
||||
}
|
||||
|
||||
public static boolean isAnvil(Material material) {
|
||||
return Tag.ANVIL.isTagged(material);
|
||||
}
|
||||
|
||||
public static boolean isCoral(Material material) {
|
||||
return Tag.CORAL_BLOCKS.isTagged(material) ||
|
||||
Tag.CORAL_PLANTS.isTagged(material) ||
|
||||
Tag.CORALS.isTagged(material) ||
|
||||
Tag.WALL_CORALS.isTagged(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the material is a crop.
|
||||
* @param type the material
|
||||
@@ -1282,22 +1216,7 @@ public final class Materials {
|
||||
|| type == Material.CACTUS
|
||||
|| type == Material.SUGAR_CANE
|
||||
|| type == Material.BAMBOO
|
||||
|| type == Material.BAMBOO_SAPLING
|
||||
|| type == Material.SWEET_BERRY_BUSH
|
||||
|| type == Material.NETHER_WART;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the material should be handled as vine. Used by the vine-growth flag
|
||||
* @param newType the material
|
||||
* @return true if the material should be handled as vine
|
||||
*/
|
||||
public static boolean isVine(Material newType) {
|
||||
return newType == Material.VINE ||
|
||||
newType == Material.KELP ||
|
||||
newType == Material.TWISTING_VINES ||
|
||||
newType == Material.WEEPING_VINES;
|
||||
|
||||
|| type == Material.BAMBOO_SAPLING;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1312,15 +1231,26 @@ public final class Materials {
|
||||
*/
|
||||
public static boolean isUseFlagApplicable(Material material) {
|
||||
if (Tag.BUTTONS.isTagged(material)
|
||||
|| Tag.WOODEN_DOORS.isTagged(material)
|
||||
|| Tag.WOODEN_TRAPDOORS.isTagged(material)
|
||||
|| Tag.FENCE_GATES.isTagged(material)
|
||||
|| Tag.PRESSURE_PLATES.isTagged(material)) {
|
||||
|| Tag.DOORS.isTagged(material)
|
||||
|| Tag.WOODEN_PRESSURE_PLATES.isTagged(material)
|
||||
|| Tag.WOODEN_TRAPDOORS.isTagged(material)) {
|
||||
return true;
|
||||
}
|
||||
switch (material) {
|
||||
case LEVER:
|
||||
case LECTERN:
|
||||
case ACACIA_FENCE_GATE:
|
||||
case DARK_OAK_FENCE_GATE:
|
||||
case JUNGLE_FENCE_GATE:
|
||||
case BIRCH_FENCE_GATE:
|
||||
case SPRUCE_FENCE_GATE:
|
||||
case OAK_FENCE_GATE:
|
||||
case LIGHT_WEIGHTED_PRESSURE_PLATE:
|
||||
case HEAVY_WEIGHTED_PRESSURE_PLATE:
|
||||
case STONE_PRESSURE_PLATE:
|
||||
case ANVIL:
|
||||
case DAMAGED_ANVIL:
|
||||
case CHIPPED_ANVIL:
|
||||
case ENCHANTING_TABLE:
|
||||
case BELL:
|
||||
case LOOM:
|
||||
@@ -1362,7 +1292,7 @@ public final class Materials {
|
||||
*/
|
||||
public static boolean isItemAppliedToBlock(Material item, Material block) {
|
||||
Integer flags = MATERIAL_FLAGS.get(item);
|
||||
return flags == null || (flags & MODIFIES_BLOCKS) == MODIFIES_BLOCKS || isToolApplicable(item, block);
|
||||
return flags == null || (flags & MODIFIES_BLOCKS) == MODIFIES_BLOCKS;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1426,10 +1356,6 @@ public final class Materials {
|
||||
case GOLDEN_CHESTPLATE:
|
||||
case GOLDEN_LEGGINGS:
|
||||
case GOLDEN_BOOTS:
|
||||
case NETHERITE_HELMET:
|
||||
case NETHERITE_CHESTPLATE:
|
||||
case NETHERITE_LEGGINGS:
|
||||
case NETHERITE_BOOTS:
|
||||
case TURTLE_HELMET:
|
||||
case ELYTRA:
|
||||
return true;
|
||||
@@ -1438,102 +1364,4 @@ public final class Materials {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the material is usable via right-click on the target
|
||||
* material. Returns false if the target material cannot be modified
|
||||
* by the provided tool, or of the provided tool material isn't
|
||||
* a tool material.
|
||||
*
|
||||
* @param toolMaterial the tool material being used
|
||||
* @param targetMaterial the target material to check
|
||||
* @return true if tool has an interact function with this material
|
||||
*/
|
||||
public static boolean isToolApplicable(Material toolMaterial, Material targetMaterial) {
|
||||
switch (toolMaterial) {
|
||||
case WOODEN_HOE:
|
||||
case STONE_HOE:
|
||||
case IRON_HOE:
|
||||
case GOLDEN_HOE:
|
||||
case DIAMOND_HOE:
|
||||
case NETHERITE_HOE:
|
||||
switch (targetMaterial) {
|
||||
case GRASS_BLOCK:
|
||||
case DIRT:
|
||||
case GRASS_PATH:
|
||||
// case COARSE_DIRT: // already handled by the server...
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WOODEN_AXE:
|
||||
case STONE_AXE:
|
||||
case IRON_AXE:
|
||||
case GOLDEN_AXE:
|
||||
case DIAMOND_AXE:
|
||||
case NETHERITE_AXE:
|
||||
switch (targetMaterial) {
|
||||
case OAK_LOG:
|
||||
case DARK_OAK_LOG:
|
||||
case ACACIA_LOG:
|
||||
case BIRCH_LOG:
|
||||
case SPRUCE_LOG:
|
||||
case JUNGLE_LOG:
|
||||
case OAK_WOOD:
|
||||
case DARK_OAK_WOOD:
|
||||
case ACACIA_WOOD:
|
||||
case BIRCH_WOOD:
|
||||
case SPRUCE_WOOD:
|
||||
case JUNGLE_WOOD:
|
||||
case CRIMSON_STEM:
|
||||
case WARPED_STEM:
|
||||
case CRIMSON_HYPHAE:
|
||||
case WARPED_HYPHAE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WOODEN_SHOVEL:
|
||||
case STONE_SHOVEL:
|
||||
case IRON_SHOVEL:
|
||||
case GOLDEN_SHOVEL:
|
||||
case DIAMOND_SHOVEL:
|
||||
case NETHERITE_SHOVEL:
|
||||
switch (targetMaterial) {
|
||||
case GRASS_BLOCK:
|
||||
case CAMPFIRE:
|
||||
case SOUL_CAMPFIRE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case SHEARS:
|
||||
switch (targetMaterial) {
|
||||
case PUMPKIN:
|
||||
case BEE_NEST:
|
||||
case BEEHIVE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case BLACK_DYE:
|
||||
case BLUE_DYE:
|
||||
case BROWN_DYE:
|
||||
case CYAN_DYE:
|
||||
case GRAY_DYE:
|
||||
case GREEN_DYE:
|
||||
case LIGHT_BLUE_DYE:
|
||||
case LIGHT_GRAY_DYE:
|
||||
case LIME_DYE:
|
||||
case MAGENTA_DYE:
|
||||
case ORANGE_DYE:
|
||||
case PINK_DYE:
|
||||
case PURPLE_DYE:
|
||||
case RED_DYE:
|
||||
case WHITE_DYE:
|
||||
case YELLOW_DYE:
|
||||
return Tag.SIGNS.isTagged(targetMaterial);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFire(Material type) {
|
||||
return type == Material.FIRE || type == Material.SOUL_FIRE;
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@ main: com.sk89q.worldguard.bukkit.WorldGuardPlugin
|
||||
version: "${internalVersion}"
|
||||
depend: [WorldEdit]
|
||||
softdepend: [CommandBook]
|
||||
api-version: 1.16
|
||||
api-version: 1.13
|
||||
@@ -7,11 +7,9 @@ plugins {
|
||||
applyPlatformAndCoreConfiguration()
|
||||
|
||||
dependencies {
|
||||
"api"(project(":worldguard-libs:core"))
|
||||
"api"("com.sk89q.worldedit:worldedit-core:${Versions.WORLDEDIT}")
|
||||
"compile"(project(":worldguard-libs:core"))
|
||||
"compile"("com.sk89q.worldedit:worldedit-core:${Versions.WORLDEDIT}")
|
||||
"implementation"("org.flywaydb:flyway-core:3.0")
|
||||
"implementation"("org.yaml:snakeyaml:1.9")
|
||||
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
|
||||
|
||||
"compileOnly"("com.google.code.findbugs:jsr305:1.3.9")
|
||||
"testImplementation"("org.hamcrest:hamcrest-library:1.2.1")
|
||||
|
||||
@@ -31,6 +31,29 @@ import java.util.List;
|
||||
|
||||
public interface LocalPlayer extends Player, RegionAssociable {
|
||||
|
||||
/**
|
||||
* Returns the default namespace for this player.
|
||||
*
|
||||
* @return the default namespace.
|
||||
*/
|
||||
String getDefaultNamespace();
|
||||
|
||||
default boolean isDefaultNamespace(String otherNamespace) {
|
||||
String namespace = getDefaultNamespace();
|
||||
// If both are null, they're the same (the global)
|
||||
if (namespace == null && otherNamespace == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If only one is null, they're a mismatch
|
||||
if (namespace == null || otherNamespace == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare string equality
|
||||
return namespace.equalsIgnoreCase(otherNamespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this player is inside a group.
|
||||
*
|
||||
|
||||
+7
-6
@@ -46,7 +46,6 @@ import com.sk89q.worldguard.protection.flags.RegistryFlag;
|
||||
import com.sk89q.worldguard.protection.flags.SetFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.UnknownFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -76,7 +75,7 @@ class FlagHelperBox extends PaginationBox {
|
||||
.collect(Collectors.toList());
|
||||
private static final int SIZE = FLAGS.size() == Flags.INBUILT_FLAGS.size() ? FLAGS.size() : FLAGS.size() + 1;
|
||||
private static final int PAD_PX_SIZE = 180;
|
||||
static final Set<Flag<?>> DANGER_ZONE = ImmutableSet.of(Flags.BUILD, Flags.PASSTHROUGH, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK);
|
||||
private static final Set<Flag<?>> DANGER_ZONE = ImmutableSet.of(Flags.BUILD, Flags.PASSTHROUGH, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK);
|
||||
|
||||
private final World world;
|
||||
private final ProtectedRegion region;
|
||||
@@ -109,7 +108,7 @@ class FlagHelperBox extends PaginationBox {
|
||||
private Component createLine(Flag<?> flag, boolean thirdParty) {
|
||||
final TextComponent.Builder builder = TextComponent.builder("");
|
||||
|
||||
appendFlagName(builder, flag, flag instanceof UnknownFlag ? TextColor.GRAY : thirdParty ? TextColor.LIGHT_PURPLE : TextColor.GOLD);
|
||||
appendFlagName(builder, flag, thirdParty ? TextColor.LIGHT_PURPLE : TextColor.GOLD);
|
||||
appendFlagValue(builder, flag);
|
||||
return builder.build();
|
||||
}
|
||||
@@ -200,7 +199,7 @@ class FlagHelperBox extends PaginationBox {
|
||||
if (maySet) {
|
||||
if (isExplicitSet) {
|
||||
hoverTexts.add(TextComponent.of("Click to unset", TextColor.GOLD));
|
||||
} else if (DANGER_ZONE.contains(flag) && !(ProtectedRegion.GLOBAL_REGION.equals(region.getId()) && flag == Flags.PASSTHROUGH)) {
|
||||
} else if (DANGER_ZONE.contains(flag)) {
|
||||
hoverTexts.add(TextComponent.of("Setting this flag may have unintended consequences.", TextColor.RED)
|
||||
.append(TextComponent.newline())
|
||||
.append(TextComponent.of("Please read the documentation and set this flag manually if you really intend to.")
|
||||
@@ -256,7 +255,7 @@ class FlagHelperBox extends PaginationBox {
|
||||
|
||||
boolean isExplicitSet = currVal != null && !inherited;
|
||||
|
||||
boolean maySet = !(flag instanceof UnknownFlag) && perms.maySetFlag(region, flag);
|
||||
boolean maySet = perms.maySetFlag(region, flag);
|
||||
|
||||
TextColor col = isExplicitSet ? TextColor.WHITE : inherited ? TextColor.GRAY : TextColor.DARK_GRAY;
|
||||
Set<TextDecoration> styles = currVal == defVal ? ImmutableSet.of(TextDecoration.UNDERLINED) : Collections.emptySet();
|
||||
@@ -360,9 +359,11 @@ class FlagHelperBox extends PaginationBox {
|
||||
if (currVal == null) {
|
||||
currVal = getInheritedValue(region, flag);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
List<V> values = currVal == null ? Collections.emptyList() : (List<V>) flag.marshal(currVal);
|
||||
String display = (currVal == null ? "" : currVal.size() + "x ") + subName;
|
||||
final String stringValue = currVal == null ? ""
|
||||
: currVal.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||
: values.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||
TextComponent hoverComp = TextComponent.of("");
|
||||
if (currVal != null) {
|
||||
hoverComp = hoverComp.append(TextComponent.of("Current values:"))
|
||||
|
||||
+25
-21
@@ -32,6 +32,7 @@ import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionIdentifier;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
|
||||
|
||||
@@ -50,13 +51,13 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
flags = "nw:",
|
||||
desc = "Add a member to a region",
|
||||
min = 2)
|
||||
public void addMember(CommandContext args, Actor sender) throws CommandException {
|
||||
public void addMember(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion region = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayAddMembers(region)) {
|
||||
@@ -69,10 +70,11 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
|
||||
final String description = String.format("Adding members to the region '%s' on '%s'", region.getId(), world.getName());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Adding members to the region '%s' on '%s'", friendlyName, world.getName());
|
||||
AsyncCommandBuilder.wrap(resolver, sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.onSuccess(String.format("Region '%s' updated with new members.", region.getId()), region.getMembers()::addAll)
|
||||
.onSuccess(String.format("Region '%s' updated with new members.", friendlyName), region.getMembers()::addAll)
|
||||
.onFailure("Failed to add new members", worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
@@ -82,15 +84,14 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
flags = "nw:",
|
||||
desc = "Add an owner to a region",
|
||||
min = 2)
|
||||
public void addOwner(CommandContext args, Actor sender) throws CommandException {
|
||||
public void addOwner(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion region = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayAddOwners(region)) {
|
||||
@@ -103,10 +104,11 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
|
||||
final String description = String.format("Adding owners to the region '%s' on '%s'", region.getId(), world.getName());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Adding owners to the region '%s' on '%s'", friendlyName, world.getName());
|
||||
AsyncCommandBuilder.wrap(checkedAddOwners(sender, manager, region, world, resolver), sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.onSuccess(String.format("Region '%s' updated with new owners.", region.getId()), region.getOwners()::addAll)
|
||||
.onSuccess(String.format("Region '%s' updated with new owners.", friendlyName), region.getOwners()::addAll)
|
||||
.onFailure("Failed to add new owners", worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
@@ -149,13 +151,13 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
flags = "naw:",
|
||||
desc = "Remove an owner to a region",
|
||||
min = 1)
|
||||
public void removeMember(CommandContext args, Actor sender) throws CommandException {
|
||||
public void removeMember(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion region = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayRemoveMembers(region)) {
|
||||
@@ -178,11 +180,12 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
callable = resolver;
|
||||
}
|
||||
|
||||
final String description = String.format("Removing members from the region '%s' on '%s'", region.getId(), world.getName());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Removing members from the region '%s' on '%s'", friendlyName, world.getName());
|
||||
AsyncCommandBuilder.wrap(callable, sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.onSuccess(String.format("Region '%s' updated with members removed.", region.getId()), region.getMembers()::removeAll)
|
||||
.onSuccess(String.format("Region '%s' updated with members removed.", friendlyName), region.getMembers()::removeAll)
|
||||
.onFailure("Failed to remove members", worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
@@ -192,13 +195,13 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
flags = "naw:",
|
||||
desc = "Remove an owner to a region",
|
||||
min = 1)
|
||||
public void removeOwner(CommandContext args, Actor sender) throws CommandException {
|
||||
public void removeOwner(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion region = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayRemoveOwners(region)) {
|
||||
@@ -221,11 +224,12 @@ public class MemberCommands extends RegionCommandsBase {
|
||||
callable = resolver;
|
||||
}
|
||||
|
||||
final String description = String.format("Removing owners from the region '%s' on '%s'", region.getId(), world.getName());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Removing owners from the region '%s' on '%s'", friendlyName, world.getName());
|
||||
AsyncCommandBuilder.wrap(callable, sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.onSuccess(String.format("Region '%s' updated with owners removed.", region.getId()), region.getOwners()::removeAll)
|
||||
.onSuccess(String.format("Region '%s' updated with owners removed.", friendlyName), region.getOwners()::removeAll)
|
||||
.onFailure("Failed to remove owners", worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
|
||||
+109
-126
@@ -25,12 +25,14 @@ import com.google.common.collect.Sets;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
|
||||
import com.sk89q.worldedit.util.formatting.component.LabelFormat;
|
||||
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
||||
@@ -66,11 +68,8 @@ import com.sk89q.worldguard.protection.managers.migration.MigrationException;
|
||||
import com.sk89q.worldguard.protection.managers.migration.UUIDMigration;
|
||||
import com.sk89q.worldguard.protection.managers.storage.DriverType;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDriver;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.*;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.util.Enums;
|
||||
@@ -127,47 +126,49 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
* @throws CommandException any error
|
||||
*/
|
||||
@Command(aliases = {"define", "def", "d", "create"},
|
||||
usage = "[-w <world>] <id> [<owner1> [<owner2> [<owners...>]]]",
|
||||
flags = "ngw:",
|
||||
usage = "<id> [<owner1> [<owner2> [<owners...>]]]",
|
||||
flags = "ng",
|
||||
desc = "Defines a region",
|
||||
min = 1)
|
||||
public void define(CommandContext args, Actor sender) throws CommandException {
|
||||
public void define(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayDefine()) {
|
||||
if (!getPermissionModel(player).mayDefine()) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
String id = checkRegionId(args.getString(0), false);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), false);
|
||||
|
||||
World world = checkWorld(args, sender, 'w');
|
||||
World world = player.getWorld();
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
|
||||
checkRegionDoesNotExist(manager, id, true);
|
||||
checkRegionDoesNotExist(sender, manager, id, true);
|
||||
|
||||
ProtectedRegion region;
|
||||
|
||||
if (args.hasFlag('g')) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
region = checkRegionFromSelection(sender, id);
|
||||
region = checkRegionFromSelection(player, id);
|
||||
}
|
||||
|
||||
RegionAdder task = new RegionAdder(manager, region);
|
||||
task.addOwnersFromCommand(args, 2);
|
||||
|
||||
final String description = String.format("Adding region '%s'", region.getId());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Adding region '%s'", friendlyName);
|
||||
AsyncCommandBuilder.wrap(task, sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.onSuccess((Component) null,
|
||||
t -> {
|
||||
sender.print(String.format("A new region has been made named '%s'.", region.getId()));
|
||||
sender.print(String.format("A new region has been made named '%s'.", friendlyName));
|
||||
warnAboutDimensions(sender, region);
|
||||
informNewUser(sender, manager, region);
|
||||
checkSpawnOverlap(sender, world, region);
|
||||
})
|
||||
.onFailure(String.format("Failed to add the region '%s'", region.getId()), worldGuard.getExceptionConverter())
|
||||
.onFailure(String.format("Failed to add the region '%s'", friendlyName), worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
|
||||
@@ -179,22 +180,24 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
* @throws CommandException any error
|
||||
*/
|
||||
@Command(aliases = {"redefine", "update", "move"},
|
||||
usage = "[-w <world>] <id>",
|
||||
usage = "<id>",
|
||||
desc = "Re-defines the shape of a region",
|
||||
flags = "gw:",
|
||||
flags = "g",
|
||||
min = 1, max = 1)
|
||||
public void redefine(CommandContext args, Actor sender) throws CommandException {
|
||||
public void redefine(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
String id = checkRegionId(args.getString(0), false);
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w');
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), false);
|
||||
|
||||
World world = player.getWorld();
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
|
||||
ProtectedRegion existing = checkExistingRegion(manager, id, false);
|
||||
ProtectedRegion existing = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayRedefine(existing)) {
|
||||
if (!getPermissionModel(player).mayRedefine(existing)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
@@ -203,25 +206,26 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
if (args.hasFlag('g')) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
region = checkRegionFromSelection(sender, id);
|
||||
region = checkRegionFromSelection(player, id);
|
||||
}
|
||||
|
||||
region.copyFrom(existing);
|
||||
|
||||
RegionAdder task = new RegionAdder(manager, region);
|
||||
|
||||
final String description = String.format("Updating region '%s'", region.getId());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Updating region '%s'", friendlyName);
|
||||
AsyncCommandBuilder.wrap(task, sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
.sendMessageAfterDelay("(Please wait... " + description + ")")
|
||||
.onSuccess((Component) null,
|
||||
t -> {
|
||||
sender.print(String.format("Region '%s' has been updated with a new area.", region.getId()));
|
||||
warnAboutDimensions(sender, region);
|
||||
informNewUser(sender, manager, region);
|
||||
player.print(String.format("Region '%s' has been updated with a new area.", friendlyName));
|
||||
warnAboutDimensions(player, region);
|
||||
informNewUser(player, manager, region);
|
||||
checkSpawnOverlap(sender, world, region);
|
||||
})
|
||||
.onFailure(String.format("Failed to update the region '%s'", region.getId()), worldGuard.getExceptionConverter())
|
||||
.onFailure(String.format("Failed to update the region '%s'", friendlyName), worldGuard.getExceptionConverter())
|
||||
.buildAndExec(worldGuard.getExecutorService());
|
||||
}
|
||||
|
||||
@@ -239,7 +243,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
usage = "<id>",
|
||||
desc = "Claim a region",
|
||||
min = 1, max = 1)
|
||||
public void claim(CommandContext args, Actor sender) throws CommandException {
|
||||
public void claim(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
@@ -250,11 +254,11 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
String id = checkRegionId(args.getString(0), false);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), false);
|
||||
|
||||
RegionManager manager = checkRegionManager(player.getWorld());
|
||||
|
||||
checkRegionDoesNotExist(manager, id, false);
|
||||
checkRegionDoesNotExist(sender, manager, id, false);
|
||||
ProtectedRegion region = checkRegionFromSelection(player, id);
|
||||
|
||||
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld());
|
||||
@@ -316,11 +320,12 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
|
||||
task.setOwnersInput(new String[]{player.getName()});
|
||||
|
||||
final String description = String.format("Claiming region '%s'", id);
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Claiming region '%s'", friendlyName);
|
||||
AsyncCommandBuilder.wrap(task, sender)
|
||||
.registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description)
|
||||
.sendMessageAfterDelay("(Please wait... " + description + ")")
|
||||
.onSuccess(TextComponent.of(String.format("A new region has been claimed named '%s'.", id)), null)
|
||||
.onSuccess(TextComponent.of(String.format("A new region has been claimed named '%s'.", friendlyName)), null)
|
||||
.onFailure("Failed to claim region", WorldGuard.getInstance().getExceptionConverter())
|
||||
.buildAndExec(WorldGuard.getInstance().getExecutorService());
|
||||
}
|
||||
@@ -333,34 +338,29 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
* @throws CommandException any error
|
||||
*/
|
||||
@Command(aliases = {"select", "sel", "s"},
|
||||
usage = "[-w <world>] [id]",
|
||||
usage = "[id]",
|
||||
desc = "Load a region as a WorldEdit selection",
|
||||
min = 0, max = 1,
|
||||
flags = "w:")
|
||||
public void select(CommandContext args, Actor sender) throws CommandException {
|
||||
World world = checkWorld(args, sender, 'w');
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
min = 0, max = 1)
|
||||
public void select(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
RegionManager manager = checkRegionManager(player.getWorld());
|
||||
ProtectedRegion existing;
|
||||
|
||||
// If no arguments were given, get the region that the player is inside
|
||||
if (args.argsLength() == 0) {
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
if (!player.getWorld().equals(world)) { // confusing to get current location regions in another world
|
||||
throw new CommandException("Please specify a region name."); // just don't allow that
|
||||
}
|
||||
world = player.getWorld();
|
||||
existing = checkRegionStandingIn(manager, player, "/rg select -w \"" + world.getName() + "\" %id%");
|
||||
existing = checkRegionStandingIn(manager, player, "/rg select %id%");
|
||||
} else {
|
||||
existing = checkExistingRegion(manager, args.getString(0), false);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), false);
|
||||
existing = checkExistingRegion(sender, manager, id);
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).maySelect(existing)) {
|
||||
if (!getPermissionModel(player).maySelect(existing)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
// Select
|
||||
setPlayerSelection(sender, existing, world);
|
||||
setPlayerSelection(player, existing);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +375,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "usw:",
|
||||
desc = "Get information about a region",
|
||||
min = 0, max = 1)
|
||||
public void info(CommandContext args, Actor sender) throws CommandException {
|
||||
public void info(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
@@ -393,7 +393,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
existing = checkRegionStandingIn(manager, (LocalPlayer) sender, true,
|
||||
"/rg info -w \"" + world.getName() + "\" %id%" + (args.hasFlag('u') ? " -u" : "") + (args.hasFlag('s') ? " -s" : ""));
|
||||
} else { // Get region from the ID
|
||||
existing = checkExistingRegion(manager, args.getString(0), true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
existing = checkExistingRegion(sender, manager, id);
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
@@ -408,7 +409,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
setPlayerSelection(worldGuard.checkPlayer(sender), existing, world);
|
||||
setPlayerSelection(worldGuard.checkPlayer(sender), existing);
|
||||
}
|
||||
|
||||
// Print region information
|
||||
@@ -418,10 +419,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
AsyncCommandBuilder.wrap(printout, sender)
|
||||
.registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Fetching region info")
|
||||
.sendMessageAfterDelay("(Please wait... fetching region information...)")
|
||||
.onSuccess((Component) null, component -> {
|
||||
sender.print(component);
|
||||
checkSpawnOverlap(sender, world, existing);
|
||||
})
|
||||
.onSuccess((Component) null, sender::print)
|
||||
.onFailure("Failed to fetch region information", WorldGuard.getInstance().getExceptionConverter())
|
||||
.buildAndExec(WorldGuard.getInstance().getExecutorService());
|
||||
}
|
||||
@@ -492,7 +490,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "g:w:eh:",
|
||||
desc = "Set flags",
|
||||
min = 2)
|
||||
public void flag(CommandContext args, Actor sender) throws CommandException {
|
||||
public void flag(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
@@ -512,13 +510,13 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
|
||||
// Lookup the existing region
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion existing = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!permModel.maySetFlag(existing)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
String regionId = existing.getId();
|
||||
|
||||
Flag<?> foundFlag = Flags.fuzzyMatchFlag(flagRegistry, flagName);
|
||||
|
||||
@@ -526,7 +524,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
// can use, and do nothing afterwards
|
||||
if (foundFlag == null) {
|
||||
AsyncCommandBuilder.wrap(new FlagListBuilder(flagRegistry, permModel, existing, world,
|
||||
regionId, sender, flagName), sender)
|
||||
id, sender, flagName), sender)
|
||||
.registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Flag list for invalid flag command.")
|
||||
.onSuccess((Component) null, sender::print)
|
||||
.onFailure((Component) null, WorldGuard.getInstance().getExceptionConverter())
|
||||
@@ -583,7 +581,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
}
|
||||
|
||||
if (!args.hasFlag('h')) {
|
||||
sender.print("Region flag " + foundFlag.getName() + " set on '" + regionId + "' to '" + value + "'.");
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
sender.print("Region flag " + foundFlag.getName() + " set on '" + friendlyName + "' to '" + value + "'.");
|
||||
}
|
||||
|
||||
// No value? Clear the flag, if -g isn't specified
|
||||
@@ -598,7 +597,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
}
|
||||
|
||||
if (!args.hasFlag('h')) {
|
||||
sender.print("Region flag " + foundFlag.getName() + " removed from '" + regionId + "'. (Any -g(roups) were also removed.)");
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
sender.print("Region flag " + foundFlag.getName() + " removed from '" + friendlyName + "'. (Any -g(roups) were also removed.)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,7 +626,6 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
printout.appendFlagsList(false);
|
||||
printout.append(SubtleFormat.wrap(")"));
|
||||
printout.send(sender);
|
||||
checkSpawnOverlap(sender, world, existing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,7 +634,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "p:w:",
|
||||
desc = "View region flags",
|
||||
min = 0, max = 2)
|
||||
public void flagHelper(CommandContext args, Actor sender) throws CommandException {
|
||||
public void flagHelper(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
|
||||
// Lookup the existing region
|
||||
@@ -643,13 +642,14 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
ProtectedRegion region;
|
||||
if (args.argsLength() == 0) { // Get region from where the player is
|
||||
if (!(sender instanceof LocalPlayer)) {
|
||||
throw new CommandException("Please specify the region with /region flags -w world_name region_name.");
|
||||
throw new CommandException("Please specify the region with /region info -w world_name region_name.");
|
||||
}
|
||||
|
||||
region = checkRegionStandingIn(manager, (LocalPlayer) sender, true,
|
||||
"/rg flags -w \"" + world.getName() + "\" %id%");
|
||||
} else { // Get region from the ID
|
||||
region = checkExistingRegion(manager, args.getString(0), true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
region = checkExistingRegion(sender, manager, id);
|
||||
}
|
||||
|
||||
final RegionPermissionModel perms = getPermissionModel(sender);
|
||||
@@ -667,12 +667,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
if (!sender.isPlayer()) {
|
||||
flagHelperBox.tryMonoSpacing();
|
||||
}
|
||||
AsyncCommandBuilder.wrap(() -> {
|
||||
if (checkSpawnOverlap(sender, world, region)) {
|
||||
flagHelperBox.setComponentsPerPage(15);
|
||||
}
|
||||
return flagHelperBox.create(page);
|
||||
}, sender)
|
||||
AsyncCommandBuilder.wrap(() -> flagHelperBox.create(page), sender)
|
||||
.onSuccess((Component) null, sender::print)
|
||||
.onFailure("Failed to get region flags", WorldGuard.getInstance().getExceptionConverter())
|
||||
.buildAndExec(WorldGuard.getInstance().getExecutorService());
|
||||
@@ -690,7 +685,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "w:",
|
||||
desc = "Set the priority of a region",
|
||||
min = 2, max = 2)
|
||||
public void setPriority(CommandContext args, Actor sender) throws CommandException {
|
||||
public void setPriority(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
@@ -698,7 +693,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
|
||||
// Lookup the existing region
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), false);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), false);
|
||||
ProtectedRegion existing = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).maySetPriority(existing)) {
|
||||
@@ -707,8 +703,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
|
||||
existing.setPriority(priority);
|
||||
|
||||
sender.print("Priority of '" + existing.getId() + "' set to " + priority + " (higher numbers override).");
|
||||
checkSpawnOverlap(sender, world, existing);
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
sender.print("Priority of '" + friendlyName + "' set to " + priority + " (higher numbers override).");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -723,7 +719,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "w:",
|
||||
desc = "Set the parent of a region",
|
||||
min = 1, max = 2)
|
||||
public void setParent(CommandContext args, Actor sender) throws CommandException {
|
||||
public void setParent(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
@@ -734,9 +730,11 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
|
||||
// Get parent and child
|
||||
child = checkExistingRegion(manager, args.getString(0), false);
|
||||
RegionIdentifier childId = processRegionId(sender, args.getString(0), false);
|
||||
child = checkExistingRegion(sender, manager, childId);
|
||||
if (args.argsLength() == 2) {
|
||||
parent = checkExistingRegion(manager, args.getString(1), false);
|
||||
RegionIdentifier parentId = processRegionId(sender, args.getString(1), false);
|
||||
parent = checkExistingRegion(sender, manager, parentId);
|
||||
} else {
|
||||
parent = null;
|
||||
}
|
||||
@@ -750,11 +748,15 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
child.setParent(parent);
|
||||
} catch (CircularInheritanceException e) {
|
||||
// Tell the user what's wrong
|
||||
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), parent, null, sender);
|
||||
assert parent != null;
|
||||
printout.append(ErrorFormat.wrap("Uh oh! Setting '", parent.getId(), "' to be the parent of '", child.getId(),
|
||||
|
||||
String parentFriendlyName = parent.getIdentifier().getDisplayName(sender);
|
||||
String childFriendlyName = childId.getDisplayName(sender);
|
||||
|
||||
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), parent, null, sender);
|
||||
printout.append(ErrorFormat.wrap("Uh oh! Setting '", parentFriendlyName, "' to be the parent of '", childFriendlyName,
|
||||
"' would cause circular inheritance.")).newline();
|
||||
printout.append(SubtleFormat.wrap("(Current inheritance on '", parent.getId(), "':")).newline();
|
||||
printout.append(SubtleFormat.wrap("(Current inheritance on '", parentFriendlyName, "':")).newline();
|
||||
printout.appendParentTree(true);
|
||||
printout.append(SubtleFormat.wrap(")"));
|
||||
printout.send(sender);
|
||||
@@ -762,8 +764,9 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
}
|
||||
|
||||
// Tell the user the current inheritance
|
||||
String childFriendlyName = childId.getDisplayName(sender);
|
||||
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), child, null, sender);
|
||||
printout.append(TextComponent.of("Inheritance set for region '" + child.getId() + "'.", TextColor.LIGHT_PURPLE));
|
||||
printout.append(TextComponent.of("Inheritance set for region '" + childFriendlyName + "'.", TextColor.LIGHT_PURPLE));
|
||||
if (parent != null) {
|
||||
printout.newline();
|
||||
printout.append(SubtleFormat.wrap("(Current inheritance:")).newline();
|
||||
@@ -787,7 +790,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "fuw:",
|
||||
desc = "Remove a region",
|
||||
min = 1, max = 1)
|
||||
public void remove(CommandContext args, Actor sender) throws CommandException {
|
||||
public void remove(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
warnAboutSaveFailures(sender);
|
||||
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
@@ -796,7 +799,8 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
|
||||
// Lookup the existing region
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion existing = checkExistingRegion(sender, manager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayDelete(existing)) {
|
||||
@@ -813,12 +817,15 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
task.setRemovalStrategy(RemovalStrategy.UNSET_PARENT_IN_CHILDREN);
|
||||
}
|
||||
|
||||
final String description = String.format("Removing region '%s' in '%s'", existing.getId(), world.getName());
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
final String description = String.format("Removing region '%s' in '%s'", friendlyName, world.getName());
|
||||
AsyncCommandBuilder.wrap(task, sender)
|
||||
.registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description)
|
||||
.sendMessageAfterDelay("Please wait... removing region.")
|
||||
.onSuccess((Component) null, removed -> sender.print(TextComponent.of(
|
||||
"Successfully removed " + removed.stream().map(ProtectedRegion::getId).collect(Collectors.joining(", ")) + ".",
|
||||
"Successfully removed " + removed.stream()
|
||||
.map((r) -> r.getIdentifier().getDisplayName(sender))
|
||||
.collect(Collectors.joining(", ")) + ".",
|
||||
TextColor.LIGHT_PURPLE)))
|
||||
.onFailure("Failed to remove region", WorldGuard.getInstance().getExceptionConverter())
|
||||
.buildAndExec(WorldGuard.getInstance().getExecutorService());
|
||||
@@ -853,10 +860,6 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
if (world != null) {
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
|
||||
if (manager == null) {
|
||||
throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
|
||||
}
|
||||
|
||||
final String description = String.format("Loading region data for '%s'.", world.getName());
|
||||
AsyncCommandBuilder.wrap(new RegionManagerLoader(manager), sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
@@ -913,10 +916,6 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
if (world != null) {
|
||||
RegionManager manager = checkRegionManager(world);
|
||||
|
||||
if (manager == null) {
|
||||
throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
|
||||
}
|
||||
|
||||
final String description = String.format("Saving region data for '%s'.", world.getName());
|
||||
AsyncCommandBuilder.wrap(new RegionManagerSaver(manager), sender)
|
||||
.registerWithSupervisor(worldGuard.getSupervisor(), description)
|
||||
@@ -1079,14 +1078,15 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
flags = "sw:",
|
||||
desc = "Teleports you to the location associated with the region.",
|
||||
min = 1, max = 1)
|
||||
public void teleport(CommandContext args, Actor sender) throws CommandException {
|
||||
public void teleport(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
Location teleportLocation;
|
||||
|
||||
// Lookup the existing region
|
||||
World world = checkWorld(args, player, 'w');
|
||||
RegionManager regionManager = checkRegionManager(world);
|
||||
ProtectedRegion existing = checkExistingRegion(regionManager, args.getString(0), true);
|
||||
RegionIdentifier id = processRegionId(sender, args.getString(0), true);
|
||||
ProtectedRegion existing = checkExistingRegion(sender, regionManager, id);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(player).mayTeleportTo(existing)) {
|
||||
@@ -1109,39 +1109,19 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
}
|
||||
}
|
||||
|
||||
String message = existing.getFlag(Flags.TELE_MESSAGE);
|
||||
|
||||
// If the flag isn't set, use the default message
|
||||
// If message.isEmpty(), no message is sent by LocalPlayer#teleport(...)
|
||||
if (message == null) {
|
||||
message = Flags.TELE_MESSAGE.getDefault();
|
||||
}
|
||||
|
||||
String friendlyName = id.getDisplayName(sender);
|
||||
player.teleport(teleportLocation,
|
||||
message.replace("%id%", existing.getId()),
|
||||
"Unable to teleport to region '" + existing.getId() + "'.");
|
||||
"Teleported you to the region '" + friendlyName + "'.",
|
||||
"Unable to teleport to region '" + friendlyName + "'.");
|
||||
}
|
||||
|
||||
@Command(aliases = {"toggle-bypass", "bypass"},
|
||||
usage = "[on|off]",
|
||||
desc = "Toggle region bypassing, effectively ignoring bypass permissions.")
|
||||
@CommandPermissions({"worldguard.region.toggle-bypass"})
|
||||
public void toggleBypass(CommandContext args, Actor sender) throws CommandException {
|
||||
LocalPlayer player = worldGuard.checkPlayer(sender);
|
||||
if (!player.hasPermission("worldguard.region.toggle-bypass")) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
|
||||
boolean shouldEnableBypass;
|
||||
if (args.argsLength() > 0) {
|
||||
String arg1 = args.getString(0);
|
||||
if (!arg1.equalsIgnoreCase("on") && !arg1.equalsIgnoreCase("off")) {
|
||||
throw new CommandException("Allowed optional arguments are: on, off");
|
||||
}
|
||||
shouldEnableBypass = arg1.equalsIgnoreCase("on");
|
||||
} else {
|
||||
shouldEnableBypass = session.hasBypassDisabled();
|
||||
}
|
||||
if (shouldEnableBypass) {
|
||||
if (session.hasBypassDisabled()) {
|
||||
session.setBypassDisabled(false);
|
||||
player.print("You are now bypassing region protection (as long as you have permission).");
|
||||
} else {
|
||||
@@ -1155,12 +1135,12 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
private final RegionPermissionModel permModel;
|
||||
private final ProtectedRegion existing;
|
||||
private final World world;
|
||||
private final String regionId;
|
||||
private final RegionIdentifier regionId;
|
||||
private final Actor sender;
|
||||
private final String flagName;
|
||||
|
||||
FlagListBuilder(FlagRegistry flagRegistry, RegionPermissionModel permModel, ProtectedRegion existing,
|
||||
World world, String regionId, Actor sender, String flagName) {
|
||||
World world, RegionIdentifier regionId, Actor sender, String flagName) {
|
||||
this.flagRegistry = flagRegistry;
|
||||
this.permModel = permModel;
|
||||
this.existing = existing;
|
||||
@@ -1192,9 +1172,10 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
for (int i = 0; i < flagList.size(); i++) {
|
||||
String flag = flagList.get(i);
|
||||
|
||||
String qualifiedName = regionId.getQualifiedName();
|
||||
builder.append(TextComponent.of(flag, i % 2 == 0 ? TextColor.GRAY : TextColor.WHITE)
|
||||
.hoverEvent(clickToSet).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND,
|
||||
"/rg flag -w \"" + world.getName() + "\" " + regionId + " " + flag + " ")));
|
||||
"/rg flag -w \"" + world.getName() + "\" " + qualifiedName + " " + flag + " ")));
|
||||
if (i < flagList.size() + 1) {
|
||||
builder.append(TextComponent.of(", "));
|
||||
}
|
||||
@@ -1204,10 +1185,12 @@ public final class RegionCommands extends RegionCommandsBase {
|
||||
.append(TextComponent.newline())
|
||||
.append(builder.build());
|
||||
if (sender.isPlayer()) {
|
||||
String friendlyName = regionId.getDisplayName(sender);
|
||||
String qualifiedName = regionId.getQualifiedName();
|
||||
return ret.append(TextComponent.of("Or use the command ", TextColor.LIGHT_PURPLE)
|
||||
.append(TextComponent.of("/rg flags " + regionId, TextColor.AQUA)
|
||||
.append(TextComponent.of("/rg flags " + friendlyName, TextColor.AQUA)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND,
|
||||
"/rg flags -w \"" + world.getName() + "\" " + regionId))));
|
||||
"/rg flags -w \"" + world.getName() + "\" " + qualifiedName))));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+289
-74
@@ -31,16 +31,15 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
|
||||
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
@@ -50,14 +49,13 @@ import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
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 com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.util.WorldEditRegionConverter;
|
||||
import com.sk89q.worldguard.protection.regions.*;
|
||||
import com.sk89q.worldguard.util.profile.Profile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class RegionCommandsBase {
|
||||
@@ -79,32 +77,16 @@ class RegionCommandsBase {
|
||||
* Gets the world from the given flag, or falling back to the the current player
|
||||
* if the sender is a player, otherwise reporting an error.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @param args the arguments
|
||||
* @param sender the sender
|
||||
* @param flag the flag (such as 'w')
|
||||
* @param flag the flag (such as 'w')
|
||||
* @return a world
|
||||
* @throws CommandException on error
|
||||
*/
|
||||
protected static World checkWorld(CommandContext args, Actor sender, char flag) throws CommandException {
|
||||
return checkWorld(args, sender, flag, true);
|
||||
}
|
||||
|
||||
protected static World checkWorld(CommandContext args, Actor sender, char flag, boolean allowWorldEditOverride) throws CommandException {
|
||||
if (args.hasFlag(flag)) {
|
||||
return WorldGuard.getInstance().getPlatform().getMatcher().matchWorld(sender, args.getFlag(flag));
|
||||
} else {
|
||||
if (allowWorldEditOverride) {
|
||||
try {
|
||||
World override = WorldEdit.getInstance().getSessionManager().get(sender).getWorldOverride();
|
||||
if (override != null) {
|
||||
if (sender instanceof LocalPlayer && !override.equals(((LocalPlayer) sender).getWorld())) {
|
||||
sender.printDebug(TextComponent.of("Using //world override for region command: " + override.getName()));
|
||||
}
|
||||
return override;
|
||||
}
|
||||
} catch (NoSuchMethodError ignored) {
|
||||
}
|
||||
}
|
||||
if (sender instanceof LocalPlayer) {
|
||||
return ((LocalPlayer) sender).getWorld();
|
||||
} else {
|
||||
@@ -113,28 +95,190 @@ class RegionCommandsBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a region name.
|
||||
*
|
||||
* @param name the name
|
||||
* @param allowGlobal whether __global__ is allowed
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
protected static void checkName(String name, boolean allowGlobal) throws CommandException {
|
||||
if (!RegionIdentifier.isValidName(name)) {
|
||||
throw new CommandException(
|
||||
"The region name of '" + name + "' contains characters that are not allowed.");
|
||||
}
|
||||
|
||||
if (!allowGlobal && name.equalsIgnoreCase("__global__")) { // Sorry, no global
|
||||
throw new CommandException(
|
||||
"Sorry, you can't use __global__ here.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a region ID.
|
||||
*
|
||||
* @param id the id
|
||||
* @param id the id
|
||||
* @param allowGlobal whether __global__ is allowed
|
||||
* @return the id given
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
@Deprecated
|
||||
protected static String checkRegionId(String id, boolean allowGlobal) throws CommandException {
|
||||
if (!ProtectedRegion.isValidId(id)) {
|
||||
throw new CommandException(
|
||||
"The region name of '" + id + "' contains characters that are not allowed.");
|
||||
}
|
||||
|
||||
if (!allowGlobal && id.equalsIgnoreCase("__global__")) { // Sorry, no global
|
||||
throw new CommandException(
|
||||
"Sorry, you can't use __global__ here.");
|
||||
}
|
||||
|
||||
checkName(id, allowGlobal);
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a region namespace.
|
||||
*
|
||||
* @param namespace the namespace name
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
protected static void checkNamespace(String namespace) throws CommandException {
|
||||
if (!RegionIdentifier.isValidNamespace(namespace)) {
|
||||
throw new CommandException(
|
||||
"The region namespace of '" + namespace + "' contains characters that are not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unqualified name from a possibly qualified region identifier.
|
||||
*
|
||||
* @param id the unprocessed region identifier
|
||||
* @return the unqualified name, or an empty string if not present
|
||||
*/
|
||||
protected static String getUnqualifiedName(String id) {
|
||||
int namespaceSeparatorIndex = id.lastIndexOf(':');
|
||||
if (namespaceSeparatorIndex == -1) {
|
||||
return id;
|
||||
}
|
||||
|
||||
int unqualifiedNameStartIndex = namespaceSeparatorIndex + 1;
|
||||
if (unqualifiedNameStartIndex == id.length()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return id.substring(unqualifiedNameStartIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespace name from a possibly qualified region identifier.
|
||||
*
|
||||
* @param id the unprocessed region identifier
|
||||
* @return an optional containing the namespace name, or an empty string if qualified,
|
||||
* if not qualified, an empty optional is returned
|
||||
*/
|
||||
protected static Optional<String> getNamespace(String id) {
|
||||
int namespaceSeparatorIndex = id.lastIndexOf(':');
|
||||
if (namespaceSeparatorIndex == -1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(id.substring(0, namespaceSeparatorIndex));
|
||||
}
|
||||
|
||||
private static class InvalidMacroException extends RuntimeException {
|
||||
public InvalidMacroException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Expand macros in the namespace name.
|
||||
*
|
||||
* @param namespace the unexpanded namespace name
|
||||
* @return the expanded namespace name
|
||||
*/
|
||||
protected static String expandNamespace(String namespace) {
|
||||
if (namespace.startsWith("#")) {
|
||||
String playerName = namespace.substring(1);
|
||||
|
||||
try {
|
||||
Profile profile = WorldGuard.getInstance().getProfileService().findByName(playerName);
|
||||
if (profile != null) {
|
||||
return profile.getUniqueId().toString();
|
||||
}
|
||||
} catch (InterruptedException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new InvalidMacroException("Macro unresolvable: " + namespace);
|
||||
}
|
||||
|
||||
return namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the macro expanded namespace name from a possibly qualified region identifier.
|
||||
*
|
||||
* @param id the unprocessed region identifier
|
||||
* @return an optional containing the expanded namespace name, or an empty string if qualified,
|
||||
* if not qualified, an empty optional is returned
|
||||
*/
|
||||
protected static Optional<String> getExpandedNamespace(String id) throws CommandException {
|
||||
try {
|
||||
return getNamespace(id).map(RegionCommandsBase::expandNamespace);
|
||||
} catch (InvalidMacroException ex) {
|
||||
throw new CommandException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default namespace for a given actor.
|
||||
*
|
||||
* @param sender the sender who's default namespace we intend to retrieve.
|
||||
* @return the default namespace
|
||||
*/
|
||||
protected static String getDefaultNamespace(Actor sender) {
|
||||
if (sender instanceof LocalPlayer) {
|
||||
return ((LocalPlayer) sender).getDefaultNamespace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a possibly qualified region identifier into a RegionIdentifier.
|
||||
*
|
||||
* This method takes a possibly qualified region identifier, and processes it, expanding any namespace macros,
|
||||
* running permissions checks, and validating the names for invalid character.
|
||||
*
|
||||
* @param sender the contextual sender to use for checks and macro expansions
|
||||
* @param id the possibly unqualified id
|
||||
* @param allowGlobal whether or not this method should allow use of the name __global__ name
|
||||
* @return the processed region id
|
||||
* @throws AuthorizationException if a permission check fails
|
||||
* @throws CommandException if a name validation check fails
|
||||
*/
|
||||
protected static RegionIdentifier processRegionId(Actor sender, String id, boolean allowGlobal) throws AuthorizationException, CommandException {
|
||||
String unqualifiedName = getUnqualifiedName(id);
|
||||
checkName(unqualifiedName, allowGlobal);
|
||||
|
||||
Optional<String> optProvidedNamespace = getExpandedNamespace(id);
|
||||
String namespace = optProvidedNamespace.orElse(getDefaultNamespace(sender));
|
||||
|
||||
// TODO use more informative permission checks
|
||||
|
||||
// This needs checked as a special case, before namespace name validation.
|
||||
if (namespace.equals("")) {
|
||||
sender.checkPermission("worldguard.region.namespace.global");
|
||||
return new RegionIdentifier(null, unqualifiedName);
|
||||
}
|
||||
|
||||
checkNamespace(namespace);
|
||||
|
||||
try {
|
||||
UUID namespacePlayerId = UUID.fromString(namespace);
|
||||
if (!namespacePlayerId.equals(sender.getUniqueId())) {
|
||||
sender.checkPermission("worldguard.region.namespace.player");
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.checkPermission("worldguard.region.namespace.custom." + namespace);
|
||||
}
|
||||
|
||||
return new RegionIdentifier(namespace, unqualifiedName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a protected region by a given name, otherwise throw a
|
||||
* {@link CommandException}.
|
||||
@@ -146,6 +290,7 @@ class RegionCommandsBase {
|
||||
* @param allowGlobal true to allow selecting __global__
|
||||
* @throws CommandException thrown if no region is found by the given name
|
||||
*/
|
||||
@Deprecated
|
||||
protected static ProtectedRegion checkExistingRegion(RegionManager regionManager, String id, boolean allowGlobal) throws CommandException {
|
||||
// Validate the id
|
||||
checkRegionId(id, allowGlobal);
|
||||
@@ -168,6 +313,36 @@ class RegionCommandsBase {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a protected region by a given name, otherwise throw a
|
||||
* {@link CommandException}.
|
||||
*
|
||||
* <p>This also validates the region ID.</p>
|
||||
*
|
||||
* @param actor the associated player
|
||||
* @param regionManager the region manager
|
||||
* @param id the name to search
|
||||
* @throws CommandException thrown if no region is found by the given name
|
||||
*/
|
||||
protected static ProtectedRegion checkExistingRegion(Actor actor, RegionManager regionManager, RegionIdentifier id) throws CommandException {
|
||||
ProtectedRegion region = regionManager.getRegion(id);
|
||||
|
||||
// No region found!
|
||||
if (region == null) {
|
||||
// But we want a __global__, so let's create one
|
||||
if (id.getQualifiedName().equals(":__global__")) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
regionManager.addRegion(region);
|
||||
return region;
|
||||
}
|
||||
|
||||
throw new CommandException(
|
||||
"No region could be found with the name of '" + id.getDisplayName(actor) + "'.");
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the region at the player's location, if possible.
|
||||
@@ -222,10 +397,12 @@ class RegionCommandsBase {
|
||||
builder.append(TextComponent.of(", "));
|
||||
}
|
||||
first = false;
|
||||
TextComponent regionComp = TextComponent.of(region.getId(), TextColor.AQUA);
|
||||
|
||||
RegionIdentifier id = region.getIdentifier();
|
||||
TextComponent regionComp = TextComponent.of(id.getDisplayName(player), TextColor.AQUA);
|
||||
if (rgCmd != null && rgCmd.contains("%id%")) {
|
||||
regionComp = regionComp.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to pick this region")))
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, rgCmd.replace("%id%", region.getId())));
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, rgCmd.replace("%id%", id.getQualifiedName())));
|
||||
}
|
||||
builder.append(regionComp);
|
||||
}
|
||||
@@ -237,24 +414,21 @@ class RegionCommandsBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a WorldEdit selection for an actor, or emit an exception if there is none
|
||||
* Get a WorldEdit selection for a player, or emit an exception if there is none
|
||||
* available.
|
||||
*
|
||||
* @param actor the actor
|
||||
* @param player the player
|
||||
* @return the selection
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
protected static Region checkSelection(Actor actor) throws CommandException {
|
||||
LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
protected static Region checkSelection(LocalPlayer player) throws CommandException {
|
||||
try {
|
||||
if (localSession == null || localSession.getSelectionWorld() == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
return localSession.getRegionSelector(localSession.getSelectionWorld()).getRegion();
|
||||
return WorldEdit.getInstance().getSessionManager().get(player).getRegionSelector(player.getWorld()).getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new CommandException("Please select an area first. " +
|
||||
"Use WorldEdit to make a selection! " +
|
||||
"(see: https://worldedit.enginehub.org/en/latest/usage/regions/selections/).");
|
||||
throw new CommandException(
|
||||
"Please select an area first. " +
|
||||
"Use WorldEdit to make a selection! " +
|
||||
"(see: https://worldedit.enginehub.org/en/latest/usage/regions/selections/).");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,10 +439,23 @@ class RegionCommandsBase {
|
||||
* @param id the ID
|
||||
* @throws CommandException thrown if the ID already exists
|
||||
*/
|
||||
@Deprecated
|
||||
protected static void checkRegionDoesNotExist(RegionManager manager, String id, boolean mayRedefine) throws CommandException {
|
||||
checkRegionDoesNotExist(null, manager, new RegionIdentifier(id), mayRedefine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a region with the given ID does not already exist.
|
||||
*
|
||||
* @param actor the associated player
|
||||
* @param manager the manager
|
||||
* @param id the identifier
|
||||
* @throws CommandException thrown if the ID already exists
|
||||
*/
|
||||
protected static void checkRegionDoesNotExist(Actor actor, RegionManager manager, RegionIdentifier id, boolean mayRedefine) throws CommandException {
|
||||
if (manager.hasRegion(id)) {
|
||||
throw new CommandException("A region with that name already exists. Please choose another name." +
|
||||
(mayRedefine ? " To change the shape, use /region redefine " + id + "." : ""));
|
||||
(mayRedefine ? " To change the shape, use /region redefine " + id.getDisplayName(actor) + "." : ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,15 +481,28 @@ class RegionCommandsBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link ProtectedRegion} from the actor's selection.
|
||||
* Create a {@link ProtectedRegion} from the player's selection.
|
||||
*
|
||||
* @param actor the actor
|
||||
* @param player the player
|
||||
* @param id the ID of the new region
|
||||
* @return a new region
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
protected static ProtectedRegion checkRegionFromSelection(Actor actor, String id) throws CommandException {
|
||||
Region selection = checkSelection(actor);
|
||||
@Deprecated
|
||||
protected static ProtectedRegion checkRegionFromSelection(LocalPlayer player, String id) throws CommandException {
|
||||
return checkRegionFromSelection(player, new RegionIdentifier(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link ProtectedRegion} from the player's selection.
|
||||
*
|
||||
* @param player the player
|
||||
* @param id the identifier of the new region
|
||||
* @return a new region
|
||||
* @throws CommandException thrown on an error
|
||||
*/
|
||||
protected static ProtectedRegion checkRegionFromSelection(LocalPlayer player, RegionIdentifier id) throws CommandException {
|
||||
Region selection = checkSelection(player);
|
||||
|
||||
// Detect the type of region from WorldEdit
|
||||
if (selection instanceof Polygonal2DRegion) {
|
||||
@@ -344,9 +544,6 @@ class RegionCommandsBase {
|
||||
* @param region the region
|
||||
*/
|
||||
protected static void warnAboutDimensions(Actor sender, ProtectedRegion region) {
|
||||
if (region instanceof GlobalProtectedRegion) {
|
||||
return;
|
||||
}
|
||||
int height = region.getMaximumPoint().getBlockY() - region.getMinimumPoint().getBlockY();
|
||||
if (height <= 2) {
|
||||
sender.printDebug("(Warning: The height of the region was " + (height + 1) + " block(s).)");
|
||||
@@ -375,38 +572,56 @@ class RegionCommandsBase {
|
||||
* @param world the world the region is in
|
||||
* @param region the region
|
||||
*/
|
||||
protected static boolean checkSpawnOverlap(Actor sender, World world, ProtectedRegion region) {
|
||||
protected static void checkSpawnOverlap(Actor sender, World world, ProtectedRegion region) {
|
||||
ProtectedRegion spawn = WorldGuard.getInstance().getPlatform().getSpawnProtection(world);
|
||||
if (spawn != null) {
|
||||
if (!spawn.getIntersectingRegions(ImmutableList.of(region)).isEmpty()) {
|
||||
sender.print(ErrorFormat.wrap("Warning!")
|
||||
.append(TextComponent.of(" This region overlaps vanilla's spawn protection. WorldGuard cannot " +
|
||||
"override this, and only server operators will be able to interact with this area.", TextColor.WHITE)));
|
||||
return true;
|
||||
"override this, and only server operators will be able to interact with this area.")));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an actor's selection to a given region.
|
||||
* Set a player's selection to a given region.
|
||||
*
|
||||
* @param actor the actor
|
||||
* @param player the player
|
||||
* @param region the region
|
||||
* @throws CommandException thrown on a command error
|
||||
*/
|
||||
protected static void setPlayerSelection(Actor actor, ProtectedRegion region, World world) throws CommandException {
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
protected static void setPlayerSelection(LocalPlayer player, ProtectedRegion region) throws CommandException {
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
|
||||
|
||||
// Set selection
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region;
|
||||
BlockVector3 pt1 = cuboid.getMinimumPoint();
|
||||
BlockVector3 pt2 = cuboid.getMaximumPoint();
|
||||
|
||||
CuboidRegionSelector selector = new CuboidRegionSelector(player.getWorld(), pt1, pt2);
|
||||
session.setRegionSelector(player.getWorld(), selector);
|
||||
selector.explainRegionAdjust(player, session);
|
||||
player.print("Region selected as a cuboid.");
|
||||
|
||||
} else if (region instanceof ProtectedPolygonalRegion) {
|
||||
ProtectedPolygonalRegion poly2d = (ProtectedPolygonalRegion) region;
|
||||
Polygonal2DRegionSelector selector = new Polygonal2DRegionSelector(
|
||||
player.getWorld(), poly2d.getPoints(),
|
||||
poly2d.getMinimumPoint().getBlockY(),
|
||||
poly2d.getMaximumPoint().getBlockY());
|
||||
session.setRegionSelector(player.getWorld(), selector);
|
||||
selector.explainRegionAdjust(player, session);
|
||||
player.print("Region selected as a polygon.");
|
||||
|
||||
} else if (region instanceof GlobalProtectedRegion) {
|
||||
throw new CommandException(
|
||||
"Can't select global regions! " +
|
||||
"That would cover the entire world.");
|
||||
|
||||
RegionSelector selector = WorldEditRegionConverter.convertToSelector(region);
|
||||
if (selector != null) {
|
||||
selector.setWorld(world);
|
||||
session.setRegionSelector(world, selector);
|
||||
selector.explainRegionAdjust(actor, session);
|
||||
actor.print("Region selected as " + region.getType().getName());
|
||||
} else {
|
||||
throw new CommandException("Can't select that region! " +
|
||||
"The region type '" + region.getType().getName() + "' can't be selected.");
|
||||
throw new CommandException("Unknown region type: " +
|
||||
region.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-20
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.commands.region;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.registry.UnknownFlag;
|
||||
import com.sk89q.worldguard.protection.regions.RegionIdentifier;
|
||||
import com.sk89q.worldguard.util.profile.cache.ProfileCache;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@@ -59,6 +59,7 @@ public class RegionPrintoutBuilder implements Callable<TextComponent> {
|
||||
@Nullable
|
||||
private final ProfileCache cache;
|
||||
private final TextComponentProducer builder = new TextComponentProducer();
|
||||
private final Actor actor;
|
||||
private final RegionPermissionModel perms;
|
||||
|
||||
/**
|
||||
@@ -71,6 +72,7 @@ public class RegionPrintoutBuilder implements Callable<TextComponent> {
|
||||
this.world = world;
|
||||
this.region = region;
|
||||
this.cache = cache;
|
||||
this.actor = actor;
|
||||
this.perms = actor != null && actor.isPlayer() ? new RegionPermissionModel(actor) : null;
|
||||
}
|
||||
|
||||
@@ -86,8 +88,10 @@ public class RegionPrintoutBuilder implements Callable<TextComponent> {
|
||||
*/
|
||||
public void appendBasics() {
|
||||
builder.append(TextComponent.of("Region: ", TextColor.BLUE));
|
||||
builder.append(TextComponent.of(region.getId(), TextColor.YELLOW)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg info -w \"" + world + "\" " + region.getId())));
|
||||
|
||||
RegionIdentifier id = region.getIdentifier();
|
||||
builder.append(TextComponent.of(id.getDisplayName(actor), TextColor.YELLOW)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg info -w \"" + world + "\" " + id.getQualifiedName())));
|
||||
|
||||
builder.append(TextComponent.of(" (type=", TextColor.GRAY));
|
||||
builder.append(TextComponent.of(region.getType().getName()));
|
||||
@@ -144,22 +148,8 @@ public class RegionPrintoutBuilder implements Callable<TextComponent> {
|
||||
flagString = flag.getName() + " -g " + group + ": ";
|
||||
}
|
||||
|
||||
TextColor flagColor = TextColor.WHITE;
|
||||
if (useColors) {
|
||||
// passthrough is ok on global
|
||||
if (FlagHelperBox.DANGER_ZONE.contains(flag)
|
||||
&& !(region.getId().equals(ProtectedRegion.GLOBAL_REGION) && flag == Flags.PASSTHROUGH)) {
|
||||
flagColor = TextColor.DARK_RED;
|
||||
} else if (Flags.INBUILT_FLAGS.contains(flag.getName())) {
|
||||
flagColor = TextColor.GOLD;
|
||||
} else if (flag instanceof UnknownFlag) {
|
||||
flagColor = TextColor.GRAY;
|
||||
} else {
|
||||
flagColor = TextColor.LIGHT_PURPLE;
|
||||
}
|
||||
}
|
||||
TextComponent flagText = TextComponent.of(flagString, flagColor)
|
||||
.append(TextComponent.of(String.valueOf(val), useColors ? TextColor.YELLOW : TextColor.WHITE));
|
||||
TextComponent flagText = TextComponent.of(flagString, useColors ? TextColor.GOLD : TextColor.WHITE)
|
||||
.append(TextComponent.of(String.valueOf(val), useColors? TextColor.YELLOW : TextColor.WHITE));
|
||||
if (perms != null && perms.maySetFlag(region, flag)) {
|
||||
flagText = flagText.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to set flag")))
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND,
|
||||
@@ -320,7 +310,7 @@ public class RegionPrintoutBuilder implements Callable<TextComponent> {
|
||||
builder.append(TextComponent.space().append(TextComponent.of("[Teleport]", TextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT,
|
||||
TextComponent.of("Click to teleport").append(TextComponent.newline()).append(
|
||||
TextComponent.of(teleFlag.getBlockX() + ", "
|
||||
TextComponent.of(teleFlag.getBlockY() + ", "
|
||||
+ teleFlag.getBlockY() + ", "
|
||||
+ teleFlag.getBlockZ()))))
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND,
|
||||
|
||||
@@ -76,9 +76,7 @@ public abstract class ConfigurationManager {
|
||||
public boolean migrateRegionsToUuid;
|
||||
public boolean keepUnresolvedNames;
|
||||
public boolean particleEffects;
|
||||
public boolean disablePermissionCache;
|
||||
public boolean disableDefaultBypass;
|
||||
public boolean announceBypassStatus;
|
||||
public boolean useNamespaces;
|
||||
|
||||
@Unreported public Map<String, String> hostKeys = new HashMap<>();
|
||||
public boolean hostKeysAllowFMLClients;
|
||||
|
||||
@@ -105,7 +105,6 @@ public abstract class WorldConfiguration {
|
||||
public boolean blockEntityPaintingDestroy;
|
||||
public boolean blockEntityItemFrameDestroy;
|
||||
public boolean blockEntityArmorStandDestroy;
|
||||
public boolean blockEntityVehicleEntry;
|
||||
public boolean blockPluginSpawning;
|
||||
public boolean blockGroundSlimes;
|
||||
public boolean blockZombieDoorDestruction;
|
||||
@@ -136,8 +135,6 @@ public abstract class WorldConfiguration {
|
||||
public boolean removeInfiniteStacks;
|
||||
public boolean disableCreatureCropTrampling;
|
||||
public boolean disablePlayerCropTrampling;
|
||||
public boolean disableCreatureTurtleEggTrampling;
|
||||
public boolean disablePlayerTurtleEggTrampling;
|
||||
public boolean preventLightningFire;
|
||||
public Set<String> disallowedLightningBlocks;
|
||||
public boolean disableThunder;
|
||||
@@ -161,20 +158,16 @@ public abstract class WorldConfiguration {
|
||||
public boolean disableEndermanGriefing;
|
||||
public boolean disableSnowmanTrails;
|
||||
public boolean disableSoilDehydration;
|
||||
public boolean disableCoralBlockFade;
|
||||
public Set<String> allowedSnowFallOver;
|
||||
public boolean regionInvinciblityRemovesMobs;
|
||||
public boolean regionCancelEmptyChatEvents;
|
||||
public boolean regionNetherPortalProtection;
|
||||
public boolean forceDefaultTitleTimes;
|
||||
public boolean fakePlayerBuildOverride;
|
||||
public boolean explosionFlagCancellation;
|
||||
public boolean disableDeathMessages;
|
||||
public boolean disableObsidianGenerators;
|
||||
public boolean strictEntitySpawn;
|
||||
public boolean ignoreHopperMoveEvents;
|
||||
public boolean breakDeniedHoppers;
|
||||
public boolean useMaxPriorityAssociation;
|
||||
protected Map<String, Integer> maxRegionCounts;
|
||||
|
||||
/**
|
||||
|
||||
+1
-4
@@ -56,9 +56,6 @@ public abstract class YamlConfigurationManager extends ConfigurationManager {
|
||||
migrateRegionsToUuid = config.getBoolean("regions.uuid-migration.perform-on-next-start", true);
|
||||
keepUnresolvedNames = config.getBoolean("regions.uuid-migration.keep-names-that-lack-uuids", true);
|
||||
useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
|
||||
disableDefaultBypass = config.getBoolean("regions.disable-bypass-by-default", false);
|
||||
announceBypassStatus = config.getBoolean("regions.announce-bypass-status", false);
|
||||
|
||||
useGodPermission = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
|
||||
useGodGroup = config.getBoolean("auto-invincible-group", false);
|
||||
useAmphibiousGroup = config.getBoolean("auto-no-drowning-group", false);
|
||||
@@ -66,7 +63,7 @@ public abstract class YamlConfigurationManager extends ConfigurationManager {
|
||||
usePlayerMove = config.getBoolean("use-player-move-event", true);
|
||||
usePlayerTeleports = config.getBoolean("use-player-teleports", true);
|
||||
particleEffects = config.getBoolean("use-particle-effects", true);
|
||||
disablePermissionCache = config.getBoolean("disable-permission-cache", false);
|
||||
useNamespaces = config.getBoolean("use-namespaces", true);
|
||||
|
||||
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
|
||||
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
|
||||
|
||||
@@ -311,7 +311,7 @@ public class DefaultDomain implements Domain, ChangeTracked {
|
||||
public String toGroupsString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Iterator<String> it = groupDomain.getGroups().iterator(); it.hasNext(); ) {
|
||||
str.append("g:");
|
||||
str.append("*");
|
||||
str.append(it.next());
|
||||
if (it.hasNext()) {
|
||||
str.append(", ");
|
||||
@@ -373,8 +373,7 @@ public class DefaultDomain implements Domain, ChangeTracked {
|
||||
private Component toGroupsComponent() {
|
||||
final TextComponent.Builder builder = TextComponent.builder("");
|
||||
for (Iterator<String> it = groupDomain.getGroups().iterator(); it.hasNext(); ) {
|
||||
builder.append(TextComponent.of("g:", TextColor.GRAY))
|
||||
.append(TextComponent.of(it.next(), TextColor.GOLD));
|
||||
builder.append(TextComponent.of(it.next(), TextColor.GOLD));
|
||||
if (it.hasNext()) {
|
||||
builder.append(TextComponent.of(", "));
|
||||
}
|
||||
|
||||
@@ -73,9 +73,7 @@ public class PlayerDomain implements Domain, ChangeTracked {
|
||||
* Add the given player to the domain, identified by the player's name.
|
||||
*
|
||||
* @param name the name of the player
|
||||
* @deprecated names are deprecated in favor of UUIDs in MC 1.7+
|
||||
*/
|
||||
@Deprecated
|
||||
public void addPlayer(String name) {
|
||||
checkNotNull(name);
|
||||
if (!name.trim().isEmpty()) {
|
||||
@@ -113,9 +111,7 @@ public class PlayerDomain implements Domain, ChangeTracked {
|
||||
* Remove the given player from the domain, identified by the player's name.
|
||||
*
|
||||
* @param name the name of the player
|
||||
* @deprecated names are deprecated in favor of UUIDs in MC 1.7+
|
||||
*/
|
||||
@Deprecated
|
||||
public void removePlayer(String name) {
|
||||
checkNotNull(name);
|
||||
setDirty(true);
|
||||
@@ -149,16 +145,14 @@ public class PlayerDomain implements Domain, ChangeTracked {
|
||||
@Override
|
||||
public boolean contains(LocalPlayer player) {
|
||||
checkNotNull(player);
|
||||
return contains(player.getUniqueId()) || (!names.isEmpty() && contains(player.getName()));
|
||||
return contains(player.getName().trim().toLowerCase()) || contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of player names.
|
||||
*
|
||||
* @return the set of player names
|
||||
* @deprecated names are deprecated in favor of UUIDs in MC 1.7+
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<String> getPlayers() {
|
||||
return Collections.unmodifiableSet(names);
|
||||
}
|
||||
|
||||
+1
@@ -26,6 +26,7 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionIdentifier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
-46
@@ -23,8 +23,6 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
@@ -121,50 +119,6 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
|
||||
@Nullable
|
||||
<V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag);
|
||||
|
||||
/**
|
||||
* Get the effective value for a key in a {@link MapFlag}. If there are multiple values
|
||||
* (for example, if there are multiple regions with the same priority
|
||||
* but with different farewell messages set, there would be multiple
|
||||
* completing values), then the selected (or "winning") value will be undefined.
|
||||
*
|
||||
* <p>A subject can be provided that is used to determine whether the value
|
||||
* of a flag on a particular region should be used. For example, if a
|
||||
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
|
||||
* subject is not a member, then the region would be skipped when
|
||||
* querying that flag. If {@code null} is provided for the subject, then
|
||||
* only flags that use {@link RegionGroup#ALL},
|
||||
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.</p>
|
||||
*
|
||||
* @param subject an optional subject, which would be used to determine the region group to apply
|
||||
* @param flag the flag of type {@link MapFlag}
|
||||
* @param key the key for the map flag
|
||||
* @return a value, which could be {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
<V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key);
|
||||
|
||||
/**
|
||||
* Get the effective value for a key in a {@link MapFlag}. If there are multiple values
|
||||
* (for example, if there are multiple regions with the same priority
|
||||
* but with different farewell messages set, there would be multiple
|
||||
* completing values), then the selected (or "winning") value will be undefined.
|
||||
*
|
||||
* <p>A subject can be provided that is used to determine whether the value
|
||||
* of a flag on a particular region should be used. For example, if a
|
||||
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
|
||||
* subject is not a member, then the region would be skipped when
|
||||
* querying that flag. If {@code null} is provided for the subject, then
|
||||
* only flags that use {@link RegionGroup#ALL},
|
||||
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.</p>
|
||||
*
|
||||
* @param subject an optional subject, which would be used to determine the region group to apply
|
||||
* @param flag the flag of type {@link MapFlag}
|
||||
* @param key the key for the map flag
|
||||
* @return a value, which could be {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
<V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, @Nullable Flag<V> fallback);
|
||||
|
||||
/**
|
||||
* Get the effective values for a flag, returning a collection of all
|
||||
* values. It is up to the caller to determine which value, if any,
|
||||
|
||||
+36
-5
@@ -21,8 +21,16 @@ package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
@@ -30,18 +38,41 @@ import java.util.List;
|
||||
*
|
||||
* <p>This class only performs a spatial query if its
|
||||
* {@link #getAssociation(List)} method is called.</p>
|
||||
*
|
||||
* @deprecated Use {@link com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation} instead. This class is mis-packaged.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DelayedRegionOverlapAssociation extends com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation {
|
||||
public class DelayedRegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
private final RegionQuery query;
|
||||
private final Location location;
|
||||
@Nullable
|
||||
private Set<ProtectedRegion> source;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
|
||||
super(query, location, false);
|
||||
checkNotNull(query);
|
||||
checkNotNull(location);
|
||||
this.query = query;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
if (source == null) {
|
||||
ApplicableRegionSet result = query.getApplicableRegions(location);
|
||||
source = result.getRegions();
|
||||
}
|
||||
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
|
||||
}
|
||||
-15
@@ -24,7 +24,6 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
@@ -32,7 +31,6 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -67,19 +65,6 @@ public class FailedLoadRegionSet extends AbstractRegionSet {
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key) {
|
||||
return queryMapValue(subject, flag, key, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, @Nullable Flag<V> fallback) {
|
||||
Map<K, V> defaultVal = flag.getDefault();
|
||||
return defaultVal != null ? defaultVal.get(key) : fallback != null ? fallback.getDefault() : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
|
||||
+11
-123
@@ -26,7 +26,6 @@ import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
@@ -90,14 +89,13 @@ public class FlagValueCalculator {
|
||||
/**
|
||||
* Return the membership status of the given subject, indicating
|
||||
* whether there are no (counted) regions in the list of regions,
|
||||
* whether the subject is a member of all (counted) regions, or
|
||||
* whether the subject is not a member of all (counted) regions.
|
||||
* whether the subject is a member of all regions, or whether
|
||||
* the region is not a member of all regions.
|
||||
*
|
||||
* <p>A region is "counted" if it doesn't have the
|
||||
* {@link Flags#PASSTHROUGH} flag set to {@code ALLOW} and if
|
||||
* there isn't another "counted" region with a higher priority.
|
||||
* (The explicit purpose of the PASSTHROUGH flag is to have the
|
||||
* region be skipped over in this check.)</p>
|
||||
* {@link Flags#PASSTHROUGH} flag set to {@code ALLOW}. (The
|
||||
* explicit purpose of the PASSTHROUGH flag is to have the region
|
||||
* be skipped over in this check.)</p>
|
||||
*
|
||||
* <p>This method is mostly for internal use. It's not particularly
|
||||
* useful.</p>
|
||||
@@ -114,13 +112,11 @@ public class FlagValueCalculator {
|
||||
Set<ProtectedRegion> ignoredRegions = Sets.newHashSet();
|
||||
|
||||
for (ProtectedRegion region : getApplicable()) {
|
||||
int priority = getPriority(region);
|
||||
|
||||
// Don't consider lower priorities below minimumPriority
|
||||
// (which starts at Integer.MIN_VALUE). A region that "counts"
|
||||
// (has the flag set OR has members) will raise minimumPriority
|
||||
// to its own priority.
|
||||
if (priority < minimumPriority) {
|
||||
if (getPriority(region) < minimumPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -133,7 +129,7 @@ public class FlagValueCalculator {
|
||||
continue;
|
||||
}
|
||||
|
||||
minimumPriority = priority;
|
||||
minimumPriority = getPriority(region);
|
||||
|
||||
boolean member = RegionGroup.MEMBERS.contains(subject.getAssociation(Collections.singletonList(region)));
|
||||
|
||||
@@ -228,112 +224,6 @@ public class FlagValueCalculator {
|
||||
return flag.chooseValue(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective value for a key in a {@link MapFlag}. If there are multiple values
|
||||
* (for example, if there are multiple regions with the same priority
|
||||
* but with different farewell messages set, there would be multiple
|
||||
* completing values), then the selected (or "winning") value will be undefined.
|
||||
*
|
||||
* <p>A subject can be provided that is used to determine whether the value
|
||||
* of a flag on a particular region should be used. For example, if a
|
||||
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
|
||||
* subject is not a member, then the region would be skipped when
|
||||
* querying that flag. If {@code null} is provided for the subject, then
|
||||
* only flags that use {@link RegionGroup#ALL},
|
||||
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.</p>
|
||||
*
|
||||
* @param subject an optional subject, which would be used to determine the region group to apply
|
||||
* @param flag the flag of type {@link MapFlag}
|
||||
* @param key the key for the map flag
|
||||
* @return a value, which could be {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, Flag<V> fallback) {
|
||||
checkNotNull(flag);
|
||||
checkNotNull(key);
|
||||
|
||||
Map<ProtectedRegion, V> consideredValues = new HashMap<>();
|
||||
Map<ProtectedRegion, V> fallbackValues = new HashMap<>();
|
||||
int minimumPriority = Integer.MIN_VALUE;
|
||||
Set<ProtectedRegion> ignoredParents = new HashSet<>();
|
||||
|
||||
for(ProtectedRegion region : getApplicable()) {
|
||||
int priority = getPriority(region);
|
||||
|
||||
if (priority < minimumPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ignoredParents.contains(region)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
V effectiveValue = getEffectiveMapValue(region, flag, key, subject);
|
||||
|
||||
if (effectiveValue != null) {
|
||||
minimumPriority = priority;
|
||||
consideredValues.put(region, effectiveValue);
|
||||
} else if (fallback != null) {
|
||||
effectiveValue = getEffectiveFlag(region, fallback, subject);
|
||||
if (effectiveValue != null) {
|
||||
minimumPriority = priority;
|
||||
fallbackValues.put(region, effectiveValue);
|
||||
}
|
||||
}
|
||||
|
||||
addParents(ignoredParents, region);
|
||||
}
|
||||
|
||||
|
||||
if (consideredValues.isEmpty()) {
|
||||
if (fallback != null && !fallbackValues.isEmpty()) {
|
||||
return fallback.chooseValue(fallbackValues.values());
|
||||
}
|
||||
V defaultValue = flag.getValueFlag().getDefault();
|
||||
return defaultValue != null ? defaultValue : fallback != null ? fallback.getDefault() : null;
|
||||
}
|
||||
|
||||
return flag.getValueFlag().chooseValue(consideredValues.values());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private <V, K> V getEffectiveMapValue(ProtectedRegion region, MapFlag<K, V> mapFlag, K key, RegionAssociable subject) {
|
||||
List<ProtectedRegion> seen = new ArrayList<>();
|
||||
ProtectedRegion current = region;
|
||||
|
||||
while (current != null) {
|
||||
seen.add(current);
|
||||
|
||||
Map<K, V> mapValue = current.getFlag(mapFlag);
|
||||
|
||||
if (mapValue != null && mapValue.containsKey(key)) {
|
||||
boolean use = true;
|
||||
|
||||
if (mapFlag.getRegionGroupFlag() != null) {
|
||||
RegionGroup group = current.getFlag(mapFlag.getRegionGroupFlag());
|
||||
if (group == null) {
|
||||
group = mapFlag.getRegionGroupFlag().getDefault();
|
||||
}
|
||||
|
||||
if (group == null) {
|
||||
use = false;
|
||||
} else if (subject == null) {
|
||||
use = group.contains(Association.NON_MEMBER);
|
||||
} else if (!group.contains(subject.getAssociation(seen))) {
|
||||
use = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (use) {
|
||||
return mapValue.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
current = current.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective values for a flag, returning a collection of all
|
||||
* values. It is up to the caller to determine which value, if any,
|
||||
@@ -393,9 +283,7 @@ public class FlagValueCalculator {
|
||||
Set<ProtectedRegion> ignoredParents = new HashSet<>();
|
||||
|
||||
for (ProtectedRegion region : getApplicable()) {
|
||||
int priority = getPriority(region);
|
||||
|
||||
if (priority < minimumPriority) {
|
||||
if (getPriority(region) < minimumPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -404,6 +292,7 @@ public class FlagValueCalculator {
|
||||
}
|
||||
|
||||
V value = getEffectiveFlag(region, flag, subject);
|
||||
int priority = getPriority(region);
|
||||
|
||||
if (value != null) {
|
||||
minimumPriority = priority;
|
||||
@@ -421,7 +310,7 @@ public class FlagValueCalculator {
|
||||
// PASSTHROUGH is not set to ALLOW
|
||||
if (priority != minimumPriority && flag.implicitlySetWithMembership()
|
||||
&& getEffectiveFlag(region, Flags.PASSTHROUGH, subject) != State.ALLOW) {
|
||||
minimumPriority = priority;
|
||||
minimumPriority = getPriority(region);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,8 +361,7 @@ public class FlagValueCalculator {
|
||||
if (flag == Flags.PASSTHROUGH) {
|
||||
// Has members/owners -> the global region acts like
|
||||
// a regular region without PASSTHROUGH
|
||||
State passthrough = region.getFlag(Flags.PASSTHROUGH);
|
||||
if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) {
|
||||
if (region.hasMembersOrOwners() || region.getFlag(Flags.PASSTHROUGH) == State.DENY) {
|
||||
return null;
|
||||
} else {
|
||||
return (V) State.ALLOW;
|
||||
|
||||
-15
@@ -24,7 +24,6 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
@@ -32,7 +31,6 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -61,19 +59,6 @@ public class PermissiveRegionSet extends AbstractRegionSet {
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key) {
|
||||
return queryMapValue(subject, flag, key, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, @Nullable Flag<V> fallback) {
|
||||
Map<K, V> defaultVal = flag.getDefault();
|
||||
return defaultVal != null ? defaultVal.get(key) : fallback != null ? fallback.getDefault() : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
|
||||
@@ -22,7 +22,6 @@ package com.sk89q.worldguard.protection;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
@@ -109,18 +108,6 @@ public class RegionResultSet extends AbstractRegionSet {
|
||||
return flagValueCalculator.queryAllValues(subject, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key) {
|
||||
return flagValueCalculator.queryMapValue(subject, flag, key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <V, K> V queryMapValue(@Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, Flag<V> fallback) {
|
||||
return flagValueCalculator.queryMapValue(subject, flag, key, fallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwnerOfAll(LocalPlayer player) {
|
||||
checkNotNull(player);
|
||||
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.association;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractRegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
@Nullable
|
||||
protected Set<ProtectedRegion> source;
|
||||
private boolean useMaxPriorityAssociation;
|
||||
private int maxPriority;
|
||||
private Set<ProtectedRegion> maxPriorityRegions;
|
||||
|
||||
protected AbstractRegionOverlapAssociation(@Nullable Set<ProtectedRegion> source, boolean useMaxPriorityAssociation) {
|
||||
this.source = source;
|
||||
this.useMaxPriorityAssociation = useMaxPriorityAssociation;
|
||||
}
|
||||
|
||||
protected void calcMaxPriority() {
|
||||
checkNotNull(source);
|
||||
int best = 0;
|
||||
Set<ProtectedRegion> bestRegions = new HashSet<>();
|
||||
for (ProtectedRegion region : source) {
|
||||
int priority = region.getPriority();
|
||||
if (priority > best) {
|
||||
best = priority;
|
||||
bestRegions.clear();
|
||||
bestRegions.add(region);
|
||||
} else if (priority == best) {
|
||||
bestRegions.add(region);
|
||||
}
|
||||
}
|
||||
this.maxPriority = best;
|
||||
this.maxPriorityRegions = bestRegions;
|
||||
}
|
||||
|
||||
private boolean checkNonplayerProtectionDomains(Iterable<? extends ProtectedRegion> source, Collection<?> domains) {
|
||||
if (source == null || domains == null || domains.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ProtectedRegion region : source) {
|
||||
Set<String> regionDomains = region.getFlag(Flags.NONPLAYER_PROTECTION_DOMAINS);
|
||||
|
||||
if (regionDomains == null || regionDomains.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Collections.disjoint(regionDomains, domains)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
checkNotNull(source);
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty())) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
|
||||
if (source.contains(region)) {
|
||||
if (useMaxPriorityAssociation) {
|
||||
int priority = region.getPriority();
|
||||
if (priority == maxPriority) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
} else {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
Set<ProtectedRegion> source;
|
||||
|
||||
if (useMaxPriorityAssociation) {
|
||||
source = maxPriorityRegions;
|
||||
} else {
|
||||
source = this.source;
|
||||
}
|
||||
|
||||
if (checkNonplayerProtectionDomains(source, region.getFlag(Flags.NONPLAYER_PROTECTION_DOMAINS))) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.association;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
* region is in a set of source regions.
|
||||
*
|
||||
* <p>This class only performs a spatial query if its
|
||||
* {@link #getAssociation(List)} method is called.</p>
|
||||
*/
|
||||
public class DelayedRegionOverlapAssociation extends AbstractRegionOverlapAssociation {
|
||||
|
||||
private final RegionQuery query;
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
|
||||
this(query, location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
* @param useMaxPriorityAssociation whether to use the max priority from regions to determine association
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location, boolean useMaxPriorityAssociation) {
|
||||
super(null, useMaxPriorityAssociation);
|
||||
checkNotNull(query);
|
||||
checkNotNull(location);
|
||||
this.query = query;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
if (source == null) {
|
||||
ApplicableRegionSet result = query.getApplicableRegions(location);
|
||||
source = result.getRegions();
|
||||
calcMaxPriority();
|
||||
}
|
||||
|
||||
return super.getAssociation(regions);
|
||||
}
|
||||
|
||||
}
|
||||
+19
-13
@@ -19,35 +19,41 @@
|
||||
|
||||
package com.sk89q.worldguard.protection.association;
|
||||
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
* region is in a set of source regions.
|
||||
*/
|
||||
public class RegionOverlapAssociation extends AbstractRegionOverlapAssociation {
|
||||
public class RegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
private final Set<ProtectedRegion> source;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param source set of regions that input regions must be contained within
|
||||
*/
|
||||
public RegionOverlapAssociation(@Nonnull Set<ProtectedRegion> source) {
|
||||
this(source, false);
|
||||
public RegionOverlapAssociation(Set<ProtectedRegion> source) {
|
||||
checkNotNull(source);
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param source set of regions that input regions must be contained within
|
||||
* @param useMaxPriorityAssociation whether to use the max priority from regions to determine association
|
||||
*/
|
||||
public RegionOverlapAssociation(@Nonnull Set<ProtectedRegion> source, boolean useMaxPriorityAssociation) {
|
||||
super(source, useMaxPriorityAssociation);
|
||||
calcMaxPriority();
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
|
||||
}
|
||||
-2
@@ -26,9 +26,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores an entity type.
|
||||
* @deprecated replaced by {@link RegistryFlag<EntityType>}, will be removed in WorldGuard 8
|
||||
*/
|
||||
@Deprecated
|
||||
public class EntityTypeFlag extends Flag<EntityType> {
|
||||
|
||||
protected EntityTypeFlag(String name, @Nullable RegionGroup defaultGroup) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class FlagUtil {
|
||||
for (Entry<Flag<?>, Object> entry : values.entrySet()) {
|
||||
try {
|
||||
rawValues.put(entry.getKey().getName(), marshal(entry.getKey(), entry.getValue()));
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
log.log(Level.WARNING, "Failed to marshal flag value for " + entry.getKey() + "; value is " + entry.getValue(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ public final class Flags {
|
||||
|
||||
// Overrides membership check
|
||||
public static final StateFlag PASSTHROUGH = register(new StateFlag("passthrough", false));
|
||||
public static final SetFlag<String> NONPLAYER_PROTECTION_DOMAINS = register(new SetFlag<>("nonplayer-protection-domains", new StringFlag(null)));
|
||||
|
||||
// This flag is unlike the others. It forces the checking of region membership
|
||||
public static final StateFlag BUILD = register(new BuildFlag("build", true));
|
||||
@@ -61,7 +60,6 @@ public final class Flags {
|
||||
public static final StateFlag DAMAGE_ANIMALS = register(new StateFlag("damage-animals", false));
|
||||
public static final StateFlag PVP = register(new StateFlag("pvp", false));
|
||||
public static final StateFlag SLEEP = register(new StateFlag("sleep", false));
|
||||
public static final StateFlag RESPAWN_ANCHORS = register(new StateFlag("respawn-anchors", false));
|
||||
public static final StateFlag TNT = register(new StateFlag("tnt", false));
|
||||
public static final StateFlag CHEST_ACCESS = register(new StateFlag("chest-access", false));
|
||||
public static final StateFlag PLACE_VEHICLE = register(new StateFlag("vehicle-place", false));
|
||||
@@ -72,7 +70,6 @@ public final class Flags {
|
||||
public static final StateFlag ITEM_FRAME_ROTATE = register(new StateFlag("item-frame-rotation", false));
|
||||
public static final StateFlag TRAMPLE_BLOCKS = register(new StateFlag("block-trampling", false));
|
||||
public static final StateFlag FIREWORK_DAMAGE = register(new StateFlag("firework-damage", false));
|
||||
public static final StateFlag USE_ANVIL = register(new StateFlag("use-anvil", false));
|
||||
|
||||
// These flags are similar to the ones above (used in tandem with BUILD),
|
||||
// but their defaults are set to TRUE because it is more user friendly.
|
||||
@@ -121,7 +118,6 @@ public final class Flags {
|
||||
public static final StateFlag VINE_GROWTH = register(new StateFlag("vine-growth", true));
|
||||
public static final StateFlag CROP_GROWTH = register(new StateFlag("crop-growth", true));
|
||||
public static final StateFlag SOIL_DRY = register(new StateFlag("soil-dry", true));
|
||||
public static final StateFlag CORAL_FADE = register(new StateFlag("coral-fade", true));
|
||||
public static final StateFlag WATER_FLOW = register(new StateFlag("water-flow", true));
|
||||
public static final StateFlag LAVA_FLOW = register(new StateFlag("lava-flow", true));
|
||||
|
||||
@@ -135,23 +131,12 @@ public final class Flags {
|
||||
public static final SetFlag<String> ALLOWED_CMDS = register(new SetFlag<>("allowed-cmds", new CommandStringFlag(null)));
|
||||
|
||||
// locations
|
||||
public static final LocationFlag TELE_LOC = register(new LocationFlag("teleport"));
|
||||
public static final LocationFlag TELE_LOC = register(new LocationFlag("teleport", RegionGroup.MEMBERS));
|
||||
public static final LocationFlag SPAWN_LOC = register(new LocationFlag("spawn", RegionGroup.MEMBERS));
|
||||
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag TELE_MESSAGE = register(new StringFlag("teleport-message",
|
||||
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of(
|
||||
"Teleported you to the region '%id%'.", TextColor.LIGHT_PURPLE)))));
|
||||
|
||||
// idk?
|
||||
public static final StateFlag INVINCIBILITY = register(new StateFlag("invincible", false));
|
||||
public static final StateFlag FALL_DAMAGE = register(new StateFlag("fall-damage", true));
|
||||
public static final StateFlag HEALTH_REGEN = register(new StateFlag("natural-health-regen", true));
|
||||
public static final StateFlag HUNGER_DRAIN = register(new StateFlag("natural-hunger-drain", true));
|
||||
|
||||
// session and movement based flags
|
||||
public static final StateFlag ENTRY = register(new StateFlag("entry", true, RegionGroup.NON_MEMBERS));
|
||||
@@ -162,29 +147,9 @@ public final class Flags {
|
||||
public static final StateFlag ENDERPEARL = register(new StateFlag("enderpearl", true));
|
||||
public static final StateFlag CHORUS_TELEPORT = register(new StateFlag("chorus-fruit-teleport", true));
|
||||
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag GREET_MESSAGE = register(new StringFlag("greeting"));
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag FAREWELL_MESSAGE = register(new StringFlag("farewell"));
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag GREET_TITLE = register(new StringFlag("greeting-title"));
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag FAREWELL_TITLE = register(new StringFlag("farewell-title"));
|
||||
|
||||
public static final BooleanFlag NOTIFY_ENTER = register(new BooleanFlag("notify-enter"));
|
||||
@@ -208,29 +173,14 @@ public final class Flags {
|
||||
public static final IntegerFlag MAX_FOOD = register(new IntegerFlag("feed-max-hunger"), f -> f.setSuggestedValues(VITALS_MAXS));
|
||||
|
||||
// deny messages
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag DENY_MESSAGE = register(new StringFlag("deny-message",
|
||||
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
|
||||
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
|
||||
.append(TextComponent.of(" Sorry, but you can't %what% here.", TextColor.GRAY)))));
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag ENTRY_DENY_MESSAGE = register(new StringFlag("entry-deny-message",
|
||||
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
|
||||
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
|
||||
.append(TextComponent.of(" You are not permitted to enter this area.", TextColor.GRAY)))));
|
||||
/**
|
||||
* @deprecated The type of this flag will change from a StringFlag to a ComponentFlag to support JSON text
|
||||
* in a future release. If you depend on the type of this flag, take proper precaution for future breakage.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final StringFlag EXIT_DENY_MESSAGE = register(new StringFlag("exit-deny-message",
|
||||
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
|
||||
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
|
||||
|
||||
-5
@@ -24,11 +24,6 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores an gamemode type.
|
||||
* @deprecated replaced by {@link RegistryFlag<GameMode>}, will be removed in WorldGuard 8
|
||||
*/
|
||||
@Deprecated
|
||||
public class GameModeTypeFlag extends Flag<GameMode> {
|
||||
|
||||
protected GameModeTypeFlag(String name, @Nullable RegionGroup defaultGroup) {
|
||||
|
||||
@@ -25,8 +25,6 @@ import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Stores a key value map of typed {@link Flag}s.
|
||||
*/
|
||||
@@ -37,16 +35,12 @@ public class MapFlag<K, V> extends Flag<Map<K, V>> {
|
||||
|
||||
public MapFlag(final String name, final Flag<K> keyFlag, final Flag<V> valueFlag) {
|
||||
super(name);
|
||||
requireNonNull(keyFlag, "keyFlag cannot be null.");
|
||||
requireNonNull(valueFlag, "valueFlag cannot be null.");
|
||||
this.keyFlag = keyFlag;
|
||||
this.valueFlag = valueFlag;
|
||||
}
|
||||
|
||||
public MapFlag(final String name, @Nullable final RegionGroup defaultGroup, final Flag<K> keyFlag, final Flag<V> valueFlag) {
|
||||
super(name, defaultGroup);
|
||||
requireNonNull(keyFlag, "keyFlag cannot be null.");
|
||||
requireNonNull(valueFlag, "valueFlag cannot be null.");
|
||||
this.keyFlag = keyFlag;
|
||||
this.valueFlag = valueFlag;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
/**
|
||||
* Stores an Number.
|
||||
*/
|
||||
@@ -39,20 +37,10 @@ public abstract class NumberFlag<T extends Number> extends Flag<T> {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not recommended for public use. Will likely be moved when migrating to piston for commands.
|
||||
* @param values suggested values
|
||||
*/
|
||||
@Beta
|
||||
public void setSuggestedValues(Number[] values) {
|
||||
this.suggestions = checkNotNull(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not recommended for public use. Will likely be moved when migrating to piston for commands.
|
||||
* @return suggested values
|
||||
*/
|
||||
@Beta
|
||||
public Number[] getSuggestedValues() {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
@@ -26,20 +26,16 @@ import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class RegistryFlag<T extends Keyed> extends Flag<T> {
|
||||
private final Registry<T> registry;
|
||||
|
||||
public RegistryFlag(String name, Registry<T> registry) {
|
||||
super(name);
|
||||
requireNonNull(registry, "registry cannot be null.");
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public RegistryFlag(String name, @Nullable RegionGroup defaultGroup, Registry<T> registry) {
|
||||
super(name, defaultGroup);
|
||||
requireNonNull(registry, "registry cannot be null.");
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Stores a set of types.
|
||||
*/
|
||||
@@ -38,13 +36,11 @@ public class SetFlag<T> extends Flag<Set<T>> {
|
||||
|
||||
public SetFlag(String name, RegionGroup defaultGroup, Flag<T> subFlag) {
|
||||
super(name, defaultGroup);
|
||||
requireNonNull(subFlag, "SubFlag cannot be null.");
|
||||
this.subFlag = subFlag;
|
||||
}
|
||||
|
||||
public SetFlag(String name, Flag<T> subFlag) {
|
||||
super(name);
|
||||
requireNonNull(subFlag, "SubFlag cannot be null.");
|
||||
this.subFlag = subFlag;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.flags;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDFlag extends Flag<UUID> {
|
||||
|
||||
public UUIDFlag(String name, @Nullable RegionGroup defaultGroup) {
|
||||
super(name, defaultGroup);
|
||||
}
|
||||
|
||||
public UUIDFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
String input = context.getUserInput();
|
||||
if ("self".equalsIgnoreCase(input)) {
|
||||
return context.getSender().getUniqueId();
|
||||
}
|
||||
try {
|
||||
return UUID.fromString(input);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidFlagFormat("Not a valid uuid: " + input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID unmarshal(@Nullable Object o) {
|
||||
if (!(o instanceof String)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return UUID.fromString((String)o);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(UUID o) {
|
||||
return o.toString();
|
||||
}
|
||||
}
|
||||
-5
@@ -24,11 +24,6 @@ import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores an weather type.
|
||||
* @deprecated replaced by {@link RegistryFlag<WeatherType>}, will be removed in WorldGuard 8
|
||||
*/
|
||||
@Deprecated
|
||||
public class WeatherTypeFlag extends Flag<WeatherType> {
|
||||
|
||||
protected WeatherTypeFlag(String name, @Nullable RegionGroup defaultGroup) {
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ public class SimpleFlagRegistry implements FlagRegistry {
|
||||
} else {
|
||||
log.warning("Failed to parse flag '" + flag.getName() + "' with value '" + entry.getValue() + "'");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
log.log(Level.WARNING, "Failed to unmarshal flag value for " + flag, e);
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -34,6 +34,7 @@ import com.sk89q.worldguard.protection.managers.storage.DifferenceSaveException;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDatabase;
|
||||
import com.sk89q.worldguard.protection.managers.storage.StorageException;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionIdentifier;
|
||||
import com.sk89q.worldguard.protection.util.RegionCollectionConsumer;
|
||||
import com.sk89q.worldguard.util.Normal;
|
||||
|
||||
@@ -242,10 +243,22 @@ public final class RegionManager {
|
||||
* @param id the name of the region
|
||||
* @return true if this index contains the region
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasRegion(String id) {
|
||||
return index.contains(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the index contains a region with the given identifier,
|
||||
* with quality determined by {@link Normal}.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @return true if this index contains the region
|
||||
*/
|
||||
public boolean hasRegion(RegionIdentifier id) {
|
||||
return index.contains(id.getLegacyQualifiedName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region named by the given name (equality determined using
|
||||
* {@link Normal}).
|
||||
@@ -254,11 +267,24 @@ public final class RegionManager {
|
||||
* @return a region or {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public ProtectedRegion getRegion(String id) {
|
||||
checkNotNull(id);
|
||||
return index.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region named y the given id.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @return a region or {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public ProtectedRegion getRegion(RegionIdentifier id) {
|
||||
checkNotNull(id);
|
||||
return index.get(id.getLegacyQualifiedName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use exact ids with {@link #getRegion}
|
||||
*/
|
||||
|
||||
+3
-2
@@ -70,12 +70,13 @@ public class HashMapIndex extends AbstractRegionIndex implements ConcurrentRegio
|
||||
region.setDirty(true);
|
||||
|
||||
synchronized (lock) {
|
||||
String normalId = normalize(region.getId());
|
||||
String newFullId = region.getIdentifier().getLegacyQualifiedName();
|
||||
String normalId = normalize(newFullId);
|
||||
|
||||
ProtectedRegion existing = regions.get(normalId);
|
||||
|
||||
// Casing / form of ID has changed
|
||||
if (existing != null && !existing.getId().equals(region.getId())) {
|
||||
if (existing != null && !existing.getIdentifier().getLegacyQualifiedName().equals(newFullId)) {
|
||||
removed.add(existing);
|
||||
}
|
||||
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
class DomainParser {
|
||||
public static class One {
|
||||
public static DefaultDomain parseDomain(YAMLNode node) {
|
||||
if (node == null) {
|
||||
return new DefaultDomain();
|
||||
}
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
||||
for (String name : node.getStringList("players", null)) {
|
||||
if (!name.isEmpty()) {
|
||||
domain.addPlayer(name);
|
||||
}
|
||||
}
|
||||
|
||||
for (String stringId : node.getStringList("unique-ids", null)) {
|
||||
try {
|
||||
domain.addPlayer(UUID.fromString(stringId));
|
||||
} catch (IllegalArgumentException e) {
|
||||
YamlCommon.log.log(Level.WARNING, "Failed to parse UUID '" + stringId + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : node.getStringList("groups", null)) {
|
||||
if (!name.isEmpty()) {
|
||||
domain.addGroup(name);
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
class FlagParser {
|
||||
public static class One {
|
||||
public static void setFlags(FlagRegistry flagRegistry, ProtectedRegion region, YAMLNode flagsData) {
|
||||
if (flagsData != null) {
|
||||
region.setFlags(flagRegistry.unmarshal(flagsData.getMap(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
class YamlCommon {
|
||||
public static final Logger log = Logger.getLogger(YamlRegionFile.class.getCanonicalName());
|
||||
public static final Yaml ERROR_DUMP_YAML;
|
||||
|
||||
static {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setIndent(4);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO);
|
||||
|
||||
ERROR_DUMP_YAML = new Yaml(new SafeConstructor(), new Representer(), options);
|
||||
}
|
||||
|
||||
public static final String YAML_GLOBAL_NAMESPACE_NAME = "__global_ns__";
|
||||
|
||||
private YamlCommon() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the given object as YAML for debugging purposes.
|
||||
*
|
||||
* @param object the object
|
||||
* @return the YAML string or an error string if dumping fals
|
||||
*/
|
||||
public static String toYamlOutput(Object object) {
|
||||
try {
|
||||
return ERROR_DUMP_YAML.dump(object).replaceAll("(?m)^", "\t");
|
||||
} catch (Throwable t) {
|
||||
return "<error while dumping object>";
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
interface YamlReader {
|
||||
public int getVersion();
|
||||
default public boolean canLoad(YAMLProcessor config) {
|
||||
return config.getInt("version", 1) == getVersion();
|
||||
}
|
||||
public Set<ProtectedRegion> load(FlagRegistry flagRegistry, YAMLProcessor config);
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDatabaseUtils;
|
||||
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 java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldguard.protection.managers.storage.file.YamlCommon.log;
|
||||
import static com.sk89q.worldguard.protection.managers.storage.file.YamlCommon.toYamlOutput;
|
||||
|
||||
class YamlReaderVersionOne implements YamlReader {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> load(FlagRegistry flagRegistry, YAMLProcessor config) {
|
||||
Map<String, ProtectedRegion> loaded = new HashMap<>();
|
||||
Map<String, YAMLNode> regionData = config.getNodes("regions");
|
||||
|
||||
if (regionData == null) {
|
||||
return Collections.emptySet(); // No regions are even configured
|
||||
}
|
||||
|
||||
Map<ProtectedRegion, String> parentSets = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, YAMLNode> entry : regionData.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
YAMLNode node = entry.getValue();
|
||||
|
||||
String type = node.getString("type");
|
||||
ProtectedRegion region;
|
||||
|
||||
try {
|
||||
if (type == null) {
|
||||
log.warning("Undefined region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) + "\n");
|
||||
continue;
|
||||
} else if (type.equals("cuboid")) {
|
||||
Vector3 pt1 = checkNotNull(node.getVector("min"));
|
||||
Vector3 pt2 = checkNotNull(node.getVector("max"));
|
||||
BlockVector3 min = pt1.getMinimum(pt2).toBlockPoint();
|
||||
BlockVector3 max = pt1.getMaximum(pt2).toBlockPoint();
|
||||
region = new ProtectedCuboidRegion(id, min, max);
|
||||
} else if (type.equals("poly2d")) {
|
||||
Integer minY = checkNotNull(node.getInt("min-y"));
|
||||
Integer maxY = checkNotNull(node.getInt("max-y"));
|
||||
List<BlockVector2> points = node.getBlockVector2List("points", null);
|
||||
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
||||
} else if (type.equals("global")) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
log.warning("Unknown region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) + "\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer priority = checkNotNull(node.getInt("priority"));
|
||||
region.setPriority(priority);
|
||||
FlagParser.One.setFlags(flagRegistry, region, node.getNode("flags"));
|
||||
region.setOwners(DomainParser.One.parseDomain(node.getNode("owners")));
|
||||
region.setMembers(DomainParser.One.parseDomain(node.getNode("members")));
|
||||
|
||||
loaded.put(id, region);
|
||||
|
||||
String parentId = node.getString("parent");
|
||||
if (parentId != null) {
|
||||
parentSets.put(region, parentId);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
log.log(Level.WARNING,
|
||||
"Unexpected NullPointerException encountered during parsing for the region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) +
|
||||
"\n\nNote: This region will disappear as a result!", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Relink parents
|
||||
RegionDatabaseUtils.relinkParents(loaded, parentSets);
|
||||
|
||||
return new HashSet<>(loaded.values());
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.managers.storage.file;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDatabaseUtils;
|
||||
import com.sk89q.worldguard.protection.regions.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldguard.protection.managers.storage.file.YamlCommon.*;
|
||||
|
||||
class YamlReaderVersionTwo implements YamlReader {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> load(FlagRegistry flagRegistry, YAMLProcessor config) {
|
||||
Map<String, ProtectedRegion> loaded = new HashMap<>();
|
||||
Map<String, YAMLNode> regionData = config.getNodes("regions");
|
||||
|
||||
if (regionData == null) {
|
||||
return Collections.emptySet(); // No regions are even configured
|
||||
}
|
||||
|
||||
Map<ProtectedRegion, String> parentSets = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, YAMLNode> namespaceEntry : regionData.entrySet()) {
|
||||
String namespaceKey = namespaceEntry.getKey();
|
||||
|
||||
String namespace = namespaceKey;
|
||||
if (namespace.equals(YAML_GLOBAL_NAMESPACE_NAME)) {
|
||||
namespace = null;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Object> entry : namespaceEntry.getValue().getMap().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
YAMLNode node = config.getNode("regions." + namespaceKey + "." + name);
|
||||
|
||||
String type = node.getString("type");
|
||||
ProtectedRegion region;
|
||||
|
||||
RegionIdentifier id = new RegionIdentifier(namespace, name);
|
||||
try {
|
||||
if (type == null) {
|
||||
log.warning("Undefined region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(node.getMap()) + "\n");
|
||||
continue;
|
||||
} else if (type.equals("cuboid")) {
|
||||
Vector3 pt1 = checkNotNull(node.getVector("min"));
|
||||
Vector3 pt2 = checkNotNull(node.getVector("max"));
|
||||
BlockVector3 min = pt1.getMinimum(pt2).toBlockPoint();
|
||||
BlockVector3 max = pt1.getMaximum(pt2).toBlockPoint();
|
||||
region = new ProtectedCuboidRegion(id, min, max);
|
||||
} else if (type.equals("poly2d")) {
|
||||
Integer minY = checkNotNull(node.getInt("min-y"));
|
||||
Integer maxY = checkNotNull(node.getInt("max-y"));
|
||||
List<BlockVector2> points = node.getBlockVector2List("points", null);
|
||||
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
||||
} else if (type.equals("global")) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
log.warning("Unknown region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(node.getMap()) + "\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer priority = checkNotNull(node.getInt("priority"));
|
||||
region.setPriority(priority);
|
||||
FlagParser.One.setFlags(flagRegistry, region, node.getNode("flags"));
|
||||
region.setOwners(DomainParser.One.parseDomain(node.getNode("owners")));
|
||||
region.setMembers(DomainParser.One.parseDomain(node.getNode("members")));
|
||||
|
||||
loaded.put(id.getLegacyQualifiedName(), region);
|
||||
|
||||
String parentQualifiedName = node.getString("parent");
|
||||
if (parentQualifiedName != null) {
|
||||
parentSets.put(region, parentQualifiedName);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
log.log(Level.WARNING,
|
||||
"Unexpected NullPointerException encountered during parsing for the region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(node.getMap()) +
|
||||
"\n\nNote: This region will disappear as a result!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Relink parents
|
||||
RegionDatabaseUtils.relinkParents(loaded, parentSets);
|
||||
|
||||
return new HashSet<>(loaded.values());
|
||||
}
|
||||
}
|
||||
+36
-155
@@ -19,56 +19,32 @@
|
||||
|
||||
package com.sk89q.worldguard.protection.managers.storage.file;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.util.yaml.YAMLFormat;
|
||||
import com.sk89q.util.yaml.YAMLNode;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.FlagUtil;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.RegionDifference;
|
||||
import com.sk89q.worldguard.protection.managers.storage.DifferenceSaveException;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDatabase;
|
||||
import com.sk89q.worldguard.protection.managers.storage.RegionDatabaseUtils;
|
||||
import com.sk89q.worldguard.protection.managers.storage.StorageException;
|
||||
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.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import com.sk89q.worldguard.protection.regions.*;
|
||||
import org.yaml.snakeyaml.parser.ParserException;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldguard.protection.managers.storage.file.YamlCommon.YAML_GLOBAL_NAMESPACE_NAME;
|
||||
|
||||
/**
|
||||
* A store that persists regions in a YAML-encoded file.
|
||||
*/
|
||||
public class YamlRegionFile implements RegionDatabase {
|
||||
|
||||
private static final Logger log = Logger.getLogger(YamlRegionFile.class.getCanonicalName());
|
||||
private static final Yaml ERROR_DUMP_YAML;
|
||||
|
||||
private static final String FILE_HEADER = "#\r\n" +
|
||||
"# WorldGuard regions file\r\n" +
|
||||
"#\r\n" +
|
||||
@@ -81,17 +57,19 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
"# REMEMBER TO KEEP PERIODICAL BACKUPS.\r\n" +
|
||||
"#";
|
||||
|
||||
private final String name;
|
||||
private final File file;
|
||||
private static final List<YamlReader> YAML_READERS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setIndent(4);
|
||||
options.setDefaultFlowStyle(FlowStyle.AUTO);
|
||||
|
||||
ERROR_DUMP_YAML = new Yaml(new SafeConstructor(), new Representer(), options);
|
||||
// IMPORTANT: For best performance, add these in reverse order.
|
||||
// We always want the latest version to be attempted first, so that once migrated, we are checking
|
||||
// one version, not n.
|
||||
YAML_READERS.add(new YamlReaderVersionTwo());
|
||||
YAML_READERS.add(new YamlReaderVersionOne());
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final File file;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
@@ -112,80 +90,22 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> loadAll(FlagRegistry flagRegistry) throws StorageException {
|
||||
Map<String, ProtectedRegion> loaded = new HashMap<>();
|
||||
|
||||
YAMLProcessor config = createYamlProcessor(file);
|
||||
try {
|
||||
config.load();
|
||||
} catch (FileNotFoundException e) {
|
||||
return new HashSet<>(loaded.values());
|
||||
return new HashSet<>();
|
||||
} catch (IOException | ParserException e) {
|
||||
throw new StorageException("Failed to load region data from '" + file + "'", e);
|
||||
}
|
||||
|
||||
Map<String, YAMLNode> regionData = config.getNodes("regions");
|
||||
|
||||
if (regionData == null) {
|
||||
return Collections.emptySet(); // No regions are even configured
|
||||
}
|
||||
|
||||
Map<ProtectedRegion, String> parentSets = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, YAMLNode> entry : regionData.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
YAMLNode node = entry.getValue();
|
||||
|
||||
String type = node.getString("type");
|
||||
ProtectedRegion region;
|
||||
|
||||
try {
|
||||
if (type == null) {
|
||||
log.warning("Undefined region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) + "\n");
|
||||
continue;
|
||||
} else if (type.equals("cuboid")) {
|
||||
Vector3 pt1 = checkNotNull(node.getVector("min"));
|
||||
Vector3 pt2 = checkNotNull(node.getVector("max"));
|
||||
BlockVector3 min = pt1.getMinimum(pt2).toBlockPoint();
|
||||
BlockVector3 max = pt1.getMaximum(pt2).toBlockPoint();
|
||||
region = new ProtectedCuboidRegion(id, min, max);
|
||||
} else if (type.equals("poly2d")) {
|
||||
Integer minY = checkNotNull(node.getInt("min-y"));
|
||||
Integer maxY = checkNotNull(node.getInt("max-y"));
|
||||
List<BlockVector2> points = node.getBlockVector2List("points", null);
|
||||
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
||||
} else if (type.equals("global")) {
|
||||
region = new GlobalProtectedRegion(id);
|
||||
} else {
|
||||
log.warning("Unknown region type for region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) + "\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer priority = checkNotNull(node.getInt("priority"));
|
||||
region.setPriority(priority);
|
||||
setFlags(flagRegistry, region, node.getNode("flags"));
|
||||
region.setOwners(parseDomain(node.getNode("owners")));
|
||||
region.setMembers(parseDomain(node.getNode("members")));
|
||||
|
||||
loaded.put(id, region);
|
||||
|
||||
String parentId = node.getString("parent");
|
||||
if (parentId != null) {
|
||||
parentSets.put(region, parentId);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
log.log(Level.WARNING,
|
||||
"Unexpected NullPointerException encountered during parsing for the region '" + id + "'!\n" +
|
||||
"Here is what the region data looks like:\n\n" + toYamlOutput(entry.getValue().getMap()) +
|
||||
"\n\nNote: This region will disappear as a result!", e);
|
||||
for (YamlReader reader : YAML_READERS) {
|
||||
if (reader.canLoad(config)) {
|
||||
return reader.load(flagRegistry, config);
|
||||
}
|
||||
}
|
||||
|
||||
// Relink parents
|
||||
RegionDatabaseUtils.relinkParents(loaded, parentSets);
|
||||
|
||||
return new HashSet<>(loaded.values());
|
||||
throw new IllegalStateException("No YAML reader was registered that understands the saved region information");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,13 +117,25 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
|
||||
config.clear();
|
||||
|
||||
config.setProperty("version", YAML_READERS.get(0).getVersion());
|
||||
YAMLNode regionsNode = config.addNode("regions");
|
||||
Map<String, Object> map = regionsNode.getMap();
|
||||
|
||||
// Creates a mapping of existing namespace node names, to their underlying YAMLNode.
|
||||
Map<String, YAMLNode> namespaceMap = new HashMap<>();
|
||||
|
||||
for (ProtectedRegion region : regions) {
|
||||
Map<String, Object> nodeMap = new HashMap<>();
|
||||
map.put(region.getId(), nodeMap);
|
||||
YAMLNode node = new YAMLNode(nodeMap, false);
|
||||
RegionIdentifier identifier = region.getIdentifier();
|
||||
|
||||
String internalNamespace = identifier.getNamespace().orElse(YAML_GLOBAL_NAMESPACE_NAME);
|
||||
YAMLNode namespaceNode = namespaceMap.compute(internalNamespace, (ignored, existingNamespaceNode) -> {
|
||||
if (existingNamespaceNode == null) {
|
||||
existingNamespaceNode = regionsNode.addNode(internalNamespace);
|
||||
}
|
||||
|
||||
return existingNamespaceNode;
|
||||
});
|
||||
|
||||
YAMLNode node = namespaceNode.addNode(identifier.getName());
|
||||
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region;
|
||||
@@ -238,7 +170,7 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
|
||||
ProtectedRegion parent = region.getParent();
|
||||
if (parent != null) {
|
||||
node.setProperty("parent", parent.getId());
|
||||
node.setProperty("parent", parent.getIdentifier().getLegacyQualifiedName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,46 +189,10 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
throw new DifferenceSaveException("Not supported");
|
||||
}
|
||||
|
||||
private DefaultDomain parseDomain(YAMLNode node) {
|
||||
if (node == null) {
|
||||
return new DefaultDomain();
|
||||
}
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
||||
for (String name : node.getStringList("players", null)) {
|
||||
if (!name.isEmpty()) {
|
||||
domain.addPlayer(name);
|
||||
}
|
||||
}
|
||||
|
||||
for (String stringId : node.getStringList("unique-ids", null)) {
|
||||
try {
|
||||
domain.addPlayer(UUID.fromString(stringId));
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.log(Level.WARNING, "Failed to parse UUID '" + stringId + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : node.getStringList("groups", null)) {
|
||||
if (!name.isEmpty()) {
|
||||
domain.addGroup(name);
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
private Map<String, Object> getFlagData(ProtectedRegion region) {
|
||||
return FlagUtil.marshal(region.getFlags());
|
||||
}
|
||||
|
||||
private void setFlags(FlagRegistry flagRegistry, ProtectedRegion region, YAMLNode flagsData) {
|
||||
if (flagsData != null) {
|
||||
region.setFlags(flagRegistry.unmarshal(flagsData.getMap(), true));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getDomainData(DefaultDomain domain) {
|
||||
Map<String, Object> domainData = new HashMap<>();
|
||||
|
||||
@@ -331,19 +227,4 @@ public class YamlRegionFile implements RegionDatabase {
|
||||
checkNotNull(file);
|
||||
return new YAMLProcessor(file, false, YAMLFormat.COMPACT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the given object as YAML for debugging purposes.
|
||||
*
|
||||
* @param object the object
|
||||
* @return the YAML string or an error string if dumping fals
|
||||
*/
|
||||
private static String toYamlOutput(Object object) {
|
||||
try {
|
||||
return ERROR_DUMP_YAML.dump(object).replaceAll("(?m)^", "\t");
|
||||
} catch (Throwable t) {
|
||||
return "<error while dumping object>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -44,6 +44,7 @@ public class GlobalProtectedRegion extends ProtectedRegion {
|
||||
*
|
||||
* @param id the ID
|
||||
*/
|
||||
@Deprecated
|
||||
public GlobalProtectedRegion(String id) {
|
||||
this(id, false);
|
||||
}
|
||||
@@ -54,7 +55,29 @@ public class GlobalProtectedRegion extends ProtectedRegion {
|
||||
* @param id the ID
|
||||
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||
*/
|
||||
@Deprecated
|
||||
public GlobalProtectedRegion(String id, boolean transientRegion) {
|
||||
this(new RegionIdentifier(id), transientRegion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.<br>
|
||||
* Equivalent to {@link #GlobalProtectedRegion(String, boolean) GlobalProtectedRegion(id, false)}<br>
|
||||
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||
*
|
||||
* @param id the region identifier
|
||||
*/
|
||||
public GlobalProtectedRegion(RegionIdentifier id) {
|
||||
this(id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||
*/
|
||||
public GlobalProtectedRegion(RegionIdentifier id, boolean transientRegion) {
|
||||
super(id, transientRegion);
|
||||
min = BlockVector3.ZERO;
|
||||
max = BlockVector3.ZERO;
|
||||
|
||||
+30
-9
@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.util.MathUtils;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
@@ -48,6 +47,7 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
|
||||
* @param pt1 the first point of this region
|
||||
* @param pt2 the second point of this region
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtectedCuboidRegion(String id, BlockVector3 pt1, BlockVector3 pt2) {
|
||||
this(id, false, pt1, pt2);
|
||||
}
|
||||
@@ -60,7 +60,34 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
|
||||
* @param pt1 the first point of this region
|
||||
* @param pt2 the second point of this region
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtectedCuboidRegion(String id, boolean transientRegion, BlockVector3 pt1, BlockVector3 pt2) {
|
||||
this(new RegionIdentifier(id), transientRegion, pt1, pt2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid region.<br>
|
||||
* Equivalent to {@link #ProtectedCuboidRegion(RegionIdentifier, boolean, BlockVector3, BlockVector3)
|
||||
* ProtectedCuboidRegion(id, false, pt1, pt2)}<br>
|
||||
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @param pt1 the first point of this region
|
||||
* @param pt2 the second point of this region
|
||||
*/
|
||||
public ProtectedCuboidRegion(RegionIdentifier id, BlockVector3 pt1, BlockVector3 pt2) {
|
||||
this(id, false, pt1, pt2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid region.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||
* @param pt1 the first point of this region
|
||||
* @param pt2 the second point of this region
|
||||
*/
|
||||
public ProtectedCuboidRegion(RegionIdentifier id, boolean transientRegion, BlockVector3 pt1, BlockVector3 pt2) {
|
||||
super(id, transientRegion);
|
||||
setMinMaxPoints(pt1, pt2);
|
||||
}
|
||||
@@ -85,24 +112,18 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
|
||||
* Set the lower point of the cuboid.
|
||||
*
|
||||
* @param position the point to set as the minimum point
|
||||
* @deprecated ProtectedRegion bounds should never be mutated. Regions must be redefined to move them.
|
||||
* This method will be removed in a future release.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMinimumPoint(BlockVector3 position) {
|
||||
WorldGuard.logger.warning("ProtectedCuboidRegion#setMinimumPoint call ignored. Mutating regions leads to undefined behavior.");
|
||||
setMinMaxPoints(position, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the upper point of the cuboid.
|
||||
*
|
||||
* @param position the point to set as the maximum point
|
||||
* @deprecated ProtectedRegion bounds should never be mutated. Regions must be redefined to move them.
|
||||
* This method will be removed in a future release.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMaximumPoint(BlockVector3 position) {
|
||||
WorldGuard.logger.warning("ProtectedCuboidRegion#setMaximumPoint call ignored. Mutating regions leads to undefined behavior.");
|
||||
setMinMaxPoints(min, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+31
@@ -47,6 +47,7 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
|
||||
* @param minY the minimum y coordinate
|
||||
* @param maxY the maximum y coordinate
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtectedPolygonalRegion(String id, List<BlockVector2> points, int minY, int maxY) {
|
||||
this(id, false, points, minY, maxY);
|
||||
}
|
||||
@@ -60,7 +61,37 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
|
||||
* @param minY the minimum y coordinate
|
||||
* @param maxY the maximum y coordinate
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtectedPolygonalRegion(String id, boolean transientRegion, List<BlockVector2> points, int minY, int maxY) {
|
||||
this(new RegionIdentifier(id), transientRegion, points, minY, maxY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of this polygonal region.<br>
|
||||
* Equivalent to {@link #ProtectedPolygonalRegion(RegionIdentifier, boolean, List, int, int)
|
||||
* ProtectedPolygonalRegion(id, false, points, minY, maxY)}<br>
|
||||
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @param points a {@link List} of points that this region should contain
|
||||
* @param minY the minimum y coordinate
|
||||
* @param maxY the maximum y coordinate
|
||||
*/
|
||||
public ProtectedPolygonalRegion(RegionIdentifier id, List<BlockVector2> points, int minY, int maxY) {
|
||||
this(id, false, points, minY, maxY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of this polygonal region.
|
||||
*
|
||||
* @param id the region identifier
|
||||
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||
* @param points a {@link List} of points that this region should contain
|
||||
* @param minY the minimum y coordinate
|
||||
* @param maxY the maximum y coordinate
|
||||
*/
|
||||
public ProtectedPolygonalRegion(RegionIdentifier id, boolean transientRegion, List<BlockVector2> points,
|
||||
int minY, int maxY) {
|
||||
super(id, transientRegion);
|
||||
ImmutableList<BlockVector2> immutablePoints = ImmutableList.copyOf(points);
|
||||
setMinMaxPoints(immutablePoints, minY, maxY);
|
||||
|
||||
+16
-18
@@ -28,7 +28,6 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.util.ChangeTracked;
|
||||
import com.sk89q.worldguard.util.Normal;
|
||||
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Line2D;
|
||||
@@ -37,7 +36,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -46,20 +44,15 @@ import javax.annotation.Nullable;
|
||||
* against it.
|
||||
*
|
||||
* <p>Instances can be modified and access from several threads at a time.</p>
|
||||
*
|
||||
* Note: this class has a natural ordering that is inconsistent with equals.
|
||||
* Regions with identical ids (and also the same priority) may exist in different managers (or no manager at all),
|
||||
* so care should be taken when comparing regions that have not been obtained from a single manager.
|
||||
*/
|
||||
public abstract class ProtectedRegion implements ChangeTracked, Comparable<ProtectedRegion> {
|
||||
|
||||
public static final String GLOBAL_REGION = "__global__";
|
||||
private static final Pattern VALID_ID_PATTERN = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
||||
|
||||
protected BlockVector3 min;
|
||||
protected BlockVector3 max;
|
||||
|
||||
private final String id;
|
||||
private final RegionIdentifier id;
|
||||
private final boolean transientRegion;
|
||||
private int priority = 0;
|
||||
private ProtectedRegion parent;
|
||||
@@ -71,18 +64,13 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
||||
/**
|
||||
* Construct a new instance of this region.
|
||||
*
|
||||
* @param id the name of this region
|
||||
* @param id the name information for this region
|
||||
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||
* @throws IllegalArgumentException thrown if the ID is invalid (see {@link #isValidId(String)}
|
||||
*/
|
||||
ProtectedRegion(String id, boolean transientRegion) { // Package private because we can't have people creating their own region types
|
||||
ProtectedRegion(RegionIdentifier id, boolean transientRegion) { // Package private because we can't have people creating their own region types
|
||||
checkNotNull(id);
|
||||
|
||||
if (!isValidId(id)) {
|
||||
throw new IllegalArgumentException("Invalid region ID: " + id);
|
||||
}
|
||||
|
||||
this.id = Normal.normalize(id);
|
||||
this.id = id;
|
||||
this.transientRegion = transientRegion;
|
||||
}
|
||||
|
||||
@@ -123,7 +111,17 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Deprecated
|
||||
public String getId() {
|
||||
return id.getLegacyQualifiedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier info for this region.
|
||||
*
|
||||
* @return the identifier info
|
||||
*/
|
||||
public RegionIdentifier getIdentifier() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -738,9 +736,9 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
||||
* @param id the id to check
|
||||
* @return whether the region id given is valid
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isValidId(String id) {
|
||||
checkNotNull(id);
|
||||
return VALID_ID_PATTERN.matcher(id).matches();
|
||||
return RegionIdentifier.isValidName(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.regions;
|
||||
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.util.Normal;
|
||||
import com.sk89q.worldguard.util.profile.Profile;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public final class RegionIdentifier {
|
||||
private static final Pattern VALID_NAME_PATTERN = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
||||
|
||||
private String namespace;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Construct a new RegionIdentifier for describing region name information, using the global namespace.<br>
|
||||
* Equivalent to {@link #RegionIdentifier(String, String) RegionIdentifier(null, name)}<br>
|
||||
* <code>namespace</code> will be set to null.
|
||||
*
|
||||
* @param name the name for this region
|
||||
* @throws IllegalArgumentException thrown if the name is invalid (see {@link #isValidName(String)}
|
||||
*/
|
||||
public RegionIdentifier(String name) {
|
||||
this(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new RegionIdentifier for describing region name information.
|
||||
*
|
||||
* @param namespace the namespace name for this region, or null if there isn't one
|
||||
* @param name the name for this region
|
||||
* @throws IllegalArgumentException thrown if the namespace is invalid (see {@link #isValidNamespace(String)}
|
||||
* @throws IllegalArgumentException thrown if the name is invalid (see {@link #isValidName(String)}
|
||||
*/
|
||||
public RegionIdentifier(@Nullable String namespace, String name) {
|
||||
if (!isValidNamespace(name)) {
|
||||
throw new IllegalArgumentException("Invalid region namespace: " + namespace);
|
||||
}
|
||||
|
||||
if (!isValidName(name)) {
|
||||
throw new IllegalArgumentException("Invalid region name: " + name);
|
||||
}
|
||||
|
||||
this.namespace = namespace == null ? null : Normal.normalize(namespace);
|
||||
this.name = Normal.normalize(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the qualified name. This is incompatible with the legacy naming scheme, and
|
||||
* should be used when interacting with the command system. This will ensure that the correct
|
||||
* region is referenced regardless of the user's default namespace.
|
||||
*
|
||||
* @return the qualified name
|
||||
*/
|
||||
public String getQualifiedName() {
|
||||
return getNamespace().orElse("") + ":" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the legacy qualified name. This is compatible with the legacy naming scheme, and
|
||||
* should be used when interacting with the region manager via names.
|
||||
*
|
||||
* If you're using this outside of WorldGuard internals, you're doing something wrong.
|
||||
*
|
||||
* @return the legacy qualified name
|
||||
*/
|
||||
@Deprecated
|
||||
public String getLegacyQualifiedName() {
|
||||
return getNamespace().map((ns) -> ns + ':' + getName()).orElse(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses the name into a more user friendly macro based name.
|
||||
*
|
||||
* @param actor a player context
|
||||
* @return the user friendly display name
|
||||
*/
|
||||
public String getDisplayName(Actor actor) {
|
||||
if (actor instanceof LocalPlayer) {
|
||||
LocalPlayer player = (LocalPlayer) actor;
|
||||
if (player.isDefaultNamespace(namespace)) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
if (namespace != null) {
|
||||
try {
|
||||
UUID playerID = UUID.fromString(namespace);
|
||||
Profile profile = WorldGuard.getInstance().getProfileCache().getIfPresent(playerID);
|
||||
if (profile != null) {
|
||||
return "#" + profile.getName() + ":" + name;
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to the fully qualified name.
|
||||
return getQualifiedName();
|
||||
}
|
||||
|
||||
public Optional<String> getNamespace() {
|
||||
return Optional.ofNullable(namespace);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static boolean isValidNamespace(String namespace) {
|
||||
if (namespace == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return VALID_NAME_PATTERN.matcher(namespace).matches();
|
||||
}
|
||||
|
||||
public static boolean isValidName(String name) {
|
||||
checkNotNull(name);
|
||||
return VALID_NAME_PATTERN.matcher(name).matches();
|
||||
}
|
||||
}
|
||||
-104
@@ -34,8 +34,6 @@ import com.sk89q.worldguard.protection.RegionResultSet;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
@@ -173,56 +171,6 @@ public class RegionQuery {
|
||||
queryState(location, associable, flag)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the BUILD flag allows the action in the location, but it
|
||||
* can be overridden by a list of other flags. The BUILD flag will not
|
||||
* override the other flags, but the other flags can override BUILD. If
|
||||
* neither BUILD or any of the flags permit the action, then false will
|
||||
* be returned.
|
||||
*
|
||||
* <p>Use this method when checking flags that are related to build
|
||||
* protection. For example, lighting fire in a region should not be
|
||||
* permitted unless the player is a member of the region or the
|
||||
* LIGHTER flag allows it. However, the LIGHTER flag should be able
|
||||
* to allow lighting fires even if BUILD is set to DENY.</p>
|
||||
*
|
||||
* <p>This method does include parameters for a {@link MapFlag}.</p>
|
||||
*
|
||||
* <p>How this method works (BUILD can be overridden by other flags but
|
||||
* not the other way around) is inconsistent, but it's required for
|
||||
* legacy reasons.</p>
|
||||
*
|
||||
* <p>This method does not check the region bypass permission. That must
|
||||
* be done by the calling code.</p>
|
||||
*
|
||||
* @param location the location
|
||||
* @param associable an optional associable
|
||||
* @param mapFlag the MapFlag
|
||||
* @param key the key for the MapFlag
|
||||
* @param fallback the fallback flag for MapFlag
|
||||
* @param flag the flags
|
||||
* @return true if the result was {@code ALLOW}
|
||||
* @see RegionResultSet#queryValue(RegionAssociable, Flag)
|
||||
*/
|
||||
public <K> boolean testBuild(Location location, RegionAssociable associable, MapFlag<K, State> mapFlag, K key,
|
||||
@Nullable StateFlag fallback, StateFlag... flag) {
|
||||
if (mapFlag == null)
|
||||
return testBuild(location, associable, flag);
|
||||
|
||||
if (flag.length == 0) {
|
||||
return StateFlag.test(StateFlag.combine(
|
||||
StateFlag.denyToNone(queryState(location, associable, Flags.BUILD)),
|
||||
queryMapValue(location, associable, mapFlag, key, fallback)
|
||||
));
|
||||
}
|
||||
|
||||
return StateFlag.test(StateFlag.combine(
|
||||
StateFlag.denyToNone(queryState(location, associable, Flags.BUILD)),
|
||||
queryMapValue(location, associable, mapFlag, key, fallback),
|
||||
queryState(location, associable, flag)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the (effective) value for a list of state flags equals
|
||||
* {@code ALLOW}.
|
||||
@@ -371,58 +319,6 @@ public class RegionQuery {
|
||||
return getApplicableRegions(location).queryValue(associable, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective value for a key in a {@link MapFlag}. If there are multiple values
|
||||
* (for example, if there are multiple regions with the same priority
|
||||
* but with different farewell messages set, there would be multiple
|
||||
* completing values), then the selected (or "winning") value will be undefined.
|
||||
*
|
||||
* <p>A subject can be provided that is used to determine whether the value
|
||||
* of a flag on a particular region should be used. For example, if a
|
||||
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
|
||||
* subject is not a member, then the region would be skipped when
|
||||
* querying that flag. If {@code null} is provided for the subject, then
|
||||
* only flags that use {@link RegionGroup#ALL},
|
||||
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.</p>
|
||||
*
|
||||
* @param subject an optional subject, which would be used to determine the region group to apply
|
||||
* @param flag the flag of type {@link MapFlag}
|
||||
* @param key the key for the map flag
|
||||
* @return a value, which could be {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public <V, K> V queryMapValue(Location location, @Nullable RegionAssociable subject, MapFlag<K, V> flag, K key) {
|
||||
return getApplicableRegions(location).queryMapValue(subject, flag, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective value for a key in a {@link MapFlag}. If there are multiple values
|
||||
* (for example, if there are multiple regions with the same priority
|
||||
* but with different farewell messages set, there would be multiple
|
||||
* completing values), then the selected (or "winning") value will be undefined.
|
||||
*
|
||||
* <p>A subject can be provided that is used to determine whether the value
|
||||
* of a flag on a particular region should be used. For example, if a
|
||||
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
|
||||
* subject is not a member, then the region would be skipped when
|
||||
* querying that flag. If {@code null} is provided for the subject, then
|
||||
* only flags that use {@link RegionGroup#ALL},
|
||||
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.</p>
|
||||
*
|
||||
* <p>It's possible to provide a fallback flag for the case when the key doesn't
|
||||
* exist in the {@link MapFlag}.</p>
|
||||
*
|
||||
* @param subject an optional subject, which would be used to determine the region group to apply
|
||||
* @param flag the flag of type {@link MapFlag}
|
||||
* @param key the key for the map flag
|
||||
* @param fallback the fallback flag
|
||||
* @return a value, which could be {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public <V, K> V queryMapValue(Location location, @Nullable RegionAssociable subject, MapFlag<K, V> flag, K key, Flag<V> fallback) {
|
||||
return getApplicableRegions(location).queryMapValue(subject, flag, key, fallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective values for a flag, returning a collection of all
|
||||
* values. It is up to the caller to determine which value, if any,
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection.util;
|
||||
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
/**
|
||||
* A helper class to convert regions from WorldGuard to WorldEdit
|
||||
*/
|
||||
public final class WorldEditRegionConverter {
|
||||
private WorldEditRegionConverter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a ProtectedRegion to a WorldEdit Region, otherwise null if
|
||||
* the ProtectedRegion can't be converted to a RegionSelector.
|
||||
*
|
||||
* @param region the WorldGuard region
|
||||
* @return the WorldEdit Region
|
||||
*/
|
||||
public static Region convertToRegion(ProtectedRegion region) {
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
return new CuboidRegion(null, region.getMinimumPoint(), region.getMaximumPoint());
|
||||
}
|
||||
if (region instanceof ProtectedPolygonalRegion) {
|
||||
return new Polygonal2DRegion(null, region.getPoints(),
|
||||
region.getMinimumPoint().getY(), region.getMaximumPoint().getY());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a ProtectedRegion to a WorldEdit RegionSelector, otherwise null if
|
||||
* the ProtectedRegion can't be converted to a RegionSelector.
|
||||
*
|
||||
* @param region the WorldGuard region
|
||||
* @return the WorldEdit Region
|
||||
*/
|
||||
public static RegionSelector convertToSelector(ProtectedRegion region) {
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
return new CuboidRegionSelector(null, region.getMinimumPoint(), region.getMaximumPoint());
|
||||
}
|
||||
if (region instanceof ProtectedPolygonalRegion) {
|
||||
return new Polygonal2DRegionSelector(null, region.getPoints(),
|
||||
region.getMinimumPoint().getY(), region.getMaximumPoint().getY());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+7
-30
@@ -44,13 +44,10 @@ import com.sk89q.worldguard.session.handler.WeatherLockFlag;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@@ -60,14 +57,11 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
public static final int RUN_DELAY = 20;
|
||||
public static final long SESSION_LIFETIME = 10;
|
||||
|
||||
private static final BiPredicate<World, LocalPlayer> BYPASS_PERMISSION_TEST = (world, player) -> {
|
||||
return player.hasPermission("worldguard.region.bypass." + world.getName());
|
||||
};
|
||||
|
||||
private final LoadingCache<WorldPlayerTuple, Boolean> bypassCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(1000)
|
||||
.expireAfterWrite(2, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from(tuple -> BYPASS_PERMISSION_TEST.test(tuple.getWorld(), tuple.getPlayer())));
|
||||
.expireAfterAccess(2, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from(tuple ->
|
||||
tuple.getPlayer().hasPermission("worldguard.region.bypass." + tuple.getWorld().getName())));
|
||||
|
||||
private final LoadingCache<CacheKey, Session> sessions = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES)
|
||||
@@ -75,8 +69,6 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
createSession(key.playerRef.get())));
|
||||
|
||||
private boolean hasCustom = false;
|
||||
// <original handler, wrapped handler>
|
||||
private Map<Handler.Factory<? extends Handler>, Handler.Factory<? extends Handler>> wrappedHandlers = new HashMap<>();
|
||||
private List<Handler.Factory<? extends Handler>> handlers = new LinkedList<>();
|
||||
|
||||
private static final List<Handler.Factory<? extends Handler>> defaultHandlers = new LinkedList<>();
|
||||
@@ -110,27 +102,20 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
return hasCustom;
|
||||
}
|
||||
|
||||
protected Handler.Factory<? extends Handler> wrapForRegistration(Handler.Factory<? extends Handler> factory) {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerHandler(Handler.Factory<? extends Handler> factory, @Nullable Handler.Factory<? extends Handler> after) {
|
||||
if (factory == null) return false;
|
||||
WorldGuard.logger.log(Level.INFO, "Registering session handler "
|
||||
+ factory.getClass().getEnclosingClass().getName());
|
||||
hasCustom = true;
|
||||
Handler.Factory<? extends Handler> wrappedFactory = wrapForRegistration(factory);
|
||||
if (after == null) {
|
||||
handlers.add(wrappedFactory);
|
||||
handlers.add(factory);
|
||||
} else {
|
||||
Handler.Factory<? extends Handler> wrappedAfter = wrappedHandlers.get(after);
|
||||
int index = handlers.indexOf(wrappedAfter != null ? wrappedAfter : after);
|
||||
int index = handlers.indexOf(after);
|
||||
if (index == -1) return false;
|
||||
|
||||
handlers.add(index, factory); // shifts "after" right one, and everything after "after" right one
|
||||
}
|
||||
wrappedHandlers.put(factory, wrappedFactory);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,7 +127,6 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
} else {
|
||||
WorldGuard.logger.log(Level.INFO, "Unregistering session handler "
|
||||
+ factory.getClass().getEnclosingClass().getName());
|
||||
factory = wrappedHandlers.remove(factory);
|
||||
}
|
||||
return handlers.remove(factory);
|
||||
}
|
||||
@@ -150,15 +134,8 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
@Override
|
||||
public boolean hasBypass(LocalPlayer player, World world) {
|
||||
Session sess = getIfPresent(player);
|
||||
if (sess == null || sess.hasBypassDisabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().disablePermissionCache) {
|
||||
return BYPASS_PERMISSION_TEST.test(world, player);
|
||||
}
|
||||
|
||||
return bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
|
||||
return sess != null && !sess.hasBypassDisabled()
|
||||
&& bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,11 +22,8 @@ package com.sk89q.worldguard.session;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.config.ConfigurationManager;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
@@ -34,10 +31,10 @@ import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.sk89q.worldguard.session.handler.Handler;
|
||||
import com.sk89q.worldguard.util.Locations;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@@ -69,7 +66,7 @@ public class Session {
|
||||
* @param handler A new handler
|
||||
*/
|
||||
public void register(Handler handler) {
|
||||
handlers.put(handler.getWrappedHandler().getClass(), handler);
|
||||
handlers.put(handler.getClass(), handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +88,7 @@ public class Session {
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Handler> T getHandler(Class<T> type) {
|
||||
return (T) handlers.get(type).getWrappedHandler();
|
||||
return (T) handlers.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,14 +103,6 @@ public class Session {
|
||||
|
||||
lastValid = location;
|
||||
lastRegionSet = set.getRegions();
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
disableBypass = cfg.disableDefaultBypass;
|
||||
if (cfg.announceBypassStatus && player.hasPermission("worldguard.region.toggle-bypass")) {
|
||||
player.printInfo(TextComponent.of(
|
||||
"You are " + (disableBypass ? "not" : "") + " bypassing region protection. " +
|
||||
"You can toggle this with /rg bypass", TextColor.DARK_PURPLE));
|
||||
}
|
||||
|
||||
|
||||
for (Handler handler : handlers.values()) {
|
||||
handler.initialize(player, location, set);
|
||||
|
||||
@@ -138,11 +138,4 @@ public abstract class Handler {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the handler wrapped by this handler object, if applicable, or just return this if no handler is wrapped.
|
||||
* @return any wrapped handler, or this handler itself
|
||||
*/
|
||||
public Handler getWrappedHandler() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
@@ -60,7 +60,7 @@ public final class SpongeUtil {
|
||||
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
|
||||
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
|
||||
BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
|
||||
BaseBlock block = world.getFullBlock(vector);
|
||||
BlockState block = world.getBlock(vector);
|
||||
BlockType blockType = block.getBlockType();
|
||||
if (isReplacable(blockType)) {
|
||||
try {
|
||||
|
||||
@@ -64,6 +64,11 @@ public class TestPlayer extends AbstractPlayerActor implements LocalPlayer {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultNamespace() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(String group) {
|
||||
return groups.contains(group.toLowerCase());
|
||||
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) 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 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 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.protection;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.MapFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public class FlagValueCalculatorMapFlagTest {
|
||||
@Test
|
||||
public void testGetEffectiveMapFlagWithFallback() throws Exception {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
|
||||
ProtectedRegion global = mock.global();
|
||||
global.setFlag(Flags.BUILD, StateFlag.State.DENY);
|
||||
MapFlag<String, StateFlag.State> mapFlag =
|
||||
new MapFlag<>("test", new StringFlag(null), new StateFlag(null, true));
|
||||
Map<String, StateFlag.State> map = new HashMap<>();
|
||||
map.put("allow", StateFlag.State.ALLOW);
|
||||
map.put("deny", StateFlag.State.DENY);
|
||||
global.setFlag(mapFlag, map);
|
||||
|
||||
ApplicableRegionSet applicableSet = mock.getApplicableSet();
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "allow", Flags.BUILD),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "deny", Flags.BUILD),
|
||||
equalTo(StateFlag.State.DENY));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "undefined", Flags.BUILD),
|
||||
equalTo(StateFlag.State.DENY));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "allow", null),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "deny", null),
|
||||
equalTo(StateFlag.State.DENY));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "undefined", null),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEffectiveMapFlagWithSamePriority() throws Exception {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
|
||||
ProtectedRegion region1 = mock.add(0);
|
||||
ProtectedRegion region2 = mock.add(0);
|
||||
|
||||
MapFlag<String, StateFlag.State> mapFlag =
|
||||
new MapFlag<>("test", new StringFlag(null), new StateFlag(null, true));
|
||||
Map<String, StateFlag.State> map1 = new HashMap<>();
|
||||
Map<String, StateFlag.State> map2 = new HashMap<>();
|
||||
|
||||
map1.put("should-deny", StateFlag.State.ALLOW);
|
||||
map2.put("should-deny", StateFlag.State.DENY);
|
||||
|
||||
map1.put("should-allow", StateFlag.State.ALLOW);
|
||||
|
||||
map1.put("should-allow2", StateFlag.State.ALLOW);
|
||||
map2.put("should-allow2", StateFlag.State.ALLOW);
|
||||
|
||||
region1.setFlag(mapFlag, map1);
|
||||
region2.setFlag(mapFlag, map2);
|
||||
|
||||
ApplicableRegionSet applicableSet = mock.getApplicableSet();
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "should-deny", null),
|
||||
equalTo(StateFlag.State.DENY));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "should-allow", null),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "should-allow2", null),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetEffectiveMapFlagWithInheritance() throws Exception {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
|
||||
ProtectedRegion parent = mock.add(0);
|
||||
ProtectedRegion child = mock.add(0, parent);
|
||||
|
||||
MapFlag<String, StateFlag.State> mapFlag =
|
||||
new MapFlag<>("test", new StringFlag(null), new StateFlag(null, true));
|
||||
Map<String, StateFlag.State> parentMap = new HashMap<>();
|
||||
Map<String, StateFlag.State> childMap = new HashMap<>();
|
||||
|
||||
parentMap.put("useChildValue", StateFlag.State.ALLOW);
|
||||
childMap.put("useChildValue", StateFlag.State.DENY);
|
||||
|
||||
parentMap.put("useParentValue", StateFlag.State.ALLOW);
|
||||
|
||||
parent.setFlag(mapFlag, parentMap);
|
||||
child.setFlag(mapFlag, childMap);
|
||||
|
||||
ApplicableRegionSet applicableSet = mock.getApplicableSet();
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "useChildValue", null),
|
||||
equalTo(StateFlag.State.DENY));
|
||||
assertThat(applicableSet.queryMapValue(null, mapFlag, "useParentValue", null),
|
||||
equalTo(StateFlag.State.ALLOW));
|
||||
}
|
||||
}
|
||||
+4
-72
@@ -27,7 +27,6 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.TestPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.association.RegionOverlapAssociation;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
@@ -38,14 +37,10 @@ import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public abstract class RegionOverlapTest {
|
||||
static String COURTYARD_ID = "courtyard";
|
||||
static String FOUNTAIN_ID = "fountain";
|
||||
@@ -64,14 +59,6 @@ public abstract class RegionOverlapTest {
|
||||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: useMaxPrio = {0}")
|
||||
public static Iterable<Object[]> params() {
|
||||
return Arrays.asList(new Object[][]{{true}, {false}});
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public boolean useMaxPriorityAssociation;
|
||||
|
||||
protected FlagRegistry getFlagRegistry() {
|
||||
return WorldGuard.getInstance().getFlagRegistry();
|
||||
}
|
||||
@@ -117,7 +104,6 @@ public abstract class RegionOverlapTest {
|
||||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
region.setOwners(domain);
|
||||
region.setPriority(5);
|
||||
manager.addRegion(region);
|
||||
|
||||
courtyard = region;
|
||||
@@ -130,7 +116,6 @@ public abstract class RegionOverlapTest {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
BlockVector3.ZERO, BlockVector3.at(5, 5, 5));
|
||||
region.setMembers(domain);
|
||||
region.setPriority(10);
|
||||
manager.addRegion(region);
|
||||
|
||||
fountain = region;
|
||||
@@ -183,6 +168,10 @@ public abstract class RegionOverlapTest {
|
||||
public void testPlayer2BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> test = new HashSet<>();
|
||||
test.add(courtyard);
|
||||
test.add(fountain);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.testState(player2, Flags.BUILD));
|
||||
@@ -193,61 +182,4 @@ public abstract class RegionOverlapTest {
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.testState(player2, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonPlayerBuildAccessInOneRegion() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
source.add(courtyard);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.testState(assoc, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonPlayerBuildAccessInBothRegions() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
source.add(fountain);
|
||||
source.add(courtyard);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(useMaxPriorityAssociation ^ appl.testState(assoc, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonPlayerBuildAccessInNoRegions() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.testState(assoc, Flags.BUILD));
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 614.24 143.11"><defs><style>.cls-1{fill:none;}.cls-2{fill:#2d2d2d;}.cls-3{clip-path:url(#clip-path);}.cls-4{fill:url(#New_Gradient_Swatch_copy);}.cls-5{mask:url(#mask);}.cls-6{opacity:0.1;}.cls-7{fill:url(#New_Gradient_Swatch_copy-2);}.cls-8{mask:url(#mask-2);}.cls-9{fill:url(#New_Gradient_Swatch_copy-3);}.cls-10{mask:url(#mask-3);}.cls-11{fill:#fff;}.cls-12{filter:url(#luminosity-invert);}</style><clipPath id="clip-path"><path class="cls-1" d="M78.54,138.1c-3.85,3.85-10.45,3.45-14.33-.42L5.07,78.54a9.85,9.85,0,0,1-.07-14L63.63,6c3.85-3.85,11.25-4.68,15.13-.8l59,59c3.88,3.88,3.63,11.13-.23,15Z"/></clipPath><linearGradient id="New_Gradient_Swatch_copy" x1="71.56" y1="3.86" x2="71.56" y2="141.19" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#006bff"/><stop offset="1" stop-color="#004dff"/></linearGradient><filter id="luminosity-invert" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"><feColorMatrix values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"/></filter><mask id="mask" x="29.59" y="-2.48" width="83" height="42" maskUnits="userSpaceOnUse"><g class="cls-12"><image width="83" height="42" transform="translate(29.59 -2.48)" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAAqCAYAAADPn2cJAAAACXBIWXMAAAsSAAALEgHS3X78AAAGoklEQVRoQ+2bWXObQBCEGxDLcsjR6eT//7vEcbmcyDE3eVD11jBaST50PXiqKKILlo+entnFCQAM+IqTRHjsC1/x9pgc+8I1IwxDRFEEAAiCAH3fu+0W42ZhTiYTWGthjHFA27ZF0zQoyxJt2x45wuXjJmHGcYyiKJDn+Qhm13Wo6xovLy/YbDZomubIkS4bNwczSRJ8+/ZtBDMMt9be9z3qukaSJDDG4Pn5GWVZHjni5eKmYFprMZ/PcXd3h+l0iizLEMfxSJlN0yBJEsRxjDAM8fT0dDNAbwamtRar1Qrz+RzT6RRFUcBaiyRJRsqsqsq9T9CPj494fX09cobzx03ATNMUq9UKy+USs9kM0+kUeZ7DWutVZlmWDuZkMkEYhnh4eLg60KvDzLIM6/Uay+USi8Vi5JcynYGtMpum2VFnGIYO6MvLy5Ezni+uCjPLMtzf32O9XmOxWGA2m+Hu7g5FUSDLsqMwqcwoihBFEYIgwK9fv64G9Gow8zzH9+/fsVqtnFfOZjMURYGiKJCm6VGYxhgkSeKABkHggG42myMjOH1cBSZB3t/fY7lcOq+UKU6Y9ERgC7NtW5Rl6dKcfShhhmGIIAgwDMPFFXpxmHme48ePH1iv1zteOZ1OXUskZz+yALVtizRNXREyxjhl0juB7fTz58+f+Pv376HhnDQuCpMg6ZMEOZ/PnSqZ4tITtTLZa/pAMtX5m2EYLpbyF4MpQcr0plfKwpOmKYwxDlYQBAC2YNq2Hc2C4jh27ROhEugwbFcXL6XQi8DUINlTEiRTPM/zUYpLSMA2zdlr1nU9quZSmQB29pdQ6Nlh7gMp05sznizLXEtEmNIHufwmYUpF+mACuJhCzwpTVm16pATJ2Q5hsoLLmQ+rNLCF0nXdTmrr9GYMw+A2vu77/mxV/mwwsyxzINlLMrUlSO2VcprI4iNhsggRIj1Vf88XUqHnSPmzwCTI9Xq9k9bSIyVImd5siWSKM/q+dxClGiVIqUTeAG7y9b9//3bG/pk4OUw5RZQgZ7PZCKT2SRYdVnCpNBm+NkiDPASRewAnn3qeFGaapg6iVCIhUolylsOeUk4NtRp1BEHgKjxjH8S2bV0X0HXd6BkSv3uq1aaTwbTW7i0yhJjnuYNorXUeqRX51pBAj0H0Ae26DsMw4OHh4SQpfxKYXNhdLBYupaUS8zzfUaNuut8LkhGG2yeYcRyPWqc0TdG2rZsxyb0EK2/CZ1fsPw3TWrvTN/Kxg0xpLkxob5RN90eClVxWd2MM2raFtXYEVkLVYIdhwO/fvz8F9FMwkyQZtToSopzNSIi67ZF95EdDzsfDMHTHj+PYeXFd10jT1DX8hEmgVOfj4yOqqjp2Sm98GKYxZm9hkRCPLUicImRf6QNLK+F4rLXIsswpVKq073s8PT19COiHYMZx7CBKkNIPZfMtZyq6jem6zr2/rx06FLLosPUhXAmWFqChUq3SBgj0vc/l3w0zjmPXJ3JxgtWZ00C9AEFAsopybZKf6dXyQ1D19JBFR6YtVeYDK9VqrUVVVQ6qLE5//vx5F9B3wZxMJsjz/CBELk7oKSDhUQEsOPJzpqZWqJ4mcs/CIW+O9kQJlsciVN50+qq11v2Wv9tsNm/+U5w3w4yiCFmWjSD65tEMDZEApUrbtt2xAl4o4F9G41436F3XOYAEUpYlqqryFhuGzwKste77fb+ddr4F6JtgRlHkTFtDlKnpA1hVlVeF2g58xWlfuyS9UcKUyqdCq6oabbLg8Di+gmWMgbXWwX99fUXXdd7xMI7CZDr4WhupGF5IXdcjlTINeZGEKCu8hikVrL1TqpLH3geUCvVBresadV2PFMjzyX61abaPSLpu+0djh4AehEmQvqeAvKtahTqNm6aBMQZVVY18VTfsPK5UOuCHyb2u5NI7pUK5EWJVVc4C+J60AILluIwxo4ImbULGXpi8MAlQp7IuJBosZzoaYByPV8hl1ZcprkEyOAad6hKo9FCtVKlWKlT6qwTHsVCt8rw6vDClh2hYhwAyfSU8mc4yrWkFMq0lUI7DFzrVJVyCkJXcp9Z9gOVGsARHqLxxGuhemNIPOTipTJ6cSpOK0/B8RUaD9MHkWGTINJfj03uqVO4JWO6leiVwvecxfHwYOzA1RN4ZqtIHR9rBIWhvUeIhkAx5AT6VcuPYtbdqwNoe+Fqrm+/viwDY/a8rvouTfqY3Hxyf2uSmzyP3vrEwfF7lU6v+t7YD32v9md58x5bhhfkVH4uPLSJ+hTf+A45XAcRn3tf4AAAAAElFTkSuQmCC"/></g></mask><linearGradient id="New_Gradient_Swatch_copy-2" x1="71.55" y1="3.86" x2="71.55" y2="141.19" xlink:href="#New_Gradient_Swatch_copy"/><mask id="mask-2" x="-2.41" y="45.52" width="148" height="51" maskUnits="userSpaceOnUse"><g class="cls-12"><image width="148" height="51" transform="translate(-2.41 45.52)" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAAzCAYAAABxJSGCAAAACXBIWXMAAAsSAAALEgHS3X78AAAInklEQVR4Xu1d63arvA4cY65J3/9BdxpuBnN+5IwRhiRA0n609azFSgMJYGk0koWztwIwICDgTYiefSAgYAviZx/4Diil3Cs3iWEYJttvB8cfRdHENgRtcES7HIJQAKC1RhzHiKJoYshhGGCtRd/3bjuK8b4ScRzPbEJYa2GtRdd1h7PJIQgVRRHiOEaSJEiSBFprZ0Aarus6GGNgrT2M8b4KURRBa40sy5CmqSOVUmoSYG3bomkaWGufnfLbcAhCKaWgtUaSJMiybEYorTWUUuj7fpYOfyOUUs4WaZoiSZKJavd9j67rnE2MMU/O+H04BKGAW8qj8RiRwI1QjExjzJ8hFANM2oRj77oOURRhGIbJ/iPgEISiAVkzcGOtAEyV6reD9mAZwLTHwGKw9X0/Cb6tWCr0X8VbCPXqjbHoJJEo8VprVzORcH+BUL4tZF0pCdV13UsKpZRy53xXbfoyoRhNwI1Mfd8/+cYcURQ5o3F2o7XGMAwz9eK1fjN8O8jZHm1irZ2o+R6QuMA4+Xm1wN93J/8Hb4jKYa11g/Z7I/xb9lUYIXmeu/NQmRiFSinEcYy+75EkCfI8n02V3xFZ/xV8e2itnT18UsnUJtWrKAo3E37Uk+K1mBFkbcZZozFmlygQuwkli0ZJKDqb9c/SACWZ0jR15+BAeQyAk3gSLU3TWQvBP//RCeanKI5X2kMGGMfuE4JES9MURVGgaRpnewBOzfxr0HfMCvRdkiSo6xpN06DrOuzBLkJxEHmeOzIAcIQyxswiRjqZg5MGI5G4yc9KAjKKGUVSon0VPDKWxiiVyB+ztIt/nJmC9gamtpDnj+MYWZY5dSKhhmGYzLCrqtpFqs2EoiSfTqdJ042FHfOw73BfNbhf67HwJnxS8fu8xiMFPLine truncated
|
||||
|
Before Width: | Height: | Size: 14 KiB |
Reference in new issue
Block a user