Per Player Friend Fire Added (Command Usage: /f friendlyfire)

This commit is contained in:
Driftay 2020-04-06 15:10:37 -04:00
parent 23320db201
commit 388f83694d
10 changed files with 89 additions and 2 deletions

View File

@ -99,6 +99,8 @@ public class Conf {
public static boolean worldGuardChecking = false; public static boolean worldGuardChecking = false;
public static boolean worldGuardBuildPriority = false; public static boolean worldGuardBuildPriority = false;
//FRIENDLY FIRE
public static boolean friendlyFireFPlayersCommand = false;
//Claim Fill //Claim Fill
public static int maxFillClaimCount = 25; public static int maxFillClaimCount = 25;

View File

@ -288,6 +288,11 @@ public interface FPlayer extends EconomyParticipator {
boolean hasMoney(int amt); boolean hasMoney(int amt);
//Fplayer specific friendly fire.
boolean hasFriendlyFire();
void setFriendlyFire(boolean status);
//inspect Stuff //inspect Stuff
boolean isInspectMode(); boolean isInspectMode();
@ -387,6 +392,7 @@ public interface FPlayer extends EconomyParticipator {
// Actions // Actions
// ------------------------------- // -------------------------------
void leave(boolean makePay); void leave(boolean makePay);
boolean canClaimForFaction(Faction forFaction); boolean canClaimForFaction(Faction forFaction);

View File

@ -10,6 +10,8 @@ public class Aliases {
/** /**
* @author DroppingAnvil * @author DroppingAnvil
*/ */
public static ArrayList<String> friendlyFire = new ArrayList<>(Arrays.asList("friendlyfire", "ff"));
public static ArrayList<String> notifications = new ArrayList<>(Arrays.asList("notifications", "notis")); public static ArrayList<String> notifications = new ArrayList<>(Arrays.asList("notifications", "notis"));
public static ArrayList<String> alts_alts = new ArrayList<>(Arrays.asList("alts", "alt")); public static ArrayList<String> alts_alts = new ArrayList<>(Arrays.asList("alts", "alt"));
public static ArrayList<String> alts_list = new ArrayList<>(Arrays.asList("list", "l")); public static ArrayList<String> alts_list = new ArrayList<>(Arrays.asList("list", "l"));

View File

@ -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;
}
}

View File

@ -171,6 +171,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdDelHome cmdDelHome = new CmdDelHome(); public CmdDelHome cmdDelHome = new CmdDelHome();
public CmdClaimFill cmdClaimFill = new CmdClaimFill(); public CmdClaimFill cmdClaimFill = new CmdClaimFill();
public CmdNotifications cmdNotifications = new CmdNotifications(); public CmdNotifications cmdNotifications = new CmdNotifications();
public CmdFriendlyFire cmdFriendlyFire = new CmdFriendlyFire();
//Variables to know if we already setup certain sub commands //Variables to know if we already setup certain sub commands
public Boolean discordEnabled = false; public Boolean discordEnabled = false;
@ -306,6 +307,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdDrain); this.addSubCommand(this.cmdDrain);
this.addSubCommand(this.cmdLookup); this.addSubCommand(this.cmdLookup);
this.addSubCommand(this.cmdNotifications); this.addSubCommand(this.cmdNotifications);
this.addSubCommand(this.cmdFriendlyFire);
addVariableCommands(); addVariableCommands();
if (CommodoreProvider.isSupported()) brigadierManager.build(); if (CommodoreProvider.isSupported()) brigadierManager.build();
} }

View File

@ -342,12 +342,26 @@ public class FactionsEntityListener implements Listener {
if (!(damagee instanceof Player)) return true; if (!(damagee instanceof Player)) return true;
FPlayer defender = FPlayers.getInstance().getByPlayer((Player) damagee); FPlayer defender = FPlayers.getInstance().getByPlayer((Player) damagee);
FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager);
if (defender == null || defender.getPlayer() == null) return true; 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(); Location defenderLoc = defender.getPlayer().getLocation();
Faction defLocFaction = Board.getInstance().getFactionAt(new FLocation(defenderLoc)); 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 // for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source
if (damager instanceof Projectile) { if (damager instanceof Projectile) {
Projectile projectile = (Projectile) damager; Projectile projectile = (Projectile) damager;
@ -361,7 +375,6 @@ public class FactionsEntityListener implements Listener {
if (defLocFaction.noPvPInTerritory()) { if (defLocFaction.noPvPInTerritory()) {
if (damager instanceof Player) { if (damager instanceof Player) {
if (notify) { if (notify) {
FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager);
attacker.msg(TL.PLAYER_CANTHURT, (defLocFaction.isSafeZone() ? TL.REGION_SAFEZONE.toString() : TL.REGION_PEACEFUL.toString())); attacker.msg(TL.PLAYER_CANTHURT, (defLocFaction.isSafeZone() ? TL.REGION_SAFEZONE.toString() : TL.REGION_PEACEFUL.toString()));
} }
return false; return false;
@ -371,7 +384,7 @@ public class FactionsEntityListener implements Listener {
if (!(damager instanceof Player)) return true; 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; if (attacker == null || attacker.getPlayer() == null) return true;

View File

@ -54,6 +54,7 @@ public enum Permission {
FLY_TRUCE("fly.truce"), FLY_TRUCE("fly.truce"),
FLY_NEUTRAL("fly.neutral"), FLY_NEUTRAL("fly.neutral"),
FOCUS("focus"), FOCUS("focus"),
FRIENDLYFIRE("friendlyfire"),
GLOBALCHAT("globalchat"), GLOBALCHAT("globalchat"),
GRACE("grace"), GRACE("grace"),
HELP("help"), HELP("help"),

View File

@ -90,6 +90,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected boolean titlesEnabled = true; protected boolean titlesEnabled = true;
protected boolean isAlt = false; protected boolean isAlt = false;
boolean inspectMode = false; boolean inspectMode = false;
boolean friendlyFire = false;
public MemoryFPlayer() { 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 @Override
public boolean isInspectMode() { public boolean isInspectMode() {
return inspectMode; return inspectMode;

View File

@ -416,6 +416,11 @@ public enum TL {
COMMAND_FOCUS_NO_LONGER("&c&l[!] &7Your faction is no longer focusing &c%s"), COMMAND_FOCUS_NO_LONGER("&c&l[!] &7Your faction is no longer focusing &c%s"),
COMMAND_FOCUS_DESCRIPTION("Focus a Specific Player"), 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_CLICKTOWARP("&c&l[!]&7 Click to &cwarp!"),
COMMAND_FWARP_COMMANDFORMAT("&c&l[!]&7 /f warp <warpname> &c[password]"), COMMAND_FWARP_COMMANDFORMAT("&c&l[!]&7 /f warp <warpname> &c[password]"),

View File

@ -158,6 +158,8 @@ permissions:
description: auto-claim land as you walk around description: auto-claim land as you walk around
factions.bypass: factions.bypass:
description: enable admin bypass mode description: enable admin bypass mode
factions.friendlyfire:
description: ability to toggle on friend fire per player
factions.lookup: factions.lookup:
description: Lookup claim & home stats for faction description: Lookup claim & home stats for faction
factions.chat: factions.chat: