mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Implemented PlatformManager, Platform over old platform registration method.
This commit is contained in:
@ -0,0 +1,343 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.command.*;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.logging.LogFormat;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.*;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Handles the registration and invocation of commands.
|
||||
* </p>
|
||||
* This class is primarily for internal usage.
|
||||
*/
|
||||
public final class CommandManager {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
||||
private static final java.util.regex.Pattern numberFormatExceptionPattern = java.util.regex.Pattern.compile("^For input string: \"(.*)\"$");
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
private final CommandsManager<LocalPlayer> commands;
|
||||
private final DynamicStreamHandler dynamicHandler = new DynamicStreamHandler();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
CommandManager(final WorldEdit worldEdit) {
|
||||
checkNotNull(worldEdit);
|
||||
this.worldEdit = worldEdit;
|
||||
|
||||
// Register this instance for command events
|
||||
worldEdit.getEventBus().register(this);
|
||||
|
||||
// Setup the logger
|
||||
logger.addHandler(dynamicHandler);
|
||||
dynamicHandler.setFormatter(new LogFormat());
|
||||
|
||||
// Set up the commands manager
|
||||
commands = new CommandsManagerImpl();
|
||||
commands.setInjector(new SimpleInjector(worldEdit));
|
||||
}
|
||||
|
||||
void register(Platform platform) {
|
||||
logger.log(Level.FINE, "Registering commands with " + platform.getClass().getCanonicalName());
|
||||
|
||||
LocalConfiguration config = platform.getConfiguration();
|
||||
boolean logging = config.logCommands;
|
||||
String path = config.logFile;
|
||||
|
||||
// Register log
|
||||
if (!logging || path.isEmpty()) {
|
||||
dynamicHandler.setHandler(null);
|
||||
} else {
|
||||
File file = new File(config.getWorkingDirectory(), path);
|
||||
|
||||
logger.log(Level.INFO, "Logging WorldEdit commands to " + file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
dynamicHandler.setHandler(new FileHandler(file.getAbsolutePath(), true));
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Could not use command log file " + path + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
register(platform, BiomeCommands.class);
|
||||
register(platform, ChunkCommands.class);
|
||||
register(platform, ClipboardCommands.class);
|
||||
register(platform, GeneralCommands.class);
|
||||
register(platform, GenerationCommands.class);
|
||||
register(platform, HistoryCommands.class);
|
||||
register(platform, NavigationCommands.class);
|
||||
register(platform, RegionCommands.class);
|
||||
register(platform, ScriptingCommands.class);
|
||||
register(platform, SelectionCommands.class);
|
||||
register(platform, SnapshotUtilCommands.class);
|
||||
register(platform, ToolUtilCommands.class);
|
||||
register(platform, ToolCommands.class);
|
||||
register(platform, UtilityCommands.class);
|
||||
}
|
||||
|
||||
void unregister() {
|
||||
dynamicHandler.setHandler(null);
|
||||
}
|
||||
|
||||
private void register(Platform platform, Class<?> clazz) {
|
||||
platform.onCommandRegistration(commands.registerAndReturn(clazz), commands);
|
||||
}
|
||||
|
||||
public CommandsManager<LocalPlayer> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public String[] commandDetection(String[] split) {
|
||||
Request.reset();
|
||||
|
||||
split[0] = split[0].substring(1);
|
||||
|
||||
// Quick script shortcut
|
||||
if (split[0].matches("^[^/].*\\.js$")) {
|
||||
String[] newSplit = new String[split.length + 1];
|
||||
System.arraycopy(split, 0, newSplit, 1, split.length);
|
||||
newSplit[0] = "cs";
|
||||
newSplit[1] = newSplit[1];
|
||||
split = newSplit;
|
||||
}
|
||||
|
||||
String searchCmd = split[0].toLowerCase();
|
||||
|
||||
// Try to detect the command
|
||||
if (commands.hasCommand(searchCmd)) {
|
||||
} else if (worldEdit.getConfiguration().noDoubleSlash && commands.hasCommand("/" + searchCmd)) {
|
||||
split[0] = "/" + split[0];
|
||||
} else if (split[0].length() >= 2 && split[0].charAt(0) == '/'
|
||||
&& commands.hasCommand(searchCmd.substring(1))) {
|
||||
split[0] = split[0].substring(1);
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleCommand(CommandEvent event) {
|
||||
Request.reset();
|
||||
|
||||
LocalPlayer player = event.getPlayer();
|
||||
String[] split = event.getArguments();
|
||||
|
||||
try {
|
||||
split = commandDetection(split);
|
||||
|
||||
// No command found!
|
||||
if (!commands.hasCommand(split[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalSession session = worldEdit.getSession(player);
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
editSession.enableQueue();
|
||||
|
||||
session.tellVersion(player);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
commands.execute(split, player, session, player, editSession);
|
||||
} catch (CommandPermissionsException e) {
|
||||
player.printError("You don't have permission to do this.");
|
||||
} catch (MissingNestedCommandException e) {
|
||||
player.printError(e.getUsage());
|
||||
} catch (CommandUsageException e) {
|
||||
player.printError(e.getMessage());
|
||||
player.printError(e.getUsage());
|
||||
} catch (PlayerNeededException e) {
|
||||
player.printError(e.getMessage());
|
||||
} catch (WrappedCommandException e) {
|
||||
throw e.getCause();
|
||||
} catch (UnhandledCommandException e) {
|
||||
player.printError("Command could not be handled; invalid sender!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
editSession.flushQueue();
|
||||
|
||||
if (worldEdit.getConfiguration().profile) {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
int changed = editSession.getBlockChangeCount();
|
||||
if (time > 0) {
|
||||
double throughput = changed / (time / 1000.0);
|
||||
player.printDebug((time / 1000.0) + "s elapsed (history: "
|
||||
+ changed + " changed; "
|
||||
+ Math.round(throughput) + " blocks/sec).");
|
||||
} else {
|
||||
player.printDebug((time / 1000.0) + "s elapsed.");
|
||||
}
|
||||
}
|
||||
|
||||
worldEdit.flushBlockBag(player, editSession);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
final Matcher matcher = numberFormatExceptionPattern.matcher(e.getMessage());
|
||||
|
||||
if (matcher.matches()) {
|
||||
player.printError("Number expected; string \"" + matcher.group(1) + "\" given.");
|
||||
} else {
|
||||
player.printError("Number expected; string given.");
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
player.printError("Make a region selection first.");
|
||||
} catch (UnknownItemException e) {
|
||||
player.printError("Block name '" + e.getID() + "' was not recognized.");
|
||||
} catch (InvalidItemException e) {
|
||||
player.printError(e.getMessage());
|
||||
} catch (DisallowedItemException e) {
|
||||
player.printError("Block '" + e.getID() + "' not allowed (see WorldEdit configuration).");
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks changed in an operation reached ("
|
||||
+ e.getBlockLimit() + ").");
|
||||
} catch (MaxBrushRadiusException e) {
|
||||
player.printError("Maximum allowed brush size: " + worldEdit.getConfiguration().maxBrushRadius);
|
||||
} catch (MaxRadiusException e) {
|
||||
player.printError("Maximum allowed size: " + worldEdit.getConfiguration().maxRadius);
|
||||
} catch (UnknownDirectionException e) {
|
||||
player.printError("Unknown direction: " + e.getDirection());
|
||||
} catch (InsufficientArgumentsException e) {
|
||||
player.printError(e.getMessage());
|
||||
} catch (EmptyClipboardException e) {
|
||||
player.printError("Your clipboard is empty. Use //copy first.");
|
||||
} catch (InvalidFilenameException e) {
|
||||
player.printError("Filename '" + e.getFilename() + "' invalid: "
|
||||
+ e.getMessage());
|
||||
} catch (FilenameResolutionException e) {
|
||||
player.printError("File '" + e.getFilename() + "' resolution error: "
|
||||
+ e.getMessage());
|
||||
} catch (InvalidToolBindException e) {
|
||||
player.printError("Can't bind tool to "
|
||||
+ ItemType.toHeldName(e.getItemId()) + ": " + e.getMessage());
|
||||
} catch (FileSelectionAbortedException e) {
|
||||
player.printError("File selection aborted.");
|
||||
} catch (WorldEditException e) {
|
||||
player.printError(e.getMessage());
|
||||
} catch (Throwable excp) {
|
||||
player.printError("Please report this error: [See console]");
|
||||
player.printRaw(excp.getClass().getName() + ": " + excp.getMessage());
|
||||
excp.printStackTrace();
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private class CommandsManagerImpl extends CommandsManager<LocalPlayer> {
|
||||
@Override
|
||||
protected void checkPermission(LocalPlayer player, Method method) throws CommandException {
|
||||
if (!player.isPlayer() && !method.isAnnotationPresent(Console.class)) {
|
||||
throw new UnhandledCommandException();
|
||||
}
|
||||
|
||||
super.checkPermission(player, method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(LocalPlayer player, String perm) {
|
||||
return player.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invokeMethod(Method parent, String[] args,
|
||||
LocalPlayer player, Method method, Object instance,
|
||||
Object[] methodArgs, int level) throws CommandException {
|
||||
if (worldEdit.getConfiguration().logCommands) {
|
||||
final Logging loggingAnnotation = method.getAnnotation(Logging.class);
|
||||
|
||||
final Logging.LogMode logMode;
|
||||
if (loggingAnnotation == null) {
|
||||
logMode = null;
|
||||
} else {
|
||||
logMode = loggingAnnotation.value();
|
||||
}
|
||||
|
||||
String msg = "WorldEdit: " + player.getName();
|
||||
if (player.isPlayer()) {
|
||||
msg += " (in \"" + player.getWorld().getName() + "\")";
|
||||
}
|
||||
msg += ": " + StringUtil.joinString(args, " ");
|
||||
if (logMode != null && player.isPlayer()) {
|
||||
Vector position = player.getPosition();
|
||||
final LocalSession session = worldEdit.getSessionManager().get(player);
|
||||
|
||||
switch (logMode) {
|
||||
case PLACEMENT:
|
||||
try {
|
||||
position = session.getPlacementPosition(player);
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case POSITION:
|
||||
msg += " - Position: " + position;
|
||||
break;
|
||||
|
||||
case ALL:
|
||||
msg += " - Position: " + position;
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case ORIENTATION_REGION:
|
||||
msg += " - Orientation: " + player.getCardinalDirection().name();
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case REGION:
|
||||
try {
|
||||
msg += " - Region: " + session.getSelection(player.getWorld());
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
getLogger().info(msg);
|
||||
}
|
||||
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
import com.sk89q.worldedit.BiomeTypes;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a platform that WorldEdit has been implemented for.
|
||||
*/
|
||||
public interface Platform {
|
||||
|
||||
/**
|
||||
* Resolves an item name to its ID.
|
||||
*
|
||||
* @param name The name to look up
|
||||
* @return The id that corresponds to the name, or -1 if no such ID exists
|
||||
*/
|
||||
int resolveItem(String name);
|
||||
|
||||
/**
|
||||
* Checks if a mob type is valid.
|
||||
*
|
||||
* @param type The mob type name to check
|
||||
* @return Whether the name is a valid mod bype
|
||||
*/
|
||||
boolean isValidMobType(String type);
|
||||
|
||||
/**
|
||||
* Reload WorldEdit configuration.
|
||||
*/
|
||||
void reload();
|
||||
|
||||
/**
|
||||
* Returns all available biomes.
|
||||
*
|
||||
* @return an object containing all the biomes
|
||||
*/
|
||||
BiomeTypes getBiomes();
|
||||
|
||||
/**
|
||||
* Schedules the given <code>task</code> to be invoked once every <code>period</code> ticks
|
||||
* after an initial delay of <code>delay</code> ticks.
|
||||
*
|
||||
* @param delay Delay in server ticks before executing first repeat
|
||||
* @param period Period in server ticks of the task
|
||||
* @param task Task to be executed
|
||||
* @return Task id number (-1 if scheduling failed)
|
||||
*/
|
||||
int schedule(long delay, long period, Runnable task);
|
||||
|
||||
List<LocalWorld> getWorlds();
|
||||
|
||||
@Deprecated
|
||||
void onCommandRegistration(List<Command> commands);
|
||||
|
||||
void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager);
|
||||
|
||||
/**
|
||||
* Get the configuration from this platform.
|
||||
*
|
||||
* @return the configuration
|
||||
*/
|
||||
LocalConfiguration getConfiguration();
|
||||
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Manages registered {@link Platform}s for WorldEdit. Platforms are
|
||||
* implementations of WorldEdit.
|
||||
* </p>
|
||||
* This class is thread-safe.
|
||||
*/
|
||||
public class PlatformManager {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PlatformManager.class.getCanonicalName());
|
||||
|
||||
private final LocalConfiguration defaultConfig = new DefaultConfiguration();
|
||||
private final List<Platform> platforms = new ArrayList<Platform>();
|
||||
private final CommandManager commandManager;
|
||||
private @Nullable Platform primary = null;
|
||||
|
||||
/**
|
||||
* Create a new platform manager.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public PlatformManager(WorldEdit worldEdit) {
|
||||
checkNotNull(worldEdit);
|
||||
this.commandManager = new CommandManager(worldEdit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a platform with WorldEdit.
|
||||
*
|
||||
* @param platform the platform
|
||||
* @throws PlatformRejectionException thrown if the registration is rejected
|
||||
*/
|
||||
public synchronized void register(Platform platform) throws PlatformRejectionException {
|
||||
checkNotNull(platform);
|
||||
logger.log(Level.FINE, "Got request to register " + platform.getClass().getCanonicalName() + " with WorldEdit");
|
||||
platforms.add(platform);
|
||||
if (this.primary == null) {
|
||||
commandManager.register(platform);
|
||||
this.primary = platform;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a platform from WorldEdit.
|
||||
*
|
||||
* @param platform the platform
|
||||
*/
|
||||
public synchronized boolean unregister(Platform platform) {
|
||||
checkNotNull(platform);
|
||||
boolean removed = platforms.remove(platform);
|
||||
if (removed) {
|
||||
logger.log(Level.FINE, "Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit");
|
||||
|
||||
if (platform == primary) {
|
||||
primary = null;
|
||||
commandManager.unregister();
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command manager.
|
||||
*
|
||||
* @return the command manager
|
||||
*/
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configuration.
|
||||
* </p>
|
||||
* If no platform has been registered yet, then a default configuration
|
||||
* will be returned.
|
||||
*
|
||||
* @return the configuration
|
||||
*/
|
||||
public LocalConfiguration getConfiguration() {
|
||||
Platform platform = primary;
|
||||
if (platform != null) {
|
||||
return platform.getConfiguration();
|
||||
} else {
|
||||
return defaultConfig;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return a {@link Platform}.
|
||||
*
|
||||
* @return a {@link Platform}
|
||||
* @throws IllegalStateException if no platform has been registered
|
||||
*/
|
||||
public Platform getPlatform() throws IllegalStateException {
|
||||
Platform platform = primary;
|
||||
if (platform != null) {
|
||||
return platform;
|
||||
} else {
|
||||
throw new IllegalStateException("No platform has been registered");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a legacy {@link ServerInterface}.
|
||||
*
|
||||
* @return a {@link ServerInterface}
|
||||
* @throws IllegalStateException if no platform has been registered
|
||||
*/
|
||||
public ServerInterface getServerInterface() throws IllegalStateException {
|
||||
Platform platform = primary;
|
||||
if (platform != null) {
|
||||
if (platform instanceof ServerInterface) {
|
||||
return (ServerInterface) platform;
|
||||
} else {
|
||||
return new ServerInterfaceAdapter(platform);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("No platform has been registered");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A default configuration for when none is set.
|
||||
*/
|
||||
private static class DefaultConfiguration extends LocalConfiguration {
|
||||
@Override
|
||||
public void load() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
/**
|
||||
* Thrown when a platform registration request is rejected, which may
|
||||
* be because another platform is already registered.
|
||||
*/
|
||||
public class PlatformRejectionException extends WorldEditException {
|
||||
|
||||
/**
|
||||
* Create with a message.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public PlatformRejectionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with a message and a cause.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public PlatformRejectionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Adapts {@link Platform}s into the legacy {@link ServerInterface}.
|
||||
*/
|
||||
class ServerInterfaceAdapter extends ServerInterface {
|
||||
|
||||
private final Platform platform;
|
||||
|
||||
/**
|
||||
* Create a new adapter.
|
||||
*
|
||||
* @param platform the platform
|
||||
*/
|
||||
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 BiomeTypes getBiomes() {
|
||||
return platform.getBiomes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int schedule(long delay, long period, Runnable task) {
|
||||
return platform.schedule(delay, period, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalWorld> getWorlds() {
|
||||
return platform.getWorlds();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void onCommandRegistration(List<Command> commands) {
|
||||
platform.onCommandRegistration(commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
|
||||
platform.onCommandRegistration(commands, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalConfiguration getConfiguration() {
|
||||
return platform.getConfiguration();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user