diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 2bf04f751..adabc5b01 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,16 +1,17 @@ package com.plotsquared.bukkit.listeners; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; - +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.util.*; +import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.object.BukkitLazyBlock; +import com.plotsquared.bukkit.object.BukkitPlayer; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.listener.PlayerBlockEventType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -19,64 +20,17 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Animals; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Creature; -import org.bukkit.entity.EnderDragon; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Hanging; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Monster; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.entity.Tameable; -import org.bukkit.entity.ThrownPotion; -import org.bukkit.entity.Vehicle; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockDispenseEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockGrowEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.block.BlockRedstoneEvent; -import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.EntityBlockFormEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.PotionSplashEvent; -import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.*; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.StructureGrowEvent; @@ -89,34 +43,9 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotHandler; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotInventory; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.RegExUtil; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.bukkit.BukkitMain; -import com.plotsquared.bukkit.object.BukkitLazyBlock; -import com.plotsquared.bukkit.object.BukkitPlayer; -import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.listener.PlayerBlockEventType; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Pattern; /** * Player Events involving plots @@ -462,10 +391,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { final Player player = event.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(player); - // Cancel teleport TaskManager.TELEPORT_QUEUE.remove(pp.getName()); - // Set last location Location loc = BukkitUtil.getLocation(to); pp.setMeta("location", loc); @@ -867,6 +794,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen return; } } + return; } final Plot plot = area.getOwnedPlot(loc); if (plot == null) { @@ -982,6 +910,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen blocks.remove(i); } } + return; } else { Plot origin = area.getOwnedPlot(loc); if (origin == null) { @@ -1104,11 +1033,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (eventType != null && !player.isSneaking()) { break; } - Material type = hand == null ? null : hand.getType(); - int id = type == null ? 0 : type.getId(); + Material type = (hand == null) ? null : hand.getType(); + int id = (type == null) ? 0 : type.getId(); if (id == 0) { eventType = PlayerBlockEventType.INTERACT_BLOCK; - lb = new BukkitLazyBlock(id, block); + lb = new BukkitLazyBlock(0, block); break; } else if (id < 198) { loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index e499b1bba..942905d66 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -1,7 +1,5 @@ package com.plotsquared.bukkit.util; -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; @@ -19,13 +17,11 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; +import java.util.*; import java.util.Map.Entry; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; + /** * An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS) * @@ -107,10 +103,6 @@ public class SendChunk { final Object c = methodGetHandleChunk.of(chunk).call(); chunks.remove(chunk); final Object con = connection.of(entity).get(); - // if (dx != 0 || dz != 0) { - // Object packet = MapChunk.create(c, true, 0); - // send.of(con).call(packet); - // } final Object packet = MapChunk.create(c, true, 65535); send.of(con).call(packet); } @@ -131,55 +123,6 @@ public class SendChunk { } }); } - // - // - // int diffx, diffz; - // << 4; - // for (final Chunk chunk : chunks) { - // if (!chunk.isLoaded()) { - // continue; - // } - // boolean unload = true; - // final Object c = methodGetHandle.of(chunk).call(); - // final Object w = world.of(c).get(); - // final Object p = players.of(w).get(); - // for (final Object ep : (List) p) { - // final int x = ((Double) locX.of(ep).get()).intValue(); - // final int z = ((Double) locZ.of(ep).get()).intValue(); - // diffx = Math.abs(x - (chunk.getX() << 4)); - // diffz = Math.abs(z - (chunk.getZ() << 4)); - // if ((diffx <= view) && (diffz <= view)) { - // unload = false; - // if (v1_7_10) { - // chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); - // chunk.load(true); - // } - // else { - // final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); - // final Object pq = chunkCoordIntPairQueue.of(ep).get(); - // ((List) pq).add(pair); - // } - // } - // } - // if (unload) { - // TaskManager.runTask(new Runnable() { - // @Override - // public void run() { - // try { - // chunk.unload(true, true); - // } - // catch (Exception e) { - // String worldname = chunk.getWorld().getName(); - // PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ()); - // PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)"); - // PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname + "level_old.dat may be corrupt (try repairing - // or removing these)"); - // } - // } - // }); - // } - // - // } } public void sendChunk(final String worldname, final List locs) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java index a79ab772a..c4044fb04 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java @@ -22,7 +22,7 @@ public class GenChunk extends PlotChunk { public GenChunk(Chunk chunk, ChunkWrapper wrap) { super(wrap); - if ((this.chunk = chunk) == null) { + if ((this.chunk = chunk) == null && wrap != null) { World world = BukkitUtil.getWorld(wrap.world); if (world != null) { chunk = world.getChunkAt(wrap.x, wrap.z); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java index 76e57ce11..7210290bd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -1,10 +1,5 @@ package com.intellectualcrafters.plot.commands; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Objects; -import java.util.Set; - import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; @@ -12,26 +7,15 @@ import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.generator.AugmentedUtils; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridPlotWorld; -import com.intellectualcrafters.plot.object.ChunkLoc; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotMessage; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.object.RunnableVal3; -import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.CmdConfirm; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.WorldUtil; +import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.util.*; import com.plotsquared.general.commands.CommandDeclaration; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Objects; +import java.util.Set; + @CommandDeclaration( command = "area", permission = "plots.area", @@ -166,6 +150,7 @@ public class Area extends SubCommand { PlotArea area = areas.iterator().next(); pa.TYPE = area.TYPE; } + pa.SIZE = (short) (pa.PLOT_WIDTH + pa.ROAD_WIDTH); for (int i = 2; i < args.length; i++) { String[] pair = args[i].split("="); if (pair.length != 2) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Middle.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Middle.java index 472d57793..2ac52a9df 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Middle.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Middle.java @@ -31,9 +31,6 @@ public class Middle extends SubCommand { if (!plot.hasOwner()) { return sendMessage(player, C.PLOT_UNOWNED); } - if (!player.hasPermission("plots.middle")) { - return sendMessage(player, C.NO_PERMISSION, "plots.middle"); - } player.teleport(plot.getCenter()); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 17cbee36c..7ccb632d7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -21,7 +21,9 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandDeclaration; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java index 398fd156c..8aa6ded1b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java @@ -5,10 +5,10 @@ import com.intellectualcrafters.plot.util.ChatManager; public class PlotMessage { - private final Object builder; + private Object builder; public PlotMessage() { - builder = ChatManager.manager.builder(); + reset(ChatManager.manager); } public T $(final ChatManager manager) { @@ -19,6 +19,10 @@ public class PlotMessage { this(); text(text); } + + public T reset(ChatManager manager) { + return (T) (builder = manager.builder()); + } public PlotMessage text(final String text) { ChatManager.manager.text(this, text); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index ca99e96f9..fd186eecd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -53,7 +53,6 @@ public class ReflectionUtils { } public static Method findMethod(Class clazz, boolean isStatic, Class returnType, Class... types) { - System.out.println("CLASS: " + clazz + " | " + isStatic + " | " + returnType + " | " + types.length); loop: for (Method method : clazz.getMethods()) { Class result = method.getReturnType(); Class[] param = method.getParameterTypes(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 450309f64..828603ea4 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -1,30 +1,5 @@ package com.plotsquared.sponge; -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import org.slf4j.Logger; -import org.spongepowered.api.Game; -import org.spongepowered.api.Server; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; -import org.spongepowered.api.event.game.state.GameInitializationEvent; -import org.spongepowered.api.event.game.state.GamePreInitializationEvent; -import org.spongepowered.api.plugin.Plugin; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.profile.GameProfileManager; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.gen.GenerationPopulator; -import org.spongepowered.api.world.gen.WorldGenerator; -import org.spongepowered.api.world.gen.WorldGeneratorModifier; - import com.google.inject.Inject; import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.plot.IPlotMain; @@ -38,44 +13,38 @@ import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.AbstractTitle; -import com.intellectualcrafters.plot.util.ChatManager; -import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.EconHandler; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.InventoryUtil; -import com.intellectualcrafters.plot.util.PlotQueue; -import com.intellectualcrafters.plot.util.SchematicHandler; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; -import com.intellectualcrafters.plot.util.WorldUtil; +import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.sponge.generator.SpongePlotGenerator; import com.plotsquared.sponge.listener.ChunkProcessor; import com.plotsquared.sponge.listener.MainListener; import com.plotsquared.sponge.listener.WorldEvents; -import com.plotsquared.sponge.util.KillRoadMobs; -import com.plotsquared.sponge.util.SpongeChatManager; -import com.plotsquared.sponge.util.SpongeChunkManager; -import com.plotsquared.sponge.util.SpongeCommand; -import com.plotsquared.sponge.util.SpongeEconHandler; -import com.plotsquared.sponge.util.SpongeEventUtil; -import com.plotsquared.sponge.util.SpongeHybridUtils; -import com.plotsquared.sponge.util.SpongeInventoryUtil; -import com.plotsquared.sponge.util.SpongeMetrics; -import com.plotsquared.sponge.util.SpongeSchematicHandler; +import com.plotsquared.sponge.util.*; import com.plotsquared.sponge.util.SpongeSetupUtils; -import com.plotsquared.sponge.util.SpongeTaskManager; -import com.plotsquared.sponge.util.SpongeTitleManager; -import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.block.FastQueue; import com.plotsquared.sponge.util.block.SlowQueue; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeUUIDHandler; +import org.slf4j.Logger; +import org.spongepowered.api.Game; +import org.spongepowered.api.Server; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; +import org.spongepowered.api.event.game.state.GameInitializationEvent; +import org.spongepowered.api.event.game.state.GamePreInitializationEvent; +import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.profile.GameProfileManager; +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.gen.GenerationPopulator; +import org.spongepowered.api.world.gen.WorldGenerator; +import org.spongepowered.api.world.gen.WorldGeneratorModifier; + +import java.io.File; +import java.util.*; /** * Created by robin on 01/11/2014 @@ -173,7 +142,7 @@ public class SpongeMain implements IPlotMain { logger.info(message); return; } - server.getConsole().sendMessage(Text.of(message)); + server.getConsole().sendMessage(SpongeUtil.getText(message)); } @Override @@ -415,6 +384,7 @@ public class SpongeMain implements IPlotMain { public PlotQueue initPlotQueue() { if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { try { + MainUtil.canSendChunk = true; return new FastQueue(); } catch (Throwable e) { e.printStackTrace(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java index 77f73718f..332b1f3f7 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java @@ -1,13 +1,5 @@ package com.plotsquared.sponge.generator; -import java.util.List; - -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.extent.ImmutableBiomeArea; -import org.spongepowered.api.world.extent.MutableBlockVolume; -import org.spongepowered.api.world.gen.GenerationPopulator; -import org.spongepowered.api.world.gen.WorldGenerator; - import com.flowpowered.math.vector.Vector3i; import com.intellectualcrafters.plot.generator.AugmentedUtils; import com.intellectualcrafters.plot.object.LazyResult; @@ -15,6 +7,13 @@ import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.plotsquared.sponge.util.SpongeUtil; +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.extent.ImmutableBiomeArea; +import org.spongepowered.api.world.extent.MutableBlockVolume; +import org.spongepowered.api.world.gen.GenerationPopulator; +import org.spongepowered.api.world.gen.WorldGenerator; + +import java.util.List; public class SpongeAugmentedGenerator implements GenerationPopulator { @@ -59,7 +58,7 @@ public class SpongeAugmentedGenerator implements GenerationPopulator { } @Override public void setBiome(int x, int z, int biome) { - world.setBiome(bx + x, bz + z, null); + System.out.println("TODO set biome: " + biome); // TODO FIXME } @Override public PlotChunk clone() { @@ -69,6 +68,10 @@ public class SpongeAugmentedGenerator implements GenerationPopulator { public PlotChunk shallowClone() { throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } + @Override + public void addToQueue() {} + @Override + public void flush(boolean fixLighting) {} }; } }); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java index caa96314a..c8b47e681 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java @@ -1,8 +1,14 @@ package com.plotsquared.sponge.generator; -import java.util.ArrayList; -import java.util.List; - +import com.flowpowered.math.vector.Vector2i; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.generator.GeneratorWrapper; +import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.ReflectionUtils; +import com.plotsquared.sponge.util.SpongeUtil; import org.spongepowered.api.data.DataContainer; import org.spongepowered.api.world.WorldCreationSettings; import org.spongepowered.api.world.biome.BiomeGenerationSettings; @@ -14,15 +20,8 @@ import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGeneratorModifier; -import com.flowpowered.math.vector.Vector2i; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.generator.GeneratorWrapper; -import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.ReflectionUtils; -import com.plotsquared.sponge.util.SpongeUtil; +import java.util.ArrayList; +import java.util.List; public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper { @@ -93,6 +92,7 @@ public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWra BiomeGenerationSettings biomeSettings = wg.getBiomeSettings(type); biomeSettings.getGenerationPopulators().clear(); biomeSettings.getPopulators().clear(); + biomeSettings.getGroundCoverLayers().clear(); } wg.getGenerationPopulators().clear(); wg.getPopulators().clear(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 63b65488c..e95077de0 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -4,24 +4,10 @@ import com.flowpowered.math.vector.Vector3d; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.util.*; import com.plotsquared.listener.PlotListener; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; @@ -31,7 +17,6 @@ import org.spongepowered.api.block.BlockState; import org.spongepowered.api.data.Transaction; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; -import org.spongepowered.api.entity.Transform; import org.spongepowered.api.entity.explosive.Explosive; import org.spongepowered.api.entity.explosive.PrimedTNT; import org.spongepowered.api.entity.living.Ambient; @@ -53,18 +38,11 @@ import org.spongepowered.api.event.message.MessageEvent; import org.spongepowered.api.event.network.ClientConnectionEvent; import org.spongepowered.api.event.world.ExplosionEvent; import org.spongepowered.api.event.world.ExplosionEvent.Detonate; -import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.text.Text; import org.spongepowered.api.world.World; -import org.spongepowered.api.world.extent.Extent; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; @@ -99,14 +77,14 @@ public class MainListener { public void onCommand(final SendCommandEvent event) { switch (event.getCommand().toLowerCase()) { case "plotme": { - Player source = SpongeUtil. getCause(event.getCause(), Player.class); + Player source = SpongeUtil.getCause(event.getCause(), Player.class); if (source == null) { return; } if (Settings.USE_PLOTME_ALIAS) { SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); } else { - source.sendMessage(Text.of(C.NOT_USING_PLOTME.s())); + source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME.s())); } event.setCancelled(true); } @@ -164,7 +142,7 @@ public class MainListener { } else { prefix = message; } - components.add(Text.of(part)); + components.add(SpongeUtil.getText(part)); } ((SpongePlayer) user).player.sendMessage(Text.join(components)); } @@ -314,7 +292,7 @@ public class MainListener { public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception { final AtomicBoolean cancelled = new AtomicBoolean(false); - SpongeUtil.printCause("physics", event.getCause()); +// SpongeUtil.printCause("physics", event.getCause()); // PlotArea area = plotloc.getPlotArea(); // event.filterDirections(new Predicate() { // @@ -457,7 +435,6 @@ public class MainListener { return; } event.filter(new Predicate>() { - @Override public boolean test(org.spongepowered.api.world.Location loc) { if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) { @@ -487,7 +464,7 @@ public class MainListener { public void onBlockBreak(final ChangeBlockEvent.Break event) { Player player = SpongeUtil. getCause(event.getCause(), Player.class); if (player == null) { - event.setCancelled(true); +// SpongeUtil.printCause("break", event.getCause()); return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); @@ -531,7 +508,7 @@ public class MainListener { } } event.filter(new Predicate>() { - + @Override public boolean test(org.spongepowered.api.world.Location l) { Location loc = SpongeUtil.getLocation(worldname, l); @@ -571,7 +548,7 @@ public class MainListener { public void onBlockPlace(final ChangeBlockEvent.Place event) { Player player = SpongeUtil. getCause(event.getCause(), Player.class); if (player == null) { - event.setCancelled(true); +// SpongeUtil.printCause("place", event.getCause()); return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); @@ -615,7 +592,7 @@ public class MainListener { } } event.filter(new Predicate>() { - + @Override public boolean test(org.spongepowered.api.world.Location l) { Location loc = SpongeUtil.getLocation(worldname, l); @@ -651,42 +628,54 @@ public class MainListener { }); } - @Listener - public void onConnect(final ClientConnectionEvent.Login event) { - GameProfile profile = event.getProfile(); - if (profile.getName().equals("PlotSquared") || profile.getUniqueId().equals(DBFunc.everyone) || DBFunc.everyone.equals(UUIDHandler.getUUID(profile.getName(), null))) { - event.setCancelled(true); - } - } - @Listener public void onJoin(final ClientConnectionEvent.Join event) { final Player player = event.getTargetEntity(); - SpongeUtil.removePlayer(player.getName()); + SpongeUtil.getPlayer(player).unregister(); final PlotPlayer pp = SpongeUtil.getPlayer(player); - final String username = pp.getName(); - final StringWrapper name = new StringWrapper(username); + // Now + String name = pp.getName(); + StringWrapper sw = new StringWrapper(name); final UUID uuid = pp.getUUID(); - UUIDHandler.add(name, uuid); - ExpireManager.dates.put(uuid, System.currentTimeMillis()); - if ((PS.get().update != null) && pp.hasPermission("plots.admin")) { - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { + UUIDHandler.add(sw, uuid); + + Location loc = pp.getLocation(); + PlotArea area = loc.getPlotArea(); + final Plot plot; + if (area != null) { + plot = area.getPlot(loc); + if (plot != null) { + PlotListener.plotEntry(pp, plot); + } + } else { + plot = null; + } + // Delayed + + // Async + TaskManager.runTaskLaterAsync(new Runnable() { + @Override + public void run() { + ExpireManager.dates.put(uuid, System.currentTimeMillis()); + if (PS.get().worldedit != null) { + if (pp.getAttribute("worldedit")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASSED); + } + } + if (PS.get().update != null && Permissions.hasPermission(pp, C.PERMISSION_ADMIN_UPDATE) && Settings.UPDATE_NOTIFICATIONS) { MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update"); } - }, 20); - } - final Location loc = SpongeUtil.getLocation(player); - final Plot plot = loc.getPlot(); - if (plot == null) { - return; - } - if (Settings.TELEPORT_ON_LOGIN) { - pp.teleport(loc); - MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); - } - PlotListener.plotEntry(pp, plot); + if (Settings.TELEPORT_ON_LOGIN && plot != null) { + TaskManager.runTask(new Runnable() { + @Override + public void run() { + plot.teleportPlayer(pp); + } + }); + MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); + } + } + }, 20); } @Listener @@ -698,61 +687,54 @@ public class MainListener { @Listener public void onMove(final DisplaceEntityEvent.TargetPlayer event) { - final org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); + org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); org.spongepowered.api.world.Location to = event.getToTransform().getLocation(); int x2; if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); - final Extent extent = to.getExtent(); - pp.setMeta("location", SpongeUtil.getLocation(player)); - final World world = (World) extent; - final String worldname = ((World) extent).getName(); - final PlotArea plotworld = PS.get().getPlotAreaByString(worldname); - if (plotworld == null) { + // Cancel teleport + TaskManager.TELEPORT_QUEUE.remove(pp.getName()); + // Set last location + Location loc = SpongeUtil.getLocation(to); + pp.setMeta("location", loc); + PlotArea area = loc.getPlotArea(); + if (area == null) { + pp.deleteMeta("lastplot"); return; } - final PlotManager plotManager = plotworld.getPlotManager(); - final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ())); - final Plot lastPlot = (Plot) pp.getMeta("lastplot"); - if (id == null) { - if (lastPlot == null) { - return; - } - if (!PlotListener.plotExit(pp, lastPlot)) { + Plot now = area.getPlotAbs(loc); + final Plot lastPlot = pp.getMeta("lastplot"); + if (now == null) { + if (lastPlot != null && !PlotListener.plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); - if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) { - event.setCancelled(true); + if (lastPlot.equals(SpongeUtil.getLocation(from).getPlot())) { + player.setLocation(from); } else { - event.setToTransform(new Transform<>(world.getSpawnLocation())); + player.setLocation(player.getWorld().getSpawnLocation()); } + event.setCancelled(true); return; } - } else if ((lastPlot != null) && id.equals(lastPlot.getId())) { + } else if (now.equals(lastPlot)) { + return; + } else if (!PlotListener.plotEntry(pp, now)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + player.setLocation(from); + event.setCancelled(true); return; - } else { - final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id); - if (!PlotListener.plotEntry(pp, plot)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!plot.getBasePlot(false).equals(SpongeUtil.getLocation(worldname, from).getPlot())) { - event.setCancelled(true); - } else { - event.setToTransform(new Transform<>(world.getSpawnLocation())); - } - return; - } } - final Integer border = plotworld.getBorder(); + final Integer border = area.getBorder(); if (x2 > border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); - event.setToTransform(new Transform<>(to)); + to.sub(x2 - border + 4, 0, 0); + player.setLocation(to); MainUtil.sendMessage(pp, C.BORDER); + return; } else if (x2 < -border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); - event.setToTransform(new Transform<>(to)); + to.add(border - x2 + 4, 0, 0); + player.setLocation(to); MainUtil.sendMessage(pp, C.BORDER); + return; } return; } @@ -760,54 +742,45 @@ public class MainListener { if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); - final Extent extent = to.getExtent(); - pp.setMeta("location", SpongeUtil.getLocation(player)); - final World world = (World) extent; - final String worldname = ((World) extent).getName(); - final PlotArea plotworld = PS.get().getPlotAreaByString(worldname); - if (plotworld == null) { + // Cancel teleport + TaskManager.TELEPORT_QUEUE.remove(pp.getName()); + // Set last location + Location loc = SpongeUtil.getLocation(to); + pp.setMeta("location", loc); + PlotArea area = loc.getPlotArea(); + if (area == null) { + pp.deleteMeta("lastplot"); return; } - final PlotManager plotManager = plotworld.getPlotManager(); - final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); + Plot now = area.getPlotAbs(loc); final Plot lastPlot = pp.getMeta("lastplot"); - if (id == null) { - if (lastPlot == null) { - return; - } - if (!PlotListener.plotExit(pp, lastPlot)) { + if (now == null) { + if (lastPlot != null && !PlotListener.plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); - if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) { - event.setCancelled(true); + if (lastPlot.equals(SpongeUtil.getLocation(from).getPlot())) { + player.setLocation(from); } else { - event.setToTransform(new Transform<>(world.getSpawnLocation())); + player.setLocation(player.getWorld().getSpawnLocation()); } + event.setCancelled(true); return; } - } else if ((lastPlot != null) && id.equals(lastPlot.getId())) { + } else if (now.equals(lastPlot)) { + return; + } else if (!PlotListener.plotEntry(pp, now)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + player.setLocation(from); + event.setCancelled(true); return; - } else { - final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id); - if (!PlotListener.plotEntry(pp, plot)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!plot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) { - event.setCancelled(true); - } else { - event.setToTransform(new Transform<>(world.getSpawnLocation())); - } - return; - } } - final Integer border = plotworld.getBorder(); + final Integer border = area.getBorder(); if (z2 > border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); - event.setToTransform(new Transform<>(to)); + to.add(0, 0, z2 - border - 4); + player.setLocation(to); MainUtil.sendMessage(pp, C.BORDER); } else if (z2 < -border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); - event.setToTransform(new Transform<>(to)); + to.add(0, 0, border - z2 + 4); + player.setLocation(to); MainUtil.sendMessage(pp, C.BORDER); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index bca246f79..af32c40ad 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -1,22 +1,5 @@ package com.plotsquared.sponge.object; -import java.time.Instant; -import java.util.HashSet; -import java.util.UUID; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.data.key.Keys; -import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData; -import org.spongepowered.api.data.value.mutable.Value; -import org.spongepowered.api.effect.sound.SoundTypes; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.entity.living.player.gamemode.GameMode; -import org.spongepowered.api.entity.living.player.gamemode.GameModes; -import org.spongepowered.api.service.ban.BanService; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.chat.ChatTypes; -import org.spongepowered.api.text.serializer.TextSerializers; - import com.flowpowered.math.vector.Vector3d; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.config.Settings; @@ -27,6 +10,21 @@ import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.sponge.util.SpongeUtil; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData; +import org.spongepowered.api.data.value.mutable.Value; +import org.spongepowered.api.effect.sound.SoundTypes; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.entity.living.player.gamemode.GameMode; +import org.spongepowered.api.entity.living.player.gamemode.GameModes; +import org.spongepowered.api.service.ban.BanService; +import org.spongepowered.api.text.chat.ChatTypes; +import org.spongepowered.api.text.serializer.TextSerializers; + +import java.time.Instant; +import java.util.HashSet; +import java.util.UUID; public class SpongePlayer extends PlotPlayer { @@ -278,7 +276,7 @@ public class SpongePlayer extends PlotPlayer { @Override public void kick(final String message) { - player.kick(Text.of(message)); + player.kick(SpongeUtil.getText(message)); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java index 507c0f839..ded1b685f 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java @@ -1,27 +1,118 @@ package com.plotsquared.sponge.util; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.action.TextActions; -import org.spongepowered.api.text.serializer.TextSerializers; - import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChatManager; import com.plotsquared.sponge.object.SpongePlayer; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.action.TextActions; +import org.spongepowered.api.text.format.TextColor; +import org.spongepowered.api.text.format.TextColors; +import org.spongepowered.api.text.format.TextStyle; +import org.spongepowered.api.text.format.TextStyles; + +import java.util.List; public class SpongeChatManager extends ChatManager { - + @Override public Text.Builder builder() { return Text.builder(); } - + @Override public void color(final PlotMessage m, final String color) { - m.$(this).color(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(color).getColor()); + TextColor tc = null; + TextStyle ts = null; + switch (color.charAt(1)) { + case 'a': + tc = TextColors.GREEN; + break; + case 'b': + tc = TextColors.AQUA; + break; + case 'c': + tc = TextColors.RED; + break; + case 'd': + tc = TextColors.LIGHT_PURPLE; + break; + case 'e': + tc = TextColors.YELLOW; + break; + case 'f': + tc = TextColors.WHITE; + break; + case '1': + tc = TextColors.DARK_BLUE; + break; + case '2': + tc = TextColors.DARK_GREEN; + break; + case '3': + tc = TextColors.DARK_AQUA; + break; + case '4': + tc = TextColors.DARK_RED; + break; + case '5': + tc = TextColors.DARK_PURPLE; + break; + case '6': + tc = TextColors.GOLD; + break; + case '7': + tc = TextColors.GRAY; + break; + case '8': + tc = TextColors.DARK_GRAY; + break; + case '9': + tc = TextColors.BLUE; + break; + case '0': + tc = TextColors.BLACK; + break; + case 'k': + ts = TextStyles.OBFUSCATED; + break; + case 'l': + ts = TextStyles.BOLD; + break; + case 'm': + ts = TextStyles.UNDERLINE; + break; + case 'n': + ts = TextStyles.STRIKETHROUGH; + break; + case 'o': + ts = TextStyles.ITALIC; + break; + case 'r': + tc = TextColors.RESET; + break; + } + if (tc != null) { + apply(m, getChild(m).color(tc)); + } + if (ts != null) { + apply(m, getChild(m).style(ts)); + } } - + + public Text.Builder getChild(PlotMessage m) { + Text.Builder builder = m.$(this); + List children = builder.getChildren(); + Text last = children.get(children.size() - 1); + builder.remove(last); + return Text.builder().append(last); + } + + public void apply(PlotMessage m, Text.Builder builder) { + m.$(this).append(builder.build()); + } + @Override public void tooltip(final PlotMessage m, final PlotMessage... tooltips) { final Text.Builder builder = Text.builder(); @@ -33,20 +124,19 @@ public class SpongeChatManager extends ChatManager { builder.append(tooltip.$(this).build()); lb = true; } - // AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder(); - m.$(this).onHover(TextActions.showText(builder.toText())); + apply(m, getChild(m).onHover(TextActions.showText(builder.toText()))); } - + @Override public void command(final PlotMessage m, final String command) { - m.$(this).onClick(TextActions.runCommand(command)); + apply(m, getChild(m).onClick(TextActions.runCommand(command))); } - + @Override public void text(final PlotMessage m, final String text) { - m.$(this).append(Text.of(text)); + m.$(this).append(SpongeUtil.getText(text)); } - + @Override public void send(final PlotMessage m, final PlotPlayer player) { if (ConsolePlayer.isConsole(player)) { @@ -55,10 +145,9 @@ public class SpongeChatManager extends ChatManager { ((SpongePlayer) player).player.sendMessage(m.$(this).build()); } } - + @Override public void suggest(final PlotMessage m, final String command) { - m.$(this).onClick(TextActions.suggestCommand(command)); + apply(m, getChild(m).onClick(TextActions.suggestCommand(command))); } - } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index b55491b7a..3fc0b1a2c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ReflectionUtils; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.TaskManager; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.chunk.IChunkProvider; @@ -17,6 +18,8 @@ import org.spongepowered.api.entity.living.monster.Monster; import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.World; +import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; @@ -83,19 +86,27 @@ public class SpongeChunkManager extends ChunkManager { PS.debug("Not valid world generator for: " + world); return; } - ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z); - System.out.println((loc.x & 4294967295L | (loc.z & 4294967295L) << 32) + ":" + pos); net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk; if (chunkServer.chunkExists(loc.x, loc.z)) { mcChunk = chunkServer.loadChunk(loc.x, loc.z); mcChunk.onChunkUnload(); } -// Set set = (Set) chunkProvider.getClass().getDeclaredField("droppedChunksSet").get(chunkProvider); - Set set = (Set) ReflectionUtils.findField(chunkServer.getClass(), Set.class).get(chunkServer); + Field fieldDroppedChunksSet; + try { + fieldDroppedChunksSet = chunkServer.getClass().getField("field_73248_b"); + } catch (Throwable t) { + try { + fieldDroppedChunksSet = chunkServer.getClass().getField("droppedChunksSet"); + } + catch (Throwable t2) { + fieldDroppedChunksSet = ReflectionUtils.findField(chunkServer.getClass(), Set.class); + } + } + Set set = (Set) fieldDroppedChunksSet.get(chunkServer); set.remove(pos); chunkServer.id2ChunkMap.remove(pos); mcChunk = chunkProvider.provideChunk(loc.x, loc.z); @@ -104,7 +115,7 @@ public class SpongeChunkManager extends ChunkManager { if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z); - System.out.println("WORKED?"); + SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc)); } else { PS.debug("CHUNK IS NULL!?"); @@ -167,4 +178,4 @@ public class SpongeChunkManager extends ChunkManager { throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } -} +} \ No newline at end of file diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java index 91bba3862..3f7059197 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java @@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.Command; import com.plotsquared.sponge.SpongeMain; import org.spongepowered.api.command.CommandCallable; @@ -20,20 +21,22 @@ public class SpongeCommand implements CommandCallable { @Override public CommandResult process(final CommandSource cmd, final String string) throws CommandException { - final String id = cmd.getIdentifier(); - PlotPlayer pp; - try { - final UUID uuid = UUID.fromString(id); - final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); - pp = SpongeUtil.getPlayer(player); - } catch (final Exception e) { - pp = ConsolePlayer.getConsole(); - } - if (MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" "))) { - return CommandResult.success(); - } else { - return CommandResult.empty(); - } + TaskManager.runTask(new Runnable() { + @Override + public void run() { + final String id = cmd.getIdentifier(); + PlotPlayer pp; + try { + final UUID uuid = UUID.fromString(id); + final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); + pp = SpongeUtil.getPlayer(player); + } catch (final Exception e) { + pp = ConsolePlayer.getConsole(); + } + MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" ")); + } + }); + return CommandResult.success(); } @Override @@ -43,14 +46,14 @@ public class SpongeCommand implements CommandCallable { } final PlotPlayer player = SpongeUtil.getPlayer((Player) source); String[] split = string.split(" "); - if (split.length < 2) { + if (split.length < 1) { return Collections.singletonList("plots"); } - if (split.length > 2) { - return null; + if (split.length > 1) { + return Collections.emptyList(); } final Set tabOptions = new HashSet<>(); - final String arg = split[1].toLowerCase(); + final String arg = split[0].toLowerCase(); ArrayList labels = new ArrayList<>(); for (final Command cmd : MainCommand.getInstance().getCommands()) { final String label = cmd.getCommand(); @@ -72,7 +75,7 @@ public class SpongeCommand implements CommandCallable { if (!tabOptions.isEmpty()) { return new ArrayList<>(tabOptions); } - return null; + return Collections.emptyList(); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java index f60894031..7c3735222 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java @@ -119,7 +119,6 @@ public class SpongeSchematicHandler extends SchematicHandler { int xxb = X << 4; int zzb = Z << 4; if (!worldObj.getChunk(xxb, 1, zzb).isPresent() && !worldObj.loadChunk(xxb, 1, zzb, false).isPresent()) { - System.out.println("COULD NOT LOAD CHUNK AT: " + chunk.x + "," + chunk.z); continue; } int xxt = xxb + 15; diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java index ea80e866b..f6c0b4aa2 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java @@ -1,21 +1,5 @@ package com.plotsquared.sponge.util; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Objects; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.world.DimensionTypes; -import org.spongepowered.api.world.GeneratorTypes; -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.WorldCreationSettings; -import org.spongepowered.api.world.WorldCreationSettings.Builder; -import org.spongepowered.api.world.gen.WorldGenerator; -import org.spongepowered.api.world.gen.WorldGeneratorModifier; -import org.spongepowered.api.world.storage.WorldProperties; - import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.ConfigurationNode; @@ -25,6 +9,21 @@ import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.sponge.generator.SpongePlotGenerator; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.world.DimensionTypes; +import org.spongepowered.api.world.GeneratorTypes; +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.WorldCreationSettings; +import org.spongepowered.api.world.WorldCreationSettings.Builder; +import org.spongepowered.api.world.gen.WorldGenerator; +import org.spongepowered.api.world.gen.WorldGeneratorModifier; +import org.spongepowered.api.world.storage.WorldProperties; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Objects; public class SpongeSetupUtils extends SetupUtils { @@ -148,9 +147,9 @@ public class SpongeSetupUtils extends SetupUtils { WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) .name(object.world) .loadsOnStartup(true) - .keepsSpawnLoaded(false) + .keepsSpawnLoaded(true) .dimension(DimensionTypes.OVERWORLD) - .generator(GeneratorTypes.FLAT) + .generator(GeneratorTypes.OVERWORLD) .usesMapFeatures(false) .enabled(true) .generatorModifiers(wgm) @@ -162,7 +161,7 @@ public class SpongeSetupUtils extends SetupUtils { WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) .name(object.world) .loadsOnStartup(true) - .keepsSpawnLoaded(false) + .keepsSpawnLoaded(true) .dimension(DimensionTypes.OVERWORLD) .generator(GeneratorTypes.OVERWORLD) .usesMapFeatures(true) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java index 5e0cb347a..8ef386fc1 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java @@ -10,7 +10,7 @@ public class SpongeTitleManager extends AbstractTitle { @Override public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) { - final Title title = Title.builder().title(Text.of(head)).subtitle(Text.of(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build(); + final Title title = Title.builder().title(SpongeUtil.getText(head)).subtitle(SpongeUtil.getText(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build(); ((SpongePlayer) player).player.sendTitle(title); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 8f21465df..e06b7a742 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -3,17 +3,13 @@ package com.plotsquared.sponge.util; import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3i; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.schematic.PlotItem; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.ReflectionUtils; -import com.intellectualcrafters.plot.util.StringComparison; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.intellectualcrafters.plot.util.WorldUtil; +import com.intellectualcrafters.plot.util.*; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; import net.minecraft.block.Block; @@ -32,6 +28,7 @@ import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.translation.Translatable; import org.spongepowered.api.text.translation.Translation; import org.spongepowered.api.world.World; @@ -41,11 +38,7 @@ import org.spongepowered.api.world.extent.Extent; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; +import java.util.*; public class SpongeUtil extends WorldUtil { @@ -105,6 +98,10 @@ public class SpongeUtil extends WorldUtil { return (BiomeType) BiomeGenBase.getBiome(index); } + public static Text getText(String m) { + return TextSerializers.LEGACY_FORMATTING_CODE.deserialize(C.color(m)); + } + public static Translation getTranslation(final String m) { return new Translatable() { @Override @@ -348,8 +345,6 @@ public class SpongeUtil extends WorldUtil { @Override public Location getSpawn(final String world) { - final World worldObj = SpongeUtil.getWorld(world); - worldObj.getSpawnLocation(); final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation()); result.setY(getHighestBlock(world, result.getX(), result.getZ())); return result; @@ -419,7 +414,7 @@ public class SpongeUtil extends WorldUtil { final Sign sign = (Sign) tile; final List text = new ArrayList<>(4); for (int i = 0; i < 4; i++) { - text.add(Text.of(lines[i])); + text.add(SpongeUtil.getText(lines[i])); } sign.offer(Keys.SIGN_LINES, text); } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastChunk.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastChunk.java index 4fc514d20..a7652c4d2 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastChunk.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastChunk.java @@ -1,5 +1,245 @@ package com.plotsquared.sponge.util.block; -public class FastChunk { - +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlotChunk; +import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.plotsquared.sponge.util.SpongeUtil; +import org.spongepowered.api.world.Chunk; + +import java.util.Arrays; + +public class FastChunk extends PlotChunk { + + public char[][] ids; + public short[] count; + public short[] air; + public short[] relight; + public int[][] biomes; + public Chunk chunk; + public FastChunk(final ChunkWrapper chunk) { + super(chunk); + ids = new char[16][]; + count = new short[16]; + air = new short[16]; + relight = new short[16]; + } + + @Override + public Chunk getChunkAbs() { + ChunkWrapper loc = getChunkWrapper(); + return SpongeUtil.getWorld(loc.world).getChunk(loc.x, 0, loc.z).get(); + } + + @Override + public Chunk getChunk() { + if (chunk == null) { + final ChunkWrapper cl = getChunkWrapper(); + chunk = SpongeUtil.getWorld(cl.world).getChunk(cl.x, 0, cl.z).get(); + } + return chunk; + } + + @Override + public void setChunkWrapper(final ChunkWrapper loc) { + super.setChunkWrapper(loc); + chunk = null; + } + + /** + * Get the number of block changes in a specified section + * @param i + * @return + */ + public int getCount(final int i) { + return count[i]; + } + + public int getAir(final int i) { + return air[i]; + } + + public void setCount(int i, short value) { + count[i] = value; + } + + /** + * Get the number of block changes in a specified section + * @param i + * @return + */ + public int getRelight(final int i) { + return relight[i]; + } + + public int getTotalCount() { + int total = 0; + for (int i = 0; i < 16; i++) { + total += count[i]; + } + return total; + } + + public int getTotalRelight() { + if (getTotalCount() == 0) { + Arrays.fill(count, (short) 1); + Arrays.fill(relight, Short.MAX_VALUE); + return Short.MAX_VALUE; + } + int total = 0; + for (int i = 0; i < 16; i++) { + total += relight[i]; + } + return total; + } + + /** + * Get the raw data for a section + * @param i + * @return + */ + public char[] getIdArray(final int i) { + return ids[i]; + } + + @Override + public void setBlock(final int x, final int y, final int z, final int id, byte data) { + final int i = MainUtil.CACHE_I[y][x][z]; + final int j = MainUtil.CACHE_J[y][x][z]; + char[] vs = ids[i]; + if (vs == null) { + vs = ids[i] = new char[4096]; + count[i]++; + } else if (vs[j] == 0) { + count[i]++; + } + switch (id) { + case 0: + air[i]++; + vs[j] = (char) 1; + return; + case 10: + case 11: + case 39: + case 40: + case 51: + case 74: + case 89: + case 122: + case 124: + case 138: + case 169: + relight[i]++; + case 2: + case 4: + case 13: + case 14: + case 15: + case 20: + case 21: + case 22: + case 30: + case 32: + case 37: + case 41: + case 42: + case 45: + case 46: + case 47: + case 48: + case 49: + case 55: + case 56: + case 57: + case 58: + case 60: + case 7: + case 8: + case 9: + case 73: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 85: + case 87: + case 88: + case 101: + case 102: + case 103: + case 110: + case 112: + case 113: + case 121: + case 129: + case 133: + case 165: + case 166: + case 170: + case 172: + case 173: + case 174: + case 181: + case 182: + case 188: + case 189: + case 190: + case 191: + case 192: + vs[j] = (char) (id << 4); + return; + case 130: + case 76: + case 62: + relight[i]++; + case 54: + case 146: + case 61: + case 65: + case 68: + case 50: + if (data < 2) { + data = 2; + } + default: + vs[j] = (char) ((id << 4) + data); + return; + } + } + + @Override + public PlotChunk clone() { + FastChunk toReturn = new FastChunk(getChunkWrapper()); + toReturn.air = air.clone(); + toReturn.count = count.clone(); + toReturn.relight = relight.clone(); + toReturn.ids = new char[ids.length][]; + for (int i = 0; i < ids.length; i++) { + char[] matrix = ids[i]; + if (matrix != null) { + toReturn.ids[i] = new char[matrix.length]; + System.arraycopy(matrix, 0, toReturn.ids[i], 0, matrix.length); + } + } + return toReturn; + } + + @Override + public PlotChunk shallowClone() { + FastChunk toReturn = new FastChunk(getChunkWrapper()); + toReturn.air = air; + toReturn.count = count; + toReturn.relight = relight; + toReturn.ids = ids; + return toReturn; + } + + @Override + public void setBiome(int x, int z, int biome) { + if (biomes == null) { + biomes = new int[16][16]; + } + biomes[x][z] = biome; + } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastQueue.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastQueue.java index c3fe50cea..86541c0f7 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastQueue.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/FastQueue.java @@ -1,5 +1,319 @@ package com.plotsquared.sponge.util.block; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlotChunk; +import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.intellectualcrafters.plot.util.TaskManager; +import com.plotsquared.sponge.util.SpongeUtil; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ClassInheritanceMultiMap; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import org.spongepowered.api.world.Chunk; +import org.spongepowered.api.world.World; + +import java.util.*; +import java.util.Map.Entry; + public class FastQueue extends SlowQueue { - // TODO FIXME + + public HashMap toUpdate = new HashMap<>(); + public final SendChunk chunkSender; + + public FastQueue() throws NoSuchMethodException, RuntimeException { + TaskManager.runTaskRepeat(new Runnable() { + @Override + public void run() { + if (toUpdate.isEmpty()) { + return; + } + int count = 0; + final ArrayList chunks = new ArrayList(); + final Iterator> i = toUpdate.entrySet().iterator(); + while (i.hasNext() && (count < 128)) { + chunks.add(i.next().getValue()); + i.remove(); + count++; + } + if (count == 0) { + return; + } + update(chunks); + } + }, 1); + chunkSender = new SendChunk(); + MainUtil.initCache(); + } + + public void update(final Collection chunks) { + if (chunks.isEmpty()) { + return; + } + if (!MainUtil.canSendChunk) { + for (final Chunk chunk : chunks) { + chunk.unloadChunk(); + chunk.loadChunk(false); + } + return; + } + try { + chunkSender.sendChunk(chunks); + } catch (final Throwable e) { + e.printStackTrace(); + MainUtil.canSendChunk = false; + } + } + + /** + * This should be overridden by any specialized queues + * @param pc + */ + @Override + public void execute(PlotChunk pc) { + FastChunk fs = (FastChunk) pc; + Chunk spongeChunk = pc.getChunk(); + net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeChunk.getWorld(); + ChunkWrapper wrapper = pc.getChunkWrapper(); + if (!toUpdate.containsKey(wrapper)) { + toUpdate.put(wrapper, spongeChunk); + } + spongeChunk.loadChunk(true); + try { + final boolean flag = !nmsWorld.provider.getHasNoSky(); + // Sections + net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk; + ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray(); + Map tiles = nmsChunk.getTileEntityMap(); + ClassInheritanceMultiMap[] entities = nmsChunk.getEntityLists(); + // Trim tiles + Set> entryset = tiles.entrySet(); + Iterator> iter = entryset.iterator(); + while (iter.hasNext()) { + Entry tile = iter.next(); + BlockPos pos = tile.getKey(); + final int lx = pos.getX() & 15; + final int ly = pos.getY(); + final int lz = pos.getZ() & 15; + final int j = MainUtil.CACHE_I[ly][lx][lz]; + final int k = MainUtil.CACHE_J[ly][lx][lz]; + final char[] array = fs.getIdArray(j); + if (array == null) { + continue; + } + if (array[k] != 0) { + iter.remove(); + } + } + // Trim entities + for (int i = 0; i < 16; i++) { + if ((entities[i] != null) && (fs.getCount(i) >= 4096)) { + entities[i].clear(); + } + } + // Efficiently merge sections + for (int j = 0; j < sections.length; j++) { + if (fs.getCount(j) == 0) { + continue; + } + final char[] newArray = fs.getIdArray(j); + if (newArray == null) { + continue; + } + ExtendedBlockStorage section = sections[j]; + if ((section == null) || (fs.getCount(j) >= 4096)) { + section = new ExtendedBlockStorage(j << 4, flag); + section.setData(newArray); + sections[j] = section; + continue; + } + final char[] currentArray = section.getData(); + boolean fill = true; + for (int k = 0; k < newArray.length; k++) { + final char n = newArray[k]; + switch (n) { + case 0: + fill = false; + continue; + case 1: + fill = false; + currentArray[k] = 0; + continue; + default: + currentArray[k] = n; + continue; + } + } + if (fill) { + fs.setCount(j, Short.MAX_VALUE); + } + } + // Clear + } catch (Throwable e) { + e.printStackTrace(); + } + int[][] biomes = fs.biomes; + if (biomes != null) { + for (int x = 0; x < 16; x++) { + int[] array = biomes[x]; + if (array == null) { + continue; + } + for (int z = 0; z < 16; z++) { + int biome = array[z]; + if (biome == 0) { + continue; + } + spongeChunk.setBiome(x, z, SpongeUtil.getBiome(biome)); + } + } + } + } + + /** + * This should be overridden by any specialized queues + * @param wrap + */ + @Override + public PlotChunk getChunk(ChunkWrapper wrap) { + return new FastChunk(wrap); + } + + /** + * This should be overridden by any specialized queues + * @param pc + */ + @Override + public boolean fixLighting(PlotChunk pc, boolean fixAll) { + try { + FastChunk bc = (FastChunk) pc; + final Chunk spongeChunk = bc.getChunk(); + final net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk; + if (!spongeChunk.isLoaded()) { + if (!spongeChunk.loadChunk(false)) { + return false; + } + } else { + spongeChunk.unloadChunk(); + spongeChunk.loadChunk(false); + } + // TODO load adjaced chunks + nmsChunk.generateSkylightMap(); + if ((bc.getTotalRelight() == 0 && !fixAll)) { + return true; + } + ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray(); + net.minecraft.world.World nmsWorld = nmsChunk.getWorld(); + + final int X = pc.getX() << 4; + final int Z = pc.getZ() << 4; + + + for (int j = 0; j < sections.length; j++) { + ExtendedBlockStorage section = sections[j]; + if (section == null) { + continue; + } + if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) { + continue; + } + final char[] array = section.getData(); + int l = PseudoRandom.random.random(2); + for (int k = 0; k < array.length; k++) { + final int i = array[k]; + if (i < 16) { + continue; + } + final short id = (short) (i >> 4); + switch (id) { // Lighting + default: + if (!fixAll) { + continue; + } + if ((k & 1) == l) { + l = 1 - l; + continue; + } + case 10: + case 11: + case 39: + case 40: + case 50: + case 51: + case 62: + case 74: + case 76: + case 89: + case 122: + case 124: + case 130: + case 138: + case 169: + final int x = MainUtil.x_loc[j][k]; + final int y = MainUtil.y_loc[j][k]; + final int z = MainUtil.z_loc[j][k]; + if (isSurrounded(sections, x, y, z)) { + continue; + } + BlockPos pos = new BlockPos(X + x, y, Z + z); + nmsWorld.checkLight(pos); + } + } + } + return true; + } catch (final Throwable e) { + e.printStackTrace(); + } + return false; + } + + public boolean isSurrounded(ExtendedBlockStorage[] sections, int x, int y, int z) { + return isSolid(getId(sections, x, y + 1, z)) + && isSolid(getId(sections, x + 1, y - 1, z)) + && isSolid(getId(sections, x - 1, y, z)) + && isSolid(getId(sections, x, y, z + 1)) + && isSolid(getId(sections, x, y, z - 1)); + } + + public boolean isSolid(int i) { + return i != 0 && Block.getBlockById(i).isOpaqueCube(); + } + + public int getId(ExtendedBlockStorage[] sections, int x, int y, int z) { + if (x < 0 || x > 15 || z < 0 || z > 15) { + return 1; + } + if (y < 0 || y > 255) { + return 1; + } + int i = MainUtil.CACHE_I[y][x][z]; + ExtendedBlockStorage section = sections[i]; + if (section == null) { + return 0; + } + char[] array = section.getData(); + int j = MainUtil.CACHE_J[y][x][z]; + return array[j] >> 4; + } + + /** + * This should be overridden by any specialized queues + * @param world + * @param locs + */ + @Override + public void sendChunk(String world, Collection locs) { + World spongeWorld = SpongeUtil.getWorld(world); + for (ChunkLoc loc : locs) { + ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z); + if (!toUpdate.containsKey(wrapper)) { + toUpdate.put(wrapper, spongeWorld.getChunk(loc.x, 0, loc.z).get()); + } + } + } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SendChunk.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SendChunk.java new file mode 100644 index 000000000..110d0aadc --- /dev/null +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SendChunk.java @@ -0,0 +1,105 @@ +package com.plotsquared.sponge.util.block; + +import com.flowpowered.math.vector.Vector3i; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.sponge.object.SpongePlayer; +import com.plotsquared.sponge.util.SpongeUtil; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.network.play.server.S21PacketChunkData; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.world.Chunk; +import org.spongepowered.api.world.World; + +import java.util.*; +import java.util.Map.Entry; + +/** + * An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS) + * + + */ +public class SendChunk { + + public void sendChunk(final Collection input) { + final HashSet chunks = new HashSet(input); + final HashMap> map = new HashMap<>(); + for (final Chunk chunk : chunks) { + final String world = chunk.getWorld().getName(); + ArrayList list = map.get(world); + if (list == null) { + list = new ArrayList<>(); + map.put(world, list); + } + list.add(chunk); + ((net.minecraft.world.chunk.Chunk) chunk).generateSkylightMap(); + } + for (Entry entry : UUIDHandler.getPlayers().entrySet()) { + PlotPlayer pp = entry.getValue(); + final Plot plot = pp.getCurrentPlot(); + Location loc = null; + String world; + if (plot != null) { + world = plot.getArea().worldname; + } else { + loc = pp.getLocation(); + world = loc.getWorld(); + } + final ArrayList list = map.get(world); + if (list == null) { + continue; + } + if (loc == null) { + loc = pp.getLocation(); + } + final int cx = loc.getX() >> 4; + final int cz = loc.getZ() >> 4; + final Player player = ((SpongePlayer) pp).player; + int view = player.getViewDistance(); + EntityPlayer nmsPlayer = (EntityPlayer) player; + if (!(nmsPlayer instanceof EntityPlayerMP)) { + PS.debug("Cannot send chunk change to: " + pp.getName()); + return; + } + EntityPlayerMP nmsPlayerMP = (EntityPlayerMP) nmsPlayer; + for (final Chunk chunk : list) { + Vector3i min = chunk.getBlockMin(); + final int dx = Math.abs(cx - (min.getX() >> 4)); + final int dz = Math.abs(cz - (min.getZ() >> 4)); + if ((dx > view) || (dz > view)) { + continue; + } + chunks.remove(chunk); + NetHandlerPlayServer con = nmsPlayerMP.playerNetServerHandler; + net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) chunk; + S21PacketChunkData packet = new S21PacketChunkData(nmsChunk, true, 65535); + con.sendPacket(packet); + } + } + for (final Chunk chunk : chunks) { + TaskManager.runTask(new Runnable() { + @Override + public void run() { + chunk.unloadChunk(); + } + }); + } + } + + public void sendChunk(final String worldname, final List locs) { + World spongeWorld = SpongeUtil.getWorld(worldname); + final ArrayList chunks = new ArrayList<>(); + for (final ChunkLoc loc : locs) { + chunks.add(spongeWorld.getChunk(loc.x, 0, loc.z).get()); + } + sendChunk(chunks); + } +}