mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-09-27 14:13:00 +02:00
Added cooldown for '/island preview' command
This commit is contained in:
parent
888667cc7e
commit
4d4bb73e4f
@ -4,9 +4,16 @@ import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.confirmation.Confirmation;
|
||||
import com.songoda.skyblock.cooldown.Cooldown;
|
||||
import com.songoda.skyblock.cooldown.CooldownManager;
|
||||
import com.songoda.skyblock.cooldown.CooldownPlayer;
|
||||
import com.songoda.skyblock.cooldown.CooldownType;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.playerdata.PlayerData;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.structure.Structure;
|
||||
import com.songoda.skyblock.utils.NumberUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@ -19,6 +26,9 @@ public class PreviewCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
CooldownManager cooldownManager = plugin.getCooldownManager();
|
||||
MessageManager messageManager = plugin.getMessageManager();
|
||||
SoundManager soundManager = plugin.getSoundManager();
|
||||
FileManager fileManager = plugin.getFileManager();
|
||||
FileManager.Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLang = config.getFileConfiguration();
|
||||
@ -61,6 +71,33 @@ public class PreviewCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Do not preview if cooldown is still active
|
||||
if (fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getBoolean("Island.Preview.Cooldown.Enable")
|
||||
&& cooldownManager.hasPlayer(CooldownType.Preview, player)) {
|
||||
CooldownPlayer cooldownPlayer = cooldownManager.getCooldownPlayer(CooldownType.Preview, player);
|
||||
Cooldown cooldown = cooldownPlayer.getCooldown();
|
||||
|
||||
if (cooldown.getTime() < 60) {
|
||||
messageManager.sendMessage(player,
|
||||
config.getFileConfiguration().getString("Island.Preview.Cooldown.Message")
|
||||
.replace("%time", cooldown.getTime() + " " + config.getFileConfiguration()
|
||||
.getString("Island.Preview.Cooldown.Word.Second")));
|
||||
} else {
|
||||
long[] durationTime = NumberUtil.getDuration(cooldown.getTime());
|
||||
messageManager.sendMessage(player,
|
||||
config.getFileConfiguration().getString("Island.Preview.Cooldown.Message")
|
||||
.replace("%time", durationTime[2] + " "
|
||||
+ config.getFileConfiguration()
|
||||
.getString("Island.Preview.Cooldown.Word.Minute")
|
||||
+ " " + durationTime[3] + " " + config.getFileConfiguration()
|
||||
.getString("Island.Preview.Cooldown.Word.Second")));
|
||||
}
|
||||
|
||||
soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F);
|
||||
|
||||
return;
|
||||
}
|
||||
// Do not preview if user has an island
|
||||
if (island != null) {
|
||||
plugin.getMessageManager().sendMessage(player, configLang.getString("Command.Island.Preview.Island.Message"));
|
||||
|
@ -94,7 +94,7 @@ public class CooldownManager {
|
||||
|
||||
int time = 0;
|
||||
|
||||
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation || cooldownType == CooldownType.Deletion) {
|
||||
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation || cooldownType == CooldownType.Deletion || cooldownType == CooldownType.Preview) {
|
||||
time = this.plugin.getConfiguration()
|
||||
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
|
||||
|
||||
|
@ -9,6 +9,7 @@ public enum CooldownType {
|
||||
Biome,
|
||||
Creation,
|
||||
Deletion,
|
||||
Preview,
|
||||
Levelling,
|
||||
Ownership,
|
||||
Teleport;
|
||||
|
@ -397,6 +397,13 @@ public class IslandManager {
|
||||
data.setConfirmation(Confirmation.Preview);
|
||||
data.setConfirmationTime(configMain.getInt("Island.Preview.Time"));
|
||||
|
||||
|
||||
FileConfiguration configLoad = this.plugin.getConfiguration();
|
||||
if (configLoad.getBoolean("Island.Preview.Cooldown.Enable") && !player.hasPermission("fabledskyblock.bypass.cooldown")
|
||||
&& !player.hasPermission("fabledskyblock.bypass.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||
plugin.getCooldownManager().createPlayer(CooldownType.Preview, player);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -563,6 +570,7 @@ public class IslandManager {
|
||||
|
||||
boolean cooldownCreationEnabled = configLoad.getBoolean("Island.Creation.Cooldown.Creation.Enable");
|
||||
boolean cooldownDeletionEnabled = configLoad.getBoolean("Island.Creation.Cooldown.Deletion.Enable");
|
||||
boolean cooldownPreviewEnabled = configLoad.getBoolean("Island.Preview.Cooldown.Enable");
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if ((island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
||||
@ -597,6 +605,11 @@ public class IslandManager {
|
||||
plugin.getCooldownManager().createPlayer(CooldownType.Deletion, player);
|
||||
}
|
||||
}
|
||||
if (cooldownPreviewEnabled) {
|
||||
if (!player.hasPermission("fabledskyblock.bypass.cooldown") && !player.hasPermission("fabledskyblock.bypass.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||
plugin.getCooldownManager().createPlayer(CooldownType.Preview, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InviteManager inviteManager = plugin.getInviteManager();
|
||||
|
@ -172,6 +172,12 @@ Island:
|
||||
# open the Island Visit menu.
|
||||
Bans: false
|
||||
Preview:
|
||||
# [!] You are adviced to keep these options both enabled to prevent any issues.
|
||||
Cooldown:
|
||||
# When enabled, cooldown will start when a player previews an Island.
|
||||
Enable: true
|
||||
Time: 60
|
||||
# Time until confirmation expires for island preview confirmation.
|
||||
Time: 10
|
||||
Visitor:
|
||||
# When an Island is unloaded if enabled players won't be able to visit the Island
|
||||
|
@ -3633,6 +3633,11 @@ Island:
|
||||
Preview:
|
||||
Timeout:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYour time to preview island has expired.'
|
||||
Cooldown:
|
||||
Word:
|
||||
Minute: minute(s)
|
||||
Second: second(s)
|
||||
Message: '&bSkyBlock &8| &cError&8: &eYou must wait &c&o%time &ebefore previewing an Island.'
|
||||
Hologram:
|
||||
Leaderboard:
|
||||
Votes:
|
||||
|
Loading…
Reference in New Issue
Block a user