Cooldown and F Spam System Implemented
This commit is contained in:
@@ -365,6 +365,12 @@ public interface FPlayer extends EconomyParticipator {
|
||||
|
||||
boolean checkIfNearbyEnemies();
|
||||
|
||||
public int getCooldown(String cmd);
|
||||
|
||||
public void setCooldown(String cmd, long cooldown);
|
||||
|
||||
public boolean isCooldownEnded(String cmd);
|
||||
|
||||
|
||||
// -------------------------------
|
||||
// Warmups
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.fupgrades.*;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import me.driftay.addons.bankxp.Deposit;
|
||||
import me.driftay.addons.bankxp.Withdraw;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.*;
|
||||
@@ -79,6 +77,7 @@ public class SavageFactions extends MPlugin {
|
||||
DIODE_BLOCK_ON, ENCHANTMENT_TABLE, FIREBALL;
|
||||
SkriptAddon skriptAddon;
|
||||
private boolean locked = false;
|
||||
private boolean spam = false;
|
||||
private Integer AutoLeaveTask = null;
|
||||
private boolean hookedPlayervaults;
|
||||
private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
|
||||
@@ -99,6 +98,15 @@ public class SavageFactions extends MPlugin {
|
||||
this.setAutoSave(val);
|
||||
}
|
||||
|
||||
public boolean getSpam() {
|
||||
return this.spam;
|
||||
}
|
||||
|
||||
public void setSpam(boolean val) {
|
||||
this.spam = val;
|
||||
this.setAutoSave(val);
|
||||
}
|
||||
|
||||
public void playSoundForAll(String sound) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
playSound(pl, sound);
|
||||
@@ -252,11 +260,6 @@ public class SavageFactions extends MPlugin {
|
||||
getCommand(this.refCommand).setExecutor(this);
|
||||
getCommand(this.refCommand).setTabCompleter(this);
|
||||
|
||||
if(getConfig().getBoolean("XP-BankNote-Enabled")) {
|
||||
getCommand("withdraw").setExecutor(new Withdraw());
|
||||
getCommand("bottle").setExecutor(new Withdraw());
|
||||
getServer().getPluginManager().registerEvents(new Deposit(), this);
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> rsp = SavageFactions.this.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
SavageFactions.econ = rsp.getProvider();
|
||||
|
||||
@@ -16,6 +16,7 @@ public class CmdAHome extends FCommand {
|
||||
|
||||
this.permission = Permission.AHOME.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class CmdAdmin extends FCommand {
|
||||
|
||||
this.permission = Permission.ADMIN.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = true;
|
||||
|
||||
|
||||
senderMustBePlayer = false;
|
||||
|
||||
@@ -20,6 +20,7 @@ public class CmdAlts extends FCommand {
|
||||
|
||||
this.permission = Permission.ALTS.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
|
||||
@@ -16,6 +16,8 @@ public class CmdAltsList extends FCommand{
|
||||
this.aliases.add("list");
|
||||
|
||||
this.permission = Permission.LIST.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
|
||||
@@ -19,6 +19,7 @@ public class CmdAnnounce extends FCommand {
|
||||
|
||||
this.permission = Permission.ANNOUNCE.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
|
||||
@@ -16,6 +16,7 @@ public class CmdAutoClaim extends FCommand {
|
||||
|
||||
this.permission = Permission.AUTOCLAIM.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class CmdBan extends FCommand {
|
||||
|
||||
this.permission = Permission.BAN.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class CmdBanlist extends FCommand {
|
||||
|
||||
this.permission = Permission.BAN.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
|
||||
@@ -24,6 +24,7 @@ public class CmdCreate extends FCommand {
|
||||
|
||||
this.permission = Permission.CREATE.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
@@ -41,6 +42,11 @@ public class CmdCreate extends FCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.isCooldownEnded("create")) {
|
||||
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Factions.getInstance().isTagTaken(tag)) {
|
||||
msg(TL.COMMAND_CREATE_INUSE);
|
||||
return;
|
||||
@@ -108,6 +114,9 @@ public class CmdCreate extends FCommand {
|
||||
if (SavageFactions.plugin.getConfig().getBoolean("fpaypal.Enabled")) {
|
||||
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
|
||||
}
|
||||
|
||||
fme.setCooldown("create", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-create") * 1000));
|
||||
|
||||
if (Conf.useCustomDefaultPermissions) {
|
||||
faction.setDefaultPerms();
|
||||
if (Conf.usePermissionHints)
|
||||
|
||||
@@ -28,7 +28,7 @@ public class CmdDisband extends FCommand {
|
||||
|
||||
this.permission = Permission.DISBAND.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
this.disableOnSpam = true;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
@@ -46,6 +46,12 @@ public class CmdDisband extends FCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!fme.isCooldownEnded("disband")) {
|
||||
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("disband"));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isMyFaction = fme != null && faction == myFaction;
|
||||
|
||||
if (isMyFaction) {
|
||||
@@ -89,6 +95,7 @@ public class CmdDisband extends FCommand {
|
||||
UtilFly.checkFly(this.fme, Board.getInstance().getFactionAt(new FLocation(follower)));
|
||||
if (follower.getFaction() == faction) {
|
||||
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
|
||||
fme.setCooldown("disband", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-disband") * 1000));
|
||||
} else {
|
||||
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.SavageFactions;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
@@ -17,6 +18,7 @@ public class CmdOpen extends FCommand {
|
||||
|
||||
this.permission = Permission.OPEN.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = true;
|
||||
|
||||
|
||||
senderMustBePlayer = true;
|
||||
@@ -33,6 +35,11 @@ public class CmdOpen extends FCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.isCooldownEnded("open")) {
|
||||
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("open"));
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen()));
|
||||
|
||||
String open = myFaction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
|
||||
@@ -45,6 +52,7 @@ public class CmdOpen extends FCommand {
|
||||
}
|
||||
fplayer.msg(TL.COMMAND_OPEN_CHANGED, myFaction.getTag(fplayer.getFaction()), open);
|
||||
}
|
||||
fme.setCooldown("open", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-open") * 1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ public class CmdShow extends FCommand {
|
||||
public CmdShow() {
|
||||
this.aliases.add("show");
|
||||
this.aliases.add("who");
|
||||
this.aliases.add("f");
|
||||
|
||||
// add defaults to /f show in case config doesnt have it
|
||||
defaults.add("{header}");
|
||||
|
||||
34
src/main/java/com/massivecraft/factions/cmd/CmdSpam.java
Normal file
34
src/main/java/com/massivecraft/factions/cmd/CmdSpam.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdSpam extends FCommand {
|
||||
|
||||
public CmdSpam(){
|
||||
this.aliases.add("spam");
|
||||
|
||||
this.optionalArgs.put("on/off", "flip");
|
||||
|
||||
this.permission = Permission.SPAM.node;
|
||||
this.disableOnLock = false;
|
||||
this.disableOnSpam = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
p.setSpam(this.argAsBool(0, !p.getSpam()));
|
||||
msg(p.getSpam() ? TL.COMMAND_SPAM_ENABLED : TL.COMMAND_SPAM_DISABLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return TL.COMMAND_SPAM_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public class CmdTag extends FCommand {
|
||||
|
||||
this.permission = Permission.TAG.node;
|
||||
this.disableOnLock = true;
|
||||
this.disableOnSpam = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
@@ -33,6 +34,13 @@ public class CmdTag extends FCommand {
|
||||
public void perform() {
|
||||
String tag = this.argAsString(0);
|
||||
|
||||
|
||||
if (!fme.isCooldownEnded("tag")) {
|
||||
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("tag"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// TODO does not first test cover selfcase?
|
||||
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
|
||||
msg(TL.COMMAND_TAG_TAKEN);
|
||||
@@ -78,7 +86,7 @@ public class CmdTag extends FCommand {
|
||||
fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
|
||||
}
|
||||
}
|
||||
|
||||
fme.setCooldown("tag", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-tag") * 1000));
|
||||
FTeamWrapper.updatePrefixes(myFaction);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdStrike cmdStrike = new CmdStrike();
|
||||
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
|
||||
public CmdAlts cmdAlts = new CmdAlts();
|
||||
public CmdSpam cmdSpam = new CmdSpam();
|
||||
|
||||
|
||||
|
||||
@@ -222,6 +223,7 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdChest);
|
||||
this.addSubCommand(this.cmdSetBanner);
|
||||
this.addSubCommand(this.cmdStrikeSet);
|
||||
this.addSubCommand(this.cmdSpam);
|
||||
|
||||
|
||||
if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){
|
||||
|
||||
@@ -18,6 +18,7 @@ public abstract class FCommand extends MCommand<SavageFactions> {
|
||||
public static final SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
|
||||
|
||||
public boolean disableOnLock;
|
||||
public boolean disableOnSpam;
|
||||
|
||||
public FPlayer fme;
|
||||
public Faction myFaction;
|
||||
@@ -34,6 +35,7 @@ public abstract class FCommand extends MCommand<SavageFactions> {
|
||||
|
||||
// Due to safety reasons it defaults to disable on lock.
|
||||
disableOnLock = true;
|
||||
disableOnSpam = false;
|
||||
|
||||
// The money commands must be disabled if money should not be used.
|
||||
isMoneyCommand = false;
|
||||
@@ -69,6 +71,11 @@ public abstract class FCommand extends MCommand<SavageFactions> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(p.getSpam() && this.disableOnSpam){
|
||||
msg("<b>Anti-Spam is currently enabled! Please try again later.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isMoneyCommand && !Conf.econEnabled) {
|
||||
msg("<b>Faction economy features are disabled on this server.");
|
||||
return false;
|
||||
|
||||
@@ -78,6 +78,7 @@ public enum Permission {
|
||||
RELATION("relation"),
|
||||
RELOAD("reload"),
|
||||
SAVE("save"),
|
||||
SPAM("spam"),
|
||||
SETHOME("sethome"),
|
||||
SETHOME_ANY("sethome.any"),
|
||||
SETSTRIKES("setstrikes"),
|
||||
|
||||
@@ -28,10 +28,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -44,7 +41,7 @@ import java.util.UUID;
|
||||
*/
|
||||
|
||||
public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
protected HashMap<String, Long> commandCooldown = new HashMap<>();
|
||||
public boolean inVault = false;
|
||||
protected String factionId;
|
||||
protected Role role;
|
||||
@@ -158,6 +155,33 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
this.deaths = getPlayer().getStatistic(Statistic.DEATHS);
|
||||
}
|
||||
|
||||
public int getCooldown(String cmd) {
|
||||
int seconds = 0;
|
||||
if (this.getPlayer().isOp())
|
||||
return 0;
|
||||
if (commandCooldown.containsKey(cmd))
|
||||
seconds = (int) ((this.commandCooldown.get(cmd) - System.currentTimeMillis()) / 1000);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public void setCooldown(String cmd, long cooldown) {
|
||||
if (this.getPlayer().isOp())
|
||||
return;
|
||||
|
||||
this.commandCooldown.put(cmd, cooldown);
|
||||
}
|
||||
|
||||
public boolean isCooldownEnded(String cmd) {
|
||||
if (this.getPlayer().isOp())
|
||||
return true;
|
||||
if (!commandCooldown.containsKey(cmd))
|
||||
return true;
|
||||
else if (commandCooldown.containsKey(cmd) && commandCooldown.get(cmd) <= System.currentTimeMillis())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public Faction getFaction() {
|
||||
if (this.factionId == null) {
|
||||
this.factionId = "0";
|
||||
|
||||
@@ -410,6 +410,11 @@ public enum TL {
|
||||
COMMAND_LIST_ONLINEFACTIONLESS("Online factionless: "),
|
||||
COMMAND_LIST_DESCRIPTION("&a&l» &7See a list of the factions"),
|
||||
|
||||
|
||||
COMMAND_SPAM_ENABLED("&c&l[!]&7 Factions Anti-Spam is now&a enabled"),
|
||||
COMMAND_SPAM_DISABLED("&c&l[!]&7 Factions Anti-Spam in now&c disabled"),
|
||||
COMMAND_SPAM_DESCRIPTION("enable antispam system"),
|
||||
|
||||
COMMAND_LOCK_LOCKED("&c&l[!]&7 Factions is now&c locked"),
|
||||
COMMAND_LOCK_UNLOCKED("&c&l[!]&7 Factions in now&a unlocked"),
|
||||
COMMAND_LOCK_DESCRIPTION("Lock all write stuff. Apparently."),
|
||||
@@ -627,6 +632,7 @@ public enum TL {
|
||||
|
||||
COMMAND_SETMAXVAULTS_DESCRIPTION("Set max vaults for a Faction."),
|
||||
COMMAND_SETMAXVAULTS_SUCCESS("&aSet max vaults for &e%s &ato &b%d"),
|
||||
COMMAND_ONCOOOLDOWN("&c&l[!] &7You cannot use this command for another &b%1$s &7seconds."),
|
||||
|
||||
COMMAND_SETSTRIKES_FAILURE("&c&l[!]&7 &c{faction} does not exist."),
|
||||
COMMAND_SETSTRIKES_BROADCAST("&c&l[!]&7 &c{faction} has received a strike for {reason}"),
|
||||
|
||||
Reference in New Issue
Block a user