From 5f5a1797ad18390c0a2dcf182891c5032014cff8 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 17 Jun 2018 22:04:35 +1000 Subject: [PATCH] Remove legacy ServerInterface --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 1 - .../com/sk89q/worldedit/blocks/LazyBlock.java | 16 --- .../com/sk89q/worldedit/ServerInterface.java | 33 ----- .../java/com/sk89q/worldedit/WorldEdit.java | 13 +- .../worldedit/command/WorldEditCommands.java | 2 +- .../extension/factory/DefaultBlockParser.java | 7 +- .../extension/platform/PlatformManager.java | 12 -- .../internal/ServerInterfaceAdapter.java | 135 ------------------ .../worldedit/sponge/SpongeWorldEdit.java | 6 + 9 files changed, 14 insertions(+), 211 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/ServerInterface.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 903a54d10..5454cb799 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -79,7 +79,6 @@ public class BukkitWorld extends AbstractWorld { * * @param world the world */ - @SuppressWarnings("unchecked") public BukkitWorld(World world) { this.worldRef = new WeakReference<>(world); } diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java index 6e3a7e9b4..e70bd31ab 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java @@ -62,22 +62,6 @@ public class LazyBlock extends BaseBlock { this.position = position; } - /** - * Create a new lazy block. - * - * @param type the block type - * @param extent the extent to later load the full block data from - * @param position the position to later load the full block data from - */ - @Deprecated - public LazyBlock(int type, Extent extent, Vector position) { - super(type); - checkNotNull(extent); - checkNotNull(position); - this.extent = extent; - this.position = position; - } - /** * Create a new lazy block. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/ServerInterface.java b/worldedit-core/src/main/java/com/sk89q/worldedit/ServerInterface.java deleted file mode 100644 index 8012fce15..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/ServerInterface.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit; - -import com.sk89q.worldedit.extension.platform.AbstractPlatform; -import com.sk89q.worldedit.extension.platform.Platform; - -/** - * A legacy abstract class that is to be replaced with {@link Platform}. - * Extend {@link AbstractPlatform} instead. - * - * @deprecated Use {@link Platform} wherever possible - */ -@Deprecated -public abstract class ServerInterface extends AbstractPlatform { -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 52124861a..761f4fb60 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -35,6 +35,7 @@ import com.sk89q.worldedit.extension.factory.ItemFactory; import com.sk89q.worldedit.extension.factory.MaskFactory; import com.sk89q.worldedit.extension.factory.PatternFactory; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extent.inventory.BlockBag; @@ -601,7 +602,8 @@ public class WorldEdit { } LocalSession session = getSessionManager().get(player); - CraftScriptContext scriptContext = new CraftScriptContext(this, getServer(), getConfiguration(), session, player, args); + CraftScriptContext scriptContext = new CraftScriptContext(this, getPlatformManager().queryCapability(Capability.USER_COMMANDS), + getConfiguration(), session, player, args); CraftScriptEngine engine; @@ -649,15 +651,6 @@ public class WorldEdit { return getPlatformManager().getConfiguration(); } - /** - * Get the server interface. - * - * @return the server interface - */ - public ServerInterface getServer() { - return getPlatformManager().getServerInterface(); - } - /** * Get a factory for {@link EditSession}s. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 1c40eb8f6..6cfa41059 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -78,7 +78,7 @@ public class WorldEditCommands { ) @CommandPermissions("worldedit.reload") public void reload(Actor actor) throws WorldEditException { - we.getServer().reload(); + we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload(); we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration())); actor.print("Configuration reloaded!"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java index 9878ec3b2..2147d05e0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.world.World; @@ -153,12 +154,12 @@ class DefaultBlockParser extends InputParser { } catch (NumberFormatException e) { blockType = BlockType.lookup(testId); if (blockType == null) { - int t = worldEdit.getServer().resolveItem(testId); + int t = worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).resolveItem(testId); if (t >= 0) { blockType = BlockType.fromID(t); // Could be null blockId = t; } else if (blockLocator.length == 2) { // Block IDs in MC 1.7 and above use mod:name - t = worldEdit.getServer().resolveItem(blockAndExtraData[0]); + t = worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).resolveItem(blockAndExtraData[0]); if (t >= 0) { blockType = BlockType.fromID(t); // Could be null blockId = t; @@ -306,7 +307,7 @@ class DefaultBlockParser extends InputParser { break; } } - if (!worldEdit.getServer().isValidMobType(mobName)) { + if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) { throw new NoMatchException("Unknown mob type '" + mobName + "'"); } return new MobSpawnerBlock(data, mobName); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 5a42e67c0..356ad5c58 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.tool.BlockTool; @@ -39,7 +38,6 @@ import com.sk89q.worldedit.event.platform.PlatformInitializeEvent; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.event.platform.PlayerInputEvent; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; -import com.sk89q.worldedit.internal.ServerInterfaceAdapter; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -286,16 +284,6 @@ public class PlatformManager { return queryCapability(Capability.CONFIGURATION).getConfiguration(); } - /** - * Return a legacy {@link ServerInterface}. - * - * @return a {@link ServerInterface} - * @throws IllegalStateException if no platform has been registered - */ - public ServerInterface getServerInterface() throws IllegalStateException { - return ServerInterfaceAdapter.adapt(queryCapability(Capability.USER_COMMANDS)); - } - @Subscribe public void handlePlatformReady(PlatformReadyEvent event) { choosePreferred(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java deleted file mode 100644 index 32d0922cc..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.internal; - -import com.sk89q.worldedit.LocalConfiguration; -import com.sk89q.worldedit.ServerInterface; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extension.platform.Platform; -import com.sk89q.worldedit.extension.platform.Preference; -import com.sk89q.worldedit.util.command.Dispatcher; -import com.sk89q.worldedit.world.World; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Adapts {@link Platform}s into the legacy {@link ServerInterface}. - */ -public class ServerInterfaceAdapter extends ServerInterface { - - private final Platform platform; - - /** - * Create a new adapter. - * - * @param platform the platform - */ - private ServerInterfaceAdapter(Platform platform) { - checkNotNull(platform); - this.platform = platform; - } - - @Override - public int resolveItem(String name) { - return platform.resolveItem(name); - } - - @Override - public boolean isValidMobType(String type) { - return platform.isValidMobType(type); - } - - @Override - public void reload() { - platform.reload(); - } - - @Override - public int schedule(long delay, long period, Runnable task) { - return platform.schedule(delay, period, task); - } - - @Override - public List getWorlds() { - return platform.getWorlds(); - } - - @Nullable - @Override - public Player matchPlayer(Player player) { - return platform.matchPlayer(player); - } - - @Nullable - @Override - public World matchWorld(World world) { - return platform.matchWorld(world); - } - - @Override - public void registerCommands(Dispatcher dispatcher) { - platform.registerCommands(dispatcher); - } - - @Override - public void registerGameHooks() { - } - - @Override - public LocalConfiguration getConfiguration() { - return platform.getConfiguration(); - } - - @Override - public String getVersion() { - return platform.getVersion(); - } - - @Override - public String getPlatformName() { - return platform.getPlatformName(); - } - - @Override - public String getPlatformVersion() { - return platform.getPlatformVersion(); - } - - @Override - public Map getCapabilities() { - return platform.getCapabilities(); - } - - /** - * Adapt an {@link Platform} instance into a {@link ServerInterface}. - * - * @param platform the platform - * @return the server interface - */ - public static ServerInterface adapt(Platform platform) { - return new ServerInterfaceAdapter(platform); - } - -} diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java index ae835075d..e5cb50c3d 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java @@ -50,6 +50,7 @@ import org.spongepowered.api.event.game.state.GamePostInitializationEvent; import org.spongepowered.api.event.game.state.GamePreInitializationEvent; import org.spongepowered.api.event.game.state.GameStartedServerEvent; import org.spongepowered.api.event.game.state.GameStoppingServerEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; @@ -132,9 +133,14 @@ public class SpongeWorldEdit { this.provider = new SpongePermissionsProvider(); for (BlockType blockType : Sponge.getRegistry().getAllOf(BlockType.class)) { + // TODO Handle blockstate stuff com.sk89q.worldedit.blocks.type.BlockTypes.registerBlock(new com.sk89q.worldedit.blocks.type.BlockType(blockType.getId())); } + for (ItemType itemType : Sponge.getRegistry().getAllOf(ItemType.class)) { + com.sk89q.worldedit.blocks.type.ItemTypes.registerItem(new com.sk89q.worldedit.blocks.type.ItemType(itemType.getId())); + } + WorldEdit.getInstance().getPlatformManager().register(platform); }