Fixed online matching preventing exact offline access, closes #9

Restored some old OpenInv behavior - Offline name partial completion.
Currently there's no minimum similarity to consider a match a success, and the first name with the same similarity will take precedence. As a result, you may see some very odd results on occasion.
This commit is contained in:
Jikoo
2016-06-15 18:49:45 -04:00
parent 9edac80544
commit 1bbdde683c
4 changed files with 75 additions and 25 deletions

View File

@@ -17,9 +17,7 @@
package com.lishid.openinv.commands;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -75,20 +73,13 @@ public class OpenInvPluginCommand implements CommandExecutor {
new BukkitRunnable() {
@Override
public void run() {
List<Player> matches = Bukkit.matchPlayer(name);
final OfflinePlayer offlinePlayer;
if (!matches.isEmpty()) {
offlinePlayer = matches.get(0);
} else {
offlinePlayer = Bukkit.getOfflinePlayer(name);
}
if (!player.isOnline()) {
return;
}
final OfflinePlayer offlinePlayer = plugin.matchPlayer(name);
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
player.sendMessage(ChatColor.RED + "Player not found!");
return;
}
new BukkitRunnable() {
@Override
public void run() {
@@ -98,6 +89,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
openInventory(player, offlinePlayer);
}
}.runTask(plugin);
}
}.runTaskAsynchronously(plugin);