From de50de30428b8a317a8228422f6c1082407af62e Mon Sep 17 00:00:00 2001
From: jklmao <22cfranco@gmail.com>
Date: Sat, 14 Jan 2023 00:58:23 +0100
Subject: [PATCH] Code overhaul
---
ClickTpa/pom.xml | 42 +++++
.../main/java/com/jklmao/plugin/ClickTpa.java | 79 +++++++++
.../jklmao/plugin/commands/CommandReload.java | 48 ++++++
.../plugin/commands/CommandTpCancel.java | 78 +++++++++
.../plugin/commands/CommandTpToggle.java | 57 ++++++
.../jklmao/plugin/commands/CommandTpa.java | 139 +++++++++++++++
.../plugin/commands/CommandTpaDeny.java | 76 ++++++++
.../plugin/commands/CommandTpaHere.java | 138 +++++++++++++++
.../plugin/commands/CommandTpaccept.java | 123 +++++++++++++
.../jklmao/plugin/commands/CommandTpo.java | 52 ++++++
.../plugin/commands/CommandTpoHere.java | 52 ++++++
.../jklmao/plugin/events/PlayerEvents.java | 54 ++++++
.../plugin/events/TpaCountdownListener.java | 109 ++++++++++++
.../java/com/jklmao/plugin/utils/Commons.java | 11 ++
.../com/jklmao/plugin/utils/CustomList.java | 23 +++
.../com/jklmao/plugin/utils/TeleportMode.java | 7 +
.../com/jklmao/plugin/utils/TeleportMsgs.java | 118 +++++++++++++
.../com/jklmao/plugin/utils/TeleportType.java | 7 +
.../com/jklmao/plugin/utils/TpaInfoList.java | 22 +++
ClickTpa/src/main/java/config.yml | 162 ++++++++++++++++++
ClickTpa/src/main/java/plugin.yml | 32 ++++
21 files changed, 1429 insertions(+)
create mode 100644 ClickTpa/pom.xml
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/ClickTpa.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandReload.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpCancel.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpToggle.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpa.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaDeny.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaHere.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaccept.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpo.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpoHere.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/events/PlayerEvents.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/events/TpaCountdownListener.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/Commons.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/CustomList.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMode.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMsgs.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportType.java
create mode 100644 ClickTpa/src/main/java/com/jklmao/plugin/utils/TpaInfoList.java
create mode 100644 ClickTpa/src/main/java/config.yml
create mode 100644 ClickTpa/src/main/java/plugin.yml
diff --git a/ClickTpa/pom.xml b/ClickTpa/pom.xml
new file mode 100644
index 0000000..062bbec
--- /dev/null
+++ b/ClickTpa/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ com.jklmao.plugin
+ ClickTpa
+ 1.7v
+ jar
+
+ ClickTpa
+
+ Simple TPA plugin for Spigot/Paper Software
+
+
+ 1.8
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+
+ papermc-repo
+ https://papermc.io/repo/repository/maven-public/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.19.3-R0.1-SNAPSHOT
+ provided
+
+
+
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/ClickTpa.java b/ClickTpa/src/main/java/com/jklmao/plugin/ClickTpa.java
new file mode 100644
index 0000000..06934d8
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/ClickTpa.java
@@ -0,0 +1,79 @@
+package com.jklmao.plugin;
+
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import com.jklmao.plugin.commands.CommandReload;
+import com.jklmao.plugin.commands.CommandTpCancel;
+import com.jklmao.plugin.commands.CommandTpToggle;
+import com.jklmao.plugin.commands.CommandTpa;
+import com.jklmao.plugin.commands.CommandTpaDeny;
+import com.jklmao.plugin.commands.CommandTpaHere;
+import com.jklmao.plugin.commands.CommandTpaccept;
+import com.jklmao.plugin.commands.CommandTpo;
+import com.jklmao.plugin.commands.CommandTpoHere;
+import com.jklmao.plugin.events.PlayerEvents;
+import com.jklmao.plugin.utils.CustomList;
+import com.jklmao.plugin.utils.TeleportMode;
+
+public final class ClickTpa extends JavaPlugin {
+
+ private HashSet graceList = new HashSet<>();
+ private HashMap tpaCancel = new HashMap<>();
+ private HashMap playerTpaList = new HashMap<>();
+
+ @Override
+ public void onEnable() {
+ commandHandler();
+ addAllPlayers();
+
+ saveDefaultConfig();
+ getServer().getPluginManager().registerEvents(new PlayerEvents(this), this);
+ getLogger().info("ClickTPA has been loaded Successfully!");
+
+ }
+
+ public HashSet getGraceList() {
+ return this.graceList;
+ }
+
+ public HashMap getTpaCancel() {
+ return tpaCancel;
+ }
+
+ public HashMap getTpaPlayers() {
+ return this.playerTpaList;
+ }
+
+ public void reloadTheConfig() {
+ reloadConfig();
+ }
+
+ public void commandHandler() {
+ getCommand("tpa").setExecutor(new CommandTpa(this));
+ getCommand("tpahere").setExecutor(new CommandTpaHere(this));
+ getCommand("tpacancel").setExecutor(new CommandTpCancel(this));
+ getCommand("tpaccept").setExecutor(new CommandTpaccept(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));
+ }
+
+ public void addAllPlayers() {
+
+ CustomList list = new CustomList();
+ list.setMode(TeleportMode.DEFAULT);
+
+ for (Player p : Bukkit.getOnlinePlayers()) {
+ playerTpaList.put(p, list);
+ }
+
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandReload.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandReload.java
new file mode 100644
index 0000000..12ebc17
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandReload.java
@@ -0,0 +1,48 @@
+package com.jklmao.plugin.commands;
+
+import java.io.File;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+
+public class CommandReload implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ public FileConfiguration config;
+
+ public File configFile;
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ String prefix = "&4&l[Click&b&lTpa]";
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.reload")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ } else {
+ this.clicktpa.saveDefaultConfig();
+ this.clicktpa.reloadConfig();
+ sender.sendMessage(colorize(String.valueOf(prefix) + " &aThe plugin has been reloaded!"));
+ }
+ } else {
+ this.clicktpa.saveDefaultConfig();
+ this.clicktpa.reloadConfig();
+ sender.sendMessage(colorize(String.valueOf(prefix) + " &aThe plugin has been reloaded!"));
+ }
+ return true;
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandReload(ClickTpa pl) {
+ this.clicktpa = pl;
+ this.clicktpa.saveDefaultConfig();
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpCancel.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpCancel.java
new file mode 100644
index 0000000..b6c4bca
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpCancel.java
@@ -0,0 +1,78 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+public class CommandTpCancel implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ public CommandTpCancel(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+
+ if (!p.hasPermission("clicktpa.tpacancel")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+
+ if (this.clicktpa.getTpaCancel().containsKey(p)) {
+
+ Player poorRejectedGuy = Bukkit.getServer().getPlayer(this.clicktpa.getTpaCancel().get(p).getName());
+
+ if (poorRejectedGuy == null) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Tpacancel-message")));
+ clicktpa.getTpaCancel().remove(p);
+ return true;
+ }
+
+ if (poorRejectedGuy.isOnline()) {
+
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Tpacancel-message")));
+ poorRejectedGuy.sendMessage(colorize(clicktpa.getConfig().getString("Tpacancel-message")));
+ removeTpaInfo(p, poorRejectedGuy);
+
+ return true;
+ }
+
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Tpacancel-message")));
+ removeTpaInfo(p, poorRejectedGuy);
+ return true;
+
+ } else {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ private void removeTpaInfo(Player p, Player target) {
+
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(target).getTpaList()) {
+ if (list.getRequester() == p) {
+ clicktpa.getTpaPlayers().get(target).getTpaList().remove(list);
+ clicktpa.getTpaCancel().remove(p);
+ return;
+ }
+ }
+
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpToggle.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpToggle.java
new file mode 100644
index 0000000..c1ab40c
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpToggle.java
@@ -0,0 +1,57 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TeleportMode;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class CommandTpToggle implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tptoggle")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (p.hasPermission("clicktpa.tptoggle")) {
+
+ TeleportMode mode = clicktpa.getTpaPlayers().get(p).getMode();
+
+ switch (mode) {
+
+ case DEFAULT:
+ // turn on tptoggle
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.TPTOGGLE_ON);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-TpToggle-On")));
+ break;
+ case TPTOGGLE_ON:
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.DEFAULT);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-TpToggle-Off")));
+ break;
+ case TELEPORTING:
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("TpToggle-While-Teleporting")));
+ break;
+ }
+ return true;
+ }
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpToggle(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpa.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpa.java
new file mode 100644
index 0000000..8bfe625
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpa.java
@@ -0,0 +1,139 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TeleportMode;
+import com.jklmao.plugin.utils.TeleportMsgs;
+import com.jklmao.plugin.utils.TeleportType;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class CommandTpa implements CommandExecutor {
+
+ private ClickTpa clicktpa;
+ private BukkitTask task;
+ private final TeleportMsgs msgs = new TeleportMsgs();
+ private TpaInfoList info;
+
+ public CommandTpa(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if (sender instanceof Player) {
+ final Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpa")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpa-usage")));
+ return true;
+ }
+ final Player target = Bukkit.getPlayer(args[0]);
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+ if (target.equals(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-teleporting-self")));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.TPTOGGLE_ON) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-Is-TpToggled")));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(target).getMode() == TeleportMode.TPTOGGLE_ON) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-Is-TpToggled").replaceAll("%target%", target.getName())));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.DEFAULT) {
+
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(target).getTpaList()) {
+
+ if (list.getRequester() == p) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-already-requested")));
+ return true;
+ }
+ }
+
+ // create a new tpa info
+ info = new TpaInfoList(TeleportType.TPA, p);
+
+ clicktpa.getTpaPlayers().get(target).getTpaList().add(info);
+ clicktpa.getTpaCancel().put(p, target);
+ msgs.sendRequestMsg(clicktpa, TeleportType.TPA, p, target);
+ startTimer(p, target);
+ return true;
+ }
+
+ } else {
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+
+ }
+ return true;
+ }
+
+ private void startTimer(Player p, Player target) {
+
+ task = Bukkit.getScheduler().runTaskTimer(clicktpa, new Runnable() {
+
+ int time = clicktpa.getConfig().getInt("Request-expire-time") * 4;
+
+ @Override
+ public void run() {
+ if (time == 0) {
+ task.cancel();
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Player-teleportation-request-expire")));
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Target-teleportation-request-expire")));
+
+ // expired request
+ clicktpa.getTpaPlayers().get(target).getTpaList().remove(info);
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.DEFAULT);
+ task = null;
+ return;
+ }
+
+ if (!target.isOnline()) {
+ task.cancel();
+ task = null;
+ return;
+ } else {
+
+ if (!clicktpa.getTpaPlayers().get(target).getTpaList().contains(info)) {
+ task.cancel();
+ task = null;
+ return;
+ }
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.TELEPORTING) {
+ task.cancel();
+ task = null;
+ return;
+ }
+
+ time = time - 1;
+ }
+
+ }, 0, 5);
+
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaDeny.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaDeny.java
new file mode 100644
index 0000000..7130a48
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaDeny.java
@@ -0,0 +1,76 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+public class CommandTpaDeny implements CommandExecutor {
+
+ private ClickTpa clicktpa;
+
+ public CommandTpaDeny(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpadeny")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpdeny-usage")));
+ return true;
+ }
+ final Player target = Bukkit.getPlayer(args[0]);
+
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+
+ if (target.isOnline()) {
+
+ boolean hasRequester = false;
+
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(p).getTpaList()) {
+ if (list.getRequester() == target) {
+ clicktpa.getTpaPlayers().get(p).getTpaList().remove(list);
+ clicktpa.getTpaCancel().remove(target);
+ hasRequester = true;
+ break;
+ }
+ }
+
+ if (hasRequester) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-deny-tpa-message")));
+ target.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-deny-tpa-message")));
+ clicktpa.getTpaCancel().remove(target);
+ return true;
+ } else {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+
+ } else {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Target-is-offline")));
+ return true;
+ }
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaHere.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaHere.java
new file mode 100644
index 0000000..2ad069a
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaHere.java
@@ -0,0 +1,138 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TeleportMode;
+import com.jklmao.plugin.utils.TeleportMsgs;
+import com.jklmao.plugin.utils.TeleportType;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+public class CommandTpaHere implements CommandExecutor {
+
+ private ClickTpa clicktpa;
+ private BukkitTask task;
+ private final TeleportMsgs msgs = new TeleportMsgs();
+ private TpaInfoList info;
+
+ public CommandTpaHere(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if (sender instanceof Player) {
+ final Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpahere")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpahere-usage")));
+ return true;
+ }
+ final Player target = Bukkit.getPlayer(args[0]);
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+ if (target.equals(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-teleporting-self")));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.TPTOGGLE_ON) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-Is-TpToggled")));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(target).getMode() == TeleportMode.TPTOGGLE_ON) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-Is-TpToggled").replaceAll("%target%", target.getName())));
+ return true;
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.DEFAULT) {
+
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(target).getTpaList()) {
+
+ if (list.getRequester() == p) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-already-requested")));
+ return true;
+ }
+ }
+
+ // create a new tpa info
+ info = new TpaInfoList(TeleportType.TPAHERE, p);
+
+ clicktpa.getTpaPlayers().get(target).getTpaList().add(info);
+ clicktpa.getTpaCancel().put(p, target);
+ msgs.sendRequestMsg(clicktpa, TeleportType.TPAHERE, p, target);
+ startTimer(p, target);
+ return true;
+ }
+
+ } else {
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+
+ }
+ return true;
+ }
+
+ private void startTimer(Player p, Player target) {
+
+ task = Bukkit.getScheduler().runTaskTimer(clicktpa, new Runnable() {
+
+ int time = clicktpa.getConfig().getInt("Request-expire-time") * 4;
+
+ @Override
+ public void run() {
+ if (time == 0) {
+ task.cancel();
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Player-teleportation-request-expire")));
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Target-teleportation-request-expire")));
+
+ // expired request
+ clicktpa.getTpaPlayers().get(target).getTpaList().remove(info);
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.DEFAULT);
+ task = null;
+ return;
+ }
+
+ if (!target.isOnline()) {
+ task.cancel();
+ task = null;
+ return;
+ } else {
+
+ if (!clicktpa.getTpaPlayers().get(target).getTpaList().contains(info)) {
+ task.cancel();
+ task = null;
+ return;
+ }
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getMode() == TeleportMode.TELEPORTING) {
+ task.cancel();
+ task = null;
+ return;
+ }
+
+ time = time - 1;
+ }
+
+ }, 0, 5);
+
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaccept.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaccept.java
new file mode 100644
index 0000000..44d3029
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaccept.java
@@ -0,0 +1,123 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.events.TpaCountdownListener;
+import com.jklmao.plugin.utils.TeleportMode;
+import com.jklmao.plugin.utils.TeleportType;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class CommandTpaccept implements CommandExecutor {
+ private int seconds;
+ private ClickTpa clicktpa;
+ ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
+
+ public CommandTpaccept(ClickTpa pl) {
+ clicktpa = pl;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+
+ seconds = clicktpa.getConfig().getInt("Seconds-until-tpa");
+
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(colorize(clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ } else {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpaccept")) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Tpaccept-usage")));
+ return true;
+ }
+
+ Player target = Bukkit.getPlayer(args[0]);
+
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+
+ if (!target.isOnline()) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Target-is-offline")));
+
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(p).getTpaList()) {
+ if (list.getRequester() == target) {
+ clicktpa.getTpaPlayers().get(p).getTpaList().remove(list);
+ clicktpa.getTpaCancel().remove(target);
+ return true;
+ }
+ }
+ }
+
+ if (clicktpa.getTpaPlayers().get(p).getTpaList().isEmpty()) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+
+ TpaInfoList tpaInfo = null;
+
+ if (clicktpa.getTpaPlayers().get(p).getTpaList().size() > 0) {
+
+ boolean hasRequester = false;
+ for (TpaInfoList list : clicktpa.getTpaPlayers().get(p).getTpaList()) {
+
+ if (list.getRequester() != target) {
+ hasRequester = false;
+ } else {
+ hasRequester = true;
+ tpaInfo = list;
+ break;
+ }
+ }
+
+ if (hasRequester == false) {
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+
+ }
+
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Player-got-accepted-tpa")));
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Target-accepted-tpa-request")));
+
+ TpaCountdownListener cdListener = new TpaCountdownListener();
+
+ switch (tpaInfo.getType()) {
+
+ case TPA:
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Countdown-until-tpa")));
+ clicktpa.getTpaPlayers().get(target).setMode(TeleportMode.TELEPORTING);
+ clicktpa.getGraceList().add(target);
+ cdListener.tpaCountdown(clicktpa, seconds, TeleportType.TPA, p, target);
+ break;
+ case TPAHERE:
+ p.sendMessage(colorize(clicktpa.getConfig().getString("Countdown-until-tpa")));
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.TELEPORTING);
+ clicktpa.getGraceList().add(p);
+ cdListener.tpaCountdown(clicktpa, seconds, TeleportType.TPAHERE, p, target);
+ break;
+ }
+ clicktpa.getTpaCancel().remove(target);
+
+ return true;
+ }
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
\ No newline at end of file
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpo.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpo.java
new file mode 100644
index 0000000..1665e66
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpo.java
@@ -0,0 +1,52 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class CommandTpo implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpo")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpo-usage")));
+ return true;
+ }
+ Player target = Bukkit.getPlayer(args[0]);
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+ if (target.equals(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-teleporting-self")));
+ return true;
+ }
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-currently-teleporting")));
+ target.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-currently-teleporting")));
+ p.teleport(target);
+ return true;
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpo(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpoHere.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpoHere.java
new file mode 100644
index 0000000..8904375
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpoHere.java
@@ -0,0 +1,52 @@
+package com.jklmao.plugin.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class CommandTpoHere implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpohere")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (args.length == 0) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpohere-usage")));
+ return true;
+ }
+ Player target = Bukkit.getPlayer(args[0]);
+ if (target == null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("No-player-found")));
+ return true;
+ }
+ if (target.equals(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-teleporting-self")));
+ return true;
+ }
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-currently-teleporting")));
+ target.teleport(p);
+ target.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-currently-teleporting")));
+ return true;
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpoHere(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/events/PlayerEvents.java b/ClickTpa/src/main/java/com/jklmao/plugin/events/PlayerEvents.java
new file mode 100644
index 0000000..fd5ecb0
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/events/PlayerEvents.java
@@ -0,0 +1,54 @@
+package com.jklmao.plugin.events;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.CustomList;
+import com.jklmao.plugin.utils.TeleportMode;
+
+public class PlayerEvents implements Listener {
+ private ClickTpa clicktpa;
+
+ public PlayerEvents(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @EventHandler
+ public void onJoin(PlayerJoinEvent e) {
+
+ CustomList list = new CustomList();
+
+ list.setMode(TeleportMode.DEFAULT);
+
+ clicktpa.getTpaPlayers().put(e.getPlayer(), list);
+
+ }
+
+ @EventHandler
+ public void onLeave(PlayerQuitEvent e) {
+
+ clicktpa.getTpaPlayers().remove(e.getPlayer());
+
+ }
+
+ @EventHandler
+ public void onMove(PlayerMoveEvent e) {
+ if (this.clicktpa.getConfig().getBoolean("Allow-player-to-move"))
+ return;
+ Player p = e.getPlayer();
+ if (!this.clicktpa.getGraceList().contains(p))
+ return;
+
+ if (this.clicktpa.getGraceList().contains(p)) {
+ if (e.getFrom().getBlockX() != e.getTo().getBlockX() || e.getFrom().getBlockZ() != e.getTo().getBlockZ()) {
+ this.clicktpa.getGraceList().remove(p);
+ clicktpa.getTpaPlayers().get(p).setMode(TeleportMode.DEFAULT);
+ }
+ }
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/events/TpaCountdownListener.java b/ClickTpa/src/main/java/com/jklmao/plugin/events/TpaCountdownListener.java
new file mode 100644
index 0000000..46c8ab1
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/events/TpaCountdownListener.java
@@ -0,0 +1,109 @@
+package com.jklmao.plugin.events;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.TeleportMode;
+import com.jklmao.plugin.utils.TeleportMsgs;
+import com.jklmao.plugin.utils.TeleportType;
+import com.jklmao.plugin.utils.TpaInfoList;
+
+public class TpaCountdownListener {
+
+ private final TeleportMsgs tpMsgs = new TeleportMsgs();
+ private BukkitTask cdTask;
+
+ public void tpaCountdown(ClickTpa plugin, int secs, TeleportType type, Player sender, Player target) {
+
+ switch (type) {
+ case TPA:
+ tpMsgs.currentlyTeleportingTitle(plugin, secs, target);
+ break;
+ case TPAHERE:
+ tpMsgs.currentlyTeleportingTitle(plugin, secs, sender);
+ break;
+ }
+
+ cdTask = Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
+ int time = secs * 2;
+
+ @Override
+ public void run() {
+
+ // if a player moves
+
+ if (time == 0) {
+ teleport(plugin, type, sender, target);
+ cdTask.cancel();
+ } else {
+ moveListener(plugin, type, sender, target);
+ }
+
+ time = time - 1;
+
+ }
+
+ }, 0, 10);
+
+ }
+
+ private void teleport(ClickTpa plugin, TeleportType type, Player sender, Player target) {
+ switch (type) {
+ case TPA:
+ target.teleport(sender);
+ tpMsgs.successfulTPATitle(plugin, target, sender);
+ plugin.getTpaPlayers().get(target).setMode(TeleportMode.DEFAULT);
+ break;
+ case TPAHERE:
+ sender.teleport(target);
+ tpMsgs.successfulTPATitle(plugin, sender, target);
+ plugin.getTpaPlayers().get(sender).setMode(TeleportMode.DEFAULT);
+ break;
+ }
+
+ removeTpaInfo(plugin, sender, target);
+
+ }
+
+ private void moveListener(ClickTpa plugin, TeleportType type, Player sender, Player target) {
+
+ switch (type) {
+ case TPA:
+
+ if (!plugin.getGraceList().contains(target)) {
+ cdTask.cancel();
+ tpMsgs.sendMoveBeforeTPATitle(plugin, sender, target);
+ removeTpaInfo(plugin, sender, target);
+ }
+
+ return;
+ case TPAHERE:
+
+ if (!plugin.getGraceList().contains(sender)) {
+ cdTask.cancel();
+ tpMsgs.sendMoveBeforeTPAHERETitle(plugin, sender, target);
+ removeTpaInfo(plugin, sender, target);
+
+ }
+
+ return;
+ }
+ }
+
+ private void removeTpaInfo(ClickTpa plugin, Player sender, Player target) {
+
+ for (TpaInfoList tpaInfo : plugin.getTpaPlayers().get(sender).getTpaList()) {
+
+ if (tpaInfo.getRequester() != target) {
+ continue;
+ } else {
+ plugin.getTpaPlayers().get(sender).getTpaList().remove(tpaInfo);
+ return;
+ }
+ }
+
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/Commons.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/Commons.java
new file mode 100644
index 0000000..ebd9af6
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/Commons.java
@@ -0,0 +1,11 @@
+package com.jklmao.plugin.utils;
+
+import net.md_5.bungee.api.ChatColor;
+
+public class Commons {
+
+ @SuppressWarnings("unused")
+ private static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/CustomList.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/CustomList.java
new file mode 100644
index 0000000..41baeea
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/CustomList.java
@@ -0,0 +1,23 @@
+package com.jklmao.plugin.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CustomList {
+
+ private TeleportMode mode;
+ private List tpaList = new ArrayList<>();
+
+ public TeleportMode getMode() {
+ return mode;
+ }
+
+ public void setMode(TeleportMode mode) {
+ this.mode = mode;
+ }
+
+ public List getTpaList() {
+ return tpaList;
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMode.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMode.java
new file mode 100644
index 0000000..7e28505
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMode.java
@@ -0,0 +1,7 @@
+package com.jklmao.plugin.utils;
+
+public enum TeleportMode {
+
+ DEFAULT, TELEPORTING, TPTOGGLE_ON
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMsgs.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMsgs.java
new file mode 100644
index 0000000..358b30d
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportMsgs.java
@@ -0,0 +1,118 @@
+package com.jklmao.plugin.utils;
+
+import java.util.List;
+
+import org.bukkit.entity.Player;
+
+import com.jklmao.plugin.ClickTpa;
+
+import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.chat.hover.content.Content;
+import net.md_5.bungee.api.chat.hover.content.Text;
+
+public class TeleportMsgs {
+
+ public TeleportMsgs() {
+ }
+
+ public void sendRequestMsg(ClickTpa clicktpa, TeleportType type, Player player, Player target) {
+
+ TextComponent eemptyspace = new TextComponent(" ");
+ TextComponent bemptyspace = new TextComponent(" ");
+
+ TextComponent accept = new TextComponent(colorize(clicktpa.getConfig().getString("Click-to-accept")));
+ Text acceptHoverText = new Text(colorize(clicktpa.getConfig().getString("Hover-message-on-accept")));
+ accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { acceptHoverText }));
+
+ TextComponent deny = new TextComponent(colorize(clicktpa.getConfig().getString("Click-to-deny")));
+ Text denyHoverText = new Text(colorize(clicktpa.getConfig().getString("Hover-message-on-deny")));
+ deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { denyHoverText }));
+
+ TextComponent requestsent = new TextComponent(
+ colorize(clicktpa.getConfig().getString("Player-sent-request").replaceAll("%target%", target.getName())));
+
+ List tpa = null;
+
+ switch (type) {
+ case TPA:
+ tpa = clicktpa.getConfig().getStringList("Tpa-message");
+ break;
+ case TPAHERE:
+ tpa = clicktpa.getConfig().getStringList("Tpahere-message");
+ break;
+ }
+
+ for (String m : tpa) {
+ target.sendMessage(
+ colorize(m).replaceAll("%player%", player.getName()).replaceAll("%accept%", accept.getText()).replaceAll("%deny%", deny.getText()));
+ }
+ accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept " + player.getName()));
+
+ deny.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpadeny " + player.getName()));
+
+ if (clicktpa.getConfig().getBoolean("Added-accept-deny-space")) {
+ target.spigot().sendMessage(new BaseComponent[] { bemptyspace, accept, eemptyspace, deny });
+ player.spigot().sendMessage(requestsent);
+ } else {
+ target.spigot().sendMessage(new BaseComponent[] { accept, deny });
+ player.spigot().sendMessage(requestsent);
+ }
+
+ }
+
+ public void successfulTPATitle(ClickTpa clicktpa, Player teleporter, Player waiter) {
+
+ String successMsg = clicktpa.getConfig().getString("On-screen-teleported");
+
+ if (clicktpa.getConfig().getBoolean("Send-on-screen-message")) {
+ teleporter.sendTitle(colorize(successMsg), "", 1, 20, 1);
+ }
+
+ teleporter.sendMessage(colorize(clicktpa.getConfig().getString("Target-currently-teleporting")));
+ waiter.sendMessage(colorize(clicktpa.getConfig().getString("Player-currently-teleporting")));
+
+ }
+
+ public void currentlyTeleportingTitle(ClickTpa clicktpa, int secs, Player teleporter) {
+
+ if (clicktpa.getConfig().getBoolean("Send-on-screen-message")) {
+
+ String mainTitle = clicktpa.getConfig().getStringList("On-screen-teleporting").get(0);
+ String subTitle = clicktpa.getConfig().getStringList("On-screen-teleporting").get(1);
+
+ teleporter.sendTitle(colorize(mainTitle), colorize(subTitle), 1, secs * 20, 1);
+
+ }
+ }
+
+ public void sendMoveBeforeTPAHERETitle(ClickTpa clicktpa, Player player, Player target) {
+
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Player-moved-before-tp").replaceAll("%player%", player.getName())));
+ player.sendMessage(colorize(clicktpa.getConfig().getString("Player-moved-before-tp").replaceAll("%player%", player.getName())));
+
+ if (clicktpa.getConfig().getBoolean("Send-on-screen-message")) {
+ String cancelMsg = clicktpa.getConfig().getString("On-screen-canceled-tp");
+ player.sendTitle(colorize(cancelMsg), "", 1, 30, 1);
+ }
+ }
+
+ public void sendMoveBeforeTPATitle(ClickTpa clicktpa, Player player, Player target) {
+
+ target.sendMessage(colorize(clicktpa.getConfig().getString("Player-moved-before-tp").replaceAll("%player%", target.getName())));
+ player.sendMessage(colorize(clicktpa.getConfig().getString("Player-moved-before-tp").replaceAll("%player%", target.getName())));
+
+ if (clicktpa.getConfig().getBoolean("Send-on-screen-message")) {
+ String cancelMsg = clicktpa.getConfig().getString("On-screen-canceled-tp");
+ target.sendTitle(colorize(cancelMsg), "", 1, 30, 1);
+ }
+ }
+
+ private String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportType.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportType.java
new file mode 100644
index 0000000..20d128c
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TeleportType.java
@@ -0,0 +1,7 @@
+package com.jklmao.plugin.utils;
+
+public enum TeleportType {
+
+ TPA, TPAHERE
+
+}
diff --git a/ClickTpa/src/main/java/com/jklmao/plugin/utils/TpaInfoList.java b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TpaInfoList.java
new file mode 100644
index 0000000..49eceba
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/TpaInfoList.java
@@ -0,0 +1,22 @@
+package com.jklmao.plugin.utils;
+
+import org.bukkit.entity.Player;
+
+public class TpaInfoList {
+
+ private TeleportType type;
+ private Player target;
+
+ public TpaInfoList(TeleportType t, Player p) {
+ type = t;
+ target = p;
+ }
+
+ public Player getRequester() {
+ return target;
+ }
+
+ public TeleportType getType() {
+ return type;
+ }
+}
diff --git a/ClickTpa/src/main/java/config.yml b/ClickTpa/src/main/java/config.yml
new file mode 100644
index 0000000..fa2eeec
--- /dev/null
+++ b/ClickTpa/src/main/java/config.yml
@@ -0,0 +1,162 @@
+# Config for ClickTpa
+# Version v1.7
+# Author: jklmao
+
+# # # # # # # # # # # # # # # # # # # # # # # # #
+# #
+# ClickTpa Config #
+# #
+# # # # # # # # # # # # # # # # # # # # # # # # #
+
+# Be aware of all warnings! #
+
+# # # # # # # # # # # # # # # # # # # # # # # # #
+# #
+# Place Holders #
+# #
+# # # # # # # # # # # # # # # # # # # # # # # # #
+
+# Use '%player%' for the player who sent the request.
+# Use '%accept%' for the 'Click-to-accept' message.
+# Use '%deny%' for the 'Click-to-deny' message.
+# Use '%target%' for the player who they wanted to teleport to, and for the 'Player-sent-request' message.
+# Example: /tpa , where is '%target%'.
+
+Player-only-command: '&cOnly players can use this command!'
+
+Insufficient-permission: '&cYou do not have sufficient permission!'
+
+Player-deny-tpa-message: '&cTeleportation request has been denied.'
+
+Target-deny-tpa-message: '&cTeleportation request has been denied.'
+
+Target-teleportion-canceled: '&cTeleportation canceled...'
+
+Player-got-accepted-tpa: '&bTeleportation request has been accepted.'
+
+Countdown-until-tpa: '&eTeleporting in 3 seconds...'
+
+Player-no-pendingtpa-message: '&cYou do not have a pending request!'
+
+Target-accepted-tpa-request: '&eRequest for teleportation is accepted.'
+
+Target-is-offline: '&cThis player is offline!'
+
+No-player-found: '&cThis player does not exist!'
+
+Player-teleporting-self: '&cYou can not teleport yourself!'
+
+Player-already-requested: '&cYou already requested, please wait..'
+
+Player-teleportation-request-expire: '&cTeleportation request has expired.'
+
+Target-teleportation-request-expire: '&cTeleportation request has expired.'
+
+Player-currently-teleporting: '&bTeleporting...'
+
+Target-currently-teleporting: '&eTeleporting...'
+
+Player-TpToggle-Off: '&eTeleportation &6OFF'
+
+Player-TpToggle-On: '&eTeleportation &6ON'
+
+Target-Is-TpToggled: '&6%target% &ehas teleportation off'
+
+Player-Is-TpToggled: '&cYou are tptoggled!'
+
+TpToggle-While-Teleporting: '&cCannot TpToggle while teleporting!'
+
+Tpacancel-message: '&6Tpa request has been canceled.'
+
+# TPA request expires in seconds
+Request-expire-time: 120
+
+
+# Seconds until tpa
+# Please use whole numbers
+
+Seconds-until-tpa: 3
+
+# Becareful in this part!
+# This is when a player uses not enough args
+# For example, when a player does '/tpa', it will say 'Usage: /tpa '
+# So please fit the correct command under the correct message!
+# P.S '/tpohere' is also '/s' (essentials-type command).
+
+Tpa-usage: '&cUse: /tpa '
+
+Tpahere-usage: '&cUse: /tpahere '
+
+Tpaccept-usage: '&cUse: /tpaccept '
+
+Tpdeny-usage: '&cUse: /tpadeny '
+
+Tpo-usage: '&cUse: /tpo '
+
+Tpohere-usage: '&cUse: /tpohere or /s '
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # #
+# #
+# Please Read! #
+# #
+# # # # # # # # # # # # # # # # # # # # # # # # #
+
+# This section is when a player gets a tpa request
+# Since the code used is broken into many parts, there will be many messages.
+# Whatever you do to the "Click-to-x" messages, will be the same in the 'Tpa-message'
+# Be careful!
+
+
+# Lets you choose if you want players to be able
+# to move before being teleported
+Allow-player-to-move: false
+
+Player-moved-before-tp: '&6The request was canceled because %player% moved!'
+
+Player-sent-request: '&eYou have sent a request to &6%target%'
+
+Tpa-message:
+ - ''
+ - '&6%player% &ehas requested to teleport to you.'
+ - '&eClick %accept% &eto accept or click %deny% &eto deny.'
+ - '&eThe request expires in 120 seconds.'
+ - ''
+
+Tpahere-message:
+ - ''
+ - '&6%player% &ehas requested to teleport you to them.'
+ - '&eClick %accept% &eto accept or click %deny% &eto deny.'
+ - '&eThe request expires in 120 seconds.'
+ - ''
+
+# This will put additional spaces for the accept/deny messages
+Added-accept-deny-space: true
+
+Click-to-accept: '&a&l&n[ACCEPT]&r'
+Click-to-deny: '&c&l&n[DENY]&r'
+
+Hover-message-on-accept: '&aClick to accept'
+Hover-message-on-deny: '&cClick to deny'
+
+#
+# On-Screen Messages
+# It pops up in the middle of the player's screen
+#
+
+Send-on-screen-message: true
+
+# When a player accepts a tp
+On-screen-teleporting:
+ - '&6Teleporting...'
+ - '&eDo not move!'
+
+# When a player has successfully tp'd.
+On-screen-teleported: '&aTeleported!'
+
+# If a player moves while they are being tp'd
+On-screen-canceled-tp: '&cCanceled TP!'
+
+#~~~~~~~~~~~~~~~~~~#
+# More Coming Soon!#
+#~~~~~~~~~~~~~~~~~~#
diff --git a/ClickTpa/src/main/java/plugin.yml b/ClickTpa/src/main/java/plugin.yml
new file mode 100644
index 0000000..7301840
--- /dev/null
+++ b/ClickTpa/src/main/java/plugin.yml
@@ -0,0 +1,32 @@
+name: ClickTpa
+version: 1.6.4
+main: com.jklmao.plugin.ClickTpa
+authors: [ jklmao ]
+description: Simple TPA plugin for Spigot/Paper Software
+
+commands:
+ tpa:
+ usage: /
+ aliases: [teleport]
+ tpahere:
+ usage: /
+ tpaccept:
+ usage: /
+ aliases: [tpyes]
+ tpadeny:
+ usage: /
+ aliases: [tpdeny, tpno]
+ tpo:
+ usage: /
+ alises: [tp]
+ tpohere:
+ usage: /
+ aliases: [s, tphere]
+ tptoggle:
+ usage: /
+ tpacancel:
+ usage: /
+ aliases: [tpcancel]
+ clicktparl:
+ usage: /
+ aliases: [ctparl]