From 411900f474dd4f8f83418d07032275f79d16b0d7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Jun 2015 17:37:59 +1000 Subject: [PATCH] Working on experimental plot analysis + ignore some interactions --- .../plot/generator/BukkitHybridUtils.java | 56 ++++++++++++++++--- .../plot/generator/HybridUtils.java | 5 +- .../plot/listeners/PlayerEvents.java | 14 +++++ .../plot/object/PlotAnalysis.java | 17 ++++++ .../plot/object/RunnableVal.java | 5 +- .../plot/util/ExpireManager.java | 4 +- 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index 0f9b16a7a..9e42c3ba1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -4,12 +4,16 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Random; import org.apache.commons.lang.mutable.MutableInt; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.block.Block; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.plugin.Plugin; import com.intellectualcrafters.plot.BukkitMain; @@ -18,7 +22,9 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.ChunkManager; @@ -28,27 +34,60 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class BukkitHybridUtils extends HybridUtils { - public void checkModified(final Plot plot, final RunnableVal whenDone) { - TaskManager.index.increment(); - - final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); - final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + @Override + public void analyzePlot(Plot plot, RunnableVal whenDone) { + // TODO Auto-generated method stub + // int diff, int variety, int verticies, int rotation, int height_sd + /* + * diff: compare to base by looping through all blocks + * variety: add to hashset for each plotblock + * height_sd: loop over all blocks and get top block + * + * verticies: store air map and compare with neighbours + * for each block check the adjacent + * - Store all blocks then go through in second loop + * - recheck each block + * + */ + World world = Bukkit.getWorld(plot.world); + ChunkGenerator gen = world.getGenerator(); + BiomeGrid base = new BiomeGrid() { @Override public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) {return null;}}; + final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); int bx = bot.getX() >> 4; int bz = bot.getZ() >> 4; - int tx = top.getX() >> 4; int tz = top.getZ() >> 4; + Random r = new Random(); + for (int X = bx; X <= tx; X++) { + for (int Z = bz; Z <= tz; Z++) { + Chunk chunk = world.getChunkAt(X, Z); + short[][] result = gen.generateExtBlockSections(world, r, x, z, base); + for (int x = 0; x < 16; x++) { + + } + } + } + short[] [] result = gen.generateExtBlockSections(world, null, x, z, ) + } + + public void checkModified(final Plot plot, final RunnableVal whenDone) { + TaskManager.index.increment(); + final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + int bx = bot.getX() >> 4; + int bz = bot.getZ() >> 4; + int tx = top.getX() >> 4; + int tz = top.getZ() >> 4; World world = BukkitUtil.getWorld(plot.world); - final HashSet chunks = new HashSet<>(); for (int X = bx; X <= tx; X++) { for (int Z = bz; Z <= tz; Z++) { chunks.add(world.getChunkAt(X,Z)); } } - PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); if (!(plotworld instanceof ClassicPlotWorld)) { whenDone.value = -1; @@ -263,5 +302,4 @@ public class BukkitHybridUtils extends HybridUtils { }, 20, 20); return true; } - } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index 2a7f528aa..cf5163b7d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotLoc; @@ -22,7 +23,9 @@ public abstract class HybridUtils { public static HybridUtils manager; - public abstract void checkModified(final Plot plot, final RunnableVal whenDone); + public abstract void checkModified(final Plot plot, final RunnableVal whenDone); + + public abstract void analyzePlot(final Plot plot, final RunnableVal whenDone); public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 2dad7f28b..cff971a86 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -72,6 +72,9 @@ import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.StructureGrowEvent; +import org.bukkit.material.MaterialData; +import org.bukkit.material.Tree; +import org.bukkit.material.Wool; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.BlockProjectileSource; @@ -827,6 +830,17 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (block == null) { return; } + Material type = block.getType(); + if (true || type.isSolid() && type.isBlock() && type.isOccluding()) { + BlockState state = block.getState(); + MaterialData data = state.getData(); + if (data instanceof Tree || data instanceof Wool || state.getData().getClass().equals(MaterialData.class)) { + Class clazz = state.getClass(); + if (clazz.getSimpleName().equals("CraftBlockState")) { + return; + } + } + } final Player player = event.getPlayer(); final String world = player.getWorld().getName(); if (!PlotSquared.isPlotWorld(world)) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java new file mode 100644 index 000000000..226880cef --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -0,0 +1,17 @@ +package com.intellectualcrafters.plot.object; + +public class PlotAnalysis { + public final long diff; + public final long variety; + public final long verticies; + public final long rotation; + public final long height_sd; + + public PlotAnalysis(int diff, int variety, int verticies, int rotation, int height_sd) { + this.diff = diff; + this.variety = variety; + this.verticies = verticies; + this.rotation = rotation; + this.height_sd = height_sd; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java index 3a4c41241..01dfc3a30 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java @@ -1,7 +1,6 @@ package com.intellectualcrafters.plot.object; -public abstract class RunnableVal implements Runnable { - public Object value; - +public abstract class RunnableVal implements Runnable { + public T value; public abstract void run(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 2e4979274..99b18a999 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -124,10 +124,10 @@ public class ExpireManager { return; } final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - RunnableVal run = new RunnableVal() { + RunnableVal run = new RunnableVal() { @Override public void run() { - int changed = (int) this.value; + int changed = (Integer) this.value; if (Settings.MIN_BLOCKS_CHANGED_IGNORED > 0 || Settings.MIN_BLOCKS_CHANGED > 0 && manager instanceof ClassicPlotManager) { if (changed >= Settings.MIN_BLOCKS_CHANGED && Settings.MIN_BLOCKS_CHANGED > 0) { PlotSquared.log("&7[&5Expire&dManager&7] &bKeep flag added to: " + plot.id + (changed != -1 ? " (changed " + value + ")" : ""));