Added F Drain Command (A Command which allows players with permission to obtain all the money in faction members balances.)

This commit is contained in:
Driftay 2019-12-22 18:21:17 -05:00
parent 3a22bb348e
commit 4e11234a08
13 changed files with 95 additions and 6 deletions

View File

@ -99,6 +99,8 @@ public class Conf {
public static boolean autoLeaveDeleteFPlayerData = true; // Let them just remove player from Faction. public static boolean autoLeaveDeleteFPlayerData = true; // Let them just remove player from Faction.
public static boolean worldGuardChecking = false; public static boolean worldGuardChecking = false;
public static boolean worldGuardBuildPriority = false; public static boolean worldGuardBuildPriority = false;
public static boolean factionsDrainEnabled = false;
//DISCORD //DISCORD
public static boolean useDiscordSystem = false; public static boolean useDiscordSystem = false;
public static String discordBotToken = "<token here>"; public static String discordBotToken = "<token here>";

View File

@ -0,0 +1,64 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import java.text.DecimalFormat;
/**
* @author Saser
*/
public class CmdDrain extends FCommand{
public CmdDrain(){
this.aliases.add("drain");
this.requirements = new CommandRequirements.Builder(Permission.DRAIN)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.DRAIN)
.build();
}
@Override
public void perform(CommandContext context) {
if (!Conf.factionsDrainEnabled) {
context.fPlayer.msg(TL.GENERIC_DISABLED, "Factions Drain");
return;
}
double totalBalance = 0;
for(FPlayer fPlayer : context.faction.getFPlayers()) {
if(context.faction.getFPlayers().size() == 1){
context.fPlayer.msg(TL.COMMAND_DRAIN_NO_PLAYERS);
return;
}
if (FPlayers.getInstance().getByPlayer(context.player).equals(fPlayer)){
continue; // skip the command executor
}
double balance = FactionsPlugin.getInstance().getEcon().getBalance(fPlayer.getPlayer());
if (balance > 0) {
FactionsPlugin.getInstance().getEcon().depositPlayer(context.player, balance);
FactionsPlugin.getInstance().getEcon().withdrawPlayer(fPlayer.getPlayer(), balance);
totalBalance = (totalBalance + balance);
}
}
context.fPlayer.msg(TL.COMMAND_DRAIN_RECIEVED_AMOUNT, commas(totalBalance));
}
public String commas(final double amount) {
final DecimalFormat formatter = new DecimalFormat("#,###.00");
return formatter.format(amount);
}
@Override
public TL getUsageTranslation() {
return null;
}
}

View File

@ -16,11 +16,11 @@ public class CmdSethome extends FCommand {
this.optionalArgs.put("faction tag", "mine"); this.optionalArgs.put("faction tag", "mine");
this.requirements = new CommandRequirements.Builder(Permission.SETHOME) this.requirements = new CommandRequirements.Builder(Permission.SETHOME)
.playerOnly() .playerOnly()
.memberOnly() .memberOnly()
.withAction(PermissableAction.SETHOME) .withAction(PermissableAction.SETHOME)
.build(); .build();
} }
@Override @Override
public void perform(CommandContext context) { public void perform(CommandContext context) {

View File

@ -162,6 +162,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdSetGuild cmdSetGuild = new CmdSetGuild(); public CmdSetGuild cmdSetGuild = new CmdSetGuild();
public CmdDiscord cmdDiscord = new CmdDiscord(); public CmdDiscord cmdDiscord = new CmdDiscord();
public CmdDebug cmdDebug = new CmdDebug(); public CmdDebug cmdDebug = new CmdDebug();
public CmdDrain cmdDrain = new CmdDrain();
//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;
public Boolean checkEnabled = false; public Boolean checkEnabled = false;
@ -291,6 +292,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdViewChest); this.addSubCommand(this.cmdViewChest);
this.addSubCommand(this.cmdConvertConfig); this.addSubCommand(this.cmdConvertConfig);
this.addSubCommand(this.cmdSpawnerLock); this.addSubCommand(this.cmdSpawnerLock);
this.addSubCommand(this.cmdDrain);
addVariableCommands(); addVariableCommands();
if (CommodoreProvider.isSupported()) brigadierManager.build(); if (CommodoreProvider.isSupported()) brigadierManager.build();
} }

View File

@ -39,7 +39,7 @@ public class CmdWild extends FCommand {
} }
@Override @Override
public void perform(CommandContext context) { public void perform(CommandContext context) {
if (!waitingTeleport.keySet().contains(context.player)) { if (!waitingTeleport.containsKey(context.player)) {
context.player.openInventory(new WildGUI(context.player, context.fPlayer).getInventory()); context.player.openInventory(new WildGUI(context.player, context.fPlayer).getInventory());
} else {context.fPlayer.msg(TL.COMMAND_WILD_WAIT);} } else {context.fPlayer.msg(TL.COMMAND_WILD_WAIT);}
} }

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd.wild;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.util.FactionGUI; import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;

View File

