9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-19 14:59:19 +00:00

Add IconCommand and teleport command cooldown, bump 1.2.8

This commit is contained in:
Sam
2020-07-17 12:53:01 +01:00
parent e5e0f16310
commit 1c4deafbe3
7 changed files with 63 additions and 12 deletions

View File

@@ -4,10 +4,12 @@ public class IconCommand {
private final String command;
private final CommandClickType clickType;
private final int cooldown;
public IconCommand(String command, CommandClickType clickType) {
public IconCommand(String command, CommandClickType clickType, int cooldown) {
this.command = command;
this.clickType = clickType;
this.cooldown = cooldown;
}
public String getCommand() {
@@ -17,7 +19,11 @@ public class IconCommand {
public CommandClickType getClickType() {
return clickType;
}
public int getCooldown() {
return cooldown;
}
public enum CommandClickType {
DISCOVERED,
UNDISCOVERED

View File

@@ -1,2 +1,2 @@
pluginGroup=net.islandearth
pluginVersion=1.2.7
pluginVersion=1.2.8

View File

@@ -10,11 +10,13 @@ import io.papermc.lib.PaperLib;
import me.arcaniax.hdb.api.HeadDatabaseAPI;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.command.IconCommand;
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.translation.Translations;
import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.StringUtils;
import net.islandearth.rpgregions.utils.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -242,11 +244,22 @@ public class DiscoveryGUI extends RPGRegionsGUI {
if (configuredRegion.isTeleportable()
&& player.hasPermission("rpgregions.teleport")
&& hasDiscovered) {
int x = configuredRegion.getX();
int y = configuredRegion.getY();
int z = configuredRegion.getZ();
if (configuredRegion.getWorld() == null) Translations.CANNOT_TELEPORT.send(player);
else PaperLib.teleportAsync(player, new Location(configuredRegion.getWorld(), x, y, z));
if (!account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.TELEPORT)) {
int x = configuredRegion.getX();
int y = configuredRegion.getY();
int z = configuredRegion.getZ();
if (configuredRegion.getWorld() == null) {
Translations.CANNOT_TELEPORT.send(player);
} else {
PaperLib.teleportAsync(player, new Location(configuredRegion.getWorld(), x, y, z));
if (configuredRegion.getTeleportCooldown() != 0) {
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.TELEPORT);
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
}
}
} else {
Translations.COOLDOWN.send(player);
}
}
if (!configuredRegion.getIconCommands().isEmpty()) {
@@ -263,10 +276,20 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|| iconCommand.getClickType() != IconCommand.CommandClickType.UNDISCOVERED && !hasDiscovered) {
return;
}
if (account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.ICON_COMMAND)) {
Translations.COOLDOWN.send(player);
return;
}
player.performCommand(iconCommand.getCommand()
.replace("%region%", configuredRegion.getId())
.replace("%player%", player.getName()));
if (iconCommand.getCooldown() != 0) {
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND), iconCommand.getCooldown());
}
});
}
}));

View File

@@ -2,6 +2,8 @@ package net.islandearth.rpgregions.managers.data.account;
import net.islandearth.rpgregions.managers.data.region.Discovery;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -9,10 +11,12 @@ public class RPGRegionsAccount {
private UUID uuid;
private Map<String, Discovery> discoveredRegions;
private List<AccountCooldown> cooldowns;
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
this.uuid = uuid;
this.discoveredRegions = discoveredRegions;
this.cooldowns = new ArrayList<>();
}
public Map<String, Discovery> getDiscoveredRegions() {
@@ -22,4 +26,13 @@ public class RPGRegionsAccount {
public void addDiscovery(Discovery discovery) {
discoveredRegions.put(discovery.getRegion(), discovery);
}
public List<AccountCooldown> getCooldowns() {
return cooldowns;
}
public enum AccountCooldown {
ICON_COMMAND,
TELEPORT
}
}

View File

@@ -60,6 +60,7 @@ public class ConfiguredRegion {
private List<String> discoveredTitle;
private List<String> discoveredSubtitle;
private Regenerate regenerate;
private final int teleportCooldown;
public ConfiguredRegion(@Nullable World world, String id, String customName,
List<DiscoveryReward> rewards, List<RegionEffect> effects, int x, int y, int z) {
@@ -85,6 +86,7 @@ public class ConfiguredRegion {
this.requirements = Collections.singletonList(new LevelRequirement(5));
this.discoveredLore = new ArrayList<>();
this.alwaysShowTitles = false;
this.teleportCooldown = 0;
}
public ConfiguredRegion(@Nullable World world, String id, String customName,
@@ -112,6 +114,7 @@ public class ConfiguredRegion {
this.requirements = Collections.singletonList(new LevelRequirement(5));
this.discoveredLore = new ArrayList<>();
this.alwaysShowTitles = false;
this.teleportCooldown = 0;
}
public String getId() {
@@ -302,7 +305,11 @@ public class ConfiguredRegion {
public void setRegenerate(@NotNull Regenerate regenerate) {
this.regenerate = regenerate;
}
public int getTeleportCooldown() {
return teleportCooldown;
}
public void save(RPGRegions plugin) throws IOException {
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
Writer writer = new FileWriter(file);

View File

@@ -29,7 +29,8 @@ public enum Translations {
UNKNOWN_REGION("Unknown Realm"),
EXIT("&cExit"),
EXIT_LORE("&fExit the GUI", true),
CANNOT_ENTER("&cYou require %0 to enter this area.");
CANNOT_ENTER("&cYou require %0 to enter this area."),
COOLDOWN("&cThat is currently on cooldown.");
private final String defaultValue;
private final boolean isList;

View File

@@ -20,4 +20,5 @@ previous_page_lore:
next_page_lore:
- "&fGo to the next page"
exit_lore:
- "&fExit the GUI"
- "&fExit the GUI"
cooldown: "&cThat is currently on cooldown."