diff --git a/pom.xml b/pom.xml index 745284a..5a4ac1e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.ShakeforProtein TreeboTeleport - 0.1.6 + 0.1.7 jar TreeboTeleport diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java new file mode 100644 index 0000000..7de131b --- /dev/null +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java @@ -0,0 +1,38 @@ +package me.shakeforprotein.treeboteleport.Commands; + +import me.shakeforprotein.treeboteleport.TreeboTeleport; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class DisableTpSafety implements CommandExecutor { + + private TreeboTeleport pl; + + public DisableTpSafety(TreeboTeleport main) { + this.pl = main; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if(sender instanceof Player){ + Player p = (Player) sender; + //If hash contains player id then tp protection is currently disabled. As such, we remove the player id to re enable protection. + if(pl.tpSafetyOff.containsKey(p.getUniqueId())){ + pl.tpSafetyOff.remove(p.getUniqueId()); + p.sendMessage(pl.badge + "Teleport protection enabled."); + } + else{ + pl.tpSafetyOff.put(p.getUniqueId(), p.getName()); + p.sendMessage(pl.badge + "Teleport Safeties disabled. TreeboMC takes no responsibility for any death as a result of this. Be safe out there."); + } + } + else{ + sender.sendMessage(pl.err + "Only players may disable their teleport protection."); + } + + return true; + } +} diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java index 6647d05..5541cbf 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java @@ -46,6 +46,9 @@ else if (sender instanceof Player) { sender.sendMessage(pl.err + "This command does not support additional arguments."); } } + else{ + sender.sendMessage(pl.err + "This command is on cooldown and can only be run once every " + pl.getConfig().getString("CommandDelay") + " seconds"); + } } return true; } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java index 08433ae..a6135c1 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java @@ -1,6 +1,7 @@ package me.shakeforprotein.treeboteleport.Listeners; import me.shakeforprotein.treeboteleport.TreeboTeleport; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -19,14 +20,36 @@ public PlayerTeleportListener(TreeboTeleport main) { @EventHandler public void playerTeleport(PlayerTeleportEvent e) { - //e.getPlayer().sendMessage(e.getCause().name()); + + if (e.getCause().name().equalsIgnoreCase("PLUGIN")) { + Player p = e.getPlayer(); - pl.lastLocConf.putIfAbsent(p.getUniqueId(), e.getFrom()); - pl.lastLocConf.replace(p.getUniqueId(), e.getFrom()); - if (e.getPlayer().hasPermission("tbteleport.vipplus.back")) { - p.sendMessage(pl.badge + "Return point set to " + Math.floor(e.getFrom().getX()) + " " + Math.floor(e.getFrom().getY()) + " " + Math.floor(e.getFrom().getZ())); + //SAVE LAST LOCATION TO HASHMAP + if(!(pl.lockMove.containsKey(p.getUniqueId()))) { + pl.lastLocConf.putIfAbsent(p.getUniqueId(), e.getFrom()); + pl.lastLocConf.replace(p.getUniqueId(), e.getFrom()); + if (e.getPlayer().hasPermission("tbteleport.vipplus.back")) { + p.sendMessage(pl.badge + "Return point set to " + Math.floor(e.getFrom().getX()) + " " + Math.floor(e.getFrom().getY()) + " " + Math.floor(e.getFrom().getZ())); + } + } + + //LOCK PLAYERS IN PLACE IF TELEPORTED BY PLUGIN + if (pl.getConfig().get("teleportProtection") != null && pl.getConfig().getInt("teleportProtection") > 0 && !(pl.tpSafetyOff.containsKey(e.getPlayer().getUniqueId()))) { + int tpProtection = pl.getConfig().getInt("teleportProtection") * 20; + pl.lockMove.putIfAbsent(e.getPlayer().getUniqueId(), e.getPlayer().getName()); + e.getPlayer().setInvulnerable(true); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + public void run() { + e.getPlayer().setInvulnerable(false); + if (pl.lockMove.containsKey(e.getPlayer().getUniqueId())) { + pl.lockMove.remove(e.getPlayer().getUniqueId()); + } + } + }, tpProtection); + e.getPlayer().sendMessage(pl.badge + "As a safety feature you have been locked in place for " + pl.getConfig().getInt("teleportProtection") + " seconds."); + e.getPlayer().sendMessage("You can at your own risk disable this protection with /disabletpsafety"); } } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java index c49bfe0..0e746d0 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java @@ -41,6 +41,7 @@ public final class TreeboTeleport extends JavaPlugin { public HashMap lockMove = new HashMap(); public HashMap commCooldown = new HashMap(); public HashMap lastLocConf = new HashMap(); + public HashMap tpSafetyOff = new HashMap(); @Override public void onEnable() { @@ -104,6 +105,7 @@ public void onEnable() { this.getCommand("tteleversion").setExecutor(new Version(this)); this.getCommand("nameit").setExecutor(new NameIt(this)); this.getCommand("tptoggle").setExecutor(new TpToggle(this)); + this.getCommand("disabletpsafety").setExecutor(new DisableTpSafety(this)); this.getCommand("tpno").setExecutor(new TpNo(this)); this.getCommand("tpdeny").setExecutor(new TpNo(this)); this.getCommand("tpcancel").setExecutor(new TpNo(this)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 21ddd6d..dd15ddc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -156,6 +156,10 @@ commands: description: 'Toggles receiving teleport requests' usage: permission: tbteleport.player.tptoggle + disabletpsafety: + description: 'Allows a player to disable their teleport safety' + usage: + permission: tbteleport.player.tptoggle back: description: 'Returns player to location prior to last teleport' usage: