Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Changelog

## 7.0.21

* Improved protection checks for placing cushions.
* Fixed straw beds not being treated as beds for certain flags.
* Fixed cases where creepers could lose tracking of players who triggered them to explode.
* Improved caching to ensure unloaded worlds are not kept around in memory longer than necessary.
* Improved Folia detection to better detect Folia forks.
* Fixed errors on Folia caused by complex cross-world block interactions.

## 7.0.20

* Require 26.3+.
* Fixed poplar boats causing errors in some situations.
* Support Paper's new EntityBreakEvent (used for cushion destruction) in protection.
* Improved handling of buckets on waterlogged blocks when sneaking.
* Fixed a Folia error caused by entity actions occuring across Folia region boundaries.
* Fixed a Folia error caused by entity actions occurring across Folia region boundaries.
* Improved command feedback when setting a state flag to "none".

## 7.0.19
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group=com.sk89q.worldguard
version=7.0.21-SNAPSHOT
version=7.0.22-SNAPSHOT

org.gradle.parallel=true
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public BukkitWorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLP
plugin.createDefaultConfiguration(configFile, "config_world.yml");
plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");

config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
config = new YAMLProcessor(configFile.toPath(), true, YAMLFormat.EXTENDED);
loadConfiguration();

if (summaryOnStart) {
Expand Down Expand Up @@ -298,7 +298,7 @@ public void loadConfiguration() {
explosionFlagCancellation = getBoolean("regions.explosion-flags-block-entity-damage", true);
highFreqFlags = getBoolean("regions.high-frequency-flags", false);
checkLiquidFlow = getBoolean("regions.protect-against-liquid-flow", false);
regionWand = convertLegacyItem(getString("regions.wand", ItemTypes.LEATHER.getId()));
regionWand = convertLegacyItem(getString("regions.wand", ItemTypes.LEATHER.id()));
maxClaimVolume = getInt("regions.max-claim-volume", 30000);
claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false);
setParentOnClaim = getString("regions.set-parent-on-claim", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@ public PlayerMoveListener getPlayerMoveListener() {
private final LazyReference<Boolean> folia = LazyReference.from(() -> {
try {
return getWorldEdit().isFolia(); // Delegate check to WorldEdit
} catch (Throwable t) {
} catch (NoSuchMethodError _) {
// Ignore, this likely means an outdated version.
LOGGER.warn("Failed to check if server is running Folia, as WorldEdit's Folia support is missing.");
} catch (Throwable t) {
// Unknown error, log it and return false.
LOGGER.warn("Failed to check if server is running Folia", t);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public Entity getFirstNonPlayerEntity() {
@Nullable
public Block getFirstBlock() {
for (Object object : causes) {
if (object instanceof Block b) {
if (object instanceof Block b && (!WorldGuardPlugin.inst().isFolia()
|| Bukkit.isOwnedByCurrentRegion(b.getLocation()))) {
return b;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
BlockState previousState = event.getBlockReplacedState();

// Some blocks, like tall grass and fire, get replaced
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockReplacedState().getType()) {
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockPlaced().getType()) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
Material targetId = blockTo.getType();

if ((isAir || isWater) &&
wcfg.preventWaterDamage.contains(BukkitAdapter.asBlockType(targetId).getId())) {
wcfg.preventWaterDamage.contains(BukkitAdapter.asBlockType(targetId).id())) {
event.setCancelled(true);
return;
}
Expand All @@ -163,7 +163,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
if (!wcfg.allowedLavaSpreadOver.isEmpty() && isLava) {
Material targetId = blockTo.getRelative(0, -1, 0).getType();

if (!wcfg.allowedLavaSpreadOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
if (!wcfg.allowedLavaSpreadOver.contains(BukkitAdapter.asBlockType(targetId).id())) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -233,11 +233,11 @@ public void onBlockIgnite(BlockIgniteEvent event) {
int y = block.getY();
int z = block.getZ();

if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y - 1, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x + 1, y, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x - 1, y, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z - 1).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z + 1).getType()).getId())) {
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y - 1, z).getType()).id())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x + 1, y, z).getType()).id())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x - 1, y, z).getType()).id())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z - 1).getType()).id())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z + 1).getType()).id())) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -303,7 +303,7 @@ public void onBlockBurn(BlockBurnEvent event) {
if (!wcfg.disableFireSpreadBlocks.isEmpty()) {
Block block = event.getBlock();

if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).id())) {
event.setCancelled(true);
checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
return;
Expand Down Expand Up @@ -511,7 +511,7 @@ public void onBlockForm(BlockFormEvent event) {
if (!wcfg.allowedSnowFallOver.isEmpty()) {
Material targetId = event.getBlock().getRelative(0, -1, 0).getType();

if (!wcfg.allowedSnowFallOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
if (!wcfg.allowedSnowFallOver.contains(BukkitAdapter.asBlockType(targetId).id())) {
event.setCancelled(true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onLightningStrike(LightningStrikeEvent event) {
if (targetId == Material.AIR) {
targetId = target.getRelative(BlockFace.DOWN).getType();
}
if (wcfg.disallowedLightningBlocks.contains(BukkitAdapter.asBlockType(targetId).getId())) {
if (wcfg.disallowedLightningBlocks.contains(BukkitAdapter.asBlockType(targetId).id())) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.bukkit.event.Event;

import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
import java.time.Duration;

public class EventDebounce<K> {

Expand All @@ -36,7 +36,7 @@ public class EventDebounce<K> {
public EventDebounce(int debounceTime) {
cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(debounceTime, TimeUnit.MILLISECONDS)
.expireAfterWrite(Duration.ofMillis(debounceTime))
.concurrencyLevel(2)
.build(new CacheLoader<K, Entry>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.bukkit.event.Event;

import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
import java.time.Duration;

public class AbstractEventDebounce<K> {

Expand All @@ -36,7 +36,7 @@ public class AbstractEventDebounce<K> {
AbstractEventDebounce(int debounceTime) {
cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(debounceTime, TimeUnit.MILLISECONDS)
.expireAfterWrite(Duration.ofMillis(debounceTime))
.concurrencyLevel(2)
.build(new CacheLoader<K, Entry>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.Tag;
import org.bukkit.entity.Allay;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Boat;
import org.bukkit.entity.BreezeWindCharge;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Creeper;
Expand Down Expand Up @@ -69,7 +71,7 @@ private Entities() {
* @return true if tamed
*/
public static boolean isTamed(@Nullable Entity entity) {
return entity instanceof Tameable && ((Tameable) entity).isTamed();
return entity instanceof Tameable tameable && tameable.isTamed();
}

/**
Expand Down Expand Up @@ -122,13 +124,8 @@ public static boolean isVehicle(EntityType type) {
* @return true if the type is a Boat type
*/
public static boolean isBoat(EntityType type) {
return switch (type) {
case OAK_BOAT, DARK_OAK_BOAT, SPRUCE_BOAT, ACACIA_BOAT, CHERRY_BOAT, JUNGLE_BOAT, MANGROVE_BOAT,
BIRCH_BOAT, PALE_OAK_BOAT, BAMBOO_RAFT, OAK_CHEST_BOAT, DARK_OAK_CHEST_BOAT, SPRUCE_CHEST_BOAT,
ACACIA_CHEST_BOAT, CHERRY_CHEST_BOAT, JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT, BIRCH_CHEST_BOAT,
PALE_OAK_CHEST_BOAT, BAMBOO_CHEST_RAFT -> true;
default -> false;
};
Class<?> entityClass = type.getEntityClass();
return entityClass != null && Boat.class.isAssignableFrom(entityClass);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 isBoat 改写后遗留未使用的导入 org.bukkit.Tag

Category: 可维护性与代码质量

isBoat 改写为基于 getEntityClass 判断后,整个文件已不再引用 Tag,但顶部的 import org.bukkit.Tag 未被一并删除,留成死导入;若项目启用了 checkstyle 的 UnusedImports 规则,该未使用导入还会导致构建失败。

Problem code:

Class<?> entityClass = type.getEntityClass();
return entityClass != null && Boat.class.isAssignableFrom(entityClass);

Recommendation:
删除该文件顶部未使用的 import org.bukkit.Tag 语句。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/Chloemlla/WorldGuard
Path: worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java
Line: 127-128

Comment:
isBoat 改写后遗留未使用的导入 org.bukkit.Tag

isBoat 改写为基于 getEntityClass 判断后,整个文件已不再引用 Tag,但顶部的 import org.bukkit.Tag 未被一并删除,留成死导入;若项目启用了 checkstyle 的 UnusedImports 规则,该未使用导入还会导致构建失败。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix with MonkeyCode
Fix with Claude
Fix with Codex

}

/**
Expand All @@ -153,8 +150,7 @@ public static boolean isMinecart(EntityType type) {
*/
public static Entity getShooter(Entity entity) {

while (entity instanceof Projectile) {
Projectile projectile = (Projectile) entity;
while (entity instanceof Projectile projectile) {
ProjectileSource remover = projectile.getShooter();
if (remover instanceof Entity && remover != entity) {
entity = (Entity) remover;
Expand Down Expand Up @@ -261,16 +257,14 @@ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReaso
*/
public static @Nonnull StateFlag getExplosionFlag(Entity entity) {
return switch (entity) {
case BreezeWindCharge breezeWindCharge -> Flags.BREEZE_WIND_CHARGE;
case WindCharge windCharge -> Flags.WIND_CHARGE_BURST;
case Firework firework -> Flags.FIREWORK_DAMAGE;
case Fireball fireball -> Flags.GHAST_FIREBALL;
case Wither wither -> Flags.WITHER_DAMAGE;
case Creeper creeper -> Flags.CREEPER_EXPLOSION;
case TNTPrimed tnt -> Flags.TNT;
case SulfurCube sulfurCube -> Flags.TNT;
case ExplosiveMinecart minecart -> Flags.TNT;
case EnderDragon dragon -> Flags.ENDERDRAGON_BLOCK_DAMAGE;
case BreezeWindCharge _ -> Flags.BREEZE_WIND_CHARGE;
case WindCharge _ -> Flags.WIND_CHARGE_BURST;
case Firework _ -> Flags.FIREWORK_DAMAGE;
case Fireball _ -> Flags.GHAST_FIREBALL;
case Wither _ -> Flags.WITHER_DAMAGE;
case Creeper _ -> Flags.CREEPER_EXPLOSION;
case TNTPrimed _, SulfurCube _, ExplosiveMinecart _ -> Flags.TNT;
case EnderDragon _ -> Flags.ENDERDRAGON_BLOCK_DAMAGE;
case null, default -> Flags.OTHER_EXPLOSION;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -53,7 +53,7 @@ public class Blacklist {
private boolean useAsWhitelist;
private LoadingCache<String, TrackedEvent> repeatingEventCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterAccess(30, TimeUnit.SECONDS)
.expireAfterAccess(Duration.ofSeconds(30))
.build(CacheLoader.from(TrackedEvent::new));

public Blacklist(boolean useAsWhitelist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BlockMatcher(BlockType type) {

@Override
public String getMatchedTypeId() {
return this.type.getId();
return this.type.id();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ItemBlockMatcher(BlockType type) {

@Override
public String getMatchedTypeId() {
return this.type.getId();
return this.type.id();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ItemMatcher(ItemType type) {

@Override
public String getMatchedTypeId() {
return this.type.getId();
return this.type.id();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ public String convertLegacyItem(String legacy) {
}
ItemType legacyItem = LegacyMapper.getInstance().getItemFromLegacy(id, data);
if (legacyItem != null) {
return legacyItem.getId();
return legacyItem.id();
}
} catch (NumberFormatException ignored) {
}
final ItemType itemType = ItemTypes.get(legacy);
if (itemType != null) {
return itemType.getId();
return itemType.id();
}

return null;
Expand All @@ -242,13 +242,13 @@ public String convertLegacyBlock(String legacy) {
}
BlockState legacyBlock = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (legacyBlock != null) {
return legacyBlock.getBlockType().getId();
return legacyBlock.getBlockType().id();
}
} catch (NumberFormatException ignored) {
}
final BlockType blockType = BlockTypes.get(legacy);
if (blockType != null) {
return blockType.getId();
return blockType.id();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class YamlConfigurationManager extends ConfigurationManager {
public void load() {
copyDefaults();

config = new YAMLProcessor(new File(getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
config = new YAMLProcessor(new File(getDataFolder(), "config.yml").toPath(), true, YAMLFormat.EXTENDED);
try {
config.load();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private void setDomainData(Map<String, Object> domainData, String key, Set<?> do
*/
private YAMLProcessor createYamlProcessor(File file) {
checkNotNull(file);
return new YAMLProcessor(file, false, YAMLFormat.COMPACT);
return new YAMLProcessor(file.toPath(), false, YAMLFormat.COMPACT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
public class DomainInputResolver implements Callable<DefaultDomain> {

private static final Pattern GROUP_PATTERN = Pattern.compile("(?i)^[G]:(.+)$");
private static final int MAX_PLAYER_NAME_LENGTH = 16;

/**
* The policy for locating users.
Expand Down Expand Up @@ -119,9 +120,14 @@ public DefaultDomain call() throws UnresolvedNamesException {
}
}

if (!namesToQuery.isEmpty()) {
// Paper rejects longer names with an exception, so leave them unresolved.
List<String> validNames = namesToQuery.stream()
.filter(name -> name.length() <= MAX_PLAYER_NAME_LENGTH)
.toList();

if (!validNames.isEmpty()) {
try {
for (Profile profile : profileService.findAllByName(namesToQuery)) {
for (Profile profile : profileService.findAllByName(validNames)) {
namesToQuery.remove(profile.getName().toLowerCase());
domain.addPlayer(profile.getUniqueId());
}
Expand Down
Loading