Skip to content

Commit

Permalink
Add cooldowns (#214)
Browse files Browse the repository at this point in the history
* Add command cooldowns

* Fix spawner booster issue

* Bump IridiumCore to 1.1.6

* Move duration format to message

* Rename method

* Add command cooldown to the biome command

* Fix the cooldown message

* Fix the remaining time

* Fix command cooldown config serialization

* Fix bad merge

Co-authored-by: Peaches_MLG <[email protected]>
  • Loading branch information
dlsf and PeachesMLG authored Jul 2, 2021
1 parent 13ca947 commit 9ae94c9
Show file tree
Hide file tree
Showing 66 changed files with 692 additions and 302 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
dependencies {
// Dependencies that we want to shade in
implementation("org.jetbrains", "annotations", "16.0.1")
implementation("com.iridium", "IridiumCore", "1.1.5")
implementation("com.iridium", "IridiumCore", "1.1.6")
implementation("org.bstats", "bstats-bukkit", "2.2.1")
implementation("com.github.j256", "ormlite-core", "master-SNAPSHOT")
implementation("com.j256.ormlite", "ormlite-jdbc", "5.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import java.time.Duration;
import org.bukkit.command.CommandSender;

import java.util.Arrays;
Expand All @@ -22,7 +23,7 @@ public class AboutCommand extends Command {
* The default constructor.
*/
public AboutCommand() {
super(Collections.singletonList("about"), "Display plugin info", "", false);
super(Collections.singletonList("about"), "Display plugin info", "", false, Duration.ZERO);
}

/**
Expand All @@ -34,12 +35,14 @@ public AboutCommand() {
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
sender.sendMessage(StringUtils.color("&7Plugin Name: &bIridiumSkyblock"));
sender.sendMessage(StringUtils.color("&7Plugin Version: &b" + IridiumSkyblock.getInstance().getDescription().getVersion()));
sender.sendMessage(StringUtils.color("&7Plugin Author: &bPeaches_MLG"));
sender.sendMessage(StringUtils.color("&7Plugin Contributors: &b" + String.join(", ", contributors)));
sender.sendMessage(StringUtils.color("&7Plugin Donations: &bwww.patreon.com/Peaches_MLG"));

return true;
}

/**
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/com/iridium/iridiumskyblock/commands/BankCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.gui.BankGUI;
import java.time.Duration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -31,7 +32,7 @@ public class BankCommand extends Command {
* The default constructor.
*/
public BankCommand() {
super(Collections.singletonList("bank"), "Open your Island bank", "", false);
super(Collections.singletonList("bank"), "Open your Island bank", "", false, Duration.ZERO);
this.bankGive = new BankGive();
this.bankSet = new BankSet();
this.bankRemove = new BankRemove();
Expand All @@ -46,28 +47,27 @@ public BankCommand() {
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
if (args.length > 1) {
for (Command command : Arrays.asList(bankGive, bankSet, bankRemove)) {
if (command.aliases.contains(args[1])) {
// Check if this command is only for players
if (command.onlyForPlayers && !(sender instanceof Player)) {
// Must be a player
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}

// Check permissions
if (!((sender.hasPermission(command.permission) || command.permission
.equalsIgnoreCase("") || command.permission
.equalsIgnoreCase("iridiumskyblock.")))) {
// No permissions
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
command.execute(sender, args);
return;

return command.execute(sender, args);
}
}
} else if (sender instanceof Player) {
Expand All @@ -77,13 +77,15 @@ public void execute(CommandSender sender, String[] args) {

if (island.isPresent()) {
player.openInventory(new BankGUI(island.get()).getInventory());
return true;
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.gui.BiomeGUI;
import java.time.Duration;
import org.apache.commons.lang.WordUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -20,36 +21,38 @@ public class BiomeCommand extends Command {
private final IridiumSkyblock plugin = IridiumSkyblock.getInstance();

public BiomeCommand() {
super(Collections.singletonList("biome"), "Change your island biome.", "", true);
super(Collections.singletonList("biome"), "Change your island biome.", "", true, Duration.ZERO);
}

@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
final Player player = (Player) sender;

final User user = this.plugin.getUserManager().getUser(player);
final Optional<Island> optionalIsland = user.getIsland();

if (!optionalIsland.isPresent()) {
player.sendMessage(StringUtils.color(this.plugin.getMessages().noIsland.replace("%prefix%", plugin.getConfiguration().prefix)));
return;
return false;
}

if (args.length != 2) {
player.openInventory(new BiomeGUI(1, optionalIsland.get(), player.getWorld().getEnvironment()).getInventory());
return;
player.openInventory(new BiomeGUI(1, optionalIsland.get(), player.getWorld().getEnvironment(), getCooldownProvider()).getInventory());
// The BiomeGUI handles the cooldown
return false;
}

final Optional<XBiome> biomeOptional = XBiome.matchXBiome(args[1]);
if (!biomeOptional.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().invalidBiome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
return false;
}
IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(optionalIsland.get(), biomeOptional.get());

player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().changedBiome
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
.replace("%biome%", WordUtils.capitalizeFully(biomeOptional.get().name().toLowerCase().replace("_", " ")))));
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.gui.BlockValueGUI;
import com.iridium.iridiumskyblock.gui.InventoryConfigGUI;
import java.time.Duration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -22,7 +23,7 @@ public class BlockValueCommand extends Command {
* The default constructor.
*/
public BlockValueCommand() {
super(Collections.singletonList("blockvalues"), "Show the values of blocks", "", true);
super(Collections.singletonList("blockvalues"), "Show the values of blocks", "", true, Duration.ZERO);

}

Expand All @@ -35,16 +36,18 @@ public BlockValueCommand() {
* @param arguments The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] arguments) {
public boolean execute(CommandSender sender, String[] arguments) {
Player player = (Player) sender;
if (arguments.length == 2) {
BlockValueGUI.BlockValueType blockValueType = BlockValueGUI.BlockValueType.getType(arguments[1]);
if (blockValueType != null) {
player.openInventory(new BlockValueGUI(blockValueType).getInventory());
return;
return true;
}
}

player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().blockValueSelectGUI).getInventory());
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.gui.BoostersGUI;
import com.iridium.iridiumskyblock.utils.PlayerUtils;
import java.time.Duration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -25,7 +26,7 @@ public class BoostersCommand extends Command {
* The default constructor.
*/
public BoostersCommand() {
super(Arrays.asList("booster", "boosters"), "Open the Island Boosters Menu", "", true);
super(Arrays.asList("booster", "boosters"), "Open the Island Boosters Menu", "", true, Duration.ZERO);
}

/**
Expand All @@ -37,7 +38,7 @@ public BoostersCommand() {
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
Expand All @@ -53,21 +54,24 @@ public void execute(CommandSender sender, String[] args) {
islandBooster.setTime(LocalDateTime.now().plusSeconds(booster.time));
IslandLog islandLog = new IslandLog(island.get(), LogAction.BOOSTER_PURCHASE, user, null, 0, boosterName);
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
return true;
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%",
IridiumSkyblock.getInstance().getConfiguration().prefix)));
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}

} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%",
IridiumSkyblock.getInstance().getConfiguration().prefix)));
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
player.openInventory(new BoostersGUI(island.get()).getInventory());
return true;
}
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.gui.InventoryConfigGUI;
import java.time.Duration;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -23,7 +24,7 @@ public class BorderCommand extends Command {
* The default constructor.
*/
public BorderCommand() {
super(Collections.singletonList("border"), "Change the Island Border", "", true);
super(Collections.singletonList("border"), "Change the Island Border", "", true, Duration.ZERO);
}

/**
Expand All @@ -35,18 +36,20 @@ public BorderCommand() {
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();

if (island.isPresent()) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.BORDER)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageBorder.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
return false;
}

if (args.length != 2) {
player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().islandBorder).getInventory());
return true;
} else {
Color color = Color.getColor(args[1]);
if (color != null) {
Expand All @@ -55,6 +58,7 @@ public void execute(CommandSender sender, String[] args) {
island.get().getMembers().stream().map(islandUser -> Bukkit.getPlayer(islandUser.getUuid())).filter(Objects::nonNull).forEach(islandPlayer ->
islandPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandBorderChanged.replace("%player%", player.getName()).replace("%color%", color.toString()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)))
);
return true;
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().borderColorDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
Expand All @@ -65,6 +69,8 @@ public void execute(CommandSender sender, String[] args) {
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.database.User;
import java.time.Duration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -18,7 +19,7 @@ public class BypassCommand extends Command {
* The default constructor.
*/
public BypassCommand() {
super(Collections.singletonList("bypass"), "Bypass Island restrictions", "iridiumskyblock.bypass", true);
super(Collections.singletonList("bypass"), "Bypass Island restrictions", "iridiumskyblock.bypass", true, Duration.ZERO);
}

/**
Expand All @@ -30,11 +31,12 @@ public BypassCommand() {
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public void execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
user.setBypass(!user.isBypass());
player.sendMessage(StringUtils.color((user.isBypass() ? IridiumSkyblock.getInstance().getMessages().nowBypassing : IridiumSkyblock.getInstance().getMessages().noLongerBypassing).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return true;
}

/**
Expand Down
Loading

0 comments on commit 9ae94c9

Please sign in to comment.