Completely Reformatted Alts System for Better Performance and Command Help

This commit is contained in:
Driftay 2019-05-22 20:12:46 -04:00
parent c5445e2d17
commit edc62a8493
13 changed files with 310 additions and 14 deletions

View File

@ -69,7 +69,7 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version> <version>2.3.2</version>
<configuration> <configuration>
<finalName>SavageFactionsPlus-${maven.build.timestamp}</finalName> <finalName>SavageFactionsPlus</finalName>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -0,0 +1,51 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdAlts extends FCommand {
public CmdKickAlt cmdKickAlt = new CmdKickAlt();
public CmdInviteAlt cmdInviteAlt = new CmdInviteAlt();
public CmdAltsList cmdAltsList = new CmdAltsList();
public CmdAlts(){
super();
this.aliases.add("alts");
this.aliases.add("alt");
this.permission = Permission.ALTS.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.addSubCommand(this.cmdInviteAlt);
this.addSubCommand(this.cmdKickAlt);
this.addSubCommand(this.cmdAltsList);
}
@Override
public void perform() {
if (!SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled", false)) {
fme.msg(TL.GENERIC_DISABLED);
return;
}
this.commandChain.add(this);
SavageFactions.plugin.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALTS_DESCRIPTION;
}
}

View File

@ -0,0 +1,44 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.ChatColor;
import java.util.ArrayList;
public class CmdAltsList extends FCommand{
public CmdAltsList() {
super();
this.aliases.add("list");
this.permission = Permission.LIST.node;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
ArrayList<String> ret = new ArrayList<>();
for (FPlayer fp : myFaction.getAltPlayers()) {
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()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET;
ret.add(String.format(TL.COMMAND_ALTS_LIST_FORMAT.toString(), ChatColor.GOLD + fp.getName() + ChatColor.RESET, power, last).trim());
}
fme.sendMessage(ret);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALTS_LIST_DESCRIPTION;
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdGrace extends FCommand {
public CmdGrace() {
super();
this.aliases.add("grace");
this.permission = Permission.GRACE.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (!SavageFactions.plugin.getConfig().getBoolean("f-grace.Enabled")) {
fme.msg(TL.GENERIC_DISABLED);
return;
}
boolean gracePeriod = Conf.gracePeriod;
if (args.size() == 0) {
if (gracePeriod)
Conf.gracePeriod = false;
else
Conf.gracePeriod = true;
}
fme.msg(TL.COMMAND_GRACE_TOGGLE, gracePeriod ? "enabled" : "disabled");
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_GRACE_DESCRIPTION;
}
}

View File

@ -15,10 +15,7 @@ public class CmdInviteAlt extends FCommand {
public CmdInviteAlt() { public CmdInviteAlt() {
super(); super();
this.aliases.add("altinvite"); this.aliases.add("invite");
this.aliases.add("altinv");
this.aliases.add("invalt");
this.aliases.add("invitealt");
this.requiredArgs.add("player name"); this.requiredArgs.add("player name");
// this.optionalArgs.put("", ""); // this.optionalArgs.put("", "");
@ -47,7 +44,6 @@ public class CmdInviteAlt extends FCommand {
if (target.getFaction() == myFaction) { if (target.getFaction() == myFaction) {
msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag()); msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag());
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdAltKick.getUseageTemplate(false));
return; return;
} }
@ -86,7 +82,7 @@ public class CmdInviteAlt extends FCommand {
message.send(target.getPlayer()); message.send(target.getPlayer());
myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), target.describeTo(myFaction)); myFaction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, fme.describeTo(myFaction, true), target.describeTo(myFaction));
} }
@Override @Override

View File

@ -120,6 +120,7 @@ public class CmdJoin extends FCommand {
if (!samePlayer) { if (!samePlayer) {
fplayer.msg(TL.COMMAND_JOIN_MOVED, fme.describeTo(fplayer, true), faction.getTag(fplayer)); fplayer.msg(TL.COMMAND_JOIN_MOVED, fme.describeTo(fplayer, true), faction.getTag(fplayer));
} }
faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true)); faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true));
fplayer.resetFactionData(); fplayer.resetFactionData();

View File

@ -68,7 +68,8 @@ public class CmdKick extends FCommand {
} }
if(toKick.isAlt()){ if(toKick.isAlt()){
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdAltKick.getUseageTemplate(false)); msg(SavageFactions.plugin.color("&cToo few arguments, &eUse like this:"));
msg(SavageFactions.plugin.color("&b/f alts,alt kick &3<player name>"));
return; return;
} }

View File

