Possible converted FPlayer

This commit is contained in:
Olof Larsson
2013-04-12 08:56:26 +02:00
parent 3e68c38861
commit 76f3f044ca
60 changed files with 174 additions and 335 deletions

View File

@ -26,7 +26,6 @@ public class CmdFactions extends FCommand
public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick();
public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave();
public CmdFactionsList cmdFactionsList = new CmdFactionsList();
public CmdFactionsLock cmdFactionsLock = new CmdFactionsLock();
public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap();
public CmdFactionsOfficer cmdFactionsOfficer = new CmdFactionsOfficer();
public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney();
@ -39,8 +38,6 @@ public class CmdFactions extends FCommand
public CmdFactionsRelationEnemy cmdFactionsRelationEnemy = new CmdFactionsRelationEnemy();
public CmdFactionsRelationNeutral cmdFactionsRelationNeutral = new CmdFactionsRelationNeutral();
public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce();
public CmdFactionsReload cmdFactionsReload = new CmdFactionsReload();
public CmdFactionsSaveAll cmdFactionsSaveAll = new CmdFactionsSaveAll();
public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk();
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
public CmdFactionsShow cmdFactionsShow = new CmdFactionsShow();
@ -67,8 +64,6 @@ public class CmdFactions extends FCommand
senderMustBeOfficer = false;
senderMustBeLeader = false;
this.disableOnLock = false;
this.setHelpShort("The faction base command");
this.helpLong.add(Txt.parse("<i>This command contains all faction stuff."));
@ -110,9 +105,6 @@ public class CmdFactions extends FCommand
this.addSubCommand(this.cmdFactionsAdmin);
this.addSubCommand(this.cmdFactionsPowerBoost);
this.addSubCommand(this.cmdFactionsPromote);
this.addSubCommand(this.cmdFactionsLock);
this.addSubCommand(this.cmdFactionsReload);
this.addSubCommand(this.cmdFactionsSaveAll);
this.addSubCommand(this.cmdFactionsVersion);
}

View File

@ -22,8 +22,6 @@ public class CmdFactionsAccess extends FCommand
this.optionalArgs.put("name", "you");
this.setHelpShort("view or grant access for the claimed territory you are in");
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -14,7 +14,6 @@ public class CmdFactionsAdmin extends FCommand
this.optionalArgs.put("on/off", "flip");
this.permission = Perm.ADMIN.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -15,7 +15,6 @@ public class CmdFactionsAutoClaim extends FCommand
this.optionalArgs.put("faction", "your");
this.permission = Perm.AUTOCLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -16,8 +16,6 @@ public abstract class CmdFactionsCapeAbstract extends FCommand
{
this.optionalArgs.put("faction", "your");
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;

View File

@ -20,7 +20,6 @@ public class CmdFactionsClaim extends FCommand
this.optionalArgs.put("radius", "1");
this.permission = Perm.CLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -26,7 +26,6 @@ public class CmdFactionsCreate extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.CREATE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -79,18 +78,18 @@ public class CmdFactionsCreate extends FCommand
}
// finish setting up the Faction
faction.setTag(tag);
// trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer
faction.setTag(tag);
// trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer
fme.setRole(Rel.LEADER);
fme.setFaction(faction);
for (FPlayer follower : FPlayerColl.i.getOnline())
for (FPlayer follower : FPlayerColl.get().getAllOnline())
{
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
}

View File

@ -16,7 +16,6 @@ public class CmdFactionsDeinvite extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.DEINVITE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -16,7 +16,6 @@ public class CmdFactionsDemote extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.DEMOTE.node;
this.disableOnLock = true;
//To demote someone from member -> recruit you must be an officer.
//To demote someone from officer -> member you must be a leader.

View File

