Fix more Sponge Classes

This commit is contained in:
Matt 2016-02-19 12:45:43 -05:00
parent 63cd7c8b97
commit 660cd1b870
5 changed files with 239 additions and 203 deletions

View File

@ -1,20 +1,50 @@
package com.plotsquared.sponge; package com.plotsquared.sponge;
import java.io.File; import com.google.inject.Inject;
import java.lang.reflect.Field; import com.intellectualcrafters.configuration.ConfigurationSection;
import java.lang.reflect.Method; import com.intellectualcrafters.plot.IPlotMain;
import java.nio.charset.StandardCharsets; import com.intellectualcrafters.plot.PS;
import java.nio.file.Files; import com.intellectualcrafters.plot.config.C;
import java.util.Arrays; import com.intellectualcrafters.plot.config.Configuration;
import java.util.Collection; import com.intellectualcrafters.plot.config.Settings;
import java.util.HashMap; import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import java.util.List; import com.intellectualcrafters.plot.generator.HybridUtils;
import java.util.Locale; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import java.util.Map; import com.intellectualcrafters.plot.object.PlotArea;
import java.util.Map.Entry; import com.intellectualcrafters.plot.object.PlotBlock;
import java.util.Optional; import com.intellectualcrafters.plot.object.PlotPlayer;
import java.util.UUID; 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.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.plotsquared.sponge.generator.SpongeBasicGen;
import com.plotsquared.sponge.generator.SpongeGeneratorWrapper;
import com.plotsquared.sponge.generator.WorldModify;
import com.plotsquared.sponge.listener.MainListener;
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.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeTaskManager;
import com.plotsquared.sponge.util.SpongeTitleManager;
import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.CatalogType; import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
@ -35,51 +65,23 @@ 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.DimensionTypes; import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.GeneratorTypes; import org.spongepowered.api.world.GeneratorTypes;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.WorldCreationSettings;
import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import com.google.inject.Inject; import java.io.File;
import com.intellectualcrafters.configuration.ConfigurationSection; import java.lang.reflect.Field;
import com.intellectualcrafters.plot.IPlotMain; import java.lang.reflect.Method;
import com.intellectualcrafters.plot.PS; import java.nio.charset.StandardCharsets;
import com.intellectualcrafters.plot.config.C; import java.nio.file.Files;
import com.intellectualcrafters.plot.config.Configuration; import java.util.Arrays;
import com.intellectualcrafters.plot.config.Settings; import java.util.Collection;
import com.intellectualcrafters.plot.generator.HybridUtils; import java.util.HashMap;
import com.intellectualcrafters.plot.object.PlotArea; import java.util.List;
import com.intellectualcrafters.plot.object.PlotBlock; import java.util.Locale;
import com.intellectualcrafters.plot.object.PlotPlayer; import java.util.Map;
import com.intellectualcrafters.plot.util.AbstractTitle; import java.util.Map.Entry;
import com.intellectualcrafters.plot.util.ChatManager; import java.util.Optional;
import com.intellectualcrafters.plot.util.ChunkManager; import java.util.UUID;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.generator.SpongeBasicGen;
import com.plotsquared.sponge.generator.SpongeGeneratorWrapper;
import com.plotsquared.sponge.generator.WorldModify;
import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.util.KillRoadMobs;
import com.plotsquared.sponge.util.SpongeBlockManager;
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.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeTaskManager;
import com.plotsquared.sponge.util.SpongeTitleManager;
import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
/** /**
* Created by robin on 01/11/2014 * Created by robin on 01/11/2014
@ -87,6 +89,7 @@ import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies = "before:WorldEdit,required-after:TotalEconomy") @Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies = "before:WorldEdit,required-after:TotalEconomy")
public class SpongeMain implements IPlotMain, PluginContainer { public class SpongeMain implements IPlotMain, PluginContainer {
public static SpongeMain THIS; public static SpongeMain THIS;
@Inject @Inject
@ -122,7 +125,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} }
public Text getText(final String m) { public Text getText(final String m) {
return Texts.of(m); return Text.of(m);
} }
public Translatable getTranslation(final String m) { public Translatable getTranslation(final String m) {
@ -191,7 +194,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override @Override
public Optional<Object> getInstance() { public Optional<Object> getInstance() {
return Optional.<Object> of(THIS); return Optional.<Object>of(THIS);
} }
@Override @Override
@ -234,8 +237,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
SpongeBasicGen generator = new SpongeBasicGen(null); SpongeBasicGen generator = new SpongeBasicGen(null);
method.invoke(null, "plotsquared", new WorldModify(generator, false)); method.invoke(null, "plotsquared", new WorldModify(generator, false));
log("Adding plotsquared modifier to Project Worlds"); log("Adding plotsquared modifier to Project Worlds");
} } catch (Throwable e) {
catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -263,7 +265,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} }
} }
public World createWorldFromConfig(final String world) { public WorldCreationSettings createWorldFromConfig(final String world) {
final SpongeBasicGen generator = new SpongeBasicGen(world); final SpongeBasicGen generator = new SpongeBasicGen(world);
final PlotArea plotworld = generator.getNewPlotWorld(world); final PlotArea plotworld = generator.getNewPlotWorld(world);
SpongeGeneratorWrapper wrapper; SpongeGeneratorWrapper wrapper;
@ -272,23 +274,26 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} else { } else {
wrapper = new SpongeGeneratorWrapper(world, null); wrapper = new SpongeGeneratorWrapper(world, null);
} }
PS.get().loadWorld(world, wrapper); PS.get().loadWorld(world, (GeneratorWrapper<?>) wrapper);
switch (plotworld.TYPE) { switch (plotworld.TYPE) {
// Normal // Normal
case 0: { case 0: {
modify = new WorldModify(generator, false); modify = new WorldModify(generator, false);
game.getRegistry().registerWorldGeneratorModifier(modify); game.getRegistry().register(WorldModify.class, modify);
final Optional<World> builder = game.getRegistry().createBuilder(WorldBuilder.class).name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD) WorldCreationSettings builder = WorldCreationSettings.builder().name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true)
.generator(GeneratorTypes.FLAT).usesMapFeatures(false).generatorModifiers(modify).build(); .dimension(DimensionTypes.OVERWORLD).generator(GeneratorTypes.OVERWORLD).usesMapFeatures(false).generatorModifiers(modify)
return builder.get(); .build();
return builder;
} }
// Augmented // Augmented
default: { default: {
modify = new WorldModify(generator, true); modify = new WorldModify(generator, true);
game.getRegistry().registerWorldGeneratorModifier(modify); game.getRegistry().register(WorldModify.class, modify);
final Optional<World> builder = game.getRegistry().createBuilder(WorldBuilder.class).name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD) final WorldCreationSettings builder =
.generator(GeneratorTypes.OVERWORLD).usesMapFeatures(false).generatorModifiers(modify).build(); WorldCreationSettings.builder().name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true)
return builder.get(); .dimension(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.OVERWORLD).usesMapFeatures(false).generatorModifiers(modify).build();
return builder;
} }
} }
} }
@ -325,7 +330,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
public void registerBlocks() { public void registerBlocks() {
blockMap = new BlockState[256][]; blockMap = new BlockState[256][];
blockMapReverse = new HashMap<BlockState, PlotBlock>(); blockMapReverse = new HashMap<>();
final HashMap<String, BlockState> states = new HashMap<>(); final HashMap<String, BlockState> states = new HashMap<>();
PS.get().copyFile("ids.txt", "config"); PS.get().copyFile("ids.txt", "config");
@ -342,15 +347,14 @@ public class SpongeMain implements IPlotMain, PluginContainer {
for (final Field field : fields) { for (final Field field : fields) {
final BlockType type = (BlockType) field.get(null); final BlockType type = (BlockType) field.get(null);
final BlockState state = type.getDefaultState(); final BlockState state = type.getDefaultState();
if (state != null) { try {
try { states.put(type.getId() + ":" + 0, state);
states.put(type.getId() + ":" + 0, state); } catch (final Exception e) {
} catch (final Exception e) {}
} }
} }
final String packaze = "org.spongepowered.api.data.type."; final String packaze = "org.spongepowered.api.data.type.";
for (int i = 0; i < data_lines.size(); i++) { for (String data_line : data_lines) {
final String classname = packaze + data_lines.get(i).trim(); final String classname = packaze + data_line.trim();
try { try {
final Class<?> clazz = Class.forName(classname); final Class<?> clazz = Class.forName(classname);
fields = clazz.getDeclaredFields(); fields = clazz.getDeclaredFields();
@ -359,10 +363,10 @@ public class SpongeMain implements IPlotMain, PluginContainer {
final String minecraft_id = type.getId(); final String minecraft_id = type.getId();
final BlockState state = states.get(minecraft_id + ":" + 0); final BlockState state = states.get(minecraft_id + ":" + 0);
if (state == null) { if (state == null) {
continue;
} }
} }
} catch (final Throwable e) {} } catch (ClassNotFoundException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
}
} }
PlotBlock block = null; PlotBlock block = null;
@ -377,8 +381,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
break; break;
} }
case 2: { case 2: {
final String minecraft_id = line; final BlockState state = states.remove(line + ":" + block.data);
final BlockState state = states.remove(minecraft_id + ":" + block.data);
if (state == null) { if (state == null) {
continue; continue;
} }
@ -401,11 +404,11 @@ public class SpongeMain implements IPlotMain, PluginContainer {
if (!Settings.CONSOLE_COLOR) { if (!Settings.CONSOLE_COLOR) {
message = message.replaceAll('\u00a7' + "[a-z|0-9]", ""); message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
} }
if ((server == null) || (server.getConsole() == null)) { if ((server == null)) {
logger.info(message); logger.info(message);
return; return;
} }
server.getConsole().sendMessage(Texts.of(message)); server.getConsole().sendMessage(Text.of(message));
} }
@Override @Override
@ -430,7 +433,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
final String version = plugin.getVersion(); final String version = plugin.getVersion();
log("Checking plugin version: PlotSquared: "); log("Checking plugin version: PlotSquared: ");
final String[] split = version.split("\\."); final String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0};
} }
@Override @Override
@ -438,7 +441,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
log("Checking minecraft version: Sponge: "); log("Checking minecraft version: Sponge: ");
final String version = game.getPlatform().getMinecraftVersion().getName(); final String version = game.getPlatform().getMinecraftVersion().getName();
final String[] split = version.split("\\."); final String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0};
} }
@Override @Override
@ -447,17 +450,21 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} }
@Override @Override
public SpongeGeneratorWrapper getGenerator(final String world, final String name) { public GeneratorWrapper<?> getGenerator(final String world, final String name) {
if (name == null) { if (name == null) {
return new SpongeGeneratorWrapper(world, null); return (GeneratorWrapper<?>) new SpongeGeneratorWrapper(world, null);
} }
if (name.equals("PlotSquared")) { if (name.equals("PlotSquared")) {
return new SpongeGeneratorWrapper(world, new SpongeBasicGen(world)); return (GeneratorWrapper<?>) new SpongeGeneratorWrapper(world, new SpongeBasicGen(world));
} else { } else {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
} }
} }
@Override public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) {
return null;
}
@Override @Override
public EconHandler getEconomyHandler() { public EconHandler getEconomyHandler() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -465,11 +472,15 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return new SpongeEconHandler(); return new SpongeEconHandler();
} }
@Override @Override public PlotQueue initPlotQueue() {
public BlockManager initBlockManager() { return null;
return new SpongeBlockManager();
} }
@Override public WorldUtil initWorldUtil() {
return null;
}
@Override @Override
public EventUtil initEventUtil() { public EventUtil initEventUtil() {
return new SpongeEventUtil(); return new SpongeEventUtil();
@ -507,7 +518,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override @Override
public void registerCommands() { public void registerCommands() {
getGame().getCommandManager().register(THIS, new SpongeCommand(), new String[] { "plots", "p", "plot", "ps", "plotsquared", "p2", "2" }); getGame().getCommandManager().register(THIS, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2", "2");
} }
@Override @Override
@ -605,6 +616,10 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return new SpongeTitleManager(); return new SpongeTitleManager();
} }
@Override public List<String> getPluginIds() {
return null;
}
@Override @Override
public PlotPlayer wrapPlayer(final Object obj) { public PlotPlayer wrapPlayer(final Object obj) {
if (obj instanceof Player) { if (obj instanceof Player) {

View File

@ -1,22 +1,6 @@
package com.plotsquared.sponge.listener; package com.plotsquared.sponge.listener;
import java.util.ArrayList; import com.flowpowered.math.vector.Vector3d;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Predicate;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Explosive;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Monster;
import com.avaje.ebean.Transaction;
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;
@ -42,7 +26,48 @@ 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;
import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.SpongeUtil;
import com.sk89q.worldedit.extent.Extent; import org.spongepowered.api.block.BlockSnapshot;
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;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.entity.living.animal.Animal;
import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.vehicle.Boat;
import org.spongepowered.api.entity.vehicle.minecart.Minecart;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.LightningEvent;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.block.GrowBlockEvent;
import org.spongepowered.api.event.block.InteractBlockEvent;
import org.spongepowered.api.event.block.MoveBlockEvent;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.command.SendCommandEvent;
import org.spongepowered.api.event.entity.BreedEntityEvent;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.event.entity.SpawnEntityEvent;
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.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.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Predicate;
public class MainListener { public class MainListener {
@ -123,12 +148,9 @@ public class MainListener {
// } // }
public <T> T getCause(Cause cause, Class<T> clazz) { public <T> T getCause(Cause cause, Class<T> clazz) {
Optional<?> root = cause.root(); Object root = cause.root();
if (root.isPresent()) { if (clazz.isInstance(root)) {
Object source = root.get(); return (T) root;
if (clazz.isInstance(source)) {
return (T) source;
}
} }
return null; return null;
} }
@ -137,13 +159,13 @@ public class MainListener {
public void onCommand(final BreedEntityEvent.Breed event) { public void onCommand(final BreedEntityEvent.Breed event) {
final Location loc = SpongeUtil.getLocation(event.getTargetEntity()); final Location loc = SpongeUtil.getLocation(event.getTargetEntity());
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotArea plotworld = PS.get().getPlotArea(world); final PlotArea plotworld = PS.get().getPlotAreaByString(world);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (MainUtil.isPlotRoad(loc)) { if (loc.isPlotRoad()) {
event.setCancelled(true); event.setCancelled(true);
} }
return; return;
@ -156,7 +178,7 @@ public class MainListener {
@Listener @Listener
public void onMobSpawn(final SpawnEntityEvent event) { public void onMobSpawn(final SpawnEntityEvent event) {
World world = event.getTargetWorld(); World world = event.getTargetWorld();
final PlotArea plotworld = PS.get().getPlotArea(world.getName()); final PlotArea plotworld = PS.get().getPlotAreaByString(world.getName());
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
@ -169,9 +191,9 @@ public class MainListener {
return true; return true;
} }
final Location loc = SpongeUtil.getLocation(entity); final Location loc = SpongeUtil.getLocation(entity);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (MainUtil.isPlotRoad(loc)) { if (loc.isPlotRoad()) {
return false; return false;
} }
return true; return true;
@ -202,7 +224,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[3] >= cap) { if (mobs[3] >= cap) {
return false; return false;
@ -216,7 +238,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[1] >= cap) { if (mobs[1] >= cap) {
return false; return false;
@ -231,7 +253,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[2] >= cap) { if (mobs[2] >= cap) {
return false; return false;
@ -248,7 +270,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[4] >= cap) { if (mobs[4] >= cap) {
return false; return false;
@ -262,7 +284,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[0] >= cap) { if (mobs[0] >= cap) {
return false; return false;
@ -286,7 +308,7 @@ public class MainListener {
return; return;
} }
if (Settings.USE_PLOTME_ALIAS) { if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandDispatcher().process(source, ("plots " + event.getArguments()).trim()); SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else { } else {
source.sendMessage(SpongeMain.THIS.getText(C.NOT_USING_PLOTME.s())); source.sendMessage(SpongeMain.THIS.getText(C.NOT_USING_PLOTME.s()));
} }
@ -304,9 +326,9 @@ public class MainListener {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions(); List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition()); Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null ) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -316,7 +338,7 @@ public class MainListener {
@Override @Override
public boolean test(org.spongepowered.api.world.Location<World> loc) { public boolean test(org.spongepowered.api.world.Location<World> loc) {
if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, loc))) { if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) {
return false; return false;
} }
return true; return true;
@ -342,7 +364,7 @@ public class MainListener {
public void printCause(String method, Cause cause) { public void printCause(String method, Cause cause) {
System.out.println(method + ": " + cause.toString()); System.out.println(method + ": " + cause.toString());
System.out.println(method + ": " + cause.getClass()); System.out.println(method + ": " + cause.getClass());
System.out.println(method + ": " + (cause.root().isPresent() ? cause.root().get() : null)); System.out.println(method + ": " + (cause.root()));
} }
@Listener @Listener
@ -356,17 +378,17 @@ public class MainListener {
if (!PS.get().hasPlotArea(world)) { if (!PS.get().hasPlotArea(world)) {
return; return;
} }
final PlotArea plotworld = PS.get().getPlotArea(world); final PlotArea plotworld = PS.get().getPlotAreaByString(world);
final PlotPlayer plr = SpongeUtil.getPlayer(player); final PlotPlayer plr = SpongeUtil.getPlayer(player);
if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) { if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) {
return; return;
} }
final Location loc = SpongeUtil.getLocation(player); final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
return; return;
} }
final Text message = event.getMessage(); final Text message = event.getMessage().orElse(Text.EMPTY);
// TODO use display name rather than username // TODO use display name rather than username
// - Getting displayname currently causes NPE, so wait until sponge fixes that // - Getting displayname currently causes NPE, so wait until sponge fixes that
@ -374,12 +396,12 @@ public class MainListener {
final String sender = player.getName(); final String sender = player.getName();
final PlotId id = plot.getId(); final PlotId id = plot.getId();
final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
final Text forcedMessage = event.getMessage(); final Text forcedMessage = event.getMessage().orElse(Text.EMPTY);
// String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); // String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer user = entry.getValue(); PlotPlayer user = entry.getValue();
String toSend; String toSend;
if (plot.equals(MainUtil.getPlot(user.getLocation()))) { if (plot.equals(user.getLocation().getPlot())) {
toSend = newMessage; toSend = newMessage;
} else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) { } else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
((SpongePlayer) user).player.sendMessage(forcedMessage); ((SpongePlayer) user).player.sendMessage(forcedMessage);
@ -396,9 +418,9 @@ public class MainListener {
} else { } else {
prefix = message; prefix = message;
} }
components.add(Texts.of(part)); components.add(Text.of(part));
} }
((SpongePlayer) user).player.sendMessage(Texts.join(components)); ((SpongePlayer) user).player.sendMessage(Text.join(components));
} }
event.setMessage(null); event.setMessage(null);
} }
@ -424,7 +446,7 @@ public class MainListener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (originPlot == null && !MainUtil.isPlotAreaAbs(current)) { if (originPlot == null && current.getPlotAbs() == null /*May not work*/) {
return; return;
} }
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) {
@ -467,11 +489,6 @@ public class MainListener {
onBlockChange(event); onBlockChange(event);
} }
@Listener
public void onBlockBreak(final ChangeBlockEvent.Fluid event) {
onBlockChange(event);
}
@Listener @Listener
public void onBlockBreak(final ChangeBlockEvent.Grow event) { public void onBlockBreak(final ChangeBlockEvent.Grow event) {
onBlockChange(event); onBlockChange(event);
@ -499,9 +516,9 @@ public class MainListener {
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot pos = first.getOriginal();
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
@ -536,7 +553,7 @@ public class MainListener {
Location loc = SpongeUtil.getLocation(worldname, l); Location loc = SpongeUtil.getLocation(worldname, l);
Plot plot = loc.getPlot(); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return true; return true;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
@ -583,9 +600,9 @@ public class MainListener {
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot pos = first.getOriginal();
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
@ -620,7 +637,7 @@ public class MainListener {
Location loc = SpongeUtil.getLocation(worldname, l); Location loc = SpongeUtil.getLocation(worldname, l);
Plot plot = loc.getPlot(); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return true; return true;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
@ -663,10 +680,10 @@ public class MainListener {
} }
org.spongepowered.api.world.Location<World> l = target.get(); org.spongepowered.api.world.Location<World> l = target.get();
Location loc = SpongeUtil.getLocation(l); Location loc = SpongeUtil.getLocation(l);
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
@ -726,12 +743,12 @@ public class MainListener {
}, 20); }, 20);
} }
final Location loc = SpongeUtil.getLocation(player); final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
return; return;
} }
if (Settings.TELEPORT_ON_LOGIN) { if (Settings.TELEPORT_ON_LOGIN) {
MainUtil.teleportPlayer(pp, pp.getLocation(), plot); pp.teleport(loc);
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
} }
PlotListener.plotEntry(pp, plot); PlotListener.plotEntry(pp, plot);
@ -764,11 +781,11 @@ public class MainListener {
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
final PlotArea plotworld = PS.get().getPlotArea(worldname); final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final PlotManager plotManager = PS.get().getPlotManager(worldname); final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin()));
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); final PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ()));
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) { if (id == null) {
@ -777,7 +794,7 @@ public class MainListener {
} }
if (!PlotListener.plotExit(pp, lastPlot)) { 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(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -787,10 +804,10 @@ public class MainListener {
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) { } else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
return; return;
} else { } else {
final Plot plot = MainUtil.getPlot(worldname, id); final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id);
if (!PlotListener.plotEntry(pp, plot)) { if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.getBasePlot(false).equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (!plot.getBasePlot(false).equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -798,19 +815,17 @@ public class MainListener {
return; return;
} }
} }
final Integer border = MainUtil.worldBorder.get(worldname); final Integer border = plotworld.getBorder();
if (border != null) { if (x2 > border) {
if (x2 > border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); event.setToTransform(new Transform(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER); } else if (x2 < -border) {
} else if (x2 < -border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); event.setToTransform(new Transform(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER);
}
} }
return; return;
} }
@ -826,20 +841,20 @@ public class MainListener {
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
final PlotArea plotworld = PS.get().getPlotArea(worldname); final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final PlotManager plotManager = PS.get().getPlotManager(worldname); final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin()));
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = pp.getMeta("lastplot");
if (id == null) { if (id == null) {
if (lastPlot == null) { if (lastPlot == null) {
return; return;
} }
if (!PlotListener.plotExit(pp, lastPlot)) { 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(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -849,10 +864,10 @@ public class MainListener {
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) { } else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
return; return;
} else { } else {
final Plot plot = MainUtil.getPlot(worldname, id); final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id);
if (!PlotListener.plotEntry(pp, plot)) { if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (!plot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -860,19 +875,17 @@ public class MainListener {
return; return;
} }
} }
final Integer border = MainUtil.worldBorder.get(worldname); final Integer border = plotworld.getBorder();
if (border != null) { if (z2 > border) {
if (z2 > border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); event.setToTransform(new Transform(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();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); event.setToTransform(new Transform(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER);
}
} }
} }
} }

