From 828c149cb03372de5cf4c21e963a284cc4d239f2 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 10 Apr 2013 13:33:17 +0200 Subject: [PATCH] Adding a ReqRoleIsAtLeast for future use. --- .../factions/cmd/req/ReqRoleIsAtLeast.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java diff --git a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java new file mode 100644 index 00000000..21d3c7b0 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java @@ -0,0 +1,49 @@ +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 +{ + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Rel rel; + public Rel getRel() { return this.rel; } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ReqRoleIsAtLeast get(Rel rel) { return new ReqRoleIsAtLeast(rel); } + private ReqRoleIsAtLeast(Rel rel) { this.rel = rel; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MCommand command) + { + + FPlayer fplayer = FPlayerColl.i.get(SenderUtil.getSenderId(sender)); + return fplayer.getRole().isAtLeast(this.rel); + } + + @Override + public String createErrorMessage(CommandSender sender, MCommand command) + { + return Txt.parse("You must be %s or higher to do this.", Txt.getNicedEnum(this.rel)); + } + +}