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
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ shadow = "9.5.1"
paperweight = "2.0.0-SNAPSHOT"
codecov = "0.3.0"
jqwik = "1.10.1"
errorproneGradlePlugin = "5.1.0"

# Error Prone
errorprone = "2.50.0"

# Minimum versions we apply to make dependencies support newer Java
minimumAsm = "9.7"
Expand All @@ -66,6 +70,7 @@ minimumJdependency = "2.10"
# Gradle plugins
shadow = { group = "com.gradleup.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" }
paperweight = { group = "io.papermc.paperweight.userdev", name = "io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paperweight" }
errorproneGradlePlugin = { group = "net.ltgt.gradle", name = "gradle-errorprone-plugin", version.ref = "errorproneGradlePlugin" }

# Minecraft expectations
paperApi = { group = "io.papermc.paper", name = "paper-api", version.ref = "paperApi" }
Expand Down Expand Up @@ -143,6 +148,9 @@ mockito-junit-jupiter = { group = "org.mockito", name = "mockito-core" }

log4j-core = { group = "org.apache.logging.log4j", name = "log4j-core", version.ref = "log4j" }

errorprone-core = { group = "com.google.errorprone", name = "error_prone_core", version.ref = "errorprone" }
errorprone-annotations = { group = "com.google.errorprone", name = "error_prone_annotations", version.ref = "errorprone" }

