mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 04:23:54 +00:00
Added support for dynamic command registration.
This commit is contained in:
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -64,4 +66,8 @@ public abstract class ServerInterface {
|
||||
public List<LocalWorld> getWorlds() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void onCommandRegistration(List<Command> commands) {
|
||||
// Do nothing :)
|
||||
}
|
||||
}
|
||||
|
@ -176,19 +176,19 @@ public class WorldEdit {
|
||||
|
||||
commands.setInjector(new SimpleInjector(this));
|
||||
|
||||
commands.register(ChunkCommands.class);
|
||||
commands.register(ClipboardCommands.class);
|
||||
commands.register(GeneralCommands.class);
|
||||
commands.register(GenerationCommands.class);
|
||||
commands.register(HistoryCommands.class);
|
||||
commands.register(NavigationCommands.class);
|
||||
commands.register(RegionCommands.class);
|
||||
commands.register(ScriptingCommands.class);
|
||||
commands.register(SelectionCommands.class);
|
||||
commands.register(SnapshotUtilCommands.class);
|
||||
commands.register(ToolUtilCommands.class);
|
||||
commands.register(ToolCommands.class);
|
||||
commands.register(UtilityCommands.class);
|
||||
server.onCommandRegistration(commands.registerAndReturn(ChunkCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(ClipboardCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(GeneralCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(GenerationCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(HistoryCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(NavigationCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(RegionCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(ScriptingCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(SelectionCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(SnapshotUtilCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(ToolUtilCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(ToolCommands.class));
|
||||
server.onCommandRegistration(commands.registerAndReturn(UtilityCommands.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1222,27 +1222,7 @@ public class WorldEdit {
|
||||
*/
|
||||
public boolean handleCommand(LocalPlayer player, String[] split) {
|
||||
try {
|
||||
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 (config.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);
|
||||
}
|
||||
split = commandDetection(split);
|
||||
|
||||
// No command found!
|
||||
if (!commands.hasCommand(split[0])) {
|
||||
@ -1337,6 +1317,31 @@ public class WorldEdit {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String[] commandDetection(String[] split) {
|
||||
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 (config.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a WorldEdit script.
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -31,23 +29,30 @@ public class BukkitCommandSender extends LocalPlayer {
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDebug(String msg) {
|
||||
Bukkit.getLogger().log(Level.WARNING, msg);
|
||||
|
||||
for (String part : msg.split("\n")) {
|
||||
sender.sendMessage(part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String msg) {
|
||||
Bukkit.getLogger().info(msg);
|
||||
for (String part : msg.split("\n")) {
|
||||
sender.sendMessage("\u00A7d" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDebug(String msg) {
|
||||
for (String part : msg.split("\n")) {
|
||||
sender.sendMessage("\u00A77" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printError(String msg) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, msg);
|
||||
for (String part : msg.split("\n")) {
|
||||
sender.sendMessage("\u00A7c" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,18 +22,30 @@ package com.sk89q.worldedit.bukkit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.bukkit.util.CommandRegistration;
|
||||
import com.sk89q.bukkit.util.DynamicPluginCommand;
|
||||
import com.sk89q.bukkit.util.FallbackRegistrationListener;
|
||||
import com.sk89q.util.ReflectionUtil;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
public class BukkitServerInterface extends ServerInterface {
|
||||
public Server server;
|
||||
public WorldEditPlugin plugin;
|
||||
private CommandRegistration dynamicCommands;
|
||||
|
||||
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
|
||||
this.plugin = plugin;
|
||||
this.server = server;
|
||||
dynamicCommands = new CommandRegistration(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,4 +80,13 @@ public class BukkitServerInterface extends ServerInterface {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandRegistration(List<Command> commands) {
|
||||
dynamicCommands.registerAll(commands);
|
||||
}
|
||||
|
||||
public void unregisterCommands() {
|
||||
dynamicCommands.unregisterCommands();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
@ -57,7 +58,7 @@ public class WorldEditPlayerListener extends PlayerListener {
|
||||
|
||||
plugin.registerEvent("PLAYER_QUIT", this);
|
||||
plugin.registerEvent("PLAYER_INTERACT", this);
|
||||
plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this);
|
||||
plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this, Event.Priority.Low);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,9 +84,12 @@ public class WorldEditPlayerListener extends PlayerListener {
|
||||
|
||||
String[] split = event.getMessage().split(" ");
|
||||
|
||||
if (plugin.getWorldEdit().handleCommand(plugin.wrapPlayer(event.getPlayer()), split)) {
|
||||
event.setCancelled(true);
|
||||
if (split.length > 0) {
|
||||
split = plugin.getWorldEdit().commandDetection(split);
|
||||
split[0] += "/";
|
||||
}
|
||||
|
||||
event.setMessage(StringUtil.joinString(split, " "));
|
||||
}
|
||||
|
||||
private boolean ignoreLeftClickAir = false;
|
||||
|
@ -56,7 +56,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
/**
|
||||
* The server interface that all server-related API goes through.
|
||||
*/
|
||||
private ServerInterface server;
|
||||
private BukkitServerInterface server;
|
||||
/**
|
||||
* Main WorldEdit instance.
|
||||
*/
|
||||
@ -121,6 +121,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
}
|
||||
controller.clearSessions();
|
||||
config.unload();
|
||||
server.unregisterCommands();
|
||||
this.getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user