@ -1052,16 +1052,21 @@ public class FactionsPlayerListener implements Listener {
if (!Discord.useDiscord) { if (!Discord.useDiscord) {
return; return;
} }
String[] msg = e.getChatMessage().split(" "); String[] msg = e.getChatMessage().split(" ");
if (msg.length == 0 | !msg[msg.length - 1].contains("@")) { if (msg.length == 0 | !msg[msg.length - 1].contains("@")) {
return; return;
} }
FPlayer fp = FPlayers.getInstance().getByPlayer(e.getPlayer()); FPlayer fp = FPlayers.getInstance().getByPlayer(e.getPlayer());
if (fp == null | fp.getChatMode() != ChatMode.FACTION) {
if(fp == null) return;
if (fp.getChatMode() != ChatMode.FACTION) {
return; return;
} }
Faction f = fp.getFaction(); Faction f = fp.getFaction();
if (f == null | f.isSystemFaction()) { if(f == null) return;
if (f.isSystemFaction()) {
return; return;
} }
if (f.getGuildId() == null | f.getFactionChatChannelId() == null) { if (f.getGuildId() == null | f.getFactionChatChannelId() == null) {

View File

@ -42,6 +42,7 @@ public enum Permission {
DISBAND("disband"), DISBAND("disband"),
DISBAND_ANY("disband.any"), DISBAND_ANY("disband.any"),
DISCORD("discord"), DISCORD("discord"),
DRAIN("drain"),
FLY("fly"), FLY("fly"),
FLY_WILD("fly.wilderness"), FLY_WILD("fly.wilderness"),
FLY_SAFEZONE("fly.safezone"), FLY_SAFEZONE("fly.safezone"),

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions.zcore.fperms; package com.massivecraft.factions.zcore.fperms;
import com.massivecraft.factions.util.XMaterial;
public class DefaultPermissions { public class DefaultPermissions {
/** /**
@ -33,6 +35,7 @@ public class DefaultPermissions {
public boolean withdraw; public boolean withdraw;
public boolean chest; public boolean chest;
public boolean check; public boolean check;
public boolean drain;
public boolean spawner; public boolean spawner;
public DefaultPermissions() { public DefaultPermissions() {
@ -66,6 +69,7 @@ public class DefaultPermissions {
this.withdraw = def; this.withdraw = def;
this.chest = def; this.chest = def;
this.check = def; this.check = def;
this.drain = def;
this.spawner = def; this.spawner = def;
} }
@ -96,6 +100,7 @@ public class DefaultPermissions {
boolean canWithdraw, boolean canWithdraw,
boolean canChest, boolean canChest,
boolean canCheck, boolean canCheck,
boolean canDrain,
boolean canSpawners) { boolean canSpawners) {
this.ban = canBan; this.ban = canBan;
this.build = canBuild; this.build = canBuild;
@ -124,6 +129,7 @@ public class DefaultPermissions {
this.withdraw = canWithdraw; this.withdraw = canWithdraw;
this.chest = canChest; this.chest = canChest;
this.check = canCheck; this.check = canCheck;
this.drain = canDrain;
this.spawner = canSpawners; this.spawner = canSpawners;
} }
@ -156,6 +162,7 @@ public class DefaultPermissions {
else if (name == "withdraw") return this.withdraw; else if (name == "withdraw") return this.withdraw;
else if (name == "chest") return this.chest; else if (name == "chest") return this.chest;
else if (name == "check") return this.check; else if (name == "check") return this.check;
else if (name == "drain") return this.drain;
else if (name == "spawner") return this.spawner; else if (name == "spawner") return this.spawner;
else return false; else return false;
} }

View File

@ -21,6 +21,7 @@ public enum PermissableAction {
BAN("ban"), BAN("ban"),
BUILD("build"), BUILD("build"),
DESTROY("destroy"), DESTROY("destroy"),
DRAIN("drain"),
FROST_WALK("frostwalk"), FROST_WALK("frostwalk"),
PAIN_BUILD("painbuild"), PAIN_BUILD("painbuild"),
DOOR("door"), DOOR("door"),

View File

@ -959,6 +959,11 @@ public enum TL {
COMMAND_WARUNCLAIMALL_SUCCESS("You unclaimed ALL war zone land."), COMMAND_WARUNCLAIMALL_SUCCESS("You unclaimed ALL war zone land."),
COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."), COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."),
COMMAND_DRAIN_NO_PLAYERS("&c&l[!] &cYou cannot drain a faction with no other members!"),
COMMAND_DRAIN_RECIEVED_AMOUNT("&c&l[!] &fYou have drained all of your faction members for &b%1$s."),
COMMAND_DRAIN_INVALID_AMOUNT("&c&l[!] &fYou cannot drain a faction with no worth."),
COMMAND_WILD_DESCRIPTION("Teleport to a random location"), COMMAND_WILD_DESCRIPTION("Teleport to a random location"),
COMMAND_WILD_WAIT("&c&l[!] &7Teleporting in %1$s"), COMMAND_WILD_WAIT("&c&l[!] &7Teleporting in %1$s"),
COMMAND_WILD_SUCCESS("&c&l[!] &7Teleporting..."), COMMAND_WILD_SUCCESS("&c&l[!] &7Teleporting..."),

View File

@ -490,6 +490,7 @@ fperm-gui:
tntfill: TNT tntfill: TNT
chest: ENDER_CHEST chest: ENDER_CHEST
check: WATCH check: WATCH
drain: BUCKET
spawner: MOB_SPAWNER spawner: MOB_SPAWNER
home: ENDER_EYE home: ENDER_EYE
slots: slots:
@ -525,6 +526,7 @@ fperm-gui:
chest: 42 chest: 42
check: 50 check: 50
spawner: 38 spawner: 38
drain: 49
home: 48 home: 48
# {action} Action name eg: Setwarp, Kick # {action} Action name eg: Setwarp, Kick
# {action-access} Access name eg: Allow, Deny # {action-access} Access name eg: Allow, Deny

View File

@ -65,6 +65,7 @@ permissions:
factions.kit.halfplayer: factions.kit.halfplayer:
description: Can do all but create factions. description: Can do all but create factions.
children: children:
factions.drain: true
factions.wild: true factions.wild: true
factions.missions: true factions.missions: true
factions.tntfill: true factions.tntfill: true