From d4ba72a83f6a6c52e8298120255acc59b06adc97 Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Mon, 21 Mar 2016 00:53:32 -0500 Subject: [PATCH] Support offline mode from the whitelist command Closes GH-79 --- ...-as-invulnerable-if-they-re-changing.patch | 2 +- ...ne-mode-in-whitelist-command-as-well.patch | 96 ++++++++++++++++++ Spigot-Server-Patches/mc-dev-imports.patch | 97 +++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 Spigot-Server-Patches/Support-offline-mode-in-whitelist-command-as-well.patch diff --git a/Spigot-Server-Patches/Only-mark-player-as-invulnerable-if-they-re-changing.patch b/Spigot-Server-Patches/Only-mark-player-as-invulnerable-if-they-re-changing.patch index 88bdaad5c..5b65d390c 100644 --- a/Spigot-Server-Patches/Only-mark-player-as-invulnerable-if-they-re-changing.patch +++ b/Spigot-Server-Patches/Only-mark-player-as-invulnerable-if-they-re-changing.patch @@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private long ch = System.currentTimeMillis(); private Entity ci = null; - private boolean cj; -+ protected boolean cj; // Paper - public -> protected ++ protected boolean cj; // Paper - private -> protected private int containerCounter; public boolean f; public int ping; diff --git a/Spigot-Server-Patches/Support-offline-mode-in-whitelist-command-as-well.patch b/Spigot-Server-Patches/Support-offline-mode-in-whitelist-command-as-well.patch new file mode 100644 index 000000000..d8b202d2e --- /dev/null +++ b/Spigot-Server-Patches/Support-offline-mode-in-whitelist-command-as-well.patch @@ -0,0 +1,96 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zach Brown <1254957+zachbr@users.noreply.github.com> +Date: Mon, 21 Mar 2016 00:19:18 -0500 +Subject: [PATCH] Support offline mode in whitelist command as well + + +diff --git a/src/main/java/net/minecraft/server/CommandWhitelist.java b/src/main/java/net/minecraft/server/CommandWhitelist.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/CommandWhitelist.java ++++ b/src/main/java/net/minecraft/server/CommandWhitelist.java +@@ -0,0 +0,0 @@ public class CommandWhitelist extends CommandAbstract { + throw new ExceptionUsage("commands.whitelist.add.usage", new Object[0]); + } + ++ // Paper start - Handle offline mode as well ++ /* + gameprofile = minecraftserver.getUserCache().getProfile(astring[1]); + if (gameprofile == null) { + throw new CommandException("commands.whitelist.add.failed", new Object[] { astring[1]}); + } + + minecraftserver.getPlayerList().addWhitelist(gameprofile); ++ */ ++ this.whitelist(minecraftserver, astring[1], true); ++ // Paper end + a(icommandlistener, (ICommand) this, "commands.whitelist.add.success", new Object[] { astring[1]}); + } else if (astring[0].equals("remove")) { + if (astring.length < 2) { + throw new ExceptionUsage("commands.whitelist.remove.usage", new Object[0]); + } + ++ // Paper start - Handle offline mode as well ++ /* + gameprofile = minecraftserver.getPlayerList().getWhitelist().a(astring[1]); + if (gameprofile == null) { + throw new CommandException("commands.whitelist.remove.failed", new Object[] { astring[1]}); + } + + minecraftserver.getPlayerList().removeWhitelist(gameprofile); ++ ++ */ ++ this.whitelist(minecraftserver, astring[1], false); ++ // Paper end + a(icommandlistener, (ICommand) this, "commands.whitelist.remove.success", new Object[] { astring[1]}); + } else if (astring[0].equals("reload")) { + minecraftserver.getPlayerList().reloadWhitelist(); +@@ -0,0 +0,0 @@ public class CommandWhitelist extends CommandAbstract { + return Collections.emptyList(); + } + } ++ ++ /** ++ * Paper - Adds or removes a player from the game whitelist ++ * ++ * @param mcserver running instance of MinecraftServer ++ * @param playerName the player we're going to be whitelisting ++ * @param add whether we're adding or removing from the whitelist ++ */ ++ private void whitelist(MinecraftServer mcserver, String playerName, boolean add) throws CommandException { ++ if (mcserver.getOnlineMode()) { ++ // The reason we essentially copy/pasta NMS code here is because the NMS online-only version ++ // is capable of providing feedback to the person running the command based on whether or ++ // not the player is a real online-mode account ++ GameProfile gameprofile = mcserver.getUserCache().getProfile(playerName); ++ if (gameprofile == null) { ++ if (add) { ++ throw new CommandException("commands.whitelist.add.failed", new Object[] { playerName}); ++ } else { ++ throw new CommandException("commands.whitelist.remove.failed", new Object[] { playerName}); ++ } ++ } ++ ++ if (add) { ++ mcserver.getPlayerList().addWhitelist(gameprofile); ++ } else { ++ mcserver.getPlayerList().removeWhitelist(gameprofile); ++ } ++ } else { ++ // versus our offline version, which will always report success all of the time ++ org.bukkit.OfflinePlayer offlinePlayer = org.bukkit.Bukkit.getOfflinePlayer(playerName); ++ if (add) { ++ offlinePlayer.setWhitelisted(true); ++ } else { ++ offlinePlayer.setWhitelisted(false); ++ } ++ } ++ } ++ ++ // Paper start - Fix decompiler error ++ @Override ++ public int compareTo(ICommand o) { ++ return a((ICommand) o); ++ } ++ // Paper end + } +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/mc-dev-imports.patch b/Spigot-Server-Patches/mc-dev-imports.patch index 92e9e077b..f71df35b6 100644 --- a/Spigot-Server-Patches/mc-dev-imports.patch +++ b/Spigot-Server-Patches/mc-dev-imports.patch @@ -4461,6 +4461,103 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return !astring[0].equalsIgnoreCase("players") ? (astring[0].equalsIgnoreCase("teams") ? i == 2 : false) : (astring.length > 1 && astring[1].equalsIgnoreCase("operation") ? i == 2 || i == 5 : i == 2); + } +} +diff --git a/src/main/java/net/minecraft/server/CommandWhitelist.java b/src/main/java/net/minecraft/server/CommandWhitelist.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/net/minecraft/server/CommandWhitelist.java +@@ -0,0 +0,0 @@ ++package net.minecraft.server; ++ ++import com.mojang.authlib.GameProfile; ++import java.util.Collections; ++import java.util.List; ++ ++public class CommandWhitelist extends CommandAbstract { ++ ++ public CommandWhitelist() {} ++ ++ public String getCommand() { ++ return "whitelist"; ++ } ++ ++ public int a() { ++ return 3; ++ } ++ ++ public String getUsage(ICommandListener icommandlistener) { ++ return "commands.whitelist.usage"; ++ } ++ ++ public void execute(MinecraftServer minecraftserver, ICommandListener icommandlistener, String[] astring) throws CommandException { ++ if (astring.length < 1) { ++ throw new ExceptionUsage("commands.whitelist.usage", new Object[0]); ++ } else { ++ if (astring[0].equals("on")) { ++ minecraftserver.getPlayerList().setHasWhitelist(true); ++ a(icommandlistener, (ICommand) this, "commands.whitelist.enabled", new Object[0]); ++ } else if (astring[0].equals("off")) { ++ minecraftserver.getPlayerList().setHasWhitelist(false); ++ a(icommandlistener, (ICommand) this, "commands.whitelist.disabled", new Object[0]); ++ } else if (astring[0].equals("list")) { ++ icommandlistener.sendMessage(new ChatMessage("commands.whitelist.list", new Object[] { Integer.valueOf(minecraftserver.getPlayerList().getWhitelisted().length), Integer.valueOf(minecraftserver.getPlayerList().getSeenPlayers().length)})); ++ String[] astring1 = minecraftserver.getPlayerList().getWhitelisted(); ++ ++ icommandlistener.sendMessage(new ChatComponentText(a((Object[]) astring1))); ++ } else { ++ GameProfile gameprofile; ++ ++ if (astring[0].equals("add")) { ++ if (astring.length < 2) { ++ throw new ExceptionUsage("commands.whitelist.add.usage", new Object[0]); ++ } ++ ++ gameprofile = minecraftserver.getUserCache().getProfile(astring[1]); ++ if (gameprofile == null) { ++ throw new CommandException("commands.whitelist.add.failed", new Object[] { astring[1]}); ++ } ++ ++ minecraftserver.getPlayerList().addWhitelist(gameprofile); ++ a(icommandlistener, (ICommand) this, "commands.whitelist.add.success", new Object[] { astring[1]}); ++ } else if (astring[0].equals("remove")) { ++ if (astring.length < 2) { ++ throw new ExceptionUsage("commands.whitelist.remove.usage", new Object[0]); ++ } ++ ++ gameprofile = minecraftserver.getPlayerList().getWhitelist().a(astring[1]); ++ if (gameprofile == null) { ++ throw new CommandException("commands.whitelist.remove.failed", new Object[] { astring[1]}); ++ } ++ ++ minecraftserver.getPlayerList().removeWhitelist(gameprofile); ++ a(icommandlistener, (ICommand) this, "commands.whitelist.remove.success", new Object[] { astring[1]}); ++ } else if (astring[0].equals("reload")) { ++ minecraftserver.getPlayerList().reloadWhitelist(); ++ a(icommandlistener, (ICommand) this, "commands.whitelist.reloaded", new Object[0]); ++ } ++ } ++ ++ } ++ } ++ ++ public List tabComplete(MinecraftServer minecraftserver, ICommandListener icommandlistener, String[] astring, BlockPosition blockposition) { ++ if (astring.length == 1) { ++ return a(astring, new String[] { "on", "off", "list", "add", "remove", "reload"}); ++ } else { ++ if (astring.length == 2) { ++ if (astring[0].equals("remove")) { ++ return a(astring, minecraftserver.getPlayerList().getWhitelisted()); ++ } ++ ++ if (astring[0].equals("add")) { ++ return a(astring, minecraftserver.getUserCache().a()); ++ } ++ } ++ ++ return Collections.emptyList(); ++ } ++ } ++} diff --git a/src/main/java/net/minecraft/server/EULA.java b/src/main/java/net/minecraft/server/EULA.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000