Added the ability to toggle titles when entering claims of a different faction

Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
This commit is contained in:
DroppingAnvil 2019-11-28 19:34:39 -06:00
parent f5e9ce3d90
commit 36f22262c6
8 changed files with 49 additions and 2 deletions

View File

@ -30,6 +30,18 @@ public interface FPlayer extends EconomyParticipator {
boolean hasNotificationsEnabled(); boolean hasNotificationsEnabled();
/**
* Used to check if this player should be served titles
* @return if this FPlayer has titles enabled as a boolean
*/
boolean hasTitlesEnabled();
/**
* Used to set if player should be served titles
* @param b Boolean to titlesEnabled to
*/
void setTitlesEnabled(Boolean b);
/** /**
* Used to determine if a player is in their faction's chest * Used to determine if a player is in their faction's chest
* @return if player is in their faction's as a boolean * @return if player is in their faction's as a boolean

View File

@ -0,0 +1,21 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdPlayerTitleToggle extends FCommand {
public CmdPlayerTitleToggle() {
super();
this.aliases.add("titles");
this.requirements = new CommandRequirements.Builder(Permission.TOGGLE_TITLES)
.build();
}
@Override
public void perform(CommandContext context) {
context.fPlayer.setTitlesEnabled(!context.fPlayer.hasTitlesEnabled());
context.msg(TL.COMMAND_TITLETOGGLE_TOGGLED, context.fPlayer.hasTitlesEnabled() ? FactionsPlugin.getInstance().color("&dEnabled") : FactionsPlugin.getInstance().color("&dDisabled"));
}
@Override
public TL getUsageTranslation() {return TL.COMMAND_TITLETOGGLE_DESCRIPTION;}
}

View File

@ -87,6 +87,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdStuck cmdStuck = new CmdStuck(); public CmdStuck cmdStuck = new CmdStuck();
public CmdTag cmdTag = new CmdTag(); public CmdTag cmdTag = new CmdTag();
public CmdTitle cmdTitle = new CmdTitle(); public CmdTitle cmdTitle = new CmdTitle();
public CmdPlayerTitleToggle cmdPlayerTitleToggle = new CmdPlayerTitleToggle();
public CmdToggleAllianceChat cmdToggleAllianceChat = new CmdToggleAllianceChat(); public CmdToggleAllianceChat cmdToggleAllianceChat = new CmdToggleAllianceChat();
public CmdUnclaim cmdUnclaim = new CmdUnclaim(); public CmdUnclaim cmdUnclaim = new CmdUnclaim();
public CmdUnclaimall cmdUnclaimall = new CmdUnclaimall(); public CmdUnclaimall cmdUnclaimall = new CmdUnclaimall();
@ -215,6 +216,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdLogout); this.addSubCommand(this.cmdLogout);
this.addSubCommand(this.cmdTag); this.addSubCommand(this.cmdTag);
this.addSubCommand(this.cmdTitle); this.addSubCommand(this.cmdTitle);
this.addSubCommand(this.cmdPlayerTitleToggle);
this.addSubCommand(this.cmdUnclaim); this.addSubCommand(this.cmdUnclaim);
this.addSubCommand(this.cmdUnclaimall); this.addSubCommand(this.cmdUnclaimall);
this.addSubCommand(this.cmdVersion); this.addSubCommand(this.cmdVersion);

View File

@ -714,7 +714,7 @@ public class FactionsPlayerListener implements Listener {
if (changedFaction) { if (changedFaction) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> Bukkit.getServer().getPluginManager().callEvent(new FPlayerEnteredFactionEvent(factionTo, factionFrom, me))); Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> Bukkit.getServer().getPluginManager().callEvent(new FPlayerEnteredFactionEvent(factionTo, factionFrom, me)));
if (FactionsPlugin.instance.getConfig().getBoolean("Title.Show-Title")) { if (FactionsPlugin.instance.getConfig().getBoolean("Title.Show-Title") && me.hasTitlesEnabled()) {
String title = FactionsPlugin.instance.getConfig().getString("Title.Format.Title"); String title = FactionsPlugin.instance.getConfig().getString("Title.Format.Title");
title = title.replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag()); title = title.replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag());
title = parseAllPlaceholders(title, factionTo, player); title = parseAllPlaceholders(title, factionTo, player);

View File

@ -108,6 +108,7 @@ public enum Permission {
STEALTH("stealth"), STEALTH("stealth"),
STUCK("stuck"), STUCK("stuck"),
TAG("tag"), TAG("tag"),
TOGGLE_TITLES("toggletitles"),
TNT("tnt"), TNT("tnt"),
TITLE("title"), TITLE("title"),
TITLE_COLOR("title.color"), TITLE_COLOR("title.color"),

View File

@ -78,6 +78,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected transient boolean shouldTakeFallDamage = true; protected transient boolean shouldTakeFallDamage = true;
protected boolean isStealthEnabled = false; protected boolean isStealthEnabled = false;
protected boolean notificationsEnabled = true; protected boolean notificationsEnabled = true;
protected boolean titlesEnabled = true;
protected boolean isAlt = false; protected boolean isAlt = false;
boolean inspectMode = false; boolean inspectMode = false;
@ -217,7 +218,12 @@ public abstract class MemoryFPlayer implements FPlayer {
public boolean hasNotificationsEnabled() { public boolean hasNotificationsEnabled() {
return this.notificationsEnabled; return this.notificationsEnabled;
} }
public boolean hasTitlesEnabled() {
return this.titlesEnabled;
}
public void setTitlesEnabled(Boolean b) {
this.titlesEnabled = b;
}
public String getFactionId() { public String getFactionId() {
return this.factionId; return this.factionId;
} }

View File

@ -867,6 +867,10 @@ public enum TL {
COMMAND_TITLE_CHANGED("%1$s changed a title: %2$s"), COMMAND_TITLE_CHANGED("%1$s changed a title: %2$s"),
COMMAND_TITLE_DESCRIPTION("Set or remove a players title"), COMMAND_TITLE_DESCRIPTION("Set or remove a players title"),
COMMAND_TITLETOGGLE_TOGGLED("You have changed your title setting to &c%1$s"),
COMMAND_TITLETOGGLE_DESCRIPTION("Toggle titles to be served to you"),
COMMAND_TOGGLEALLIANCECHAT_DESCRIPTION("Toggles whether or not you will see alliance chat"), COMMAND_TOGGLEALLIANCECHAT_DESCRIPTION("Toggles whether or not you will see alliance chat"),
COMMAND_TOGGLEALLIANCECHAT_IGNORE("Alliance chat is now ignored"), COMMAND_TOGGLEALLIANCECHAT_IGNORE("Alliance chat is now ignored"),
COMMAND_TOGGLEALLIANCECHAT_UNIGNORE("Alliance chat is no longer ignored"), COMMAND_TOGGLEALLIANCECHAT_UNIGNORE("Alliance chat is no longer ignored"),

View File

@ -104,6 +104,7 @@ permissions:
factions.show: true factions.show: true
factions.stuck: true factions.stuck: true
factions.tag: true factions.tag: true
factions.toggletitles: true
factions.title: true factions.title: true
factions.version: true factions.version: true
factions.unclaim: true factions.unclaim: true