Skip to content

Commit

Permalink
added command /disabletpsafety
Browse files Browse the repository at this point in the history
disabled saving previous location when teleport protection triggers

fixed command cooldown for /wild
  • Loading branch information
ShakeforProtein committed Jul 2, 2019
1 parent 43c3fe3 commit 70fa855
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>TreeboTeleport</artifactId>
<version>0.1.6</version>
<version>0.1.7</version>
<packaging>jar</packaging>

<name>TreeboTeleport</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class TreeboTeleport extends JavaPlugin {
public HashMap lockMove = new HashMap<UUID, Long>();
public HashMap commCooldown = new HashMap<Player, Long>();
public HashMap lastLocConf = new HashMap<UUID, Location>();
public HashMap tpSafetyOff = new HashMap<UUID, String>();

@Override
public void onEnable() {
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ commands:
description: 'Toggles receiving teleport requests'
usage: <command>
permission: tbteleport.player.tptoggle
disabletpsafety:
description: 'Allows a player to disable their teleport safety'
usage: <command>
permission: tbteleport.player.tptoggle
back:
description: 'Returns player to location prior to last teleport'
usage: <command>
Expand Down

0 comments on commit 70fa855

Please sign in to comment.