Cooldowns initiated & Disable Open Broadcasts

This commit is contained in:
Driftay 2020-04-06 16:19:41 -04:00
parent cb2afb5a4f
commit 62e4114466
8 changed files with 64 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import com.massivecraft.factions.event.FactionCreateEvent;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.Cooldown;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
@ -70,6 +71,11 @@ public class CmdCreate extends FCommand {
return; return;
} }
if(Cooldown.isOnCooldown(context.fPlayer.getPlayer(), "createCooldwn")){
context.msg(TL.COMMAND_COOLDOWN);
return;
}
// trigger the faction creation event (cancellable) // trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag); FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent); Bukkit.getServer().getPluginManager().callEvent(createEvent);
@ -105,6 +111,7 @@ public class CmdCreate extends FCommand {
// That way we don't have to mess up deleting more stuff. // That way we don't have to mess up deleting more stuff.
// And prevent the user from being returned to NORMAL after deleting his old faction. // And prevent the user from being returned to NORMAL after deleting his old faction.
context.fPlayer.setRole(Role.LEADER); context.fPlayer.setRole(Role.LEADER);
Cooldown.setCooldown(context.fPlayer.getPlayer(), "createCooldown", FactionsPlugin.getInstance().getConfig().getInt("fcooldowns.f-create"));
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-creation-broadcast", true)) { if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-creation-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
follower.msg(TL.COMMAND_CREATE_CREATED, context.fPlayer.getName(), faction.getTag(follower)); follower.msg(TL.COMMAND_CREATE_CREATED, context.fPlayer.getName(), faction.getTag(follower));

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason; import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.Cooldown;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.frame.fdisband.FDisbandFrame; import com.massivecraft.factions.zcore.frame.fdisband.FDisbandFrame;
@ -84,6 +85,10 @@ public class CmdDisband extends FCommand {
} }
} }
if(Cooldown.isOnCooldown(context.fPlayer.getPlayer(), "disbandCooldown")){
context.msg(TL.COMMAND_COOLDOWN);
return;
}
// check for tnt before disbanding. // check for tnt before disbanding.
if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) { if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) {
@ -106,12 +111,14 @@ public class CmdDisband extends FCommand {
if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) {
faction.disband(context.player, PlayerDisbandReason.COMMAND); faction.disband(context.player, PlayerDisbandReason.COMMAND);
context.fPlayer.setFFlying(false, false); context.fPlayer.setFFlying(false, false);
Cooldown.setCooldown(context.fPlayer.getPlayer(), "disbandCooldown", FactionsPlugin.getInstance().getConfig().getInt("fcooldowns.f-disband"));
return; return;
} }
} else { } else {
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER)); context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
} }
faction.disband(context.player, PlayerDisbandReason.COMMAND); faction.disband(context.player, PlayerDisbandReason.COMMAND);
Cooldown.setCooldown(context.fPlayer.getPlayer(), "disbandCooldown", FactionsPlugin.getInstance().getConfig().getInt("fcooldowns.f-disband"));
if (!context.fPlayer.canFlyAtLocation() && FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) { if (!context.fPlayer.canFlyAtLocation() && FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) {
context.fPlayer.setFFlying(false, false); context.fPlayer.setFFlying(false, false);
} }

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.Cooldown;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdOpen extends FCommand { public class CmdOpen extends FCommand {
@ -38,12 +39,19 @@ public class CmdOpen extends FCommand {
String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString(); String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
if(Cooldown.isOnCooldown(context.fPlayer.getPlayer(), "openCooldown")){
context.msg(TL.COMMAND_COOLDOWN);
return;
}
// Inform // Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(context.faction.getId())) { if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open); fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open);
Cooldown.setCooldown(fplayer.getPlayer(), "openCooldown", FactionsPlugin.getInstance().getConfig().getInt("fcooldowns.f-open"));
continue; continue;
} }
if(FactionsPlugin.getInstance().getConfig().getBoolean("faction-open-broadcast")) return;
fplayer.msg(TL.COMMAND_OPEN_CHANGED, context.faction.getTag(fplayer.getFaction()), open); fplayer.msg(TL.COMMAND_OPEN_CHANGED, context.faction.getTag(fplayer.getFaction()), open);
} }
}); });

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.event.FactionRenameEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.Cooldown;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -53,6 +54,11 @@ public class CmdTag extends FCommand {
return; return;
} }
if(Cooldown.isOnCooldown(context.player, "tagCooldown")){
context.msg(TL.COMMAND_COOLDOWN);
return;
}
// trigger the faction rename event (cancellable) // trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag); FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent); Bukkit.getServer().getPluginManager().callEvent(renameEvent);
@ -65,8 +71,11 @@ public class CmdTag extends FCommand {
return; return;
} }
String oldtag = context.faction.getTag(); String oldtag = context.faction.getTag();
context.faction.setTag(tag); context.faction.setTag(tag);
Discord.changeFactionTag(context.faction, oldtag); Discord.changeFactionTag(context.faction, oldtag);
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.FTAG_EDIT, context.fPlayer.getName(), tag); FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.FTAG_EDIT, context.fPlayer.getName(), tag);
@ -75,6 +84,7 @@ public class CmdTag extends FCommand {
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(context.faction.getId())) { if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction)); fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction));
Cooldown.setCooldown(fplayer.getPlayer(), "tagCooldown", FactionsPlugin.getInstance().getConfig().getInt("fcooldowns.f-tag"));
continue; continue;
} }
// Broadcast the tag change (if applicable) // Broadcast the tag change (if applicable)

