From 388f83694d340d5a4f29b75e056de3d81b506f58 Mon Sep 17 00:00:00 2001 From: Driftay Date: Mon, 6 Apr 2020 15:10:37 -0400 Subject: [PATCH] Per Player Friend Fire Added (Command Usage: /f friendlyfire) --- .../java/com/massivecraft/factions/Conf.java | 2 + .../com/massivecraft/factions/FPlayer.java | 6 +++ .../massivecraft/factions/cmd/Aliases.java | 2 + .../factions/cmd/CmdFriendlyFire.java | 44 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../listeners/FactionsEntityListener.java | 17 ++++++- .../factions/struct/Permission.java | 1 + .../factions/zcore/persist/MemoryFPlayer.java | 10 +++++ .../massivecraft/factions/zcore/util/TL.java | 5 +++ src/main/resources/plugin.yml | 2 + 10 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFriendlyFire.java diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 724c750e..da0bb7e5 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -99,6 +99,8 @@ public class Conf { public static boolean worldGuardChecking = false; public static boolean worldGuardBuildPriority = false; + //FRIENDLY FIRE + public static boolean friendlyFireFPlayersCommand = false; //Claim Fill public static int maxFillClaimCount = 25; diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index e20a7b55..2076b522 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -288,6 +288,11 @@ public interface FPlayer extends EconomyParticipator { boolean hasMoney(int amt); + //Fplayer specific friendly fire. + boolean hasFriendlyFire(); + + void setFriendlyFire(boolean status); + //inspect Stuff boolean isInspectMode(); @@ -387,6 +392,7 @@ public interface FPlayer extends EconomyParticipator { // Actions // ------------------------------- + void leave(boolean makePay); boolean canClaimForFaction(Faction forFaction); diff --git a/src/main/java/com/massivecraft/factions/cmd/Aliases.java b/src/main/java/com/massivecraft/factions/cmd/Aliases.java index 7755d8ca..6f3a45e1 100644 --- a/src/main/java/com/massivecraft/factions/cmd/Aliases.java +++ b/src/main/java/com/massivecraft/factions/cmd/Aliases.java @@ -10,6 +10,8 @@ public class Aliases { /** * @author DroppingAnvil */ + + public static ArrayList friendlyFire = new ArrayList<>(Arrays.asList("friendlyfire", "ff")); public static ArrayList notifications = new ArrayList<>(Arrays.asList("notifications", "notis")); public static ArrayList alts_alts = new ArrayList<>(Arrays.asList("alts", "alt")); public static ArrayList alts_list = new ArrayList<>(Arrays.asList("list", "l")); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFriendlyFire.java b/src/main/java/com/massivecraft/factions/cmd/CmdFriendlyFire.java new file mode 100644 index 00000000..1e35c32c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFriendlyFire.java @@ -0,0 +1,44 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +/** + * Factions - Developed by Driftay. + * All rights reserved 2020. + * Creation Date: 4/6/2020 + */ +public class CmdFriendlyFire extends FCommand { + + public CmdFriendlyFire(){ + super(); + this.aliases.addAll(Aliases.friendlyFire); + + this.requirements = new CommandRequirements.Builder(Permission.FRIENDLYFIRE) + .playerOnly() + .memberOnly() + .build(); + } + + @Override + public void perform(CommandContext context) { + if(!Conf.friendlyFireFPlayersCommand){ + context.msg(TL.GENERIC_DISABLED, "friendly fire"); + return; + } + + if(context.fPlayer.hasFriendlyFire()){ + context.fPlayer.setFriendlyFire(false); + context.msg(TL.COMMAND_FRIENDLY_FIRE_TOGGLE_OFF); + } else { + context.fPlayer.setFriendlyFire(true); + context.msg(TL.COMMAND_FRIENDLY_FIRE_TOGGLE_ON); + } + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_FRIENDLY_FIRE_DESCRIPTION; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 5b3ef3b1..a6d6b218 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -171,6 +171,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor { public CmdDelHome cmdDelHome = new CmdDelHome(); public CmdClaimFill cmdClaimFill = new CmdClaimFill(); public CmdNotifications cmdNotifications = new CmdNotifications(); + public CmdFriendlyFire cmdFriendlyFire = new CmdFriendlyFire(); //Variables to know if we already setup certain sub commands public Boolean discordEnabled = false; @@ -306,6 +307,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor { this.addSubCommand(this.cmdDrain); this.addSubCommand(this.cmdLookup); this.addSubCommand(this.cmdNotifications); + this.addSubCommand(this.cmdFriendlyFire); addVariableCommands(); if (CommodoreProvider.isSupported()) brigadierManager.build(); } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index 6730ce50..e2502155 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -342,12 +342,26 @@ public class FactionsEntityListener implements Listener { if (!(damagee instanceof Player)) return true; FPlayer defender = FPlayers.getInstance().getByPlayer((Player) damagee); + FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager); if (defender == null || defender.getPlayer() == null) return true; + if (attacker.getFaction() == defender.getFaction()) { + if (attacker.hasFriendlyFire() && defender.hasFriendlyFire()) return true; + if (attacker.hasFriendlyFire() && !defender.hasFriendlyFire()) { + attacker.msg(TL.FRIENDLY_FIRE_OFF_ATTACKER, defender.getName()); + return false; + } else if(!attacker.hasFriendlyFire() && defender.hasFriendlyFire()){ + attacker.msg(TL.FRIENDLY_FIRE_YOU_MUST); + return false; + } + } + + Location defenderLoc = defender.getPlayer().getLocation(); Faction defLocFaction = Board.getInstance().getFactionAt(new FLocation(defenderLoc)); + // for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source if (damager instanceof Projectile) { Projectile projectile = (Projectile) damager; @@ -361,7 +375,6 @@ public class FactionsEntityListener implements Listener { if (defLocFaction.noPvPInTerritory()) { if (damager instanceof Player) { if (notify) { - FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager); attacker.msg(TL.PLAYER_CANTHURT, (defLocFaction.isSafeZone() ? TL.REGION_SAFEZONE.toString() : TL.REGION_PEACEFUL.toString())); } return false; @@ -371,7 +384,7 @@ public class FactionsEntityListener implements Listener { if (!(damager instanceof Player)) return true; - FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager); + attacker = FPlayers.getInstance().getByPlayer((Player) damager); if (attacker == null || attacker.getPlayer() == null) return true; diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index dee0eb3a..0632d4f0 100755 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -54,6 +54,7 @@ public enum Permission { FLY_TRUCE("fly.truce"), FLY_NEUTRAL("fly.neutral"), FOCUS("focus"), + FRIENDLYFIRE("friendlyfire"), GLOBALCHAT("globalchat"), GRACE("grace"), HELP("help"), 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 55a700ed..e678d3d9 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -90,6 +90,7 @@ public abstract class MemoryFPlayer implements FPlayer { protected boolean titlesEnabled = true; protected boolean isAlt = false; boolean inspectMode = false; + boolean friendlyFire = false; public MemoryFPlayer() { } @@ -1202,6 +1203,15 @@ public abstract class MemoryFPlayer implements FPlayer { } + + public boolean hasFriendlyFire(){ + return friendlyFire; + } + + public void setFriendlyFire(boolean status){ + friendlyFire = status; + } + @Override public boolean isInspectMode() { return inspectMode; 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 0943a440..54198ab5 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -416,6 +416,11 @@ public enum TL { COMMAND_FOCUS_NO_LONGER("&c&l[!] &7Your faction is no longer focusing &c%s"), COMMAND_FOCUS_DESCRIPTION("Focus a Specific Player"), + COMMAND_FRIENDLY_FIRE_DESCRIPTION("Toggle friendly fire for yourself."), + COMMAND_FRIENDLY_FIRE_TOGGLE_OFF("&c[!] &7You have toggled friendly fire &4off&7!"), + COMMAND_FRIENDLY_FIRE_TOGGLE_ON("&c[!] &7You have toggled friendly fire &aon&7!"), + FRIENDLY_FIRE_OFF_ATTACKER("&b%1$s &7has friendly fire toggle &4off&7!"), + FRIENDLY_FIRE_YOU_MUST("&c[!] &7You must have friendly fire active to attack faction members!"), COMMAND_FWARP_CLICKTOWARP("&c&l[!]&7 Click to &cwarp!"), COMMAND_FWARP_COMMANDFORMAT("&c&l[!]&7 /f warp &c[password]"), diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1cc7d033..35fbb713 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -158,6 +158,8 @@ permissions: description: auto-claim land as you walk around factions.bypass: description: enable admin bypass mode + factions.friendlyfire: + description: ability to toggle on friend fire per player factions.lookup: description: Lookup claim & home stats for faction factions.chat: