From 498e63dbfa6883a7424f334bc7513d011eed4b1c Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 3 Sep 2011 00:41:22 +0100 Subject: [PATCH] Added the ability to access offline players & more reverse lookup fixes in Permissible. By: Dinnerbone --- .../src/main/java/org/bukkit/Bukkit.java | 6 +++- .../src/main/java/org/bukkit/Server.java | 10 ++++++ .../org/bukkit/command/CommandSender.java | 7 +++++ .../bukkit/command/ConsoleCommandSender.java | 4 +++ .../org/bukkit/command/SimpleCommandMap.java | 31 +++++-------------- .../main/java/org/bukkit/entity/Player.java | 3 +- .../bukkit/permissions/PermissibleBase.java | 2 +- .../bukkit/plugin/SimplePluginManager.java | 16 +++++----- 8 files changed, 43 insertions(+), 36 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/Bukkit.java b/paper-api/src/main/java/org/bukkit/Bukkit.java index 5ab3f94e0f..ca1e537a73 100644 --- a/paper-api/src/main/java/org/bukkit/Bukkit.java +++ b/paper-api/src/main/java/org/bukkit/Bukkit.java @@ -220,7 +220,11 @@ public final class Bukkit { server.shutdown(); } - public int broadcast(String message, String permission) { + public static int broadcast(String message, String permission) { return server.broadcast(message, permission); } + + public static OfflinePlayer getOfflinePlayer(String name) { + return server.getOfflinePlayer(name); + } } diff --git a/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index 1edceb1801..51b90f4ebe 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/src/main/java/org/bukkit/Server.java @@ -375,4 +375,14 @@ public interface Server { * @return Amount of users who received the message */ public int broadcast(String message, String permission); + + /** + * Gets the player by the given name, regardless if they are offline or online. + * + * This will return an object even if the player does not exist. To this method, all players will exist. + * + * @param name Name of the player to retrieve + * @return OfflinePlayer object + */ + public OfflinePlayer getOfflinePlayer(String name); } diff --git a/paper-api/src/main/java/org/bukkit/command/CommandSender.java b/paper-api/src/main/java/org/bukkit/command/CommandSender.java index 555ba1b3ec..7bc46c53a7 100644 --- a/paper-api/src/main/java/org/bukkit/command/CommandSender.java +++ b/paper-api/src/main/java/org/bukkit/command/CommandSender.java @@ -18,4 +18,11 @@ public interface CommandSender extends Permissible { * @return Server instance */ public Server getServer(); + + /** + * Gets the name of this command sender + * + * @return Name of the sender + */ + public String getName(); } diff --git a/paper-api/src/main/java/org/bukkit/command/ConsoleCommandSender.java b/paper-api/src/main/java/org/bukkit/command/ConsoleCommandSender.java index 72ba11ce11..b63e873345 100644 --- a/paper-api/src/main/java/org/bukkit/command/ConsoleCommandSender.java +++ b/paper-api/src/main/java/org/bukkit/command/ConsoleCommandSender.java @@ -83,4 +83,8 @@ public class ConsoleCommandSender implements CommandSender { public Set getEffectivePermissions() { return perm.getEffectivePermissions(); } + + public String getName() { + return "CONSOLE"; + } } diff --git a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java b/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java index f2a02194c5..178edabbde 100644 --- a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -1,31 +1,27 @@ package org.bukkit.command; +import org.bukkit.command.defaults.ReloadCommand; +import org.bukkit.command.defaults.PluginsCommand; import org.bukkit.command.defaults.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Iterator; + +import org.bukkit.ChatColor; import org.bukkit.Server; + +import org.bukkit.plugin.Plugin; import static org.bukkit.util.Java15Compat.Arrays_copyOfRange; public final class SimpleCommandMap implements CommandMap { private final Map knownCommands = new HashMap(); private final Set aliases = new HashSet(); private final Server server; - private static final Set fallbackCommands = new HashSet(); - - static { - fallbackCommands.add(new ListCommand()); - fallbackCommands.add(new StopCommand()); - fallbackCommands.add(new SaveCommand()); - fallbackCommands.add(new SaveOnCommand()); - fallbackCommands.add(new SaveOffCommand()); - fallbackCommands.add(new OpCommand()); - fallbackCommands.add(new DeopCommand()); - } public SimpleCommandMap(final Server server) { this.server = server; @@ -114,16 +110,6 @@ public final class SimpleCommandMap implements CommandMap { return registerdPassedLabel; } - private Command getFallback(String label) { - for (Command cmd : fallbackCommands) { - if (label.startsWith(cmd.getName().toLowerCase())) { - return cmd; - } - } - - return null; - } - /** * {@inheritDoc} */ @@ -136,9 +122,6 @@ public final class SimpleCommandMap implements CommandMap { String sentCommandLabel = args[0].toLowerCase(); Command target = getCommand(sentCommandLabel); - if (target == null) { - target = getFallback(sentCommandLabel); - } if (target == null) { return false; } diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index f599f298ff..69d7e173ee 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -9,13 +9,14 @@ import org.bukkit.Material; import org.bukkit.Note; import org.bukkit.OfflinePlayer; import org.bukkit.Statistic; +import org.bukkit.command.CommandSender; import org.bukkit.map.MapView; /** * Represents a player, connected or not * */ -public interface Player extends HumanEntity, OfflinePlayer { +public interface Player extends HumanEntity, CommandSender, OfflinePlayer { /** * Gets the "friendly" name to display of this player. This may include color. * diff --git a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java index 8c2be973a7..ec6fb6ca33 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java +++ b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java @@ -159,7 +159,7 @@ public class PermissibleBase implements Permissible { dirtyPermissions = true; } - private synchronized void calculatePermissions() { + public synchronized void calculatePermissions() { if (dirtyPermissions) { clearPermissions(); Set defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp()); diff --git a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 1c25077ab3..0e611cc3e8 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -449,15 +449,13 @@ public final class SimplePluginManager implements PluginManager { } private void calculatePermissionDefault(Permission perm) { - if (!perm.getChildren().isEmpty()) { - if ((perm.getDefault() == PermissionDefault.OP) || (perm.getDefault() == PermissionDefault.TRUE)) { - defaultPerms.get(true).add(perm); - dirtyPermissibles(true); - } - if ((perm.getDefault() == PermissionDefault.NOT_OP) || (perm.getDefault() == PermissionDefault.TRUE)) { - defaultPerms.get(false).add(perm); - dirtyPermissibles(false); - } + if ((perm.getDefault() == PermissionDefault.OP) || (perm.getDefault() == PermissionDefault.TRUE)) { + defaultPerms.get(true).add(perm); + dirtyPermissibles(true); + } + if ((perm.getDefault() == PermissionDefault.NOT_OP) || (perm.getDefault() == PermissionDefault.TRUE)) { + defaultPerms.get(false).add(perm); + dirtyPermissibles(false); } }