mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-25 07:33:44 +02:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			fix/v7/buk
			...
			debug/home
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | ac285cae99 | ||
|   | 612402d9cb | ||
|   | c9d210bd64 | ||
|   | 25defaac07 | ||
|   | 0661d0d5a1 | 
| @@ -35,6 +35,9 @@ import com.plotsquared.core.util.query.PlotQuery; | |||||||
| import com.plotsquared.core.util.query.SortingStrategy; | import com.plotsquared.core.util.query.SortingStrategy; | ||||||
| import com.plotsquared.core.util.task.RunnableVal2; | import com.plotsquared.core.util.task.RunnableVal2; | ||||||
| import com.plotsquared.core.util.task.RunnableVal3; | 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 net.kyori.adventure.text.minimessage.Template; | ||||||
| import org.checkerframework.checker.nullness.qual.NonNull; | import org.checkerframework.checker.nullness.qual.NonNull; | ||||||
|  |  | ||||||
| @@ -59,13 +62,24 @@ public class HomeCommand extends Command { | |||||||
|         this.plotAreaManager = plotAreaManager; |         this.plotAreaManager = plotAreaManager; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Label("Home Query") | ||||||
|  |     @Category("PlotSquared") | ||||||
|  |     static class HomeQueryEvent extends Event { | ||||||
|  |         @Label("Result Size") | ||||||
|  |         public int size; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private void home( |     private void home( | ||||||
|             final @NonNull PlotPlayer<?> player, |             final @NonNull PlotPlayer<?> player, | ||||||
|             final @NonNull PlotQuery query, final int page, |             final @NonNull PlotQuery query, final int page, | ||||||
|             final RunnableVal3<Command, Runnable, Runnable> confirm, |             final RunnableVal3<Command, Runnable, Runnable> confirm, | ||||||
|             final RunnableVal2<Command, CommandResult> whenDone |             final RunnableVal2<Command, CommandResult> whenDone | ||||||
|     ) { |     ) { | ||||||
|  |         final HomeQueryEvent event = new HomeQueryEvent(); | ||||||
|  |         event.begin(); | ||||||
|         List<Plot> plots = query.asList(); |         List<Plot> plots = query.asList(); | ||||||
|  |         event.size = plots.size(); | ||||||
|  |         event.commit(); | ||||||
|         if (plots.isEmpty()) { |         if (plots.isEmpty()) { | ||||||
|             player.sendMessage(TranslatableCaption.of("invalid.found_no_plots")); |             player.sendMessage(TranslatableCaption.of("invalid.found_no_plots")); | ||||||
|             return; |             return; | ||||||
|   | |||||||
| @@ -68,6 +68,9 @@ import com.plotsquared.core.util.task.TaskTime; | |||||||
| import com.sk89q.worldedit.math.BlockVector3; | import com.sk89q.worldedit.math.BlockVector3; | ||||||
| import com.sk89q.worldedit.regions.CuboidRegion; | import com.sk89q.worldedit.regions.CuboidRegion; | ||||||
| import com.sk89q.worldedit.world.biome.BiomeType; | 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.Component; | ||||||
| import net.kyori.adventure.text.TextComponent; | import net.kyori.adventure.text.TextComponent; | ||||||
| import net.kyori.adventure.text.minimessage.MiniMessage; | 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 MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); | ||||||
|     private static final Cleaner CLEANER = Cleaner.create(); |     private static final Cleaner CLEANER = Cleaner.create(); | ||||||
|  |  | ||||||
|     static Set<Plot> connected_cache; |  | ||||||
|     static Set<CuboidRegion> regions_cache; |  | ||||||
|  |  | ||||||
|     static { |     static { | ||||||
|         FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); |         FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); | ||||||
|     } |     } | ||||||
| @@ -207,6 +207,8 @@ public class Plot { | |||||||
|      */ |      */ | ||||||
|     private Plot origin; |     private Plot origin; | ||||||
|  |  | ||||||
|  |     private Set<Plot> connectedCache; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Constructor for a new plot. |      * Constructor for a new plot. | ||||||
|      * (Only changes after plot.create() will be properly set in the database) |      * (Only changes after plot.create() will be properly set in the database) | ||||||
| @@ -576,7 +578,14 @@ public class Plot { | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|         final Set<Plot> connected = getConnectedPlots(); |         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); |             DBFunc.delete(current); | ||||||
|             current.setOwnerAbs(null); |             current.setOwnerAbs(null); | ||||||
|             current.settings = null; |             current.settings = null; | ||||||
|  |             current.clearCache(); | ||||||
|             for (final PlotPlayer<?> pp : players) { |             for (final PlotPlayer<?> pp : players) { | ||||||
|                 this.plotListener.plotEntry(pp, current); |                 this.plotListener.plotEntry(pp, current); | ||||||
|             } |             } | ||||||
| @@ -1864,6 +1874,7 @@ public class Plot { | |||||||
|         this.area.removePlot(this.id); |         this.area.removePlot(this.id); | ||||||
|         this.id = plot.getId(); |         this.id = plot.getId(); | ||||||
|         this.area.addPlotAbs(this); |         this.area.addPlotAbs(this); | ||||||
|  |         clearCache(); | ||||||
|         DBFunc.movePlot(this, plot); |         DBFunc.movePlot(this, plot); | ||||||
|         TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); |         TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); | ||||||
|         return true; |         return true; | ||||||
| @@ -2128,17 +2139,16 @@ public class Plot { | |||||||
|                     this.origin.origin = base; |                     this.origin.origin = base; | ||||||
|                     other.origin = base; |                     other.origin = base; | ||||||
|                     this.origin = base; |                     this.origin = base; | ||||||
|                     connected_cache = null; |                     this.connectedCache = null; | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 if (this.origin != null) { |                 if (this.origin != null) { | ||||||
|                     this.origin.origin = null; |                     this.origin.origin = null; | ||||||
|                     this.origin = null; |                     this.origin = null; | ||||||
|                 } |                 } | ||||||
|                 connected_cache = null; |                 this.connectedCache = null; | ||||||
|             } |             } | ||||||
|             DBFunc.setMerged(this, this.getSettings().getMerged()); |             DBFunc.setMerged(this, this.getSettings().getMerged()); | ||||||
|             regions_cache = null; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -2173,8 +2183,7 @@ public class Plot { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void clearCache() { |     public void clearCache() { | ||||||
|         connected_cache = null; |         this.connectedCache = null; | ||||||
|         regions_cache = null; |  | ||||||
|         if (this.origin != null) { |         if (this.origin != null) { | ||||||
|             this.origin.origin = null; |             this.origin.origin = null; | ||||||
|             this.origin = null; |             this.origin = null; | ||||||
| @@ -2288,6 +2297,25 @@ public class Plot { | |||||||
|         return this.area.getPlotAbs(this.id.getRelative(direction)); |         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> |      * Gets a set of plots connected (and including) this plot<br> | ||||||
|      * - This result is cached globally |      * - This result is cached globally | ||||||
| @@ -2295,16 +2323,21 @@ public class Plot { | |||||||
|      * @return a Set of Plots connected to this Plot |      * @return a Set of Plots connected to this Plot | ||||||
|      */ |      */ | ||||||
|     public Set<Plot> getConnectedPlots() { |     public Set<Plot> getConnectedPlots() { | ||||||
|  |         ConnectedPlotsEvent event = new ConnectedPlotsEvent(this.id.getX(), this.id.getY()); | ||||||
|  |         event.begin(); | ||||||
|         if (this.settings == null) { |         if (this.settings == null) { | ||||||
|  |             event.commit(); | ||||||
|             return Collections.singleton(this); |             return Collections.singleton(this); | ||||||
|         } |         } | ||||||
|         if (!this.isMerged()) { |         if (!this.isMerged()) { | ||||||
|  |             event.commit(); | ||||||
|             return Collections.singleton(this); |             return Collections.singleton(this); | ||||||
|         } |         } | ||||||
|         if (connected_cache != null && connected_cache.contains(this)) { |         if (this.connectedCache != null && this.connectedCache.contains(this)) { | ||||||
|             return connected_cache; |             event.mergedSize = this.connectedCache.size(); | ||||||
|  |             event.commit(); | ||||||
|  |             return this.connectedCache; | ||||||
|         } |         } | ||||||
|         regions_cache = null; |  | ||||||
|  |  | ||||||
|         HashSet<Plot> tmpSet = new HashSet<>(); |         HashSet<Plot> tmpSet = new HashSet<>(); | ||||||
|         tmpSet.add(this); |         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; |         return tmpSet; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -2421,19 +2457,15 @@ public class Plot { | |||||||
|      * @return all regions within the plot |      * @return all regions within the plot | ||||||
|      */ |      */ | ||||||
|     public @NonNull Set<CuboidRegion> getRegions() { |     public @NonNull Set<CuboidRegion> getRegions() { | ||||||
|         if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) { |  | ||||||
|             return regions_cache; |  | ||||||
|         } |  | ||||||
|         if (!this.isMerged()) { |         if (!this.isMerged()) { | ||||||
|             Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight()); |             Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight()); | ||||||
|             Location pos2 = this.getTopAbs().withY(getArea().getMaxBuildHeight()); |             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()); |             CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()); | ||||||
|             regions_cache = Collections.singleton(rg); |             return Collections.singleton(rg); | ||||||
|             return regions_cache; |  | ||||||
|         } |         } | ||||||
|         Set<Plot> plots = this.getConnectedPlots(); |         Set<Plot> plots = this.getConnectedPlots(); | ||||||
|         Set<CuboidRegion> regions = regions_cache = new HashSet<>(); |         Set<CuboidRegion> regions = new HashSet<>(); | ||||||
|         Set<PlotId> visited = new HashSet<>(); |         Set<PlotId> visited = new HashSet<>(); | ||||||
|         for (Plot current : plots) { |         for (Plot current : plots) { | ||||||
|             if (visited.contains(current.getId())) { |             if (visited.contains(current.getId())) { | ||||||
|   | |||||||
| @@ -263,6 +263,7 @@ public final class PlotModificationManager { | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|                 Plot current = queue.poll(); |                 Plot current = queue.poll(); | ||||||
|  |                 current.clearCache(); | ||||||
|                 if (plot.getArea().getTerrain() != PlotAreaTerrainType.NONE) { |                 if (plot.getArea().getTerrain() != PlotAreaTerrainType.NONE) { | ||||||
|                     try { |                     try { | ||||||
|                         PlotSquared.platform().regionManager().regenerateRegion( |                         PlotSquared.platform().regionManager().regenerateRegion( | ||||||
| @@ -327,6 +328,7 @@ public final class PlotModificationManager { | |||||||
|         ArrayList<PlotId> ids = new ArrayList<>(plots.size()); |         ArrayList<PlotId> ids = new ArrayList<>(plots.size()); | ||||||
|         for (Plot current : plots) { |         for (Plot current : plots) { | ||||||
|             current.setHome(null); |             current.setHome(null); | ||||||
|  |             current.clearCache(); | ||||||
|             ids.add(current.getId()); |             ids.add(current.getId()); | ||||||
|         } |         } | ||||||
|         this.plot.clearRatings(); |         this.plot.clearRatings(); | ||||||
| @@ -478,8 +480,7 @@ public final class PlotModificationManager { | |||||||
|                 this.plot.updateWorldBorder(); |                 this.plot.updateWorldBorder(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         Plot.connected_cache = null; |         this.plot.clearCache(); | ||||||
|         Plot.regions_cache = null; |  | ||||||
|         this.plot.getTrusted().clear(); |         this.plot.getTrusted().clear(); | ||||||
|         this.plot.getMembers().clear(); |         this.plot.getMembers().clear(); | ||||||
|         this.plot.getDenied().clear(); |         this.plot.getDenied().clear(); | ||||||
| @@ -630,6 +631,7 @@ public final class PlotModificationManager { | |||||||
|         if (queue.size() > 0) { |         if (queue.size() > 0) { | ||||||
|             queue.enqueue(); |             queue.enqueue(); | ||||||
|         } |         } | ||||||
|  |         visited.forEach(Plot::clearCache); | ||||||
|         return toReturn; |         return toReturn; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,9 +23,9 @@ import com.plotsquared.core.plot.PlotArea; | |||||||
| import com.plotsquared.core.plot.world.PlotAreaManager; | import com.plotsquared.core.plot.world.PlotAreaManager; | ||||||
| import org.checkerframework.checker.nullness.qual.NonNull; | import org.checkerframework.checker.nullness.qual.NonNull; | ||||||
|  |  | ||||||
|  | import java.util.ArrayList; | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.HashSet; | import java.util.List; | ||||||
| import java.util.Set; |  | ||||||
|  |  | ||||||
| class GlobalPlotProvider implements PlotProvider { | class GlobalPlotProvider implements PlotProvider { | ||||||
|  |  | ||||||
| @@ -37,7 +37,7 @@ class GlobalPlotProvider implements PlotProvider { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Collection<Plot> getPlots() { |     public Collection<Plot> getPlots() { | ||||||
|         final Set<Plot> plots = new HashSet<>(); |         final List<Plot> plots = new ArrayList<>(); | ||||||
|         for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) { |         for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) { | ||||||
|             plots.addAll(plotArea.getPlots()); |             plots.addAll(plotArea.getPlots()); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user