View File

@ -425,8 +425,7 @@ public class FactionsBlockListener implements Listener {
if (!justCheck) fPlayer.setLastFrostwalkerMessage(); if (!justCheck) fPlayer.setLastFrostwalkerMessage();
// Check if they have build permissions here. If not, block this from happening. // Check if they have build permissions here. If not, block this from happening.
if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) event.setCancelled(true);
event.setCancelled(true);
} }
@EventHandler @EventHandler
@ -486,7 +485,6 @@ public class FactionsBlockListener implements Listener {
Faction at = Board.getInstance().getFactionAt(new FLocation(block)); Faction at = Board.getInstance().getFactionAt(new FLocation(block));
boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()); boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@ -0,0 +1,27 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import java.util.concurrent.TimeUnit;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/6/2020
*/
public class Cooldown {
public static void setCooldown(Player player, String name, int seconds) {
player.setMetadata(name, new FixedMetadataValue(FactionsPlugin.getInstance(), System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(seconds)));
}
public static boolean isOnCooldown(Player player, String name) {
if (!player.hasMetadata(name) || player.getMetadata(name).size() <= 0) return false;
long time = player.getMetadata(name).get(0).asLong();
return (time > System.currentTimeMillis());
}
}

View File

@ -611,6 +611,8 @@ public enum TL {
COMMAND_MONEYWITHDRAW_DESCRIPTION("Withdraw money"), COMMAND_MONEYWITHDRAW_DESCRIPTION("Withdraw money"),
COMMAND_MONEYWITHDRAW_WITHDRAW("&c&l[!]&7 &c%1$s&7 withdrew&c %2$s &7from the faction bank:&c %3$s"), COMMAND_MONEYWITHDRAW_WITHDRAW("&c&l[!]&7 &c%1$s&7 withdrew&c %2$s &7from the faction bank:&c %3$s"),
COMMAND_COOLDOWN("&c&l[!] &7You are currently on cooldown for this command!"),
COMMAND_OPEN_TOOPEN("to open or close the faction"), COMMAND_OPEN_TOOPEN("to open or close the faction"),
COMMAND_OPEN_FOROPEN("for opening or closing the faction"), COMMAND_OPEN_FOROPEN("for opening or closing the faction"),
COMMAND_OPEN_OPEN("open"), COMMAND_OPEN_OPEN("open"),

View File

@ -594,11 +594,12 @@ fwarp-gui:
- ' ' - ' '
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
# | Faction Creation/Disband Broadcast | # # | Faction Broadcasts | #
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
############################################################ ############################################################
faction-creation-broadcast: true #Disabling this will not make faction creation broadcasts appear in chat. faction-creation-broadcast: true #Disabling this will not make faction creation broadcasts appear in chat.
faction-disband-broadcast: true #Disabling this will not make faction disband broadcasts appear in chat. faction-disband-broadcast: true #Disabling this will not make faction disband broadcasts appear in chat.
faction-open-broadcast: true #Disabling this will not make faction open broadcasts appear in chat.
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
@ -729,7 +730,6 @@ F-Shop:
# | Faction Command Cooldowns | # # | Faction Command Cooldowns | #
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
############################################################ ############################################################
#To-Do#
fcooldowns: fcooldowns:
f-open: 5 f-open: 5
f-disband: 10 f-disband: 10