Fixed Teleport Bug

This commit is contained in:
jklmao committed 2022-11-29 21:31:05 +01:00
1 parent 39271b24e1
commit b2b59d2408
2 files changed
+35 -45

No files matched your search

@@ -3,10 +3,7 @@ package com.jklmao.plugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.jklmao.plugin.commands.CommandReload; import com.jklmao.plugin.commands.CommandReload;
@@ -45,8 +42,9 @@ public final class ClickTpa extends JavaPlugin {
commandHandler(); commandHandler();
instance = this; instance = this;
saveDefaultConfig(); saveDefaultConfig();
getServer().getPluginManager().registerEvents(new PlayerEvents(this), this);
getLogger().info("ClickTPA has been loaded Successfully!"); getLogger().info("ClickTPA has been loaded Successfully!");
getServer().getPluginManager().registerEvents((Listener) new PlayerEvents(this), (Plugin) this);
} }
public HashMap<Player, Player> getHash() { public HashMap<Player, Player> getHash() {
@@ -86,14 +84,14 @@ public final class ClickTpa extends JavaPlugin {
} }
public void commandHandler() { public void commandHandler() {
getCommand("tpa").setExecutor((CommandExecutor) new CommandTpa(this)); getCommand("tpa").setExecutor(new CommandTpa(this));
getCommand("tpahere").setExecutor((CommandExecutor) new CommandTpaHere(this)); getCommand("tpahere").setExecutor(new CommandTpaHere(this));
getCommand("tpacancel").setExecutor((CommandExecutor) new CommandTpCancel(this)); getCommand("tpacancel").setExecutor(new CommandTpCancel(this));
getCommand("tpaccept").setExecutor((CommandExecutor) new Commands(this)); getCommand("tpaccept").setExecutor(new Commands(this));
getCommand("tpdeny").setExecutor((CommandExecutor) new CommandTpaDeny(this)); getCommand("tpdeny").setExecutor(new CommandTpaDeny(this));
getCommand("tpo").setExecutor((CommandExecutor) new CommandTpo(this)); getCommand("tpo").setExecutor(new CommandTpo(this));
getCommand("tpohere").setExecutor((CommandExecutor) new CommandTpoHere(this)); getCommand("tpohere").setExecutor(new CommandTpoHere(this));
getCommand("tptoggle").setExecutor((CommandExecutor) new CommandTpToggle(this)); getCommand("tptoggle").setExecutor(new CommandTpToggle(this));
getCommand("clicktparl").setExecutor((CommandExecutor) new CommandReload(this)); getCommand("clicktparl").setExecutor(new CommandReload(this));
} }
} }
@@ -41,23 +41,19 @@ public class Commands implements CommandExecutor {
return true; return true;
} }
if (!this.clicktpa.getHash().containsKey(target) if (!this.clicktpa.getHash().containsKey(target) && !this.clicktpa.getTpaHere().containsKey(target)) {
&& !this.clicktpa.getTpaHere().containsKey(target)) {
if (this.clicktpa.getTpaHere().containsKey(p) && this.clicktpa.getHash().containsKey(p)) { if (this.clicktpa.getTpaHere().containsKey(p) && this.clicktpa.getHash().containsKey(p)) {
return true; return true;
} }
p.sendMessage( p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
this.colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
return true; return true;
} }
p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-got-accepted-tpa"))); p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-got-accepted-tpa")));
target.sendMessage( target.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Target-accepted-tpa-request")));
this.colorize(this.clicktpa.getConfig().getString("Target-accepted-tpa-request")));
if (this.clicktpa.getHash().containsKey(target)) { if (this.clicktpa.getHash().containsKey(target)) {
target.sendMessage( target.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa")));
this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa")));
} else { } else {
p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa"))); p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa")));
} }
@@ -77,32 +73,26 @@ public class Commands implements CommandExecutor {
} }
this.clicktpa.getTpaInfo().remove(target); this.clicktpa.getTpaInfo().remove(target);
this.countdown = this.clicktpa.getServer().getScheduler() this.countdown = this.clicktpa.getServer().getScheduler().scheduleSyncRepeatingTask(this.clicktpa, () -> {
.scheduleSyncRepeatingTask(this.clicktpa, () -> {
if (this.seconds != -1) { if (this.seconds != -1) {
if (this.seconds != 0) { if (this.seconds != 0) {
if (!this.clicktpa.getTeleportStatus().contains(target) if (!this.clicktpa.getTeleportStatus().contains(target) && !this.clicktpa.getTeleportStatus().contains(p)) {
&& !this.clicktpa.getTeleportStatus().contains(p)) {
this.clicktpa.getServer().getScheduler().cancelTask(this.countdown); this.clicktpa.getServer().getScheduler().cancelTask(this.countdown);
if (!this.clicktpa.getTeleportStatus().contains(target)
|| !this.clicktpa.getTeleportStatus().contains(p)) { if (!this.clicktpa.getTeleportStatus().contains(target) || !this.clicktpa.getTeleportStatus().contains(p)) {
if (this.clicktpa.getWhosFault().contains(p)) { if (this.clicktpa.getWhosFault().contains(p)) {
target.sendMessage(this.colorize(this.clicktpa.getConfig() target.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-moved-before-tp")
.getString("Player-moved-before-tp")
.replaceAll("%player%", p.getName()))); .replaceAll("%player%", p.getName())));
p.sendMessage(this.colorize(this.clicktpa.getConfig() p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-moved-before-tp")
.getString("Player-moved-before-tp")
.replaceAll("%player%", p.getName()))); .replaceAll("%player%", p.getName())));
this.clicktpa.getWhosFault().remove(p); this.clicktpa.getWhosFault().remove(p);
this.clicktpa.getWhosFault().remove(target); this.clicktpa.getWhosFault().remove(target);
} }
if (this.clicktpa.getWhosFault().contains(target)) { if (this.clicktpa.getWhosFault().contains(target)) {
target.sendMessage(this.colorize(this.clicktpa.getConfig() target.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-moved-before-tp")
.getString("Player-moved-before-tp")
.replaceAll("%player%", target.getName()))); .replaceAll("%player%", target.getName())));
p.sendMessage(this.colorize(this.clicktpa.getConfig() p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-moved-before-tp")
.getString("Player-moved-before-tp")
.replaceAll("%player%", target.getName()))); .replaceAll("%player%", target.getName())));
this.clicktpa.getWhosFault().remove(target); this.clicktpa.getWhosFault().remove(target);
this.clicktpa.getWhosFault().remove(p); this.clicktpa.getWhosFault().remove(p);
@@ -114,11 +104,16 @@ public class Commands implements CommandExecutor {
} else { } else {
this.clicktpa.getTeleportStatus().remove(p); this.clicktpa.getTeleportStatus().remove(p);
this.clicktpa.getTeleportStatus().remove(target); this.clicktpa.getTeleportStatus().remove(target);
if (clicktpa.getTpaInfo().get(target).getType() == 1) {
p.teleport(target); p.teleport(target);
p.sendMessage(this.colorize(this.clicktpa.getConfig()
.getString("Target-currently-teleporting"))); } else if (clicktpa.getTpaInfo().get(target).getType() == 0) {
target.sendMessage(this.colorize(this.clicktpa.getConfig() target.teleport(p);
.getString("Player-currently-teleporting"))); }
p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Target-currently-teleporting")));
target.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-currently-teleporting")));
this.clicktpa.getServer().getScheduler().cancelTask(this.countdown); this.clicktpa.getServer().getScheduler().cancelTask(this.countdown);
} }
} }
@@ -128,16 +123,13 @@ public class Commands implements CommandExecutor {
} }
if (target == null) { if (target == null) {
if (this.clicktpa.getHash().containsKey(target) if (this.clicktpa.getHash().containsKey(target) && !this.clicktpa.getTpaHere().containsKey(target)) {
&& !this.clicktpa.getTpaHere().containsKey(target)) { if (!this.clicktpa.getHash().containsKey(target) && !this.clicktpa.getTpaHere().containsKey(target)) {
if (!this.clicktpa.getHash().containsKey(target)
&& !this.clicktpa.getTpaHere().containsKey(target)) {
return true; return true;
} }
this.clearLists(p, target); this.clearLists(p, target);
p.sendMessage( p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
this.colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
return true; return true;
} }