mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 14:33:56 +01:00
[Bleeding] Implement Mojang command fallback system. Adds BUKKIT-5385
This commit is contained in:
parent
b18bedd848
commit
553acdf0cd
@ -6,6 +6,7 @@ import java.util.Date;
|
|||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
@ -94,14 +95,23 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure this is a valid command
|
// If the world has no players don't run
|
||||||
if (commandMap.getCommand(args[0]) == null) {
|
if (this.getWorld().players.isEmpty()) {
|
||||||
this.b = 0;
|
this.b = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the world has no players don't run
|
// Handle vanilla commands;
|
||||||
if (this.getWorld().players.isEmpty()) {
|
if (minecraftserver.server.getCommandBlockOverride(args[0])) {
|
||||||
|
org.bukkit.command.Command commandBlockCommand = commandMap.getCommand("minecraft:" + args[0]);
|
||||||
|
if (commandBlockCommand instanceof VanillaCommandWrapper) {
|
||||||
|
this.b = ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommandBlock(this, this.e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure this is a valid command
|
||||||
|
if (commandMap.getCommand(args[0]) == null) {
|
||||||
this.b = 0;
|
this.b = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -23,6 +24,47 @@ import javax.imageio.ImageIO;
|
|||||||
|
|
||||||
import net.minecraft.server.BanEntry;
|
import net.minecraft.server.BanEntry;
|
||||||
import net.minecraft.server.ChunkCoordinates;
|
import net.minecraft.server.ChunkCoordinates;
|
||||||
|
import net.minecraft.server.CommandAchievement;
|
||||||
|
import net.minecraft.server.CommandBan;
|
||||||
|
import net.minecraft.server.CommandBanIp;
|
||||||
|
import net.minecraft.server.CommandBanList;
|
||||||
|
import net.minecraft.server.CommandClear;
|
||||||
|
import net.minecraft.server.CommandDeop;
|
||||||
|
import net.minecraft.server.CommandDifficulty;
|
||||||
|
import net.minecraft.server.CommandEffect;
|
||||||
|
import net.minecraft.server.CommandEnchant;
|
||||||
|
import net.minecraft.server.CommandGamemode;
|
||||||
|
import net.minecraft.server.CommandGamemodeDefault;
|
||||||
|
import net.minecraft.server.CommandGamerule;
|
||||||
|
import net.minecraft.server.CommandGive;
|
||||||
|
import net.minecraft.server.CommandHelp;
|
||||||
|
import net.minecraft.server.CommandIdleTimeout;
|
||||||
|
import net.minecraft.server.CommandKick;
|
||||||
|
import net.minecraft.server.CommandKill;
|
||||||
|
import net.minecraft.server.CommandList;
|
||||||
|
import net.minecraft.server.CommandMe;
|
||||||
|
import net.minecraft.server.CommandOp;
|
||||||
|
import net.minecraft.server.CommandPardon;
|
||||||
|
import net.minecraft.server.CommandPardonIP;
|
||||||
|
import net.minecraft.server.CommandPlaySound;
|
||||||
|
import net.minecraft.server.CommandSay;
|
||||||
|
import net.minecraft.server.CommandScoreboard;
|
||||||
|
import net.minecraft.server.CommandSeed;
|
||||||
|
import net.minecraft.server.CommandSetBlock;
|
||||||
|
import net.minecraft.server.CommandSetWorldSpawn;
|
||||||
|
import net.minecraft.server.CommandSpawnpoint;
|
||||||
|
import net.minecraft.server.CommandSpreadPlayers;
|
||||||
|
import net.minecraft.server.CommandSummon;
|
||||||
|
import net.minecraft.server.CommandTell;
|
||||||
|
import net.minecraft.server.CommandTellRaw;
|
||||||
|
import net.minecraft.server.CommandTestFor;
|
||||||
|
import net.minecraft.server.CommandTestForBlock;
|
||||||
|
import net.minecraft.server.CommandTime;
|
||||||
|
import net.minecraft.server.CommandToggleDownfall;
|
||||||
|
import net.minecraft.server.CommandTp;
|
||||||
|
import net.minecraft.server.CommandWeather;
|
||||||
|
import net.minecraft.server.CommandWhitelist;
|
||||||
|
import net.minecraft.server.CommandXp;
|
||||||
import net.minecraft.server.Convertable;
|
import net.minecraft.server.Convertable;
|
||||||
import net.minecraft.server.ConvertProgressUpdater;
|
import net.minecraft.server.ConvertProgressUpdater;
|
||||||
import net.minecraft.server.CraftingManager;
|
import net.minecraft.server.CraftingManager;
|
||||||
@ -77,6 +119,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.conversations.Conversable;
|
import org.bukkit.conversations.Conversable;
|
||||||
|
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||||
import org.bukkit.craftbukkit.help.SimpleHelpMap;
|
import org.bukkit.craftbukkit.help.SimpleHelpMap;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftInventoryCustom;
|
import org.bukkit.craftbukkit.inventory.CraftInventoryCustom;
|
||||||
@ -159,6 +202,7 @@ public final class CraftServer implements Server {
|
|||||||
protected final DedicatedPlayerList playerList;
|
protected final DedicatedPlayerList playerList;
|
||||||
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
|
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
|
||||||
private YamlConfiguration configuration;
|
private YamlConfiguration configuration;
|
||||||
|
private YamlConfiguration commandsConfiguration;
|
||||||
private final Yaml yaml = new Yaml(new SafeConstructor());
|
private final Yaml yaml = new Yaml(new SafeConstructor());
|
||||||
private final Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap();
|
private final Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap();
|
||||||
private final AutoUpdater updater;
|
private final AutoUpdater updater;
|
||||||
@ -178,6 +222,7 @@ public final class CraftServer implements Server {
|
|||||||
public boolean playerCommandState;
|
public boolean playerCommandState;
|
||||||
private boolean printSaveWarning;
|
private boolean printSaveWarning;
|
||||||
private CraftIconCache icon;
|
private CraftIconCache icon;
|
||||||
|
private boolean overrideAllCommandBlockCommands = false;
|
||||||
|
|
||||||
private final class BooleanWrapper {
|
private final class BooleanWrapper {
|
||||||
private boolean value = true;
|
private boolean value = true;
|
||||||
@ -212,7 +257,27 @@ public final class CraftServer implements Server {
|
|||||||
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||||
configuration.options().copyDefaults(true);
|
configuration.options().copyDefaults(true);
|
||||||
configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")));
|
configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")));
|
||||||
|
ConfigurationSection legacyAlias = null;
|
||||||
|
if (!configuration.isString("aliases")) {
|
||||||
|
legacyAlias = configuration.getConfigurationSection("aliases");
|
||||||
|
configuration.set("aliases", "now-in-commands.yml");
|
||||||
|
}
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
if (getCommandsConfigFile().isFile()) {
|
||||||
|
legacyAlias = null;
|
||||||
|
}
|
||||||
|
commandsConfiguration = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
|
||||||
|
commandsConfiguration.options().copyDefaults(true);
|
||||||
|
commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/commands.yml")));
|
||||||
|
saveCommandsConfig();
|
||||||
|
if (legacyAlias != null) {
|
||||||
|
ConfigurationSection aliases = commandsConfiguration.createSection("aliases");
|
||||||
|
for (Entry<String, Object> entry : legacyAlias.getValues(true).entrySet()) {
|
||||||
|
aliases.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveCommandsConfig();
|
||||||
|
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
|
||||||
((SimplePluginManager) pluginManager).useTimings(configuration.getBoolean("settings.plugin-profiling"));
|
((SimplePluginManager) pluginManager).useTimings(configuration.getBoolean("settings.plugin-profiling"));
|
||||||
monsterSpawn = configuration.getInt("spawn-limits.monsters");
|
monsterSpawn = configuration.getInt("spawn-limits.monsters");
|
||||||
animalSpawn = configuration.getInt("spawn-limits.animals");
|
animalSpawn = configuration.getInt("spawn-limits.animals");
|
||||||
@ -235,10 +300,18 @@ public final class CraftServer implements Server {
|
|||||||
enablePlugins(PluginLoadOrder.STARTUP);
|
enablePlugins(PluginLoadOrder.STARTUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getCommandBlockOverride(String command) {
|
||||||
|
return overrideAllCommandBlockCommands || commandsConfiguration.getStringList("command-block-overrides").contains(command);
|
||||||
|
}
|
||||||
|
|
||||||
private File getConfigFile() {
|
private File getConfigFile() {
|
||||||
return (File) console.options.valueOf("bukkit-settings");
|
return (File) console.options.valueOf("bukkit-settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File getCommandsConfigFile() {
|
||||||
|
return (File) console.options.valueOf("commands-settings");
|
||||||
|
}
|
||||||
|
|
||||||
private void saveConfig() {
|
private void saveConfig() {
|
||||||
try {
|
try {
|
||||||
configuration.save(getConfigFile());
|
configuration.save(getConfigFile());
|
||||||
@ -247,6 +320,14 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveCommandsConfig() {
|
||||||
|
try {
|
||||||
|
commandsConfiguration.save(getCommandsConfigFile());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, "Could not save " + getCommandsConfigFile(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void loadPlugins() {
|
public void loadPlugins() {
|
||||||
pluginManager.registerInterface(JavaPluginLoader.class);
|
pluginManager.registerInterface(JavaPluginLoader.class);
|
||||||
|
|
||||||
@ -283,6 +364,8 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == PluginLoadOrder.POSTWORLD) {
|
if (type == PluginLoadOrder.POSTWORLD) {
|
||||||
|
commandMap.setFallbackCommands();
|
||||||
|
setVanillaCommands();
|
||||||
commandMap.registerServerAliases();
|
commandMap.registerServerAliases();
|
||||||
loadCustomPermissions();
|
loadCustomPermissions();
|
||||||
DefaultPermissions.registerCorePermissions();
|
DefaultPermissions.registerCorePermissions();
|
||||||
@ -294,6 +377,50 @@ public final class CraftServer implements Server {
|
|||||||
pluginManager.disablePlugins();
|
pluginManager.disablePlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setVanillaCommands() {
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandAchievement(), "/achievement give <stat_name> [player]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBan(), "/ban <playername> [reason]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanIp(), "/ban-ip <ip-address|playername>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanList(), "/banlist [ips]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandClear(), "/clear <playername> [item] [metadata]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemodeDefault(), "/defaultgamemode <mode>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDeop(), "/deop <playername>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDifficulty(), "/difficulty <new difficulty>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEffect(), "/effect <player> <effect|clear> [seconds] [amplifier]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEnchant(), "/enchant <playername> <enchantment ID> [enchantment level]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemode(), "/gamemode <mode> [player]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamerule(), "/gamerule <rulename> [true|false]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGive(), "/give <playername> <item> [amount] [metadata] [dataTag]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandHelp(), "/help [page|commandname]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandIdleTimeout(), "/setidletimeout <Minutes until kick>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandKick(), "/kick <playername> [reason]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandKill(), "/kill [playername]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandList(), "/list"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandMe(), "/me <actiontext>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandOp(), "/op <playername>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardon(), "/pardon <playername>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardonIP(), "/pardon-ip <ip-address>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPlaySound(), "/playsound <sound> <playername> [x] [y] [z] [volume] [pitch] [minimumVolume]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSay(), "/say <message>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandScoreboard(), "/scoreboard"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSeed(), "/seed"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetBlock(), "/setblock <x> <y> <z> <tilename> [datavalue] [oldblockHandling] [dataTag]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetWorldSpawn(), "/setworldspawn [x] [y] [z]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpawnpoint(), "/spawnpoint <playername> [x] [y] [z]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpreadPlayers(), "/spreadplayers <x> <z> [spreadDistance] [maxRange] [respectTeams] <playernames>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSummon(), "/summon <EntityName> [x] [y] [z] [dataTag]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTp(), "/tp [player] <target>\n/tp [player] <x> <y> <z>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTell(), "/tell <playername> <message>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTellRaw(), "/tellraw <playername> <raw message>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestFor(), "/testfor <playername | selector> [dataTag]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestForBlock(), "/testforblock <x> <y> <z> <tilename> [datavalue] [dataTag]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTime(), "/time set <value>\n/time add <value>"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandToggleDownfall(), "/toggledownfall"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWeather(), "/weather <clear/rain/thunder> [duration in seconds]"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWhitelist(), "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)"));
|
||||||
|
commandMap.register("minecraft", new VanillaCommandWrapper(new CommandXp(), "/xp <amount> [player]\n/xp <amount>L [player]"));
|
||||||
|
}
|
||||||
|
|
||||||
private void loadPlugin(Plugin plugin) {
|
private void loadPlugin(Plugin plugin) {
|
||||||
try {
|
try {
|
||||||
pluginManager.enablePlugin(plugin);
|
pluginManager.enablePlugin(plugin);
|
||||||
@ -555,6 +682,7 @@ public final class CraftServer implements Server {
|
|||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||||
|
commandsConfiguration = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
|
||||||
PropertyManager config = new PropertyManager(console.options);
|
PropertyManager config = new PropertyManager(console.options);
|
||||||
|
|
||||||
((DedicatedServer) console).propertyManager = config;
|
((DedicatedServer) console).propertyManager = config;
|
||||||
@ -601,6 +729,7 @@ public final class CraftServer implements Server {
|
|||||||
pluginManager.clearPlugins();
|
pluginManager.clearPlugins();
|
||||||
commandMap.clearCommands();
|
commandMap.clearCommands();
|
||||||
resetRecipes();
|
resetRecipes();
|
||||||
|
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
|
||||||
|
|
||||||
int pollCount = 0;
|
int pollCount = 0;
|
||||||
|
|
||||||
@ -972,7 +1101,7 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String[]> getCommandAliases() {
|
public Map<String, String[]> getCommandAliases() {
|
||||||
ConfigurationSection section = configuration.getConfigurationSection("aliases");
|
ConfigurationSection section = commandsConfiguration.getConfigurationSection("aliases");
|
||||||
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
|
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
|
||||||
|
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
|
@ -100,6 +100,12 @@ public class Main {
|
|||||||
.defaultsTo(new File("bukkit.yml"))
|
.defaultsTo(new File("bukkit.yml"))
|
||||||
.describedAs("Yml file");
|
.describedAs("Yml file");
|
||||||
|
|
||||||
|
acceptsAll(asList("C", "commands-settings"), "File for command settings")
|
||||||
|
.withRequiredArg()
|
||||||
|
.ofType(File.class)
|
||||||
|
.defaultsTo(new File("commands.yml"))
|
||||||
|
.describedAs("Yml file");
|
||||||
|
|
||||||
acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");
|
acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");
|
||||||
|
|
||||||
acceptsAll(asList("noconsole"), "Disables the console");
|
acceptsAll(asList("noconsole"), "Disables the console");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.bukkit.craftbukkit.command;
|
package org.bukkit.craftbukkit.command;
|
||||||
|
|
||||||
|
import net.minecraft.server.ICommandListener;
|
||||||
import net.minecraft.server.TileEntityCommandListener;
|
import net.minecraft.server.TileEntityCommandListener;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -37,4 +38,8 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
|||||||
public void setOp(boolean value) {
|
public void setOp(boolean value) {
|
||||||
throw new UnsupportedOperationException("Cannot change operator status of a block");
|
throw new UnsupportedOperationException("Cannot change operator status of a block");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommandListener getTileEntity() {
|
||||||
|
return commandBlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,192 @@
|
|||||||
|
package org.bukkit.craftbukkit.command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.server.ChatMessage;
|
||||||
|
import net.minecraft.server.CommandAbstract;
|
||||||
|
import net.minecraft.server.CommandBlockListenerAbstract;
|
||||||
|
import net.minecraft.server.CommandException;
|
||||||
|
import net.minecraft.server.EntityMinecartCommandBlock;
|
||||||
|
import net.minecraft.server.EntityMinecartCommandBlockListener;
|
||||||
|
import net.minecraft.server.EntityPlayer;
|
||||||
|
import net.minecraft.server.EnumChatFormat;
|
||||||
|
import net.minecraft.server.ExceptionUsage;
|
||||||
|
import net.minecraft.server.ICommandListener;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.PlayerSelector;
|
||||||
|
import net.minecraft.server.RemoteControlCommandListener;
|
||||||
|
import net.minecraft.server.TileEntityCommandListener;
|
||||||
|
import net.minecraft.server.WorldServer;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||||
|
import org.bukkit.command.defaults.*;
|
||||||
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftMinecartCommand;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.minecart.CommandMinecart;
|
||||||
|
|
||||||
|
public final class VanillaCommandWrapper extends VanillaCommand {
|
||||||
|
protected final CommandAbstract vanillaCommand;
|
||||||
|
|
||||||
|
public VanillaCommandWrapper(CommandAbstract vanillaCommand) {
|
||||||
|
super(vanillaCommand.c());
|
||||||
|
this.vanillaCommand = vanillaCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VanillaCommandWrapper(CommandAbstract vanillaCommand, String usage) {
|
||||||
|
super(vanillaCommand.c());
|
||||||
|
this.vanillaCommand = vanillaCommand;
|
||||||
|
this.description = "A Mojang provided command.";
|
||||||
|
this.usageMessage = usage;
|
||||||
|
this.setPermission("vanilla.command." + vanillaCommand.c());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||||
|
if (!testPermission(sender)) return true;
|
||||||
|
|
||||||
|
ICommandListener icommandlistener = getListener(sender);
|
||||||
|
// Some commands use the worldserver variable but we leave it full of null values,
|
||||||
|
// so we must temporarily populate it with the world of the commandsender
|
||||||
|
WorldServer[] prev = MinecraftServer.getServer().worldServer;
|
||||||
|
MinecraftServer.getServer().worldServer = new WorldServer[]{(WorldServer) icommandlistener.getWorld()};
|
||||||
|
try {
|
||||||
|
vanillaCommand.b(icommandlistener, args);
|
||||||
|
} catch (ExceptionUsage exceptionusage) {
|
||||||
|
ChatMessage chatmessage = new ChatMessage("commands.generic.usage", new Object[] {new ChatMessage(exceptionusage.getMessage(), exceptionusage.a())});
|
||||||
|
chatmessage.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage);
|
||||||
|
} catch (CommandException commandexception) {
|
||||||
|
ChatMessage chatmessage = new ChatMessage(commandexception.getMessage(), commandexception.a());
|
||||||
|
chatmessage.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage);
|
||||||
|
} finally {
|
||||||
|
MinecraftServer.getServer().worldServer = prev;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
|
Validate.notNull(sender, "Sender cannot be null");
|
||||||
|
Validate.notNull(args, "Arguments cannot be null");
|
||||||
|
Validate.notNull(alias, "Alias cannot be null");
|
||||||
|
return (List<String>) vanillaCommand.a(getListener(sender), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int dispatchVanillaCommandBlock(CommandBlockListenerAbstract icommandlistener, String s) {
|
||||||
|
// Copied from net.minecraft.server.CommandHandler
|
||||||
|
s = s.trim();
|
||||||
|
if (s.startsWith("/")) {
|
||||||
|
s = s.substring(1);
|
||||||
|
}
|
||||||
|
String as[] = s.split(" ");
|
||||||
|
as = dropFirstArgument(as);
|
||||||
|
int i = getPlayerListSize(as);
|
||||||
|
int j = 0;
|
||||||
|
// Some commands use the worldserver variable but we leave it full of null values,
|
||||||
|
// so we must temporarily populate it with the world of the commandsender
|
||||||
|
WorldServer[] prev = MinecraftServer.getServer().worldServer;
|
||||||
|
MinecraftServer.getServer().worldServer = new WorldServer[]{(WorldServer) icommandlistener.getWorld()};
|
||||||
|
try {
|
||||||
|
if (vanillaCommand.a(icommandlistener)) {
|
||||||
|
if (i > -1) {
|
||||||
|
EntityPlayer aentityplayer[] = PlayerSelector.getPlayers(icommandlistener, as[i]);
|
||||||
|
String s2 = as[i];
|
||||||
|
EntityPlayer aentityplayer1[] = aentityplayer;
|
||||||
|
int k = aentityplayer1.length;
|
||||||
|
for (int l = 0; l < k;) {
|
||||||
|
EntityPlayer entityplayer = aentityplayer1[l];
|
||||||
|
as[i] = entityplayer.getName();
|
||||||
|
try {
|
||||||
|
vanillaCommand.b(icommandlistener, as);
|
||||||
|
j++;
|
||||||
|
continue;
|
||||||
|
} catch (CommandException commandexception1) {
|
||||||
|
ChatMessage chatmessage4 = new ChatMessage(commandexception1.getMessage(), commandexception1.a());
|
||||||
|
chatmessage4.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage4);
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
as[i] = s2;
|
||||||
|
} else {
|
||||||
|
vanillaCommand.b(icommandlistener, as);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ChatMessage chatmessage = new ChatMessage("commands.generic.permission", new Object[0]);
|
||||||
|
chatmessage.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage);
|
||||||
|
}
|
||||||
|
} catch (ExceptionUsage exceptionusage) {
|
||||||
|
ChatMessage chatmessage1 = new ChatMessage("commands.generic.usage", new Object[] { new ChatMessage(exceptionusage.getMessage(), exceptionusage.a()) });
|
||||||
|
chatmessage1.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage1);
|
||||||
|
} catch (CommandException commandexception) {
|
||||||
|
ChatMessage chatmessage2 = new ChatMessage(commandexception.getMessage(), commandexception.a());
|
||||||
|
chatmessage2.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage2);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
ChatMessage chatmessage3 = new ChatMessage("commands.generic.exception", new Object[0]);
|
||||||
|
chatmessage3.b().setColor(EnumChatFormat.RED);
|
||||||
|
icommandlistener.sendMessage(chatmessage3);
|
||||||
|
if(icommandlistener instanceof TileEntityCommandListener) {
|
||||||
|
TileEntityCommandListener listener = (TileEntityCommandListener) icommandlistener;
|
||||||
|
MinecraftServer.av().log(Level.WARN, String.format("CommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().x, listener.getChunkCoordinates().y, listener.getChunkCoordinates().z), throwable);
|
||||||
|
} else if (icommandlistener instanceof EntityMinecartCommandBlockListener) {
|
||||||
|
EntityMinecartCommandBlockListener listener = (EntityMinecartCommandBlockListener) icommandlistener;
|
||||||
|
MinecraftServer.av().log(Level.WARN, String.format("MinecartCommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().x, listener.getChunkCoordinates().y, listener.getChunkCoordinates().z), throwable);
|
||||||
|
} else {
|
||||||
|
MinecraftServer.av().log(Level.WARN, String.format("Unknown CommandBlock failed to handle command"), throwable);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
MinecraftServer.getServer().worldServer = prev;
|
||||||
|
}
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICommandListener getListener(CommandSender sender) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
return ((CraftPlayer) sender).getHandle();
|
||||||
|
}
|
||||||
|
if (sender instanceof BlockCommandSender) {
|
||||||
|
return ((CraftBlockCommandSender) sender).getTileEntity();
|
||||||
|
}
|
||||||
|
if (sender instanceof CommandMinecart) {
|
||||||
|
return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).e();
|
||||||
|
}
|
||||||
|
if (sender instanceof RemoteConsoleCommandSender) {
|
||||||
|
return RemoteControlCommandListener.instance;
|
||||||
|
}
|
||||||
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
|
return ((CraftServer) sender.getServer()).getServer();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPlayerListSize(String as[]) {
|
||||||
|
for (int i = 0; i < as.length; i++) {
|
||||||
|
if (vanillaCommand.a(as, i) && PlayerSelector.isList(as[i])) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] dropFirstArgument(String as[]) {
|
||||||
|
String as1[] = new String[as.length - 1];
|
||||||
|
for (int i = 1; i < as.length; i++) {
|
||||||
|
as1[i - 1] = as[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return as1;
|
||||||
|
}
|
||||||
|
}
|
@ -3,10 +3,12 @@ package org.bukkit.craftbukkit.help;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
|
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
import org.bukkit.command.defaults.VanillaCommand;
|
import org.bukkit.command.defaults.VanillaCommand;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||||
import org.bukkit.help.*;
|
import org.bukkit.help.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -131,19 +133,13 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (String alias : command.getAliases()) {
|
for (String alias : command.getAliases()) {
|
||||||
if (!helpTopics.containsKey("/" + alias)) {
|
// Only register if this command owns the alias
|
||||||
|
if (server.getCommandMap().getCommand(alias) == command) {
|
||||||
addTopic(new CommandAliasHelpTopic("/" + alias, "/" + command.getLabel(), this));
|
addTopic(new CommandAliasHelpTopic("/" + alias, "/" + command.getLabel(), this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize help topics from the server's fallback commands
|
|
||||||
for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
|
|
||||||
if (!commandInIgnoredPlugin(command, ignoredPlugins)) {
|
|
||||||
addTopic(new GenericCommandHelpTopic(command));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add alias sub-index
|
// Add alias sub-index
|
||||||
Collection<HelpTopic> filteredTopics = Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class));
|
Collection<HelpTopic> filteredTopics = Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class));
|
||||||
if (!filteredTopics.isEmpty()) {
|
if (!filteredTopics.isEmpty()) {
|
||||||
@ -153,7 +149,6 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
// Initialize plugin-level sub-topics
|
// Initialize plugin-level sub-topics
|
||||||
Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<String, Set<HelpTopic>>();
|
Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<String, Set<HelpTopic>>();
|
||||||
fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands());
|
fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands());
|
||||||
fillPluginIndexes(pluginIndexes, server.getCommandMap().getFallbackCommands());
|
|
||||||
|
|
||||||
for (Map.Entry<String, Set<HelpTopic>> entry : pluginIndexes.entrySet()) {
|
for (Map.Entry<String, Set<HelpTopic>> entry : pluginIndexes.entrySet()) {
|
||||||
addTopic(new IndexHelpTopic(entry.getKey(), "All commands for " + entry.getKey(), null, entry.getValue(), "Below is a list of all " + entry.getKey() + " commands:"));
|
addTopic(new IndexHelpTopic(entry.getKey(), "All commands for " + entry.getKey(), null, entry.getValue(), "Below is a list of all " + entry.getKey() + " commands:"));
|
||||||
@ -186,6 +181,9 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCommandPluginName(Command command) {
|
private String getCommandPluginName(Command command) {
|
||||||
|
if (command instanceof VanillaCommandWrapper) {
|
||||||
|
return "Minecraft";
|
||||||
|
}
|
||||||
if (command instanceof BukkitCommand || command instanceof VanillaCommand) {
|
if (command instanceof BukkitCommand || command instanceof VanillaCommand) {
|
||||||
return "Bukkit";
|
return "Bukkit";
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,7 @@ auto-updater:
|
|||||||
preferred-channel: rb
|
preferred-channel: rb
|
||||||
host: dl.bukkit.org
|
host: dl.bukkit.org
|
||||||
suggest-channels: true
|
suggest-channels: true
|
||||||
aliases:
|
aliases: now-in-commands.yml
|
||||||
# icanhasbukkit:
|
|
||||||
# - version
|
|
||||||
database:
|
database:
|
||||||
username: bukkit
|
username: bukkit
|
||||||
isolation: SERIALIZABLE
|
isolation: SERIALIZABLE
|
||||||
|
4
src/main/resources/configurations/commands.yml
Normal file
4
src/main/resources/configurations/commands.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
command-block-overrides: []
|
||||||
|
aliases:
|
||||||
|
icanhasbukkit:
|
||||||
|
- version
|
Loading…
Reference in New Issue
Block a user