@ -18,7 +18,6 @@ public class CmdFactionsDescription extends FCommand
//this.optionalArgs
this.permission = Perm.DESCRIPTION.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -43,7 +42,7 @@ public class CmdFactionsDescription extends FCommand
}
// Broadcast the description to everyone
for (FPlayer fplayer : FPlayerColl.i.getOnline())
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{
fplayer.msg("<h>%s<i> changed their description to:", myFaction.describeTo(fplayer));
fplayer.sendMessage(myFaction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description, thus exploitable (masquerade as server messages or whatever); by the way, &k is particularly interesting looking

View File

@ -26,7 +26,6 @@ public class CmdFactionsDisband extends FCommand
this.optionalArgs.put("faction", "your");
this.permission = Perm.DISBAND.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
@ -60,7 +59,7 @@ public class CmdFactionsDisband extends FCommand
}
// Inform all players
for (FPlayer fplayer : FPlayerColl.i.getOnline())
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{
String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer);
if (fplayer.getFaction() == faction)

View File

@ -19,7 +19,6 @@ public class CmdFactionsFlag extends FCommand
this.optionalArgs.put("yes/no", "read");
this.permission = Perm.FLAG.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -32,7 +32,6 @@ public class CmdFactionsHome extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.HOME.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
@ -107,7 +106,7 @@ public class CmdFactionsHome extends FCommand
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
continue;
FPlayer fp = FPlayerColl.i.get(p);
FPlayer fp = FPlayerColl.get().get(p);
if (fme.getRelationTo(fp) != Rel.ENEMY)
continue;

View File

@ -17,7 +17,6 @@ public class CmdFactionsInvite extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.INVITE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -21,7 +21,6 @@ public class CmdFactionsJoin extends FCommand
this.optionalArgs.put("player", "you");
this.permission = Perm.JOIN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -80,7 +79,7 @@ public class CmdFactionsJoin extends FCommand
if (samePlayer && ! canAffordCommand(ConfServer.econCostJoin, "to join a faction")) return;
// trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND);
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) return;

View File

@ -23,7 +23,6 @@ public class CmdFactionsKick extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.KICK.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -22,7 +22,6 @@ public class CmdFactionsLeader extends FCommand
this.optionalArgs.put("faction", "your");
this.permission = Perm.LEADER.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
@ -71,7 +70,7 @@ public class CmdFactionsLeader extends FCommand
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
if (newLeader.getFaction() != targetFaction)
{
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayerColl.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER);
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayerColl.get().get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return;
}
@ -95,7 +94,7 @@ public class CmdFactionsLeader extends FCommand
msg("<i>You have promoted %s<i> to the position of faction leader.", newLeader.describeTo(fme, true));
// Inform all players
for (FPlayer fplayer : FPlayerColl.i.getOnline())
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{
fplayer.msg("%s<i> gave %s<i> the leadership of %s<i>.", senderIsConsole ? "A server admin" : RelationUtil.describeThatToMe(fme, fplayer, true), newLeader.describeTo(fplayer), targetFaction.describeTo(fplayer));
}

View File

