Compare commits

...
44 Commits
Author SHA1 Message Date
wizjany 33cdb4a6a8 Release 7.0.8 2023-05-27 13:39:01 -04:00
wizjany feb548aa84 Check movement on AbstractHorse instead of Horse.
Not tested cuz I don't know how to enable camels, but in theory this should work for that.
2023-05-16 17:04:28 -04:00
wizjany 961461c23c Protect against allay pickups and modification.
Closes #1923.
2023-05-16 17:02:19 -04:00
wizjany ad6d5af592 Treat tameables with offline owners as unknown causes.
Paper-only.

Closes #1900.
2023-05-16 16:15:57 -04:00
wizjany 7ae7a04721 Make region wand act more like /rg info.
Addresses the part that #1534 and #1817 missed.
2023-05-16 15:25:52 -04:00
wizjany 40adfe9cef Add dragon egg teleporting to build protection.
Closes #1977.
2023-05-16 14:22:47 -04:00
Joo200 78498491dd Remove timings for third-party session handlers
Reverted MR #1717
2023-04-09 21:27:13 -04:00
stonar96 ca636d20af Fix NPE when non-player entities create new nether portals (#1995)
* Fix NPE when non-player entities create new nether portals

* Fix flag checking for portal create event

* Use failed load region set

* Clean up
2023-04-09 21:25:44 -04:00
Joo200 bddfbdd353 gradle: updated wrapper to gradle 8.0.2 2023-03-26 15:14:10 +02:00
JOO200 ece376a69e Improve NPC handling in WorldGuard's listeners (#1988)
* fix: added more npc checks in listeners
* Do not listen to events from NPCs such as Citizens. Don't handle NPCs as players.
* replaced hasMetaData calls by Entities utilities class
2023-03-23 18:58:48 +01:00
wizjany 1e81a91d4d Bump squirrelid, remove workaround. 2023-03-23 11:47:02 -04:00
JOO200 216f95f87c Merge pull request #1989 from EngineHub/feature/copper-fade-flag
Add copper-fade flag to WorldGuard
2023-03-23 15:05:53 +01:00
JOO200 ca6e228f61 Merge pull request #1973 from EngineHub/feat/datapackreport
Add DataPack Report to track active DataPacks
2023-03-23 14:53:06 +01:00
Joo200 fd1cb1e4bd flags: added copper-fade flag to prevent oxidizing copper 2023-03-19 16:56:46 +01:00
Joo200 8c8a8092b5 deps: updated Paper repository to new url, updated bstats to 3.0.1 2023-03-12 16:50:21 +01:00
Maddy Miller 1729e5e3d6 Add additional holder snapshot bypasses for performance (#1978)
* Add additional holder snapshot bypasses for performance

* Extra optimisation - cuts lookups of block data in the world by half
2023-01-19 20:28:54 +10:00
Madeline Miller 46dfb69fb1 Use updated PaperLib for InventoryHolder optimisation 2023-01-05 21:28:13 +10:00
Joo200 9ceecf5d3a Add DataPack Report to track active DataPacks 2022-12-27 13:39:35 +01:00
Maddy Miller 20044a72d3 fix: re-enable no snapshot inventories (#1972) 2022-12-26 10:29:26 +10:00
JOO200 8bc7ff49ab Merge pull request #1971 from EngineHub/version/1.19.3
Update to Minecraft 1.19.3
2022-12-19 11:01:20 +01:00
Joo200 6f749b058b Restore 1.19.2 compatibility 2022-12-09 16:37:04 +01:00
Joo200 91380a8316 Updated wrapper 2022-12-09 13:26:02 +01:00
Joo200 ba55cc79c2 Update to Minecraft 1.19.3 2022-12-09 13:23:57 +01:00
aromaa cb100bb797 Improve compatibility with the new onClearValue 2022-09-20 09:07:27 -04:00
Joni Aromaa bd1d772faa Introduce uninitialize for sessions (#1940)
* Introduce uninitialize for sessions

* Add FlagValueChangeHandler#onClearValue
2022-09-18 11:18:08 -04:00
wizjany f1f1e8aa7d Remove command reg delay for CommandBook compat.
This may break said compat but I doubt anyone is using it anyway.

Fixes #1943.
2022-08-28 10:15:49 -04:00
wizjany 598c441718 Back to snapshot.
Also update changelog
2022-07-27 21:28:09 -04:00
wizjany cbb2ba7216 Release 7.0.8 beta 1. 2022-07-27 21:15:21 -04:00
dordsor21 e756d127c5 Account for possible world nullability for Entity#getOrigin Location 2022-07-27 21:15:31 -04:00
Joo200 0d2ed8205f Properly protect chest_boats as vehicles 2022-07-07 21:04:44 +02:00
JOO200 6efdb1089e Fix Report for Spigot based servers
Bukkit.spigot().getSpigotConfig() is the paper implementation, it's not available on Non-Paper servers
2022-06-21 20:44:30 +02:00
wizjany 4a21bf43e7 Check if InventoryHolder BlockState is placed.
Closes #1903.
2022-06-14 11:31:24 -04:00
JOO200 3a181a230f Tidy up Materials.java, added missing effect type, removed todo for paper only 2022-06-14 11:25:06 -04:00
JOO200 857f7468d8 Add Sculk Growth Flag and options to disable sculk growths 2022-06-14 11:25:06 -04:00
JOO200 f8e8d0f01e Plugin Version to 1.19, cleanup from Materials, added 1.19 Materials 2022-06-14 11:25:06 -04:00
JOO200 23521858fd Bumped versions: Minecraft to 1.19 and JDK 17 2022-06-14 11:25:06 -04:00
JOO200 0fddd2a573 Fixed Typo in CommandException 2022-04-26 18:26:07 +02:00
JOO200 85dd012b85 Improvement and Cleanup Domain view for /region info
* Don't suggest the uuids to the command line, copy them to the clipboard instead
* Tidy up the hover events and added hints to copy uuids
2022-04-09 11:46:54 +02:00
wizjany dc23af7947 Skip lookups on claim.
Claim hasn't allowed user-input for ages, so no need to resolve anything.
2022-04-05 12:23:32 -04:00
JOO200 b698941378 Append OnlineMode server information to ServerReport (#1891) 2022-04-03 16:35:34 -04:00
wizjany 271b32aa1d Default chest-protection.disable-off-check to true.
Fixes #1890.
2022-03-24 10:01:17 -04:00
wizjany 938f0c3b66 Handle all the amethyst growth.
Fixes #1889.
2022-03-20 08:26:41 -04:00
wizjany 216b061172 Fix class source validator on spigot. 2022-03-06 08:59:44 -05:00
wizjany 27dca2b506 Bump to snapshot. 2022-03-03 15:05:52 -05:00
49 changed files with 651 additions and 854 deletions

No files matched your search

+15
View File
@@ -1,5 +1,20 @@
# Changelog
## 7.0.8
* Add support for MC 1.19
* Add skulk-growth flag and config option
* Add copper-fade flag
* Add data packs to report output
* Add protection for allay inventory slot
* Categorize allay item pickups under item-pickup flag
* Categorize dragon egg interaction (teleporting) as building
* Ignore most NPC-based actions for Player events
* Optimize handling of tamed animals where the owner was offline (Paper only)
* Optimize additional InventoryHolder accesses (Paper only)
* Fix an exception that occurred when plugins created portals with non-player entities
* Fix possible error when using Paper's entity origin API
* Update bstats and squirrelid libs
## 7.0.7
* Add rock-growth flag for budding amethyst and pointed dripstone.
* Add /rg migrateheights command. See https://worldguard.enginehub.org/en/latest/regions/commands/#migrate-region-heights
+3 -3
View File
@@ -1,11 +1,11 @@
Compiling
=========
You can compile WorldGuard as long as you have some version of Java greater than or equal to 16 installed. Gradle will download JDK 16 specifically if needed,
You can compile WorldGuard as long as you have some version of Java greater than or equal to 17 installed. Gradle will download JDK 17 specifically if needed,
but it needs some version of Java to bootstrap from.
Note that if you have JRE 16 installed, Gradle will currently attempt to use that to compile, which will not work. It is easiest to uninstall JRE 16 and
replace it with JDK 16.
Note that if you have JRE 17 installed, Gradle will currently attempt to use that to compile, which will not work. It is easiest to uninstall JRE 16 and
replace it with JDK 17.
The build process uses Gradle, which you do *not* need to download. WorldGuard is a multi-module project with three modules:
+3 -3
View File
@@ -11,7 +11,7 @@ repositories {
dependencies {
implementation(gradleApi())
implementation("gradle.plugin.org.cadixdev.gradle:licenser:0.6.1")
implementation("org.ajoberstar.grgit:grgit-gradle:4.1.0")
implementation("com.github.jengelman.gradle.plugins:shadow:6.1.0")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0")
implementation("org.ajoberstar.grgit:grgit-gradle:4.1.1")
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.27.1")
}
+1 -1
View File
@@ -25,7 +25,7 @@ fun Project.applyCommonConfiguration() {
plugins.withId("java") {
the<JavaPluginExtension>().toolchain {
languageVersion.set(JavaLanguageVersion.of(16))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
configure<CheckstyleExtension> {
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
toolVersion = "8.34"
toolVersion = "10.3"
}
tasks.withType<Test>().configureEach {
+8 -7
View File
@@ -1,9 +1,10 @@
object Versions {
// const val PISTON = "0.4.3"
// const val AUTO_VALUE = "1.6.5"
const val WORLDEDIT = "7.2.7"
const val JUNIT = "5.7.0"
const val SQUIRRELID = "0.3.0"
const val GUAVA = "31.0.1-jre"
const val MOCKITO = "3.7.7"
// const val PISTON = "0.4.3"
// const val AUTO_VALUE = "1.6.5"
const val WORLDEDIT = "7.2.12"
const val JUNIT = "5.9.1"
const val MOCKITO = "4.9.0"
const val SQUIRRELID = "0.3.2"
const val GUAVA = "31.1-jre"
const val FINDBUGS = "3.0.2"
}
+1 -1
View File
@@ -30,7 +30,7 @@
<allow pkg="org.bstats.charts"/>
<allow pkg="io.papermc.lib"/>
<allow pkg="com.destroystokyo.paper"/>
<allow pkg="co.aikar.timings.lib" />
<allow pkg="io.papermc.paper"/>
<allow pkg="org.spigotmc" />
</subpackage>
+1 -1
View File
@@ -1,2 +1,2 @@
group=com.sk89q.worldguard
version=7.0.7
version=7.0.8
Binary file not shown.
+2 -1
View File
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+14 -4
View File
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# 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"'
@@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Vendored
+9 -6
View File
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
+5 -14
View File
@@ -10,15 +10,7 @@ applyShadowConfiguration()
repositories {
maven {
name = "paper"
url = uri("https://papermc.io/repo/repository/maven-public/")
}
maven {
name = "bstats"
url = uri("https://repo.codemc.org/repository/maven-public")
}
maven {
name = "aikar-timings"
url = uri("https://repo.aikar.co/nexus/content/groups/aikar/")
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
@@ -28,16 +20,15 @@ configurations {
dependencies {
"api"(project(":worldguard-core"))
"compileOnly"("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT")
"runtimeOnly"("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT") {
"compileOnly"("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
"runtimeOnly"("org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
"shadeOnly"("io.papermc:paperlib:1.0.7")
"shadeOnly"("org.bstats:bstats-bukkit:2.1.0")
"shadeOnly"("co.aikar:minecraft-timings:1.0.4")
"shadeOnly"("io.papermc:paperlib:1.0.8")
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
}
tasks.named<Copy>("processResources") {
@@ -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
@@ -244,7 +244,7 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
disableDeathMessages = getBoolean("player-damage.disable-death-messages", false);
signChestProtection = getBoolean("chest-protection.enable", false);
disableSignChestProtectionCheck = getBoolean("chest-protection.disable-off-check", false);
disableSignChestProtectionCheck = getBoolean("chest-protection.disable-off-check", true);
if (signChestProtection) {
log.warning("Sign-based chest protection is deprecated for removal in a future version. See https://worldguard.enginehub.org/en/latest/chest-protection/ for details.");
} else {
@@ -277,9 +277,11 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
disableRockGrowth = getBoolean("dynamics.disable-rock-growth", false);
disableSculkGrowth = getBoolean("dynamics.disable-sculk-growth", false);
disableCropGrowth = getBoolean("dynamics.disable-crop-growth", false);
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
disableCoralBlockFade = getBoolean("dynamics.disable-coral-block-fade", false);
disableCopperBlockFade = getBoolean("dynamics.disable-copper-block-fade", false);
allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null)));
useRegions = getBoolean("regions.enable", true);
@@ -34,6 +34,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.util.profile.resolver.PaperPlayerService;
import com.sk89q.worldguard.bukkit.protection.events.flags.FlagContextCreateEvent;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.bukkit.util.report.DatapackReport;
import com.sk89q.worldguard.bukkit.util.report.PerformanceReport;
import com.sk89q.worldguard.bukkit.util.report.PluginReport;
import com.sk89q.worldguard.bukkit.util.report.SchedulerReport;
@@ -138,7 +139,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());
@@ -146,6 +146,7 @@ public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
@Override
public void unload() {
sessionManager.shutdown();
configuration.unload();
regionContainer.shutdown();
}
@@ -238,6 +239,7 @@ public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
report.add(new ServicesReport());
report.add(new WorldReport());
report.add(new PerformanceReport());
if (PaperLib.isPaper()) report.add(new DatapackReport());
}
@Override
@@ -60,6 +60,7 @@ import com.sk89q.worldguard.bukkit.listener.WorldGuardWorldListener;
import com.sk89q.worldguard.bukkit.listener.WorldRulesListener;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.bukkit.util.ClassSourceValidator;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.commands.GeneralCommands;
import com.sk89q.worldguard.commands.ProtectionCommands;
@@ -158,11 +159,9 @@ public class WorldGuardPlugin extends JavaPlugin {
reg.register(ToggleCommands.class);
reg.register(ProtectionCommands.class);
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
reg.register(GeneralCommands.class);
}
}, 0L);
if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
reg.register(GeneralCommands.class);
}
getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
@@ -421,8 +420,9 @@ public class WorldGuardPlugin extends JavaPlugin {
}
public Actor wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
if (sender instanceof Player player) {
if (Entities.isNPC(player)) return null;
return wrapPlayer(player);
}
try {
@@ -24,9 +24,12 @@ import com.google.common.collect.Sets;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.internal.WGMetadata;
import com.sk89q.worldguard.bukkit.util.Entities;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
@@ -106,6 +109,12 @@ public final class Cause {
return false;
}
if (object instanceof Tameable tameable && tameable.isTamed()) {
// if they're tamed but also the root cause, the owner is offline
// otherwise the owner will be the root cause (and known)
return false;
}
if (object instanceof TNTPrimed || object instanceof Vehicle) {
if (!PaperLib.isPaper()) {
return false;
@@ -134,8 +143,8 @@ public final class Cause {
@Nullable
public Player getFirstPlayer() {
for (Object object : causes) {
if (object instanceof Player) {
return (Player) object;
if (object instanceof Player p && !Entities.isNPC(p)) {
return p;
}
}
@@ -145,8 +154,8 @@ public final class Cause {
@Nullable
public Entity getFirstEntity() {
for (Object object : causes) {
if (object instanceof Entity) {
return (Entity) object;
if (object instanceof Entity e) {
return e;
}
}
@@ -156,8 +165,8 @@ public final class Cause {
@Nullable
public Entity getFirstNonPlayerEntity() {
for (Object object : causes) {
if (object instanceof Entity && !(object instanceof Player)) {
return (Entity) object;
if (object instanceof Entity e && (!(object instanceof Player) || Entities.isNPC(e))) {
return e;
}
}
@@ -167,8 +176,8 @@ public final class Cause {
@Nullable
public Block getFirstBlock() {
for (Object object : causes) {
if (object instanceof Block) {
return (Block) object;
if (object instanceof Block b) {
return b;
}
}
@@ -299,9 +308,24 @@ public final class Cause {
} else if (o instanceof AreaEffectCloud) {
indirect = true;
addAll(((AreaEffectCloud) o).getSource());
} else if (o instanceof Tameable) {
} else if (o instanceof Tameable tameable) {
indirect = true;
addAll(((Tameable) o).getOwner());
if (PaperLib.isPaper()) {
UUID ownerId = tameable.getOwnerUniqueId();
if (ownerId != null) {
Player owner = Bukkit.getPlayer(ownerId);
if (owner != null) {
addAll(owner);
}
}
} else {
// this will cause offline player loads if the player is offline
// too bad for spigot users
AnimalTamer owner = tameable.getOwner();
if (owner instanceof OfflinePlayer player) {
addAll(player.getPlayer()); // player object if online, else null
}
}
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
indirect = true;
addAll(((Creature) o).getTarget());
@@ -29,6 +29,7 @@ import com.sk89q.worldguard.bukkit.BukkitPlayer;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation;
@@ -124,18 +125,18 @@ class AbstractListener implements Listener {
if (!cause.isKnown()) {
return Associables.constant(Association.NON_MEMBER);
} else if (rootCause instanceof Player) {
return getPlugin().wrapPlayer((Player) rootCause);
} else if (rootCause instanceof OfflinePlayer) {
return getPlugin().wrapOfflinePlayer((OfflinePlayer) rootCause);
} else if (rootCause instanceof Entity) {
} else if (rootCause instanceof Player player && !Entities.isNPC(player)) {
return getPlugin().wrapPlayer(player);
} else if (rootCause instanceof OfflinePlayer offlinePlayer) {
return getPlugin().wrapOfflinePlayer(offlinePlayer);
} else if (rootCause instanceof Entity entity) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
final Entity entity = (Entity) rootCause;
BukkitWorldConfiguration config = getWorldConfig(entity.getWorld());
Location loc;
if (PaperLib.isPaper() && config.usePaperEntityOrigin) {
loc = entity.getOrigin();
if (loc == null) {
// Origin world may be null, and thus a Location with a null world created, which cannot be adapted to a WorldEdit location
if (loc == null || loc.getWorld() == null) {
loc = entity.getLocation();
}
} else {
@@ -143,9 +144,9 @@ class AbstractListener implements Listener {
}
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
config.useMaxPriorityAssociation);
} else if (rootCause instanceof Block) {
} else if (rootCause instanceof Block block) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location loc = ((Block) rootCause).getLocation();
Location loc = block.getLocation();
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
getWorldConfig(loc.getWorld()).useMaxPriorityAssociation);
} else {
@@ -22,8 +22,6 @@ package com.sk89q.worldguard.bukkit.listener;
import static com.sk89q.worldguard.bukkit.cause.Cause.create;
import com.destroystokyo.paper.event.entity.EntityZapEvent;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.DelegateEvent;
@@ -115,6 +113,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.ExpBottleEvent;
@@ -142,7 +141,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.plugin.PluginManager;
@@ -165,17 +163,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.
*
@@ -933,6 +920,12 @@ public class EventAbstractionListener extends AbstractListener {
pickupDebounce.debounce(event.getPlayer(), item, event, new DestroyEntityEvent(event, create(event.getPlayer()), event.getItem()));
}
@EventHandler(ignoreCancelled = true)
public void onEntityPickupItem(EntityPickupItemEvent event) {
Item item = event.getItem();
pickupDebounce.debounce(event.getEntity(), item, event, new DestroyEntityEvent(event, create(event.getEntity()), event.getItem()));
}
@EventHandler(ignoreCancelled = true)
public void onPlayerDropItem(PlayerDropItemEvent event) {
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getItemDrop()));
@@ -963,12 +956,7 @@ 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();
}
InventoryHolder causeHolder = PaperLib.getHolder(event.getInitiator(), false).getHolder();
WorldConfiguration wcfg = null;
if (causeHolder instanceof Hopper
@@ -982,15 +970,8 @@ public class EventAbstractionListener extends AbstractListener {
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 = PaperLib.getHolder(event.getSource(), false).getHolder();
InventoryHolder targetHolder = PaperLib.getHolder(event.getDestination(), false).getHolder();
Cause cause;
@@ -1197,9 +1178,12 @@ public class EventAbstractionListener extends AbstractListener {
}
// Handle created spawn eggs
if (item != null && Materials.isSpawnEgg(item.getType())) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), Materials.getEntitySpawnEgg(item.getType())));
return;
if (item != null) {
EntityType possibleEntityType = Materials.getEntitySpawnEgg(item.getType());
if (possibleEntityType != null) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), possibleEntityType));
return;
}
}
// handle water/lava placement
@@ -1215,8 +1199,7 @@ public class EventAbstractionListener extends AbstractListener {
return;
}
if (holder instanceof Entity) {
Entity entity = (Entity) holder;
if (holder instanceof Entity entity) {
Material mat = Materials.getRelatedMaterial((entity).getType());
UseEntityEvent useEntityEvent = new UseEntityEvent(originalEvent, cause, entity);
if (mat != null && hasInteractBypass((entity).getWorld(), mat)) {
@@ -1224,8 +1207,7 @@ public class EventAbstractionListener extends AbstractListener {
}
Events.fireToCancel(originalEvent, useEntityEvent);
} else {
if (holder instanceof BlockState) {
final BlockState block = (BlockState) holder;
if (holder instanceof BlockState block && block.isPlaced()) {
final UseBlockEvent useBlockEvent = new UseBlockEvent(originalEvent, cause, block.getBlock());
if (hasInteractBypass(block.getWorld(), block.getType())) {
useBlockEvent.setAllowed(true);
@@ -22,6 +22,7 @@ package com.sk89q.worldguard.bukkit.listener;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.Entities;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@@ -57,9 +58,9 @@ public class InvincibilityListener extends AbstractListener {
@EventHandler(ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
Entity victim = event.getEntity();
if (Entities.isNPC(victim)) return;
if (victim instanceof Player) {
Player player = (Player) victim;
if (victim instanceof Player player) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (isInvincible(localPlayer)) {
@@ -87,9 +88,9 @@ public class InvincibilityListener extends AbstractListener {
@EventHandler(ignoreCancelled = true)
public void onEntityCombust(EntityCombustEvent event) {
Entity entity = event.getEntity();
if (Entities.isNPC(entity)) return;
if (entity instanceof Player) {
Player player = (Player) entity;
if (entity instanceof Player player) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (isInvincible(localPlayer)) {
@@ -100,8 +101,9 @@ public class InvincibilityListener extends AbstractListener {
@EventHandler(ignoreCancelled = true)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (Entities.isNPC(event.getEntity())) return;
if (event.getEntity() instanceof Player player) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (event.getFoodLevel() < player.getFoodLevel() && isInvincible(localPlayer)) {
@@ -28,8 +28,8 @@ import com.sk89q.worldguard.session.Session;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -99,7 +99,7 @@ public class PlayerMoveListener extends AbstractListener {
moveType = MoveType.GLIDE;
} else if (event.getPlayer().isSwimming()) {
moveType = MoveType.SWIM;
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Horse) {
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof AbstractHorse) {
moveType = MoveType.RIDE;
}
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
@@ -148,6 +148,8 @@ public class PlayerMoveListener extends AbstractListener {
if (loc != null) {
player.teleport(BukkitAdapter.adapt(loc));
}
session.uninitialize(localPlayer);
}
private class EntityMountListener implements Listener {
@@ -25,6 +25,7 @@ import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.association.RegionAssociable;
@@ -118,24 +119,24 @@ public class RegionFlagsListener extends AbstractListener {
World world = entity.getWorld();
if (!isRegionSupportEnabled(world)) return; // Region support disabled
if (Entities.isNPC(entity)) return;
if (!(entity instanceof Player player)) return;
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
if (entity instanceof Player && event.getCause() == DamageCause.FALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer((Player) entity);
if (event.getCause() == DamageCause.FALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), localPlayer, Flags.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
} else {
if (entity instanceof Player && event.getCause() == DamageCause.FLY_INTO_WALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer((Player) entity);
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), localPlayer, Flags.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
} else if (event.getCause() == DamageCause.FLY_INTO_WALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), localPlayer, Flags.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
}
}
/**
@@ -522,8 +522,7 @@ public class RegionProtectionListener extends AbstractListener {
if (!isRegionSupportEnabled(vehicle.getWorld())) return; // Region support disabled
Entity exited = event.getExited();
if (vehicle instanceof Tameable && exited instanceof Player) {
Player player = (Player) exited;
if (vehicle instanceof Tameable && exited instanceof Player player && !Entities.isNPC(player)) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (!isWhitelisted(Cause.create(player), vehicle.getWorld(), false)) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
@@ -588,7 +588,7 @@ public class WorldGuardBlockListener extends AbstractListener {
}
}
if (newType == Material.BUDDING_AMETHYST || newType == Material.POINTED_DRIPSTONE) {
if (Materials.isAmethystGrowth(newType) || newType == Material.POINTED_DRIPSTONE) {
if (wcfg.disableRockGrowth) {
event.setCancelled(true);
return;
@@ -601,6 +601,19 @@ public class WorldGuardBlockListener extends AbstractListener {
}
}
if (Materials.isSculkGrowth(newType)) {
if (wcfg.disableSculkGrowth) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SCULK_GROWTH))) {
event.setCancelled(true);
return;
}
}
handleGrow(event, event.getBlock().getLocation(), newType);
}
@@ -684,6 +697,16 @@ public class WorldGuardBlockListener extends AbstractListener {
event.setCancelled(true);
return;
}
} else if (Materials.isUnwaxedCopper(event.getBlock().getType())) {
if (wcfg.disableCopperBlockFade) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.COPPER_FADE))) {
event.setCancelled(true);
return;
}
}
}
@@ -25,13 +25,17 @@ import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.InteropUtils;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.FailedLoadRegionSet;
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.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.RegionQuery;
@@ -138,8 +142,7 @@ public class WorldGuardEntityListener extends AbstractListener {
event.setCancelled(true);
return;
}
} else if (defender instanceof Player) {
Player player = (Player) defender;
} else if (defender instanceof Player player && !Entities.isNPC(defender)) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
@@ -227,8 +230,7 @@ public class WorldGuardEntityListener extends AbstractListener {
}
}
if (defender instanceof Player) {
Player player = (Player) defender;
if (defender instanceof Player player && !Entities.isNPC(defender)) {
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
if (wcfg.disableLightningDamage && event.getCause() == DamageCause.LIGHTNING) {
@@ -289,8 +291,7 @@ public class WorldGuardEntityListener extends AbstractListener {
}
WorldConfiguration wcfg = getWorldConfig(defender.getWorld());
if (defender instanceof Player) {
Player player = (Player) defender;
if (defender instanceof Player player && !Entities.isNPC(defender)) {
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
@@ -363,8 +364,7 @@ public class WorldGuardEntityListener extends AbstractListener {
event.setCancelled(true);
return;
}
} else if (defender instanceof Player) {
Player player = (Player) defender;
} else if (defender instanceof Player player && !Entities.isNPC(defender)) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (type == DamageCause.WITHER) {
@@ -657,35 +657,46 @@ public class WorldGuardEntityListener extends AbstractListener {
public void onCreatePortal(PortalCreateEvent event) {
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
if (wcfg.regionNetherPortalProtection
if (wcfg.useRegions && wcfg.regionNetherPortalProtection
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
&& !event.getBlocks().isEmpty()) {
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
.get(world);
if (regionManager == null) return;
LocalPlayer associable = null;
if (event.getEntity() instanceof Player) {
associable = getPlugin().wrapPlayer(((Player) event.getEntity()));
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
final Cause cause = Cause.create(event.getEntity());
LocalPlayer localPlayer = null;
if (cause.getRootCause() instanceof Player player) {
if (wcfg.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
return;
}
localPlayer = getPlugin().wrapPlayer(player);
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) {
return;
}
}
BlockVector3 min = null;
BlockVector3 max = null;
for (BlockState block : event.getBlocks()) {
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
min = min == null ? loc : loc.getMinimum(min);
max = max == null ? loc : loc.getMaximum(max);
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
.get(world);
ApplicableRegionSet regions;
if (regionManager == null) {
regions = FailedLoadRegionSet.getInstance();
} else {
BlockVector3 min = null;
BlockVector3 max = null;
for (BlockState block : event.getBlocks()) {
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
min = min == null ? loc : loc.getMinimum(min);
max = max == null ? loc : loc.getMaximum(max);
}
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
regions = regionManager.getApplicableRegions(target);
}
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
final ApplicableRegionSet regions = regionManager.getApplicableRegions(target);
if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) {
if (associable != null) {
final RegionAssociable associable = createRegionAssociable(cause);
final State buildState = StateFlag.denyToNone(regions.queryState(associable, Flags.BUILD));
if (!StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_BREAK))
|| !StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_PLACE))) {
if (localPlayer != null && !cause.isIndirect()) {
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
// removing PTA was a mistake
String message = regions.queryValue(associable, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message);
String message = regions.queryValue(localPlayer, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("create portals", localPlayer, message);
}
event.setCancelled(true);
}
@@ -745,10 +756,10 @@ public class WorldGuardEntityListener extends AbstractListener {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && ent instanceof Player
if (wcfg.useRegions && ent instanceof Player player && !Entities.isNPC(ent)
&& !WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testState(
BukkitAdapter.adapt(ent.getLocation()),
WorldGuardPlugin.inst().wrapPlayer((Player) ent),
WorldGuardPlugin.inst().wrapPlayer(player),
Flags.HEALTH_REGEN)) {
event.setCancelled(true);
}
@@ -758,10 +769,11 @@ public class WorldGuardEntityListener extends AbstractListener {
public void onFoodChange(FoodLevelChangeEvent event) {
if (event.getItem() != null) return;
HumanEntity ent = event.getEntity();
if (!(ent instanceof Player)) return;
if (Entities.isNPC(ent)) return;
if (!(ent instanceof Player bukkitPlayer)) return;
if (event.getFoodLevel() > ent.getFoodLevel()) return;
LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer((Player) ent);
LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(bukkitPlayer);
WorldConfiguration wcfg = getWorldConfig(ent.getWorld());
if (wcfg.useRegions
@@ -258,13 +258,11 @@ public class WorldGuardPlayerListener extends AbstractListener {
}
if (wcfg.useRegions) {
//Block placedIn = block.getRelative(event.getBlockFace());
ApplicableRegionSet set =
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
//ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().getApplicableRegions(placedIn.getLocation());
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && getPlugin().hasPermission(player, "worldguard.region.wand")) {
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.getApplicableRegions(BukkitAdapter.adapt(block.getLocation()), RegionQuery.QueryOption.SORT);
if (set.size() > 0) {
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
@@ -314,6 +312,7 @@ public class WorldGuardPlayerListener extends AbstractListener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if (com.sk89q.worldguard.bukkit.util.Entities.isNPC(player)) return;
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
if (wcfg.useRegions) {
@@ -348,6 +347,7 @@ public class WorldGuardPlayerListener extends AbstractListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
if (com.sk89q.worldguard.bukkit.util.Entities.isNPC(player)) return;
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.util.Locations;
@@ -59,6 +60,7 @@ public class WorldGuardVehicleListener extends AbstractListener {
// Did we move a block?
if (Locations.isDifferentBlock(BukkitAdapter.adapt(event.getFrom()), BukkitAdapter.adapt(event.getTo()))) {
for (Player player : playerPassengers) {
if (Entities.isNPC(player)) continue;
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
Location lastValid;
if ((lastValid = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer)
@@ -20,6 +20,7 @@
package com.sk89q.worldguard.bukkit.listener.debounce.legacy;
import com.sk89q.worldguard.bukkit.listener.debounce.legacy.InventoryMoveItemEventDebounce.Key;
import io.papermc.lib.PaperLib;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
@@ -44,18 +45,18 @@ public class InventoryMoveItemEventDebounce extends AbstractEventDebounce<Key> {
private final Object target;
public Key(InventoryMoveItemEvent event) {
cause = transform(event.getInitiator().getHolder());
source = transform(event.getSource().getHolder());
target = transform(event.getDestination().getHolder());
cause = transform(PaperLib.getHolder(event.getInitiator(), false).getHolder());
source = transform(PaperLib.getHolder(event.getSource(), false).getHolder());
target = transform(PaperLib.getHolder(event.getDestination(), false).getHolder());
}
private Object transform(InventoryHolder holder) {
if (holder instanceof BlockState) {
return new BlockMaterialKey(((BlockState) holder).getBlock());
} else if (holder instanceof DoubleChest) {
InventoryHolder left = ((DoubleChest) holder).getLeftSide();
if (left instanceof Chest) {
return new BlockMaterialKey(((Chest) left).getBlock());
if (holder instanceof BlockState blockState) {
return new BlockMaterialKey(blockState);
} else if (holder instanceof DoubleChest doubleChest) {
InventoryHolder left = doubleChest.getLeftSide();
if (left instanceof Chest chest) {
return new BlockMaterialKey(chest);
} else {
return holder;
}
@@ -94,8 +95,8 @@ public class InventoryMoveItemEventDebounce extends AbstractEventDebounce<Key> {
private final Block block;
private final Material material;
private BlockMaterialKey(Block block) {
this.block = block;
private BlockMaterialKey(BlockState block) {
this.block = block.getBlock();
material = block.getType();
}
@@ -25,9 +25,9 @@ import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.session.AbstractSessionManager;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
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.
@@ -81,9 +74,9 @@ public class BukkitSessionManager extends AbstractSessionManager implements Runn
@Override
public boolean hasBypass(LocalPlayer player, World world) {
if (player instanceof BukkitPlayer) {
if (((BukkitPlayer) player).getPlayer().hasMetadata("NPC")
&& WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).fakePlayerBuildOverride) {
if (player instanceof BukkitPlayer bukkitPlayer) {
if (Entities.isNPC(bukkitPlayer.getPlayer())
&& WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).fakePlayerBuildOverride) {
return true;
}
if (!((BukkitPlayer) player).getPlayer().isOnline()) {
@@ -93,11 +86,10 @@ public class BukkitSessionManager extends AbstractSessionManager implements Runn
return super.hasBypass(player, world);
}
public boolean isUsingTimings() {
return useTimings;
}
public void setUsingTimings(boolean useTimings) {
this.useTimings = useTimings;
public void shutdown() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
get(localPlayer).uninitialize(localPlayer);
}
}
}
@@ -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;
}
}
}
@@ -47,14 +47,17 @@ public class ClassSourceValidator {
private static final String SEPARATOR_LINE = Strings.repeat("*", 46);
private static final Method loadClass;
private static Class<?> pluginClassLoaderClass;
static {
Method tmp;
try {
tmp = PluginClassLoader.class.getDeclaredMethod("loadClass0",
pluginClassLoaderClass = Class.forName("org.bukkit.plugin.java.PluginClassLoader", false,
Bukkit.class.getClassLoader());
tmp = pluginClassLoaderClass.getDeclaredMethod("loadClass0",
String.class, boolean.class, boolean.class, boolean.class);
tmp.setAccessible(true);
} catch (NoSuchMethodException e) {
} catch (NoSuchMethodException | ClassNotFoundException e) {
tmp = null;
}
loadClass = tmp;
@@ -95,7 +98,7 @@ public class ClassSourceValidator {
continue;
}
ClassLoader targetLoader = target.getClass().getClassLoader();
if (!(targetLoader instanceof PluginClassLoader)) {
if (!(pluginClassLoaderClass.isAssignableFrom(targetLoader.getClass()))) {
continue;
}
for (Class<?> testClass : classes) {
@@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit.util;
import org.bukkit.entity.Allay;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow;
@@ -101,8 +102,20 @@ public final class Entities {
* @return true if the type is a vehicle type
*/
public static boolean isVehicle(EntityType type) {
return type == EntityType.BOAT
|| isMinecart(type);
return isBoat(type) || isMinecart(type);
}
/**
* Test whether the given entity type is a Boat type.
*
* @param type the type
* @return true if the type is a Boat type
*/
public static boolean isBoat(EntityType type) {
return switch(type) {
case BOAT, CHEST_BOAT -> true;
default -> false;
};
}
/**
@@ -112,13 +125,11 @@ public final class Entities {
* @return true if the type is a Minecart type
*/
public static boolean isMinecart(EntityType type) {
return type == EntityType.MINECART
|| type == EntityType.MINECART_CHEST
|| type == EntityType.MINECART_COMMAND
|| type == EntityType.MINECART_FURNACE
|| type == EntityType.MINECART_HOPPER
|| type == EntityType.MINECART_MOB_SPAWNER
|| type == EntityType.MINECART_TNT;
return switch(type) {
case MINECART, MINECART_CHEST, MINECART_COMMAND, MINECART_FURNACE,
MINECART_HOPPER, MINECART_MOB_SPAWNER, MINECART_TNT -> true;
default -> false;
};
}
/**
@@ -208,6 +219,7 @@ public final class Entities {
return entity instanceof Hanging
|| entity instanceof ArmorStand
|| entity instanceof EnderCrystal
|| entity instanceof Allay
|| entity instanceof Minecart && entity instanceof InventoryHolder;
}
@@ -70,7 +70,7 @@ public final class InteropUtils {
UUID uuid = player.getUniqueId();
String name = player.getName();
if (player.hasMetadata("NPC")) {
if (Entities.isNPC(player)) {
return true;
}
@@ -52,6 +52,11 @@ 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 void putMaterialTag(Tag<Material> tag, Integer value) {
tag.getValues().forEach(mat -> MATERIAL_FLAGS.put(mat, value));
}
private static Tag<Material> SIGNS_TAG;
static {
ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);
ENTITY_ITEMS.put(EntityType.ARROW, Material.ARROW);
@@ -110,7 +115,7 @@ public final class Materials {
MATERIAL_FLAGS.put(Material.IRON_BLOCK, 0);
MATERIAL_FLAGS.put(Material.BRICK, 0);
MATERIAL_FLAGS.put(Material.TNT, MODIFIED_ON_RIGHT);
MATERIAL_FLAGS.put(Material.BOOKSHELF, 0);
MATERIAL_FLAGS.put(Material.BOOKSHELF, MODIFIED_ON_RIGHT);
MATERIAL_FLAGS.put(Material.MOSSY_COBBLESTONE, 0);
MATERIAL_FLAGS.put(Material.OBSIDIAN, 0);
MATERIAL_FLAGS.put(Material.TORCH, 0);
@@ -794,111 +799,75 @@ public final class Materials {
MATERIAL_FLAGS.put(Material.HANGING_ROOTS, 0);
MATERIAL_FLAGS.put(Material.POINTED_DRIPSTONE, 0);
// 1.19
MATERIAL_FLAGS.put(Material.MUD, 0);
MATERIAL_FLAGS.put(Material.MANGROVE_ROOTS, 0);
MATERIAL_FLAGS.put(Material.MUDDY_MANGROVE_ROOTS, 0);
MATERIAL_FLAGS.put(Material.PACKED_MUD, 0);
MATERIAL_FLAGS.put(Material.MUD_BRICKS, 0);
MATERIAL_FLAGS.put(Material.SCULK, 0);
MATERIAL_FLAGS.put(Material.SCULK_VEIN, 0);
MATERIAL_FLAGS.put(Material.SCULK_CATALYST, 0);
MATERIAL_FLAGS.put(Material.SCULK_SHRIEKER, 0);
MATERIAL_FLAGS.put(Material.TADPOLE_BUCKET, 0);
MATERIAL_FLAGS.put(Material.RECOVERY_COMPASS, 0);
MATERIAL_FLAGS.put(Material.DISC_FRAGMENT_5, 0);
MATERIAL_FLAGS.put(Material.GOAT_HORN, 0);
MATERIAL_FLAGS.put(Material.OCHRE_FROGLIGHT, 0);
MATERIAL_FLAGS.put(Material.VERDANT_FROGLIGHT, 0);
MATERIAL_FLAGS.put(Material.PEARLESCENT_FROGLIGHT, 0);
MATERIAL_FLAGS.put(Material.FROGSPAWN, 0);
MATERIAL_FLAGS.put(Material.ECHO_SHARD, 0);
MATERIAL_FLAGS.put(Material.REINFORCED_DEEPSLATE, 0);
// 1.19.3: Try to register those things
try {
SIGNS_TAG = Tag.ALL_SIGNS;
MATERIAL_FLAGS.put(Material.BAMBOO_MOSAIC, 0);
MATERIAL_FLAGS.put(Material.BAMBOO_BLOCK, 0);
MATERIAL_FLAGS.put(Material.STRIPPED_BAMBOO_BLOCK, 0);
} catch (NoSuchFieldError ignored) {
SIGNS_TAG = Tag.SIGNS;
}
// 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 boat : Tag.ITEMS_BOATS.getValues()) {
MATERIAL_FLAGS.put(boat, 0);
}
for (Material banner : Tag.BANNERS.getValues()) {
MATERIAL_FLAGS.put(banner, 0);
}
for (Material slab : Tag.SLABS.getValues()) {
MATERIAL_FLAGS.put(slab, 0);
}
for (Material plank : Tag.PLANKS.getValues()) {
MATERIAL_FLAGS.put(plank, 0);
}
for (Material carpet : Tag.CARPETS.getValues()) {
MATERIAL_FLAGS.put(carpet, 0);
}
for (Material sapling : Tag.SAPLINGS.getValues()) {
MATERIAL_FLAGS.put(sapling, 0);
}
for (Material log : Tag.LOGS.getValues()) {
MATERIAL_FLAGS.put(log, 0);
}
for (Material leaves : Tag.LEAVES.getValues()) {
MATERIAL_FLAGS.put(leaves, 0);
}
for (Material stair : Tag.STAIRS.getValues()) {
MATERIAL_FLAGS.put(stair, 0);
}
for (Material wool : Tag.WOOL.getValues()) {
MATERIAL_FLAGS.put(wool, 0);
}
for (Material plate : Tag.WOODEN_PRESSURE_PLATES.getValues()) {
MATERIAL_FLAGS.put(plate, 0);
}
for (Material button : Tag.BUTTONS.getValues()) {
MATERIAL_FLAGS.put(button, MODIFIED_ON_RIGHT);
}
for (Material pot : Tag.FLOWER_POTS.getValues()) {
MATERIAL_FLAGS.put(pot, MODIFIED_ON_RIGHT);
}
for (Material wall : Tag.WALLS.getValues()) {
MATERIAL_FLAGS.put(wall, 0);
}
for (Material sign : Tag.SIGNS.getValues()) {
MATERIAL_FLAGS.put(sign, 0);
}
for (Material flower : Tag.SMALL_FLOWERS.getValues()) {
MATERIAL_FLAGS.put(flower, 0);
}
for (Material bed : Tag.BEDS.getValues()) {
MATERIAL_FLAGS.put(bed, MODIFIED_ON_RIGHT);
}
for (Material musicDisc : Tag.ITEMS_MUSIC_DISCS.getValues()) {
MATERIAL_FLAGS.put(musicDisc, 0);
}
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);
} for (Material coalOre : Tag.COAL_ORES.getValues()) {
MATERIAL_FLAGS.put(coalOre, 0);
}
for (Material ironOre : Tag.IRON_ORES.getValues()) {
MATERIAL_FLAGS.put(ironOre, 0);
}
for (Material goldOre : Tag.GOLD_ORES.getValues()) {
MATERIAL_FLAGS.put(goldOre, 0);
}
for (Material diamondOre : Tag.DIAMOND_ORES.getValues()) {
MATERIAL_FLAGS.put(diamondOre, 0);
}
for (Material redstoneOre : Tag.REDSTONE_ORES.getValues()) {
MATERIAL_FLAGS.put(redstoneOre, 0);
}
for (Material copperOre : Tag.COPPER_ORES.getValues()) {
MATERIAL_FLAGS.put(copperOre, 0);
}
for (Material emeraldOre : Tag.EMERALD_ORES.getValues()) {
MATERIAL_FLAGS.put(emeraldOre, 0);
}
for (Material lapisOre : Tag.LAPIS_ORES.getValues()) {
MATERIAL_FLAGS.put(lapisOre, 0);
}
for (Material candle : Tag.CANDLES.getValues()) {
MATERIAL_FLAGS.put(candle, MODIFIED_ON_RIGHT);
}
for (Material candleCakes : Tag.CANDLE_CAKES.getValues()) {
MATERIAL_FLAGS.put(candleCakes, MODIFIED_ON_RIGHT);
}
for (Material cauldron : Tag.CAULDRONS.getValues()) {
MATERIAL_FLAGS.put(cauldron, MODIFIED_ON_RIGHT);
}
putMaterialTag(Tag.WOODEN_DOORS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.WOODEN_TRAPDOORS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.ITEMS_BOATS, 0);
putMaterialTag(Tag.BANNERS, 0);
putMaterialTag(Tag.SLABS, 0);
putMaterialTag(Tag.PLANKS, 0);
putMaterialTag(Tag.WOOL_CARPETS, 0);
putMaterialTag(Tag.SAPLINGS, 0);
putMaterialTag(Tag.LOGS, 0);
putMaterialTag(Tag.LEAVES, 0);
putMaterialTag(Tag.STAIRS, 0);
putMaterialTag(Tag.WOOL, 0);
putMaterialTag(Tag.WOODEN_PRESSURE_PLATES, 0);
putMaterialTag(Tag.BUTTONS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.FLOWER_POTS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.WALLS, 0);
putMaterialTag(SIGNS_TAG, 0);
putMaterialTag(Tag.SMALL_FLOWERS, 0);
putMaterialTag(Tag.BEDS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.ITEMS_MUSIC_DISCS, 0);
putMaterialTag(Tag.ITEMS_BANNERS, 0);
putMaterialTag(Tag.FENCE_GATES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.FENCES, 0);
putMaterialTag(Tag.COAL_ORES, 0);
putMaterialTag(Tag.IRON_ORES, 0);
putMaterialTag(Tag.GOLD_ORES, 0);
putMaterialTag(Tag.DIAMOND_ORES, 0);
putMaterialTag(Tag.REDSTONE_ORES, 0);
putMaterialTag(Tag.COPPER_ORES, 0);
putMaterialTag(Tag.EMERALD_ORES, 0);
putMaterialTag(Tag.LAPIS_ORES, 0);
putMaterialTag(Tag.CANDLES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.CANDLE_CAKES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.CAULDRONS, MODIFIED_ON_RIGHT);
Stream.concat(Stream.concat(
Tag.CORAL_BLOCKS.getValues().stream(),
@@ -956,6 +925,7 @@ public final class Materials {
// DAMAGE_EFFECTS.add(PotionEffectType.DOLPHINS_GRACE);
DAMAGE_EFFECTS.add(PotionEffectType.BAD_OMEN);
// DAMAGE_EFFECTS.add(PotionEffectType.HERO_OF_THE_VILLAGE);
DAMAGE_EFFECTS.add(PotionEffectType.DARKNESS);
}
private Materials() {
@@ -1143,220 +1113,94 @@ public final class Materials {
|| material == Material.BARREL
|| material == Material.BLAST_FURNACE
|| material == Material.SMOKER
|| Tag.ITEMS_CHEST_BOATS.isTagged(material)
|| Tag.SHULKER_BOXES.isTagged(material);
}
public static boolean isSpawnEgg(Material material) {
switch (material) {
case AXOLOTL_SPAWN_EGG:
case BAT_SPAWN_EGG:
case BEE_SPAWN_EGG:
case BLAZE_SPAWN_EGG:
case CAT_SPAWN_EGG:
case CAVE_SPIDER_SPAWN_EGG:
case CHICKEN_SPAWN_EGG:
case COD_SPAWN_EGG:
case COW_SPAWN_EGG:
case CREEPER_SPAWN_EGG:
case DOLPHIN_SPAWN_EGG:
case DONKEY_SPAWN_EGG:
case DROWNED_SPAWN_EGG:
case ELDER_GUARDIAN_SPAWN_EGG:
case ENDERMAN_SPAWN_EGG:
case ENDERMITE_SPAWN_EGG:
case EVOKER_SPAWN_EGG:
case FOX_SPAWN_EGG:
case GHAST_SPAWN_EGG:
case GLOW_SQUID_SPAWN_EGG:
case GOAT_SPAWN_EGG:
case GUARDIAN_SPAWN_EGG:
case HOGLIN_SPAWN_EGG:
case HORSE_SPAWN_EGG:
case HUSK_SPAWN_EGG:
case LLAMA_SPAWN_EGG:
case MAGMA_CUBE_SPAWN_EGG:
case MOOSHROOM_SPAWN_EGG:
case MULE_SPAWN_EGG:
case OCELOT_SPAWN_EGG:
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:
case PUFFERFISH_SPAWN_EGG:
case RABBIT_SPAWN_EGG:
case RAVAGER_SPAWN_EGG:
case SALMON_SPAWN_EGG:
case SHEEP_SPAWN_EGG:
case SHULKER_SPAWN_EGG:
case SILVERFISH_SPAWN_EGG:
case SKELETON_HORSE_SPAWN_EGG:
case SKELETON_SPAWN_EGG:
case SLIME_SPAWN_EGG:
case SPIDER_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:
case VEX_SPAWN_EGG:
case VILLAGER_SPAWN_EGG:
case VINDICATOR_SPAWN_EGG:
case WANDERING_TRADER_SPAWN_EGG:
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_SPAWN_EGG:
case ZOMBIE_VILLAGER_SPAWN_EGG:
return true;
default:
return false;
}
return getEntitySpawnEgg(material) != null;
}
public static EntityType getEntitySpawnEgg(Material material) {
switch (material) {
case AXOLOTL_SPAWN_EGG:
return EntityType.AXOLOTL;
case SPIDER_SPAWN_EGG:
return EntityType.SPIDER;
case BAT_SPAWN_EGG:
return EntityType.BAT;
case BEE_SPAWN_EGG:
return EntityType.BEE;
case BLAZE_SPAWN_EGG:
return EntityType.BLAZE;
case CAT_SPAWN_EGG:
return EntityType.CAT;
case CAVE_SPIDER_SPAWN_EGG:
return EntityType.CAVE_SPIDER;
case CHICKEN_SPAWN_EGG:
return EntityType.CHICKEN;
case COD_SPAWN_EGG:
return EntityType.COD;
case COW_SPAWN_EGG:
return EntityType.COW;
case CREEPER_SPAWN_EGG:
return EntityType.CREEPER;
case DOLPHIN_SPAWN_EGG:
return EntityType.DOLPHIN;
case DONKEY_SPAWN_EGG:
return EntityType.DONKEY;
case DROWNED_SPAWN_EGG:
return EntityType.DROWNED;
case ELDER_GUARDIAN_SPAWN_EGG:
return EntityType.ELDER_GUARDIAN;
case ENDERMAN_SPAWN_EGG:
return EntityType.ENDERMAN;
case ENDERMITE_SPAWN_EGG:
return EntityType.ENDERMITE;
case EVOKER_SPAWN_EGG:
return EntityType.EVOKER;
case FOX_SPAWN_EGG:
return EntityType.FOX;
case GHAST_SPAWN_EGG:
return EntityType.GHAST;
case GLOW_SQUID_SPAWN_EGG:
return EntityType.GLOW_SQUID;
case GOAT_SPAWN_EGG:
return EntityType.GOAT;
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:
return EntityType.HUSK;
case LLAMA_SPAWN_EGG:
return EntityType.LLAMA;
case MAGMA_CUBE_SPAWN_EGG:
return EntityType.MAGMA_CUBE;
case MOOSHROOM_SPAWN_EGG:
return EntityType.MUSHROOM_COW;
case MULE_SPAWN_EGG:
return EntityType.MULE;
case OCELOT_SPAWN_EGG:
return EntityType.OCELOT;
case PANDA_SPAWN_EGG:
return EntityType.PANDA;
case PARROT_SPAWN_EGG:
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:
return EntityType.POLAR_BEAR;
case PUFFERFISH_SPAWN_EGG:
return EntityType.PUFFERFISH;
case RABBIT_SPAWN_EGG:
return EntityType.RABBIT;
case RAVAGER_SPAWN_EGG:
return EntityType.RAVAGER;
case SALMON_SPAWN_EGG:
return EntityType.SALMON;
case SHEEP_SPAWN_EGG:
return EntityType.SHEEP;
case SHULKER_SPAWN_EGG:
return EntityType.SHULKER;
case SILVERFISH_SPAWN_EGG:
return EntityType.SILVERFISH;
case SKELETON_HORSE_SPAWN_EGG:
return EntityType.SKELETON_HORSE;
case SKELETON_SPAWN_EGG:
return EntityType.SKELETON;
case SLIME_SPAWN_EGG:
return EntityType.SLIME;
case SQUID_SPAWN_EGG:
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:
return EntityType.TROPICAL_FISH;
case TURTLE_SPAWN_EGG:
return EntityType.TURTLE;
case VEX_SPAWN_EGG:
return EntityType.VEX;
case VILLAGER_SPAWN_EGG:
return EntityType.VILLAGER;
case VINDICATOR_SPAWN_EGG:
return EntityType.VINDICATOR;
case WANDERING_TRADER_SPAWN_EGG:
return EntityType.WANDERING_TRADER;
case WITCH_SPAWN_EGG:
return EntityType.WITCH;
case WITHER_SKELETON_SPAWN_EGG:
return EntityType.WITHER_SKELETON;
case WOLF_SPAWN_EGG:
return EntityType.WOLF;
case ZOMBIE_HORSE_SPAWN_EGG:
return EntityType.ZOMBIE_HORSE;
case ZOMBIFIED_PIGLIN_SPAWN_EGG:
return EntityType.ZOMBIFIED_PIGLIN;
case ZOMBIE_SPAWN_EGG:
return EntityType.ZOMBIE;
case ZOMBIE_VILLAGER_SPAWN_EGG:
return EntityType.ZOMBIE_VILLAGER;
case PIG_SPAWN_EGG:
default: // Uhh
return EntityType.PIG;
}
return switch (material) {
case ALLAY_SPAWN_EGG -> EntityType.ALLAY;
case AXOLOTL_SPAWN_EGG -> EntityType.AXOLOTL;
case SPIDER_SPAWN_EGG -> EntityType.SPIDER;
case BAT_SPAWN_EGG -> EntityType.BAT;
case BEE_SPAWN_EGG -> EntityType.BEE;
case BLAZE_SPAWN_EGG -> EntityType.BLAZE;
case CAT_SPAWN_EGG -> EntityType.CAT;
case CAMEL_SPAWN_EGG -> EntityType.CAMEL;
case CAVE_SPIDER_SPAWN_EGG -> EntityType.CAVE_SPIDER;
case CHICKEN_SPAWN_EGG -> EntityType.CHICKEN;
case COD_SPAWN_EGG -> EntityType.COD;
case COW_SPAWN_EGG -> EntityType.COW;
case CREEPER_SPAWN_EGG -> EntityType.CREEPER;
case DOLPHIN_SPAWN_EGG -> EntityType.DOLPHIN;
case DONKEY_SPAWN_EGG -> EntityType.DONKEY;
case DROWNED_SPAWN_EGG -> EntityType.DROWNED;
case ELDER_GUARDIAN_SPAWN_EGG -> EntityType.ELDER_GUARDIAN;
case ENDER_DRAGON_SPAWN_EGG -> EntityType.ENDER_DRAGON;
case ENDERMAN_SPAWN_EGG -> EntityType.ENDERMAN;
case ENDERMITE_SPAWN_EGG -> EntityType.ENDERMITE;
case EVOKER_SPAWN_EGG -> EntityType.EVOKER;
case FOX_SPAWN_EGG -> EntityType.FOX;
case FROG_SPAWN_EGG -> EntityType.FROG;
case GHAST_SPAWN_EGG -> EntityType.GHAST;
case GLOW_SQUID_SPAWN_EGG -> EntityType.GLOW_SQUID;
case GOAT_SPAWN_EGG -> EntityType.GOAT;
case GUARDIAN_SPAWN_EGG -> EntityType.GUARDIAN;
case HOGLIN_SPAWN_EGG -> EntityType.HOGLIN;
case HORSE_SPAWN_EGG -> EntityType.HORSE;
case HUSK_SPAWN_EGG -> EntityType.HUSK;
case IRON_GOLEM_SPAWN_EGG -> EntityType.IRON_GOLEM;
case LLAMA_SPAWN_EGG -> EntityType.LLAMA;
case MAGMA_CUBE_SPAWN_EGG -> EntityType.MAGMA_CUBE;
case MOOSHROOM_SPAWN_EGG -> EntityType.MUSHROOM_COW;
case MULE_SPAWN_EGG -> EntityType.MULE;
case OCELOT_SPAWN_EGG -> EntityType.OCELOT;
case PANDA_SPAWN_EGG -> EntityType.PANDA;
case PARROT_SPAWN_EGG -> EntityType.PARROT;
case PHANTOM_SPAWN_EGG -> EntityType.PHANTOM;
case PIGLIN_BRUTE_SPAWN_EGG -> EntityType.PIGLIN_BRUTE;
case PIGLIN_SPAWN_EGG -> EntityType.PIGLIN;
case PILLAGER_SPAWN_EGG -> EntityType.PILLAGER;
case POLAR_BEAR_SPAWN_EGG -> EntityType.POLAR_BEAR;
case PUFFERFISH_SPAWN_EGG -> EntityType.PUFFERFISH;
case RABBIT_SPAWN_EGG -> EntityType.RABBIT;
case RAVAGER_SPAWN_EGG -> EntityType.RAVAGER;
case SALMON_SPAWN_EGG -> EntityType.SALMON;
case SHEEP_SPAWN_EGG -> EntityType.SHEEP;
case SHULKER_SPAWN_EGG -> EntityType.SHULKER;
case SILVERFISH_SPAWN_EGG -> EntityType.SILVERFISH;
case SKELETON_HORSE_SPAWN_EGG -> EntityType.SKELETON_HORSE;
case SKELETON_SPAWN_EGG -> EntityType.SKELETON;
case SLIME_SPAWN_EGG -> EntityType.SLIME;
case SNOW_GOLEM_SPAWN_EGG -> EntityType.SNOWMAN;
case SQUID_SPAWN_EGG -> EntityType.SQUID;
case STRAY_SPAWN_EGG -> EntityType.STRAY;
case STRIDER_SPAWN_EGG -> EntityType.STRIDER;
case TADPOLE_SPAWN_EGG -> EntityType.TADPOLE;
case TRADER_LLAMA_SPAWN_EGG -> EntityType.TRADER_LLAMA;
case TROPICAL_FISH_SPAWN_EGG -> EntityType.TROPICAL_FISH;
case TURTLE_SPAWN_EGG -> EntityType.TURTLE;
case VEX_SPAWN_EGG -> EntityType.VEX;
case VILLAGER_SPAWN_EGG -> EntityType.VILLAGER;
case VINDICATOR_SPAWN_EGG -> EntityType.VINDICATOR;
case WANDERING_TRADER_SPAWN_EGG -> EntityType.WANDERING_TRADER;
case WARDEN_SPAWN_EGG -> EntityType.WARDEN;
case WITCH_SPAWN_EGG -> EntityType.WITCH;
case WITHER_SPAWN_EGG -> EntityType.WITHER;
case WITHER_SKELETON_SPAWN_EGG -> EntityType.WITHER_SKELETON;
case WOLF_SPAWN_EGG -> EntityType.WOLF;
case ZOGLIN_SPAWN_EGG -> EntityType.ZOGLIN;
case ZOMBIE_HORSE_SPAWN_EGG -> EntityType.ZOMBIE_HORSE;
case ZOMBIFIED_PIGLIN_SPAWN_EGG -> EntityType.ZOMBIFIED_PIGLIN;
case ZOMBIE_SPAWN_EGG -> EntityType.ZOMBIE;
case ZOMBIE_VILLAGER_SPAWN_EGG -> EntityType.ZOMBIE_VILLAGER;
case PIG_SPAWN_EGG -> EntityType.PIG;
default -> null;
};
}
public static boolean isBed(Material material) {
@@ -1380,26 +1224,14 @@ public final class Materials {
* @return true if the material is a crop
*/
public static boolean isCrop(Material type) {
switch (type) {
case WHEAT:
case CARROTS:
case POTATOES:
case BEETROOTS:
case MELON_STEM:
case PUMPKIN_STEM:
case PUMPKIN:
case MELON:
case CACTUS:
case SUGAR_CANE:
case BAMBOO:
case BAMBOO_SAPLING:
case SWEET_BERRY_BUSH:
case NETHER_WART:
case CAVE_VINES:
case CAVE_VINES_PLANT:
return true;
}
return false;
if (Tag.CROPS.isTagged(type)) return true;
// yea, that's not all, there are some more
return switch (type) {
case PUMPKIN, MELON, CACTUS, SUGAR_CANE, BAMBOO, BAMBOO_SAPLING,
SWEET_BERRY_BUSH, NETHER_WART, CAVE_VINES, CAVE_VINES_PLANT ->
true;
default -> false;
};
}
/**
@@ -1434,18 +1266,11 @@ public final class Materials {
|| Tag.PRESSURE_PLATES.isTagged(material)) {
return true;
}
switch (material) {
case LEVER:
case LECTERN:
case ENCHANTING_TABLE:
case BELL:
case LOOM:
case CARTOGRAPHY_TABLE:
case STONECUTTER:
case GRINDSTONE:
return true;
default: return false;
}
return switch (material) {
case LEVER, LECTERN, ENCHANTING_TABLE, BELL, LOOM,
CARTOGRAPHY_TABLE, STONECUTTER, GRINDSTONE -> true;
default -> false;
};
}
/**
@@ -1492,6 +1317,7 @@ public final class Materials {
return type == Material.REPEATER
|| type == Material.COMPARATOR
|| type == Material.CAKE
|| type == Material.DRAGON_EGG
|| Tag.FLOWER_POTS.isTagged(type)
|| Tag.CANDLES.isTagged(type)
|| Tag.CANDLE_CAKES.isTagged(type);
@@ -1524,37 +1350,17 @@ public final class Materials {
* @return true if equippable armor
*/
public static boolean isArmor(Material type) {
switch (type) {
case LEATHER_HELMET:
case LEATHER_CHESTPLATE:
case LEATHER_LEGGINGS:
case LEATHER_BOOTS:
case CHAINMAIL_HELMET:
case CHAINMAIL_CHESTPLATE:
case CHAINMAIL_LEGGINGS:
case CHAINMAIL_BOOTS:
case IRON_HELMET:
case IRON_CHESTPLATE:
case IRON_LEGGINGS:
case IRON_BOOTS:
case DIAMOND_HELMET:
case DIAMOND_CHESTPLATE:
case DIAMOND_LEGGINGS:
case DIAMOND_BOOTS:
case GOLDEN_HELMET:
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;
default:
return false;
}
return switch (type) {
case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS,
CHAINMAIL_HELMET, CHAINMAIL_CHESTPLATE, CHAINMAIL_LEGGINGS, CHAINMAIL_BOOTS,
IRON_HELMET, IRON_CHESTPLATE, IRON_LEGGINGS, IRON_BOOTS,
DIAMOND_HELMET, DIAMOND_CHESTPLATE, DIAMOND_LEGGINGS, DIAMOND_BOOTS,
GOLDEN_HELMET, GOLDEN_CHESTPLATE, GOLDEN_LEGGINGS, GOLDEN_BOOTS,
NETHERITE_HELMET, NETHERITE_CHESTPLATE, NETHERITE_LEGGINGS, NETHERITE_BOOTS,
TURTLE_HELMET, ELYTRA ->
true;
default -> false;
};
}
/**
@@ -1575,64 +1381,40 @@ public final class Materials {
case GOLDEN_HOE:
case DIAMOND_HOE:
case NETHERITE_HOE:
switch (targetMaterial) {
case GRASS_BLOCK:
case DIRT:
case DIRT_PATH:
case ROOTED_DIRT:
// case COARSE_DIRT: // already handled by the server...
return true;
}
return false;
return switch (targetMaterial) {
case GRASS_BLOCK, DIRT, DIRT_PATH, ROOTED_DIRT ->
true;
default -> false;
};
case WOODEN_AXE:
case STONE_AXE:
case IRON_AXE:
case GOLDEN_AXE:
case DIAMOND_AXE:
case NETHERITE_AXE:
if (isWaxedCopper(targetMaterial))
return true;
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;
if (isWaxedCopper(targetMaterial)) return true;
if (Tag.LOGS.isTagged(targetMaterial)) return true;
return switch (targetMaterial) {
case OAK_WOOD, DARK_OAK_WOOD, ACACIA_WOOD, BIRCH_WOOD, SPRUCE_WOOD, PUMPKIN, BAMBOO_BLOCK,
JUNGLE_WOOD, CRIMSON_STEM, WARPED_STEM, CRIMSON_HYPHAE, WARPED_HYPHAE ->
true;
default -> 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;
return switch (targetMaterial) {
case GRASS_BLOCK, CAMPFIRE, SOUL_CAMPFIRE -> true;
default -> false;
};
case SHEARS:
switch (targetMaterial) {
case PUMPKIN:
case BEE_NEST:
case BEEHIVE:
return true;
}
return false;
return switch (targetMaterial) {
case PUMPKIN, BEE_NEST, BEEHIVE -> true;
default -> false;
};
case BLACK_DYE:
case BLUE_DYE:
case BROWN_DYE:
@@ -1651,7 +1433,7 @@ public final class Materials {
case YELLOW_DYE:
case GLOW_INK_SAC:
case INK_SAC:
return Tag.SIGNS.isTagged(targetMaterial);
return SIGNS_TAG.isTagged(targetMaterial);
case HONEYCOMB:
return isUnwaxedCopper(targetMaterial);
default:
@@ -1664,48 +1446,37 @@ public final class Materials {
}
public static boolean isWaxedCopper(Material type) {
switch (type) {
case WAXED_COPPER_BLOCK:
case WAXED_EXPOSED_COPPER:
case WAXED_WEATHERED_COPPER:
case WAXED_OXIDIZED_COPPER:
case WAXED_CUT_COPPER:
case WAXED_EXPOSED_CUT_COPPER:
case WAXED_WEATHERED_CUT_COPPER:
case WAXED_OXIDIZED_CUT_COPPER:
case WAXED_CUT_COPPER_STAIRS:
case WAXED_EXPOSED_CUT_COPPER_STAIRS:
case WAXED_WEATHERED_CUT_COPPER_STAIRS:
case WAXED_OXIDIZED_CUT_COPPER_STAIRS:
case WAXED_CUT_COPPER_SLAB:
case WAXED_EXPOSED_CUT_COPPER_SLAB:
case WAXED_WEATHERED_CUT_COPPER_SLAB:
case WAXED_OXIDIZED_CUT_COPPER_SLAB:
return true;
}
return false;
return switch (type) {
case WAXED_COPPER_BLOCK, WAXED_EXPOSED_COPPER, WAXED_WEATHERED_COPPER, WAXED_OXIDIZED_COPPER,
WAXED_CUT_COPPER, WAXED_EXPOSED_CUT_COPPER, WAXED_WEATHERED_CUT_COPPER,
WAXED_OXIDIZED_CUT_COPPER, WAXED_CUT_COPPER_STAIRS, WAXED_EXPOSED_CUT_COPPER_STAIRS,
WAXED_WEATHERED_CUT_COPPER_STAIRS, WAXED_OXIDIZED_CUT_COPPER_STAIRS, WAXED_CUT_COPPER_SLAB,
WAXED_EXPOSED_CUT_COPPER_SLAB, WAXED_WEATHERED_CUT_COPPER_SLAB, WAXED_OXIDIZED_CUT_COPPER_SLAB ->
true;
default -> false;
};
}
public static boolean isUnwaxedCopper(Material type) {
switch (type) {
case COPPER_BLOCK:
case EXPOSED_COPPER:
case WEATHERED_COPPER:
case OXIDIZED_COPPER:
case CUT_COPPER:
case EXPOSED_CUT_COPPER:
case WEATHERED_CUT_COPPER:
case OXIDIZED_CUT_COPPER:
case CUT_COPPER_STAIRS:
case EXPOSED_CUT_COPPER_STAIRS:
case WEATHERED_CUT_COPPER_STAIRS:
case OXIDIZED_CUT_COPPER_STAIRS:
case CUT_COPPER_SLAB:
case EXPOSED_CUT_COPPER_SLAB:
case WEATHERED_CUT_COPPER_SLAB:
case OXIDIZED_CUT_COPPER_SLAB:
return true;
}
return false;
return switch (type) {
case COPPER_BLOCK, EXPOSED_COPPER, WEATHERED_COPPER, OXIDIZED_COPPER, CUT_COPPER,
EXPOSED_CUT_COPPER, WEATHERED_CUT_COPPER, OXIDIZED_CUT_COPPER, CUT_COPPER_STAIRS,
EXPOSED_CUT_COPPER_STAIRS, WEATHERED_CUT_COPPER_STAIRS, OXIDIZED_CUT_COPPER_STAIRS,
CUT_COPPER_SLAB, EXPOSED_CUT_COPPER_SLAB, WEATHERED_CUT_COPPER_SLAB, OXIDIZED_CUT_COPPER_SLAB ->
true;
default -> false;
};
}
public static boolean isAmethystGrowth(Material mat) {
return mat == Material.BUDDING_AMETHYST
|| mat == Material.AMETHYST_CLUSTER
|| mat == Material.LARGE_AMETHYST_BUD
|| mat == Material.MEDIUM_AMETHYST_BUD
|| mat == Material.SMALL_AMETHYST_BUD;
}
public static boolean isSculkGrowth(Material mat) {
return mat == Material.SCULK || mat == Material.SCULK_VEIN;
}
}
@@ -0,0 +1,48 @@
/*
* 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.util.report;
import com.sk89q.worldedit.util.report.DataReport;
import io.papermc.paper.datapack.Datapack;
import org.bukkit.Bukkit;
import java.util.Collection;
/**
* A report for current datapacks with some information. Only available on Paper
*/
public class DatapackReport extends DataReport {
public DatapackReport() {
super("DataPacks");
Collection<Datapack> packs = Bukkit.getDatapackManager().getPacks();
append("Datapack Count", packs.size());
append("Datapack Enabled Count", Bukkit.getDatapackManager().getEnabledPacks().size());
for (Datapack pack : packs) {
DataReport report = new DataReport("DataPack: " + pack.getName());
report.append("Enabled?", pack.isEnabled());
report.append("Name", pack.getName());
report.append("Compatibility", pack.getCompatibility().name());
append(report.getTitle(), report);
}
}
}
@@ -20,6 +20,7 @@
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldedit.util.report.DataReport;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Server;
@@ -33,9 +34,18 @@ public class ServerReport extends DataReport {
append("Bukkit Version", server.getBukkitVersion());
append("Implementation", server.getName() + " " + server.getVersion());
append("Player Count", "%d/%d", Bukkit.getOnlinePlayers().size(), server.getMaxPlayers());
append("Server Class Source", server.getClass().getProtectionDomain().getCodeSource().getLocation());
DataReport onlineMode = new DataReport("Online Mode");
onlineMode.append("enabled?", server.getOnlineMode());
if (PaperLib.isSpigot()) {
onlineMode.append("BungeeCord support?", Bukkit.spigot().getConfig().getBoolean("settings.bungeecord", false));
}
if (PaperLib.isPaper()) {
onlineMode.append("Velocity support?", Bukkit.spigot().getPaperConfig().getBoolean("proxies.velocity.enabled", false));
}
append(onlineMode.getTitle(), onlineMode);
DataReport spawning = new DataReport("Spawning");
spawning.append("Ambient Spawn Limit", server.getAmbientSpawnLimit());
spawning.append("Animal Spawn Limit", server.getAnimalSpawnLimit());
@@ -3,4 +3,4 @@ main: com.sk89q.worldguard.bukkit.WorldGuardPlugin
version: "${internalVersion}"
depend: [WorldEdit]
softdepend: [CommandBook]
api-version: 1.17
api-version: 1.19
+3 -3
View File
@@ -8,11 +8,11 @@ dependencies {
"api"(project(":worldguard-libs:core"))
"api"("com.sk89q.worldedit:worldedit-core:${Versions.WORLDEDIT}")
"implementation"("org.flywaydb:flyway-core:3.0")
"implementation"("org.yaml:snakeyaml:1.29")
"implementation"("org.yaml:snakeyaml:1.33")
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
"compileOnly"("com.google.code.findbugs:jsr305:1.3.9")
"testImplementation"("org.hamcrest:hamcrest-library:1.2.1")
"compileOnly"("com.google.code.findbugs:jsr305:${Versions.FINDBUGS}")
"testImplementation"("org.hamcrest:hamcrest-library:2.2")
}
tasks.withType<JavaCompile>().configureEach {
@@ -330,17 +330,9 @@ public final class RegionCommands extends RegionCommandsBase {
}
}
RegionAdder task = new RegionAdder(manager, region);
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
task.setOwnersInput(new String[]{player.getName()});
final String description = String.format("Claiming region '%s'", id);
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)
.onFailure("Failed to claim region", WorldGuard.getInstance().getExceptionConverter())
.buildAndExec(WorldGuard.getInstance().getExecutorService());
region.getOwners().addPlayer(player);
manager.addRegion(region);
player.print(TextComponent.of(String.format("A new region has been claimed named '%s'.", id)));
}
/**
@@ -1200,7 +1192,7 @@ public final class RegionCommands extends RegionCommandsBase {
// TODO: Add some method to create a safe teleport location.
// The method AbstractPlayerActor$findFreePoisition(Location loc) is no good way for this.
// It doesn't return the found location and it can't be checked if the location is inside the region.
throw new CommandException("Center teleport is only availible in Spectator gamemode.");
throw new CommandException("Center teleport is only available in Spectator gamemode.");
}
} else {
teleportLocation = FlagValueCalculator.getEffectiveFlagOf(existing, Flags.TELE_LOC, player);
@@ -159,11 +159,13 @@ public abstract class WorldConfiguration {
public boolean disableMyceliumSpread;
public boolean disableVineGrowth;
public boolean disableRockGrowth;
public boolean disableSculkGrowth;
public boolean disableCropGrowth;
public boolean disableEndermanGriefing;
public boolean disableSnowmanTrails;
public boolean disableSoilDehydration;
public boolean disableCoralBlockFade;
public boolean disableCopperBlockFade;
public Set<String> allowedSnowFallOver;
public boolean regionInvinciblityRemovesMobs;
public boolean regionCancelEmptyChatEvents;
@@ -409,15 +409,18 @@ public class DefaultDomain implements Domain, ChangeTracked {
final TextComponent.Builder builder = TextComponent.builder("");
final Iterator<TextComponent> profiles = profileMap.keySet().stream().sorted().map(name -> {
final UUID uuid = profileMap.get(name);
final TextComponent component = TextComponent.of(name, TextColor.YELLOW)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, uuid == null
? TextComponent.of("Name only", TextColor.GRAY)
: TextComponent.of("Last known name of uuid: ", TextColor.GRAY)
.append(TextComponent.of(uuid.toString(), TextColor.WHITE))));
if (uuid == null) {
return component;
return TextComponent.of(name, TextColor.YELLOW)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Name only", TextColor.GRAY)
.append(TextComponent.newline()).append(TextComponent.of("Click to copy"))))
.clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, name));
} else {
return TextComponent.of(name, TextColor.YELLOW)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Last known name of uuid: ", TextColor.GRAY)
.append(TextComponent.of(uuid.toString(), TextColor.WHITE))
.append(TextComponent.newline()).append(TextComponent.of("Click to copy"))))
.clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString()));
}
return component.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, uuid.toString()));
}).iterator();
while (profiles.hasNext()) {
builder.append(profiles.next());
@@ -428,9 +431,11 @@ public class DefaultDomain implements Domain, ChangeTracked {
if (!uuids.isEmpty()) {
builder.append(TextComponent.of(uuids.size() + " unknown uuid" + (uuids.size() == 1 ? "" : "s"), TextColor.GRAY)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(String.join("\n", uuids))
.append(TextComponent.newline().append(TextComponent.of("Click to select")))))
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, String.join(",", uuids))));
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Unable to resolve the name for:", TextColor.GRAY)
.append(TextComponent.newline())
.append(TextComponent.of(String.join("\n", uuids), TextColor.WHITE))
.append(TextComponent.newline().append(TextComponent.of("Click to copy")))))
.clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, String.join(",", uuids))));
}
@@ -121,9 +121,11 @@ public final class Flags {
public static final StateFlag MYCELIUM_SPREAD = register(new StateFlag("mycelium-spread", true));
public static final StateFlag VINE_GROWTH = register(new StateFlag("vine-growth", true));
public static final StateFlag ROCK_GROWTH = register(new StateFlag("rock-growth", true));
public static final StateFlag SCULK_GROWTH = register (new StateFlag("sculk-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 COPPER_FADE = register(new StateFlag("copper-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));
@@ -44,10 +44,8 @@ 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;
@@ -75,8 +73,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 +106,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 + 1, factory); // shifts "after" right one, and everything after "after" right one
}
wrappedHandlers.put(factory, wrappedFactory);
return true;
}
@@ -142,7 +131,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);
}
@@ -34,10 +34,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 +69,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 +91,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);
}
/**
@@ -120,6 +120,21 @@ public class Session {
}
}
/**
* Uninitialize the session.
*
* @param player The player
*/
public void uninitialize(LocalPlayer player) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location location = player.getLocation();
ApplicableRegionSet set = query.getApplicableRegions(location);
for (Handler handler : handlers.values()) {
handler.uninitialize(player, location, set);
}
}
/**
* Tick the session.
*
@@ -45,6 +45,12 @@ public abstract class FlagValueChangeHandler<T> extends Handler {
onInitialValue(player, set, lastValue);
}
@Override
public final void uninitialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
onClearValue(player, set);
lastValue = null;
}
@Override
public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
if (entered.isEmpty() && exited.isEmpty()
@@ -74,4 +80,10 @@ public abstract class FlagValueChangeHandler<T> extends Handler {
protected abstract boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, T lastValue, MoveType moveType);
protected void onClearValue(LocalPlayer player, ApplicableRegionSet set) {
if (lastValue != null) {
Location current = player.getLocation();
onAbsentValue(player, current, current, set, lastValue, MoveType.OTHER_NON_CANCELLABLE);
}
}
}
@@ -74,6 +74,16 @@ public abstract class Handler {
public void initialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
}
/**
* Called when the session should clear its caches.
*
* @param player The player
* @param current The player's current location
* @param set The regions for the current location
*/
public void uninitialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
}
/**
* Called when {@link Session#testMoveTo(LocalPlayer, Location, MoveType)} is called.
*
@@ -138,11 +148,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;
}
}
@@ -59,4 +59,8 @@ public class NotifyExitFlag extends FlagValueChangeHandler<Boolean> {
WorldGuard.getInstance().getPlatform().broadcastNotification(new Notify(player.getName(), " left NOTIFY region").create());
return true;
}
@Override
protected void onClearValue(LocalPlayer player, ApplicableRegionSet set) {
}
}
+2 -4
View File
@@ -3,9 +3,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
applyLibrariesConfiguration()
dependencies {
"shade"("org.enginehub:squirrelid:${Versions.SQUIRRELID}") {
exclude(group = "com.destroystokyo.paper", module = "paper-api")
}
"shade"("org.enginehub:squirrelid:${Versions.SQUIRRELID}")
"shade"("org.khelekore:prtree:1.5.0")
}
@@ -17,4 +15,4 @@ tasks.named<ShadowJar>("jar") {
include(dependency("org.khelekore:prtree"))
}
}
}