Compare commits

..

1 Commits

Author SHA1 Message Date
f54bb88394 deprecate PlotId#copy 2022-10-02 20:23:26 +02:00
9 changed files with 21 additions and 50 deletions

View File

@ -18,6 +18,7 @@
*/ */
package com.plotsquared.bukkit.listener; package com.plotsquared.bukkit.listener;
import com.google.common.collect.Iterables;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
@ -38,11 +39,8 @@ public class ForceFieldListener {
private static Set<PlotPlayer<?>> getNearbyPlayers(Player player, Plot plot) { private static Set<PlotPlayer<?>> getNearbyPlayers(Player player, Plot plot) {
Set<PlotPlayer<?>> players = new HashSet<>(); Set<PlotPlayer<?>> players = new HashSet<>();
for (Player nearPlayer : player.getNearbyEntities(5d, 5d, 5d).stream() for (Player nearPlayer : Iterables
.filter(entity -> entity instanceof Player) .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
.map(entity -> (Player) entity)
.toList()
) {
PlotPlayer<?> plotPlayer; PlotPlayer<?> plotPlayer;
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
.equals(plotPlayer.getCurrentPlot())) { .equals(plotPlayer.getCurrentPlot())) {
@ -56,11 +54,8 @@ public class ForceFieldListener {
} }
private static PlotPlayer<?> hasNearbyPermitted(Player player, Plot plot) { private static PlotPlayer<?> hasNearbyPermitted(Player player, Plot plot) {
for (Player nearPlayer : player.getNearbyEntities(5d, 5d, 5d).stream() for (Player nearPlayer : Iterables
.filter(entity -> entity instanceof Player) .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
.map(entity -> (Player) entity)
.toList()
) {
PlotPlayer<?> plotPlayer; PlotPlayer<?> plotPlayer;
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
.equals(plotPlayer.getCurrentPlot())) { .equals(plotPlayer.getCurrentPlot())) {

View File

@ -126,7 +126,6 @@ public class Buy extends Command {
plot.removeFlag(event.getFlag()); plot.removeFlag(event.getFlag());
} }
plot.setOwner(player.getUUID()); plot.setOwner(player.getUUID());
plot.getPlotModificationManager().setSign(player.getName());
player.sendMessage( player.sendMessage(
TranslatableCaption.of("working.claimed"), TranslatableCaption.of("working.claimed"),
Template.of("plot", plot.getId().toString()) Template.of("plot", plot.getId().toString())

View File

@ -176,7 +176,7 @@ public class DatabaseCommand extends SubCommand {
); );
worldFile.renameTo(newFile); worldFile.renameTo(newFile);
} }
plot.setId(newId.copy()); plot.setId(newId);
plot.setArea(pa); plot.setArea(pa);
plots.add(plot); plots.add(plot);
continue; continue;

View File

@ -181,7 +181,6 @@ public class Download extends SubCommand {
schematicHandler.upload(compoundTag, null, null, new RunnableVal<>() { schematicHandler.upload(compoundTag, null, null, new RunnableVal<>() {
@Override @Override
public void run(URL value) { public void run(URL value) {
plot.removeRunning();
player.sendMessage( player.sendMessage(
TranslatableCaption.of("web.generation_link_success"), TranslatableCaption.of("web.generation_link_success"),
Template.of("download", value.toString()), Template.of("download", value.toString()),

View File

@ -26,7 +26,6 @@ import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.RunnableVal3;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "near", @CommandDeclaration(command = "near",
@ -49,13 +48,9 @@ public class Near extends Command {
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot")); final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
player.sendMessage( player.sendMessage(
TranslatableCaption.of("near.plot_near"), TranslatableCaption.of("near.plot_near"),
Template.of("list", StringMan.join(getPlayersInPlotVisible(plot, player), ", ")) Template.of("list", StringMan.join(plot.getPlayersInPlot(), ", "))
); );
return CompletableFuture.completedFuture(true); return CompletableFuture.completedFuture(true);
} }
private List<PlotPlayer<?>> getPlayersInPlotVisible(Plot plot, PlotPlayer<?> executor) {
return plot.getPlayersInPlot().stream().filter(executor::canSee).toList();
}
} }

View File

@ -28,17 +28,13 @@ import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.GlobalBlockQueue;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public abstract class ClassicPlotWorld extends SquarePlotWorld { public abstract class ClassicPlotWorld extends SquarePlotWorld {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + ClassicPlotWorld.class.getSimpleName());
public int ROAD_HEIGHT = 62; public int ROAD_HEIGHT = 62;
public int PLOT_HEIGHT = 62; public int PLOT_HEIGHT = 62;
@ -125,15 +121,15 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
super.loadConfiguration(config); super.loadConfiguration(config);
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock"); this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
this.PLOT_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("plot.height")); this.PLOT_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("plot.height"));
this.MAIN_BLOCK = createCheckedBlockBucket(config.getString("plot.filling"), MAIN_BLOCK); this.MAIN_BLOCK = new BlockBucket(config.getString("plot.filling"));
this.TOP_BLOCK = createCheckedBlockBucket(config.getString("plot.floor"), TOP_BLOCK); this.TOP_BLOCK = new BlockBucket(config.getString("plot.floor"));
this.WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block"), WALL_BLOCK); this.WALL_BLOCK = new BlockBucket(config.getString("wall.block"));
this.ROAD_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("road.height")); this.ROAD_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("road.height"));
this.ROAD_BLOCK = createCheckedBlockBucket(config.getString("road.block"), ROAD_BLOCK); this.ROAD_BLOCK = new BlockBucket(config.getString("road.block"));
this.WALL_FILLING = createCheckedBlockBucket(config.getString("wall.filling"), WALL_FILLING); this.WALL_FILLING = new BlockBucket(config.getString("wall.filling"));
this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block"); this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block");
this.WALL_HEIGHT = Math.min(getMaxGenHeight() - (PLACE_TOP_BLOCK ? 1 : 0), config.getInt("wall.height")); this.WALL_HEIGHT = Math.min(getMaxGenHeight() - (PLACE_TOP_BLOCK ? 1 : 0), config.getInt("wall.height"));
this.CLAIMED_WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block_claimed"), CLAIMED_WALL_BLOCK); this.CLAIMED_WALL_BLOCK = new BlockBucket(config.getString("wall.block_claimed"));
} }
int schematicStartHeight() { int schematicStartHeight() {
@ -144,19 +140,4 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
return Math.min(WALL_HEIGHT, plotRoadMin); return Math.min(WALL_HEIGHT, plotRoadMin);
} }
private static BlockBucket createCheckedBlockBucket(String input, BlockBucket def) {
final BlockBucket bucket = new BlockBucket(input);
Pattern pattern = null;
try {
pattern = bucket.toPattern();
} catch (Exception ignore) {
}
if (pattern == null) {
LOGGER.error("Failed to parse pattern '{}', check your worlds.yml", input);
LOGGER.error("Falling back to {}", def);
return def;
}
return bucket;
}
} }

View File

@ -1836,8 +1836,8 @@ public class Plot {
} }
// Swap cached // Swap cached
final PlotId temp = PlotId.of(this.getId().getX(), this.getId().getY()); final PlotId temp = PlotId.of(this.getId().getX(), this.getId().getY());
this.id = plot.getId().copy(); this.id = plot.getId();
plot.id = temp.copy(); plot.id = temp;
this.area.removePlot(this.getId()); this.area.removePlot(this.getId());
plot.area.removePlot(plot.getId()); plot.area.removePlot(plot.getId());
this.area.addPlotAbs(this); this.area.addPlotAbs(this);
@ -1863,7 +1863,7 @@ public class Plot {
return false; return false;
} }
this.area.removePlot(this.id); this.area.removePlot(this.id);
this.id = plot.getId().copy(); this.id = plot.getId();
this.area.addPlotAbs(this); this.area.addPlotAbs(this);
DBFunc.movePlot(this, plot); DBFunc.movePlot(this, plot);
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));

View File

@ -110,9 +110,11 @@ public final class PlotId {
* Get a copy of the plot ID * Get a copy of the plot ID
* *
* @return Plot ID copy * @return Plot ID copy
* @deprecated PlotId is immutable, copy is not required.
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public @NonNull PlotId copy() { public @NonNull PlotId copy() {
return of(this.getX(), this.getY()); return this;
} }
/** /**

View File

@ -19,7 +19,7 @@ plugins {
} }
group = "com.plotsquared" group = "com.plotsquared"
version = "6.10.1" version = "6.10.1-SNAPSHOT"
subprojects { subprojects {
group = rootProject.group group = rootProject.group