@ -13,7 +13,6 @@ public class CmdFactionsLeave extends FCommand {
//this.optionalArgs.put("", "");
this.permission = Perm.LEAVE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;

View File

@ -24,7 +24,6 @@ public class CmdFactionsList extends FCommand
this.optionalArgs.put("page", "1");
this.permission = Perm.LIST.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -1,46 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
public class CmdFactionsLock extends FCommand {
// TODO: This solution needs refactoring.
/*
factions.lock:
description: use the /f lock [on/off] command to temporarily lock the data files from being overwritten
default: op
*/
public CmdFactionsLock()
{
super();
this.aliases.add("lock");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.permission = Perm.LOCK.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
}
@Override
public void perform()
{
p.setLocked(this.argAsBool(0, ! p.getLocked()));
if( p.getLocked())
{
msg("<i>Factions is now locked");
}
else
{
msg("<i>Factions in now unlocked");
}
}
}

View File

@ -17,7 +17,6 @@ public class CmdFactionsMap extends FCommand
this.optionalArgs.put("on/off", "once");
this.permission = Perm.MAP.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -17,7 +17,6 @@ public class CmdFactionsOfficer extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.OFFICER.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -16,7 +16,6 @@ public class CmdFactionsOpen extends FCommand
this.optionalArgs.put("yes/no", "flip");
this.permission = Perm.OPEN.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -20,7 +20,6 @@ public class CmdFactionsPerm extends FCommand
this.optionalArgs.put("yes/no", "read");
this.permission = Perm.PERM.node;
this.disableOnLock = true;
this.errorOnToManyArgs = false;

View File

@ -17,7 +17,6 @@ public class CmdFactionsPower extends FCommand
this.optionalArgs.put("player", "you");
this.permission = Perm.POWER.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -17,7 +17,6 @@ public class CmdFactionsPowerBoost extends FCommand
this.requiredArgs.add("#");
this.permission = Perm.POWERBOOST.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -16,7 +16,6 @@ public class CmdFactionsPromote extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.PROMOTE.node;
this.disableOnLock = true;
//To promote someone from recruit -> member you must be an officer.
//To promote someone from member -> officer you must be a leader.

View File

@ -21,7 +21,6 @@ public abstract class CmdFactionsRelationAbstract extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.RELATION.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -1,64 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
public class CmdFactionsReload extends FCommand
{
public CmdFactionsReload()
{
super();
this.aliases.add("reload");
//this.requiredArgs.add("");
this.optionalArgs.put("file", "all");
this.permission = Perm.RELOAD.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
}
@Override
public void perform()
{
long timeInitStart = System.currentTimeMillis();
String file = this.argAsString(0, "all").toLowerCase();
String fileName;
if (file.startsWith("f"))
{
FactionColl.i.loadFromDisc();
fileName = "factions.json";
}
else if (file.startsWith("p"))
{
FPlayerColl.i.loadFromDisc();
fileName = "players.json";
}
else if (file.startsWith("a"))
{
fileName = "all";
FPlayerColl.i.loadFromDisc();
FactionColl.i.loadFromDisc();
}
else
{
Factions.get().log("RELOAD CANCELLED - SPECIFIED FILE INVALID");
msg("<b>Invalid file specified. <i>Valid files: all, board, factions, players");
return;
}
long timeReload = (System.currentTimeMillis()-timeInitStart);
msg("<i>Reloaded <h>%s <i>from disk, took <h>%dms<i>.", fileName, timeReload);
}
}

View File

@ -1,36 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Perm;
public class CmdFactionsSaveAll extends FCommand
{
public CmdFactionsSaveAll()
{
super();
this.aliases.add("saveall");
this.aliases.add("save");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Perm.SAVE.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
}
@Override
public void perform()
{
FPlayerColl.i.saveToDisc();
FactionColl.i.saveToDisc();
msg("<i>Factions saved to disk!");
}
}

View File

@ -17,7 +17,6 @@ public class CmdFactionsSeeChunk extends FCommand
this.aliases.add("seechunk");
this.permission = Perm.SEE_CHUNK.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -17,7 +17,6 @@ public class CmdFactionsSethome extends FCommand
this.optionalArgs.put("faction", "your");
this.permission = Perm.SETHOME.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -12,6 +12,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.util.Txt;
public class CmdFactionsShow extends FCommand
@ -25,7 +26,6 @@ public class CmdFactionsShow extends FCommand
this.optionalArgs.put("faction", "your");
this.permission = Perm.SHOW.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -114,7 +114,7 @@ public class CmdFactionsShow extends FCommand
for (FPlayer follower : admins)
{
if (follower.isOnlineAndVisibleTo(me))
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
{
memberOnlineNames.add(follower.getNameAndTitle(fme));
}
@ -126,7 +126,7 @@ public class CmdFactionsShow extends FCommand
for (FPlayer follower : mods)
{
if (follower.isOnlineAndVisibleTo(me))
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
{
memberOnlineNames.add(follower.getNameAndTitle(fme));
}
@ -138,7 +138,7 @@ public class CmdFactionsShow extends FCommand
for (FPlayer follower : normals)
{
if (follower.isOnlineAndVisibleTo(me))
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
{
memberOnlineNames.add(follower.getNameAndTitle(fme));
}

View File

@ -23,7 +23,6 @@ public class CmdFactionsTag extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.TAG.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -16,7 +16,6 @@ public class CmdFactionsTitle extends FCommand
this.optionalArgs.put("title", "");
this.permission = Perm.TITLE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -24,7 +24,6 @@ public class CmdFactionsUnclaim extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.UNCLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -21,7 +21,6 @@ public class CmdFactionsUnclaimall extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.UNCLAIM_ALL.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -14,7 +14,6 @@ public class CmdFactionsVersion extends FCommand
//this.optionalArgs.put("", "");
this.permission = Perm.VERSION.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -21,8 +21,6 @@ import com.massivecraft.mcore.util.Txt;
public abstract class FCommand extends MCommand<Factions>
{
public boolean disableOnLock;
public FPlayer fme;
public Faction myFaction;
@ -37,9 +35,6 @@ public abstract class FCommand extends MCommand<Factions>
{
super(Factions.get());
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
@ -53,7 +48,7 @@ public abstract class FCommand extends MCommand<Factions>
{
if (sender instanceof Player)
{
this.fme = FPlayerColl.i.get((Player)sender);
this.fme = FPlayerColl.get().get(sender);
this.myFaction = this.fme.getFaction();
}
else
@ -66,13 +61,7 @@ public abstract class FCommand extends MCommand<Factions>
@Override
public boolean isEnabled()
{
if (p.getLocked() && this.disableOnLock)
{
msg("<b>Factions was locked by an admin. Please try again later.");
return false;
}
{
if (this.isMoneyCommand && ! ConfServer.econEnabled)
{
msg("<b>Faction economy features are disabled on this server.");
@ -98,7 +87,7 @@ public abstract class FCommand extends MCommand<Factions>
if ( ! (sender instanceof Player)) return false;
FPlayer fplayer = FPlayerColl.i.get((Player)sender);
FPlayer fplayer = FPlayerColl.get().get((Player)sender);
if ( ! fplayer.hasFaction())
{
@ -165,7 +154,7 @@ public abstract class FCommand extends MCommand<Factions>
if (name != null)
{
FPlayer fplayer = FPlayerColl.i.get(name);
FPlayer fplayer = FPlayerColl.get().get(name);
if (fplayer != null)
{
ret = fplayer;
@ -199,7 +188,9 @@ public abstract class FCommand extends MCommand<Factions>
if (name != null)
{
FPlayer fplayer = FPlayerColl.i.getBestIdMatch(name);
// TODO: Easy fix for now
//FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name);
FPlayer fplayer = FPlayerColl.get().getId2entity().get(name);
if (fplayer != null)
{
ret = fplayer;
@ -250,7 +241,10 @@ public abstract class FCommand extends MCommand<Factions>
// Next we match player names
if (faction == null)
{
FPlayer fplayer = FPlayerColl.i.getBestIdMatch(name);
// TODO: Easy fix for now
//FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name);
FPlayer fplayer = FPlayerColl.get().getId2entity().get(name);
if (fplayer != null)
{
faction = fplayer.getFaction();

View File

@ -3,11 +3,9 @@ package com.massivecraft.factions.cmd.req;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Rel;
import com.massivecraft.mcore.cmd.MCommand;
import com.massivecraft.mcore.cmd.req.ReqAbstract;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.util.Txt;
public class ReqRoleIsAtLeast extends ReqAbstract
@ -35,8 +33,7 @@ public class ReqRoleIsAtLeast extends ReqAbstract
@Override
public boolean apply(CommandSender sender, MCommand command)
{
FPlayer fplayer = FPlayerColl.i.get(SenderUtil.getSenderId(sender));
FPlayer fplayer = FPlayer.get(sender);
return fplayer.getRole().isAtLeast(this.rel);
}