2015-07-27 02:14:34 +10:00
|
|
|
package com.plotsquared.sponge;
|
|
|
|
|
2015-07-27 19:50:04 +02:00
|
|
|
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.Settings;
|
|
|
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.*;
|
2015-07-28 21:38:49 +10:00
|
|
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
|
|
import com.plotsquared.listener.APlotListener;
|
2015-07-28 16:06:19 +10:00
|
|
|
|
2015-07-27 02:14:34 +10:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.spongepowered.api.Game;
|
2015-07-28 21:38:49 +10:00
|
|
|
import org.spongepowered.api.GameRegistry;
|
|
|
|
import org.spongepowered.api.MinecraftVersion;
|
2015-07-27 02:14:34 +10:00
|
|
|
import org.spongepowered.api.Server;
|
|
|
|
import org.spongepowered.api.entity.player.Player;
|
|
|
|
import org.spongepowered.api.entity.player.gamemode.GameModes;
|
|
|
|
import org.spongepowered.api.event.Subscribe;
|
|
|
|
import org.spongepowered.api.event.entity.player.PlayerChatEvent;
|
|
|
|
import org.spongepowered.api.event.state.PreInitializationEvent;
|
|
|
|
import org.spongepowered.api.event.state.ServerAboutToStartEvent;
|
2015-07-27 04:38:08 +10:00
|
|
|
import org.spongepowered.api.plugin.Plugin;
|
2015-07-27 02:14:34 +10:00
|
|
|
import org.spongepowered.api.plugin.PluginContainer;
|
2015-07-28 21:38:49 +10:00
|
|
|
import org.spongepowered.api.service.profile.GameProfileResolver;
|
2015-07-27 02:14:34 +10:00
|
|
|
import org.spongepowered.api.world.DimensionTypes;
|
|
|
|
import org.spongepowered.api.world.GeneratorTypes;
|
|
|
|
import org.spongepowered.api.world.World;
|
|
|
|
|
2015-07-27 19:50:04 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.UUID;
|
2015-07-27 02:14:34 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by robin on 01/11/2014
|
|
|
|
*/
|
|
|
|
|
2015-07-27 04:38:08 +10:00
|
|
|
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0")
|
2015-07-27 02:14:34 +10:00
|
|
|
public class SpongeMain implements IPlotMain, PluginContainer {
|
|
|
|
public static SpongeMain THIS;
|
|
|
|
|
|
|
|
@Inject private Logger logger;
|
|
|
|
@Inject private Game game;
|
|
|
|
private Server server;
|
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
private GameProfileResolver resolver;
|
|
|
|
|
2015-07-27 02:14:34 +10:00
|
|
|
private WorldModify modify;
|
2015-07-28 21:38:49 +10:00
|
|
|
|
|
|
|
private Object plugin;
|
|
|
|
|
|
|
|
// stuff //
|
|
|
|
public Logger getLogger() {
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Game getGame() {
|
|
|
|
return game;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Server getServer() {
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GameProfileResolver getResolver() {
|
|
|
|
return resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getPlugin() {
|
|
|
|
return this.plugin;
|
|
|
|
}
|
|
|
|
/////////
|
2015-07-27 02:14:34 +10:00
|
|
|
|
|
|
|
////////////////////// SPONGE PLUGIN REGISTRATION ////////////////////
|
|
|
|
@Override
|
|
|
|
public String getId() {
|
|
|
|
return "PlotSquared";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getInstance() {
|
|
|
|
return THIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "PlotSquared";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getVersion() {
|
|
|
|
int[] version = PS.get().getVersion();
|
|
|
|
String result = "";
|
|
|
|
String prefix = "";
|
|
|
|
for (int i : version) {
|
|
|
|
result += prefix + i;
|
|
|
|
prefix = ".";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
///////////////////// ON ENABLE /////////////////////
|
|
|
|
@Subscribe
|
|
|
|
public void onInit(PreInitializationEvent event) {
|
2015-07-27 04:38:08 +10:00
|
|
|
log("PRE INIT");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
public void onServerAboutToStart(ServerAboutToStartEvent event) {
|
|
|
|
log("INIT");
|
2015-07-27 02:14:34 +10:00
|
|
|
THIS = this;
|
2015-07-27 04:38:08 +10:00
|
|
|
|
2015-07-28 21:38:49 +10:00
|
|
|
// resolver
|
|
|
|
resolver = game.getServiceManager().provide(GameProfileResolver.class).get();
|
|
|
|
plugin = game.getPluginManager().getPlugin("PlotSquared").get().getInstance();
|
|
|
|
|
|
|
|
PS.instance = new PS(this);
|
2015-07-27 04:38:08 +10:00
|
|
|
|
|
|
|
// Set the generators for each world...
|
2015-07-27 02:14:34 +10:00
|
|
|
server = game.getServer();
|
|
|
|
Collection<World> worlds = server.getWorlds();
|
|
|
|
if (worlds.size() > 0) {
|
2015-07-27 04:38:08 +10:00
|
|
|
log("INJECTING WORLDS!!!!!!!");
|
2015-07-27 02:14:34 +10:00
|
|
|
for (World world : server.getWorlds()) {
|
2015-07-27 04:38:08 +10:00
|
|
|
log("INJECTING WORLD: " + world.getName());
|
2015-07-27 02:14:34 +10:00
|
|
|
world.setWorldGenerator(new SpongePlotGenerator(world.getName()));
|
|
|
|
}
|
|
|
|
}
|
2015-07-27 04:38:08 +10:00
|
|
|
|
|
|
|
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
|
2015-07-28 21:38:49 +10:00
|
|
|
if (worldSection != null) {
|
|
|
|
for (String world : worldSection.getKeys(false)) {
|
|
|
|
this.modify = new WorldModify(this);
|
|
|
|
Game game = event.getGame();
|
|
|
|
game.getRegistry().registerWorldGeneratorModifier(modify);
|
|
|
|
game.getRegistry().getWorldBuilder()
|
|
|
|
.name(world)
|
|
|
|
.enabled(true)
|
|
|
|
.loadsOnStartup(true)
|
|
|
|
.keepsSpawnLoaded(true)
|
|
|
|
.dimensionType(DimensionTypes.OVERWORLD)
|
|
|
|
.generator(GeneratorTypes.DEBUG)
|
|
|
|
.gameMode(GameModes.CREATIVE)
|
|
|
|
.generatorModifiers(modify)
|
|
|
|
.build();
|
|
|
|
}
|
2015-07-27 04:38:08 +10:00
|
|
|
}
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
public void onPlayerChat(PlayerChatEvent event) {
|
|
|
|
// This is how events sort of work?
|
|
|
|
Player player = event.getUser();
|
|
|
|
log(player.getWorld().getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void log(String message) {
|
2015-07-27 04:42:27 +10:00
|
|
|
message = ConsoleColors.fromString(message);
|
2015-07-27 02:14:34 +10:00
|
|
|
logger.info(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File getDirectory() {
|
|
|
|
return new File("mods/PlotSquared");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disable() {
|
|
|
|
PS.get().disable();
|
|
|
|
THIS = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getPluginVersion() {
|
2015-07-28 21:38:49 +10:00
|
|
|
PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
|
|
|
String version = plugin.getVersion();
|
|
|
|
log("Checking plugin version: PlotSquared: ");
|
|
|
|
String[] split = version.split("\\.");
|
|
|
|
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getServerVersion() {
|
2015-07-28 21:38:49 +10:00
|
|
|
log("Checking minecraft version: Sponge: ");
|
|
|
|
String version = game.getPlatform().getMinecraftVersion().getName();
|
|
|
|
String[] split = version.split("\\.");
|
|
|
|
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TaskManager getTaskManager() {
|
2015-07-28 21:38:49 +10:00
|
|
|
return new SpongeTaskManager();
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void runEntityTask() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("runEntityTask is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerCommands() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerCommands is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerPlayerEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerPlayerEvents is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerInventoryEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerInventoryEvents is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerPlotPlusEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerPlotPlusEvents is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerForceFieldEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerForceFieldEvents is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerWorldEditEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerWorldEditEvents is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerTNTListener() {
|
|
|
|
// TODO Auto-generated method stub
|
2015-07-28 21:38:49 +10:00
|
|
|
log("registerTNTListener is not implemented!");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconHandler getEconomyHandler() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockManager initBlockManager() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EventUtil initEventUtil() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChunkManager initChunkManager() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SetupUtils initSetupUtils() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HybridUtils initHybridUtils() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-27 19:14:28 +10:00
|
|
|
public UUIDHandlerImplementation initUUIDHandler() {
|
2015-07-28 21:38:49 +10:00
|
|
|
UUIDWrapper wrapper;
|
|
|
|
if (Settings.OFFLINE_MODE || !PS.get().checkVersion(this.getServerVersion(), 1, 7, 6)) {
|
|
|
|
wrapper = new SpongeLowerOfflineUUIDWrapper();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wrapper = new SpongeOnlineUUIDWrapper();
|
|
|
|
}
|
|
|
|
return new SpongeUUIDHandler(wrapper);
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InventoryUtil initInventoryUtil() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean initPlotMeConverter() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unregister(PlotPlayer player) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-27 04:38:08 +10:00
|
|
|
public SpongeGeneratorWrapper getGenerator(String world, String name) {
|
2015-07-27 02:14:34 +10:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public APlotListener initPlotListener() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerChunkProcessor() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerWorldEvents() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerManager initPlayerManager() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getServerName() {
|
2015-07-28 21:38:49 +10:00
|
|
|
// TODO FIXME
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|
2015-07-28 16:06:19 +10:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startMetrics() {
|
2015-07-28 21:38:49 +10:00
|
|
|
try {
|
|
|
|
final SpongeMetrics metrics = new SpongeMetrics(game, this);
|
|
|
|
metrics.start();
|
|
|
|
log(C.PREFIX.s() + "&6Metrics enabled.");
|
|
|
|
} catch (final Exception e) {
|
|
|
|
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
|
|
|
}
|
2015-07-28 16:06:19 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGenerator(String world) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
2015-07-27 02:14:34 +10:00
|
|
|
}
|