commit 39271b24e1dcc4b04379a4853a3af263ec612fa0
Author: jklmao <22cfranco@gmail.com>
Date: Wed Nov 23 05:14:03 2022 +0100
ClickTpa Redo
diff --git a/ClickTpa/.classpath b/ClickTpa/.classpath
new file mode 100644
index 0000000..5869b87
--- /dev/null
+++ b/ClickTpa/.classpath
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ClickTpa/.gitignore b/ClickTpa/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/ClickTpa/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/ClickTpa/.project b/ClickTpa/.project
new file mode 100644
index 0000000..91569b6
--- /dev/null
+++ b/ClickTpa/.project
@@ -0,0 +1,23 @@
+
+
+ ClickTpa
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/ClickTpa/.settings/org.eclipse.jdt.core.prefs b/ClickTpa/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..cac0df4
--- /dev/null
+++ b/ClickTpa/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/ClickTpa/.settings/org.eclipse.m2e.core.prefs b/ClickTpa/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/ClickTpa/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/ClickTpa/pom.xml b/ClickTpa/pom.xml
new file mode 100644
index 0000000..057fb64
--- /dev/null
+++ b/ClickTpa/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ com.jklmao.plugin
+ ClickTpa
+ 1.6.2v
+ 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.2-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..42fe8e6
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/ClickTpa.java
@@ -0,0 +1,99 @@
+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;
+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.CommandTpo;
+import com.jklmao.plugin.commands.CommandTpoHere;
+import com.jklmao.plugin.commands.Commands;
+import com.jklmao.plugin.events.PlayerEvents;
+import com.jklmao.plugin.utils.CustomList;
+
+public final class ClickTpa extends JavaPlugin {
+ public static ClickTpa instance;
+
+ private HashMap tpacommandlist = new HashMap<>();
+
+ private HashMap tpaherecommandlist = new HashMap<>();
+
+ private HashMap tpacancel = new HashMap<>();
+
+ private ArrayList tptoggled = new ArrayList<>();
+
+ private ArrayList willTeleport = new ArrayList<>();
+
+ private ArrayList whosFault = new ArrayList<>();
+
+ private ArrayList graceList = new ArrayList<>();
+
+ private HashMap tpaInfo = new HashMap<>();
+
+ @Override
+ public void onEnable() {
+ commandHandler();
+ instance = this;
+ saveDefaultConfig();
+ getLogger().info("ClickTPA has been loaded Successfully!");
+ getServer().getPluginManager().registerEvents((Listener) new PlayerEvents(this), (Plugin) this);
+ }
+
+ public HashMap getHash() {
+ return this.tpacommandlist;
+ }
+
+ public HashMap getTpaHere() {
+ return this.tpaherecommandlist;
+ }
+
+ public HashMap getTpaCancel() {
+ return this.tpacancel;
+ }
+
+ public ArrayList getTpToggled() {
+ return this.tptoggled;
+ }
+
+ public ArrayList getTeleportStatus() {
+ return this.willTeleport;
+ }
+
+ public ArrayList getWhosFault() {
+ return this.whosFault;
+ }
+
+ public ArrayList getGraceList() {
+ return this.graceList;
+ }
+
+ public HashMap getTpaInfo() {
+ return this.tpaInfo;
+ }
+
+ public void reloadTheConfig() {
+ reloadConfig();
+ }
+
+ 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));
+ }
+}
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..17479e8
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpCancel.java
@@ -0,0 +1,71 @@
+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;
+
+public class CommandTpCancel implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ Player p = null;
+ if (sender instanceof Player) {
+ p = (Player) sender;
+ if (p != null) {
+ if (!p.hasPermission("clicktpa.tpacancel")) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ }
+ if (this.clicktpa.getTpaCancel().containsKey(p.getName())) {
+ Player poorRejectedGuy = Bukkit.getServer()
+ .getPlayer((String) this.clicktpa.getTpaCancel().get(p.getName()));
+ clearLists(p, poorRejectedGuy);
+ if (poorRejectedGuy != null) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpacancel-message")));
+ poorRejectedGuy.sendMessage(colorize(this.clicktpa.getConfig().getString("Tpacancel-message")));
+ return true;
+ }
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ } else if (!this.clicktpa.getTpaCancel().containsKey(p.getName())) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+ }
+ return true;
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public String returnStatementPlayer(String configMessages, Player player) {
+ return this.clicktpa.getConfig().getString(configMessages).replaceAll("%player%", player.getName());
+ }
+
+ public String returnStatementTarget(String configMessages, Player target) {
+ return this.clicktpa.getConfig().getString(configMessages).replaceAll("%target%", target.getName());
+ }
+
+ private void clearLists(Player player, Player target) {
+ this.clicktpa.getHash().remove(player);
+ this.clicktpa.getHash().remove(target);
+ this.clicktpa.getTpaHere().remove(player);
+ this.clicktpa.getTpaHere().remove(target);
+ this.clicktpa.getTeleportStatus().remove(player);
+ this.clicktpa.getTeleportStatus().remove(target);
+ this.clicktpa.getTpaCancel().remove(player.getName());
+ this.clicktpa.getTpaCancel().remove(target.getName());
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpCancel(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
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..6a42f35
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpToggle.java
@@ -0,0 +1,48 @@
+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 net.md_5.bungee.api.ChatColor;
+
+public class CommandTpToggle implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ 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")) {
+ if (!this.clicktpa.getTpToggled().contains(p)) {
+ this.clicktpa.getTpToggled().add(p);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-TpToggle-Off")));
+ return true;
+ }
+ if (this.clicktpa.getTpToggled().contains(p)) {
+ this.clicktpa.getTpToggled().remove(p);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-TpToggle-On")));
+ return true;
+ }
+ return true;
+ }
+ 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..6488b17
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpa.java
@@ -0,0 +1,134 @@
+package com.jklmao.plugin.commands;
+
+import java.util.List;
+
+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.BukkitRunnable;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.CustomList;
+
+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 CommandTpa implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ @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 (target != null) {
+ if (this.clicktpa.getTpToggled().contains(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-Is-TpToggled")));
+ return true;
+ }
+ if (this.clicktpa.getTpToggled().contains(target)) {
+ p.sendMessage(colorize(
+ this.clicktpa.getConfig().getString("Target-Is-TpToggled").replaceAll("%target%", target.getName())));
+ return true;
+ }
+ if (this.clicktpa.getHash().containsKey(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-already-requested")));
+ return true;
+ }
+ if (!this.clicktpa.getTpToggled().contains(target)) {
+ this.clicktpa.getHash().put(p, p);
+ this.clicktpa.getHash().put(target, target);
+ this.clicktpa.getTeleportStatus().add(p);
+ CustomList info = new CustomList();
+ info.setTarget(target);
+ info.setType(0);
+ this.clicktpa.getTpaInfo().put(p, info);
+ addThemToList(target, p);
+ TextComponent eemptyspace = new TextComponent(" ");
+ TextComponent bemptyspace = new TextComponent(" ");
+
+ TextComponent accept = new TextComponent(colorize(this.clicktpa.getConfig().getString("Click-to-accept")));
+ Text acceptHoverText = new Text(colorize(this.clicktpa.getConfig().getString("Hover-message-on-accept")));
+ accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { acceptHoverText }));
+
+ TextComponent deny = new TextComponent(colorize(this.clicktpa.getConfig().getString("Click-to-deny")));
+ Text denyHoverText = new Text(colorize(this.clicktpa.getConfig().getString("Hover-message-on-deny")));
+ deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { denyHoverText }));
+
+ TextComponent requestsent = new TextComponent(colorize(
+ this.clicktpa.getConfig().getString("Player-sent-request").replaceAll("%target%", target.getName())));
+
+ List tpa = this.clicktpa.getConfig().getStringList("Tpa-message");
+ for (String m : tpa) {
+ target.sendMessage(colorize(m).replaceAll("%player%", p.getName())
+ .replaceAll("%accept%", accept.getText()).replaceAll("%deny%", deny.getText()));
+ }
+ accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept " + p.getName()));
+ deny.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpadeny " + p.getName()));
+
+ if (this.clicktpa.getConfig().getBoolean("Added-accept-deny-space")) {
+ target.spigot().sendMessage(new BaseComponent[] { bemptyspace, accept, eemptyspace, deny });
+ p.spigot().sendMessage(requestsent);
+ } else {
+ target.spigot().sendMessage(new BaseComponent[] { accept, deny });
+ p.spigot().sendMessage(requestsent);
+ }
+ }
+ (new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (CommandTpa.this.clicktpa.getHash().containsKey(p)
+ && CommandTpa.this.clicktpa.getHash().containsKey(target)) {
+ CommandTpa.this.clicktpa.getHash().remove(p);
+ CommandTpa.this.clicktpa.getHash().remove(target);
+ p.sendMessage(CommandTpa.this
+ .colorize(CommandTpa.this.clicktpa.getConfig().getString("Player-teleportation-request-expire")));
+ target.sendMessage(CommandTpa.this
+ .colorize(CommandTpa.this.clicktpa.getConfig().getString("Target-teleportation-request-expire")));
+ }
+ }
+ }).runTaskLaterAsynchronously(ClickTpa.instance, 2400L);
+ }
+ return true;
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ public void addThemToList(Player sender, Player recipient) {
+ String senderName = sender.getName();
+ String recipientName = recipient.getName();
+ this.clicktpa.getTpaCancel().put(recipientName, senderName);
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpa(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
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..4fcfc72
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaDeny.java
@@ -0,0 +1,85 @@
+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;
+
+public class CommandTpaDeny implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ String targetsname = new String();
+
+ 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;
+ }
+ Player target = Bukkit.getPlayer(args[0]);
+ if (target != null) {
+ if (target.isOnline()) {
+ if (this.clicktpa.getHash().containsKey(target) || this.clicktpa.getTpaHere().containsKey(target)) {
+ clearLists(p, target);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-deny-tpa-message")));
+ target.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-deny-tpa-message")));
+ return true;
+ }
+ if (!this.clicktpa.getHash().containsKey(p) || !this.clicktpa.getTpaHere().containsKey(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+ } else {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-is-offline")));
+ clearLists(p, target);
+ return true;
+ }
+ } else {
+ if (!this.clicktpa.getHash().containsKey(target) || !this.clicktpa.getTpaHere().containsKey(target)) {
+ clearLists(p, target);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Target-is-offline")));
+ return true;
+ }
+ if (this.clicktpa.getHash().containsKey(target) || this.clicktpa.getTpaHere().containsKey(target)) {
+ clearLists(p, target);
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+ }
+ return true;
+ }
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+
+ private void clearLists(Player player, Player target) {
+ this.clicktpa.getHash().remove(player);
+ this.clicktpa.getHash().remove(target);
+ this.clicktpa.getTpaHere().remove(player);
+ this.clicktpa.getTpaHere().remove(target);
+ this.clicktpa.getTeleportStatus().remove(player);
+ this.clicktpa.getTeleportStatus().remove(target);
+ this.clicktpa.getTpaCancel().remove(player.getName());
+ this.clicktpa.getTpaCancel().remove(target.getName());
+ this.clicktpa.getGraceList().remove(player);
+ this.clicktpa.getGraceList().remove(target);
+ this.clicktpa.getTpaInfo().remove(target);
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpaDeny(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
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..bd77c91
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/CommandTpaHere.java
@@ -0,0 +1,133 @@
+package com.jklmao.plugin.commands;
+
+import java.util.List;
+
+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.BukkitRunnable;
+
+import com.jklmao.plugin.ClickTpa;
+import com.jklmao.plugin.utils.CustomList;
+
+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 CommandTpaHere implements CommandExecutor {
+ private ClickTpa clicktpa;
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, 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 (this.clicktpa.getTpToggled().contains(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-Is-TpToggled")));
+ return true;
+ }
+ if (this.clicktpa.getTpaHere().containsKey(p)) {
+ p.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-already-requested")));
+ return true;
+ }
+ if (this.clicktpa.getTpToggled().contains(target)) {
+ p.sendMessage(colorize(
+ this.clicktpa.getConfig().getString("Target-Is-TpToggled").replaceAll("%target%", target.getName())));
+ return true;
+ }
+ if (!this.clicktpa.getTpToggled().contains(target)) {
+ this.clicktpa.getTpaHere().put(p, p);
+ this.clicktpa.getTpaHere().put(target, target);
+ this.clicktpa.getTeleportStatus().add(target);
+ addThemToList(target, p);
+ CustomList info = new CustomList();
+ info.setTarget(target);
+ info.setType(1);
+ this.clicktpa.getTpaInfo().put(p, info);
+ TextComponent eemptyspace = new TextComponent(" ");
+ TextComponent bemptyspace = new TextComponent(" ");
+
+ TextComponent accept = new TextComponent(colorize(this.clicktpa.getConfig().getString("Click-to-accept")));
+ Text acceptHoverText = new Text(colorize(this.clicktpa.getConfig().getString("Hover-message-on-accept")));
+ accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { acceptHoverText }));
+
+ TextComponent deny = new TextComponent(colorize(this.clicktpa.getConfig().getString("Click-to-deny")));
+ Text denyHoverText = new Text(colorize(this.clicktpa.getConfig().getString("Hover-message-on-deny")));
+ deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Content[] { denyHoverText }));
+
+ TextComponent requestsent = new TextComponent(colorize(
+ this.clicktpa.getConfig().getString("Player-sent-request").replaceAll("%target%", target.getName())));
+ List tpa = this.clicktpa.getConfig().getStringList("Tpahere-message");
+
+ for (String m : tpa) {
+ target.sendMessage(colorize(m).replaceAll("%player%", p.getName()).replaceAll("%accept%", accept.getText())
+ .replaceAll("%deny%", deny.getText()));
+ }
+
+ accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept " + p.getName()));
+ deny.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpadeny " + p.getName()));
+
+ if (this.clicktpa.getConfig().getBoolean("Added-accept-deny-space")) {
+ target.spigot().sendMessage(new BaseComponent[] { bemptyspace, accept, eemptyspace, deny });
+ p.spigot().sendMessage(requestsent);
+ } else {
+ target.spigot().sendMessage(new BaseComponent[] { accept, deny });
+ p.spigot().sendMessage(requestsent);
+ }
+ }
+ (new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (CommandTpaHere.this.clicktpa.getTpaHere().containsKey(p)
+ && CommandTpaHere.this.clicktpa.getTpaHere().containsKey(target)) {
+ CommandTpaHere.this.clicktpa.getTpaHere().clear();
+ p.sendMessage(CommandTpaHere
+ .colorize(CommandTpaHere.this.clicktpa.getConfig().getString("Player-teleportation-request-expire")));
+ target.sendMessage(CommandTpaHere
+ .colorize(CommandTpaHere.this.clicktpa.getConfig().getString("Target-teleportation-request-expire")));
+ }
+ }
+ }).runTaskLaterAsynchronously(ClickTpa.instance, 2400L);
+ } else {
+ sender.sendMessage(colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ }
+ return true;
+ }
+
+ public void addThemToList(Player sender, Player recipient) {
+ String senderName = sender.getName();
+ String recipientName = recipient.getName();
+ this.clicktpa.getTpaCancel().put(recipientName, senderName);
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public CommandTpaHere(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
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/commands/Commands.java b/ClickTpa/src/main/java/com/jklmao/plugin/commands/Commands.java
new file mode 100644
index 0000000..43aef0f
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/commands/Commands.java
@@ -0,0 +1,173 @@
+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 net.md_5.bungee.api.ChatColor;
+
+public class Commands implements CommandExecutor {
+ private int seconds;
+ private int countdown;
+ private ClickTpa clicktpa;
+ ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ this.seconds = this.clicktpa.getConfig().getInt("Seconds-until-tpa");
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Player-only-command")));
+ return true;
+ } else {
+ Player p = (Player) sender;
+ if (!p.hasPermission("clicktpa.tpaccept")) {
+ p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Insufficient-permission")));
+ return true;
+ } else if (args.length == 0) {
+ p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Tpaccept-usage")));
+ return true;
+ } else {
+ Player target = Bukkit.getPlayer(args[0]);
+ if (args.length >= 1) {
+ if (target != null) {
+ if (!target.isOnline()) {
+ p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Target-is-offline")));
+ this.clearLists(p, target);
+ return true;
+ }
+
+ 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")));
+ 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")));
+ if (this.clicktpa.getHash().containsKey(target)) {
+ target.sendMessage(
+ this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa")));
+ } else {
+ p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Countdown-until-tpa")));
+ }
+
+ this.clicktpa.getHash().remove(p);
+ this.clicktpa.getHash().remove(target);
+ this.clicktpa.getTpaHere().remove(p);
+ this.clicktpa.getTpaHere().remove(target);
+ this.clicktpa.getTpaCancel().remove(p.getName());
+ this.clicktpa.getTpaCancel().remove(target.getName());
+ if (this.clicktpa.getTpaInfo().get(target).getType() == 0) {
+ this.clicktpa.getGraceList().add(target);
+ }
+
+ if (this.clicktpa.getTpaInfo().get(target).getType() == 1) {
+ this.clicktpa.getGraceList().add(p);
+ }
+
+ 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);
+ }
+
+ 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;
+ }
+ } 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);
+ }
+ }
+
+ }, 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)) {
+ return true;
+ }
+
+ this.clearLists(p, target);
+ p.sendMessage(
+ this.colorize(this.clicktpa.getConfig().getString("Player-no-pendingtpa-message")));
+ return true;
+ }
+
+ this.clearLists(p, target);
+ p.sendMessage(this.colorize(this.clicktpa.getConfig().getString("Target-is-offline")));
+ return true;
+ }
+ }
+
+ return true;
+ }
+ }
+ }
+
+ private void clearLists(Player player, Player target) {
+ this.clicktpa.getHash().remove(player);
+ this.clicktpa.getHash().remove(target);
+ this.clicktpa.getTpaHere().remove(player);
+ this.clicktpa.getTpaHere().remove(target);
+ this.clicktpa.getTeleportStatus().remove(player);
+ this.clicktpa.getTeleportStatus().remove(target);
+ this.clicktpa.getTpaCancel().remove(player.getName());
+ this.clicktpa.getTpaCancel().remove(target.getName());
+ }
+
+ public String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+
+ public Commands(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+}
\ No newline at end of file
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..72f5d11
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/events/PlayerEvents.java
@@ -0,0 +1,39 @@
+package com.jklmao.plugin.events;
+
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+import com.jklmao.plugin.ClickTpa;
+
+public class PlayerEvents implements Listener {
+ private ClickTpa clicktpa;
+
+ public PlayerEvents(ClickTpa pl) {
+ this.clicktpa = pl;
+ }
+
+ @EventHandler
+ public void onWalk(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().getX() != e.getTo().getX() || e.getFrom().getZ() != e.getTo().getZ()) {
+ this.clicktpa.getTeleportStatus().remove(p);
+ this.clicktpa.getWhosFault().add(p);
+ this.clicktpa.getGraceList().remove(p);
+ }
+ } else {
+ return;
+ }
+ }
+
+ public static String colorize(String message) {
+ return ChatColor.translateAlternateColorCodes('&', message);
+ }
+}
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..67ca330
--- /dev/null
+++ b/ClickTpa/src/main/java/com/jklmao/plugin/utils/CustomList.java
@@ -0,0 +1,25 @@
+package com.jklmao.plugin.utils;
+
+import org.bukkit.entity.Player;
+
+public class CustomList {
+ private Player target;
+
+ private int type;
+
+ public void setTarget(Player t) {
+ this.target = t;
+ }
+
+ public Player getTarget() {
+ return this.target;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getType() {
+ return this.type;
+ }
+}