Finished several core parts of the sponge port

Mass block changes / chunk packet sending
AsyncWorldEdit (buggy)
Fixed world ground cover layers being generated
Fixed tab completion
Fixed plot title color
Fixed worlds unloading when no players are present
Fixed falling blocks not falling where they should
Fixed console color
Fixed chunk regeneration on full plot worlds
Other stuff
This commit is contained in:
Jesse Boyd 2016-02-25 20:13:07 +11:00
parent d3465b7bde
commit efae2c2e63
23 changed files with 1051 additions and 493 deletions

View File

@ -1,16 +1,17 @@
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import java.util.ArrayList; import com.intellectualcrafters.plot.PS;
import java.util.Arrays; import com.intellectualcrafters.plot.config.C;
import java.util.HashSet; import com.intellectualcrafters.plot.config.Settings;
import java.util.Iterator; import com.intellectualcrafters.plot.flag.Flag;
import java.util.List; import com.intellectualcrafters.plot.flag.FlagManager;
import java.util.Map.Entry; import com.intellectualcrafters.plot.object.*;
import java.util.Objects; import com.intellectualcrafters.plot.util.*;
import java.util.Set; import com.plotsquared.bukkit.BukkitMain;
import java.util.UUID; import com.plotsquared.bukkit.object.BukkitLazyBlock;
import java.util.regex.Pattern; import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.listener.PlayerBlockEventType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,64 +20,17 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Animals; import org.bukkit.entity.*;
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.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.*;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.*;
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.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.*;
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.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.StructureGrowEvent;
@ -89,34 +43,9 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.PS; import java.util.*;
import com.intellectualcrafters.plot.config.C; import java.util.Map.Entry;
import com.intellectualcrafters.plot.config.Settings; import java.util.regex.Pattern;
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;
/** /**
* Player Events involving plots * 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()))) { if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Cancel teleport // Cancel teleport
TaskManager.TELEPORT_QUEUE.remove(pp.getName()); TaskManager.TELEPORT_QUEUE.remove(pp.getName());
// Set last location // Set last location
Location loc = BukkitUtil.getLocation(to); Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc); pp.setMeta("location", loc);
@ -867,6 +794,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; return;
} }
} }
return;
} }
final Plot plot = area.getOwnedPlot(loc); final Plot plot = area.getOwnedPlot(loc);
if (plot == null) { if (plot == null) {
@ -982,6 +910,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
blocks.remove(i); blocks.remove(i);
} }
} }
return;
} else { } else {
Plot origin = area.getOwnedPlot(loc); Plot origin = area.getOwnedPlot(loc);
if (origin == null) { if (origin == null) {
@ -1104,11 +1033,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (eventType != null && !player.isSneaking()) { if (eventType != null && !player.isSneaking()) {
break; break;
} }
Material type = hand == null ? null : hand.getType(); Material type = (hand == null) ? null : hand.getType();
int id = type == null ? 0 : type.getId(); int id = (type == null) ? 0 : type.getId();
if (id == 0) { if (id == 0) {
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
lb = new BukkitLazyBlock(id, block); lb = new BukkitLazyBlock(0, block);
break; break;
} else if (id < 198) { } else if (id < 198) {
loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());

View File

@ -1,7 +1,5 @@
package com.plotsquared.bukkit.util; package com.plotsquared.bukkit.util;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -19,13 +17,11 @@ import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry; 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) * 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(); final Object c = methodGetHandleChunk.of(chunk).call();
chunks.remove(chunk); chunks.remove(chunk);
final Object con = connection.of(entity).get(); 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); final Object packet = MapChunk.create(c, true, 65535);
send.of(con).call(packet); 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<Object>) 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<ChunkLoc> locs) { public void sendChunk(final String worldname, final List<ChunkLoc> locs) {

View File

@ -22,7 +22,7 @@ public class GenChunk extends PlotChunk<Chunk> {
public GenChunk(Chunk chunk, ChunkWrapper wrap) { public GenChunk(Chunk chunk, ChunkWrapper wrap) {
super(wrap); super(wrap);
if ((this.chunk = chunk) == null) { if ((this.chunk = chunk) == null && wrap != null) {
World world = BukkitUtil.getWorld(wrap.world); World world = BukkitUtil.getWorld(wrap.world);
if (world != null) { if (world != null) {
chunk = world.getChunkAt(wrap.x, wrap.z); chunk = world.getChunkAt(wrap.x, wrap.z);

View File

@ -1,10 +1,5 @@
package com.intellectualcrafters.plot.commands; 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.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; 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.AugmentedUtils;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.util.*;
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.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Set;
@CommandDeclaration( @CommandDeclaration(
command = "area", command = "area",
permission = "plots.area", permission = "plots.area",
@ -166,6 +150,7 @@ public class Area extends SubCommand {
PlotArea area = areas.iterator().next(); PlotArea area = areas.iterator().next();
pa.TYPE = area.TYPE; pa.TYPE = area.TYPE;
} }
pa.SIZE = (short) (pa.PLOT_WIDTH + pa.ROAD_WIDTH);
for (int i = 2; i < args.length; i++) { for (int i = 2; i < args.length; i++) {
String[] pair = args[i].split("="); String[] pair = args[i].split("=");
if (pair.length != 2) { if (pair.length != 2) {

View File

@ -31,9 +31,6 @@ public class Middle extends SubCommand {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return sendMessage(player, C.PLOT_UNOWNED); return sendMessage(player, C.PLOT_UNOWNED);
} }
if (!player.hasPermission("plots.middle")) {
return sendMessage(player, C.NO_PERMISSION, "plots.middle");
}
player.teleport(plot.getCenter()); player.teleport(plot.getCenter());
return true; return true;
} }

View File

@ -21,7 +21,9 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;

View File

@ -5,10 +5,10 @@ import com.intellectualcrafters.plot.util.ChatManager;
public class PlotMessage { public class PlotMessage {
private final Object builder; private Object builder;
public PlotMessage() { public PlotMessage() {
builder = ChatManager.manager.builder(); reset(ChatManager.manager);
} }
public <T> T $(final ChatManager<T> manager) { public <T> T $(final ChatManager<T> manager) {
@ -20,6 +20,10 @@ public class PlotMessage {
text(text); text(text);
} }
public <T> T reset(ChatManager<T> manager) {
return (T) (builder = manager.builder());
}
public PlotMessage text(final String text) { public PlotMessage text(final String text) {
ChatManager.manager.text(this, text); ChatManager.manager.text(this, text);
return this; return this;

View File

@ -53,7 +53,6 @@ public class ReflectionUtils {
} }
public static Method findMethod(Class<?> clazz, boolean isStatic, Class<?> returnType, Class... types) { 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()) { loop: for (Method method : clazz.getMethods()) {
Class<?> result = method.getReturnType(); Class<?> result = method.getReturnType();
Class<?>[] param = method.getParameterTypes(); Class<?>[] param = method.getParameterTypes();

View File

@ -1,30 +1,5 @@
package com.plotsquared.sponge; 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.google.inject.Inject;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain; 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.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.*;
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.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.generator.SpongePlotGenerator; import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.listener.ChunkProcessor; import com.plotsquared.sponge.listener.ChunkProcessor;
import com.plotsquared.sponge.listener.MainListener; import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.listener.WorldEvents; import com.plotsquared.sponge.listener.WorldEvents;
import com.plotsquared.sponge.util.KillRoadMobs; import com.plotsquared.sponge.util.*;
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.SpongeSetupUtils; 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.FastQueue;
import com.plotsquared.sponge.util.block.SlowQueue; import com.plotsquared.sponge.util.block.SlowQueue;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler; 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 * Created by robin on 01/11/2014
@ -173,7 +142,7 @@ public class SpongeMain implements IPlotMain {
logger.info(message); logger.info(message);
return; return;
} }
server.getConsole().sendMessage(Text.of(message)); server.getConsole().sendMessage(SpongeUtil.getText(message));
} }
@Override @Override
@ -415,6 +384,7 @@ public class SpongeMain implements IPlotMain {
public PlotQueue initPlotQueue() { public PlotQueue initPlotQueue() {
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
try { try {
MainUtil.canSendChunk = true;
return new FastQueue(); return new FastQueue();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -1,13 +1,5 @@
package com.plotsquared.sponge.generator; 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.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.generator.AugmentedUtils; import com.intellectualcrafters.plot.generator.AugmentedUtils;
import com.intellectualcrafters.plot.object.LazyResult; 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;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil; 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 { public class SpongeAugmentedGenerator implements GenerationPopulator {
@ -59,7 +58,7 @@ public class SpongeAugmentedGenerator implements GenerationPopulator {
} }
@Override @Override
public void setBiome(int x, int z, int biome) { 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 @Override
public PlotChunk clone() { public PlotChunk clone() {
@ -69,6 +68,10 @@ public class SpongeAugmentedGenerator implements GenerationPopulator {
public PlotChunk shallowClone() { public PlotChunk shallowClone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
} }
@Override
public void addToQueue() {}
@Override
public void flush(boolean fixLighting) {}
}; };
} }
}); });

View File

@ -1,8 +1,14 @@
package com.plotsquared.sponge.generator; package com.plotsquared.sponge.generator;
import java.util.ArrayList; import com.flowpowered.math.vector.Vector2i;
import java.util.List; 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.data.DataContainer;
import org.spongepowered.api.world.WorldCreationSettings; import org.spongepowered.api.world.WorldCreationSettings;
import org.spongepowered.api.world.biome.BiomeGenerationSettings; 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.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import com.flowpowered.math.vector.Vector2i; import java.util.ArrayList;
import com.intellectualcrafters.plot.PS; import java.util.List;
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;
public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper<WorldGeneratorModifier> { public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper<WorldGeneratorModifier> {
@ -93,6 +92,7 @@ public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWra
BiomeGenerationSettings biomeSettings = wg.getBiomeSettings(type); BiomeGenerationSettings biomeSettings = wg.getBiomeSettings(type);
biomeSettings.getGenerationPopulators().clear(); biomeSettings.getGenerationPopulators().clear();
biomeSettings.getPopulators().clear(); biomeSettings.getPopulators().clear();
biomeSettings.getGroundCoverLayers().clear();
} }
wg.getGenerationPopulators().clear(); wg.getGenerationPopulators().clear();
wg.getPopulators().clear(); wg.getPopulators().clear();

View File

@ -4,24 +4,10 @@ import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.*;
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.plotsquared.listener.PlotListener; import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; 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.data.Transaction;
import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes; 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.Explosive;
import org.spongepowered.api.entity.explosive.PrimedTNT; import org.spongepowered.api.entity.explosive.PrimedTNT;
import org.spongepowered.api.entity.living.Ambient; 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.network.ClientConnectionEvent;
import org.spongepowered.api.event.world.ExplosionEvent; import org.spongepowered.api.event.world.ExplosionEvent;
import org.spongepowered.api.event.world.ExplosionEvent.Detonate; import org.spongepowered.api.event.world.ExplosionEvent.Detonate;
import org.spongepowered.api.profile.GameProfile;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry; 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.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -99,14 +77,14 @@ public class MainListener {
public void onCommand(final SendCommandEvent event) { public void onCommand(final SendCommandEvent event) {
switch (event.getCommand().toLowerCase()) { switch (event.getCommand().toLowerCase()) {
case "plotme": { case "plotme": {
Player source = SpongeUtil.<Player> getCause(event.getCause(), Player.class); Player source = SpongeUtil.getCause(event.getCause(), Player.class);
if (source == null) { if (source == null) {
return; return;
} }
if (Settings.USE_PLOTME_ALIAS) { if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else { } else {
source.sendMessage(Text.of(C.NOT_USING_PLOTME.s())); source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME.s()));
} }
event.setCancelled(true); event.setCancelled(true);
} }
@ -164,7 +142,7 @@ public class MainListener {
} else { } else {
prefix = message; prefix = message;
} }
components.add(Text.of(part)); components.add(SpongeUtil.getText(part));
} }
((SpongePlayer) user).player.sendMessage(Text.join(components)); ((SpongePlayer) user).player.sendMessage(Text.join(components));
} }
@ -314,7 +292,7 @@ public class MainListener {
public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception { public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception {
final AtomicBoolean cancelled = new AtomicBoolean(false); final AtomicBoolean cancelled = new AtomicBoolean(false);
SpongeUtil.printCause("physics", event.getCause()); // SpongeUtil.printCause("physics", event.getCause());
// PlotArea area = plotloc.getPlotArea(); // PlotArea area = plotloc.getPlotArea();
// event.filterDirections(new Predicate<Direction>() { // event.filterDirections(new Predicate<Direction>() {
// //
@ -457,7 +435,6 @@ public class MainListener {
return; return;
} }
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() { event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
@Override @Override
public boolean test(org.spongepowered.api.world.Location<World> loc) { public boolean test(org.spongepowered.api.world.Location<World> loc) {
if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) { if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) {
@ -487,7 +464,7 @@ public class MainListener {
public void onBlockBreak(final ChangeBlockEvent.Break event) { public void onBlockBreak(final ChangeBlockEvent.Break event) {
Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class); Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
if (player == null) { if (player == null) {
event.setCancelled(true); // SpongeUtil.printCause("break", event.getCause());
return; return;
} }
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
@ -571,7 +548,7 @@ public class MainListener {
public void onBlockPlace(final ChangeBlockEvent.Place event) { public void onBlockPlace(final ChangeBlockEvent.Place event) {
Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class); Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
if (player == null) { if (player == null) {
event.setCancelled(true); // SpongeUtil.printCause("place", event.getCause());
return; return;
} }
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
@ -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 @Listener
public void onJoin(final ClientConnectionEvent.Join event) { public void onJoin(final ClientConnectionEvent.Join event) {
final Player player = event.getTargetEntity(); final Player player = event.getTargetEntity();
SpongeUtil.removePlayer(player.getName()); SpongeUtil.getPlayer(player).unregister();
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
final String username = pp.getName(); // Now
final StringWrapper name = new StringWrapper(username); String name = pp.getName();
StringWrapper sw = new StringWrapper(name);
final UUID uuid = pp.getUUID(); final UUID uuid = pp.getUUID();
UUIDHandler.add(name, uuid); UUIDHandler.add(sw, uuid);
ExpireManager.dates.put(uuid, System.currentTimeMillis());
if ((PS.get().update != null) && pp.hasPermission("plots.admin")) { Location loc = pp.getLocation();
TaskManager.runTaskLater(new Runnable() { PlotArea area = loc.getPlotArea();
@Override final Plot plot;
public void run() { 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"); MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
} }
}, 20); if (Settings.TELEPORT_ON_LOGIN && plot != null) {
} TaskManager.runTask(new Runnable() {
final Location loc = SpongeUtil.getLocation(player); @Override
final Plot plot = loc.getPlot(); public void run() {
if (plot == null) { plot.teleportPlayer(pp);
return; }
} });
if (Settings.TELEPORT_ON_LOGIN) { MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
pp.teleport(loc); }
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); }
} }, 20);
PlotListener.plotEntry(pp, plot);
} }
@Listener @Listener
@ -698,61 +687,54 @@ public class MainListener {
@Listener @Listener
public void onMove(final DisplaceEntityEvent.TargetPlayer event) { public void onMove(final DisplaceEntityEvent.TargetPlayer event) {
final org.spongepowered.api.world.Location<World> from = event.getFromTransform().getLocation(); org.spongepowered.api.world.Location<World> from = event.getFromTransform().getLocation();
org.spongepowered.api.world.Location<World> to = event.getToTransform().getLocation(); org.spongepowered.api.world.Location<World> to = event.getToTransform().getLocation();
int x2; int x2;
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
final Player player = event.getTargetEntity(); final Player player = event.getTargetEntity();
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
final Extent extent = to.getExtent(); // Cancel teleport
pp.setMeta("location", SpongeUtil.getLocation(player)); TaskManager.TELEPORT_QUEUE.remove(pp.getName());
final World world = (World) extent; // Set last location
final String worldname = ((World) extent).getName(); Location loc = SpongeUtil.getLocation(to);
final PlotArea plotworld = PS.get().getPlotAreaByString(worldname); pp.setMeta("location", loc);
if (plotworld == null) { PlotArea area = loc.getPlotArea();
if (area == null) {
pp.deleteMeta("lastplot");
return; return;
} }
final PlotManager plotManager = plotworld.getPlotManager(); Plot now = area.getPlotAbs(loc);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ())); final Plot lastPlot = pp.getMeta("lastplot");
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (now == null) {
if (id == null) { if (lastPlot != null && !PlotListener.plotExit(pp, lastPlot)) {
if (lastPlot == null) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) { if (lastPlot.equals(SpongeUtil.getLocation(from).getPlot())) {
event.setCancelled(true); player.setLocation(from);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); player.setLocation(player.getWorld().getSpawnLocation());
} }
event.setCancelled(true);
return; 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; 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) { if (x2 > border) {
final Vector3d pos = to.getPosition(); to.sub(x2 - border + 4, 0, 0);
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); player.setLocation(to);
event.setToTransform(new Transform<>(to));
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
return;
} else if (x2 < -border) { } else if (x2 < -border) {
final Vector3d pos = to.getPosition(); to.add(border - x2 + 4, 0, 0);
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); player.setLocation(to);
event.setToTransform(new Transform<>(to));
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
return;
} }
return; return;
} }
@ -760,54 +742,45 @@ public class MainListener {
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) { if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
final Player player = event.getTargetEntity(); final Player player = event.getTargetEntity();
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
final Extent extent = to.getExtent(); // Cancel teleport
pp.setMeta("location", SpongeUtil.getLocation(player)); TaskManager.TELEPORT_QUEUE.remove(pp.getName());
final World world = (World) extent; // Set last location
final String worldname = ((World) extent).getName(); Location loc = SpongeUtil.getLocation(to);
final PlotArea plotworld = PS.get().getPlotAreaByString(worldname); pp.setMeta("location", loc);
if (plotworld == null) { PlotArea area = loc.getPlotArea();
if (area == null) {
pp.deleteMeta("lastplot");
return; return;
} }
final PlotManager plotManager = plotworld.getPlotManager(); Plot now = area.getPlotAbs(loc);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
final Plot lastPlot = pp.getMeta("lastplot"); final Plot lastPlot = pp.getMeta("lastplot");
if (id == null) { if (now == null) {
if (lastPlot == null) { if (lastPlot != null && !PlotListener.plotExit(pp, lastPlot)) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) { if (lastPlot.equals(SpongeUtil.getLocation(from).getPlot())) {
event.setCancelled(true); player.setLocation(from);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); player.setLocation(player.getWorld().getSpawnLocation());
} }
event.setCancelled(true);
return; 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; 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) { if (z2 > border) {
final Vector3d pos = to.getPosition(); to.add(0, 0, z2 - border - 4);
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); player.setLocation(to);
event.setToTransform(new Transform<>(to));
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
} else if (z2 < -border) { } else if (z2 < -border) {
final Vector3d pos = to.getPosition(); to.add(0, 0, border - z2 + 4);
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); player.setLocation(to);
event.setToTransform(new Transform<>(to));
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
} }
} }

View File

@ -1,22 +1,5 @@
package com.plotsquared.sponge.object; 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.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.Settings; 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.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.util.SpongeUtil; 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 { public class SpongePlayer extends PlotPlayer {
@ -278,7 +276,7 @@ public class SpongePlayer extends PlotPlayer {
@Override @Override
public void kick(final String message) { public void kick(final String message) {
player.kick(Text.of(message)); player.kick(SpongeUtil.getText(message));
} }
@Override @Override

View File

@ -1,14 +1,18 @@
package com.plotsquared.sponge.util; 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.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotMessage;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChatManager;
import com.plotsquared.sponge.object.SpongePlayer; 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<Text.Builder> { public class SpongeChatManager extends ChatManager<Text.Builder> {
@ -19,7 +23,94 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
@Override @Override
public void color(final PlotMessage m, final String color) { 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<Text> 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 @Override
@ -33,18 +124,17 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
builder.append(tooltip.$(this).build()); builder.append(tooltip.$(this).build());
lb = true; lb = true;
} }
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder(); apply(m, getChild(m).onHover(TextActions.showText(builder.toText())));
m.$(this).onHover(TextActions.showText(builder.toText()));
} }
@Override @Override
public void command(final PlotMessage m, final String command) { public void command(final PlotMessage m, final String command) {
m.$(this).onClick(TextActions.runCommand(command)); apply(m, getChild(m).onClick(TextActions.runCommand(command)));
} }
@Override @Override
public void text(final PlotMessage m, final String text) { public void text(final PlotMessage m, final String text) {
m.$(this).append(Text.of(text)); m.$(this).append(SpongeUtil.getText(text));
} }
@Override @Override
@ -58,7 +148,6 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
@Override @Override
public void suggest(final PlotMessage m, final String command) { public void suggest(final PlotMessage m, final String command) {
m.$(this).onClick(TextActions.suggestCommand(command)); apply(m, getChild(m).onClick(TextActions.suggestCommand(command)));
} }
} }

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ReflectionUtils; import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.IChunkProvider; 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.Chunk;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -83,19 +86,27 @@ public class SpongeChunkManager extends ChunkManager {
PS.debug("Not valid world generator for: " + world); PS.debug("Not valid world generator for: " + world);
return; return;
} }
ChunkProviderServer chunkServer = (ChunkProviderServer) provider; ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z); 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; net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
if (chunkServer.chunkExists(loc.x, loc.z)) { if (chunkServer.chunkExists(loc.x, loc.z)) {
mcChunk = chunkServer.loadChunk(loc.x, loc.z); mcChunk = chunkServer.loadChunk(loc.x, loc.z);
mcChunk.onChunkUnload(); mcChunk.onChunkUnload();
} }
// Set<Long> set = (Set<Long>) chunkProvider.getClass().getDeclaredField("droppedChunksSet").get(chunkProvider); Field fieldDroppedChunksSet;
Set<Long> set = (Set<Long>) ReflectionUtils.findField(chunkServer.getClass(), Set.class).get(chunkServer); 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<Long> set = (Set<Long>) fieldDroppedChunksSet.get(chunkServer);
set.remove(pos); set.remove(pos);
chunkServer.id2ChunkMap.remove(pos); chunkServer.id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(loc.x, loc.z); mcChunk = chunkProvider.provideChunk(loc.x, loc.z);
@ -104,7 +115,7 @@ public class SpongeChunkManager extends ChunkManager {
if (mcChunk != null) { if (mcChunk != null) {
mcChunk.onChunkLoad(); mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z); mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z);
System.out.println("WORKED?"); SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc));
} }
else { else {
PS.debug("CHUNK IS NULL!?"); PS.debug("CHUNK IS NULL!?");

View File

@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.Command;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandCallable;
@ -20,20 +21,22 @@ public class SpongeCommand implements CommandCallable {
@Override @Override
public CommandResult process(final CommandSource cmd, final String string) throws CommandException { public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
final String id = cmd.getIdentifier(); TaskManager.runTask(new Runnable() {
PlotPlayer pp; @Override
try { public void run() {
final UUID uuid = UUID.fromString(id); final String id = cmd.getIdentifier();
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); PlotPlayer pp;
pp = SpongeUtil.getPlayer(player); try {
} catch (final Exception e) { final UUID uuid = UUID.fromString(id);
pp = ConsolePlayer.getConsole(); final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
} pp = SpongeUtil.getPlayer(player);
if (MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" "))) { } catch (final Exception e) {
return CommandResult.success(); pp = ConsolePlayer.getConsole();
} else { }
return CommandResult.empty(); MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" "));
} }
});
return CommandResult.success();
} }
@Override @Override
@ -43,14 +46,14 @@ public class SpongeCommand implements CommandCallable {
} }
final PlotPlayer player = SpongeUtil.getPlayer((Player) source); final PlotPlayer player = SpongeUtil.getPlayer((Player) source);
String[] split = string.split(" "); String[] split = string.split(" ");
if (split.length < 2) { if (split.length < 1) {
return Collections.singletonList("plots"); return Collections.singletonList("plots");
} }
if (split.length > 2) { if (split.length > 1) {
return null; return Collections.emptyList();
} }
final Set<String> tabOptions = new HashSet<>(); final Set<String> tabOptions = new HashSet<>();
final String arg = split[1].toLowerCase(); final String arg = split[0].toLowerCase();
ArrayList<String> labels = new ArrayList<>(); ArrayList<String> labels = new ArrayList<>();
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) { for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
final String label = cmd.getCommand(); final String label = cmd.getCommand();
@ -72,7 +75,7 @@ public class SpongeCommand implements CommandCallable {
if (!tabOptions.isEmpty()) { if (!tabOptions.isEmpty()) {
return new ArrayList<>(tabOptions); return new ArrayList<>(tabOptions);
} }
return null; return Collections.emptyList();
} }
@Override @Override

View File

@ -119,7 +119,6 @@ public class SpongeSchematicHandler extends SchematicHandler {
int xxb = X << 4; int xxb = X << 4;
int zzb = Z << 4; int zzb = Z << 4;
if (!worldObj.getChunk(xxb, 1, zzb).isPresent() && !worldObj.loadChunk(xxb, 1, zzb, false).isPresent()) { 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; continue;
} }
int xxt = xxb + 15; int xxt = xxb + 15;

View File

@ -1,21 +1,5 @@
package com.plotsquared.sponge.util; 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.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.ConfigurationNode; 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.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.sponge.generator.SpongePlotGenerator; 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 { public class SpongeSetupUtils extends SetupUtils {
@ -148,9 +147,9 @@ public class SpongeSetupUtils extends SetupUtils {
WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class)
.name(object.world) .name(object.world)
.loadsOnStartup(true) .loadsOnStartup(true)
.keepsSpawnLoaded(false) .keepsSpawnLoaded(true)
.dimension(DimensionTypes.OVERWORLD) .dimension(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.FLAT) .generator(GeneratorTypes.OVERWORLD)
.usesMapFeatures(false) .usesMapFeatures(false)
.enabled(true) .enabled(true)
.generatorModifiers(wgm) .generatorModifiers(wgm)
@ -162,7 +161,7 @@ public class SpongeSetupUtils extends SetupUtils {
WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class)
.name(object.world) .name(object.world)
.loadsOnStartup(true) .loadsOnStartup(true)
.keepsSpawnLoaded(false) .keepsSpawnLoaded(true)
.dimension(DimensionTypes.OVERWORLD) .dimension(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.OVERWORLD) .generator(GeneratorTypes.OVERWORLD)
.usesMapFeatures(true) .usesMapFeatures(true)

View File

@ -10,7 +10,7 @@ public class SpongeTitleManager extends AbstractTitle {
@Override @Override
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) { 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); ((SpongePlayer) player).player.sendTitle(title);
} }
} }

View File

@ -3,17 +3,13 @@ package com.plotsquared.sponge.util;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.*;
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.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
import net.minecraft.block.Block; 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.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.text.Text; 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.Translatable;
import org.spongepowered.api.text.translation.Translation; import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.world.World; 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.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
public class SpongeUtil extends WorldUtil { public class SpongeUtil extends WorldUtil {
@ -105,6 +98,10 @@ public class SpongeUtil extends WorldUtil {
return (BiomeType) BiomeGenBase.getBiome(index); 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) { public static Translation getTranslation(final String m) {
return new Translatable() { return new Translatable() {
@Override @Override
@ -348,8 +345,6 @@ public class SpongeUtil extends WorldUtil {
@Override @Override
public Location getSpawn(final String world) { public Location getSpawn(final String world) {
final World worldObj = SpongeUtil.getWorld(world);
worldObj.getSpawnLocation();
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation()); final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
result.setY(getHighestBlock(world, result.getX(), result.getZ())); result.setY(getHighestBlock(world, result.getX(), result.getZ()));
return result; return result;
@ -419,7 +414,7 @@ public class SpongeUtil extends WorldUtil {
final Sign sign = (Sign) tile; final Sign sign = (Sign) tile;
final List<Text> text = new ArrayList<>(4); final List<Text> text = new ArrayList<>(4);
for (int i = 0; i < 4; i++) { 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); sign.offer(Keys.SIGN_LINES, text);
} }

View File

@ -1,5 +1,245 @@
package com.plotsquared.sponge.util.block; 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<Chunk> {
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;
}
} }

View File

@ -1,5 +1,319 @@
package com.plotsquared.sponge.util.block; 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 { public class FastQueue extends SlowQueue {
// TODO FIXME
public HashMap<ChunkWrapper, Chunk> 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<Chunk> chunks = new ArrayList<Chunk>();
final Iterator<Entry<ChunkWrapper, Chunk>> 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<Chunk> 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<Chunk> 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<BlockPos, TileEntity> tiles = nmsChunk.getTileEntityMap();
ClassInheritanceMultiMap<Entity>[] entities = nmsChunk.getEntityLists();
// Trim tiles
Set<Entry<BlockPos, TileEntity>> entryset = tiles.entrySet();
Iterator<Entry<BlockPos, TileEntity>> iter = entryset.iterator();
while (iter.hasNext()) {
Entry<BlockPos,TileEntity> 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<Chunk> getChunk(ChunkWrapper wrap) {
return new FastChunk(wrap);
}
/**
* This should be overridden by any specialized queues
* @param pc
*/
@Override
public boolean fixLighting(PlotChunk<Chunk> 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<ChunkLoc> 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());
}
}
}
} }

View File

@ -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<Chunk> input) {
final HashSet<Chunk> chunks = new HashSet<Chunk>(input);
final HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
for (final Chunk chunk : chunks) {
final String world = chunk.getWorld().getName();
ArrayList<Chunk> 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<String, PlotPlayer> 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<Chunk> 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<ChunkLoc> locs) {
World spongeWorld = SpongeUtil.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<>();
for (final ChunkLoc loc : locs) {
chunks.add(spongeWorld.getChunk(loc.x, 0, loc.z).get());
}
sendChunk(chunks);
}
}