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