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