Compare commits

..

5 Commits

Author SHA1 Message Date
ac285cae99 Clear caches in more cases 2022-12-21 21:27:23 +01:00
612402d9cb Avoid extensive hashing of plots 2022-12-21 16:11:58 +01:00
c9d210bd64 Simplify isOwner check 2022-12-21 16:08:09 +01:00
25defaac07 Replace global connected plots cache with local cache 2022-12-21 15:20:15 +01:00
0661d0d5a1 Add JFR events 2022-12-20 18:53:33 +01:00
11 changed files with 140 additions and 69 deletions

View File

@ -27,7 +27,6 @@ body:
description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first.
multiple: false
options:
- '1.19.3'
- '1.19.2'
- '1.19.1'
- '1.19'

View File

@ -48,6 +48,7 @@ dependencies {
// Our libraries
implementation(libs.arkitektonika)
implementation(libs.http4j)
implementation("com.intellectualsites.paster:Paster")
implementation("com.intellectualsites.informative-annotations:informative-annotations")

View File

@ -71,7 +71,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
@ -101,6 +100,7 @@ import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SpongeAbsorbEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.material.Directional;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.util.Vector;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -926,9 +926,6 @@ public class BlockEventListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent event) {
if (!this.plotAreaManager.hasPlotArea(event.getBlock().getWorld().getName())) {
return;
}
Material type = event.getItem().getType();
switch (type.toString()) {
case "SHULKER_BOX", "WHITE_SHULKER_BOX", "ORANGE_SHULKER_BOX", "MAGENTA_SHULKER_BOX", "LIGHT_BLUE_SHULKER_BOX",
@ -940,7 +937,7 @@ public class BlockEventListener implements Listener {
if (event.getBlock().getType() == Material.DROPPER) {
return;
}
BlockFace targetFace = ((Dispenser) event.getBlock().getBlockData()).getFacing();
BlockFace targetFace = ((Directional) event.getBlock().getState().getData()).getFacing();
Location location = BukkitUtil.adapt(event.getBlock().getRelative(targetFace).getLocation());
if (location.isPlotRoad()) {
event.setCancelled(true);

View File

@ -35,6 +35,9 @@ import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import net.kyori.adventure.text.minimessage.Template;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -59,13 +62,24 @@ public class HomeCommand extends Command {
this.plotAreaManager = plotAreaManager;
}
@Label("Home Query")
@Category("PlotSquared")
static class HomeQueryEvent extends Event {
@Label("Result Size")
public int size;
}
private void home(
final @NonNull PlotPlayer<?> player,
final @NonNull PlotQuery query, final int page,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone
) {
final HomeQueryEvent event = new HomeQueryEvent();
event.begin();
List<Plot> plots = query.asList();
event.size = plots.size();
event.commit();
if (plots.isEmpty()) {
player.sendMessage(TranslatableCaption.of("invalid.found_no_plots"));
return;

View File

@ -114,14 +114,26 @@ public abstract class SquarePlotManager extends GridPlotManager {
end = pathWidthLower + squarePlotWorld.PLOT_WIDTH;
}
int size = squarePlotWorld.PLOT_WIDTH + squarePlotWorld.ROAD_WIDTH;
int dx = Math.floorDiv(x, size) + 1;
int rx = Math.floorMod(x, size);
int dz = Math.floorDiv(z, size) + 1;
int rz = Math.floorMod(z, size);
if (rz <= pathWidthLower || rz > end || rx <= pathWidthLower || rx > end) {
int idx;
if (x < 0) {
idx = x / size;
x = size + (x % size);
} else {
idx = (x / size) + 1;
x = x % size;
}
int idz;
if (z < 0) {
idz = z / size;
z = size + (z % size);
} else {
idz = (z / size) + 1;
z = z % size;
}
if (z <= pathWidthLower || z > end || x <= pathWidthLower || x > end) {
return null;
} else {
return PlotId.of(dx, dz);
return PlotId.of(idx, idz);
}
}
@ -168,10 +180,24 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
end = pathWidthLower + squarePlotWorld.PLOT_WIDTH;
}
int dx = Math.floorDiv(x, size) + 1;
int rx = Math.floorMod(x, size);
int dz = Math.floorDiv(z, size) + 1;
int rz = Math.floorMod(z, size);
int dx;
int rx;
if (x < 0) {
dx = x / size;
rx = size + (x % size);
} else {
dx = (x / size) + 1;
rx = x % size;
}
int dz;
int rz;
if (z < 0) {
dz = z / size;
rz = size + (z % size);
} else {
dz = (z / size) + 1;
rz = z % size;
}
PlotId id = PlotId.of(dx, dz);
boolean[] merged = new boolean[]{rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower};
int hash = HashUtil.hash(merged);

View File

@ -68,6 +68,9 @@ import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -122,9 +125,6 @@ public class Plot {
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private static final Cleaner CLEANER = Cleaner.create();
static Set<Plot> connected_cache;
static Set<CuboidRegion> regions_cache;
static {
FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340);
}
@ -207,6 +207,8 @@ public class Plot {
*/
private Plot origin;
private Set<Plot> connectedCache;
/**
* Constructor for a new plot.
* (Only changes after plot.create() will be properly set in the database)
@ -576,7 +578,14 @@ public class Plot {
return false;
}
final Set<Plot> connected = getConnectedPlots();
return connected.stream().anyMatch(current -> uuid.equals(current.getOwner()));
for (Plot current : connected) {
// can skip ServerPlotFlag check in getOwner()
// as flags are synchronized between plots
if (uuid.equals(current.getOwnerAbs())) {
return true;
}
}
return false;
}
/**
@ -1294,6 +1303,7 @@ public class Plot {
DBFunc.delete(current);
current.setOwnerAbs(null);
current.settings = null;
current.clearCache();
for (final PlotPlayer<?> pp : players) {
this.plotListener.plotEntry(pp, current);
}
@ -1864,6 +1874,7 @@ public class Plot {
this.area.removePlot(this.id);
this.id = plot.getId();
this.area.addPlotAbs(this);
clearCache();
DBFunc.movePlot(this, plot);
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
return true;
@ -2128,17 +2139,16 @@ public class Plot {
this.origin.origin = base;
other.origin = base;
this.origin = base;
connected_cache = null;
this.connectedCache = null;
}
} else {
if (this.origin != null) {
this.origin.origin = null;
this.origin = null;
}
connected_cache = null;
this.connectedCache = null;
}
DBFunc.setMerged(this, this.getSettings().getMerged());
regions_cache = null;
}
}
@ -2173,8 +2183,7 @@ public class Plot {
}
public void clearCache() {
connected_cache = null;
regions_cache = null;
this.connectedCache = null;
if (this.origin != null) {
this.origin.origin = null;
this.origin = null;
@ -2288,6 +2297,25 @@ public class Plot {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
@Label("Connected Plots Search")
@Category("PlotSquared")
static class ConnectedPlotsEvent extends Event {
public ConnectedPlotsEvent(final int x, final int y) {
this.x = x;
this.y = y;
}
@Label("Plot Id X")
public int x;
@Label("Plot Id Y")
public int y;
@Label("Merged Plots Count")
public int mergedSize;
@Label("Connected Plots Cache Miss")
public boolean cacheMiss;
}
/**
* Gets a set of plots connected (and including) this plot<br>
* - This result is cached globally
@ -2295,16 +2323,21 @@ public class Plot {
* @return a Set of Plots connected to this Plot
*/
public Set<Plot> getConnectedPlots() {
ConnectedPlotsEvent event = new ConnectedPlotsEvent(this.id.getX(), this.id.getY());
event.begin();
if (this.settings == null) {
event.commit();
return Collections.singleton(this);
}
if (!this.isMerged()) {
event.commit();
return Collections.singleton(this);
}
if (connected_cache != null && connected_cache.contains(this)) {
return connected_cache;
if (this.connectedCache != null && this.connectedCache.contains(this)) {
event.mergedSize = this.connectedCache.size();
event.commit();
return this.connectedCache;
}
regions_cache = null;
HashSet<Plot> tmpSet = new HashSet<>();
tmpSet.add(this);
@ -2409,7 +2442,10 @@ public class Plot {
}
}
}
connected_cache = tmpSet;
this.connectedCache = tmpSet;
event.mergedSize = tmpSet.size();
event.cacheMiss = true;
event.commit();
return tmpSet;
}
@ -2421,19 +2457,15 @@ public class Plot {
* @return all regions within the plot
*/
public @NonNull Set<CuboidRegion> getRegions() {
if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) {
return regions_cache;
}
if (!this.isMerged()) {
Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight());
Location pos2 = this.getTopAbs().withY(getArea().getMaxBuildHeight());
connected_cache = Sets.newHashSet(this);
this.connectedCache = Sets.newHashSet(this);
CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
regions_cache = Collections.singleton(rg);
return regions_cache;
return Collections.singleton(rg);
}
Set<Plot> plots = this.getConnectedPlots();
Set<CuboidRegion> regions = regions_cache = new HashSet<>();
Set<CuboidRegion> regions = new HashSet<>();
Set<PlotId> visited = new HashSet<>();
for (Plot current : plots) {
if (visited.contains(current.getId())) {

View File

@ -263,6 +263,7 @@ public final class PlotModificationManager {
return;
}
Plot current = queue.poll();
current.clearCache();
if (plot.getArea().getTerrain() != PlotAreaTerrainType.NONE) {
try {
PlotSquared.platform().regionManager().regenerateRegion(
@ -327,6 +328,7 @@ public final class PlotModificationManager {
ArrayList<PlotId> ids = new ArrayList<>(plots.size());
for (Plot current : plots) {
current.setHome(null);
current.clearCache();
ids.add(current.getId());
}
this.plot.clearRatings();
@ -478,8 +480,7 @@ public final class PlotModificationManager {
this.plot.updateWorldBorder();
}
}
Plot.connected_cache = null;
Plot.regions_cache = null;
this.plot.clearCache();
this.plot.getTrusted().clear();
this.plot.getMembers().clear();
this.plot.getDenied().clear();
@ -630,6 +631,7 @@ public final class PlotModificationManager {
if (queue.size() > 0) {
queue.enqueue();
}
visited.forEach(Plot::clearCache);
return toReturn;
}

View File

@ -23,9 +23,9 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
class GlobalPlotProvider implements PlotProvider {
@ -37,7 +37,7 @@ class GlobalPlotProvider implements PlotProvider {
@Override
public Collection<Plot> getPlots() {
final Set<Plot> plots = new HashSet<>();
final List<Plot> plots = new ArrayList<>();
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
plots.addAll(plotArea.getPlots());
}

View File

@ -1,18 +1,16 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
PlotSquared, a land and world management plugin for Minecraft.
Copyright (C) IntellectualSites <https://intellectualsites.com>
Copyright (C) IntellectualSites team and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

View File

@ -1,6 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.cadixdev.gradle.licenser.LicenseExtension
import org.cadixdev.gradle.licenser.Licenser
import java.net.URI
import com.diffplug.gradle.spotless.SpotlessPlugin
plugins {
java
@ -9,7 +10,7 @@ plugins {
signing
alias(libs.plugins.shadow)
alias(libs.plugins.spotless)
alias(libs.plugins.licenser)
alias(libs.plugins.grgit)
alias(libs.plugins.nexus)
@ -56,7 +57,7 @@ subprojects {
plugin<JavaLibraryPlugin>()
plugin<MavenPublishPlugin>()
plugin<ShadowPlugin>()
plugin<SpotlessPlugin>()
plugin<Licenser>()
plugin<SigningPlugin>()
plugin<EclipsePlugin>()
@ -86,11 +87,10 @@ subprojects {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER.txt"))
target("**/*.java")
}
configure<LicenseExtension> {
header(rootProject.file("HEADER.txt"))
include("**/*.java")
newLine.set(false)
}
java {

View File

@ -16,11 +16,12 @@ aopalliance = "1.0"
cloud-services = "1.8.0"
arkitektonika = "2.1.1"
squirrelid = "0.3.1"
http4j = "1.3"
# Gradle plugins
shadow = "7.1.2"
grgit = "4.1.1"
spotless = "6.12.1"
licenser = "0.6.1"
nexus = "1.1.0"
[libraries]
@ -43,9 +44,10 @@ cloudServices = { group = "cloud.commandframework", name = "cloud-services", ver
mvdwapi = { group = "com.intellectualsites.mvdwplaceholderapi", name = "MVdWPlaceholderAPI", version.ref = "mvdwapi" }
squirrelid = { group = "org.enginehub", name = "squirrelid", version.ref = "squirrelid" }
arkitektonika = { group = "com.intellectualsites.arkitektonika", name = "Arkitektonika-Client", version.ref = "arkitektonika" }
http4j = { group = "com.intellectualsites.http", name = "HTTP4J", version.ref = "http4j" }
[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
grgit = { id = "org.ajoberstar.grgit", version.ref = "grgit" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
licenser = { id = "org.cadixdev.licenser", version.ref = "licenser" }
nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }