diff --git a/README.md b/README.md index 0567fb8..c504eb1 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,12 @@ All features are disabled/OP-only by default to allow for maximum configurabilit - `survivalutils.tpa.toggle` allows the player to use `/tptoggle`. - `survivalutils.home` allows the player to use `/home`, `/sethome`, `/delhome`, and `/homes`. - `survivalutils.homelimit.x` allows the player to use home limit 'x' as defined in the config.yml. -- `survivalutils.allowafk` allows the player to bypass all anti-AFK measures. -- `survivalutils.warp` allows the player to use `/warp`, `/warps`, and warp commands, if enabled. +- `survivalutils.warp` allows the player to teleport to and list warps. - `survivalutils.warps` allows the player to warp everywhere. - `survivalutils.warps.x` allows the player to warp to warp 'x'. - `survivalutils.warpsigns` allows the player to place warp signs. +- `survivalutils.allowafk` allows the player to bypass all anti-AFK measures. +- `survivalutils.notpcooldown` allows the player to bypass the teleportation cooldown. - `survivalutils.managewarps` allows the player to use `/setwarp` and `/delwarp`. - `survivalutils.coloredsigns` allows the player to use colors on signs. - `survivalutils.reload` allows the player to use `/survivalutils reload`. @@ -84,6 +85,7 @@ Similarly, you can use the permissions.yml to remove permissions from OPs: - `message`: The message that will be sent to all players in a dimension when at least one player is sleeping. - `intervalTicks`: The amount of ticks to wait before broadcasting the message. (1 second = 20 ticks) - `skipPercent`: The percent of players that have to sleep for the night or storm to end. +- `teleportCooldown`: The amount of seconds players will have to wait to teleport again. - `createWarpCommands`: Create warp commands, e.g. `/spawn` to alias `/warp spawn`? (true/false) - `warpSigns` - `line`: The first line of warp signs diff --git a/pom.xml b/pom.xml index bd11ac2..03c56f4 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 de.timmyRS SurvivalUtils - 1.7 + 1.8 diff --git a/src/de/timmyrs/SurvivalUtils.java b/src/de/timmyrs/SurvivalUtils.java index aef7a62..0ac4f4d 100644 --- a/src/de/timmyrs/SurvivalUtils.java +++ b/src/de/timmyrs/SurvivalUtils.java @@ -47,6 +47,7 @@ public class SurvivalUtils extends JavaPlugin implements Listener, CommandExecut private final ArrayList sleepingPlayers = new ArrayList<>(); private final HashMap sleepMessageTasks = new HashMap<>(); private final ArrayList colorSignInformed = new ArrayList<>(); + private final HashMap playersNextTeleport = new HashMap<>(); @Override public void onEnable() @@ -80,6 +81,7 @@ public void onEnable() getConfig().addDefault("sleepCoordination.message", "&e%sleeping%/%total% players are sleeping. Won't you join them?"); getConfig().addDefault("sleepCoordination.intervalTicks", 50); getConfig().addDefault("sleepCoordination.skipPercent", 100D); + getConfig().addDefault("teleportCooldown", 0); getConfig().addDefault("createWarpCommands", false); getConfig().addDefault("warpSigns.line", "[Warp]"); getConfig().addDefault("warpSigns.color", "5"); @@ -197,7 +199,38 @@ private boolean isVanished(Player player) private boolean canTeleport(Player p) { //noinspection deprecation - return p.isOnGround() || p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR; + if(p.isOnGround() || p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR) + { + final long time = getTime(); + final Long nextTeleport; + synchronized(playersNextTeleport) + { + nextTeleport = playersNextTeleport.get(p); + if(nextTeleport == null || time >= nextTeleport) + { + return true; + } + } + final long seconds = (nextTeleport - time); + p.sendMessage("§cYou can teleport again in " + seconds + " second" + (seconds == 1 ? "" : "s") + "."); + } + else + { + p.sendMessage("§cYou may not teleport right now."); + } + return false; + } + + private void teleport(Player p, Location l) + { + p.teleport(l); + if(!p.hasPermission("survivalutils.notpcooldown") && getConfig().getLong("teleportCooldown") > 0) + { + synchronized(playersNextTeleport) + { + playersNextTeleport.put(p, getTime() + getConfig().getLong("teleportCooldown")); + } + } } static long getTime() @@ -301,6 +334,10 @@ private void reloadSurvivalUtilsConfig() } } } + synchronized(playersNextTeleport) + { + playersNextTeleport.clear(); + } saveConfig(); } @@ -658,11 +695,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) e.setCancelled(true); if(canTeleport(p)) { - p.teleport(stringToLocation(getConfig().getString("warps." + command))); - } - else - { - p.sendMessage("§cYou may not teleport right now."); + teleport(p, stringToLocation(getConfig().getString("warps." + command))); } } } @@ -895,17 +928,13 @@ public boolean onCommand(CommandSender s, Command c, String l, String[] a) final String w = a[0].toLowerCase(); if((p.hasPermission("survivalutils.warps") || p.hasPermission("survivalutils.warps." + w)) && getConfig().contains("warps." + w)) { - p.teleport(stringToLocation(getConfig().getString("warps." + w))); + teleport(p, stringToLocation(getConfig().getString("warps." + w))); } else { p.sendMessage("§c'" + w + "' is not a warp point."); } } - else - { - p.sendMessage("§cYou may not teleport right now."); - } } else { @@ -1021,11 +1050,11 @@ public boolean onCommand(CommandSender s, Command c, String l, String[] a) final Map homes = playerConfig.getConfigurationSection("homes").getValues(false); if(homes.containsKey(homename)) { - p.teleport(stringToLocation((String) homes.get(homename))); + teleport(p, stringToLocation((String) homes.get(homename))); } else if(homes.size() == 1) { - p.teleport(stringToLocation((String) homes.values().iterator().next())); + teleport(p, stringToLocation((String) homes.values().iterator().next())); } else { @@ -1043,10 +1072,6 @@ else if(homes.size() == 1) p.sendMessage("§cAn I/O error has occured. Please contact an administrator."); } } - else - { - p.sendMessage("§cYou may not teleport right now."); - } } } else diff --git a/src/plugin.yml b/src/plugin.yml index 815d2e3..e6ca0b1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ --- name: SurvivalUtils -version: 1.7 +version: 1.8 main: de.timmyrs.SurvivalUtils author: timmyRS website: https://www.spigotmc.org/resources/survivalutils.62574/