## Piston
[libraries.piston-core]
module = "org.enginehub.piston:core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ public boolean save(CompoundTag tag, String path) {
try {
File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
tmp.getParentFile().mkdirs();
if (tag instanceof CompressedCompoundTag) {
CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
if (tag instanceof CompressedCompoundTag cTag) {
if (cTag instanceof CompressedSchematicTag) {
Clipboard clipboard = (Clipboard) cTag.getSource();
try (OutputStream stream = new FileOutputStream(tmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,26 @@ public boolean hasPermission(OfflinePlayer player, String permission) {
return false; // Permissions are only registered for objects with a Permissible
}
switch (internalHasPermission(perms, permission)) {
case -1:
case -1 -> {
return false;
case 1:
}
case 1 -> {
return true;
default:
break;
}
default -> {
}
}
int dotPos = permission.lastIndexOf(".");
while (dotPos > -1) {
switch (internalHasPermission(perms, permission.substring(0, dotPos + 1) + "*")) {
case -1:
case -1 -> {
return false;
case 1:
}
case 1 -> {
return true;
default:
break;
}
default -> {
}
}
dotPos = permission.lastIndexOf(".", dotPos - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ public static BukkitPlayer adapt(Player player) {
* @return The Bukkit command sender
*/
public static CommandSender adapt(Actor actor) {
if (actor instanceof com.sk89q.worldedit.entity.Player) {
return adapt((com.sk89q.worldedit.entity.Player) actor);
} else if (actor instanceof BukkitBlockCommandSender) {
return ((BukkitBlockCommandSender) actor).getSender();
}
return ((BukkitCommandSender) actor).getSender();
return switch (actor) {
case com.sk89q.worldedit.entity.Player player -> adapt(player);
case BukkitBlockCommandSender bukkitBlockCommandSender -> bukkitBlockCommandSender.getSender();
case null, default -> ((BukkitCommandSender) actor).getSender();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this may result in an NPE. I just want a second opinion on this before I go and fix it before the PR is approved and merged.

};
}

/**
Expand All @@ -181,24 +180,15 @@ public static Player adapt(com.sk89q.worldedit.entity.Player player) {
* @return a WorldEdit direction
*/
public static Direction adapt(@Nullable BlockFace face) {
if (face == null) {
return null;
}
switch (face) {
case NORTH:
return Direction.NORTH;
case SOUTH:
return Direction.SOUTH;
case WEST:
return Direction.WEST;
case EAST:
return Direction.EAST;
case DOWN:
return Direction.DOWN;
case UP:
default:
return Direction.UP;
}
return switch (face) {
case null -> null;
case NORTH -> Direction.NORTH;
case SOUTH -> Direction.SOUTH;
case WEST -> Direction.WEST;
case EAST -> Direction.EAST;
case DOWN -> Direction.DOWN;
default -> Direction.UP;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMate

@Override
public boolean isAir() {
switch (material) {
case AIR:
case CAVE_AIR:
case VOID_AIR:
return true;
default:
return false;
}
return switch (material) {
case AIR, CAVE_AIR, VOID_AIR -> true;
default -> false;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public String getName() {
@Override
public boolean isActive() {
//FAWE start - check if sender instanceof Entity, before returning true
if (sender instanceof Entity) {
Entity entity = (Entity) sender;
if (sender instanceof Entity entity) {
return entity.isValid() && !entity.isDead();
}
//FAWE end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean isGolem() {

@Override
public boolean isTamed() {
return entity instanceof Tameable && ((Tameable) entity).isTamed();
return entity instanceof Tameable tameable && tameable.isTamed();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ public void print(Component component) {
public boolean trySetPosition(Vector3 pos, float pitch, float yaw) {
//FAWE start
org.bukkit.World world = player.getWorld();
if (pos instanceof com.sk89q.worldedit.util.Location) {
com.sk89q.worldedit.util.Location loc = (com.sk89q.worldedit.util.Location) pos;
if (pos instanceof com.sk89q.worldedit.util.Location loc) {
Extent extent = loc.getExtent();
if (extent instanceof World) {
world = Bukkit.getWorld(((World) extent).getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public BaseItem getItem(int slot) {
@Override
public void setItem(int slot, BaseItem block) {
loadInventory();
BaseItemStack stack = block instanceof BaseItemStack ? (BaseItemStack) block : new BaseItemStack(
BaseItemStack stack = block instanceof BaseItemStack baseItemStack ? baseItemStack : new BaseItemStack(
block.getType(),
block.getNbtData(),
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public boolean clearContainerBlockContents(BlockVector3 pt) {

TaskManager.taskManager().sync(() -> {
Inventory inven = chest.getInventory();
if (chest instanceof Chest) {
inven = ((Chest) chest).getBlockInventory();
if (chest instanceof Chest chest1) {
inven = chest1.getBlockInventory();
}
inven.clear();
return null;
Expand Down Expand Up @@ -416,11 +416,11 @@ public boolean equals(Object other) {
return false;
} else if (other == null) {
return false;
} else if ((other instanceof BukkitWorld)) {
World otherWorld = ((BukkitWorld) other).worldRef.get();
} else if (other instanceof BukkitWorld bukkitWorld) {
World otherWorld = bukkitWorld.worldRef.get();
return ref.equals(otherWorld);
} else if (other instanceof com.sk89q.worldedit.world.World) {
return ((com.sk89q.worldedit.world.World) other).getName().equals(ref.getName());
} else if (other instanceof com.sk89q.worldedit.world.World world) {
return world.getName().equals(ref.getName());
} else {
return false;
}
Expand Down Expand Up @@ -610,10 +610,10 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B
try {
return worldNativeAccess.setBlock(position, block, sideEffects);
} catch (Exception e) {
if (block instanceof BaseBlock && ((BaseBlock) block).getNbt() != null) {
if (block instanceof BaseBlock baseBlock && baseBlock.getNbt() != null) {
LOGGER.warn(
"Tried to set a corrupt tile entity at " + position.toString()
+ ": " + ((BaseBlock) block).getNbt(), e
+ ": " + baseBlock.getNbt(), e
);
} else {
LOGGER.warn("Failed to set block via adapter, falling back to generic", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
final Block clickedBlock = event.getClickedBlock();
final Location pos = clickedBlock == null ? null : new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

boolean result = false;
switch (event.getAction()) {
case LEFT_CLICK_BLOCK:
result = we.handleBlockLeftClick(player, pos, direction) || we.handleArmSwing(player);
break;
case LEFT_CLICK_AIR:
result = we.handleArmSwing(player);
break;
case RIGHT_CLICK_BLOCK:
result = we.handleBlockRightClick(player, pos, direction) || we.handleRightClick(player);
break;
case RIGHT_CLICK_AIR:
result = we.handleRightClick(player);
break;
default:
break;
}
boolean result = switch (event.getAction()) {
case LEFT_CLICK_BLOCK -> we.handleBlockLeftClick(player, pos, direction) || we.handleArmSwing(player);
case LEFT_CLICK_AIR -> we.handleArmSwing(player);
case RIGHT_CLICK_BLOCK -> we.handleBlockRightClick(player, pos, direction) || we.handleRightClick(player);
case RIGHT_CLICK_AIR -> we.handleRightClick(player);
default -> false;
};
debouncer.setLastInteraction(player, result);
if (result) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ BukkitPlayer reCachePlayer(Player player) {
//FAWE end

public Actor wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
} else if (config.commandBlockSupport && sender instanceof BlockCommandSender) {
return new BukkitBlockCommandSender(this, (BlockCommandSender) sender);
if (sender instanceof Player player) {
return wrapPlayer(player);
} else if (config.commandBlockSupport && sender instanceof BlockCommandSender blockCommandSender) {
return new BukkitBlockCommandSender(this, blockCommandSender);
}

return bukkitConsoleCommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ public class BukkitImplLoader {
private static final String CLASS_SUFFIX = ".class";

private static final String LOAD_ERROR_MESSAGE =
//FAWE start - exchange WorldEdit to FAWE & suggest to update Fawe & the server software
"\n**********************************************\n"
+ "** This FastAsyncWorldEdit version does not fully support your version of Bukkit.\n"
+ "** You can fix this by:\n"
+ "** - Updating your server version (Check /version to see how many versions you are behind)\n** - Updating FAWE\n"
+ "**\n" + "** When working with blocks or undoing, chests will be empty, signs\n"
+ "** will be blank, and so on. There will be no support for entity\n"
+ "** and block property-related functions.\n"
+ "**********************************************\n";
//FAWE start - exchange WorldEdit to FAWE & suggest to update FAWE & the server software
"""
**********************************************
** This FastAsyncWorldEdit version does not fully support your version of Bukkit.
** You can fix this by:
** - Updating your server version (Check /version to see how many versions you are behind)
** - Updating FAWE
**
** When working with blocks or undoing, chests will be empty, signs
** will be blank, and so on. There will be no support for entity
** and block property-related functions.
**********************************************
""";
//FAWE end

/**
Expand Down Expand Up @@ -89,9 +93,8 @@ private void addDefaults() {
* @throws IOException thrown on I/O error
*/
public void addFromJar(File file) throws IOException {
Closer closer = Closer.create();
try (Closer closer = Closer.create()) {
JarFile jar = closer.register(new JarFile(file));
try {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
Expand All @@ -111,8 +114,6 @@ public void addFromJar(File file) throws IOException {
adapterCandidates.add(className);
}
}
} finally {
closer.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,26 @@
public class CLIBlockRegistry extends BundledBlockRegistry {

private Property<?> createProperty(String type, String key, List<String> values) {
switch (type) {
case "int": {
return switch (type) {
case "int" -> {
List<Integer> fixedValues = values.stream().map(Integer::parseInt).collect(Collectors.toList());
return new IntegerProperty(key, fixedValues);
yield new IntegerProperty(key, fixedValues);
}
case "bool": {
case "bool" -> {
List<Boolean> fixedValues = values.stream().map(Boolean::parseBoolean).collect(Collectors.toList());
return new BooleanProperty(key, fixedValues);
yield new BooleanProperty(key, fixedValues);
}
case "enum": {
return new EnumProperty(key, values);
}
case "direction": {
case "enum" -> new EnumProperty(key, values);
case "direction" -> {
List<Direction> fixedValues = values
.stream()
.map(String::toUpperCase)
.map(Direction::valueOf)
.collect(Collectors.toList());
return new DirectionalProperty(key, fixedValues);
yield new DirectionalProperty(key, fixedValues);
}
default:
throw new RuntimeException("Failed to create property");
}
default -> throw new RuntimeException("Failed to create property");
};
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinTag;

import javax.annotation.Nonnull;
import java.util.ArrayList;
Expand Down Expand Up @@ -664,9 +666,8 @@ public ThreadPoolExecutor newBlockingExecutor(String name, Logger logger) {

protected synchronized void afterExecute(Runnable runnable, Throwable throwable) {
super.afterExecute(runnable, throwable);
if (throwable == null && runnable instanceof Future<?>) {
if (throwable == null && runnable instanceof final Future<?> future) {
try {
Future<?> future = (Future<?>) runnable;
if (future.isDone()) {
future.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public boolean reset() {
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws
MaxChangedBlocksException {
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
if (!(actor instanceof final Player player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
ClipboardHolder clipboard = session.getExistingClipboard();
if (clipboard == null) {
Mask mask = editSession.getMask();
Expand Down
Loading
Loading