More refactor work, encapsulate classes

This commit is contained in:
William278 committed 2023-03-02 15:00:02 +00:00
1 parent 3e1ec09487
commit 1cebdac9b8
51 files changed
+756 -621

No files matched your search

@@ -163,8 +163,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
this.eventDispatcher = new BukkitEventDispatcher(this);
// Initialize the cache
cache = new Cache(eventDispatcher);
cache.initialize(database);
this.cache = new Cache(this);
// Prepare the home and warp position manager
this.manager = new Manager(this);
@@ -445,7 +444,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
final int y = snapshot.getHighestBlockYAt(x, z);
final Material blockType = snapshot.getBlockType(chunkX, y, chunkZ);
if (!isBlockUnsafe(blockType.getKey().toString())) {
return new Location((location.x + dX) + 0.5d, y + 1.25d, (location.z + dZ) + 0.5d, location.world);
return new Location((location.getX() + dX) + 0.5d, y + 1.25d, (location.getZ() + dZ) + 0.5d, location.getWorld());
}
}
}
@@ -18,7 +18,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
/**
* Hook to display warps and public homes on Dynmap
@@ -35,7 +34,8 @@ public class DynMapHook extends MapHook {
@Override
protected CompletableFuture<Void> initializeMap() {
return CompletableFuture.runAsync(() -> {
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
plugin.runAsync(() -> {
final MarkerAPI markerAPI = dynmapAPI.getMarkerAPI();
if (plugin.getSettings().isPublicHomesOnMap()) {
markerAPI.getMarkerIcons().stream()
@@ -57,10 +57,9 @@ public class DynMapHook extends MapHook {
markerAPI.createMarkerSet(WARPS_MARKER_SET_ID,
"Warps", dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
}
}).exceptionally(throwable -> {
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to initialize Dynmap integration", throwable);
return null;
initializedFuture.complete(null);
});
return initializedFuture;
}
@Override
@@ -70,13 +69,13 @@ public class DynMapHook extends MapHook {
final CompletableFuture<Void> updatedFuture = new CompletableFuture<>();
removeHome(home).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).createMarker(
home.owner.uuid + ":" + home.uuid, home.meta.name, home.world.name,
home.x, home.y, home.z, dynmapAPI.getMarkerAPI().getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), false)
.setDescription(MarkerInformationPopup.create(home.meta.name)
home.getOwner().uuid + ":" + home.getUuid(), home.getMeta().getName(), home.getWorld().getName(),
home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), false)
.setDescription(MarkerInformationPopup.create(home.getMeta().getName())
.setThumbnailMarker(PUBLIC_HOME_MARKER_IMAGE_NAME)
.addField("Owner", home.owner.username)
.addField("Description", plugin.getLocales().formatDescription(home.meta.description))
.addField("Command", "/" + BukkitCommandType.PUBLIC_HOME_COMMAND.commandBase.command + " " + home.meta.name)
.addField("Owner", home.getOwner().username)
.addField("Description", plugin.getLocales().formatDescription(home.getMeta().getDescription()))
.addField("Command", "/" + BukkitCommandType.PUBLIC_HOME_COMMAND.commandBase.command + " " + home.getMeta().getName())
.toHtml());
updatedFuture.complete(null);
}));
@@ -90,7 +89,7 @@ public class DynMapHook extends MapHook {
final CompletableFuture<Void> removedFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(home.owner.uuid + ":" + home.uuid))
.filter(marker -> marker.getMarkerID().equals(home.getOwner().uuid + ":" + home.getUuid()))
.findFirst()
.ifPresent(Marker::deleteMarker);
removedFuture.complete(null);
@@ -117,12 +116,12 @@ public class DynMapHook extends MapHook {
final CompletableFuture<Void> updatedFuture = new CompletableFuture<>();
removeWarp(warp).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).createMarker(
warp.uuid.toString(), warp.meta.name, warp.world.name,
warp.x, warp.y, warp.z, dynmapAPI.getMarkerAPI().getMarkerIcon(WARP_MARKER_IMAGE_NAME), false)
.setDescription(MarkerInformationPopup.create(warp.meta.name)
warp.getUuid().toString(), warp.getMeta().getName(), warp.getWorld().getName(),
warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(WARP_MARKER_IMAGE_NAME), false)
.setDescription(MarkerInformationPopup.create(warp.getMeta().getName())
.setThumbnailMarker(WARP_MARKER_IMAGE_NAME)
.addField("Description", plugin.getLocales().formatDescription(warp.meta.description))
.addField("Command", "/" + BukkitCommandType.WARP_COMMAND.commandBase.command + " " + warp.meta.name)
.addField("Description", plugin.getLocales().formatDescription(warp.getMeta().getDescription()))
.addField("Command", "/" + BukkitCommandType.WARP_COMMAND.commandBase.command + " " + warp.getMeta().getName())
.toHtml());
updatedFuture.complete(null);
}));
@@ -136,7 +135,7 @@ public class DynMapHook extends MapHook {
final CompletableFuture<Void> removedFuture = new CompletableFuture<>();
CompletableFuture.runAsync(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(warp.uuid.toString()))
.filter(marker -> marker.getMarkerID().equals(warp.getUuid().toString()))
.findFirst()
.ifPresent(Marker::deleteMarker);
removedFuture.complete(null);
@@ -74,9 +74,9 @@ public class BukkitEventListener extends EventListener implements Listener {
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> {
final OnlineUser onlineUser = BukkitPlayer.adapt(event.getPlayer());
super.handlePlayerUpdateSpawnPoint(onlineUser, new Position(
adaptedLocation.x, adaptedLocation.y, adaptedLocation.z,
adaptedLocation.yaw, adaptedLocation.pitch,
adaptedLocation.world, plugin.getServerName()));
adaptedLocation.getX(), adaptedLocation.getY(), adaptedLocation.getZ(),
adaptedLocation.getYaw(), adaptedLocation.getPitch(),
adaptedLocation.getWorld(), plugin.getServerName()));
});
}
@@ -78,18 +78,18 @@ public class PluginMessenger extends Messenger implements PluginMessageListener
return fetchOnlineServerList(onlineUser).thenApply(onlineServers -> {
// Ensure the server is online
final Optional<String> targetServer = Arrays.stream(onlineServers)
.filter(serverName -> serverName.equals(server.name))
.filter(serverName -> serverName.equals(server.getName()))
.findFirst();
if (targetServer.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING,
"Failed to send " + dispatcher.username + " to " + server.name + "; server offline?");
"Failed to send " + dispatcher.username + " to " + server.getName() + "; server offline?");
return false;
}
// Send player to target server
final ByteArrayDataOutput messageWriter = ByteStreams.newDataOutput();
messageWriter.writeUTF("Connect");
messageWriter.writeUTF(server.name);
messageWriter.writeUTF(server.getName());
dispatcher.sendPluginMessage(BUNGEE_PLUGIN_CHANNEL_NAME, messageWriter.toByteArray());
return true;
});
@@ -19,15 +19,15 @@ public final class BukkitAdapter {
* @return the adapted {@link Location}
*/
public static Optional<org.bukkit.Location> adaptLocation(@NotNull Location location) {
org.bukkit.World world = Bukkit.getWorld(location.world.name);
org.bukkit.World world = Bukkit.getWorld(location.getWorld().getName());
if (world == null) {
world = Bukkit.getWorld(location.world.uuid);
world = Bukkit.getWorld(location.getWorld().getUuid());
}
if (world == null) {
return Optional.empty();
}
return Optional.of(new org.bukkit.Location(world, location.x, location.y, location.z,
location.yaw, location.pitch));
return Optional.of(new org.bukkit.Location(world, location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch()));
}
/**