View File

@ -50,17 +50,17 @@ public class SpongeCommand implements CommandCallable {
@Override @Override
public Optional<? extends Text> getShortDescription(final CommandSource cmd) { public Optional<? extends Text> getShortDescription(final CommandSource cmd) {
return Optional.of(Texts.of("Shows plot help")); return Optional.of(Text.of("Shows plot help"));
} }
@Override @Override
public Optional<? extends Text> getHelp(final CommandSource cmd) { public Optional<? extends Text> getHelp(final CommandSource cmd) {
return Optional.of(Texts.of("/plot help")); return Optional.of(Text.of("/plot help"));
} }
@Override @Override
public Text getUsage(final CommandSource cmd) { public Text getUsage(final CommandSource cmd) {
return Texts.of("/plot <command>"); return Text.of("/plot <command>");
} }
} }

View File

@ -28,6 +28,15 @@ package com.plotsquared.sponge.util;
* either expressed or implied, of anybody else. * either expressed or implied, of anybody else.
*/ */
import com.google.inject.Inject;
import com.intellectualcrafters.plot.PS;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.Game;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -43,8 +52,6 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import com.intellectualcrafters.plot.PS;
public class SpongeMetrics { public class SpongeMetrics {
/** /**

View File

@ -11,7 +11,8 @@ 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 = new TitleBuilder().title(SpongeMain.THIS.getText(head)).subtitle(SpongeMain.THIS.getText(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build(); final Title title = Title.builder().title(SpongeMain.THIS.getText(head)).subtitle(SpongeMain.THIS.getText(sub)).fadeIn(in * 20).stay
(delay * 20).fadeOut(out * 20).build();
((SpongePlayer) player).player.sendTitle(title); ((SpongePlayer) player).player.sendTitle(title);
} }
} }