mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Updated Gradle
This commit is contained in:
70
Sponge/build.gradle
Normal file
70
Sponge/build.gradle
Normal file
@ -0,0 +1,70 @@
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
dependencies {
|
||||
compile project(':Core')
|
||||
compile 'org.spongepowered:spongeapi:3.1.0-SNAPSHOT'
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = 'forge'
|
||||
url = 'http://files.minecraftforge.net/maven'
|
||||
}
|
||||
maven {
|
||||
name = "Sponge"
|
||||
url = "https://repo.spongepowered.org/maven"
|
||||
}
|
||||
}
|
||||
|
||||
version = "3.2.27"
|
||||
|
||||
minecraft {
|
||||
version = "1.8.9-11.15.1.1742"
|
||||
mappings = "snapshot_20160204"
|
||||
runDir = 'run'
|
||||
}
|
||||
|
||||
project.archivesBaseName = "${project.archivesBaseName}-mc${minecraft.version}"
|
||||
|
||||
processResources {
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
expand 'version': project.version,
|
||||
'mcVersion': project.minecraft.version
|
||||
}
|
||||
}
|
||||
shadowJar {
|
||||
dependencies {
|
||||
include(dependency(':Core'))
|
||||
}
|
||||
}
|
||||
|
||||
reobf {
|
||||
shadowJar {
|
||||
mappingType = 'SEARGE'
|
||||
}
|
||||
}
|
||||
|
||||
task deobfJar(type: Jar) {
|
||||
from sourceSets.main.output
|
||||
classifier = 'dev'
|
||||
}
|
||||
|
||||
build.dependsOn(shadowJar)
|
461
Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java
Normal file
461
Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java
Normal file
@ -0,0 +1,461 @@
|
||||
package com.plotsquared.sponge;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
|
||||
import org.spongepowered.api.event.game.state.GameInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.profile.GameProfileManager;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.gen.GenerationPopulator;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.plot.IPlotMain;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.ChatManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotQueue;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.generator.SpongePlotGenerator;
|
||||
import com.plotsquared.sponge.listener.ChunkProcessor;
|
||||
import com.plotsquared.sponge.listener.MainListener;
|
||||
import com.plotsquared.sponge.listener.WorldEvents;
|
||||
import com.plotsquared.sponge.util.KillRoadMobs;
|
||||
import com.plotsquared.sponge.util.SpongeChatManager;
|
||||
import com.plotsquared.sponge.util.SpongeChunkManager;
|
||||
import com.plotsquared.sponge.util.SpongeCommand;
|
||||
import com.plotsquared.sponge.util.SpongeEconHandler;
|
||||
import com.plotsquared.sponge.util.SpongeEventUtil;
|
||||
import com.plotsquared.sponge.util.SpongeHybridUtils;
|
||||
import com.plotsquared.sponge.util.SpongeInventoryUtil;
|
||||
import com.plotsquared.sponge.util.SpongeMetrics;
|
||||
import com.plotsquared.sponge.util.SpongeSchematicHandler;
|
||||
import com.plotsquared.sponge.util.SpongeSetupUtils;
|
||||
import com.plotsquared.sponge.util.SpongeTaskManager;
|
||||
import com.plotsquared.sponge.util.SpongeTitleManager;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
import com.plotsquared.sponge.util.block.FastQueue;
|
||||
import com.plotsquared.sponge.util.block.SlowQueue;
|
||||
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
|
||||
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
|
||||
|
||||
/**
|
||||
* Created by robin on 01/11/2014
|
||||
*/
|
||||
|
||||
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.0", dependencies = "before:WorldEdit")
|
||||
public class SpongeMain implements IPlotMain {
|
||||
public static SpongeMain THIS;
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
@Inject
|
||||
private Game game;
|
||||
private Server server;
|
||||
|
||||
private GameProfileManager resolver;
|
||||
|
||||
// @Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public GameProfileManager getResolver() {
|
||||
if (resolver == null) {
|
||||
resolver = game.getServer().getGameProfileManager();
|
||||
}
|
||||
return resolver;
|
||||
}
|
||||
|
||||
public SpongeMain getPlugin() {
|
||||
return THIS;
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getId() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
// @Override
|
||||
public Optional<Object> getInstance() {
|
||||
return Optional.<Object> of(THIS);
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getName() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
// @Override
|
||||
public String getVersion() {
|
||||
final int[] version = PS.get().getVersion();
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (final int i : version) {
|
||||
result += prefix + i;
|
||||
prefix = ".";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void init(final GameInitializationEvent event) {
|
||||
log("PlotSquared: Game init");
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onInit(final GamePreInitializationEvent event) {
|
||||
log("PlotSquared: Game pre init");
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onServerAboutToStart(final GameAboutToStartServerEvent event) {
|
||||
log("PlotSquared: Server init");
|
||||
THIS = this;
|
||||
new PS(this, "Sponge");
|
||||
server = game.getServer();
|
||||
game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
message = C.format(message, C.replacements);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
|
||||
}
|
||||
if ((server == null) || (server.getConsole() == null)) {
|
||||
logger.info(message);
|
||||
return;
|
||||
}
|
||||
server.getConsole().sendMessage(Text.of(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDirectory() {
|
||||
return new File("mods/PlotSquared");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldContainer() {
|
||||
return new File("world");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
PS.get().disable();
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
final PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
||||
final String version = plugin.getVersion();
|
||||
log("Checking plugin version: PlotSquared: ");
|
||||
final String[] split = version.split("\\.");
|
||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getServerVersion() {
|
||||
log("Checking minecraft version: Sponge: ");
|
||||
final String version = game.getPlatform().getMinecraftVersion().getName();
|
||||
final String[] split = version.split("\\.");
|
||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryUtil initInventoryUtil() {
|
||||
return new SpongeInventoryUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconHandler getEconomyHandler() {
|
||||
SpongeEconHandler econ = new SpongeEconHandler();
|
||||
Sponge.getEventManager().registerListeners(this, econ);
|
||||
return econ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventUtil initEventUtil() {
|
||||
return new SpongeEventUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkManager initChunkManager() {
|
||||
return new SpongeChunkManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetupUtils initSetupUtils() {
|
||||
return new SpongeSetupUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HybridUtils initHybridUtils() {
|
||||
return new SpongeHybridUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicHandler initSchematicHandler() {
|
||||
return new SpongeSchematicHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
return new SpongeTaskManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEntityTask() {
|
||||
new KillRoadMobs().run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands() {
|
||||
getGame().getCommandManager().register(THIS, new SpongeCommand(), new String[] { "plots", "p", "plot", "ps", "plotsquared", "p2", "2" });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerEvents() {
|
||||
Sponge.getEventManager().registerListeners(this, new MainListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInventoryEvents() {
|
||||
// Part of PlayerEvents - can be moved if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlotPlusEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerPlotPlusEvents is not implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerForceFieldEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerForceFieldEvents is not implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initWorldEdit() {
|
||||
try {
|
||||
Class.forName("com.sk89q.worldedit.WorldEdit");
|
||||
return true;
|
||||
} catch (final Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUIDHandlerImplementation initUUIDHandler() {
|
||||
UUIDWrapper wrapper;
|
||||
if (Settings.OFFLINE_MODE || !PS.get().checkVersion(getServerVersion(), 1, 7, 6)) {
|
||||
wrapper = new SpongeLowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
wrapper = new SpongeOnlineUUIDWrapper();
|
||||
}
|
||||
return new SpongeUUIDHandler(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initPlotMeConverter() {
|
||||
// PlotMe was never ported to sponge
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(final PlotPlayer player) {
|
||||
SpongeUtil.removePlayer(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerChunkProcessor() {
|
||||
Sponge.getEventManager().registerListeners(this, new ChunkProcessor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWorldEvents() {
|
||||
Sponge.getEventManager().registerListeners(this, new WorldEvents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
try {
|
||||
final SpongeMetrics metrics = new SpongeMetrics(game, (PluginContainer) this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(final String worldname) {
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
// create world
|
||||
final ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
|
||||
String manager = worldConfig.getString("generator.plugin");
|
||||
if (manager == null) {
|
||||
manager = "PlotSquared";
|
||||
}
|
||||
String generator = worldConfig.getString("generator.init");
|
||||
if (generator == null) {
|
||||
generator = manager;
|
||||
}
|
||||
|
||||
final int type = worldConfig.getInt("generator.type");
|
||||
final int terrain = worldConfig.getInt("generator.terrain");
|
||||
final SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = generator;
|
||||
setup.type = type;
|
||||
setup.terrain = terrain;
|
||||
setup.step = new ConfigurationNode[0];
|
||||
setup.world = worldname;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
} else {
|
||||
throw new IllegalArgumentException("World already loaded: " + worldname + "???");
|
||||
}
|
||||
WorldGenerator wg = world.getWorldGenerator();
|
||||
GenerationPopulator gen = wg.getBaseGenerationPopulator();
|
||||
if (gen instanceof SpongePlotGenerator) {
|
||||
PS.get().loadWorld(worldname, (SpongePlotGenerator) gen);
|
||||
} else if (gen != null) {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET!");
|
||||
} else {
|
||||
if (PS.get().config.contains("worlds." + worldname)) {
|
||||
PS.get().loadWorld(worldname, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTitle initTitleManager() {
|
||||
return new SpongeTitleManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotPlayer wrapPlayer(final Object obj) {
|
||||
if (obj instanceof Player) {
|
||||
return SpongeUtil.getPlayer((Player) obj);
|
||||
}
|
||||
else if (obj instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) obj);
|
||||
} else if (obj instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) obj);
|
||||
}
|
||||
// TODO FIXME offline player
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNMSPackage() {
|
||||
return "";//TODO FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatManager<?> initChatManager() {
|
||||
return new SpongeChatManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotQueue initPlotQueue() {
|
||||
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
|
||||
try {
|
||||
return new FastQueue();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new SlowQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldUtil initWorldUtil() {
|
||||
return new SpongeUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorWrapper<?> getGenerator(String world, String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
Collection<WorldGeneratorModifier> wgms = game.getRegistry().getAllOf(WorldGeneratorModifier.class);
|
||||
for (WorldGeneratorModifier wgm : wgms) {
|
||||
if (StringMan.isEqualIgnoreCaseToAny(name, wgm.getName(), wgm.getId())) {
|
||||
if (wgm instanceof GeneratorWrapper<?>) {
|
||||
return (GeneratorWrapper<?>) wgm;
|
||||
}
|
||||
return new SpongePlotGenerator(wgm);
|
||||
}
|
||||
}
|
||||
return new SpongePlotGenerator(new HybridGen());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
|
||||
return new SpongePlotGenerator(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPluginIds() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (PluginContainer plugin : game.getPluginManager().getPlugins()) {
|
||||
names.add(plugin.getName() + ";" + plugin.getVersion() + ":" + true);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.plotsquared.sponge;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.plotsquared.sponge.generator.SpongePlotGenerator;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpongeSetupUtils extends SetupUtils {
|
||||
|
||||
@Override
|
||||
public void updateGenerators() {
|
||||
if (!SetupUtils.generators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
|
||||
throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenerator(final PlotArea plotworld) {
|
||||
if (SetupUtils.generators.isEmpty()) {
|
||||
updateGenerators();
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(plotworld.worldname);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
final WorldGenerator generator = world.getWorldGenerator();
|
||||
if (!(generator instanceof SpongePlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
for (final Map.Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
|
||||
GeneratorWrapper<?> current = entry.getValue();
|
||||
if (current.equals(generator)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setupWorld(final SetupObject object) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
final ConfigurationNode[] steps = object.step;
|
||||
final String world = object.world;
|
||||
for (final ConfigurationNode step : steps) {
|
||||
PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue());
|
||||
}
|
||||
if (object.type != 0) {
|
||||
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager);
|
||||
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
|
||||
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
||||
}
|
||||
final PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
|
||||
if ((gen != null) && (gen.generator instanceof SpongePlotGenerator)) {
|
||||
object.setupGenerator = null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET: Create a new world here");
|
||||
// return object.world;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
|
||||
public class ClusterFlagRemoveEvent extends AbstractEvent implements Cancellable {
|
||||
|
||||
private final PlotCluster cluster;
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster involved
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
public PlotCluster getCluster() {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private final Plot plot;
|
||||
private final boolean auto;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||
*
|
||||
* @param player Player that claimed the plot
|
||||
* @param plot Plot that was claimed
|
||||
*/
|
||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
this.auto = auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if it was an automated claim, else false
|
||||
*/
|
||||
public boolean wasAuto() {
|
||||
return auto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
*/
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
public abstract class PlayerEvent extends AbstractEvent {
|
||||
|
||||
public final Player player;
|
||||
|
||||
public PlayerEvent(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that left the plot
|
||||
* @param plot Plot that was left
|
||||
*/
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was denied/un-denied
|
||||
* @param added true of add to deny list, false if removed
|
||||
*/
|
||||
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the helper list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the trusted list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private final Location from;
|
||||
private final Plot plot;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
||||
*
|
||||
* @param player That was teleported
|
||||
* @param from Start location
|
||||
* @param plot Plot to which the player was teleported
|
||||
*/
|
||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
|
||||
super(player);
|
||||
this.from = from;
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the from location
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotClearEvent extends AbstractEvent implements Cancellable {
|
||||
|
||||
private boolean cancelled;
|
||||
private Plot plot;
|
||||
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is cleared
|
||||
*
|
||||
* @param plot The plot that was cleared
|
||||
*/
|
||||
|
||||
public PlotClearEvent(Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return plot.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return plot.getArea().worldname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotDeleteEvent extends AbstractEvent {
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is deleted
|
||||
*
|
||||
* @param plot The plot that was deleted
|
||||
*/
|
||||
public PlotDeleteEvent(Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return plot.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return plot.getArea().worldname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public abstract class PlotEvent extends AbstractEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
public PlotEvent(final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public final Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
||||
*
|
||||
* @param flag Flag that was added
|
||||
* @param plot Plot to which the flag was added
|
||||
*/
|
||||
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param plot Plot from which the flag was removed
|
||||
*/
|
||||
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotMergeEvent extends AbstractEvent implements Cancellable {
|
||||
private final ArrayList<PlotId> plots;
|
||||
private boolean cancelled;
|
||||
private Plot plot;
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* PlotMergeEvent: Called when plots are merged
|
||||
*
|
||||
* @param world World in which the event occurred
|
||||
* @param plot Plot that was merged
|
||||
* @param plots A list of plots involved in the event
|
||||
*/
|
||||
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) {
|
||||
this.plots = plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added;
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main plot
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
|
||||
public class PlotRateEvent extends PlotEvent {
|
||||
private final PlotPlayer rater;
|
||||
private Rating rating;
|
||||
|
||||
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
|
||||
super(plot);
|
||||
this.rater = rater;
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public PlotPlayer getRater() {
|
||||
return rater;
|
||||
}
|
||||
|
||||
public void setRating(final Rating rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public Rating getRating() {
|
||||
return rating;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.plotsquared.sponge.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotUnlinkEvent extends AbstractEvent implements Cancellable {
|
||||
private final ArrayList<PlotId> plots;
|
||||
private final World world;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when a mega-plot is unlinked.
|
||||
*
|
||||
* @param world World in which the event occurred
|
||||
* @param plots Plots that are involved in the event
|
||||
*/
|
||||
public PlotUnlinkEvent(final World world, final ArrayList<PlotId> plots) {
|
||||
this.plots = plots;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots involved
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.plotsquared.sponge.generator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.extent.ImmutableBiomeArea;
|
||||
import org.spongepowered.api.world.extent.MutableBlockVolume;
|
||||
import org.spongepowered.api.world.gen.GenerationPopulator;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
||||
import com.intellectualcrafters.plot.object.LazyResult;
|
||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongeAugmentedGenerator implements GenerationPopulator {
|
||||
|
||||
private static SpongeAugmentedGenerator generator;
|
||||
|
||||
private SpongeAugmentedGenerator() {};
|
||||
|
||||
public static SpongeAugmentedGenerator get(World world) {
|
||||
WorldGenerator wg = world.getWorldGenerator();
|
||||
List<GenerationPopulator> populators = wg.getGenerationPopulators();
|
||||
for (GenerationPopulator poplator : populators) {
|
||||
if (poplator instanceof SpongeAugmentedGenerator) {
|
||||
return (SpongeAugmentedGenerator) poplator;
|
||||
}
|
||||
}
|
||||
if (generator == null) {
|
||||
generator = new SpongeAugmentedGenerator();
|
||||
}
|
||||
populators.add(generator);
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(final World world, final MutableBlockVolume terrain, final ImmutableBiomeArea biome) {
|
||||
Vector3i min = terrain.getBlockMin();
|
||||
final int bx = min.getX();
|
||||
final int bz = min.getZ();
|
||||
final int cx = bx >> 4;
|
||||
final int cz = bz >> 4;
|
||||
AugmentedUtils.generate(world.getName(), cx, cz, new LazyResult<PlotChunk<?>>() {
|
||||
@Override
|
||||
public PlotChunk<?> create() {
|
||||
ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz);
|
||||
return new PlotChunk<ChunkWrapper>(wrap) {
|
||||
@Override
|
||||
public ChunkWrapper getChunkAbs() {
|
||||
return getChunkWrapper();
|
||||
}
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
terrain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
|
||||
}
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
world.setBiome(bx + x, bz + z, null);
|
||||
}
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package com.plotsquared.sponge.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.api.data.DataContainer;
|
||||
import org.spongepowered.api.world.WorldCreationSettings;
|
||||
import org.spongepowered.api.world.biome.BiomeGenerationSettings;
|
||||
import org.spongepowered.api.world.biome.BiomeType;
|
||||
import org.spongepowered.api.world.biome.BiomeTypes;
|
||||
import org.spongepowered.api.world.extent.MutableBiomeArea;
|
||||
import org.spongepowered.api.world.gen.BiomeGenerator;
|
||||
import org.spongepowered.api.world.gen.GenerationPopulator;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper<WorldGeneratorModifier> {
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final List<GenerationPopulator> populators = new ArrayList<>();
|
||||
private final boolean loaded = false;
|
||||
private PlotManager manager;
|
||||
private final WorldGeneratorModifier platformGenerator;
|
||||
private final boolean full;
|
||||
|
||||
public SpongePlotGenerator(IndependentPlotGenerator generator) {
|
||||
this.plotGenerator = generator;
|
||||
this.platformGenerator = this;
|
||||
this.full = true;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
public SpongePlotGenerator(WorldGeneratorModifier wgm) {
|
||||
this.plotGenerator = null;
|
||||
this.platformGenerator = wgm;
|
||||
this.full = false;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
if (plotGenerator == null) {
|
||||
if (platformGenerator != this) {
|
||||
return platformGenerator.getId();
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
return plotGenerator.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (plotGenerator == null) {
|
||||
if (platformGenerator != this) {
|
||||
return platformGenerator.getName();
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
return plotGenerator.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyWorldGenerator(WorldCreationSettings settings, DataContainer data, WorldGenerator wg) {
|
||||
final String worldname = settings.getWorldName();
|
||||
wg.setBaseGenerationPopulator(new SpongeTerrainGen(this, plotGenerator));
|
||||
wg.setBiomeGenerator(new BiomeGenerator() {
|
||||
@Override
|
||||
public void generateBiomes(MutableBiomeArea buffer) {
|
||||
PlotArea area = PS.get().getPlotArea(worldname, null);
|
||||
if (area != null) {
|
||||
BiomeType biome = SpongeUtil.getBiome(area.PLOT_BIOME);
|
||||
Vector2i min = buffer.getBiomeMin();
|
||||
Vector2i max = buffer.getBiomeMax();
|
||||
for (int x = min.getX(); x <= max.getX(); x++) {
|
||||
for (int z = min.getY(); z <= max.getY(); z++) {
|
||||
buffer.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
for (BiomeType type : ReflectionUtils.<BiomeType> getStaticFields(BiomeTypes.class)) {
|
||||
BiomeGenerationSettings biomeSettings = wg.getBiomeSettings(type);
|
||||
biomeSettings.getGenerationPopulators().clear();
|
||||
biomeSettings.getPopulators().clear();
|
||||
}
|
||||
wg.getGenerationPopulators().clear();
|
||||
wg.getPopulators().clear();
|
||||
PS.get().loadWorld(worldname, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndependentPlotGenerator getPlotGenerator() {
|
||||
return plotGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGeneratorModifier getPlatformGenerator() {
|
||||
return platformGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void augment(PlotArea area) {
|
||||
SpongeAugmentedGenerator.get(SpongeUtil.getWorld(area.worldname));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return full;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.plotsquared.sponge.generator;
|
||||
|
||||
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 com.flowpowered.math.vector.Vector3i;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.sponge.util.block.GenChunk;
|
||||
|
||||
public class SpongeTerrainGen implements GenerationPopulator {
|
||||
|
||||
public final SpongePlotGenerator parent;
|
||||
public final IndependentPlotGenerator child;
|
||||
private final PseudoRandom random = new PseudoRandom();
|
||||
|
||||
public SpongeTerrainGen(SpongePlotGenerator parent, IndependentPlotGenerator ipg) {
|
||||
this.parent = parent;
|
||||
this.child = ipg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biomes) {
|
||||
Vector3i size = terrain.getBlockSize();
|
||||
if (size.getX() != 16 || size.getZ() != 16) {
|
||||
throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED");
|
||||
}
|
||||
String worldname = world.getName();
|
||||
Vector3i min = terrain.getBlockMin();
|
||||
int cx = min.getX() >> 4;
|
||||
int cz = min.getZ() >> 4;
|
||||
ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(worldname, cx, cz);
|
||||
// Create the result object
|
||||
GenChunk result = new GenChunk(terrain, null, wrap);
|
||||
// Catch any exceptions
|
||||
try {
|
||||
// Set random seed
|
||||
random.state = (cx << 16) | (cz & 0xFFFF);
|
||||
// Process the chunk
|
||||
result.modified = false;
|
||||
ChunkManager.preProcessChunk(result);
|
||||
if (result.modified) {
|
||||
return;
|
||||
}
|
||||
// Fill the result data
|
||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
||||
child.generateChunk(result, area, random);
|
||||
ChunkManager.postProcessChunk(result);
|
||||
return;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.plotsquared.sponge.listener;
|
||||
|
||||
public class ChunkProcessor {
|
||||
// TODO FIXME
|
||||
}
|
@ -0,0 +1,819 @@
|
||||
package com.plotsquared.sponge.listener;
|
||||
|
||||
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.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
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.InteractEvent;
|
||||
import org.spongepowered.api.event.block.ChangeBlockEvent;
|
||||
import org.spongepowered.api.event.block.NotifyNeighborBlockEvent;
|
||||
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.event.world.ExplosionEvent.Detonate;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.extent.Extent;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.listener.PlotListener;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class MainListener {
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - Anything marked with a TODO below
|
||||
* - BlockPhysicsEvent
|
||||
* - BlockFormEvent
|
||||
* - BlockFadeEvent
|
||||
* - BlockFromToEvent
|
||||
* - BlockDamageEvent
|
||||
* - Structure (tree etc)
|
||||
* - ChunkPreGenerateEvent
|
||||
* - PlayerIgniteBlockEvent
|
||||
* - PlayerBucketEmptyEvent
|
||||
* - PlayerBucketFillEvent
|
||||
* - VehicleCreateEvent
|
||||
* - HangingPlaceEvent
|
||||
* - HangingBreakEvent
|
||||
* - EntityChangeBlockEvent
|
||||
* - PVP
|
||||
* - block dispense
|
||||
* - PVE
|
||||
* - VehicleDestroy
|
||||
* - Projectile
|
||||
* - enderman harvest
|
||||
*/
|
||||
|
||||
@Listener
|
||||
public void onCommand(final SendCommandEvent event) {
|
||||
switch (event.getCommand().toLowerCase()) {
|
||||
case "plotme": {
|
||||
Player source = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
if (Settings.USE_PLOTME_ALIAS) {
|
||||
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
|
||||
} else {
|
||||
source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s()));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onChat(final MessageEvent event) {
|
||||
// TODO
|
||||
Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
final String world = player.getWorld().getName();
|
||||
if (!PS.get().hasPlotArea(world)) {
|
||||
return;
|
||||
}
|
||||
final PlotArea plotworld = PS.get().getPlotAreaByString(world);
|
||||
final PlotPlayer plr = SpongeUtil.getPlayer(player);
|
||||
if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) {
|
||||
return;
|
||||
}
|
||||
final Location loc = SpongeUtil.getLocation(player);
|
||||
final Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
final Text message = event.getMessage().orElse(Text.EMPTY);
|
||||
|
||||
// TODO use display name rather than username
|
||||
// - Getting displayname currently causes NPE, so wait until sponge fixes that
|
||||
|
||||
final String sender = player.getName();
|
||||
final PlotId id = plot.getId();
|
||||
final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
|
||||
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);
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer user = entry.getValue();
|
||||
String toSend;
|
||||
if (plot.equals(user.getLocation().getPlot())) {
|
||||
toSend = newMessage;
|
||||
} else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
|
||||
((SpongePlayer) user).player.sendMessage(forcedMessage);
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
final String[] split = (toSend + " ").split("%msg%");
|
||||
final List<Text> components = new ArrayList<>();
|
||||
Text prefix = null;
|
||||
for (final String part : split) {
|
||||
if (prefix != null) {
|
||||
components.add(prefix);
|
||||
} else {
|
||||
prefix = message;
|
||||
}
|
||||
components.add(Text.of(part));
|
||||
}
|
||||
((SpongePlayer) user).player.sendMessage(Text.join(components));
|
||||
}
|
||||
event.setMessage(null);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBreedEntity(final BreedEntityEvent.Breed event) {
|
||||
final Location loc = SpongeUtil.getLocation(event.getTargetEntity());
|
||||
final String world = loc.getWorld();
|
||||
final PlotArea plotworld = PS.get().getPlotAreaByString(world);
|
||||
if (plotworld == null) {
|
||||
return;
|
||||
}
|
||||
final Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.isPlotRoad()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!plotworld.SPAWN_BREEDING) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onSpawnEntity(SpawnEntityEvent event) throws Exception {
|
||||
World world = event.getTargetWorld();
|
||||
final PlotArea plotworld = PS.get().getPlotAreaByString(world.getName());
|
||||
if (plotworld == null) {
|
||||
return;
|
||||
}
|
||||
event.filterEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean test(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
return true;
|
||||
}
|
||||
final Location loc = SpongeUtil.getLocation(entity);
|
||||
final Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.isPlotRoad()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Player player = this.<Player> getCause(event.getCause());
|
||||
// TODO selectively cancel depending on spawn reason
|
||||
// - Not sure if possible to get spawn reason (since there are no callbacks)
|
||||
// if (player != null && !plotworld.SPAWN_EGGS) {
|
||||
// return false;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
if (entity.getType() == EntityTypes.ITEM) {
|
||||
if (FlagManager.isPlotFlagFalse(plot, "item-drop")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int[] mobs = null;
|
||||
if (entity instanceof Living) {
|
||||
if (!plotworld.MOB_SPAWNING) {
|
||||
return false;
|
||||
}
|
||||
final Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap");
|
||||
if (mobCap != null) {
|
||||
final Integer cap = (Integer) mobCap.getValue();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[3] >= cap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((entity instanceof Ambient) || (entity instanceof Animal)) {
|
||||
final Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap");
|
||||
if (animalFlag != null) {
|
||||
final int cap = ((Integer) animalFlag.getValue());
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[1] >= cap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity instanceof Monster) {
|
||||
final Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap");
|
||||
if (monsterFlag != null) {
|
||||
final int cap = ((Integer) monsterFlag.getValue());
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[2] >= cap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ((entity instanceof Minecart) || (entity instanceof Boat)) {
|
||||
final Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap");
|
||||
if (vehicleFlag != null) {
|
||||
final int cap = ((Integer) vehicleFlag.getValue());
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[4] >= cap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
final Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap");
|
||||
if (entityCap != null) {
|
||||
final Integer cap = (Integer) entityCap.getValue();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[0] >= cap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (entity instanceof PrimedTNT) {
|
||||
Vector3d pos = entity.getLocation().getPosition();
|
||||
entity.setRotation(new Vector3d(MathMan.roundInt(pos.getX()), MathMan.roundInt(pos.getY()), MathMan.roundInt(pos.getZ())));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception {
|
||||
final AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||
SpongeUtil.printCause("physics", event.getCause());
|
||||
// PlotArea area = plotloc.getPlotArea();
|
||||
// event.filterDirections(new Predicate<Direction>() {
|
||||
//
|
||||
// @Override
|
||||
// public boolean test(Direction dir) {
|
||||
// if (cancelled.get()) {
|
||||
// return true;
|
||||
// }
|
||||
// org.spongepowered.api.world.Location<World> loc = relatives.get(dir);
|
||||
// com.intellectualcrafters.plot.object.Location plotloc = SpongeUtil.getLocation(loc.getExtent().getName(), loc);
|
||||
// if (area == null) {
|
||||
// return true;
|
||||
// }
|
||||
// plot = area.get
|
||||
// Plot plot = plotloc.getPlot();
|
||||
// if (plot == null) {
|
||||
// if (MainUtil.isPlotAreaAbs(plotloc)) {
|
||||
// cancelled.set(true);
|
||||
// return false;
|
||||
// }
|
||||
// cancelled.set(true);
|
||||
// return true;
|
||||
// }
|
||||
// org.spongepowered.api.world.Location<World> relative = loc.getRelative(dir);
|
||||
// com.intellectualcrafters.plot.object.Location relLoc = SpongeUtil.getLocation(relative.getExtent().getName(), relative);
|
||||
// if (plot.equals(MainUtil.getPlot(relLoc))) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onInteract(InteractEvent event) throws Exception {
|
||||
final Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
|
||||
if (player == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Optional<Vector3d> target = event.getInteractionPoint();
|
||||
if (!target.isPresent()) {
|
||||
return;
|
||||
}
|
||||
Location loc = SpongeUtil.getLocation(player.getWorld().getName(), target.get());
|
||||
org.spongepowered.api.world.Location l = SpongeUtil.getLocation(loc);
|
||||
Plot plot = loc.getPlot();
|
||||
PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return;
|
||||
}
|
||||
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||
return;
|
||||
} else {
|
||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
if ((flag != null) && ((HashSet<PlotBlock>) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onExplosion(ExplosionEvent e) throws Exception {
|
||||
if (e instanceof ExplosionEvent.Detonate) {
|
||||
ExplosionEvent.Detonate event = (Detonate) e;
|
||||
final World world = event.getTargetWorld();
|
||||
final String worldname = world.getName();
|
||||
if (!PS.get().hasPlotArea(worldname)) {
|
||||
return;
|
||||
}
|
||||
Optional<Explosive> source = event.getExplosion().getSourceExplosive();
|
||||
if (!source.isPresent()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Explosive tnt = source.get();
|
||||
Location origin = SpongeUtil.getLocation(worldname, tnt.getRotation());
|
||||
Plot originPlot = origin.getPlot();
|
||||
Location current = SpongeUtil.getLocation(tnt);
|
||||
final Plot currentPlot = current.getPlot();
|
||||
if (!Objects.equals(originPlot, currentPlot)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (originPlot == null && current.getPlotAbs() == null) {
|
||||
return;
|
||||
}
|
||||
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
@Override
|
||||
public boolean test(org.spongepowered.api.world.Location<World> loc) {
|
||||
return currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot());
|
||||
}
|
||||
});
|
||||
event.filterEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean test(Entity entity) {
|
||||
return currentPlot.equals(SpongeUtil.getLocation(entity).getPlot());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void onChangeBlock(ChangeBlockEvent event) {
|
||||
final World world = event.getTargetWorld();
|
||||
final String worldname = world.getName();
|
||||
if (!PS.get().hasPlotArea(worldname)) {
|
||||
return;
|
||||
}
|
||||
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
|
||||
Transaction<BlockSnapshot> first = transactions.get(0);
|
||||
Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition());
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
|
||||
@Override
|
||||
public boolean test(org.spongepowered.api.world.Location<World> loc) {
|
||||
if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBlockBreak(final ChangeBlockEvent.Decay event) {
|
||||
onChangeBlock(event);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBlockBreak(final ChangeBlockEvent.Grow event) {
|
||||
onChangeBlock(event);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBlockBreak(final ChangeBlockEvent.Modify event) {
|
||||
onChangeBlock(event);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBlockBreak(final ChangeBlockEvent.Break event) {
|
||||
Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
|
||||
if (player == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
final World world = event.getTargetWorld();
|
||||
final String worldname = world.getName();
|
||||
if (!PS.get().hasPlotArea(worldname)) {
|
||||
return;
|
||||
}
|
||||
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
|
||||
Transaction<BlockSnapshot> first = transactions.get(0);
|
||||
BlockSnapshot pos = first.getOriginal();
|
||||
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return;
|
||||
}
|
||||
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (transactions.size() == 1) {
|
||||
if (!plot.hasOwner()) {
|
||||
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
return;
|
||||
} else {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
|
||||
final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
|
||||
final BlockState state = pos.getState();
|
||||
if ((destroy == null) || !((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
|
||||
@Override
|
||||
public boolean test(org.spongepowered.api.world.Location<World> l) {
|
||||
Location loc = SpongeUtil.getLocation(worldname, l);
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
return true;
|
||||
} else {
|
||||
final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
|
||||
final BlockState state = l.getBlock();
|
||||
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onBlockPlace(final ChangeBlockEvent.Place event) {
|
||||
Player player = SpongeUtil.<Player> getCause(event.getCause(), Player.class);
|
||||
if (player == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
final World world = event.getTargetWorld();
|
||||
final String worldname = world.getName();
|
||||
if (!PS.get().hasPlotArea(worldname)) {
|
||||
return;
|
||||
}
|
||||
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
|
||||
Transaction<BlockSnapshot> first = transactions.get(0);
|
||||
BlockSnapshot pos = first.getOriginal();
|
||||
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return;
|
||||
}
|
||||
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (transactions.size() == 1) {
|
||||
if (!plot.hasOwner()) {
|
||||
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
return;
|
||||
} else {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
|
||||
final Flag BUILD = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
|
||||
final BlockState state = pos.getState();
|
||||
if ((BUILD == null) || !((HashSet<PlotBlock>) BUILD.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
|
||||
@Override
|
||||
public boolean test(org.spongepowered.api.world.Location<World> l) {
|
||||
Location loc = SpongeUtil.getLocation(worldname, l);
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.getPlotAbs() == null) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
return true;
|
||||
} else {
|
||||
final Flag build = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
|
||||
final BlockState state = l.getBlock();
|
||||
if ((build != null) && ((HashSet<PlotBlock>) build.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onConnect(final ClientConnectionEvent.Login event) {
|
||||
GameProfile profile = event.getProfile();
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
if (profile.getName().equals("PlotSquared") || profile.getUniqueId().equals(DBFunc.everyone) || DBFunc.everyone.equals(UUIDHandler.getUUID(profile.getName(), null))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onJoin(final ClientConnectionEvent.Join event) {
|
||||
final Player player = event.getTargetEntity();
|
||||
SpongeUtil.removePlayer(player.getName());
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
final String username = pp.getName();
|
||||
final StringWrapper name = new StringWrapper(username);
|
||||
final UUID uuid = pp.getUUID();
|
||||
UUIDHandler.add(name, uuid);
|
||||
ExpireManager.dates.put(uuid, System.currentTimeMillis());
|
||||
if ((PS.get().update != null) && pp.hasPermission("plots.admin")) {
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
final Location loc = SpongeUtil.getLocation(player);
|
||||
final Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (Settings.TELEPORT_ON_LOGIN) {
|
||||
pp.teleport(loc);
|
||||
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
|
||||
}
|
||||
PlotListener.plotEntry(pp, plot);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onQuit(final ClientConnectionEvent.Disconnect event) {
|
||||
final Player player = event.getTargetEntity();
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
pp.unregister();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onMove(final DisplaceEntityEvent.TargetPlayer event) {
|
||||
final org.spongepowered.api.world.Location<World> from = event.getFromTransform().getLocation();
|
||||
org.spongepowered.api.world.Location<World> to = event.getToTransform().getLocation();
|
||||
int x2;
|
||||
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
|
||||
final Player player = event.getTargetEntity();
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
final Extent extent = to.getExtent();
|
||||
pp.setMeta("location", SpongeUtil.getLocation(player));
|
||||
final World world = (World) extent;
|
||||
final String worldname = ((World) extent).getName();
|
||||
final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
|
||||
if (plotworld == null) {
|
||||
return;
|
||||
}
|
||||
final PlotManager plotManager = plotworld.getPlotManager();
|
||||
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ()));
|
||||
final Plot lastPlot = (Plot) pp.getMeta("lastplot");
|
||||
if (id == null) {
|
||||
if (lastPlot == null) {
|
||||
return;
|
||||
}
|
||||
if (!PlotListener.plotExit(pp, lastPlot)) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
|
||||
if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setToTransform(new Transform<>(world.getSpawnLocation()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
|
||||
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();
|
||||
if (x2 > border) {
|
||||
final Vector3d pos = to.getPosition();
|
||||
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
|
||||
event.setToTransform(new Transform<>(to));
|
||||
MainUtil.sendMessage(pp, C.BORDER);
|
||||
} else if (x2 < -border) {
|
||||
final Vector3d pos = to.getPosition();
|
||||
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
|
||||
event.setToTransform(new Transform<>(to));
|
||||
MainUtil.sendMessage(pp, C.BORDER);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int z2;
|
||||
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
|
||||
final Player player = event.getTargetEntity();
|
||||
final PlotPlayer pp = SpongeUtil.getPlayer(player);
|
||||
final Extent extent = to.getExtent();
|
||||
pp.setMeta("location", SpongeUtil.getLocation(player));
|
||||
final World world = (World) extent;
|
||||
final String worldname = ((World) extent).getName();
|
||||
final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
|
||||
if (plotworld == null) {
|
||||
return;
|
||||
}
|
||||
final PlotManager plotManager = plotworld.getPlotManager();
|
||||
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
|
||||
final Plot lastPlot = pp.getMeta("lastplot");
|
||||
if (id == null) {
|
||||
if (lastPlot == null) {
|
||||
return;
|
||||
}
|
||||
if (!PlotListener.plotExit(pp, lastPlot)) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
|
||||
if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setToTransform(new Transform<>(world.getSpawnLocation()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
|
||||
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();
|
||||
if (z2 > border) {
|
||||
final Vector3d pos = to.getPosition();
|
||||
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
|
||||
event.setToTransform(new Transform<>(to));
|
||||
MainUtil.sendMessage(pp, C.BORDER);
|
||||
} else if (z2 < -border) {
|
||||
final Vector3d pos = to.getPosition();
|
||||
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
|
||||
event.setToTransform(new Transform<>(to));
|
||||
MainUtil.sendMessage(pp, C.BORDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.plotsquared.sponge.listener;
|
||||
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.world.LoadWorldEvent;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.gen.GenerationPopulator;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.plotsquared.sponge.generator.SpongeTerrainGen;
|
||||
|
||||
public class WorldEvents {
|
||||
|
||||
@Listener
|
||||
public void onLoadWorld(LoadWorldEvent event) {
|
||||
final World world = event.getTargetWorld();
|
||||
final String name = world.getName();
|
||||
WorldGenerator generator = world.getWorldGenerator();
|
||||
GenerationPopulator terrain = generator.getBaseGenerationPopulator();
|
||||
if (terrain instanceof SpongeTerrainGen) {
|
||||
SpongeTerrainGen stg = (SpongeTerrainGen) terrain;
|
||||
PS.get().loadWorld(name, stg.parent);
|
||||
}
|
||||
else if (PS.get().config.contains("worlds." + name)) {
|
||||
PS.get().loadWorld(name, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.plotsquared.sponge.object;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeOfflinePlayer implements OfflinePlotPlayer {
|
||||
|
||||
@Override public UUID getUUID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public long getLastPlayed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public boolean isOnline() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,289 @@
|
||||
package com.plotsquared.sponge.object;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData;
|
||||
import org.spongepowered.api.data.value.mutable.Value;
|
||||
import org.spongepowered.api.effect.sound.SoundTypes;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
|
||||
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
|
||||
import org.spongepowered.api.service.ban.BanService;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.chat.ChatTypes;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongePlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private long last = 0;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
public SpongePlayer(final Player player) {
|
||||
this.player = player;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequiredType getSuperCaller() {
|
||||
return RequiredType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPreviousLogin() {
|
||||
if (last != 0) {
|
||||
return last;
|
||||
}
|
||||
final Value<Instant> data = player.getJoinData().lastPlayed();
|
||||
if (data.exists()) {
|
||||
return last = data.get().getEpochSecond() * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
final Location loc = super.getLocation();
|
||||
return loc == null ? SpongeUtil.getLocation(player) : loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocationFull() {
|
||||
return SpongeUtil.getLocationFull(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String perm) {
|
||||
if (Settings.PERMISSION_CACHING) {
|
||||
if (noPerm.contains(perm)) {
|
||||
return false;
|
||||
}
|
||||
if (hasPerm.contains(perm)) {
|
||||
return true;
|
||||
}
|
||||
final boolean result = player.hasPermission(perm);
|
||||
if (!result) {
|
||||
noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
hasPerm.add(perm);
|
||||
return true;
|
||||
}
|
||||
return player.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc) {
|
||||
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) {
|
||||
return;
|
||||
}
|
||||
final String world = player.getWorld().getName();
|
||||
if (!world.equals(loc.getWorld())) {
|
||||
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
} else {
|
||||
org.spongepowered.api.world.Location current = player.getLocation();
|
||||
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
player.setLocation(current);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
name = player.getName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc) {
|
||||
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
|
||||
setMeta(key, true);
|
||||
return;
|
||||
}
|
||||
EconHandler.manager.setPermission(getName(), key, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
|
||||
final Object v = getMeta(key);
|
||||
return v == null ? false : (Boolean) v;
|
||||
}
|
||||
return player.hasPermission(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
EconHandler.manager.setPermission(getName(), key, false);
|
||||
deleteMeta(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(final PlotWeather weather) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotGamemode getGamemode() {
|
||||
final GameMode gamemode = player.getGameModeData().type().get();
|
||||
if (gamemode == GameModes.ADVENTURE) {
|
||||
return PlotGamemode.ADVENTURE;
|
||||
}
|
||||
if (gamemode == GameModes.CREATIVE) {
|
||||
return PlotGamemode.CREATIVE;
|
||||
}
|
||||
if (gamemode == GameModes.SPECTATOR) {
|
||||
return PlotGamemode.SPECTATOR;
|
||||
}
|
||||
if (gamemode == GameModes.SURVIVAL) {
|
||||
return PlotGamemode.SURVIVAL;
|
||||
}
|
||||
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGamemode(final PlotGamemode gamemode) {
|
||||
switch (gamemode) {
|
||||
case ADVENTURE:
|
||||
player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
||||
return;
|
||||
case CREATIVE:
|
||||
player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
||||
return;
|
||||
case SPECTATOR:
|
||||
player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
||||
return;
|
||||
case SURVIVAL:
|
||||
player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(final long time) {
|
||||
// TODO Auto-generated method stub
|
||||
if (time != Long.MAX_VALUE) {} else {}
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlight(final boolean fly) {
|
||||
player.offer(Keys.IS_FLYING, fly);
|
||||
player.offer(Keys.CAN_FLY, fly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMusic(final Location loc, final int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
player.playSound(null, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2256:
|
||||
player.playSound(SoundTypes.RECORDS_11, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2257:
|
||||
player.playSound(SoundTypes.RECORDS_13, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2258:
|
||||
player.playSound(SoundTypes.RECORDS_BLOCKS, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2259:
|
||||
player.playSound(SoundTypes.RECORDS_CAT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2260:
|
||||
player.playSound(SoundTypes.RECORDS_CHIRP, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2261:
|
||||
player.playSound(SoundTypes.RECORDS_FAR, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2262:
|
||||
player.playSound(SoundTypes.RECORDS_MALL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2263:
|
||||
player.playSound(SoundTypes.RECORDS_MELLOHI, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2264:
|
||||
player.playSound(SoundTypes.RECORDS_STAL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2265:
|
||||
player.playSound(SoundTypes.RECORDS_STRAD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2266:
|
||||
player.playSound(SoundTypes.RECORDS_WAIT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
case 2267:
|
||||
player.playSound(SoundTypes.RECORDS_WARD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(final String message) {
|
||||
player.kick(Text.of(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
BanService service = Sponge.getServiceManager().provide(BanService.class).get();
|
||||
return service.isBanned(player.getProfile());
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
public class KillRoadMobs {
|
||||
public void run() {
|
||||
// TODO kill road mobs
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.action.TextActions;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotMessage;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChatManager;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeChatManager extends ChatManager<Text.Builder> {
|
||||
|
||||
@Override
|
||||
public Text.Builder builder() {
|
||||
return Text.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(final PlotMessage m, final String color) {
|
||||
m.$(this).color(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(color).getColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
||||
final Text.Builder builder = Text.builder();
|
||||
boolean lb = false;
|
||||
for (final PlotMessage tooltip : tooltips) {
|
||||
if (lb) {
|
||||
builder.append(Text.of("\n"));
|
||||
}
|
||||
builder.append(tooltip.$(this).build());
|
||||
lb = true;
|
||||
}
|
||||
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
||||
m.$(this).onHover(TextActions.showText(builder.toText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.runCommand(command));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(final PlotMessage m, final String text) {
|
||||
m.$(this).append(Text.of(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
||||
if (ConsolePlayer.isConsole(player)) {
|
||||
player.sendMessage(m.$(this).build().toPlain());
|
||||
} else {
|
||||
((SpongePlayer) player).player.sendMessage(m.$(this).build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.suggestCommand(command));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
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.world.Chunk;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class SpongeChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
public int[] countEntities(final Plot plot) {
|
||||
final Location pos1 = plot.getBottomAbs();
|
||||
final Location pos2 = plot.getTopAbs();
|
||||
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
final int bz = pos1.getZ();
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
final int[] count = new int[6];
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean test(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
count[0]++;
|
||||
if (entity instanceof Living) {
|
||||
count[3]++;
|
||||
if (entity instanceof Animal) {
|
||||
count[1]++;
|
||||
} else if (entity instanceof Monster) {
|
||||
count[2]++;
|
||||
}
|
||||
} else {
|
||||
count[4]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ChunkLoc> getChunkChunks(final String world) {
|
||||
// TODO save world;
|
||||
return super.getChunkChunks(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regenerateChunk(final String world, final ChunkLoc loc) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunkOpt = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunkOpt.isPresent()) {
|
||||
Chunk chunk = chunkOpt.get();
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
// TODO copy a region
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(final Location pos1, final Location pos2) {
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
final int bz = pos1.getZ();
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean test(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swap(Location bot1, Location top1, Location bot2, Location top2, Runnable whenDone) {
|
||||
// TODO swap region
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent()) {
|
||||
worldObj.unloadChunk(chunk.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerateRegion(Location pos1, Location pos2, boolean ignoreAugment, Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeCommand implements CommandCallable {
|
||||
|
||||
@Override
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
|
||||
final String id = cmd.getIdentifier();
|
||||
PlotPlayer pp;
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||
pp = SpongeUtil.getPlayer(player);
|
||||
} catch (final Exception e) {
|
||||
pp = ConsolePlayer.getConsole();
|
||||
}
|
||||
if (MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" "))) {
|
||||
return CommandResult.success();
|
||||
} else {
|
||||
return CommandResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<>(Collections.singletonList("TEST"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(final CommandSource cmd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd) {
|
||||
return Optional.of(Text.of("Shows plot help"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd) {
|
||||
return Optional.of(Text.of("/plot help"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(final CommandSource cmd) {
|
||||
return Text.of("/plot <command>");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
|
||||
import org.spongepowered.api.service.economy.EconomyService;
|
||||
import org.spongepowered.api.service.economy.account.UniqueAccount;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeEconHandler extends EconHandler {
|
||||
private EconomyService econ;
|
||||
|
||||
public SpongeEconHandler() {
|
||||
if (Sponge.getServiceManager().isRegistered(EconomyService.class)) {
|
||||
econ = Sponge.getServiceManager().provide(EconomyService.class).get();
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onChangeServiceProvider(ChangeServiceProviderEvent event) {
|
||||
if (event.getService().equals(EconomyService.class)) {
|
||||
econ = (EconomyService) event.getNewProviderRegistration().getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withdrawMoney(PlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
|
||||
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depositMoney(PlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(String world, String player, String perm, boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("TODO/WIP/NOT IMPLEMENTED!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String world, String player, String perm) {
|
||||
SpongePlayer obj = (SpongePlayer) UUIDHandler.getPlayer(player);
|
||||
if (obj != null) {
|
||||
return obj.player.hasPermission(perm);
|
||||
}
|
||||
// TODO offline
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(PlotPlayer player) {
|
||||
if (econ != null) {
|
||||
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
|
||||
if (accOpt.isPresent()) {
|
||||
UniqueAccount acc = accOpt.get();
|
||||
BigDecimal balance = acc.getBalance(econ.getDefaultCurrency());
|
||||
return balance.doubleValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.events.ClusterFlagRemoveEvent;
|
||||
import com.plotsquared.sponge.events.PlayerClaimPlotEvent;
|
||||
import com.plotsquared.sponge.events.PlayerEnterPlotEvent;
|
||||
import com.plotsquared.sponge.events.PlayerLeavePlotEvent;
|
||||
import com.plotsquared.sponge.events.PlayerPlotDeniedEvent;
|
||||
import com.plotsquared.sponge.events.PlayerPlotHelperEvent;
|
||||
import com.plotsquared.sponge.events.PlayerPlotTrustedEvent;
|
||||
import com.plotsquared.sponge.events.PlayerTeleportToPlotEvent;
|
||||
import com.plotsquared.sponge.events.PlotClearEvent;
|
||||
import com.plotsquared.sponge.events.PlotDeleteEvent;
|
||||
import com.plotsquared.sponge.events.PlotFlagAddEvent;
|
||||
import com.plotsquared.sponge.events.PlotFlagRemoveEvent;
|
||||
import com.plotsquared.sponge.events.PlotMergeEvent;
|
||||
import com.plotsquared.sponge.events.PlotRateEvent;
|
||||
import com.plotsquared.sponge.events.PlotUnlinkEvent;
|
||||
import org.spongepowered.api.event.Event;
|
||||
import org.spongepowered.api.event.EventManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeEventUtil extends EventUtil {
|
||||
|
||||
public EventManager events;
|
||||
|
||||
public SpongeEventUtil() {
|
||||
events = SpongeMain.THIS.getGame().getEventManager();
|
||||
}
|
||||
|
||||
public boolean callEvent(final Event event) {
|
||||
return !events.post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callClear(final Plot plot) {
|
||||
return callEvent(new PlotClearEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(Plot plot) {
|
||||
callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(final Plot plot, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getArea().worldname), plot, plots));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callUnlink(final PlotArea area, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(area.worldname), plots));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callEntry(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callLeave(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) {
|
||||
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
events.post(event);
|
||||
return event.getRating();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.block.BlockTypes;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.PlotAnalysis;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
|
||||
public class SpongeHybridUtils extends HybridUtils {
|
||||
|
||||
@Override
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
int count = 0;
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
final BlockState state = world.getBlock(x, y, z);
|
||||
final PlotBlock block = SpongeUtil.getPlotBlock(state);
|
||||
boolean same = false;
|
||||
for (final PlotBlock p : blocks) {
|
||||
if (block.id == p.id) {
|
||||
same = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!same) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
int ey = sy;
|
||||
for (int x = sx; x <= ex; x++) {
|
||||
for (int z = sz; z <= ez; z++) {
|
||||
for (int y = sy; y < 256; y++) {
|
||||
if (y > ey) {
|
||||
final BlockState state = world.getBlock(x, y, z);
|
||||
if ((state != null) && (state.getType() != BlockTypes.AIR)) {
|
||||
ey = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analyzeRegion(String world, RegionWrapper region, RunnableVal<PlotAnalysis> whenDone) {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.ItemTypes;
|
||||
import org.spongepowered.api.item.inventory.Carrier;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.item.inventory.custom.CustomInventory;
|
||||
import org.spongepowered.api.item.inventory.property.SlotIndex;
|
||||
import org.spongepowered.api.item.inventory.type.CarriedInventory;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil {
|
||||
|
||||
public ItemStack.Builder builder;
|
||||
|
||||
public SpongeInventoryUtil() {
|
||||
builder = SpongeMain.THIS.getGame().getRegistry().createBuilder(ItemStack.Builder.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(final PlotInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
|
||||
final CustomInventory inventory = SpongeMain.THIS.getGame().getRegistry().createBuilder(CustomInventory.Builder.class).name(SpongeUtil.getTranslation(inv.getTitle())).size(inv.size).build();
|
||||
final PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < (inv.size * 9); i++) {
|
||||
final PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.set(new SlotIndex(i), getItem(item));
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item) {
|
||||
// FIXME item type, item data, item name, item lore
|
||||
return builder.itemType(ItemTypes.SPONGE).quantity(item.amount).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
sp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
player.getOpenInventory().get();
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
final ItemType type = item.getItem();
|
||||
final String id = type.getId();
|
||||
final int amount = item.getQuantity();
|
||||
// TODO name / lore
|
||||
return new PlotItemStack(id, amount, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotItemStack[] getItems(final PlotPlayer player) {
|
||||
final SpongePlayer sp = (SpongePlayer) player;
|
||||
sp.player.getInventory();
|
||||
new ArrayList<PlotItemStack>();
|
||||
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
// return list.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
if (player.isViewingInventory()) {
|
||||
final CarriedInventory<? extends Carrier> inventory = player.getInventory();
|
||||
return inv.getTitle().equals(inventory.getName().getId()); // TODO getId()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,521 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
/*
|
||||
* Copyright 2011-2013 Tyler Blair. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and contributors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of anybody else.
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
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 com.google.inject.Inject;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class SpongeMetrics {
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 7;
|
||||
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
private static final String BASE_URL = "http://report.mcstats.org";
|
||||
|
||||
/**
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/plugin/%s";
|
||||
|
||||
/**
|
||||
* Interval of time to ping (in minutes)
|
||||
*/
|
||||
private static final int PING_INTERVAL = 15;
|
||||
|
||||
/**
|
||||
* The game data is being sent for
|
||||
*/
|
||||
private final Game game;
|
||||
|
||||
/**
|
||||
* The plugin this metrics submits for
|
||||
*/
|
||||
private final PluginContainer plugin;
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private CommentedConfigurationNode config;
|
||||
/**
|
||||
* The configuration loader
|
||||
*/
|
||||
private ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private File configurationFile;
|
||||
/**
|
||||
* Unique server id
|
||||
*/
|
||||
private String guid;
|
||||
/**
|
||||
* Debug mode
|
||||
*/
|
||||
private boolean debug;
|
||||
/**
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile Task task = null;
|
||||
|
||||
@Inject
|
||||
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
this.game = game;
|
||||
this.plugin = plugin;
|
||||
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(final String input) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) {
|
||||
try {
|
||||
gzos.close();
|
||||
} catch (final IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
* @param json
|
||||
* @param key
|
||||
* @param value
|
||||
* @throws java.io.UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(final String text) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
final char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
final String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the configuration
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
configurationFile = getConfigFile();
|
||||
configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();
|
||||
|
||||
try {
|
||||
if (!configurationFile.exists()) {
|
||||
configurationFile.createNewFile();
|
||||
config = configurationLoader.load();
|
||||
|
||||
config.setComment("This contains settings for MCStats: http://mcstats.org");
|
||||
config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
config.getNode("mcstats.debug").setValue(false);
|
||||
|
||||
configurationLoader.save(config);
|
||||
} else {
|
||||
config = configurationLoader.load();
|
||||
}
|
||||
|
||||
guid = config.getNode("mcstats.guid").getString();
|
||||
debug = config.getNode("mcstats.debug").getBoolean();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
|
||||
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
|
||||
* ticks.
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
final Task.Builder builder = game.getScheduler().createTaskBuilder();
|
||||
builder.async().interval(PING_INTERVAL, TimeUnit.MINUTES).execute(new Runnable() {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && (task != null)) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (final IOException e) {
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
loadConfiguration();
|
||||
|
||||
return config.getNode("mcstats.opt-out").getBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(true);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
// TODO configDir
|
||||
final File configFolder = new File("config");
|
||||
|
||||
return new File(configFolder, "PluginMetrics.conf");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
final String pluginName = plugin.getName();
|
||||
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
final String pluginVersion = plugin.getVersion();
|
||||
// TODO no visible way to get MC version at the moment
|
||||
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
|
||||
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
|
||||
final int playersOnline = game.getServer().getOnlinePlayers().size();
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
// Construct the post data
|
||||
final StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
// New data as of R6
|
||||
final String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
final String osversion = System.getProperty("os.version");
|
||||
final String java_version = System.getProperty("java.version");
|
||||
final int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64")) {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
|
||||
// close json
|
||||
json.append('}');
|
||||
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent()) {
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
final byte[] uncompressed = json.toString().getBytes();
|
||||
final byte[] compressed = gzip(json.toString());
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
|
||||
// Write the data
|
||||
final OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
// close resources
|
||||
os.close();
|
||||
reader.close();
|
||||
|
||||
if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
response = "null";
|
||||
} else if (response.startsWith("7")) {
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
|
||||
throw new IOException(response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,310 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.item.inventory.Carrier;
|
||||
import org.spongepowered.api.item.inventory.type.CarriedInventory;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.jnbt.IntTag;
|
||||
import com.intellectualcrafters.jnbt.ListTag;
|
||||
import com.intellectualcrafters.jnbt.ShortTag;
|
||||
import com.intellectualcrafters.jnbt.StringTag;
|
||||
import com.intellectualcrafters.jnbt.Tag;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class SpongeSchematicHandler extends SchematicHandler {
|
||||
|
||||
@Override
|
||||
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
|
||||
// async
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Main positions
|
||||
Location[] corners = MainUtil.getCorners(world, regions);
|
||||
final Location bot = corners[0];
|
||||
final Location top = corners[1];
|
||||
|
||||
final int width = (top.getX() - bot.getX()) + 1;
|
||||
final int height = (top.getY() - bot.getY()) + 1;
|
||||
final int length = (top.getZ() - bot.getZ()) + 1;
|
||||
// Main Schematic tag
|
||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||
schematic.put("Width", new ShortTag("Width", (short) width));
|
||||
schematic.put("Length", new ShortTag("Length", (short) length));
|
||||
schematic.put("Height", new ShortTag("Height", (short) height));
|
||||
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
||||
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
|
||||
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
|
||||
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
|
||||
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
|
||||
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
|
||||
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
|
||||
// Arrays of data types
|
||||
final List<Tag> tileEntities = new ArrayList<Tag>();
|
||||
final byte[] blocks = new byte[width * height * length];
|
||||
final byte[] blockData = new byte[width * height * length];
|
||||
// Queue
|
||||
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (queue.isEmpty()) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
||||
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
|
||||
whenDone.value = new CompoundTag("Schematic", schematic);
|
||||
TaskManager.runTask(whenDone);
|
||||
System.gc();
|
||||
System.gc();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
final Runnable regionTask = this;
|
||||
RegionWrapper region = queue.poll();
|
||||
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
||||
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
||||
final int bx = bot.getX();
|
||||
final int bz = bot.getZ();
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
final int p2x = pos2.getX();
|
||||
final int p2z = pos2.getZ();
|
||||
final int bcx = p1x >> 4;
|
||||
final int bcz = p1z >> 4;
|
||||
final int tcx = p2x >> 4;
|
||||
final int tcz = p2z >> 4;
|
||||
final int sy = pos1.getY();
|
||||
final int ey = pos2.getY();
|
||||
// Generate list of chunks
|
||||
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
for (int x = bcx; x <= tcx; x++) {
|
||||
for (int z = bcz; z <= tcz; z++) {
|
||||
chunks.add(new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
// Main thread
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
|
||||
// save schematics
|
||||
final ChunkLoc chunk = chunks.remove(0);
|
||||
final int X = chunk.x;
|
||||
final int Z = chunk.z;
|
||||
int xxb = X << 4;
|
||||
int zzb = Z << 4;
|
||||
if (!worldObj.getChunk(xxb, 1, zzb).isPresent() && !worldObj.loadChunk(xxb, 1, zzb, false).isPresent()) {
|
||||
System.out.println("COULD NOT LOAD CHUNK AT: " + chunk.x + "," + chunk.z);
|
||||
continue;
|
||||
}
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
|
||||
if (X == bcx) {
|
||||
xxb = p1x;
|
||||
}
|
||||
if (X == tcx) {
|
||||
xxt = p2x;
|
||||
}
|
||||
if (Z == bcz) {
|
||||
zzb = p1z;
|
||||
}
|
||||
if (Z == tcz) {
|
||||
zzt = p2z;
|
||||
}
|
||||
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||
final int ry = y - sy;
|
||||
final int i1 = (ry * width * length);
|
||||
for (int z = zzb; z <= zzt; z++) {
|
||||
final int rz = z - p1z;
|
||||
final int i2 = i1 + (rz * width);
|
||||
for (int x = xxb; x <= xxt; x++) {
|
||||
final int rx = x - p1x;
|
||||
final int index = i2 + rx;
|
||||
|
||||
final BlockState state = worldObj.getBlock(x, y, z);
|
||||
PlotBlock block = SpongeUtil.getPlotBlock(state);
|
||||
final int id = block.id;
|
||||
switch (id) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 24:
|
||||
case 30:
|
||||
case 32:
|
||||
case 37:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 51:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 60:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 73:
|
||||
case 74:
|
||||
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 122:
|
||||
case 129:
|
||||
case 133:
|
||||
case 165:
|
||||
case 166:
|
||||
case 169:
|
||||
case 170:
|
||||
case 172:
|
||||
case 173:
|
||||
case 174:
|
||||
case 181:
|
||||
case 182:
|
||||
case 188:
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192: {
|
||||
break;
|
||||
}
|
||||
case 54:
|
||||
case 130:
|
||||
case 142:
|
||||
case 27:
|
||||
case 137:
|
||||
case 52:
|
||||
case 154:
|
||||
case 84:
|
||||
case 25:
|
||||
case 144:
|
||||
case 138:
|
||||
case 176:
|
||||
case 177:
|
||||
case 63:
|
||||
case 68:
|
||||
case 323:
|
||||
case 117:
|
||||
case 116:
|
||||
case 28:
|
||||
case 66:
|
||||
case 157:
|
||||
case 61:
|
||||
case 62:
|
||||
case 140:
|
||||
case 146:
|
||||
case 149:
|
||||
case 150:
|
||||
case 158:
|
||||
case 23:
|
||||
case 123:
|
||||
case 124:
|
||||
case 29:
|
||||
case 33:
|
||||
case 151:
|
||||
case 178: {
|
||||
CompoundTag rawTag;
|
||||
if (state instanceof Carrier) {
|
||||
Carrier chest = (Carrier) state;
|
||||
CarriedInventory<? extends Carrier> inv = chest.getInventory();
|
||||
// TODO serialize inventory
|
||||
rawTag = null;
|
||||
} else {
|
||||
rawTag = null;
|
||||
}
|
||||
if (rawTag != null) {
|
||||
final Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
values.put("id", new StringTag("id", "Chest"));
|
||||
values.put("x", new IntTag("x", x));
|
||||
values.put("y", new IntTag("y", y));
|
||||
values.put("z", new IntTag("z", z));
|
||||
final CompoundTag tileEntityTag = new CompoundTag(values);
|
||||
tileEntities.add(tileEntityTag);
|
||||
}
|
||||
}
|
||||
default: {
|
||||
blockData[index] = block.data;
|
||||
}
|
||||
}
|
||||
blocks[index] = (byte) id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!chunks.isEmpty()) {
|
||||
TaskManager.runTaskLater(this, 1);
|
||||
} else {
|
||||
regionTask.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
|
||||
// TODO Auto-generated method stub
|
||||
// This method should place the compound tag at a location e.g. chest contents
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.world.DimensionTypes;
|
||||
import org.spongepowered.api.world.GeneratorTypes;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.WorldCreationSettings;
|
||||
import org.spongepowered.api.world.WorldCreationSettings.Builder;
|
||||
import org.spongepowered.api.world.gen.WorldGenerator;
|
||||
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
|
||||
import org.spongepowered.api.world.storage.WorldProperties;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.plotsquared.sponge.generator.SpongePlotGenerator;
|
||||
|
||||
public class SpongeSetupUtils extends SetupUtils {
|
||||
|
||||
@Override
|
||||
public void updateGenerators() {
|
||||
if (!SetupUtils.generators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
|
||||
// TODO get external world generators
|
||||
Collection<WorldGeneratorModifier> wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class);
|
||||
for (WorldGeneratorModifier wgm : wgms) {
|
||||
String id = wgm.getId();
|
||||
String name = wgm.getName();
|
||||
if (wgm instanceof GeneratorWrapper<?>) {
|
||||
generators.put(id, (GeneratorWrapper<?>) wgm);
|
||||
generators.put(name, (GeneratorWrapper<?>) wgm);
|
||||
} else {
|
||||
SpongePlotGenerator wrap = new SpongePlotGenerator(wgm);
|
||||
generators.put(id, wrap);
|
||||
generators.put(name, wrap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenerator(final PlotArea plotworld) {
|
||||
if (SetupUtils.generators.isEmpty()) {
|
||||
updateGenerators();
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(plotworld.worldname);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
final WorldGenerator generator = world.getWorldGenerator();
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setupWorld(final SetupObject object) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
||||
final String world = object.world;
|
||||
int type = object.type;
|
||||
String worldPath = "worlds." + object.world;
|
||||
if (!PS.get().config.contains(worldPath)) {
|
||||
PS.get().config.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection = PS.get().config.getConfigurationSection(worldPath);
|
||||
switch (type) {
|
||||
case 2: {
|
||||
if (object.id != null) {
|
||||
String areaname = object.id + "-" + object.min + "-" + object.max;
|
||||
String areaPath = "areas." + areaname;
|
||||
if (!worldSection.contains(areaPath)) {
|
||||
worldSection.createSection(areaPath);
|
||||
}
|
||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
||||
HashMap<String, Object> options = new HashMap<>();
|
||||
for (final ConfigurationNode step : steps) {
|
||||
options.put(step.getConstant(), step.getValue());
|
||||
}
|
||||
options.put("generator.type", object.type);
|
||||
options.put("generator.terrain", object.terrain);
|
||||
options.put("generator.plugin", object.plotManager);
|
||||
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
|
||||
options.put("generator.init", object.setupGenerator);
|
||||
}
|
||||
for (Entry<String, Object> entry : options.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (worldSection.contains(key)) {
|
||||
Object current = worldSection.get(key);
|
||||
if (!Objects.equals(value, current)) {
|
||||
areaSection.set(key, value);
|
||||
}
|
||||
} else {
|
||||
worldSection.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
GeneratorWrapper<?> gen = generators.get(object.setupGenerator);
|
||||
if ((gen != null) && gen.isFull()) {
|
||||
object.setupGenerator = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
for (final ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager);
|
||||
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
|
||||
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
||||
}
|
||||
GeneratorWrapper<?> gen = generators.get(object.setupGenerator);
|
||||
if ((gen != null) && gen.isFull()) {
|
||||
object.setupGenerator = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
for (final ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (object.setupGenerator != null) {
|
||||
// create world with generator
|
||||
GeneratorWrapper<?> gw = generators.get(object.setupGenerator);
|
||||
WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator();
|
||||
|
||||
WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class)
|
||||
.name(object.world)
|
||||
.loadsOnStartup(true)
|
||||
.keepsSpawnLoaded(false)
|
||||
.dimension(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.FLAT)
|
||||
.usesMapFeatures(false)
|
||||
.enabled(true)
|
||||
.generatorModifiers(wgm)
|
||||
.build();
|
||||
WorldProperties properties = Sponge.getServer().createWorldProperties(settings).get();
|
||||
World worldObj = Sponge.getServer().loadWorld(properties).get();
|
||||
} else {
|
||||
// create vanilla world
|
||||
WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class)
|
||||
.name(object.world)
|
||||
.loadsOnStartup(true)
|
||||
.keepsSpawnLoaded(false)
|
||||
.dimension(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.OVERWORLD)
|
||||
.usesMapFeatures(true)
|
||||
.enabled(true)
|
||||
.build();
|
||||
WorldProperties properties = Sponge.getServer().createWorldProperties(settings).get();
|
||||
World worldObj = Sponge.getServer().loadWorld(properties).get();
|
||||
}
|
||||
return object.world;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeTaskManager extends TaskManager {
|
||||
|
||||
private final AtomicInteger i = new AtomicInteger();
|
||||
|
||||
private final HashMap<Integer, Task> tasks = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public int taskRepeat(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(r);
|
||||
final Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int taskRepeatAsync(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(r);
|
||||
final Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskAsync(final Runnable r) {
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void task(final Runnable r) {
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLater(final Runnable r, final int delay) {
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLaterAsync(final Runnable r, final int delay) {
|
||||
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(final int i) {
|
||||
final Task task = tasks.remove(i);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.title.Title;
|
||||
|
||||
public class SpongeTitleManager extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
final Title title = Title.builder().title(Text.of(head)).subtitle(Text.of(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build();
|
||||
((SpongePlayer) player).player.sendTitle(title);
|
||||
}
|
||||
}
|
450
Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java
Normal file
450
Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java
Normal file
@ -0,0 +1,450 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.block.BlockType;
|
||||
import org.spongepowered.api.block.BlockTypes;
|
||||
import org.spongepowered.api.block.tileentity.Sign;
|
||||
import org.spongepowered.api.block.tileentity.TileEntity;
|
||||
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
|
||||
import org.spongepowered.api.data.value.mutable.ListValue;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.translation.Translatable;
|
||||
import org.spongepowered.api.text.translation.Translation;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.biome.BiomeType;
|
||||
import org.spongepowered.api.world.biome.BiomeTypes;
|
||||
import org.spongepowered.api.world.extent.Extent;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeUtil extends WorldUtil {
|
||||
|
||||
public static Location getLocation(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
private static BiomeType[] biomes;
|
||||
private static HashMap<String, Integer> biomeMap;
|
||||
|
||||
public static BiomeType getBiome(String biome) {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
return biomes[biomeMap.get(biome.toUpperCase())];
|
||||
}
|
||||
|
||||
public static <T> T getCause(Cause cause, Class<T> clazz) {
|
||||
Optional<?> root = Optional.of(cause.root());
|
||||
if (root.isPresent()) {
|
||||
Object source = root.get();
|
||||
if (clazz.isInstance(source)) {
|
||||
return (T) source;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void printCause(String method, Cause cause) {
|
||||
System.out.println(method + ": " + cause.toString());
|
||||
System.out.println(method + ": " + cause.getClass());
|
||||
System.out.println(method + ": " + StringMan.getString(cause.all()));
|
||||
System.out.println(method + ": " + (cause.root()));
|
||||
}
|
||||
|
||||
public static void initBiomeCache() {
|
||||
try {
|
||||
Field[] fields = BiomeTypes.class.getFields();
|
||||
biomes = new BiomeType[fields.length];
|
||||
biomeMap = new HashMap<>();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Field field = fields[i];
|
||||
String name = field.getName();
|
||||
biomeMap.put(name, i);
|
||||
biomes[i] = (BiomeType) field.get(null);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static BiomeType getBiome(int index) {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
return biomes[index];
|
||||
}
|
||||
|
||||
public static Text text(String m) {
|
||||
return Text.of(m);
|
||||
}
|
||||
|
||||
public static Translation getTranslation(final String m) {
|
||||
return new Translatable() {
|
||||
@Override
|
||||
public Translation getTranslation() {
|
||||
return new Translation() {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(final Locale l, final Object... args) {
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(final Locale l) {
|
||||
return m;
|
||||
}
|
||||
};
|
||||
}
|
||||
}.getTranslation();
|
||||
}
|
||||
|
||||
private static HashMap<BlockState, PlotBlock> stateMap;
|
||||
private static BlockState[] stateArray;
|
||||
|
||||
private static void initBlockCache() {
|
||||
try {
|
||||
PS.debug("Caching block id/data: Please wait...");
|
||||
stateArray = new BlockState[Character.MAX_VALUE];
|
||||
stateMap = new HashMap<>();
|
||||
Method methodGetByCombinedId = ReflectionUtils.findMethod(Class.forName("net.minecraft.block.Block"), true, Class.forName("net.minecraft.block.state.IBlockState"), int.class);
|
||||
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
||||
try {
|
||||
BlockState state = (BlockState) methodGetByCombinedId.invoke(null, i);
|
||||
if (state.getType() == BlockTypes.AIR) {
|
||||
continue;
|
||||
}
|
||||
PlotBlock plotBlock = new PlotBlock((short) (i & 0xFFF), (byte) (i >> 12 & 0xF));
|
||||
stateArray[i] = state;
|
||||
stateMap.put(state, plotBlock);
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
PS.debug("Done!");
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockState getBlockState(int id, int data) {
|
||||
if (stateArray == null) {
|
||||
initBlockCache();
|
||||
}
|
||||
return stateArray[id + (data << 12)];
|
||||
}
|
||||
|
||||
public static PlotBlock getPlotBlock(BlockState state) {
|
||||
if (stateMap == null) {
|
||||
initBlockCache();
|
||||
}
|
||||
return stateMap.get(state);
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
|
||||
return getLocation(block.getExtent().getName(), block);
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final Vector3d rot = player.getRotation();
|
||||
final float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
|
||||
}
|
||||
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
|
||||
public static PlotPlayer getPlayer(final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final String name = player.getName();
|
||||
final PlotPlayer pp = UUIDHandler.getPlayer(name);
|
||||
if (pp != null) {
|
||||
return pp;
|
||||
}
|
||||
lastPlotPlayer = new SpongePlayer(player);
|
||||
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player) {
|
||||
if (player instanceof SpongePlayer) {
|
||||
return ((SpongePlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static World lastWorld;
|
||||
private static String last;
|
||||
|
||||
public static World getWorld(final String world) {
|
||||
if (world == last) {
|
||||
return lastWorld;
|
||||
}
|
||||
final Optional<World> optional = Sponge.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return optional.get();
|
||||
}
|
||||
|
||||
public static void removePlayer(final String player) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
}
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn) {
|
||||
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
||||
}
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
|
||||
final Extent extent = origin.getExtent();
|
||||
if (extent == lastWorld) {
|
||||
return last;
|
||||
}
|
||||
if (extent instanceof World) {
|
||||
lastWorld = (World) extent;
|
||||
last = ((World) extent).getName();
|
||||
return last;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc) {
|
||||
final Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
||||
if (!world.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public static Location getLocation(String world, Vector3i position) {
|
||||
return new Location(world, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
|
||||
public static Location getLocation(String world, Vector3d position) {
|
||||
return new Location(world, MathMan.roundInt(position.getX()), MathMan.roundInt(position.getY()), MathMan.roundInt(position.getZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(final PlotBlock block) {
|
||||
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
||||
final BlockType type = state.getType();
|
||||
// TODO check if solid;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
try {
|
||||
|
||||
double match;
|
||||
short id;
|
||||
byte data;
|
||||
final String[] split = name.split(":");
|
||||
if (split.length == 2) {
|
||||
data = Byte.parseByte(split[1]);
|
||||
name = split[0];
|
||||
} else {
|
||||
data = 0;
|
||||
}
|
||||
if (MathMan.isInteger(split[0])) {
|
||||
id = Short.parseShort(split[0]);
|
||||
match = 0;
|
||||
} else {
|
||||
List<BlockType> types = ReflectionUtils.<BlockType> getStaticFields(BlockTypes.class);
|
||||
final StringComparison<BlockType>.ComparisonResult comparison = new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
|
||||
@Override
|
||||
public String getString(final BlockType type) {
|
||||
return type.getId();
|
||||
};
|
||||
}.getBestMatchAdvanced();
|
||||
match = comparison.match;
|
||||
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
||||
}
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
} catch (final Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(final PlotBlock block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getBiomeList() {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
return biomeMap.keySet().toArray(new String[biomeMap.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addItems(final String world, final PlotItem items) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(final String biome) {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
return biomeMap.get(biome.toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBiome(final String world, final int x, final int z) {
|
||||
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(final Location loc) {
|
||||
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||
return SpongeUtil.getPlotBlock(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getSpawn(final String world) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
worldObj.getSpawnLocation();
|
||||
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
result.setY(getHighestBlock(world, result.getX(), result.getZ()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSign(final Location loc) {
|
||||
final World world = SpongeUtil.getWorld(loc.getWorld());
|
||||
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (!block.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final String[] result = new String[4];
|
||||
ListValue<Text> lines = optional.get().lines();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result[i] = lines.get(i).toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world) {
|
||||
return SpongeUtil.getWorld(world) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainWorld() {
|
||||
return Sponge.getServer().getWorlds().iterator().next().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestBlock(String worldname, int x, int z) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
return 64;
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
||||
return y + 1;
|
||||
}
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) {
|
||||
return;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text.add(Text.of(lines[i]));
|
||||
}
|
||||
try {
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (optional.isPresent()) {
|
||||
final SignData offering = optional.get();
|
||||
offering.lines().set(0, Text.of(lines[0]));
|
||||
offering.lines().set(1, Text.of(lines[1]));
|
||||
offering.lines().set(2, Text.of(lines[2]));
|
||||
offering.lines().set(3, Text.of(lines[3]));
|
||||
sign.offer(offering);
|
||||
}
|
||||
} catch (final NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(String worldname, RegionWrapper region, String biomename) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final BiomeType biome = SpongeUtil.getBiome(biomename);
|
||||
for (int x = region.minX; x <= region.maxX; x++) {
|
||||
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||
world.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
public class FastChunk {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
public class FastQueue extends SlowQueue {
|
||||
// TODO FIXME
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
import org.spongepowered.api.world.Chunk;
|
||||
import org.spongepowered.api.world.extent.MutableBiomeArea;
|
||||
import org.spongepowered.api.world.extent.MutableBlockVolume;
|
||||
|
||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class GenChunk extends PlotChunk<Chunk> {
|
||||
|
||||
public boolean modified = false;
|
||||
private final MutableBlockVolume terain;
|
||||
private final MutableBiomeArea biome;
|
||||
private final int bz;
|
||||
private final int bx;
|
||||
|
||||
public GenChunk(MutableBlockVolume terain, MutableBiomeArea biome, ChunkWrapper wrap) {
|
||||
super(wrap);
|
||||
this.bx = wrap.x << 4;
|
||||
this.bz = wrap.z << 4;
|
||||
this.terain = terain;
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAbs() {
|
||||
ChunkWrapper wrap = getChunkWrapper();
|
||||
return SpongeUtil.getWorld(wrap.world).getChunk(wrap.x << 4, 0, wrap.z << 4).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (this.biome != null) {
|
||||
this.biome.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
import org.spongepowered.api.world.Chunk;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
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;
|
||||
|
||||
public class SlowChunk extends PlotChunk<Chunk> {
|
||||
|
||||
public PlotBlock[][] result = new PlotBlock[16][];
|
||||
public int[][] biomes;
|
||||
private PlotBlock lastBlock;
|
||||
|
||||
public SlowChunk(ChunkWrapper chunk) {
|
||||
super(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAbs() {
|
||||
ChunkWrapper loc = getChunkWrapper();
|
||||
return SpongeUtil.getWorld(loc.world).getChunk(loc.x << 4, 0, loc.z << 4).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (biomes == null) {
|
||||
biomes = new int[16][16];
|
||||
}
|
||||
biomes[x][z] = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
if (result[y >> 4] == null) {
|
||||
result[y >> 4] = new PlotBlock[4096];
|
||||
}
|
||||
if (id == lastBlock.id && data == lastBlock.data) {
|
||||
result[MainUtil.CACHE_I[x][y][z]][MainUtil.CACHE_J[x][y][z]] = lastBlock;
|
||||
} else {
|
||||
result[MainUtil.CACHE_I[x][y][z]][MainUtil.CACHE_J[x][y][z]] = new PlotBlock((short) id, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
PlotBlock[] matrix = result[i];
|
||||
if (matrix != null) {
|
||||
toReturn.result[i] = new PlotBlock[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||
toReturn.result = result;
|
||||
return toReturn;
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.world.Chunk;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||
import com.intellectualcrafters.plot.util.PlotQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SlowQueue implements PlotQueue<Chunk> {
|
||||
|
||||
private final ConcurrentHashMap<ChunkWrapper, PlotChunk<Chunk>> blocks = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean setBlock(String world, int x, int y, int z, short id, byte data) {
|
||||
if (y > 255 || y < 0) {
|
||||
return false;
|
||||
}
|
||||
final ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, x >> 4, z >> 4);
|
||||
x = x & 15;
|
||||
z = z & 15;
|
||||
PlotChunk<Chunk> result = blocks.get(wrap);
|
||||
if (result == null) {
|
||||
result = getChunk(wrap);
|
||||
result.setBlock(x, y, z, id, data);
|
||||
final PlotChunk<Chunk> previous = blocks.put(wrap, result);
|
||||
if (previous == null) {
|
||||
return true;
|
||||
}
|
||||
blocks.put(wrap, previous);
|
||||
result = previous;
|
||||
}
|
||||
result.setBlock(x, y, z, id, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(PlotChunk<Chunk> chunk) {
|
||||
blocks.put(chunk.getChunkWrapper(), chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk<Chunk> next() {
|
||||
if (!PS.get().isMainThread(Thread.currentThread())) {
|
||||
throw new IllegalStateException("Must be called from main thread!");
|
||||
}
|
||||
try {
|
||||
if (blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = blocks.entrySet().iterator();
|
||||
final PlotChunk<Chunk> toReturn = iter.next().getValue();
|
||||
if (SetQueue.IMP.isWaiting()) {
|
||||
return null;
|
||||
}
|
||||
iter.remove();
|
||||
execute(toReturn);
|
||||
fixLighting(toReturn, true);
|
||||
return toReturn;
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk<Chunk> next(ChunkWrapper wrap, boolean fixLighting) {
|
||||
if (!PS.get().isMainThread(Thread.currentThread())) {
|
||||
throw new IllegalStateException("Must be called from main thread!");
|
||||
}
|
||||
try {
|
||||
if (blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final PlotChunk<Chunk> toReturn = blocks.remove(wrap);
|
||||
if (toReturn == null) {
|
||||
return null;
|
||||
}
|
||||
execute(toReturn);
|
||||
fixLighting(toReturn, fixLighting);
|
||||
return toReturn;
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
blocks.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param pc
|
||||
*/
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
SlowChunk sc = (SlowChunk) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
chunk.loadChunk(true);
|
||||
Vector3i min = chunk.getBlockMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int i = 0; i < sc.result.length; i++) {
|
||||
PlotBlock[] result2 = sc.result[i];
|
||||
if (result2 == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int x = MainUtil.x_loc[i][j];
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
final int z = MainUtil.z_loc[i][j];
|
||||
PlotBlock newBlock = result2[j];
|
||||
BlockState state = SpongeUtil.getBlockState(newBlock.id, newBlock.data);
|
||||
chunk.setBlock(bx + x, y, bz + z, state, false);
|
||||
}
|
||||
}
|
||||
int[][] biomes = sc.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;
|
||||
}
|
||||
chunk.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param wrap
|
||||
*/
|
||||
@Override
|
||||
public PlotChunk<Chunk> getChunk(ChunkWrapper wrap) {
|
||||
return new SlowChunk(wrap);
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param fixAll
|
||||
*/
|
||||
@Override
|
||||
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
||||
// Do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param locs
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
public SpongeLowerOfflineUUIDWrapper() {
|
||||
// Anything?
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final PlotPlayer player) {
|
||||
return getUUID(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
||||
return getUUID(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
||||
String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
try {
|
||||
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
||||
if (profile != null) {
|
||||
name = profile.getName();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
if (getUUID(profile.getName()).equals(uuid)) {
|
||||
name = profile.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final String username = name;
|
||||
return new OfflinePlotPlayer() {
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return UUIDHandler.getPlayer(uuid) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Player[] getOnlinePlayers() {
|
||||
Collection<Player> onlinePlayers = SpongeMain.THIS.getServer().getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final PlotPlayer player) {
|
||||
return ((SpongePlayer) player).player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
||||
return player.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final String name) {
|
||||
try {
|
||||
return SpongeMain.THIS.getResolver().get(name, true).get().getUniqueId();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
||||
String name;
|
||||
try {
|
||||
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName();
|
||||
} catch (final Exception e) {
|
||||
name = null;
|
||||
}
|
||||
final String username = name;
|
||||
return new OfflinePlotPlayer() {
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return UUIDHandler.getPlayer(uuid) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.plotsquared.sponge.uuid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
|
||||
|
||||
public SpongeUUIDHandler(final UUIDWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startCaching(final Runnable whenDone) {
|
||||
if (!super.startCaching(whenDone)) {
|
||||
return false;
|
||||
}
|
||||
return cache(whenDone);
|
||||
}
|
||||
|
||||
public boolean cache(final Runnable whenDone) {
|
||||
add(new StringWrapper("*"), DBFunc.everyone);
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
add(new StringWrapper(profile.getName()), profile.getUniqueId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ifFetch.value = uuidWrapper.getUUID(name);
|
||||
TaskManager.runTask(ifFetch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user