Added support for matching offline players for player wrappers.

This commit is contained in:
Olof Larsson 2011-12-14 16:44:45 +01:00
parent a21dd2bbc0
commit 5ee13b7af9
4 changed files with 47 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import com.massivecraft.mcore1.persist.One;
import com.massivecraft.mcore1.persist.Persist;
import com.massivecraft.mcore1.text.Txt;
import com.massivecraft.mcore1.util.Perm;
import com.massivecraft.mcore1.util.PlayerUtil;
public class MCore extends JavaPlugin
{
@ -138,6 +139,8 @@ public class MCore extends JavaPlugin
{
logPrefix = "["+this.getDescription().getName()+"] ";
PlayerUtil.populateAllVisitorNames();
// This is safe since all plugins using Persist should bukkit-depend this plugin.
getPersistInstances().clear();

View File

@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerPreLoginEvent;
import com.massivecraft.mcore1.persist.IClassManager;
import com.massivecraft.mcore1.persist.Persist;
import com.massivecraft.mcore1.util.PlayerUtil;
public class MCorePlayerListener extends PlayerListener
{
@ -22,6 +23,8 @@ public class MCorePlayerListener extends PlayerListener
{
String id = event.getName();
PlayerUtil.getAllVisitorNames().add(id);
for (Persist realm : MCore.getPersistInstances().values())
{
for (IClassManager<?> manager : realm.getClassManagers().values())

View File

@ -4,6 +4,8 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.mcore1.MPlugin;
import com.massivecraft.mcore1.persist.IClassManager;
import com.massivecraft.mcore1.persist.Persist;
import com.massivecraft.mcore1.util.PlayerUtil;
public abstract class AHPlayerWrapper<T> extends AHBase<T>
{
@ -23,7 +25,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
IClassManager<T> manager = this.getManager(p);
T ret;
if (style != null && style.equals("match"))
if (style != null && style.equalsIgnoreCase("match"))
{
ret = manager.getBestMatch(str);
if (ret != null)
@ -32,6 +34,15 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
}
this.error = "<b>No player name begins with \"<p>"+str+"<b>\".";
}
else if (style != null && style.equalsIgnoreCase("matchany"))
{
ret = manager.get(Persist.getBestCIStart(PlayerUtil.getAllVisitorNames(), str));
if (ret != null)
{
return ret;
}
this.error = "<b>No player name begins with \"<p>"+str+"<b>\".";
}
else
{
ret = manager.get(str);

View File

@ -0,0 +1,29 @@
package com.massivecraft.mcore1.util;
import java.io.File;
import java.util.Set;
import java.util.TreeSet;
import org.bukkit.Bukkit;
public class PlayerUtil
{
private static Set<String> allVisitorNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
public static Set<String> getAllVisitorNames() { return allVisitorNames; }
public static void populateAllVisitorNames()
{
// What is the name of the default world?
String worldname = Bukkit.getWorlds().get(0).getName();
// Find the player folder
File playerfolder = new File(worldname, "players");
// Populate by removing .dat
for (File playerfile : playerfolder.listFiles())
{
String filename = playerfile.getName();
String playername = filename.substring(0, filename.length()-4);
allVisitorNames.add(playername);
}
}
}