@ -0,0 +1,147 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
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;
public class CmdKickAlt extends FCommand{
public CmdKickAlt(){
super();
this.aliases.add("kick");
this.requiredArgs.add("player name");
// this.optionalArgs.put("", "");
this.permission = Permission.KICK.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (!SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled", false)) {
fme.msg(TL.GENERIC_DISABLED);
return;
}
FPlayer toKick = this.argIsSet(0) ? this.argAsBestFPlayerMatch(0) : null;
if (toKick == null) {
msg(TL.COMMAND_ALTKICK_NOTMEMBER);
return;
}
if (fme == toKick) {
msg(TL.COMMAND_KICK_SELF);
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdLeave.getUseageTemplate(false));
return;
}
Faction toKickFaction = toKick.getFaction();
if (toKickFaction.isWilderness()) {
sender.sendMessage(TL.COMMAND_KICK_NONE.toString());
return;
}
// players with admin-level "disband" permission can bypass these
// requirements
if (!Permission.KICK_ANY.has(sender)) {
Access access = myFaction.getAccess(fme, PermissableAction.KICKALT);
if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) {
fme.msg(TL.GENERIC_NOPERMISSION, "kickalt");
return;
}
if (toKickFaction != myFaction) {
msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(fme, true), myFaction.describeTo(fme));
return;
}
if (!toKick.isAlt()) {
msg(TL.COMMAND_ALTKICK_NOTALT);
return;
}
// Check for Access before we check for Role.
if (access != Access.ALLOW && toKick.getRole().value >= fme.getRole().value) {
msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return;
}
if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) {
msg(TL.COMMAND_KICK_NEGATIVEPOWER);
return;
}
}
Access access = myFaction.getAccess(fme, PermissableAction.KICKALT);
// This statement allows us to check if they've specifically denied it,
// or default to
// the old setting of allowing moderators to kick
if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) {
fme.msg(TL.GENERIC_NOPERMISSION, "kickalt");
return;
}
// if economy is enabled, they're not on the bypass list, and this
// command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) {
return;
}
// trigger the leave event (cancellable) [reason:kicked]
FPlayerLeaveEvent event = new FPlayerLeaveEvent(toKick, toKick.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) {
return;
}
toKickFaction.msg(TL.COMMAND_KICK_FACTION, fme.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true));
toKick.msg(TL.COMMAND_KICK_KICKED, fme.describeTo(toKick, true), toKickFaction.describeTo(toKick));
if (toKickFaction != myFaction) {
fme.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(fme), toKickFaction.describeTo(fme));
}
if (Conf.logFactionKick) {
SavageFactions.plugin.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + toKick.getName() + " from the faction: "
+ toKickFaction.getTag());
}
// SHOULD NOT BE POSSIBLE BUT KEPT INCASE
if (toKick.getRole() == Role.LEADER) {
toKickFaction.promoteNewLeader();
}
toKickFaction.removeAltPlayer(toKick);
toKickFaction.deinvite(toKick);
toKick.resetFactionData();
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALTKICK_DESCRIPTION;
}
}

View File

@ -107,8 +107,7 @@ public class FCmdRoot extends FCommand {
public CmdSetBanner cmdSetBanner = new CmdSetBanner(); public CmdSetBanner cmdSetBanner = new CmdSetBanner();
public CmdStrike cmdStrike = new CmdStrike(); public CmdStrike cmdStrike = new CmdStrike();
public CmdSetStrikes cmdSetStrikes = new CmdSetStrikes(); public CmdSetStrikes cmdSetStrikes = new CmdSetStrikes();
public CmdKickAlt cmdAltKick = new CmdKickAlt(); public CmdAlts cmdAlts = new CmdAlts();
public CmdInviteAlt cmdAltInvite = new CmdInviteAlt();
@ -224,9 +223,9 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdChest); this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdSetBanner); this.addSubCommand(this.cmdSetBanner);
if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){ if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){
this.addSubCommand(this.cmdAltInvite); this.addSubCommand(cmdAlts);
this.addSubCommand(this.cmdAltKick);
} }
if (SavageFactions.plugin.getConfig().getBoolean("f-grace.Enabled")) { if (SavageFactions.plugin.getConfig().getBoolean("f-grace.Enabled")) {

View File

@ -8,8 +8,8 @@ public enum Permission {
MANAGE_WAR_ZONE("managewarzone"), MANAGE_WAR_ZONE("managewarzone"),
OWNERSHIP_BYPASS("ownershipbypass"), OWNERSHIP_BYPASS("ownershipbypass"),
ADMIN("admin"), ADMIN("admin"),
ALTS("alts"),
ADMIN_ANY("admin.any"), ADMIN_ANY("admin.any"),
INVITEALT("invitealt"),
AHOME("ahome"), AHOME("ahome"),
ANNOUNCE("announce"), ANNOUNCE("announce"),
AUTOCLAIM("autoclaim"), AUTOCLAIM("autoclaim"),
@ -25,6 +25,7 @@ public enum Permission {
CONFIG("config"), CONFIG("config"),
CONVERT("convert"), CONVERT("convert"),
CREATE("create"), CREATE("create"),
CORNER("corner"),
DEFAULTRANK("defaultrank"), DEFAULTRANK("defaultrank"),
DEINVITE("deinvite"), DEINVITE("deinvite"),
DESCRIPTION("description"), DESCRIPTION("description"),

View File

@ -155,6 +155,8 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
return String.valueOf(faction.getDeaths()); return String.valueOf(faction.getDeaths());
case "faction_maxvaults": case "faction_maxvaults":
return String.valueOf(faction.getMaxVaults()); return String.valueOf(faction.getMaxVaults());
case "faction_grace":
return String.valueOf(Conf.gracePeriod);
case "faction_name_at_location": case "faction_name_at_location":
Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation())); Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation()));
return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag(); return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag();

