Add a couple of Reqs I found useful.
This commit is contained in:
parent
7de7d30e28
commit
b4095ed4ab
64
src/com/massivecraft/mcore/cmd/req/ReqAnd.java
Normal file
64
src/com/massivecraft/mcore/cmd/req/ReqAnd.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.massivecraft.mcore.cmd.req;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.mcore.cmd.MCommand;
|
||||
|
||||
public class ReqAnd extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ReqAnd get(Req... reqs) { return new ReqAnd(reqs); }
|
||||
public ReqAnd(Req... reqs)
|
||||
{
|
||||
this(Arrays.asList(reqs));
|
||||
}
|
||||
|
||||
public static ReqAnd get(Collection<Req> reqs) { return new ReqAnd(reqs); }
|
||||
public ReqAnd(Collection<Req> reqs)
|
||||
{
|
||||
this.reqs = Collections.unmodifiableList(new ArrayList<Req>(reqs));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final List<Req> reqs;
|
||||
public List<Req> getReqs() { return this.reqs; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MCommand command)
|
||||
{
|
||||
return this.getFirstFailedSubreq(sender, command) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MCommand command)
|
||||
{
|
||||
return this.getFirstFailedSubreq(sender, command).createErrorMessage(sender, command);
|
||||
}
|
||||
|
||||
public Req getFirstFailedSubreq(CommandSender sender, MCommand command)
|
||||
{
|
||||
for (Req req : this.getReqs())
|
||||
{
|
||||
if (!req.apply(sender, command)) return req;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
46
src/com/massivecraft/mcore/cmd/req/ReqIsntCertainSender.java
Normal file
46
src/com/massivecraft/mcore/cmd/req/ReqIsntCertainSender.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.massivecraft.mcore.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.mcore.cmd.MCommand;
|
||||
import com.massivecraft.mcore.mixin.Mixin;
|
||||
import com.massivecraft.mcore.util.SenderUtil;
|
||||
import com.massivecraft.mcore.util.Txt;
|
||||
|
||||
public class ReqIsntCertainSender extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ReqIsntCertainSender get(CommandSender sender) { return new ReqIsntCertainSender(sender); }
|
||||
public ReqIsntCertainSender(CommandSender sender) { this.senderId = SenderUtil.getSenderId(sender); }
|
||||
|
||||
public static ReqIsntCertainSender get(String senderId) { return new ReqIsntCertainSender(senderId); }
|
||||
public ReqIsntCertainSender(String senderId) { this.senderId = senderId; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String senderId;
|
||||
public String getSenderId() { return this.senderId; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MCommand command)
|
||||
{
|
||||
return !this.getSenderId().equalsIgnoreCase(SenderUtil.getSenderId(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MCommand command)
|
||||
{
|
||||
return Txt.parse("<b>Player can't be <h>%s<b>.", Mixin.getDisplayName(this.getSenderId()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user