Jelajahi Sumber

Disable partial name matching for offline players by default

#1482
TfT_02 11 tahun lalu
induk
melakukan
933b6f278b

+ 2 - 0
src/main/java/com/gmail/nossr50/config/Config.java

@@ -197,6 +197,8 @@ public class Config extends AutoUpdateConfigLoader {
     public String getAdminChatPrefix() { return config.getString("Commands.a.Chat_Prefix_Format", "[[AQUA]][[[WHITE]]{0}[[AQUA]]]"); }
     public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
 
+    public boolean getMatchOfflinePlayers() { return config.getBoolean("Commands.General.Match_OfflinePlayers", false); }
+
     /* Mob Healthbar */
     public MobHealthbarType getMobHealthbarDefault() {
         try {

+ 14 - 3
src/main/java/com/gmail/nossr50/util/Misc.java

@@ -22,6 +22,7 @@ import org.bukkit.inventory.Inventory;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.metadata.MetadataValue;
 
+import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
 import com.gmail.nossr50.util.player.UserManager;
@@ -283,13 +284,23 @@ public final class Misc {
      * Get a matched player name if one was found in the database.
      *
      * @param partialName Name to match
+     *
      * @return Matched name or {@code partialName} if no match was found
      */
     public static String getMatchedPlayerName(String partialName) {
-        List<String> matches = matchPlayer(partialName);
+        if (Config.getInstance().getMatchOfflinePlayers()) {
+            List<String> matches = matchPlayer(partialName);
+
+            if (matches.size() == 1) {
+                partialName = matches.get(0);
+            }
 
-        if (matches.size() == 1) {
-            partialName = matches.get(0);
+        }
+        else {
+            Player player = mcMMO.p.getServer().getPlayer(partialName);
+            if (player != null) {
+                partialName = player.getName();
+            }
         }
 
         return partialName;

+ 4 - 0
src/main/resources/config.yml

@@ -309,6 +309,10 @@ Double_Drops:
 #  Settings for commands
 ###
 Commands:
+    General:
+        # If true, when using partial names in commands mcMMO will try to look for a match from
+        # the offline players. Enabling this might slow the server down if there are a lot of offline players.
+        Match_OfflinePlayers: false
     mcmmo:
         Donate_Message: true
     inspect: