Introduced Brigadier Command System. More Formatting Coming in next commit.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.LazyLocation;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
@@ -17,63 +15,51 @@ public class CmdSetFWarp extends FCommand {
|
||||
|
||||
this.aliases.add("setwarp");
|
||||
this.aliases.add("sw");
|
||||
|
||||
this.requiredArgs.add("warp name");
|
||||
this.optionalArgs.put("password", "password");
|
||||
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = false;
|
||||
|
||||
this.senderMustBePlayer = true;
|
||||
|
||||
this.permission = Permission.SETWARP.node;
|
||||
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
|
||||
.playerOnly()
|
||||
.memberOnly()
|
||||
.withAction(PermissableAction.SETWARP)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!(fme.getRelationToLocation() == Relation.MEMBER)) {
|
||||
fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
|
||||
public void perform(CommandContext context) {
|
||||
if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
|
||||
context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
|
||||
return;
|
||||
}
|
||||
|
||||
// This statement allows us to check if they've specifically denied it, or default to
|
||||
// the old setting of allowing moderators to set warps.
|
||||
if (!fme.isAdminBypassing()) {
|
||||
Access access = myFaction.getAccess(fme, PermissableAction.SETWARP);
|
||||
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
||||
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String warp = argAsString(0);
|
||||
String warp = context.argAsString(0);
|
||||
|
||||
// Checks if warp with same name already exists and ignores maxWarp check if it does.
|
||||
boolean warpExists = myFaction.isWarp(warp);
|
||||
boolean warpExists = context.faction.isWarp(warp);
|
||||
|
||||
int maxWarps = P.p.getConfig().getInt("max-warps", 5);
|
||||
boolean tooManyWarps = maxWarps <= myFaction.getWarps().size();
|
||||
int maxWarps = FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5);
|
||||
boolean tooManyWarps = maxWarps <= context.faction.getWarps().size();
|
||||
if (tooManyWarps && !warpExists) {
|
||||
fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
|
||||
context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!transact(fme)) {
|
||||
if (!transact(context.fPlayer, context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String password = argAsString(1);
|
||||
String password = context.argAsString(1);
|
||||
|
||||
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation());
|
||||
myFaction.setWarp(warp, loc);
|
||||
LazyLocation loc = new LazyLocation(context.player.getLocation());
|
||||
context.faction.setWarp(warp, loc);
|
||||
if (password != null) {
|
||||
myFaction.setWarpPassword(warp, password);
|
||||
context.faction.setWarpPassword(warp, password);
|
||||
}
|
||||
fme.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
|
||||
context.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
|
||||
}
|
||||
|
||||
private boolean transact(FPlayer player) {
|
||||
return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
|
||||
private boolean transact(FPlayer player, CommandContext context) {
|
||||
return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,3 +67,4 @@ public class CmdSetFWarp extends FCommand {
|
||||
return TL.COMMAND_SETFWARP_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user