mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Re implement tab completion list (Close #47)
This commit is contained in:
1 parent
1601ce6949
commit
4cc19cb71b
14 files changed
+123
-47
No files matched your search
@@ -114,6 +114,12 @@
|
|||||||
<version>3.0.1</version>
|
<version>3.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.BlueMap-Minecraft</groupId>
|
||||||
|
<artifactId>BlueMapAPI</artifactId>
|
||||||
|
<version>v1.5.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.MilkBowl</groupId>
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
<artifactId>VaultAPI</artifactId>
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import me.william278.huskhomes2.integrations.VaultIntegration;
|
|||||||
import me.william278.huskhomes2.listeners.PlayerListener;
|
import me.william278.huskhomes2.listeners.PlayerListener;
|
||||||
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
||||||
import me.william278.huskhomes2.teleport.SettingHandler;
|
import me.william278.huskhomes2.teleport.SettingHandler;
|
||||||
|
import me.william278.huskhomes2.util.PlayerList;
|
||||||
import org.bstats.bukkit.MetricsLite;
|
import org.bstats.bukkit.MetricsLite;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -71,6 +72,10 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Player list managing
|
||||||
|
private static PlayerList playerList;
|
||||||
|
public static PlayerList getPlayerList() { return playerList; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HuskHomes API
|
* Returns the HuskHomes API
|
||||||
@@ -163,12 +168,8 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
// Fetch config file
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
// Plugin startup logic
|
|
||||||
getLogger().info("Enabling HuskHomes version " + this.getDescription().getVersion());
|
|
||||||
|
|
||||||
// Load the config
|
|
||||||
settings.reload();
|
settings.reload();
|
||||||
|
|
||||||
// Load the messages (in the right language)
|
// Load the messages (in the right language)
|
||||||
@@ -213,11 +214,21 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
|
|
||||||
// bStats initialisation
|
// bStats initialisation
|
||||||
new MetricsLite(this, 8430);
|
new MetricsLite(this, 8430);
|
||||||
|
|
||||||
|
// Setup player list
|
||||||
|
playerList = new PlayerList();
|
||||||
|
playerList.initialize();
|
||||||
|
|
||||||
|
// Log a message
|
||||||
|
getLogger().info("Enabled HuskHomes version " + this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
// Cancel remaining tasks
|
||||||
|
Bukkit.getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
|
// Log a message
|
||||||
getLogger().info("Disabled HuskHomes version " + this.getDescription().getVersion());
|
getLogger().info("Disabled HuskHomes version " + this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,14 +95,7 @@ public class TpCommand extends CommandBase {
|
|||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
List<String> players = new ArrayList<>();
|
List<String> players = new ArrayList<>();
|
||||||
if (args.length == 0 || args.length == 1) {
|
if (args.length == 0 || args.length == 1) {
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
players.addAll(HuskHomes.getPlayerList().getPlayers());
|
||||||
if (!VanishChecker.isVanished(p) && !(p.getName().equals(sender.getName()))) {
|
|
||||||
players.add(p.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (HuskHomes.getSettings().doBungee() & HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
|
||||||
//players.addAll(CrossServerListHandler.getOtherServerPlayerList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
players.remove(sender.getName());
|
players.remove(sender.getName());
|
||||||
final List<String> tabCompletions = new ArrayList<>();
|
final List<String> tabCompletions = new ArrayList<>();
|
||||||
|
|||||||
@@ -107,13 +107,17 @@ public class PluginMessage {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll(Player sender) {
|
public void sendToServer(Player sender) {
|
||||||
|
sendToServer(sender, "ALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToServer(Player sender, String server) {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
// Send a plugin message to all players
|
// Send a plugin message to the specified player name
|
||||||
out.writeUTF("Forward");
|
out.writeUTF("Forward");
|
||||||
out.writeUTF("ALL");
|
out.writeUTF(server);
|
||||||
|
|
||||||
// Send the HuskHomes message with a specific type
|
// Send the HuskHomes message with a specific type
|
||||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||||
@@ -124,7 +128,7 @@ public class PluginMessage {
|
|||||||
try {
|
try {
|
||||||
messageOut.writeUTF(messageData);
|
messageOut.writeUTF(messageData);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
plugin.getLogger().warning("An error occurred trying to send a plugin message to a server (" + e.getCause() + ")");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ public enum PluginMessageType {
|
|||||||
TPA_REQUEST_REPLY,
|
TPA_REQUEST_REPLY,
|
||||||
TPAHERE_REQUEST_REPLY,
|
TPAHERE_REQUEST_REPLY,
|
||||||
TELEPORT_TO_ME,
|
TELEPORT_TO_ME,
|
||||||
GET_ONLINE_PLAYERS,
|
GET_PLAYER_LIST,
|
||||||
RETURN_ONLINE_PLAYERS,
|
RETURN_PLAYER_LIST
|
||||||
PLAYER_CHANGE
|
|
||||||
}
|
}
|
||||||
@@ -82,5 +82,12 @@ public class PlayerListener implements Listener {
|
|||||||
});
|
});
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
} // Ignore NullPointerExceptions from players that execute this event and return null (e.g Citizens).
|
} // Ignore NullPointerExceptions from players that execute this event and return null (e.g Citizens).
|
||||||
|
|
||||||
|
// Update the player list
|
||||||
|
if (Bukkit.getOnlinePlayers().size() == 1) {
|
||||||
|
HuskHomes.getPlayerList().updateList(p);
|
||||||
|
} else {
|
||||||
|
HuskHomes.getPlayerList().addPlayer(p.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,13 +93,24 @@ public class PluginMessageListener implements org.bukkit.plugin.messaging.Plugin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
case GET_ONLINE_PLAYERS:
|
case GET_PLAYER_LIST:
|
||||||
/*if (Bukkit.getOnlinePlayers().size() > 0) {
|
final String requestingServer = pluginMessage.getMessageData();
|
||||||
returnPlayerList(messageData, recipient);
|
StringBuilder playerList = new StringBuilder();
|
||||||
}*/
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
playerList.append(p.getName());
|
||||||
|
playerList.append("£");
|
||||||
|
}
|
||||||
|
if (playerList.toString().equals("")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new PluginMessage(PluginMessageType.RETURN_PLAYER_LIST, playerList.substring(0, playerList.length()-1)).sendToServer(recipient, requestingServer);
|
||||||
|
return;
|
||||||
|
case RETURN_PLAYER_LIST:
|
||||||
|
final String[] returningPlayers = pluginMessage.getMessageData().split("£");
|
||||||
|
HuskHomes.getPlayerList().addPlayers(returningPlayers);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
HuskHomes.getInstance().getLogger().log(Level.WARNING, "Received a HuskHomes plugin message with an unrecognised type. Is your version of HuskTowns up to date?");
|
HuskHomes.getInstance().getLogger().log(Level.WARNING, "Received a HuskHomes plugin message with an unrecognised type. Is your version of HuskHomes up to date?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import me.william278.huskhomes2.commands.HomeCommand;
|
|||||||
import me.william278.huskhomes2.commands.PublicHomeCommand;
|
import me.william278.huskhomes2.commands.PublicHomeCommand;
|
||||||
import me.william278.huskhomes2.commands.WarpCommand;
|
import me.william278.huskhomes2.commands.WarpCommand;
|
||||||
import me.william278.huskhomes2.data.DataManager;
|
import me.william278.huskhomes2.data.DataManager;
|
||||||
import me.william278.huskhomes2.integrations.Map.DynMap;
|
|
||||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||||
import me.william278.huskhomes2.teleport.points.Home;
|
import me.william278.huskhomes2.teleport.points.Home;
|
||||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||||
|
|||||||
@@ -115,9 +115,9 @@ public class TeleportManager {
|
|||||||
public static void queueRandomTeleport(Player player, Connection connection) throws SQLException {
|
public static void queueRandomTeleport(Player player, Connection connection) throws SQLException {
|
||||||
if (!player.hasPermission("huskhomes.rtp.bypass_cooldown")) {
|
if (!player.hasPermission("huskhomes.rtp.bypass_cooldown")) {
|
||||||
long currentTime = Instant.now().getEpochSecond();
|
long currentTime = Instant.now().getEpochSecond();
|
||||||
long cooldownTime = DataManager.getPlayerRtpCooldown(player, connection);
|
long coolDownTime = DataManager.getPlayerRtpCooldown(player, connection);
|
||||||
if (currentTime < cooldownTime) {
|
if (currentTime < coolDownTime) {
|
||||||
long timeRemaining = cooldownTime - currentTime;
|
long timeRemaining = coolDownTime - currentTime;
|
||||||
long timeRemainingMinutes = timeRemaining / 60;
|
long timeRemainingMinutes = timeRemaining / 60;
|
||||||
MessageManager.sendMessage(player, "error_rtp_cooldown", Long.toString(timeRemainingMinutes));
|
MessageManager.sendMessage(player, "error_rtp_cooldown", Long.toString(timeRemainingMinutes));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class TimedTeleport {
|
|||||||
private final Location initialLocation;
|
private final Location initialLocation;
|
||||||
private final double initialHealth;
|
private final double initialHealth;
|
||||||
|
|
||||||
private int timeRemaining;
|
|
||||||
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
||||||
|
|
||||||
public TimedTeleport(Player player, TeleportationPoint targetPoint, TargetType targetType) {
|
public TimedTeleport(Player player, TeleportationPoint targetPoint, TargetType targetType) {
|
||||||
@@ -37,7 +36,6 @@ public class TimedTeleport {
|
|||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
this.targetType = targetType;
|
this.targetType = targetType;
|
||||||
this.targetPoint = targetPoint;
|
this.targetPoint = targetPoint;
|
||||||
this.timeRemaining = warmupTime;
|
|
||||||
|
|
||||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||||
@@ -48,7 +46,6 @@ public class TimedTeleport {
|
|||||||
this.initialLocation = player.getLocation();
|
this.initialLocation = player.getLocation();
|
||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
this.targetType = TargetType.RANDOM;
|
this.targetType = TargetType.RANDOM;
|
||||||
this.timeRemaining = warmupTime;
|
|
||||||
|
|
||||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||||
@@ -60,7 +57,6 @@ public class TimedTeleport {
|
|||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
this.targetType = TargetType.PLAYER;
|
this.targetType = TargetType.PLAYER;
|
||||||
this.targetPlayerName = targetPlayerName;
|
this.targetPlayerName = targetPlayerName;
|
||||||
this.timeRemaining = warmupTime;
|
|
||||||
|
|
||||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||||
@@ -192,14 +188,6 @@ public class TimedTeleport {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTimeRemaining() {
|
|
||||||
return timeRemaining;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void decrementTimeRemaining() {
|
|
||||||
timeRemaining = timeRemaining - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TargetType {
|
public enum TargetType {
|
||||||
POINT,
|
POINT,
|
||||||
BACK,
|
BACK,
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package me.william278.huskhomes2.util;
|
||||||
|
|
||||||
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
|
import me.william278.huskhomes2.data.pluginmessage.PluginMessage;
|
||||||
|
import me.william278.huskhomes2.data.pluginmessage.PluginMessageType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PlayerList {
|
||||||
|
|
||||||
|
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||||
|
private static final long playerListUpdateTime = HuskHomes.getSettings().getCrossServerTabUpdateDelay() * 20L;
|
||||||
|
|
||||||
|
private static HashSet<String> players;
|
||||||
|
|
||||||
|
public PlayerList() {
|
||||||
|
players = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
updateList(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, 0, playerListUpdateTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateList(Player updateRequester) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
players.clear();
|
||||||
|
if (HuskHomes.getSettings().doBungee() && HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> new PluginMessage(PluginMessageType.GET_PLAYER_LIST, HuskHomes.getSettings().getServerID()).sendToServer(updateRequester));
|
||||||
|
}
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
players.add(player.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getPlayers() {
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(String player) {
|
||||||
|
players.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayers(String[] playerList) {
|
||||||
|
players.addAll(Arrays.asList(playerList));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -49,8 +49,8 @@ set_home_success: '[Successfully set a new home called](#00fb9a) [%1%](#00fb9a b
|
|||||||
set_warp_success: '[Successfully set a new warp called](#00fb9a) [%1%](#00fb9a bold)'
|
set_warp_success: '[Successfully set a new warp called](#00fb9a) [%1%](#00fb9a bold)'
|
||||||
error_set_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
|
error_set_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
|
||||||
error_set_warp_name_taken: '[Error:](#ff3300) [There is already a warp set with that name.](#ff7e5e)'
|
error_set_warp_name_taken: '[Error:](#ff3300) [There is already a warp set with that name.](#ff7e5e)'
|
||||||
set_spawn_success: '[Updated /spawn command location for this server to your current position.](#00fb9a)'
|
set_spawn_success: '[Updated spawn position for this server to your current location.](#00fb9a)'
|
||||||
error_spawn_undefined: '[Error:](#ff3300) [There is no spawn location defined on this server.](#ff7e5e)'
|
error_spawn_undefined: '[Error:](#ff3300) [There is no spawn position defined on this server.](#ff7e5e)'
|
||||||
error_tpa_no_pending_request: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)'
|
error_tpa_no_pending_request: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)'
|
||||||
error_tpa_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)'
|
error_tpa_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)'
|
||||||
error_player_not_found: '[Error:](#ff3300) [Could not find the player %1%.](#ff7e5e)'
|
error_player_not_found: '[Error:](#ff3300) [Could not find the player %1%.](#ff7e5e)'
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ random_teleport_command:
|
|||||||
cooldown: 30
|
cooldown: 30
|
||||||
range: 5000
|
range: 5000
|
||||||
map_integration:
|
map_integration:
|
||||||
enabled: true
|
enabled: false
|
||||||
plugin: 'dynmap'
|
plugin: 'dynmap'
|
||||||
markers:
|
markers:
|
||||||
public_homes:
|
public_homes:
|
||||||
|
|||||||
@@ -99,11 +99,11 @@ commands:
|
|||||||
permission: huskhomes.rtp
|
permission: huskhomes.rtp
|
||||||
aliases: [randomtp, randomteleport, wild]
|
aliases: [randomtp, randomteleport, wild]
|
||||||
spawn:
|
spawn:
|
||||||
description: Teleport to the spawn location
|
description: Teleport to spawn
|
||||||
usage: /spawn
|
usage: /spawn
|
||||||
permission: huskhomes.spawn
|
permission: huskhomes.spawn
|
||||||
setspawn:
|
setspawn:
|
||||||
description: Set the spawn location
|
description: Set the spawn position
|
||||||
usage: /setspawn
|
usage: /setspawn
|
||||||
permission: huskhomes.spawn.set
|
permission: huskhomes.spawn.set
|
||||||
huskhomes:
|
huskhomes:
|
||||||
|
|||||||
Reference in new issue
Block a user