mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +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
@@ -35,6 +35,7 @@ import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.listeners.PlayerListener;
|
||||
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
||||
import me.william278.huskhomes2.teleport.SettingHandler;
|
||||
import me.william278.huskhomes2.util.PlayerList;
|
||||
import org.bstats.bukkit.MetricsLite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -71,6 +72,10 @@ public final class HuskHomes extends JavaPlugin {
|
||||
return settings;
|
||||
}
|
||||
|
||||
// Player list managing
|
||||
private static PlayerList playerList;
|
||||
public static PlayerList getPlayerList() { return playerList; }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the HuskHomes API
|
||||
@@ -163,12 +168,8 @@ public final class HuskHomes extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Fetch config file
|
||||
saveDefaultConfig();
|
||||
|
||||
// Plugin startup logic
|
||||
getLogger().info("Enabling HuskHomes version " + this.getDescription().getVersion());
|
||||
|
||||
// Load the config
|
||||
settings.reload();
|
||||
|
||||
// Load the messages (in the right language)
|
||||
@@ -213,11 +214,21 @@ public final class HuskHomes extends JavaPlugin {
|
||||
|
||||
// bStats initialisation
|
||||
new MetricsLite(this, 8430);
|
||||
|
||||
// Setup player list
|
||||
playerList = new PlayerList();
|
||||
playerList.initialize();
|
||||
|
||||
// Log a message
|
||||
getLogger().info("Enabled HuskHomes version " + this.getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -95,14 +95,7 @@ public class TpCommand extends CommandBase {
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> players = new ArrayList<>();
|
||||
if (args.length == 0 || args.length == 1) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
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.addAll(HuskHomes.getPlayerList().getPlayers());
|
||||
}
|
||||
players.remove(sender.getName());
|
||||
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, () -> {
|
||||
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("ALL");
|
||||
out.writeUTF(server);
|
||||
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||
@@ -124,7 +128,7 @@ public class PluginMessage {
|
||||
try {
|
||||
messageOut.writeUTF(messageData);
|
||||
} 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ public enum PluginMessageType {
|
||||
TPA_REQUEST_REPLY,
|
||||
TPAHERE_REQUEST_REPLY,
|
||||
TELEPORT_TO_ME,
|
||||
GET_ONLINE_PLAYERS,
|
||||
RETURN_ONLINE_PLAYERS,
|
||||
PLAYER_CHANGE
|
||||
GET_PLAYER_LIST,
|
||||
RETURN_PLAYER_LIST
|
||||
}
|
||||
@@ -82,5 +82,12 @@ public class PlayerListener implements Listener {
|
||||
});
|
||||
} catch (NullPointerException ignored) {
|
||||
} // 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;
|
||||
case GET_ONLINE_PLAYERS:
|
||||
/*if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
returnPlayerList(messageData, recipient);
|
||||
}*/
|
||||
case GET_PLAYER_LIST:
|
||||
final String requestingServer = pluginMessage.getMessageData();
|
||||
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;
|
||||
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.WarpCommand;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.integrations.Map.DynMap;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
|
||||
@@ -115,9 +115,9 @@ public class TeleportManager {
|
||||
public static void queueRandomTeleport(Player player, Connection connection) throws SQLException {
|
||||
if (!player.hasPermission("huskhomes.rtp.bypass_cooldown")) {
|
||||
long currentTime = Instant.now().getEpochSecond();
|
||||
long cooldownTime = DataManager.getPlayerRtpCooldown(player, connection);
|
||||
if (currentTime < cooldownTime) {
|
||||
long timeRemaining = cooldownTime - currentTime;
|
||||
long coolDownTime = DataManager.getPlayerRtpCooldown(player, connection);
|
||||
if (currentTime < coolDownTime) {
|
||||
long timeRemaining = coolDownTime - currentTime;
|
||||
long timeRemainingMinutes = timeRemaining / 60;
|
||||
MessageManager.sendMessage(player, "error_rtp_cooldown", Long.toString(timeRemainingMinutes));
|
||||
return;
|
||||
|
||||
@@ -28,7 +28,6 @@ public class TimedTeleport {
|
||||
private final Location initialLocation;
|
||||
private final double initialHealth;
|
||||
|
||||
private int timeRemaining;
|
||||
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
||||
|
||||
public TimedTeleport(Player player, TeleportationPoint targetPoint, TargetType targetType) {
|
||||
@@ -37,7 +36,6 @@ public class TimedTeleport {
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = targetType;
|
||||
this.targetPoint = targetPoint;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
@@ -48,7 +46,6 @@ public class TimedTeleport {
|
||||
this.initialLocation = player.getLocation();
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = TargetType.RANDOM;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
@@ -60,7 +57,6 @@ public class TimedTeleport {
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = TargetType.PLAYER;
|
||||
this.targetPlayerName = targetPlayerName;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
@@ -192,14 +188,6 @@ public class TimedTeleport {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getTimeRemaining() {
|
||||
return timeRemaining;
|
||||
}
|
||||
|
||||
public void decrementTimeRemaining() {
|
||||
timeRemaining = timeRemaining - 1;
|
||||
}
|
||||
|
||||
public enum TargetType {
|
||||
POINT,
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user