Skip to content

Commit

Permalink
1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyRS committed Jan 5, 2019
1 parent a3e6d62 commit 97f5a12
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.timmyRS</groupId>
<artifactId>SurvivalUtils</artifactId>
<version>1.7</version>
<version>1.8</version>
<build>
<plugins>
<plugin>
Expand Down
59 changes: 42 additions & 17 deletions src/de/timmyrs/SurvivalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class SurvivalUtils extends JavaPlugin implements Listener, CommandExecut
private final ArrayList<Player> sleepingPlayers = new ArrayList<>();
private final HashMap<World, Integer> sleepMessageTasks = new HashMap<>();
private final ArrayList<Player> colorSignInformed = new ArrayList<>();
private final HashMap<Player, Long> playersNextTeleport = new HashMap<>();

@Override
public void onEnable()
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -301,6 +334,10 @@ private void reloadSurvivalUtilsConfig()
}
}
}
synchronized(playersNextTeleport)
{
playersNextTeleport.clear();
}
saveConfig();
}

Expand Down Expand Up @@ -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)));
}
}
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1021,11 +1050,11 @@ public boolean onCommand(CommandSender s, Command c, String l, String[] a)
final Map<String, Object> 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
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -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/
Expand Down

0 comments on commit 97f5a12

Please sign in to comment.