From 751f46e57e326334e15501ef8ff4183ac92b5d86 Mon Sep 17 00:00:00 2001 From: Driftay Date: Mon, 30 Jul 2018 12:05:28 -0400 Subject: [PATCH] F Stealth Added Signed-off-by: Driftay --- .../java/com/massivecraft/factions/Conf.java | 4 +- .../com/massivecraft/factions/FPlayer.java | 5 +++ .../com/massivecraft/factions/cmd/CmdFly.java | 3 +- .../massivecraft/factions/cmd/CmdStealth.java | 43 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/struct/Permission.java | 1 + .../factions/zcore/persist/MemoryFPlayer.java | 27 ++++++------ .../massivecraft/factions/zcore/util/TL.java | 4 ++ src/main/resources/plugin.yml | 2 + 9 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdStealth.java diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 91258e52..94a7bbd3 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -20,6 +20,8 @@ public class Conf { public static final transient boolean DYNMAP_STYLE_BOOST = false; public static List baseCommandAliases = new ArrayList<>(); public static boolean allowNoSlashCommand = true; + public static Set allowedStealthFactions = new LinkedHashSet<>(); + // Colors public static ChatColor colorMember = ChatColor.GREEN; public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; @@ -76,7 +78,7 @@ public class Conf { public static String allianceChatFormat = ChatColor.LIGHT_PURPLE + "%s:" + ChatColor.WHITE + " %s"; public static String truceChatFormat = ChatColor.DARK_PURPLE + "%s:" + ChatColor.WHITE + " %s"; public static String modChatFormat = ChatColor.RED + "%s:" + ChatColor.WHITE + " %s"; - public static int enemyFlyCheckRadius = 16; + public static int stealthFlyCheckRadius = 32; public static boolean noEnderpearlsInFly = false; public static boolean broadcastDescriptionChanges = false; public static boolean broadcastTagChanges = false; diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index cc8adfb1..46bccc4e 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -27,6 +27,11 @@ import java.util.List; */ public interface FPlayer extends EconomyParticipator { + + boolean isStealthEnabled(); + + void setStealth(boolean isStealthEnabled); + void login(); void logout(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index e253580f..34d8ee7c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -206,7 +206,7 @@ public class CmdFly extends FCommand { if (entities.get(i) instanceof Player) { Player eplayer = (Player) entities.get(i); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); - if (efplayer.getRelationTo(fme) == Relation.ENEMY) { + if (efplayer.getRelationTo(fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); return; } @@ -214,6 +214,7 @@ public class CmdFly extends FCommand { } + if (args.size() == 0) { toggleFlight(!fme.isFlying(), me); } else if (args.size() == 1) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java new file mode 100644 index 00000000..1c6fc8a7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java @@ -0,0 +1,43 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.ChatColor; + +public class CmdStealth extends FCommand { + public CmdStealth() { + this.aliases.add("ninja"); + this.aliases.add("stealth"); + this.permission = Permission.STEALTH.node; + + this.disableOnLock = true; + + this.senderMustBePlayer = true; + this.senderMustBeMember = false; + this.senderMustBeModerator = false; + this.senderMustBeColeader = false; + this.senderMustBeAdmin = false; + } + + public void perform() { + //Grabs Faction + Faction faction = fme.getFaction(); + + if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) { + //Grabs Boolean From FPlayer + fme.setStealth(!fme.isStealthEnabled()); + //Sends Enable/Disable Message + fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE); + + } else { + //Send "Needed Faction" Message + fme.sendMessage(ChatColor.RED + "You must be in a faction to use this command"); + } + } + @Override + public TL getUsageTranslation() { + return TL.COMMAND_STEALTH_DESCRIPTION; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 8d03ed70..bfc21e70 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -51,6 +51,7 @@ public class FCmdRoot extends FCommand { public CmdSethome cmdSethome = new CmdSethome(); public CmdShow cmdShow = new CmdShow(); public CmdStatus cmdStatus = new CmdStatus(); + public CmdStealth cmdStealth = new CmdStealth(); public CmdStuck cmdStuck = new CmdStuck(); public CmdTag cmdTag = new CmdTag(); public CmdTitle cmdTitle = new CmdTitle(); @@ -166,6 +167,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdSethome); this.addSubCommand(this.cmdShow); this.addSubCommand(this.cmdStatus); + this.addSubCommand(this.cmdStealth); this.addSubCommand(this.cmdStuck); this.addSubCommand(this.cmdTag); this.addSubCommand(this.cmdTitle); diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index a9343244..c26a8d6e 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -76,6 +76,7 @@ public enum Permission { SETHOME_ANY("sethome.any"), SHOW("show"), STATUS("status"), + STEALTH("stealth"), STUCK("stuck"), TAG("tag"), TNT("tnt"), diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index a8bdbee0..d19788c6 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -79,11 +79,19 @@ public abstract class MemoryFPlayer implements FPlayer { protected transient boolean loginPvpDisabled; protected transient long lastFrostwalkerMessage; protected transient boolean shouldTakeFallDamage = true; + protected boolean isStealthEnabled = false; boolean playerAlerts = false; boolean inspectMode = false; public MemoryFPlayer() { } + public boolean isStealthEnabled() { + return this.isStealthEnabled; + } + + public void setStealth(boolean stealth) { + this.isStealthEnabled = stealth; + } public MemoryFPlayer(String id) { this.id = id; @@ -1028,24 +1036,17 @@ public abstract class MemoryFPlayer implements FPlayer { } @Override - public boolean checkIfNearbyEnemies() { + public boolean checkIfNearbyEnemies(){ Player me = this.getPlayer(); - int radius = Conf.enemyFlyCheckRadius; + int radius = Conf.stealthFlyCheckRadius; for (Entity e : me.getNearbyEntities(radius, 255, radius)) { - if (e == null) { - continue; - } + if (e == null) { continue; } if (e instanceof Player) { Player eplayer = (((Player) e).getPlayer()); - if (eplayer == null) { - continue; - } + if (eplayer == null) { continue; } FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); - if (efplayer == null) { - continue; - } - if (this.getRelationTo(efplayer).equals(Relation.ENEMY)) { - + if (efplayer == null) { continue; } + if (Conf.allowedStealthFactions != null && !efplayer.isStealthEnabled()) { this.setFlying(false); this.msg(TL.COMMAND_FLY_ENEMY_NEAR); Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this)); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 6a4483d3..23fbab06 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -632,6 +632,10 @@ public enum TL { COMMAND_STATUS_AGOSUFFIX(" ago."), COMMAND_STATUS_DESCRIPTION("Show the status of a player"), + COMMAND_STEALTH_DESCRIPTION("Enable and Disable Stealth Mode"), + COMMAND_STEALTH_ENABLE( "&2Stealth &8» &7You will no longer disable nearby players fly."), + COMMAND_STEALTH_DISABLE("&2Stealth &8» &7You will now disable other nearby players fly."), + COMMAND_STUCK_TIMEFORMAT("m 'minutes', s 'seconds.'"), COMMAND_STUCK_CANCELLED("Teleport cancelled because you were damaged"), COMMAND_STUCK_OUTSIDE("Teleport cancelled because you left %1$d block radius"), diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fe7f6ff3..e5519188 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -318,5 +318,7 @@ permissions: description: create banner factions.killholos: description: kill invisible holograms + factions.stealth: + description: Enter faction stealth mode factions.coords: description: broadcast your coords to the player