2018-03-27 01:42:26 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2019-06-29 03:49:46 +02:00
|
|
|
import com.massivecraft.factions.SaberFactions;
|
2018-03-27 01:42:26 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class CmdRules extends FCommand {
|
2019-03-03 04:51:21 +01:00
|
|
|
public CmdRules() {
|
|
|
|
super();
|
|
|
|
aliases.add("r");
|
|
|
|
aliases.add("rule");
|
|
|
|
aliases.add("rules");
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
this.optionalArgs.put("add/remove/set/clear", "");
|
|
|
|
this.errorOnToManyArgs = false;
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
permission = Permission.RULES.node;
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeColeader = true;
|
|
|
|
senderMustBeAdmin = false;
|
2018-12-21 22:46:10 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
@Override
|
|
|
|
public void perform() {
|
2019-06-29 03:49:46 +02:00
|
|
|
if (!SaberFactions.plugin.getConfig().getBoolean("frules.Enabled")) {
|
2019-03-03 04:51:21 +01:00
|
|
|
fme.msg(TL.COMMAND_RULES_DISABLED_MSG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.args.size() == 0) {
|
|
|
|
HashMap<Integer, String> rules = fme.getFaction().getRulesMap();
|
|
|
|
if (rules.size() == 0) {
|
2019-06-29 03:49:46 +02:00
|
|
|
List<String> ruleList = SaberFactions.plugin.getConfig().getStringList("frules.default-rules");
|
|
|
|
fme.sendMessage(SaberFactions.plugin.colorList(ruleList));
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i <= rules.size() - 1; i++) {
|
2019-06-29 03:49:46 +02:00
|
|
|
fme.sendMessage(SaberFactions.plugin.color(rules.get(i)));
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
if (this.args.size() == 1) {
|
|
|
|
if (args.get(0).equalsIgnoreCase("add")) {
|
|
|
|
fme.msg(TL.COMMAND_RULES_ADD_INVALIDARGS);
|
|
|
|
}
|
|
|
|
if (args.get(0).equalsIgnoreCase("set")) {
|
|
|
|
fme.msg(TL.COMMAND_RULES_SET_INVALIDARGS);
|
|
|
|
}
|
|
|
|
if (args.get(0).equalsIgnoreCase("remove")) {
|
|
|
|
fme.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS);
|
|
|
|
}
|
|
|
|
if (args.get(0).equalsIgnoreCase("clear")) {
|
|
|
|
fme.getFaction().clearRules();
|
|
|
|
fme.msg(TL.COMMAND_RULES_CLEAR_SUCCESS);
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
if (this.args.size() >= 2) {
|
|
|
|
if (args.get(0).equalsIgnoreCase("add")) {
|
|
|
|
String message = "";
|
|
|
|
StringBuilder string = new StringBuilder(message);
|
|
|
|
for (int i = 1; i <= args.size() - 1; i++) {
|
|
|
|
string.append(" " + args.get(i));
|
|
|
|
}
|
|
|
|
fme.getFaction().addRule(string.toString());
|
|
|
|
fme.msg(TL.COMMAND_RULES_ADD_SUCCESS);
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
if (this.args.size() == 2) {
|
|
|
|
if (args.get(0).equalsIgnoreCase("remove")) {
|
|
|
|
int index = argAsInt(1);
|
|
|
|
fme.getFaction().removeRule(index - 1);
|
|
|
|
fme.msg(TL.COMMAND_RULES_REMOVE_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_RULES_DESCRIPTION;
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
}
|