mirror of
https://github.com/darksaid98/AlathranCommands.git
synced 2026-12-01 15:38:52 +00:00
ClickTpa Redo
This commit is contained in:
commit
39271b24e1
19 files changed
+1090
No files matched your search
@@ -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<Player, Player> tpacommandlist = new HashMap<>();
|
||||
|
||||
private HashMap<Player, Player> tpaherecommandlist = new HashMap<>();
|
||||
|
||||
private HashMap<String, String> tpacancel = new HashMap<>();
|
||||
|
||||
private ArrayList<Player> tptoggled = new ArrayList<>();
|
||||
|
||||
private ArrayList<Player> willTeleport = new ArrayList<>();
|
||||
|
||||
private ArrayList<Player> whosFault = new ArrayList<>();
|
||||
|
||||
private ArrayList<Player> graceList = new ArrayList<>();
|
||||
|
||||
private HashMap<Player, CustomList> 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<Player, Player> getHash() {
|
||||
return this.tpacommandlist;
|
||||
}
|
||||
|
||||
public HashMap<Player, Player> getTpaHere() {
|
||||
return this.tpaherecommandlist;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getTpaCancel() {
|
||||
return this.tpacancel;
|
||||
}
|
||||
|
||||
public ArrayList<Player> getTpToggled() {
|
||||
return this.tptoggled;
|
||||
}
|
||||
|
||||
public ArrayList<Player> getTeleportStatus() {
|
||||
return this.willTeleport;
|
||||
}
|
||||
|
||||
public ArrayList<Player> getWhosFault() {
|
||||
return this.whosFault;
|
||||
}
|
||||
|
||||
public ArrayList<Player> getGraceList() {
|
||||
return this.graceList;
|
||||
}
|
||||
|
||||
public HashMap<Player, CustomList> 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));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user