9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-20 07:19:18 +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 String command;
private final CommandClickType clickType; 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.command = command;
this.clickType = clickType; this.clickType = clickType;
this.cooldown = cooldown;
} }
public String getCommand() { public String getCommand() {
@@ -18,6 +20,10 @@ public class IconCommand {
return clickType; return clickType;
} }
public int getCooldown() {
return cooldown;
}
public enum CommandClickType { public enum CommandClickType {
DISCOVERED, DISCOVERED,
UNDISCOVERED UNDISCOVERED

View File

@@ -1,2 +1,2 @@
pluginGroup=net.islandearth 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 me.arcaniax.hdb.api.HeadDatabaseAPI;
import net.islandearth.rpgregions.RPGRegions; import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.command.IconCommand; 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.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.translation.Translations; import net.islandearth.rpgregions.translation.Translations;
import net.islandearth.rpgregions.utils.ItemStackBuilder; import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.StringUtils; import net.islandearth.rpgregions.utils.StringUtils;
import net.islandearth.rpgregions.utils.XMaterial; import net.islandearth.rpgregions.utils.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -242,11 +244,22 @@ public class DiscoveryGUI extends RPGRegionsGUI {
if (configuredRegion.isTeleportable() if (configuredRegion.isTeleportable()
&& player.hasPermission("rpgregions.teleport") && player.hasPermission("rpgregions.teleport")
&& hasDiscovered) { && hasDiscovered) {
if (!account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.TELEPORT)) {
int x = configuredRegion.getX(); int x = configuredRegion.getX();
int y = configuredRegion.getY(); int y = configuredRegion.getY();
int z = configuredRegion.getZ(); int z = configuredRegion.getZ();
if (configuredRegion.getWorld() == null) Translations.CANNOT_TELEPORT.send(player); if (configuredRegion.getWorld() == null) {
else PaperLib.teleportAsync(player, new Location(configuredRegion.getWorld(), x, y, z)); 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()) { if (!configuredRegion.getIconCommands().isEmpty()) {
@@ -264,9 +277,19 @@ public class DiscoveryGUI extends RPGRegionsGUI {
return; return;
} }
if (account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.ICON_COMMAND)) {
Translations.COOLDOWN.send(player);
return;
}
player.performCommand(iconCommand.getCommand() player.performCommand(iconCommand.getCommand()
.replace("%region%", configuredRegion.getId()) .replace("%region%", configuredRegion.getId())
.replace("%player%", player.getName())); .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 net.islandearth.rpgregions.managers.data.region.Discovery;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -9,10 +11,12 @@ public class RPGRegionsAccount {
private UUID uuid; private UUID uuid;
private Map<String, Discovery> discoveredRegions; private Map<String, Discovery> discoveredRegions;
private List<AccountCooldown> cooldowns;
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) { public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
this.uuid = uuid; this.uuid = uuid;
this.discoveredRegions = discoveredRegions; this.discoveredRegions = discoveredRegions;
this.cooldowns = new ArrayList<>();
} }
public Map<String, Discovery> getDiscoveredRegions() { public Map<String, Discovery> getDiscoveredRegions() {
@@ -22,4 +26,13 @@ public class RPGRegionsAccount {
public void addDiscovery(Discovery discovery) { public void addDiscovery(Discovery discovery) {
discoveredRegions.put(discovery.getRegion(), 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> discoveredTitle;
private List<String> discoveredSubtitle; private List<String> discoveredSubtitle;
private Regenerate regenerate; private Regenerate regenerate;
private final int teleportCooldown;
public ConfiguredRegion(@Nullable World world, String id, String customName, public ConfiguredRegion(@Nullable World world, String id, String customName,
List<DiscoveryReward> rewards, List<RegionEffect> effects, int x, int y, int z) { 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.requirements = Collections.singletonList(new LevelRequirement(5));
this.discoveredLore = new ArrayList<>(); this.discoveredLore = new ArrayList<>();
this.alwaysShowTitles = false; this.alwaysShowTitles = false;
this.teleportCooldown = 0;
} }
public ConfiguredRegion(@Nullable World world, String id, String customName, public ConfiguredRegion(@Nullable World world, String id, String customName,
@@ -112,6 +114,7 @@ public class ConfiguredRegion {
this.requirements = Collections.singletonList(new LevelRequirement(5)); this.requirements = Collections.singletonList(new LevelRequirement(5));
this.discoveredLore = new ArrayList<>(); this.discoveredLore = new ArrayList<>();
this.alwaysShowTitles = false; this.alwaysShowTitles = false;
this.teleportCooldown = 0;
} }
public String getId() { public String getId() {
@@ -303,6 +306,10 @@ public class ConfiguredRegion {
this.regenerate = regenerate; this.regenerate = regenerate;
} }
public int getTeleportCooldown() {
return teleportCooldown;
}
public void save(RPGRegions plugin) throws IOException { public void save(RPGRegions plugin) throws IOException {
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json"); File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
Writer writer = new FileWriter(file); Writer writer = new FileWriter(file);

View File

@@ -29,7 +29,8 @@ public enum Translations {
UNKNOWN_REGION("Unknown Realm"), UNKNOWN_REGION("Unknown Realm"),
EXIT("&cExit"), EXIT("&cExit"),
EXIT_LORE("&fExit the GUI", true), 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 String defaultValue;
private final boolean isList; private final boolean isList;

View File

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