mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Some more encapsulation
This commit is contained in:
8 files changed
+33
-17
No files matched your search
@@ -120,6 +120,6 @@ public class HuskHomesAPI {
|
||||
* @return the spawn position as a TeleportationPoint
|
||||
*/
|
||||
public TeleportationPoint getSpawnPosition() {
|
||||
return TeleportManager.spawnLocation;
|
||||
return TeleportManager.getSpawnLocation();
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final List<String> tabCompletions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(args[0], HomeCommand.Tab.homeTabCache.get(p.getUniqueId()), tabCompletions);
|
||||
StringUtil.copyPartialMatches(args[0], HomeCommand.Tab.getHomeTabCache().get(p.getUniqueId()), tabCompletions);
|
||||
Collections.sort(tabCompletions);
|
||||
return tabCompletions;
|
||||
} else if (args.length == 2) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class HomeCommand extends CommandBase {
|
||||
// TODO Remove
|
||||
// This HashMap stores a cache of a player's homes that is displayed when a user presses TAB.
|
||||
// Owner UUID, Home Name
|
||||
public static Map<UUID, List<String>> homeTabCache = new HashMap<>();
|
||||
private static Map<UUID, List<String>> homeTabCache = new HashMap<>();
|
||||
|
||||
// This method updates a player's home cache.
|
||||
public static void updatePlayerHomeCache(Player p) {
|
||||
@@ -85,5 +85,9 @@ public class HomeCommand extends CommandBase {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<UUID, List<String>> getHomeTabCache() {
|
||||
return homeTabCache;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ public class SpawnCommand extends CommandBase {
|
||||
@Override
|
||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
||||
if (HuskHomes.getSettings().doSpawnCommand()) {
|
||||
if (TeleportManager.spawnLocation != null) {
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.spawnLocation);
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_spawn_undefined");
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ public class PlayerListener implements Listener {
|
||||
// Create player on SQL if they don't exist already
|
||||
if (!DataManager.playerExists(p)) {
|
||||
DataManager.createPlayer(p);
|
||||
if (TeleportManager.spawnLocation != null) {
|
||||
p.teleport(TeleportManager.spawnLocation.getLocation());
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
p.teleport(TeleportManager.getSpawnLocation().getLocation());
|
||||
}
|
||||
} else {
|
||||
// Check if they've changed their name and update if so
|
||||
|
||||
@@ -136,12 +136,12 @@ public class SettingHandler {
|
||||
plugin.saveConfig();
|
||||
|
||||
// Update the current spawn location
|
||||
TeleportManager.spawnLocation = new TeleportationPoint(location, HuskHomes.getSettings().getServerID());
|
||||
TeleportManager.setSpawnLocation(new TeleportationPoint(location, HuskHomes.getSettings().getServerID()));
|
||||
}
|
||||
|
||||
// Update current spawn location from config
|
||||
public static void fetchSpawnLocation() {
|
||||
TeleportManager.spawnLocation = getSpawnLocation();
|
||||
TeleportManager.setSpawnLocation(getSpawnLocation());
|
||||
}
|
||||
|
||||
// Get spawn location from config
|
||||
|
||||
@@ -12,12 +12,13 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TeleportManager {
|
||||
|
||||
public static HashSet<TimedTeleport> queuedTeleports = new HashSet<>();
|
||||
private static Set<TimedTeleport> queuedTeleports = new HashSet<>();
|
||||
|
||||
public static TeleportationPoint spawnLocation = null;
|
||||
private static TeleportationPoint spawnLocation;
|
||||
|
||||
public static void teleportPlayer(Player player, String targetPlayer) {
|
||||
DataManager.setPlayerLastPosition(player, new TeleportationPoint(player.getLocation(), HuskHomes.getSettings().getServerID()));
|
||||
@@ -54,7 +55,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player, targetPlayer));
|
||||
getQueuedTeleports().add(new TimedTeleport(player, targetPlayer));
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, TeleportationPoint point) {
|
||||
@@ -63,7 +64,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player, point));
|
||||
getQueuedTeleports().add(new TimedTeleport(player, point));
|
||||
}
|
||||
|
||||
public static void queueRandomTeleport(Player player) {
|
||||
@@ -99,7 +100,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player));
|
||||
getQueuedTeleports().add(new TimedTeleport(player));
|
||||
}
|
||||
|
||||
public static void teleportHere(Player requester, String targetPlayerName) {
|
||||
@@ -146,4 +147,15 @@ public class TeleportManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<TimedTeleport> getQueuedTeleports() {
|
||||
return queuedTeleports;
|
||||
}
|
||||
|
||||
public static TeleportationPoint getSpawnLocation() {
|
||||
return spawnLocation;
|
||||
}
|
||||
|
||||
public static void setSpawnLocation(TeleportationPoint spawnLocation) {
|
||||
TeleportManager.spawnLocation = spawnLocation;
|
||||
}
|
||||
}
|
||||
@@ -166,8 +166,8 @@ public class TeleportRequestHandler {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
|
||||
// Update active timed teleports
|
||||
if (!TeleportManager.queuedTeleports.isEmpty()) {
|
||||
for (TimedTeleport timedTeleport : TeleportManager.queuedTeleports) {
|
||||
if (!TeleportManager.getQueuedTeleports().isEmpty()) {
|
||||
for (TimedTeleport timedTeleport : TeleportManager.getQueuedTeleports()) {
|
||||
Player teleporter = Bukkit.getPlayer(timedTeleport.getTeleporter().getUniqueId());
|
||||
if (teleporter != null) {
|
||||
if (timedTeleport.getTimeRemaining() > 0) {
|
||||
@@ -226,7 +226,7 @@ public class TeleportRequestHandler {
|
||||
// Clear completed teleports
|
||||
if (!completedTeleports.isEmpty()) {
|
||||
for (TimedTeleport timedTeleport : completedTeleports) {
|
||||
TeleportManager.queuedTeleports.remove(timedTeleport);
|
||||
TeleportManager.getQueuedTeleports().remove(timedTeleport);
|
||||
}
|
||||
}
|
||||
completedTeleports.clear();
|
||||
|
||||
Reference in new issue
Block a user