Java 1.6 compatibility and tweaks to the previous commit.
This commit is contained in:
parent
68fe1f2d28
commit
1f479bd699
@ -25,7 +25,7 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
//These fields are set upon perform() and unset afterwards
|
// These fields are set upon perform() and unset afterwards.
|
||||||
|
|
||||||
// Target
|
// Target
|
||||||
private Faction targetFaction = null;
|
private Faction targetFaction = null;
|
||||||
@ -60,20 +60,20 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
// This sets target and much other. Returns false if not succeeded
|
// This sets target and much other. Returns false if not succeeded.
|
||||||
if(!registerFields())
|
if ( ! this.registerFields())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes we just want to show the rank
|
// Sometimes we just want to show the rank.
|
||||||
if ( ! this.argIsSet(1))
|
if ( ! this.argIsSet(1))
|
||||||
{
|
{
|
||||||
if ( ! Perm.RANK_SHOW.has(sender, true))
|
if ( ! Perm.RANK_SHOW.has(sender, true))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showRank();
|
this.showRank();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the player allowed or not. Method can be found later down
|
// Is the player allowed or not. Method can be found later down.
|
||||||
if(!isPlayerAllowed())
|
if ( ! this.isPlayerAllowed())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -96,15 +96,15 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should we fire an event when rank is changed?
|
// Should we fire an event when rank is changed?
|
||||||
// Currently we don't
|
// Currently we don't.
|
||||||
|
|
||||||
// Change the rank
|
// Change the rank
|
||||||
changeRank();
|
this.changeRank();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is always run after performing a MassiveCommand
|
// This is always run after performing a MassiveCommand.
|
||||||
// It might be a bit hacky, but is easier than adding a line of code at every return statement
|
// It might be a bit hacky, but is easier than adding a line of code at every return statement.
|
||||||
// Sometimes it is nice to know the exact mechanics of MassiveCore
|
// Sometimes it is nice to know the exact mechanics of MassiveCore.
|
||||||
@Override
|
@Override
|
||||||
public void unsetSenderVars()
|
public void unsetSenderVars()
|
||||||
{
|
{
|
||||||
@ -214,47 +214,47 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it wasn't cancelled above, player is allowe
|
// If it wasn't cancelled above, player is allowed.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isChangeRequired()
|
private boolean isChangeRequired()
|
||||||
{
|
{
|
||||||
// Just a nice msg. It would however be caught by an if statement below
|
// Just a nice msg. It would however be caught by an if statement below.
|
||||||
if (target.getRole() == Rel.RECRUIT && arg(1).equalsIgnoreCase("demote"))
|
if (target.getRole() == Rel.RECRUIT && arg(1).equalsIgnoreCase("demote"))
|
||||||
{
|
{
|
||||||
msg("<b>You can't demote a recruit");
|
msg("<b>You can't demote a recruit");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just a nice msg. It would however be caught by an if statement below
|
// Just a nice msg. It would however be caught by an if statement below.
|
||||||
if (target.getRole() == Rel.LEADER && arg(1).equalsIgnoreCase("promote"))
|
if (target.getRole() == Rel.LEADER && arg(1).equalsIgnoreCase("promote"))
|
||||||
{
|
{
|
||||||
msg("<b>You can't promote the leader");
|
msg("<b>You can't promote the leader");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There must be a change, else it is all waste of time
|
// There must be a change, else it is all waste of time.
|
||||||
if (target.getRole() == rank)
|
if (target.getRole() == rank)
|
||||||
{
|
{
|
||||||
msg("<b>Player already has that rank");
|
msg("<b>Player already has that rank");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeRank()
|
private void changeRank()
|
||||||
{
|
{
|
||||||
// In case of leadership change, we do special things not done in other rank changes
|
// In case of leadership change, we do special things not done in other rank changes.
|
||||||
if (rank == Rel.LEADER)
|
if (rank == Rel.LEADER)
|
||||||
{
|
{
|
||||||
changeRankLeader();
|
this.changeRankLeader();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
changeRankOther();
|
this.changeRankOther();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeRankLeader()
|
private void changeRankLeader()
|
||||||
@ -265,14 +265,20 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
{
|
{
|
||||||
// Inform & demote the old leader
|
// Inform & demote the old leader
|
||||||
targetFactionCurrentLeader.setRole(Rel.OFFICER);
|
targetFactionCurrentLeader.setRole(Rel.OFFICER);
|
||||||
if (targetFactionCurrentLeader != msender) //They kinda know if they fired the command themself
|
if (targetFactionCurrentLeader != msender)
|
||||||
|
{
|
||||||
|
// They kinda know if they fired the command themself
|
||||||
targetFactionCurrentLeader.msg("<i>You have been demoted from the position of faction leader by %s<i>.", msender.describeTo(targetFactionCurrentLeader, true));
|
targetFactionCurrentLeader.msg("<i>You have been demoted from the position of faction leader by %s<i>.", msender.describeTo(targetFactionCurrentLeader, true));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Inform & promote the new leader
|
// Inform & promote the new leader
|
||||||
target.setRole(Rel.LEADER);
|
target.setRole(Rel.LEADER);
|
||||||
if (target != msender) //They kinda know if they fired the command themself
|
if (target != msender)
|
||||||
|
{
|
||||||
|
// They kinda know if they fired the command themself
|
||||||
target.msg("<i>You have been promoted to the position of faction leader by %s<i>.", msender.describeTo(target, true));
|
target.msg("<i>You have been promoted to the position of faction leader by %s<i>.", msender.describeTo(target, true));
|
||||||
|
}
|
||||||
|
|
||||||
// Inform the msg sender
|
// Inform the msg sender
|
||||||
msg("<i>You have promoted %s<i> to the position of faction leader.", target.describeTo(msender, true));
|
msg("<i>You have promoted %s<i> to the position of faction leader.", target.describeTo(msender, true));
|
||||||
@ -288,15 +294,16 @@ public class CmdFactionsRank extends FactionsCommand
|
|||||||
private void changeRankOther()
|
private void changeRankOther()
|
||||||
{
|
{
|
||||||
// If the target is currently the leader and faction isn't permanent...
|
// If the target is currently the leader and faction isn't permanent...
|
||||||
if(targetRole == Rel.LEADER && (!MConf.get().permanentFactionsDisableLeaderPromotion
|
if (targetRole == Rel.LEADER && (!MConf.get().permanentFactionsDisableLeaderPromotion || !targetFaction.getFlag(MFlag.ID_PERMANENT)))
|
||||||
|| !targetFaction.getFlag(MFlag.ID_PERMANENT)))
|
|
||||||
{
|
{
|
||||||
// ...we must promote a new one
|
// ...we must promote a new one
|
||||||
targetFaction.promoteNewLeader();
|
targetFaction.promoteNewLeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Were they demoted or promoted?
|
// Were they demoted or promoted?
|
||||||
String change = (rank.isLessThan(targetRole) ? "demoted" : "promoted");
|
String change = (rank.isLessThan(targetRole) ? "demoted" : "promoted");
|
||||||
// The rank will be set before the msg, so they have the appropriate prefix
|
|
||||||
|
// The rank will be set before the msg, so they have the appropriate prefix.
|
||||||
target.setRole(rank);
|
target.setRole(rank);
|
||||||
String rankName = Txt.getNicedEnum(rank).toLowerCase();
|
String rankName = Txt.getNicedEnum(rank).toLowerCase();
|
||||||
msenderFaction.msg("%s<i> was %s to being %s %s in your faction.", target.describeTo(msenderFaction, true), change, Txt.aan(rankName), rankName);
|
msenderFaction.msg("%s<i> was %s to being %s %s in your faction.", target.describeTo(msenderFaction, true), change, Txt.aan(rankName), rankName);
|
||||||
|
@ -10,7 +10,7 @@ public class CmdFactionsRankOld extends FactionsCommand
|
|||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
final String rankName;
|
public final String rankName;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
@ -18,6 +18,7 @@ public class CmdFactionsRankOld extends FactionsCommand
|
|||||||
|
|
||||||
public CmdFactionsRankOld(String rank)
|
public CmdFactionsRankOld(String rank)
|
||||||
{
|
{
|
||||||
|
// Fields
|
||||||
this.rankName = rank.toLowerCase();
|
this.rankName = rank.toLowerCase();
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
@ -26,6 +27,7 @@ public class CmdFactionsRankOld extends FactionsCommand
|
|||||||
// Args
|
// Args
|
||||||
this.addRequiredArg("player");
|
this.addRequiredArg("player");
|
||||||
|
|
||||||
|
// VisibilityMode
|
||||||
this.setVisibilityMode(VisibilityMode.INVISIBLE);
|
this.setVisibilityMode(VisibilityMode.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +38,7 @@ public class CmdFactionsRankOld extends FactionsCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
Factions.get().getOuterCmdFactions().cmdFactionsRank.execute(sender, MUtil.list(arg(0),rankName));
|
Factions.get().getOuterCmdFactions().cmdFactionsRank.execute(sender, MUtil.list(this.arg(0), this.rankName));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import com.massivecraft.massivecore.util.Txt;
|
|||||||
|
|
||||||
public class ARRank extends ARAbstractSelect<Rel>
|
public class ARRank extends ARAbstractSelect<Rel>
|
||||||
{
|
{
|
||||||
//----------------------------------------------//
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
this.startRank = null;
|
this.startRank = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fancy constructor. Can use promote and demote
|
// Fancy constructor. Can use promote and demote.
|
||||||
public static ARRank get(Rel rank) { return new ARRank(rank); }
|
public static ARRank get(Rel rank) { return new ARRank(rank); }
|
||||||
|
|
||||||
public ARRank(Rel rank)
|
public ARRank(Rel rank)
|
||||||
@ -33,11 +33,12 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
this.startRank = rank;
|
this.startRank = rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------//
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
final Rel startRank;
|
private final Rel startRank;
|
||||||
|
public Rel getStartRank() { return this.startRank; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
@ -52,55 +53,44 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
@Override
|
@Override
|
||||||
public Rel select(String arg, CommandSender sender)
|
public Rel select(String arg, CommandSender sender)
|
||||||
{
|
{
|
||||||
//Default it is nothing
|
|
||||||
Rel ret = null;
|
|
||||||
|
|
||||||
// This is especially useful when one rank can have aliases.
|
// This is especially useful when one rank can have aliases.
|
||||||
// In the case of promote/demote,
|
// In the case of promote/demote,
|
||||||
// that would require 10 lines of code repeated for each alias.
|
// that would require 10 lines of code repeated for each alias.
|
||||||
arg = this.prepareArg(arg);
|
arg = this.prepareArg(arg);
|
||||||
|
|
||||||
switch(arg)
|
|
||||||
{
|
|
||||||
// All the normal ranks
|
// All the normal ranks
|
||||||
case "leader": ret = Rel.LEADER; break;
|
if (arg.equals("leader")) return Rel.LEADER;
|
||||||
case "officer": ret = Rel.OFFICER; break;
|
if (arg.equals("officer")) return Rel.OFFICER;
|
||||||
case "member": ret = Rel.MEMBER; break;
|
if (arg.equals("member")) return Rel.MEMBER;
|
||||||
case "recruit": ret = Rel.RECRUIT; break;
|
if (arg.equals("recruit")) return Rel.RECRUIT;
|
||||||
|
|
||||||
// Promote
|
// No start rank?
|
||||||
case "promote":
|
if (startRank == null)
|
||||||
switch(startRank)
|
|
||||||
{
|
{
|
||||||
case LEADER : ret = Rel.LEADER; break;
|
// This might happen of the default constructor is used
|
||||||
case OFFICER : ret = Rel.LEADER; break;
|
|
||||||
case MEMBER : ret = Rel.OFFICER; break;
|
|
||||||
case RECRUIT : ret = Rel.MEMBER; break;
|
|
||||||
// This should not happen
|
|
||||||
default:
|
|
||||||
//This might happen of the default constrcutor is used
|
|
||||||
Mixin.msgOne(sender, Txt.parse("<b>You can't use promote & demote"));
|
Mixin.msgOne(sender, Txt.parse("<b>You can't use promote & demote"));
|
||||||
ret = null; break;
|
return null;
|
||||||
|
|
||||||
} break;
|
|
||||||
|
|
||||||
// Demote
|
|
||||||
case "demote":
|
|
||||||
switch(startRank)
|
|
||||||
{
|
|
||||||
case LEADER : ret = Rel.OFFICER; break;
|
|
||||||
case OFFICER : ret = Rel.MEMBER; break;
|
|
||||||
case MEMBER : ret = Rel.RECRUIT; break;
|
|
||||||
case RECRUIT : ret = Rel.RECRUIT; break;
|
|
||||||
// This should not happen
|
|
||||||
default:
|
|
||||||
//This might happen of the default constrcutor is used
|
|
||||||
Mixin.msgOne(sender, Txt.parse("<b>You can't use promote & demote"));
|
|
||||||
ret = null; break;
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
// Promote
|
||||||
|
if (arg.equals("promote"))
|
||||||
|
{
|
||||||
|
if (Rel.LEADER.equals(startRank)) return Rel.LEADER;
|
||||||
|
if (Rel.OFFICER.equals(startRank)) return Rel.LEADER;
|
||||||
|
if (Rel.MEMBER.equals(startRank)) return Rel.OFFICER;
|
||||||
|
if (Rel.RECRUIT.equals(startRank)) return Rel.MEMBER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demote
|
||||||
|
if (arg.equals("demote"))
|
||||||
|
{
|
||||||
|
if (Rel.LEADER.equals(startRank)) return Rel.OFFICER;
|
||||||
|
if (Rel.OFFICER.equals(startRank)) return Rel.MEMBER;
|
||||||
|
if (Rel.MEMBER.equals(startRank)) return Rel.RECRUIT;
|
||||||
|
if (Rel.RECRUIT.equals(startRank)) return Rel.RECRUIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,7 +102,8 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
Txt.getNicedEnum(Rel.MEMBER),
|
Txt.getNicedEnum(Rel.MEMBER),
|
||||||
Txt.getNicedEnum(Rel.RECRUIT),
|
Txt.getNicedEnum(Rel.RECRUIT),
|
||||||
"Promote",
|
"Promote",
|
||||||
"Demote");
|
"Demote"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -121,29 +112,29 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
|
|
||||||
private String prepareArg(String str)
|
private String prepareArg(String str)
|
||||||
{
|
{
|
||||||
String ret = str;
|
String ret = str.toLowerCase();
|
||||||
|
|
||||||
if (str.startsWith("admin") || str.startsWith("lea"))
|
if (ret.startsWith("admin") || ret.startsWith("lea"))
|
||||||
{
|
{
|
||||||
ret = "leader";
|
ret = "leader";
|
||||||
}
|
}
|
||||||
else if (str.startsWith("mod") || str.startsWith("off"))
|
else if (ret.startsWith("mod") || ret.startsWith("off"))
|
||||||
{
|
{
|
||||||
ret = "officer";
|
ret = "officer";
|
||||||
}
|
}
|
||||||
else if (str.startsWith("mem"))
|
else if (ret.startsWith("mem"))
|
||||||
{
|
{
|
||||||
ret = "member";
|
ret = "member";
|
||||||
}
|
}
|
||||||
else if (str.startsWith("rec"))
|
else if (ret.startsWith("rec"))
|
||||||
{
|
{
|
||||||
ret = "recruit";
|
ret = "recruit";
|
||||||
}
|
}
|
||||||
else if (str.startsWith("+") || str.startsWith("plus"))
|
else if (ret.startsWith("+") || ret.startsWith("plus") || ret.startsWith("up"))
|
||||||
{
|
{
|
||||||
ret = "promote";
|
ret = "promote";
|
||||||
}
|
}
|
||||||
else if (str.startsWith("-") || str.startsWith("minus"))
|
else if (ret.startsWith("-") || ret.startsWith("minus") || ret.startsWith("down"))
|
||||||
{
|
{
|
||||||
ret = "demote";
|
ret = "demote";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user