View File

@ -63,7 +63,6 @@ public enum TL {
/** /**
* Messsges for /f help * Messsges for /f help
*/ */
ALT_PLACE_DENY("&c[!] &7You are a alt you may not place blocks!"),
COMMAND_HELP_NEXTCREATE("<i>Learn how to create a faction on the next page."), COMMAND_HELP_NEXTCREATE("<i>Learn how to create a faction on the next page."),
COMMAND_HELP_INVITATIONS("command.help.invitations", "<i>You might want to close it and use invitations:"), COMMAND_HELP_INVITATIONS("command.help.invitations", "<i>You might want to close it and use invitations:"),
COMMAND_HELP_HOME("<i>And don't forget to set your home:"), COMMAND_HELP_HOME("<i>And don't forget to set your home:"),
@ -134,6 +133,10 @@ public enum TL {
COMMAND_ANNOUNCE_DESCRIPTION("Announce a message to players in faction."), COMMAND_ANNOUNCE_DESCRIPTION("Announce a message to players in faction."),
COMMAND_ALTS_DESCRIPTION("Faction Alts Commands"),
COMMAND_ALTS_LIST_DESCRIPTION("List all alts in your faction"),
COMMAND_FREECAM_ENEMYINRADIUS("Freecam disabled, An enemy is closeby!"), COMMAND_FREECAM_ENEMYINRADIUS("Freecam disabled, An enemy is closeby!"),
COMMAND_FREECAM_OUTSIDEFLIGHT("Please dont leave the flight radius!"), COMMAND_FREECAM_OUTSIDEFLIGHT("Please dont leave the flight radius!"),
COMMAND_FREECAM_ENABLED("Freecam is now enabled!"), COMMAND_FREECAM_ENABLED("Freecam is now enabled!"),
@ -356,6 +359,8 @@ public enum TL {
COMMAND_INVITE_CLICKTOJOIN("Click to join!"), COMMAND_INVITE_CLICKTOJOIN("Click to join!"),
COMMAND_INVITE_INVITEDYOU(" &chas invited you to join "), COMMAND_INVITE_INVITEDYOU(" &chas invited you to join "),
COMMAND_INVITE_INVITED("&c&l[!]&7 &c%1$s&7 invited &c%2$s&7 to your faction."), COMMAND_INVITE_INVITED("&c&l[!]&7 &c%1$s&7 invited &c%2$s&7 to your faction."),
COMMAND_ALTINVITE_INVITED_ALT("&c&l[!]&7 &c%1$s&7 invited &c%2$s&7 to your faction as an alt."),
COMMAND_INVITE_ALREADYMEMBER("&c&l[!]&7 &c%1$s&7 is already a member of&c %2$s"), COMMAND_INVITE_ALREADYMEMBER("&c&l[!]&7 &c%1$s&7 is already a member of&c %2$s"),
COMMAND_INVITE_ALREADYINVITED("&c&l[!]&7 &c%1$s&7 has already been invited"), COMMAND_INVITE_ALREADYINVITED("&c&l[!]&7 &c%1$s&7 has already been invited"),
COMMAND_INVITE_DESCRIPTION("Invite a player to your faction"), COMMAND_INVITE_DESCRIPTION("Invite a player to your faction"),
@ -676,6 +681,8 @@ public enum TL {
COMMAND_SHOWINVITES_CLICKTOREVOKE("Click to revoke invite for %1$s"), COMMAND_SHOWINVITES_CLICKTOREVOKE("Click to revoke invite for %1$s"),
COMMAND_SHOWINVITES_DESCRIPTION("Show pending faction invites"), COMMAND_SHOWINVITES_DESCRIPTION("Show pending faction invites"),
COMMAND_ALTS_LIST_FORMAT("%1$s Power: %2$s Last Seen: %3$s"),
COMMAND_STATUS_FORMAT("%1$s Power: %2$s Last Seen: %3$s"), COMMAND_STATUS_FORMAT("%1$s Power: %2$s Last Seen: %3$s"),
COMMAND_STATUS_ONLINE("Online"), COMMAND_STATUS_ONLINE("Online"),
COMMAND_STATUS_AGOSUFFIX(" ago."), COMMAND_STATUS_AGOSUFFIX(" ago."),

View File

@ -1132,6 +1132,7 @@ Tntfill:
max-radius: 32 max-radius: 32
max-amount: 64 max-amount: 64
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
# | Big List of variables | # # | Big List of variables | #