Adding match mode for id search to MassiveCraftCore and improving the faction argument readers.

This commit is contained in:
Olof Larsson
2011-10-22 14:39:01 +02:00
parent e6d45a6aa2
commit 5bf38ab0aa
7 changed files with 97 additions and 45 deletions

View File

@ -148,15 +148,14 @@ public abstract class FCommand extends MCommand<P>
// Argument Readers
// -------------------------------------------- //
// ARG AS FPLAYER
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg)
// FPLAYER ======================
public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.get(name);
FPlayer fplayer = FPlayers.i.get(name);
if (fplayer != null)
{
ret = fplayer;
@ -165,11 +164,15 @@ public abstract class FCommand extends MCommand<P>
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
this.msg("<b>No player \"<p>%s<b>\" could not be found.", name);
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg)
{
return this.strAsFPlayer(this.argAsString(idx), def, msg);
}
public FPlayer argAsFPlayer(int idx, FPlayer def)
{
return this.argAsFPlayer(idx, def, true);
@ -179,15 +182,14 @@ public abstract class FCommand extends MCommand<P>
return this.argAsFPlayer(idx, null);
}
// ARG AS BEST FPLAYER MATCH
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg)
// BEST FPLAYER MATCH ======================
public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.find(name);
FPlayer fplayer = FPlayers.i.getBestIdMatch(name);
if (fplayer != null)
{
ret = fplayer;
@ -196,11 +198,15 @@ public abstract class FCommand extends MCommand<P>
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
this.msg("<b>No player match found for \"<p>%s<b>\".", name);
}
return ret;
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg)
{
return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def)
{
return this.argAsBestFPlayerMatch(idx, def, true);
@ -210,37 +216,43 @@ public abstract class FCommand extends MCommand<P>
return this.argAsBestFPlayerMatch(idx, null);
}
// ARG AS FACTION
public Faction argAsFaction(int idx, Faction def, boolean msg)
// FACTION ======================
public Faction strAsFaction(String name, Faction def, boolean msg)
{
Faction ret = def;
String name = this.argAsString(idx);
if (name != null)
{
// First we search faction names
Faction faction = Factions.i.findByTag(name);
// First we match faction tags
Faction faction = Factions.i.getBestTagMatch(name);
// Next we match player names
if (faction == null)
{
FPlayer fplayer = FPlayers.i.getBestIdMatch(name);
if (fplayer != null)
{
faction = fplayer.getFaction();
}
}
if (faction != null)
{
ret = faction;
}
// Next we search player names
FPlayer fplayer = FPlayers.i.find(name);
if (fplayer != null)
{
ret = fplayer.getFaction();
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The faction or player \"<p>%s<b>\" could not be found.", name));
this.msg("<b>The faction or player \"<p>%s<b>\" could not be found.", name);
}
return ret;
}
public Faction argAsFaction(int idx, Faction def, boolean msg)
{
return this.strAsFaction(this.argAsString(idx), def, msg);
}
public Faction argAsFaction(int idx, Faction def)
{
return this.argAsFaction(idx, def, true);