Fixed the spam issue with a real fix.
This commit is contained in:
parent
ee3c5446e2
commit
266c598b76
@ -8,6 +8,6 @@
|
||||
<version>1.6.9.5-U0.2.1-RC-1.5-BETA</version>
|
||||
<version>1.6.9.5-U0.2.1-RC-1.5-BETA-2</version>
|
||||
</versions>
|
||||
<lastUpdated>20181221181311</lastUpdated>
|
||||
<lastUpdated>20181221214408</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
|
@ -1 +1 @@
|
||||
9bdc33366d81ebbb51cec5b2a0092585
|
||||
e9ce0bdae55853de86510ddacb671877
|
@ -1 +1 @@
|
||||
cdb7b8ec048405faa43f32d2daf226382f5952d2
|
||||
694467945b9eeace46a9acb0cfd0fddc9c87fad8
|
@ -508,10 +508,6 @@ public class SavageFactions extends MPlugin {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player) sender);
|
||||
if (!fPlayer.hasFaction()) {
|
||||
fPlayer.msg("Autocomplete is not available if you do not have a faction.");
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args));
|
||||
|
@ -24,7 +24,8 @@ public class CmdAdmin extends FCommand {
|
||||
this.permission = Permission.ADMIN.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
@ -22,7 +22,8 @@ public class CmdBanner extends FCommand {
|
||||
this.permission = Permission.BANNER.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
|
@ -19,6 +19,7 @@ public class CmdChat extends FCommand {
|
||||
this.permission = Permission.CHAT.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
|
@ -19,7 +19,8 @@ public class CmdChest extends FCommand {
|
||||
this.permission = Permission.CHEST.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
@ -24,7 +24,8 @@ public class CmdClaim extends FCommand {
|
||||
this.permission = Permission.CLAIM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -17,7 +17,8 @@ public class CmdClaimAt extends FCommand {
|
||||
this.permission = Permission.CLAIMAT.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -25,7 +25,8 @@ public class CmdClaimLine extends FCommand {
|
||||
this.permission = Permission.CLAIM_LINE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -23,7 +23,8 @@ public class CmdColeader extends FCommand {
|
||||
this.permission = Permission.COLEADER.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = true;
|
||||
|
@ -15,7 +15,8 @@ public class CmdCoords extends FCommand {
|
||||
this.permission = Permission.COORD.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -24,7 +24,8 @@ public class CmdDeinvite extends FCommand {
|
||||
this.permission = Permission.DEINVITE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -17,6 +17,7 @@ public class CmdDelFWarp extends FCommand {
|
||||
this.senderMustBeModerator = true;
|
||||
this.senderMustBePlayer = true;
|
||||
this.permission = Permission.SETWARP.node;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,8 @@ public class CmdDescription extends FCommand {
|
||||
this.permission = Permission.DESCRIPTION.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
|
@ -1,88 +1,89 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class CmdDisband extends FCommand {
|
||||
|
||||
|
||||
private static HashMap<String, String> disbandMap = new HashMap<>();
|
||||
|
||||
|
||||
public CmdDisband() {
|
||||
super();
|
||||
this.aliases.add("disband");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction tag", "yours");
|
||||
|
||||
this.permission = Permission.DISBAND.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// The faction, default to your own.. but null if console sender.
|
||||
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.isAdminBypassing()) {
|
||||
Access access = faction.getAccess(fme, PermissableAction.DISBAND);
|
||||
if (fme.getRole() != Role.LEADER && access != Access.ALLOW) {
|
||||
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!faction.isNormal()) {
|
||||
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
|
||||
return;
|
||||
}
|
||||
if (faction.isPermanent()) {
|
||||
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check for tnt before disbanding.
|
||||
|
||||
if (!disbandMap.containsKey(me.getUniqueId().toString()) && faction.getTnt() > 0) {
|
||||
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
|
||||
disbandMap.put(me.getUniqueId().toString(), faction.getId());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
disbandMap.remove(me.getUniqueId().toString());
|
||||
}
|
||||
}, 200L);
|
||||
} else {
|
||||
//Check if the faction we asked confirmation for is the one being disbanded.
|
||||
if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
|
||||
faction.disband(me, PlayerDisbandReason.COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_DISBAND_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class CmdDisband extends FCommand {
|
||||
|
||||
|
||||
private static HashMap<String, String> disbandMap = new HashMap<>();
|
||||
|
||||
|
||||
public CmdDisband() {
|
||||
super();
|
||||
this.aliases.add("disband");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction tag", "yours");
|
||||
|
||||
this.permission = Permission.DISBAND.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// The faction, default to your own.. but null if console sender.
|
||||
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.isAdminBypassing()) {
|
||||
Access access = faction.getAccess(fme, PermissableAction.DISBAND);
|
||||
if (fme.getRole() != Role.LEADER && access != Access.ALLOW) {
|
||||
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!faction.isNormal()) {
|
||||
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
|
||||
return;
|
||||
}
|
||||
if (faction.isPermanent()) {
|
||||
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check for tnt before disbanding.
|
||||
|
||||
if (!disbandMap.containsKey(me.getUniqueId().toString()) && faction.getTnt() > 0) {
|
||||
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
|
||||
disbandMap.put(me.getUniqueId().toString(), faction.getId());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
disbandMap.remove(me.getUniqueId().toString());
|
||||
}
|
||||
}, 200L);
|
||||
} else {
|
||||
//Check if the faction we asked confirmation for is the one being disbanded.
|
||||
if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
|
||||
faction.disband(me, PlayerDisbandReason.COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_DISBAND_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ public class CmdFWarp extends FCommand {
|
||||
this.optionalArgs.put("warpname", "warpname");
|
||||
this.optionalArgs.put("password", "password");
|
||||
|
||||
this.permission = Permission.WARP.node;
|
||||
|
||||
this.permission = Permission.WARP.node;
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = false;
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ public class CmdFly extends FCommand {
|
||||
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.FLY.node;
|
||||
|
||||
this.permission = Permission.FLY.node;
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = false;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ public class CmdFocus
|
||||
|
||||
permission = Permission.FOCUS.node;
|
||||
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
|
@ -17,7 +17,8 @@ public class CmdGetVault extends FCommand {
|
||||
this.permission = Permission.GETVAULT.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -30,7 +30,8 @@ public class CmdHome extends FCommand {
|
||||
this.permission = Permission.HOME.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -12,7 +12,8 @@ public class CmdInspect extends FCommand {
|
||||
this.permission = Permission.INSPECT.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -23,7 +23,8 @@ public class CmdInvite extends FCommand {
|
||||
this.permission = Permission.INVITE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -18,7 +18,8 @@ public class CmdJoin extends FCommand {
|
||||
this.permission = Permission.JOIN.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -26,7 +26,8 @@ public class CmdKick extends FCommand {
|
||||
this.permission = Permission.KICK.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
@ -15,7 +15,8 @@ public class CmdLeave extends FCommand {
|
||||
this.permission = Permission.LEAVE.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -31,7 +31,8 @@ public class CmdList extends FCommand {
|
||||
this.permission = Permission.LIST.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -1,43 +1,44 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdLock extends FCommand {
|
||||
|
||||
// TODO: This solution needs refactoring.
|
||||
/*
|
||||
factions.lock:
|
||||
description: use the /f lock [on/off] command to temporarily lock the data files from being overwritten
|
||||
default: op
|
||||
*/
|
||||
|
||||
public CmdLock() {
|
||||
super();
|
||||
this.aliases.add("lock");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.LOCK.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
p.setLocked(this.argAsBool(0, !p.getLocked()));
|
||||
msg(p.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_LOCK_DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdLock extends FCommand {
|
||||
|
||||
// TODO: This solution needs refactoring.
|
||||
/*
|
||||
factions.lock:
|
||||
description: use the /f lock [on/off] command to temporarily lock the data files from being overwritten
|
||||
default: op
|
||||
*/
|
||||
|
||||
public CmdLock() {
|
||||
super();
|
||||
this.aliases.add("lock");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.LOCK.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
p.setLocked(this.argAsBool(0, !p.getLocked()));
|
||||
msg(p.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_LOCK_DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ public class CmdLogins extends FCommand {
|
||||
this.aliases.add("logout");
|
||||
this.aliases.add("logouts");
|
||||
this.senderMustBePlayer = true;
|
||||
this.senderMustBeMember = true;
|
||||
|
||||
this.senderMustBeMember = true;
|
||||
this.permission = Permission.MONITOR_LOGINS.node;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@ public class CmdLowPower extends FCommand {
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
@ -19,7 +19,8 @@ public class CmdMap extends FCommand {
|
||||
this.permission = Permission.MAP.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -15,7 +15,8 @@ public class CmdMapHeight extends FCommand {
|
||||
|
||||
this.permission = Permission.MAPHEIGHT.node;
|
||||
|
||||
this.senderMustBePlayer = true;
|
||||
|
||||
this.senderMustBePlayer = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,8 @@ public class CmdMod extends FCommand {
|
||||
this.permission = Permission.MOD.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
|
@ -35,6 +35,7 @@ public class CmdMoney extends FCommand {
|
||||
this.addSubCommand(this.cmdMoneyTransferFf);
|
||||
this.addSubCommand(this.cmdMoneyTransferFp);
|
||||
this.addSubCommand(this.cmdMoneyTransferPf);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,8 @@ public class CmdMoneyBalance extends FCommand {
|
||||
this.permission = Permission.MONEY_BALANCE.node;
|
||||
this.setHelpShort(TL.COMMAND_MONEYBALANCE_SHORT.toString());
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
@ -21,7 +21,8 @@ public class CmdMoneyDeposit extends FCommand {
|
||||
|
||||
this.permission = Permission.MONEY_DEPOSIT.node;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -23,7 +23,8 @@ public class CmdMoneyTransferFf extends FCommand {
|
||||
|
||||
this.permission = Permission.MONEY_F2F.node;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -22,7 +22,8 @@ public class CmdMoneyTransferFp extends FCommand {
|
||||
|
||||
this.permission = Permission.MONEY_F2P.node;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -22,7 +22,8 @@ public class CmdMoneyTransferPf extends FCommand {
|
||||
|
||||
this.permission = Permission.MONEY_P2F.node;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -22,7 +22,8 @@ public class CmdMoneyWithdraw extends FCommand {
|
||||
|
||||
this.permission = Permission.MONEY_WITHDRAW.node;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -16,7 +16,8 @@ public class CmdNear extends FCommand {
|
||||
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -18,7 +18,8 @@ public class CmdOpen extends FCommand {
|
||||
this.permission = Permission.OPEN.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
|
@ -18,7 +18,8 @@ public class CmdOwner extends FCommand {
|
||||
this.permission = Permission.OWNER.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -19,7 +19,8 @@ public class CmdOwnerList extends FCommand {
|
||||
this.permission = Permission.OWNERLIST.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
|
@ -17,6 +17,7 @@ public class CmdPaypalSee extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
@ -17,6 +17,7 @@ public class CmdPaypalSet extends FCommand {
|
||||
this.senderMustBeModerator = false;
|
||||
this.senderMustBeColeader = true;
|
||||
this.senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
@ -1,61 +1,62 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdPeaceful extends FCommand {
|
||||
|
||||
public CmdPeaceful() {
|
||||
super();
|
||||
this.aliases.add("peaceful");
|
||||
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.SET_PEACEFUL.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String change;
|
||||
if (faction.isPeaceful()) {
|
||||
change = TL.COMMAND_PEACEFUL_REVOKE.toString();
|
||||
faction.setPeaceful(false);
|
||||
} else {
|
||||
change = TL.COMMAND_PEACEFUL_GRANT.toString();
|
||||
faction.setPeaceful(true);
|
||||
}
|
||||
|
||||
// Inform all players
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true));
|
||||
if (fplayer.getFaction() == faction) {
|
||||
fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change);
|
||||
} else {
|
||||
fplayer.msg(TL.COMMAND_PEACEFUL_OTHER, blame, change, faction.getTag(fplayer));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_PEACEFUL_DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdPeaceful extends FCommand {
|
||||
|
||||
public CmdPeaceful() {
|
||||
super();
|
||||
this.aliases.add("peaceful");
|
||||
|
||||
this.requiredArgs.add("faction tag");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.SET_PEACEFUL.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
Faction faction = this.argAsFaction(0);
|
||||
if (faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String change;
|
||||
if (faction.isPeaceful()) {
|
||||
change = TL.COMMAND_PEACEFUL_REVOKE.toString();
|
||||
faction.setPeaceful(false);
|
||||
} else {
|
||||
change = TL.COMMAND_PEACEFUL_GRANT.toString();
|
||||
faction.setPeaceful(true);
|
||||
}
|
||||
|
||||
// Inform all players
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true));
|
||||
if (fplayer.getFaction() == faction) {
|
||||
fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change);
|
||||
} else {
|
||||
fplayer.msg(TL.COMMAND_PEACEFUL_OTHER, blame, change, faction.getTag(fplayer));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_PEACEFUL_DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class CmdPerm extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ public class CmdPower extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@ public class CmdRules extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ public class CmdSafeunclaimall extends FCommand {
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,153 +1,154 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.Particles.ParticleEffect;
|
||||
import com.massivecraft.factions.util.VisualizeUtil;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CmdSeeChunk extends FCommand {
|
||||
|
||||
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
|
||||
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
|
||||
Long interval = 10L;
|
||||
private boolean useParticles;
|
||||
private int length;
|
||||
private ParticleEffect effect;
|
||||
private int taskID = - 1;
|
||||
|
||||
|
||||
//I remade it cause of people getting mad that I had the same seechunk as drtshock
|
||||
|
||||
|
||||
public CmdSeeChunk() {
|
||||
super();
|
||||
aliases.add("seechunk");
|
||||
aliases.add("sc");
|
||||
|
||||
permission = Permission.SEECHUNK.node;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.useParticles = p.getConfig().getBoolean("see-chunk.particles", true);
|
||||
interval = SavageFactions.plugin.getConfig().getLong("see-chunk.interval", 10L);
|
||||
if (effect == null) {
|
||||
effect = ParticleEffect.REDSTONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (seeChunkMap.containsKey(me.getName())) {
|
||||
seeChunkMap.remove(me.getName());
|
||||
msg(TL.COMMAND_SEECHUNK_DISABLED);
|
||||
} else {
|
||||
seeChunkMap.put(me.getName(), true);
|
||||
msg(TL.COMMAND_SEECHUNK_ENABLED);
|
||||
manageTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void manageTask() {
|
||||
if (taskID != - 1) {
|
||||
if (seeChunkMap.keySet().size() == 0) {
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
taskID = - 1;
|
||||
}
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void startTask() {
|
||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<String> itr = seeChunkMap.keySet().iterator();
|
||||
while (itr.hasNext()) {
|
||||
Object nameObject = itr.next();
|
||||
String name = nameObject + "";
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
showBorders(player);
|
||||
}
|
||||
manageTask();
|
||||
}
|
||||
}, 0, interval);
|
||||
}
|
||||
|
||||
private void showBorders(Player me) {
|
||||
World world = me.getWorld();
|
||||
FLocation flocation = new FLocation(me);
|
||||
int chunkX = (int) flocation.getX();
|
||||
int chunkZ = (int) flocation.getZ();
|
||||
|
||||
int blockX;
|
||||
int blockZ;
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
|
||||
blockX = chunkX * 16 + 15;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX * 16 + 15;
|
||||
blockZ = chunkZ * 16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
}
|
||||
|
||||
private void showPillar(Player player, World world, int blockX, int blockZ) {
|
||||
List<Player> onePlayer = Arrays.asList(player);
|
||||
for (int blockY = 0; blockY < player.getLocation().getBlockY() + 30; blockY++) {
|
||||
Location loc = new Location(world, blockX, blockY, blockZ).add(0.5, 0, 0.5);
|
||||
if (loc.getBlock().getType() != Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (useParticles) {
|
||||
if (SavageFactions.plugin.useNonPacketParticles) {
|
||||
// Dust options only exists in the 1.13 API, so we use an
|
||||
// alternative method to achieve this in lower versions.
|
||||
if (SavageFactions.plugin.mc113) {
|
||||
player.spawnParticle(Particle.REDSTONE, loc, 0, new Particle.DustOptions(Color.RED, 1));
|
||||
} else {
|
||||
player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
this.effect.display(0, 0, 0, 0, 1, loc, player);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Material type = blockY % 5 == 0 ? SavageFactions.plugin.REDSTONE_LAMP_ON : SavageFactions.plugin.STAINED_GLASS;
|
||||
VisualizeUtil.addLocation(player, loc, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.GENERIC_PLACEHOLDER;
|
||||
}
|
||||
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.Particles.ParticleEffect;
|
||||
import com.massivecraft.factions.util.VisualizeUtil;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CmdSeeChunk extends FCommand {
|
||||
|
||||
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
|
||||
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
|
||||
Long interval = 10L;
|
||||
private boolean useParticles;
|
||||
private int length;
|
||||
private ParticleEffect effect;
|
||||
private int taskID = - 1;
|
||||
|
||||
|
||||
//I remade it cause of people getting mad that I had the same seechunk as drtshock
|
||||
|
||||
|
||||
public CmdSeeChunk() {
|
||||
super();
|
||||
aliases.add("seechunk");
|
||||
aliases.add("sc");
|
||||
|
||||
permission = Permission.SEECHUNK.node;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
|
||||
this.useParticles = p.getConfig().getBoolean("see-chunk.particles", true);
|
||||
interval = SavageFactions.plugin.getConfig().getLong("see-chunk.interval", 10L);
|
||||
if (effect == null) {
|
||||
effect = ParticleEffect.REDSTONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (seeChunkMap.containsKey(me.getName())) {
|
||||
seeChunkMap.remove(me.getName());
|
||||
msg(TL.COMMAND_SEECHUNK_DISABLED);
|
||||
} else {
|
||||
seeChunkMap.put(me.getName(), true);
|
||||
msg(TL.COMMAND_SEECHUNK_ENABLED);
|
||||
manageTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void manageTask() {
|
||||
if (taskID != - 1) {
|
||||
if (seeChunkMap.keySet().size() == 0) {
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
taskID = - 1;
|
||||
}
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void startTask() {
|
||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<String> itr = seeChunkMap.keySet().iterator();
|
||||
while (itr.hasNext()) {
|
||||
Object nameObject = itr.next();
|
||||
String name = nameObject + "";
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
showBorders(player);
|
||||
}
|
||||
manageTask();
|
||||
}
|
||||
}, 0, interval);
|
||||
}
|
||||
|
||||
private void showBorders(Player me) {
|
||||
World world = me.getWorld();
|
||||
FLocation flocation = new FLocation(me);
|
||||
int chunkX = (int) flocation.getX();
|
||||
int chunkZ = (int) flocation.getZ();
|
||||
|
||||
int blockX;
|
||||
int blockZ;
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
|
||||
blockX = chunkX * 16 + 15;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX * 16 + 15;
|
||||
blockZ = chunkZ * 16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
}
|
||||
|
||||
private void showPillar(Player player, World world, int blockX, int blockZ) {
|
||||
List<Player> onePlayer = Arrays.asList(player);
|
||||
for (int blockY = 0; blockY < player.getLocation().getBlockY() + 30; blockY++) {
|
||||
Location loc = new Location(world, blockX, blockY, blockZ).add(0.5, 0, 0.5);
|
||||
if (loc.getBlock().getType() != Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (useParticles) {
|
||||
if (SavageFactions.plugin.useNonPacketParticles) {
|
||||
// Dust options only exists in the 1.13 API, so we use an
|
||||
// alternative method to achieve this in lower versions.
|
||||
if (SavageFactions.plugin.mc113) {
|
||||
player.spawnParticle(Particle.REDSTONE, loc, 0, new Particle.DustOptions(Color.RED, 1));
|
||||
} else {
|
||||
player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
this.effect.display(0, 0, 0, 0, 1, loc, player);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Material type = blockY % 5 == 0 ? SavageFactions.plugin.REDSTONE_LAMP_ON : SavageFactions.plugin.STAINED_GLASS;
|
||||
VisualizeUtil.addLocation(player, loc, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.GENERIC_PLACEHOLDER;
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ public class CmdSetBanner extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
@ -19,7 +19,8 @@ public class CmdSetDefaultRole extends FCommand {
|
||||
this.senderMustBePlayer = true;
|
||||
senderMustBeColeader = false;
|
||||
|
||||
this.permission = Permission.DEFAULTRANK.node;
|
||||
|
||||
this.permission = Permission.DEFAULTRANK.node;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,8 @@ public class CmdSetFWarp extends FCommand {
|
||||
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = false;
|
||||
this.senderMustBePlayer = true;
|
||||
|
||||
this.senderMustBePlayer = true;
|
||||
|
||||
this.permission = Permission.SETWARP.node;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public class CmdSetMaxVaults extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ public class CmdSethome extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ public class CmdShowClaims extends FCommand {
|
||||
this.senderMustBePlayer = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,7 +35,7 @@ public class CmdShowClaims extends FCommand {
|
||||
for (String world : chunkMap.keySet()) {
|
||||
String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}", world);
|
||||
sendMessage(message.replace("{chunks}", "")); // made {chunks} blank as I removed the placeholder and people wont update their config :shrug:
|
||||
StringBuilder chunks = new StringBuilder("");
|
||||
StringBuilder chunks = new StringBuilder();
|
||||
for (String chunkString : chunkMap.get(world)) {
|
||||
chunks.append(chunkString + ", ");
|
||||
if (chunks.toString().length() >= 2000) {
|
||||
|
@ -17,6 +17,7 @@ public class CmdShowInvites extends FCommand {
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ public class CmdStatus extends FCommand {
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +30,7 @@ public class CmdStatus extends FCommand {
|
||||
for (FPlayer fp : myFaction.getFPlayers()) {
|
||||
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
|
||||
String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
||||
String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + String.valueOf(fp.getPowerMaxRounded()) + ChatColor.RESET;
|
||||
String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET;
|
||||
ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim());
|
||||
}
|
||||
fme.sendMessage(ret);
|
||||
|
@ -17,6 +17,7 @@ public class CmdStealth extends FCommand {
|
||||
this.senderMustBeModerator = false;
|
||||
this.senderMustBeColeader = false;
|
||||
this.senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
@ -27,6 +27,7 @@ public class CmdStuck extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ public class CmdTag extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ public class CmdTitle extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ public class CmdTnt extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,7 @@ public class CmdTntFill extends FCommand {
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ public class CmdToggleAllianceChat extends FCommand {
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,9 +30,11 @@ public class CmdTop extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
// Can sort by: money, members, online, allies, enemies, power, land.
|
||||
// Get all Factions and remove non player ones.
|
||||
|
@ -21,6 +21,7 @@ public class CmdTpBanner extends FCommand {
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,8 @@ public class CmdUnban extends FCommand {
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ public class CmdUnclaim extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ public class CmdUnclaimall extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ public class CmdUpgrades extends FCommand {
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ public class CmdVault extends FCommand {
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ public class CmdWarunclaimall extends FCommand {
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ public abstract class FCommand extends MCommand<SavageFactions> {
|
||||
public boolean senderMustBeAdmin;
|
||||
public boolean senderMustBeColeader;
|
||||
|
||||
|
||||
public boolean isMoneyCommand;
|
||||
|
||||
public FCommand() {
|
||||
@ -98,22 +99,30 @@ public abstract class FCommand extends MCommand<SavageFactions> {
|
||||
}
|
||||
|
||||
if (!fme.hasFaction()) {
|
||||
sender.sendMessage(p.txt.parse("<b>You are not member of any faction."));
|
||||
if (informSenderIfNot) {
|
||||
sender.sendMessage(p.txt.parse("<b>You are not member of any faction."));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.senderMustBeModerator && !fme.getRole().isAtLeast(Role.MODERATOR)) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
|
||||
if (informSenderIfNot) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.senderMustBeColeader && !fme.getRole().isAtLeast(Role.COLEADER)) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction coleaders can %s.", this.getHelpShort()));
|
||||
if (informSenderIfNot) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction coleaders can %s.", this.getHelpShort()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.senderMustBeAdmin && !fme.getRole().isAtLeast(Role.LEADER)) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.getHelpShort()));
|
||||
if (informSenderIfNot) {
|
||||
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.getHelpShort()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,482 +1,486 @@
|
||||
package com.massivecraft.factions.zcore;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import mkremins.fanciful.FancyMessage;
|
||||
import org.apache.commons.lang.time.DurationFormatUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
public T p;
|
||||
|
||||
// The sub-commands to this command
|
||||
public List<MCommand<?>> subCommands;
|
||||
// The different names this commands will react to
|
||||
public List<String> aliases;
|
||||
public boolean allowNoSlashAccess;
|
||||
// Information on the args
|
||||
public List<String> requiredArgs;
|
||||
public LinkedHashMap<String, String> optionalArgs;
|
||||
public boolean errorOnToManyArgs = true;
|
||||
public List<String> helpLong;
|
||||
public CommandVisibility visibility;
|
||||
// Some information on permissions
|
||||
public boolean senderMustBePlayer;
|
||||
public String permission;
|
||||
// Information available on execution of the command
|
||||
public CommandSender sender; // Will always be set
|
||||
public Player me; // Will only be set when the sender is a player
|
||||
public boolean senderIsConsole;
|
||||
public List<String> args; // Will contain the arguments, or and empty list if there are none.
|
||||
public List<MCommand<?>> commandChain = new ArrayList<>(); // The command chain used to execute this command
|
||||
// FIELD: Help Short
|
||||
// This field may be left blank and will in such case be loaded from the permissions node instead.
|
||||
// Thus make sure the permissions node description is an action description like "eat hamburgers" or "do admin stuff".
|
||||
private String helpShort;
|
||||
|
||||
public MCommand(T p) {
|
||||
this.p = p;
|
||||
|
||||
this.permission = null;
|
||||
|
||||
this.allowNoSlashAccess = false;
|
||||
|
||||
this.subCommands = new ArrayList<>();
|
||||
this.aliases = new ArrayList<>();
|
||||
|
||||
this.requiredArgs = new ArrayList<>();
|
||||
this.optionalArgs = new LinkedHashMap<>();
|
||||
|
||||
this.helpShort = null;
|
||||
this.helpLong = new ArrayList<>();
|
||||
this.visibility = CommandVisibility.VISIBLE;
|
||||
}
|
||||
|
||||
public void addSubCommand(MCommand<?> subCommand) {
|
||||
subCommand.commandChain.addAll(this.commandChain);
|
||||
subCommand.commandChain.add(this);
|
||||
this.subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
public String getHelpShort() {
|
||||
return this.helpShort != null ? this.helpShort:getUsageTranslation().toString();
|
||||
}
|
||||
|
||||
public void setHelpShort(String val) {
|
||||
this.helpShort = val;
|
||||
}
|
||||
|
||||
public abstract TL getUsageTranslation();
|
||||
|
||||
public void setCommandSender(CommandSender sender)
|
||||
{
|
||||
this.sender = sender;
|
||||
if (sender instanceof Player) {
|
||||
this.me = (Player) sender;
|
||||
this.senderIsConsole = false;
|
||||
} else {
|
||||
this.me = null;
|
||||
this.senderIsConsole = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The commandChain is a list of the parent command chain used to get to this command.
|
||||
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
|
||||
// Set the execution-time specific variables
|
||||
setCommandSender(sender);
|
||||
this.args = args;
|
||||
this.commandChain = commandChain;
|
||||
|
||||
// Is there a matching sub command?
|
||||
if (args.size() > 0) {
|
||||
for (MCommand<?> subCommand : this.subCommands) {
|
||||
if (subCommand.aliases.contains(args.get(0).toLowerCase())) {
|
||||
args.remove(0);
|
||||
commandChain.add(this);
|
||||
subCommand.execute(sender, args, commandChain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validCall(this.sender, this.args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
perform();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, List<String> args) {
|
||||
execute(sender, args, new ArrayList<MCommand<?>>());
|
||||
}
|
||||
|
||||
// This is where the command action is performed.
|
||||
public abstract void perform();
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Call Validation
|
||||
// -------------------------------------------- //
|
||||
|
||||
/**
|
||||
* In this method we validate that all prerequisites to perform this command has been met.
|
||||
*
|
||||
* @param sender of the command
|
||||
* @param args of the command
|
||||
* @return true if valid, false if not.
|
||||
*/
|
||||
// TODO: There should be a boolean for silence
|
||||
public boolean validCall(CommandSender sender, List<String> args) {
|
||||
return validSenderType(sender, true) && validSenderPermissions(sender, true) && validArgs(args, sender);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) {
|
||||
if (this.senderMustBePlayer && !(sender instanceof Player)) {
|
||||
if (informSenderIfNot) {
|
||||
msg(TL.GENERIC_PLAYERONLY);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) {
|
||||
return this.permission == null || p.perm.has(sender, this.permission, informSenderIfNot);
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args, CommandSender sender) {
|
||||
if (args.size() < this.requiredArgs.size()) {
|
||||
if (sender != null) {
|
||||
msg(TL.GENERIC_ARGS_TOOFEW);
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs) {
|
||||
if (sender != null) {
|
||||
// Get the to many string slice
|
||||
List<String> theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size());
|
||||
msg(TL.GENERIC_ARGS_TOOMANY, TextUtil.implode(theToMany, " "));
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args) {
|
||||
return this.validArgs(args, null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Help and Usage information
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getUseageTemplate(List<MCommand<?>> commandChain, boolean addShortHelp) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append(p.txt.parseTags("<c>"));
|
||||
ret.append('/');
|
||||
|
||||
for (MCommand<?> mc : commandChain) {
|
||||
ret.append(TextUtil.implode(mc.aliases, ","));
|
||||
ret.append(' ');
|
||||
}
|
||||
|
||||
ret.append(TextUtil.implode(this.aliases, ","));
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
for (String requiredArg : this.requiredArgs) {
|
||||
args.add("<" + requiredArg + ">");
|
||||
}
|
||||
|
||||
for (Entry<String, String> optionalArg : this.optionalArgs.entrySet()) {
|
||||
String val = optionalArg.getValue();
|
||||
if (val == null) {
|
||||
val = "";
|
||||
} else {
|
||||
val = "=" + val;
|
||||
}
|
||||
args.add("[" + optionalArg.getKey() + val + "]");
|
||||
}
|
||||
|
||||
if (args.size() > 0) {
|
||||
ret.append(p.txt.parseTags("<plugin> "));
|
||||
ret.append(TextUtil.implode(args, " "));
|
||||
}
|
||||
|
||||
if (addShortHelp) {
|
||||
ret.append(p.txt.parseTags(" <i>"));
|
||||
ret.append(this.getHelpShort());
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public String getUseageTemplate(boolean addShortHelp) {
|
||||
return getUseageTemplate(this.commandChain, addShortHelp);
|
||||
}
|
||||
|
||||
public String getUseageTemplate() {
|
||||
return getUseageTemplate(false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Message Sending Helpers
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void msg(String str, Object... args) {
|
||||
sender.sendMessage(p.txt.parse(str, args));
|
||||
}
|
||||
|
||||
public void msg(TL translation, Object... args) {
|
||||
sender.sendMessage(p.txt.parse(translation.toString(), args));
|
||||
}
|
||||
|
||||
public void sendMessage(String msg) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> msgs) {
|
||||
for (String msg : msgs) {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendFancyMessage(FancyMessage message) {
|
||||
message.send(sender);
|
||||
}
|
||||
|
||||
public void sendFancyMessage(List<FancyMessage> messages) {
|
||||
for (FancyMessage m : messages) {
|
||||
sendFancyMessage(m);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getToolTips(FPlayer player) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (String s : p.getConfig().getStringList("tooltips.show")) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public List<String> getToolTips(Faction faction) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (String s : p.getConfig().getStringList("tooltips.list")) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String replaceFPlayerTags(String s, FPlayer player) {
|
||||
if (s.contains("{balance}")) {
|
||||
String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance";
|
||||
s = s.replace("{balance}", balance);
|
||||
}
|
||||
if (s.contains("{lastSeen}")) {
|
||||
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago";
|
||||
String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
||||
s = s.replace("{lastSeen}", lastSeen);
|
||||
}
|
||||
if (s.contains("{power}")) {
|
||||
String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded();
|
||||
s = s.replace("{power}", power);
|
||||
}
|
||||
if (s.contains("{group}")) {
|
||||
String group = SavageFactions.plugin.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId())));
|
||||
s = s.replace("{group}", group);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String replaceFactionTags(String s, Faction faction) {
|
||||
if (s.contains("{power}")) {
|
||||
s = s.replace("{power}", String.valueOf(faction.getPowerRounded()));
|
||||
}
|
||||
if (s.contains("{maxPower}")) {
|
||||
s = s.replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded()));
|
||||
}
|
||||
if (s.contains("{leader}")) {
|
||||
FPlayer fLeader = faction.getFPlayerAdmin();
|
||||
String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
|
||||
s = s.replace("{leader}", leader);
|
||||
}
|
||||
if (s.contains("{chunks}")) {
|
||||
s = s.replace("{chunks}", String.valueOf(faction.getLandRounded()));
|
||||
}
|
||||
if (s.contains("{members}")) {
|
||||
s = s.replace("{members}", String.valueOf(faction.getSize()));
|
||||
|
||||
}
|
||||
if (s.contains("{online}")) {
|
||||
s = s.replace("{online}", String.valueOf(faction.getOnlinePlayers().size()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Argument Readers
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Is set? ======================
|
||||
public boolean argIsSet(int idx) {
|
||||
return this.args.size() >= idx + 1;
|
||||
}
|
||||
|
||||
// STRING ======================
|
||||
public String argAsString(int idx, String def) {
|
||||
if (this.args.size() < idx + 1) {
|
||||
return def;
|
||||
}
|
||||
return this.args.get(idx);
|
||||
}
|
||||
|
||||
public String argAsString(int idx) {
|
||||
return this.argAsString(idx, null);
|
||||
}
|
||||
|
||||
// INT ======================
|
||||
public Integer strAsInt(String str, Integer def) {
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer argAsInt(int idx, Integer def) {
|
||||
return strAsInt(this.argAsString(idx), def);
|
||||
}
|
||||
|
||||
public Integer argAsInt(int idx) {
|
||||
return this.argAsInt(idx, null);
|
||||
}
|
||||
|
||||
// Double ======================
|
||||
public Double strAsDouble(String str, Double def) {
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(str);
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public Double argAsDouble(int idx, Double def) {
|
||||
return strAsDouble(this.argAsString(idx), def);
|
||||
}
|
||||
|
||||
public Double argAsDouble(int idx) {
|
||||
return this.argAsDouble(idx, null);
|
||||
}
|
||||
|
||||
// TODO: Go through the str conversion for the other arg-readers as well.
|
||||
// Boolean ======================
|
||||
public Boolean strAsBool(String str) {
|
||||
str = str.toLowerCase();
|
||||
return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1");
|
||||
}
|
||||
|
||||
public Boolean argAsBool(int idx, boolean def) {
|
||||
String str = this.argAsString(idx);
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return strAsBool(str);
|
||||
}
|
||||
|
||||
public Boolean argAsBool(int idx) {
|
||||
return this.argAsBool(idx, false);
|
||||
}
|
||||
|
||||
// PLAYER ======================
|
||||
public Player strAsPlayer(String name, Player def, boolean msg) {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
Player player = Bukkit.getServer().getPlayer(name);
|
||||
if (player != null) {
|
||||
ret = player;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg && ret == null) {
|
||||
this.msg(TL.GENERIC_NOPLAYERFOUND, name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx, Player def, boolean msg) {
|
||||
return this.strAsPlayer(this.argAsString(idx), def, msg);
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx, Player def) {
|
||||
return this.argAsPlayer(idx, def, true);
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx) {
|
||||
return this.argAsPlayer(idx, null);
|
||||
}
|
||||
|
||||
// BEST PLAYER MATCH ======================
|
||||
public Player strAsBestPlayerMatch(String name, Player def, boolean msg) {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
List<Player> players = Bukkit.getServer().matchPlayer(name);
|
||||
if (players.size() > 0) {
|
||||
ret = players.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg && ret == null) {
|
||||
this.msg(TL.GENERIC_NOPLAYERMATCH, name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) {
|
||||
return this.strAsBestPlayerMatch(this.argAsString(idx), def, msg);
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx, Player def) {
|
||||
return this.argAsBestPlayerMatch(idx, def, true);
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx) {
|
||||
return this.argAsPlayer(idx, null);
|
||||
}
|
||||
package com.massivecraft.factions.zcore;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import mkremins.fanciful.FancyMessage;
|
||||
import org.apache.commons.lang.time.DurationFormatUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public abstract class MCommand<T extends MPlugin> {
|
||||
|
||||
public T p;
|
||||
|
||||
// The sub-commands to this command
|
||||
public List<MCommand<?>> subCommands;
|
||||
// The different names this commands will react to
|
||||
public List<String> aliases;
|
||||
public boolean allowNoSlashAccess;
|
||||
// Information on the args
|
||||
public List<String> requiredArgs;
|
||||
public LinkedHashMap<String, String> optionalArgs;
|
||||
public boolean errorOnToManyArgs = true;
|
||||
public List<String> helpLong;
|
||||
public CommandVisibility visibility;
|
||||
// Some information on permissions
|
||||
public boolean senderMustBePlayer;
|
||||
public boolean senderMustHaveFaction;
|
||||
public String permission;
|
||||
// Information available on execution of the command
|
||||
public CommandSender sender; // Will always be set
|
||||
public Player me; // Will only be set when the sender is a player
|
||||
public boolean senderIsConsole;
|
||||
public List<String> args; // Will contain the arguments, or and empty list if there are none.
|
||||
public List<MCommand<?>> commandChain = new ArrayList<>(); // The command chain used to execute this command
|
||||
// FIELD: Help Short
|
||||
// This field may be left blank and will in such case be loaded from the permissions node instead.
|
||||
// Thus make sure the permissions node description is an action description like "eat hamburgers" or "do admin stuff".
|
||||
private String helpShort;
|
||||
|
||||
public MCommand(T p) {
|
||||
this.p = p;
|
||||
|
||||
this.permission = null;
|
||||
|
||||
this.allowNoSlashAccess = false;
|
||||
|
||||
this.subCommands = new ArrayList<>();
|
||||
this.aliases = new ArrayList<>();
|
||||
|
||||
this.requiredArgs = new ArrayList<>();
|
||||
this.optionalArgs = new LinkedHashMap<>();
|
||||
|
||||
this.helpShort = null;
|
||||
this.helpLong = new ArrayList<>();
|
||||
this.visibility = CommandVisibility.VISIBLE;
|
||||
}
|
||||
|
||||
public void addSubCommand(MCommand<?> subCommand) {
|
||||
subCommand.commandChain.addAll(this.commandChain);
|
||||
subCommand.commandChain.add(this);
|
||||
this.subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
public String getHelpShort() {
|
||||
return this.helpShort != null ? this.helpShort:getUsageTranslation().toString();
|
||||
}
|
||||
|
||||
public void setHelpShort(String val) {
|
||||
this.helpShort = val;
|
||||
}
|
||||
|
||||
public abstract TL getUsageTranslation();
|
||||
|
||||
public void setCommandSender(CommandSender sender)
|
||||
{
|
||||
this.sender = sender;
|
||||
if (sender instanceof Player) {
|
||||
this.me = (Player) sender;
|
||||
this.senderIsConsole = false;
|
||||
} else {
|
||||
this.me = null;
|
||||
this.senderIsConsole = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The commandChain is a list of the parent command chain used to get to this command.
|
||||
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
|
||||
// Set the execution-time specific variables
|
||||
setCommandSender(sender);
|
||||
this.args = args;
|
||||
this.commandChain = commandChain;
|
||||
|
||||
// Is there a matching sub command?
|
||||
if (args.size() > 0) {
|
||||
for (MCommand<?> subCommand : this.subCommands) {
|
||||
if (subCommand.aliases.contains(args.get(0).toLowerCase())) {
|
||||
args.remove(0);
|
||||
commandChain.add(this);
|
||||
subCommand.execute(sender, args, commandChain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validCall(this.sender, this.args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
perform();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, List<String> args) {
|
||||
execute(sender, args, new ArrayList<MCommand<?>>());
|
||||
}
|
||||
|
||||
// This is where the command action is performed.
|
||||
public abstract void perform();
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Call Validation
|
||||
// -------------------------------------------- //
|
||||
|
||||
/**
|
||||
* In this method we validate that all prerequisites to perform this command has been met.
|
||||
*
|
||||
* @param sender of the command
|
||||
* @param args of the command
|
||||
* @return true if valid, false if not.
|
||||
*/
|
||||
// TODO: There should be a boolean for silence
|
||||
public boolean validCall(CommandSender sender, List<String> args) {
|
||||
return validSenderType(sender, true) && validSenderPermissions(sender, true) && validArgs(args, sender);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) {
|
||||
if (this.senderMustBePlayer && !(sender instanceof Player)) {
|
||||
if (informSenderIfNot) {
|
||||
msg(TL.GENERIC_PLAYERONLY);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return !this.senderMustHaveFaction || !FPlayers.getInstance().getByPlayer((Player) sender).hasFaction();
|
||||
}
|
||||
|
||||
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) {
|
||||
return this.permission == null || p.perm.has(sender, this.permission, informSenderIfNot);
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args, CommandSender sender) {
|
||||
if (args.size() < this.requiredArgs.size()) {
|
||||
if (sender != null) {
|
||||
msg(TL.GENERIC_ARGS_TOOFEW);
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs) {
|
||||
if (sender != null) {
|
||||
// Get the to many string slice
|
||||
List<String> theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size());
|
||||
msg(TL.GENERIC_ARGS_TOOMANY, TextUtil.implode(theToMany, " "));
|
||||
sender.sendMessage(this.getUseageTemplate());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validArgs(List<String> args) {
|
||||
return this.validArgs(args, null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Help and Usage information
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getUseageTemplate(List<MCommand<?>> commandChain, boolean addShortHelp) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append(p.txt.parseTags("<c>"));
|
||||
ret.append('/');
|
||||
|
||||
for (MCommand<?> mc : commandChain) {
|
||||
ret.append(TextUtil.implode(mc.aliases, ","));
|
||||
ret.append(' ');
|
||||
}
|
||||
|
||||
ret.append(TextUtil.implode(this.aliases, ","));
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
for (String requiredArg : this.requiredArgs) {
|
||||
args.add("<" + requiredArg + ">");
|
||||
}
|
||||
|
||||
for (Entry<String, String> optionalArg : this.optionalArgs.entrySet()) {
|
||||
String val = optionalArg.getValue();
|
||||
if (val == null) {
|
||||
val = "";
|
||||
} else {
|
||||
val = "=" + val;
|
||||
}
|
||||
args.add("[" + optionalArg.getKey() + val + "]");
|
||||
}
|
||||
|
||||
if (args.size() > 0) {
|
||||
ret.append(p.txt.parseTags("<plugin> "));
|
||||
ret.append(TextUtil.implode(args, " "));
|
||||
}
|
||||
|
||||
if (addShortHelp) {
|
||||
ret.append(p.txt.parseTags(" <i>"));
|
||||
ret.append(this.getHelpShort());
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public String getUseageTemplate(boolean addShortHelp) {
|
||||
return getUseageTemplate(this.commandChain, addShortHelp);
|
||||
}
|
||||
|
||||
public String getUseageTemplate() {
|
||||
return getUseageTemplate(false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Message Sending Helpers
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void msg(String str, Object... args) {
|
||||
sender.sendMessage(p.txt.parse(str, args));
|
||||
}
|
||||
|
||||
public void msg(TL translation, Object... args) {
|
||||
sender.sendMessage(p.txt.parse(translation.toString(), args));
|
||||
}
|
||||
|
||||
public void sendMessage(String msg) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> msgs) {
|
||||
for (String msg : msgs) {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendFancyMessage(FancyMessage message) {
|
||||
message.send(sender);
|
||||
}
|
||||
|
||||
public void sendFancyMessage(List<FancyMessage> messages) {
|
||||
for (FancyMessage m : messages) {
|
||||
sendFancyMessage(m);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getToolTips(FPlayer player) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (String s : p.getConfig().getStringList("tooltips.show")) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public List<String> getToolTips(Faction faction) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (String s : p.getConfig().getStringList("tooltips.list")) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String replaceFPlayerTags(String s, FPlayer player) {
|
||||
if (s.contains("{balance}")) {
|
||||
String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance";
|
||||
s = s.replace("{balance}", balance);
|
||||
}
|
||||
if (s.contains("{lastSeen}")) {
|
||||
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago";
|
||||
String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
||||
s = s.replace("{lastSeen}", lastSeen);
|
||||
}
|
||||
if (s.contains("{power}")) {
|
||||
String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded();
|
||||
s = s.replace("{power}", power);
|
||||
}
|
||||
if (s.contains("{group}")) {
|
||||
String group = SavageFactions.plugin.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId())));
|
||||
s = s.replace("{group}", group);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String replaceFactionTags(String s, Faction faction) {
|
||||
if (s.contains("{power}")) {
|
||||
s = s.replace("{power}", String.valueOf(faction.getPowerRounded()));
|
||||
}
|
||||
if (s.contains("{maxPower}")) {
|
||||
s = s.replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded()));
|
||||
}
|
||||
if (s.contains("{leader}")) {
|
||||
FPlayer fLeader = faction.getFPlayerAdmin();
|
||||
String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
|
||||
s = s.replace("{leader}", leader);
|
||||
}
|
||||
if (s.contains("{chunks}")) {
|
||||
s = s.replace("{chunks}", String.valueOf(faction.getLandRounded()));
|
||||
}
|
||||
if (s.contains("{members}")) {
|
||||
s = s.replace("{members}", String.valueOf(faction.getSize()));
|
||||
|
||||
}
|
||||
if (s.contains("{online}")) {
|
||||
s = s.replace("{online}", String.valueOf(faction.getOnlinePlayers().size()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Argument Readers
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Is set? ======================
|
||||
public boolean argIsSet(int idx) {
|
||||
return this.args.size() >= idx + 1;
|
||||
}
|
||||
|
||||
// STRING ======================
|
||||
public String argAsString(int idx, String def) {
|
||||
if (this.args.size() < idx + 1) {
|
||||
return def;
|
||||
}
|
||||
return this.args.get(idx);
|
||||
}
|
||||
|
||||
public String argAsString(int idx) {
|
||||
return this.argAsString(idx, null);
|
||||
}
|
||||
|
||||
// INT ======================
|
||||
public Integer strAsInt(String str, Integer def) {
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer argAsInt(int idx, Integer def) {
|
||||
return strAsInt(this.argAsString(idx), def);
|
||||
}
|
||||
|
||||
public Integer argAsInt(int idx) {
|
||||
return this.argAsInt(idx, null);
|
||||
}
|
||||
|
||||
// Double ======================
|
||||
public Double strAsDouble(String str, Double def) {
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(str);
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public Double argAsDouble(int idx, Double def) {
|
||||
return strAsDouble(this.argAsString(idx), def);
|
||||
}
|
||||
|
||||
public Double argAsDouble(int idx) {
|
||||
return this.argAsDouble(idx, null);
|
||||
}
|
||||
|
||||
// TODO: Go through the str conversion for the other arg-readers as well.
|
||||
// Boolean ======================
|
||||
public Boolean strAsBool(String str) {
|
||||
str = str.toLowerCase();
|
||||
return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1");
|
||||
}
|
||||
|
||||
public Boolean argAsBool(int idx, boolean def) {
|
||||
String str = this.argAsString(idx);
|
||||
if (str == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return strAsBool(str);
|
||||
}
|
||||
|
||||
public Boolean argAsBool(int idx) {
|
||||
return this.argAsBool(idx, false);
|
||||
}
|
||||
|
||||
// PLAYER ======================
|
||||
public Player strAsPlayer(String name, Player def, boolean msg) {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
Player player = Bukkit.getServer().getPlayer(name);
|
||||
if (player != null) {
|
||||
ret = player;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg && ret == null) {
|
||||
this.msg(TL.GENERIC_NOPLAYERFOUND, name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx, Player def, boolean msg) {
|
||||
return this.strAsPlayer(this.argAsString(idx), def, msg);
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx, Player def) {
|
||||
return this.argAsPlayer(idx, def, true);
|
||||
}
|
||||
|
||||
public Player argAsPlayer(int idx) {
|
||||
return this.argAsPlayer(idx, null);
|
||||
}
|
||||
|
||||
// BEST PLAYER MATCH ======================
|
||||
public Player strAsBestPlayerMatch(String name, Player def, boolean msg) {
|
||||
Player ret = def;
|
||||
|
||||
if (name != null) {
|
||||
List<Player> players = Bukkit.getServer().matchPlayer(name);
|
||||
if (players.size() > 0) {
|
||||
ret = players.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg && ret == null) {
|
||||
this.msg(TL.GENERIC_NOPLAYERMATCH, name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) {
|
||||
return this.strAsBestPlayerMatch(this.argAsString(idx), def, msg);
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx, Player def) {
|
||||
return this.argAsBestPlayerMatch(idx, def, true);
|
||||
}
|
||||
|
||||
public Player argAsBestPlayerMatch(int idx) {
|
||||
return this.argAsPlayer(idx, null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user