Merge remote-tracking branch 'origin/big-refactor' into big-refactor

This commit is contained in:
William committed 2023-03-23 00:43:30 +00:00
commit 9f4fb11dda
61 files changed
+1113 -733

No files matched your search

-4
View File
@@ -9,14 +9,10 @@ dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:24.0.0'
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
compileOnly 'redis.clients:jedis:' + jedis_version
compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'com.google.guava:guava:31.1-jre'
compileOnly 'net.william278:Annotaml:2.0.1'
compileOnly 'net.william278:DesertWell:1.1.1'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4'
compileOnly 'us.dynmap:dynmap-api:3.1'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
testImplementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
@@ -22,7 +22,7 @@ import net.william278.huskhomes.network.Broker;
import net.william278.huskhomes.network.PluginMessageBroker;
import net.william278.huskhomes.network.RedisBroker;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.config.Server;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.random.NormalDistributionEngine;
import net.william278.huskhomes.random.RandomTeleportEngine;
@@ -68,7 +68,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
private RandomTeleportEngine randomTeleportEngine;
private Spawn serverSpawn;
private UnsafeBlocks unsafeBlocks;
private Set<PluginHook> pluginHooks;
private List<Hook> hooks;
private List<Command> commands;
private Map<String, List<String>> globalPlayerList;
private Set<UUID> currentlyOnWarmup;
@@ -168,12 +168,12 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
}
private void loadHooks() {
this.pluginHooks = new HashSet<>();
this.hooks = new ArrayList<>();
if (settings.doEconomy()) {
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
pluginHooks.add(new RedisEconomyHook(this));
hooks.add(new RedisEconomyHook(this));
} else if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
pluginHooks.add(new VaultEconomyHook(this));
hooks.add(new VaultEconomyHook(this));
}
}
if (settings.doMapHook()) {
@@ -181,24 +181,24 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
case DYNMAP -> {
final Plugin dynmapPlugin = Bukkit.getPluginManager().getPlugin("Dynmap");
if (dynmapPlugin != null) {
pluginHooks.add(new DynMapHook(this, dynmapPlugin));
hooks.add(new DynmapHook(this));
}
}
case BLUEMAP -> {
if (Bukkit.getPluginManager().getPlugin("BlueMap") != null) {
pluginHooks.add(new BlueMapHook(this));
hooks.add(new BlueMapHook(this));
}
}
}
}
if (Bukkit.getPluginManager().getPlugin("Plan") != null) {
pluginHooks.add(new PlanHook(this));
hooks.add(new PlanHook(this));
}
if (pluginHooks.size() > 0) {
pluginHooks.forEach(PluginHook::initialize);
log(Level.INFO, "Registered " + pluginHooks.size() + " plugin hooks: " + pluginHooks.stream()
.map(PluginHook::getHookName)
if (hooks.size() > 0) {
hooks.forEach(Hook::initialize);
log(Level.INFO, "Registered " + hooks.size() + " plugin hooks: " + hooks.stream()
.map(Hook::getName)
.collect(Collectors.joining(", ")));
}
}
@@ -314,8 +314,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
@Override
@NotNull
public Set<PluginHook> getPluginHooks() {
return pluginHooks;
public List<Hook> getHooks() {
return hooks;
}
@Override
@@ -341,7 +341,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.getX() + dX) + 0.5d, y + 1.25d, (location.getZ() + dZ) + 0.5d, location.getWorld());
return Location.at((location.getX() + dX) + 0.5d, y + 1.25d, (location.getZ() + dZ) + 0.5d, location.getWorld());
}
}
}
@@ -441,7 +441,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy())));
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
if (getSettings().doMapHook()) {
metrics.addCustomChart(new SimplePie("map_type", () -> getSettings().getMappingPlugin().displayName));
metrics.addCustomChart(new SimplePie("map_type", () -> getSettings().getMappingPlugin().getDisplayName()));
}
} catch (Exception e) {
log(Level.WARNING, "Failed to register metrics", e);
@@ -484,6 +484,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
}
// Super constructor for unit testing
@SuppressWarnings("unused")
protected BukkitHuskHomes(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) {
super(loader, description, dataFolder, file);
}
@@ -3,7 +3,7 @@ package net.william278.huskhomes.api;
import net.william278.huskhomes.BukkitHuskHomes;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.config.Server;
import net.william278.huskhomes.user.BukkitUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
@@ -26,7 +26,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
/**
* <b>(Internal use only)</b> - Instance of the API class
*/
private static final HuskHomesAPI INSTANCE = new HuskHomesAPI();
private static HuskHomesAPI instance;
/**
* <b>(Internal use only)</b> - Constructor, instantiating the API
@@ -40,8 +40,9 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
*
* @return instance of the HuskHomes API
*/
@NotNull
public static HuskHomesAPI getInstance() {
return INSTANCE;
return instance == null ? instance = new HuskHomesAPI() : instance;
}
/**
@@ -103,18 +104,19 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
*/
@NotNull
public Position adaptPosition(@NotNull org.bukkit.Location location, @NotNull String server) {
return new Position(Objects.requireNonNull(adaptLocation(location)), server);
return Position.at(Objects.requireNonNull(adaptLocation(location)), server);
}
/**
* Returns a {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on.
*
* @param location the bukkit location to get the {@link Position} instance for
* @return the {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on
* @since 4.0
*/
@NotNull
public Position adaptPosition(@NotNull org.bukkit.Location location) {
return new Position(Objects.requireNonNull(adaptLocation(location)), getServer());
return Position.at(Objects.requireNonNull(adaptLocation(location)), getServer());
}
/**
@@ -1,212 +0,0 @@
package net.william278.huskhomes.hook;
import net.william278.huskhomes.BukkitHuskHomes;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.command.BukkitCommand;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.user.User;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* Hook to display warps and public homes on Dynmap
*/
public class DynMapHook extends MapHook {
@NotNull
private final DynmapAPI dynmapAPI;
public DynMapHook(@NotNull HuskHomes implementor, @NotNull Plugin dynmapPlugin) {
super(implementor, "Dynmap");
this.dynmapAPI = (DynmapAPI) dynmapPlugin;
}
@Override
protected CompletableFuture<Void> initializeMap() {
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
plugin.runAsync(() -> {
final MarkerAPI markerAPI = dynmapAPI.getMarkerAPI();
if (plugin.getSettings().isPublicHomesOnMap()) {
markerAPI.getMarkerIcons().stream()
.filter(markerIcon -> markerIcon.getMarkerIconID().equals(PUBLIC_HOME_MARKER_IMAGE_NAME))
.findFirst()
.ifPresent(markerIcon -> markerAPI.getMarkerIcons().remove(markerIcon));
markerAPI.createMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME, "Public Home",
((BukkitHuskHomes) plugin).getResource("markers/16x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png"));
markerAPI.createMarkerSet(PUBLIC_HOMES_MARKER_SET_ID,
"Public Homes", dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
}
if (plugin.getSettings().isWarpsOnMap()) {
markerAPI.getMarkerIcons().stream()
.filter(markerIcon -> markerIcon.getMarkerIconID().equals(WARP_MARKER_IMAGE_NAME))
.findFirst()
.ifPresent(markerIcon -> markerAPI.getMarkerIcons().remove(markerIcon));
markerAPI.createMarkerIcon(WARP_MARKER_IMAGE_NAME, "Warp",
((BukkitHuskHomes) plugin).getResource("markers/16x/" + WARP_MARKER_IMAGE_NAME + ".png"));
markerAPI.createMarkerSet(WARPS_MARKER_SET_ID,
"Warps", dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
}
initializedFuture.complete(null);
});
return initializedFuture;
}
@Override
public CompletableFuture<Void> updateHome(@NotNull Home home) {
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
final CompletableFuture<Void> updatedFuture = new CompletableFuture<>();
removeHome(home).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).createMarker(
home.getOwner().getUuid() + ":" + 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.getOwner().getUsername())
.addField("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60))
.addField("Command", "/" + BukkitCommand.Type.PUBLIC_HOME_COMMAND.getCommand().getName() + " " + home.getMeta().getName())
.toHtml());
updatedFuture.complete(null);
}));
return updatedFuture;
}
@Override
public CompletableFuture<Void> removeHome(@NotNull Home home) {
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
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.getOwner().getUuid() + ":" + home.getUuid()))
.findFirst()
.ifPresent(Marker::deleteMarker);
removedFuture.complete(null);
});
return removedFuture;
}
@Override
public void clearHomes(@NotNull User user) {
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream()
.filter(marker -> marker.getMarkerID().startsWith(user.getUuid().toString()))
.forEach(Marker::deleteMarker);
clearedFuture.complete(null);
});
}
@Override
public CompletableFuture<Void> updateWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
final CompletableFuture<Void> updatedFuture = new CompletableFuture<>();
removeWarp(warp).thenRun(() -> Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).createMarker(
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().wrapText(warp.getMeta().getDescription(), 60))
.addField("Command", "/" + BukkitCommand.Type.WARP_COMMAND.getCommand().getName() + " " + warp.getMeta().getName())
.toHtml());
updatedFuture.complete(null);
}));
return updatedFuture;
}
@Override
public CompletableFuture<Void> removeWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
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.getUuid().toString()))
.findFirst()
.ifPresent(Marker::deleteMarker);
removedFuture.complete(null);
}));
return removedFuture;
}
@Override
public void clearWarps() {
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers()
.forEach(Marker::deleteMarker);
clearedFuture.complete(null);
});
}
/**
* Creates an HTML Dynmap marker information popup widget
*/
private static class MarkerInformationPopup {
@NotNull
private final String title;
@Nullable
private String thumbnailMarkerId;
@NotNull
private final Map<String, String> fields;
private MarkerInformationPopup(@NotNull String title) {
this.title = title;
this.fields = new HashMap<>();
}
@NotNull
private static DynMapHook.MarkerInformationPopup create(@NotNull String title) {
return new MarkerInformationPopup(title);
}
@NotNull
private DynMapHook.MarkerInformationPopup setThumbnailMarker(@NotNull String thumbnailMarkerId) {
this.thumbnailMarkerId = thumbnailMarkerId;
return this;
}
@NotNull
private DynMapHook.MarkerInformationPopup addField(@NotNull String key, @NotNull String value) {
fields.put(key, value);
return this;
}
@NotNull
private String toHtml() {
final StringBuilder html = new StringBuilder();
html.append("<div class=\"infowindow\">");
if (thumbnailMarkerId != null) {
html.append("<img src=\"/tiles/_markers_/")
.append(thumbnailMarkerId)
.append(".png\" class=\"thumbnail\"/>")
.append("&nbsp;");
}
html.append("<span style=\"font-weight: bold;\">")
.append(StringEscapeUtils.escapeHtml(title))
.append("</span><br/>");
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
.append(StringEscapeUtils.escapeHtml(key))
.append(": </span><span>")
.append(StringEscapeUtils.escapeHtml(value))
.append("</span><br/>"));
return html.toString();
}
}
}
@@ -6,19 +6,19 @@ import org.jetbrains.annotations.NotNull;
public class RedisEconomyHook extends VaultEconomyHook {
public RedisEconomyHook(@NotNull HuskHomes implementor) {
super(implementor);
public RedisEconomyHook(@NotNull HuskHomes plugin) {
super(plugin);
}
@Override
public boolean initialize() {
public void initialize() {
RedisEconomyAPI api = RedisEconomyAPI.getAPI();
if (api != null) {
economy = api.getCurrencyByName(plugin.getSettings().getRedisEconomyName());
if (economy != null) {
return true;
return;
}
}
return super.initialize();
super.initialize();
}
}
@@ -16,19 +16,17 @@ public class VaultEconomyHook extends EconomyHook {
protected Economy economy;
public VaultEconomyHook(@NotNull HuskHomes implementor) {
super(implementor, "Vault (Economy)");
public VaultEconomyHook(@NotNull HuskHomes plugin) {
super(plugin, "Vault (Economy)");
}
@Override
public boolean initialize() {
public void initialize() {
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
.getServicesManager().getRegistration(Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
return true;
}
return false;
}
@Override
@@ -55,7 +55,7 @@ public class BukkitEventListener extends EventListener implements Listener {
final BukkitUser bukkitUser = BukkitUser.adapt(player);
BukkitAdapter.adaptLocation(event.getFrom()).ifPresent(sourceLocation ->
handlePlayerTeleport(bukkitUser, new Position(sourceLocation, plugin.getServerName())));
handlePlayerTeleport(bukkitUser, Position.at(sourceLocation, plugin.getServerName())));
}
//todo When defining paper-plugin.yml files gets merged, use the PlayerSetSpawnEvent in the paper module
@@ -73,7 +73,7 @@ public class BukkitEventListener extends EventListener implements Listener {
// Update the player's respawn location
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> {
final OnlineUser onlineUser = BukkitUser.adapt(event.getPlayer());
super.handlePlayerUpdateSpawnPoint(onlineUser, new Position(
super.handlePlayerUpdateSpawnPoint(onlineUser, Position.at(
adaptedLocation.getX(), adaptedLocation.getY(), adaptedLocation.getZ(),
adaptedLocation.getYaw(), adaptedLocation.getPitch(),
adaptedLocation.getWorld(), plugin.getServerName()));
@@ -45,7 +45,7 @@ public class BukkitUser extends OnlineUser {
@Override
public Position getPosition() {
return new Position(BukkitAdapter.adaptLocation(player.getLocation())
return Position.at(BukkitAdapter.adaptLocation(player.getLocation())
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
plugin.getServerName());
@@ -54,7 +54,7 @@ public class BukkitUser extends OnlineUser {
@Override
public Optional<Position> getBedSpawnPosition() {
return Optional.ofNullable(player.getBedSpawnLocation()).flatMap(BukkitAdapter::adaptLocation)
.map(location -> new Position(location, plugin.getServerName()));
.map(location -> Position.at(location, plugin.getServerName()));
}
@Override
@@ -1,6 +1,7 @@
package net.william278.huskhomes.util;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.World;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,21 +39,21 @@ public final class BukkitAdapter {
*/
public static Optional<Location> adaptLocation(@NotNull org.bukkit.Location location) {
if (location.getWorld() == null) return Optional.empty();
return Optional.of(new Location(location.getX(), location.getY(), location.getZ(),
return Optional.of(Location.at(location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch(),
adaptWorld(location.getWorld()).orElse(new net.william278.huskhomes.position.World())));
}
public static Optional<net.william278.huskhomes.position.World> adaptWorld(@Nullable org.bukkit.World world) {
public static Optional<World> adaptWorld(@Nullable org.bukkit.World world) {
if (world == null) {
return Optional.empty();
}
return Optional.of(new net.william278.huskhomes.position.World(world.getName(), world.getUID(),
return Optional.of(World.from(world.getName(), world.getUID(),
switch (world.getEnvironment()) {
case NORMAL -> net.william278.huskhomes.position.World.Environment.OVERWORLD;
case NETHER -> net.william278.huskhomes.position.World.Environment.NETHER;
case THE_END -> net.william278.huskhomes.position.World.Environment.THE_END;
case CUSTOM -> net.william278.huskhomes.position.World.Environment.CUSTOM;
case NORMAL -> World.Environment.OVERWORLD;
case NETHER -> World.Environment.NETHER;
case THE_END -> World.Environment.THE_END;
case CUSTOM -> World.Environment.CUSTOM;
})
);
}
@@ -271,9 +271,9 @@ public class BukkitPluginTests {
@Order(4)
public void testWarpRelocation(@NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
0, 0, world, plugin.getServerName());
plugin.getManager().warps().relocateWarp(name, newPosition);
plugin.getManager().warps().setWarpPosition(name, newPosition);
final Optional<Position> warpPosition = plugin.getDatabase().getWarp(name).map(warp -> warp);
Assertions.assertTrue(warpPosition.isPresent());
@@ -288,7 +288,7 @@ public class BukkitPluginTests {
@Order(5)
public void testWarpOverwrite(@NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
0, 0, world, plugin.getServerName());
plugin.getManager().warps().createWarp(name, newPosition, true);
@@ -327,7 +327,7 @@ public class BukkitPluginTests {
@NotNull
public static Stream<Arguments> provideWarpData() {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position position = new Position(0, 0, 0, 0, 0, world, plugin.getServerName());
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
return WARP_NAMES.stream()
.flatMap(name -> Stream.of(Arguments.of(name, position)));
}
@@ -415,7 +415,7 @@ public class BukkitPluginTests {
@Order(4)
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
0, 0, world, plugin.getServerName());
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -434,7 +434,7 @@ public class BukkitPluginTests {
@Order(5)
public void testHomeOverwrite(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
0, 0, world, plugin.getServerName());
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -507,7 +507,7 @@ public class BukkitPluginTests {
@NotNull
public static Stream<Arguments> provideHomeData() {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
final Position position = new Position(0, 0, 0, 0, 0, world, plugin.getServerName());
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
return HOME_NAMES.stream()
.flatMap(name -> Stream.of(Arguments.of(homeOwner, name, position)));
}
+2 -1
View File
@@ -17,8 +17,9 @@ dependencies {
compileOnly 'redis.clients:jedis:' + jedis_version
compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
compileOnly 'com.mysql:mysql-connector-j:' + mysql_driver_version
compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:v2.1.0'
compileOnly 'com.github.plan-player-analytics:Plan:5.5.1923'
compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.5.0'
compileOnly 'us.dynmap:DynmapCoreAPI:3.4'
testImplementation 'com.github.plan-player-analytics:Plan:5.5.1833'
testImplementation 'com.github.yuriy-g:simple-java-plot:5c502c2e98'
@@ -13,12 +13,12 @@ import net.william278.huskhomes.database.Database;
import net.william278.huskhomes.event.EventDispatcher;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.hook.MapHook;
import net.william278.huskhomes.hook.PluginHook;
import net.william278.huskhomes.hook.Hook;
import net.william278.huskhomes.manager.Manager;
import net.william278.huskhomes.network.Broker;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.config.Server;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.random.RandomTeleportEngine;
import net.william278.huskhomes.user.ConsoleUser;
@@ -161,43 +161,26 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
void setServerSpawn(@NotNull Location location);
/**
* Set of active {@link PluginHook}s running on the server
* Set of active {@link Hook}s running on the server
*
* @return the {@link Set} of active {@link PluginHook}s
* @return the {@link Set} of active {@link Hook}s
*/
@NotNull
Set<PluginHook> getPluginHooks();
List<Hook> getHooks();
/**
* Finds the {@link PluginHook} of the given class instance from the set of active {@link PluginHook}s
*
* @param hookClass the class of the {@link PluginHook} to get
* @param <H> the type of the {@link PluginHook}
* @return the {@link PluginHook} instance, or an empty {@link Optional} if not found
*/
default <H extends PluginHook> Optional<H> getHook(@NotNull Class<H> hookClass) {
return getPluginHooks().stream()
.filter(hook -> hook.getClass().isInstance(hookClass))
.findFirst()
.map(hookClass::cast);
default <T extends Hook> Optional<T> getHook(@NotNull Class<T> hookClass) {
return getHooks().stream()
.filter(hook -> hookClass.isAssignableFrom(hook.getClass()))
.map(hookClass::cast)
.findFirst();
}
/**
* Gets the {@link MapHook} being used to display public homes and warps on a web map, if there is one, and it is enabled
*
* @return the {@link MapHook} optionally being used
*/
default Optional<MapHook> getMapHook() {
return getSettings().doMapHook() ? getHook(MapHook.class) : Optional.empty();
}
/**
* Gets the {@link EconomyHook} being used to charge players for commands, if there is one, and it is enabled
*
* @return the {@link EconomyHook} optionally being used
*/
default Optional<EconomyHook> getEconomyHook() {
return getSettings().doEconomy() ? getHook(EconomyHook.class) : Optional.empty();
return getHook(EconomyHook.class);
}
default Optional<MapHook> getMapHook() {
return getHook(MapHook.class);
}
/**
@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -123,6 +124,40 @@ public abstract class BaseHuskHomesAPI {
plugin.runAsync(() -> plugin.getDatabase().updateUserData(savedUser));
}
/**
* Edit {@link SavedUser} data for a given player by username, if they exist.
*
* @param username The username of the user to edit data for.
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
* @since 4.0
*/
public final void editUserData(@NotNull String username, @NotNull Consumer<SavedUser> editor) {
plugin.runAsync(() -> {
Optional<SavedUser> savedUser = plugin.getDatabase().getUserDataByName(username);
if (savedUser.isPresent()) {
editor.accept(savedUser.get());
plugin.getDatabase().updateUserData(savedUser.get());
}
});
}
/**
* Edit {@link SavedUser} data for the given player's account {@link UUID}, if they exist.
*
* @param uuid The {@link UUID} of the user to edit data for.
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
* @since 4.0
*/
public final void editUserData(@NotNull UUID uuid, @NotNull Consumer<SavedUser> editor) {
plugin.runAsync(() -> {
Optional<SavedUser> savedUser = plugin.getDatabase().getUserData(uuid);
if (savedUser.isPresent()) {
editor.accept(savedUser.get());
plugin.getDatabase().updateUserData(savedUser.get());
}
});
}
/**
* Get a list of {@link Home}s set by the given user.
*
@@ -142,11 +177,22 @@ public abstract class BaseHuskHomesAPI {
* @since 3.0
*/
public final CompletableFuture<List<Home>> getUserPublicHomes(@NotNull User user) {
return getUserHomes(user).thenApply(homes -> homes.stream()
return plugin.supplyAsync(() -> plugin.getDatabase().getHomes(user).stream()
.filter(Home::isPublic)
.collect(Collectors.toList()));
}
/**
* Get a list of public homes local to this server
*
* @param user The {@link User} to get the local public homes of
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s local to the server
* @since 4.0
*/
public final CompletableFuture<List<Home>> getLocalPublicHomes(@NotNull User user) {
return plugin.supplyAsync(() -> plugin.getDatabase().getLocalPublicHomes(plugin));
}
/**
* Get a list of homes that have been made public ("public homes")
*
@@ -169,6 +215,7 @@ public abstract class BaseHuskHomesAPI {
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(user, homeName));
}
/**
* Get a {@link Home} from the database by its' unique id
*
@@ -179,6 +226,141 @@ public abstract class BaseHuskHomesAPI {
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(homeUuid));
}
/**
* Create a home for a given user with the specified name and position
*
* @param owner The {@link User} to create the home for
* @param name The name of the home
* @param position The {@link Position} of the home
* @since 4.0
*/
public void createHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().homes().createHome(owner, name, position, false, false));
}
/**
* Delete a home for a given user with the specified name
*
* @param owner The {@link User} to delete the home for
* @param name The name of the home
* @since 4.0
*/
public final void deleteHome(@NotNull User owner, @NotNull String name) {
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(owner, name));
}
/**
* Delete a home
*
* @param home The {@link Home} to delete
* @since 4.0
*/
public final void deleteHome(@NotNull Home home) {
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(home));
}
/**
* Rename a home for a given user
*
* @param owner The {@link User} to rename the home for
* @param oldName The name of the home to rename
* @param newName The new name of the home
* @since 4.0
*/
public final void renameHome(@NotNull User owner, @NotNull String oldName, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(owner, oldName, newName));
}
/**
* Rename a home
*
* @param home The {@link Home} to rename
* @param newName The new name of the home
* @since 4.0
*/
public final void renameHome(@NotNull Home home, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(home, newName));
}
/**
* Set the privacy of a home
*
* @param owner The {@link User} to set the privacy of the home for
* @param name The name of the home
* @param isPublic Whether the home should be public or not
* @since 4.0
*/
public final void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean isPublic) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(owner, name, isPublic));
}
/**
* Set the privacy of a home
*
* @param home The {@link Home} to set the privacy of
* @param isPublic Whether the home should be public or not
* @since 4.0
*/
public final void setHomePrivacy(@NotNull Home home, boolean isPublic) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(home, isPublic));
}
/**
* Set the description of a home
*
* @param owner The {@link User} to set the description of the home for
* @param name The name of the home
* @param description The description of the home
* @since 4.0
*/
public final void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(owner, name, description));
}
/**
* Set the description of a home
*
* @param home The {@link Home} to set the description of
* @param description The description of the home
* @since 4.0
*/
public final void setHomeDescription(@NotNull Home home, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(home, description));
}
/**
* Relocate a home for a given user
*
* @param owner The {@link User} to relocate the home for
* @param name The name of the home
* @param position The new {@link Position} of the home
* @since 4.0
*/
public final void relocateHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(owner, name, position));
}
/**
* Relocate a home
*
* @param home The {@link Home} to relocate
* @param position The new {@link Position} of the home
* @since 4.0
*/
public final void relocateHome(@NotNull Home home, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(home, position));
}
/**
* Get a list of {@link Warp}s local to this server
*
* @return A {@link CompletableFuture} that will complete with a list of {@link Warp}s local to the server
* @since 4.0
*/
public final CompletableFuture<List<Warp>> getLocalWarps() {
return plugin.supplyAsync(() -> plugin.getDatabase().getLocalWarps(plugin));
}
/**
* Get a list of {@link Warp}s
*
@@ -210,6 +392,95 @@ public abstract class BaseHuskHomesAPI {
return plugin.supplyAsync(() -> plugin.getDatabase().getWarp(warpUuid));
}
/**
* Create a new {@link Warp} with the given name and {@link Position}
*
* @param name The name of the warp
* @param position The {@link Position} of the warp
* @since 4.0
*/
public final void createWarp(@NotNull String name, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().warps().createWarp(name, position));
}
/**
* Delete a {@link Warp} with the given name
*
* @param name The name of the warp to delete
*/
public final void deleteWarp(@NotNull String name) {
plugin.runAsync(() -> plugin.getManager().warps().deleteWarp(name));
}
/**
* Delete a {@link Warp}
*
* @param warp The {@link Warp} to delete
*/
public final void deleteWarp(@NotNull Warp warp) {
plugin.runAsync(() -> plugin.getManager().warps().deleteWarp(warp));
}
/**
* Rename a {@link Warp} by name
*
* @param oldName The name of the warp to rename
* @param newName The new name of the warp
*/
public final void renameWarp(@NotNull String oldName, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpName(oldName, newName));
}
/**
* Rename a {@link Warp}
*
* @param warp The {@link Warp} to rename
* @param newName The new name of the warp
*/
public final void renameWarp(@NotNull Warp warp, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpName(warp, newName));
}
/**
* Set the description of a {@link Warp} by name
*
* @param name The name of the warp to set the description of
* @param description The new description of the warp
*/
public final void setWarpDescription(@NotNull String name, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpDescription(name, description));
}
/**
* Set the description of a {@link Warp}
*
* @param warp The {@link Warp} to set the description of
* @param description The new description of the warp
*/
public final void setWarpDescription(@NotNull Warp warp, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpDescription(warp, description));
}
/**
* Set the {@link Position} of a {@link Warp} by name
*
* @param name The name of the warp to set the {@link Position} of
* @param position The new {@link Position} of the warp
*/
public final void relocateWarp(@NotNull String name, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpPosition(name, position));
}
/**
* Set the {@link Position} of a {@link Warp}
*
* @param warp The {@link Warp} to set the {@link Position} of
* @param position The new {@link Position} of the warp
*/
public final void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().warps().setWarpPosition(warp, position));
}
/**
* Get the canonical {@link Position} of the spawn point. Note that if cross-server and global spawn
* are enabled in the config, this may not return a position on this server.
@@ -278,7 +549,7 @@ public abstract class BaseHuskHomesAPI {
* @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine}
* @since 3.0
*/
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, final boolean timedTeleport, @NotNull String... rtpArgs) {
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, boolean timedTeleport, @NotNull String... rtpArgs) {
plugin.runAsync(() -> {
final Optional<Position> position = plugin.getRandomTeleportEngine()
.getRandomPosition(user.getPosition().getWorld(), rtpArgs);
@@ -11,8 +11,8 @@ import java.util.List;
public class DelHomeCommand extends SavedPositionCommand<Home> {
public DelHomeCommand(@NotNull HuskHomes implementor) {
super("delhome", List.of(), Home.class, List.of(), implementor);
public DelHomeCommand(@NotNull HuskHomes plugin) {
super("delhome", List.of(), Home.class, List.of(), plugin);
}
@Override
@@ -10,8 +10,8 @@ import java.util.List;
public class DelWarpCommand extends SavedPositionCommand<Warp> {
public DelWarpCommand(@NotNull HuskHomes implementor) {
super("delwarp", List.of(), Warp.class, List.of(), implementor);
public DelWarpCommand(@NotNull HuskHomes plugin) {
super("delwarp", List.of(), Warp.class, List.of(), plugin);
}
@Override
@@ -88,7 +88,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
final String oldDescription = home.getMeta().getDescription();
final Optional<String> optionalDescription = parseGreedyString(args, 1);
final Optional<String> optionalDescription = parseGreedyArguments(args);
if (optionalDescription.isEmpty()) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/edithome " + home.getName() + " description <text>")
@@ -166,7 +166,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
home.setPublic(privacyArg.get().equals("public"));
plugin.fireEvent(plugin.getHomeEditEvent(home, executor), (event) -> {
try {
plugin.getManager().homes().setHomePrivacy(home, home.isPublic());
plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic());
} catch (ValidationException e) {
int maxHomes = executor instanceof OnlineUser user ?
user.getMaxPublicHomes(plugin.getSettings().getMaxPublicHomes(),
@@ -67,7 +67,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
}
private void setWarpDescription(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
final Optional<String> optionalDescription = parseGreedyString(args, 1);
final Optional<String> optionalDescription = parseGreedyArguments(args);
if (optionalDescription.isEmpty()) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/editwarp " + warp.getName() + " description <text>")
@@ -99,7 +99,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
warp.update(user.getPosition());
plugin.fireEvent(plugin.getWarpEditEvent(warp, executor), (event) -> {
try {
plugin.getManager().warps().relocateWarp(warp, warp);
plugin.getManager().warps().setWarpPosition(warp, warp);
} catch (ValidationException e) {
e.dispatchWarpError(executor, plugin, warp.getName());
return;
@@ -114,15 +114,15 @@ public abstract class Node implements Executable {
return Optional.of(plugin.getWorlds().stream()
.filter(world -> world.getName().equalsIgnoreCase(worldName))
.findFirst()
.orElse(new World(worldName, new UUID(0, 0), environment)));
.orElse(World.from(worldName, new UUID(0, 0), environment)));
}
return Optional.empty();
}
protected Optional<String> parseGreedyString(@NotNull String[] args, int startIndex) {
if (args.length > startIndex) {
protected Optional<String> parseGreedyArguments(@NotNull String[] args) {
if (args.length > 1) {
final StringJoiner sentence = new StringJoiner(" ");
for (int i = startIndex; i < args.length; i++) {
for (int i = 1; i < args.length; i++) {
sentence.add(args[i]);
}
return Optional.of(sentence.toString().trim());
@@ -132,7 +132,7 @@ public abstract class Node implements Executable {
protected Position getBasePosition(@NotNull CommandUser executor) {
return executor instanceof OnlineUser user ? user.getPosition() : plugin.getSpawn()
.orElse(new Position(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName()));
.orElse(Position.at(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName()));
}
protected Optional<Position> parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int startIndex) {
@@ -153,7 +153,7 @@ public abstract class Node implements Executable {
final Optional<Float> yaw = parseFloatArg(args, startIndex + angleStartIndex);
final Optional<Float> pitch = parseFloatArg(args, startIndex + angleStartIndex + 1);
return Optional.of(new Position(x.get(), y.get(), z.get(),
return Optional.of(Position.at(x.get(), y.get(), z.get(),
yaw.orElse(basePosition.getYaw()), pitch.orElse(basePosition.getPitch()),
world.orElse(basePosition.getWorld()), server.orElse(basePosition.getServer())));
}
@@ -64,13 +64,14 @@ public class RtpCommand extends Command {
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
final Instant currentTime = Instant.now();
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
!executor.hasPermission(getPermission("bypass_cooldown"))) {
!executor.hasPermission(getPermission("bypass_cooldown"))) {
plugin.getLocales().getLocale("error_rtp_cooldown",
Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1))
.ifPresent(executor::sendMessage);
return;
}
// Generate a random position
plugin.getLocales().getLocale("teleporting_random_generation")
.ifPresent(teleporter::sendMessage);
final Optional<Position> position = plugin.getRandomTeleportEngine()
@@ -14,8 +14,8 @@ import java.util.stream.Collectors;
public class TpCommand extends Command implements TabProvider {
protected TpCommand(@NotNull HuskHomes implementor) {
super("tp", List.of("tpo"), "[<player|position>] [target]", implementor);
protected TpCommand(@NotNull HuskHomes plugin) {
super("tp", List.of("tpo"), "[<player|position>] [target]", plugin);
setOperatorCommand(true);
}
@@ -172,4 +172,14 @@ public class Locales {
.setSpaceBeforeFooter(false);
}
/**
* Represents where a locale should be displayed
*/
public enum DisplaySlot {
CHAT,
ACTION_BAR,
SUBTITLE,
TITLE
}
}
@@ -1,4 +1,4 @@
package net.william278.huskhomes.position;
package net.william278.huskhomes.config;
import net.william278.annotaml.YamlFile;
import net.william278.annotaml.YamlKey;
@@ -100,7 +100,7 @@ public class Settings {
private int maxPublicHomes = 10;
@YamlKey("general.stack_permission_limits")
private boolean stackPermissionLimits = true;
private boolean stackPermissionLimits = false;
@YamlKey("general.permission_restrict_warps")
private boolean permissionRestrictWarps = false;
@@ -112,7 +112,7 @@ public class Settings {
private int teleportWarmupTime = 5;
@YamlKey("general.teleport_warmup_display")
private MessageDisplayType teleportWarmupDisplay = MessageDisplayType.ACTION_BAR;
private Locales.DisplaySlot teleportWarmupDisplay = Locales.DisplaySlot.ACTION_BAR;
@YamlKey("general.teleport_request_expiry_time")
private int teleportRequestExpiryTime = 60;
@@ -249,7 +249,7 @@ public class Settings {
private boolean doMapHook = false;
@YamlKey("map_hook.map_plugin")
private MapHook.MappingPlugin mappingPlugin = MapHook.MappingPlugin.DYNMAP;
private MapHook.Plugin type = MapHook.Plugin.DYNMAP;
@YamlKey("map_hook.show_public_homes")
private boolean publicHomesOnMap = true;
@@ -351,7 +351,7 @@ public class Settings {
return teleportWarmupTime;
}
public MessageDisplayType getTeleportWarmupDisplay() {
public Locales.DisplaySlot getTeleportWarmupDisplay() {
return teleportWarmupDisplay;
}
@@ -479,15 +479,15 @@ public class Settings {
return doMapHook;
}
public MapHook.MappingPlugin getMappingPlugin() {
return mappingPlugin;
public MapHook.Plugin getMappingPlugin() {
return type;
}
public boolean isPublicHomesOnMap() {
public boolean doPublicHomesOnMap() {
return publicHomesOnMap;
}
public boolean isWarpsOnMap() {
public boolean doWarpsOnMap() {
return warpsOnMap;
}
@@ -503,16 +503,6 @@ public class Settings {
return brigadierTabCompletion;
}
/**
* Represents where a chat message should display
*/
public enum MessageDisplayType {
MESSAGE,
ACTION_BAR,
SUBTITLE,
TITLE
}
/**
* Represents the sound effect to play when an action happens
*/
@@ -37,7 +37,7 @@ public class Spawn {
*/
@NotNull
public Position getPosition(@NotNull String server) {
return new Position(x, y, z, yaw, pitch, new World(worldName, UUID.fromString(worldUuid)), server);
return Position.at(x, y, z, yaw, pitch, World.from(worldName, UUID.fromString(worldUuid)), server);
}
/**
@@ -1,6 +1,7 @@
package net.william278.huskhomes.database;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Server;
import net.william278.huskhomes.position.*;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.user.OnlineUser;
@@ -86,7 +87,7 @@ public abstract class Database {
* <b>(Internal use only)</b> - Updates position data
*
* @param positionId ID of the position to update
* @param position the new position
* @param position the Position.at
* @param connection SQL connection
* @throws SQLException if an SQL exception occurs doing this
*/
@@ -302,15 +302,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(new Home(resultSet.getDouble("x"),
userHomes.add(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -338,15 +338,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
warps.add(new Warp(resultSet.getDouble("x"),
warps.add(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -374,15 +374,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(new Home(resultSet.getDouble("x"),
userHomes.add(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -414,15 +414,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Home(resultSet.getDouble("x"),
return Optional.of(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -451,15 +451,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Home(resultSet.getDouble("x"),
return Optional.of(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -488,15 +488,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Warp(resultSet.getDouble("x"),
return Optional.of(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -522,15 +522,15 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Warp(resultSet.getDouble("x"),
return Optional.of(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -557,12 +557,12 @@ public class MySqlDatabase extends Database {
if (resultSet.next()) {
return Optional.of(Teleport.builder(plugin)
.teleporter(onlineUser)
.target(new Position(resultSet.getDouble("x"),
.target(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")))
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
@@ -640,12 +640,12 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -699,12 +699,12 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -757,12 +757,12 @@ public class MySqlDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -38,9 +38,9 @@ public class SqLiteDatabase extends Database {
private Connection connection;
public SqLiteDatabase(@NotNull HuskHomes implementor) {
super(implementor);
this.databaseFile = new File(implementor.getDataFolder(), DATABASE_FILE_NAME);
public SqLiteDatabase(@NotNull HuskHomes plugin) {
super(plugin);
this.databaseFile = new File(plugin.getDataFolder(), DATABASE_FILE_NAME);
}
private Connection getConnection() throws SQLException {
@@ -310,15 +310,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(new Home(resultSet.getDouble("x"),
userHomes.add(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -346,15 +346,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
warps.add(new Warp(resultSet.getDouble("x"),
warps.add(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -382,15 +382,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
userHomes.add(new Home(resultSet.getDouble("x"),
userHomes.add(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -422,15 +422,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Home(resultSet.getDouble("x"),
return Optional.of(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -459,15 +459,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Home(resultSet.getDouble("x"),
return Optional.of(Home.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -496,15 +496,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Warp(resultSet.getDouble("x"),
return Optional.of(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -530,15 +530,15 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Warp(resultSet.getDouble("x"),
return Optional.of(Warp.from(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name"),
new PositionMeta(resultSet.getString("name"),
PositionMeta.from(resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("timestamp").toInstant(),
resultSet.getString("tags")),
@@ -565,12 +565,12 @@ public class SqLiteDatabase extends Database {
if (resultSet.next()) {
return Optional.of(Teleport.builder(plugin)
.teleporter(onlineUser)
.target(new Position(resultSet.getDouble("x"),
.target(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")))
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
@@ -648,12 +648,12 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -705,12 +705,12 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -760,12 +760,12 @@ public class SqLiteDatabase extends Database {
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return Optional.of(new Position(resultSet.getDouble("x"),
return Optional.of(Position.at(resultSet.getDouble("x"),
resultSet.getDouble("y"),
resultSet.getDouble("z"),
resultSet.getFloat("yaw"),
resultSet.getFloat("pitch"),
new World(resultSet.getString("world_name"),
World.from(resultSet.getString("world_name"),
UUID.fromString(resultSet.getString("world_uuid"))),
resultSet.getString("server_name")));
}
@@ -1,7 +1,7 @@
package net.william278.huskhomes.hook;
import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.BlueMapWorld;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.api.markers.POIMarker;
@@ -10,14 +10,18 @@ import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.util.ThrowingConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
/**
@@ -25,148 +29,144 @@ import java.util.logging.Level;
*/
public class BlueMapHook extends MapHook {
private String publicHomeMarkerIconPath;
private String warpMarkerIconPath;
private Map<String, MarkerSet> publicHomesMarkerSets;
private Map<String, MarkerSet> warpsMarkerSets;
public BlueMapHook(@NotNull HuskHomes implementor) {
super(implementor, "BlueMap");
public BlueMapHook(@NotNull HuskHomes plugin) {
super(plugin, Plugin.BLUEMAP);
}
@Override
protected CompletableFuture<Void> initializeMap() {
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
plugin.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> {
// Create marker sets
plugin.getWorlds().forEach(world -> blueMapAPI.getWorld(world.getUuid())
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(map -> {
if (plugin.getSettings().isPublicHomesOnMap()) {
map.getMarkerSets().put(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID,
MarkerSet.builder().label("Public Homes").build());
}
if (plugin.getSettings().isWarpsOnMap()) {
map.getMarkerSets().put(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID,
MarkerSet.builder().label("Warps").build());
}
})));
public void initialize() {
BlueMapAPI.onEnable(api -> {
this.publicHomesMarkerSets = new HashMap<>();
this.warpsMarkerSets = new HashMap<>();
// Create marker icons
try {
publicHomeMarkerIconPath = blueMapAPI.getWebApp().createImage(
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png"))),
"huskhomes/" + PUBLIC_HOMES_MARKER_SET_ID + ".png");
warpMarkerIconPath = blueMapAPI.getWebApp().createImage(
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + WARP_MARKER_IMAGE_NAME + ".png"))),
"huskhomes/" + WARP_MARKER_IMAGE_NAME + ".png");
} catch (IOException e) {
plugin.log(Level.SEVERE, "Failed to create warp marker image", e);
for (World world : plugin.getWorlds()) {
this.editMapWorld(world, (mapWorld -> {
final MarkerSet publicHomeMarkers = MarkerSet.builder().label(getPublicHomesMarkerSetName()).build();
final MarkerSet warpsMarkers = MarkerSet.builder().label(getWarpsMarkerSetName()).build();
for (BlueMapMap map : mapWorld.getMaps()) {
map.getMarkerSets().put(getPublicHomesKey(), publicHomeMarkers);
map.getMarkerSets().put(getWarpsKey(), warpsMarkers);
}
publicHomesMarkerSets.put(world.getName(), publicHomeMarkers);
warpsMarkerSets.put(world.getName(), warpsMarkers);
}));
}
initializedFuture.complete(null);
this.populateMap();
});
}
@Override
public void updateHome(@NotNull Home home) {
if (!isValidPosition(home)) {
return;
}
this.editPublicHomesMarkerSet(home.getWorld(), (markerSet -> {
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
markerSet.remove(markerId);
markerSet.put(markerId, POIMarker.builder()
.label("/phome " + home.getOwner().getUsername() + "." + home.getName())
.position(home.getX(), home.getY(), home.getZ())
.maxDistance(5000)
.icon(getIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), 25, 25)
.build());
}));
return initializedFuture;
}
@Override
public CompletableFuture<Void> updateHome(@NotNull Home home) {
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
public void removeHome(@NotNull Home home) {
this.editPublicHomesMarkerSet(home.getWorld(), markerSet -> markerSet
.remove(home.getOwner().getUuid() + ":" + home.getUuid()));
return removeHome(home).thenRun(() -> BlueMapAPI.getInstance().flatMap(
blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld())).ifPresent(blueMapWorld -> blueMapWorld.getMaps()
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().put(home.getOwner().getUuid() + ":" + home.getUuid(),
POIMarker.toBuilder()
.label("/phome" + home.getOwner().getUsername() + "." + home.getMeta().getName())
.position((int) home.getX(), (int) home.getY(), (int) home.getZ())
.icon(publicHomeMarkerIconPath, Vector2i.from(25, 25))
.maxDistance(5000)
.build());
return markerSet;
}))));
}
@Override
public CompletableFuture<Void> removeHome(@NotNull Home home) {
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld()))
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().remove(home.getOwner().getUuid() + ":" + home.getUuid());
return markerSet;
})));
return CompletableFuture.completedFuture(null);
}
@Override
public void clearHomes(@NotNull User user) {
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
.forEach(blueMapWorld -> blueMapWorld.getMaps()
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().keySet().removeIf(key -> key.startsWith(user.getUuid().toString()));
return markerSet;
}))));
CompletableFuture.completedFuture(null);
if (publicHomesMarkerSets != null) {
publicHomesMarkerSets.values().forEach(markerSet -> markerSet.getMarkers().keySet()
.removeIf(markerId -> markerId.startsWith(user.getUuid().toString())));
}
}
@Override
public CompletableFuture<Void> updateWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
public void updateWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) {
return;
}
return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld()))
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().put(warp.getUuid().toString(),
POIMarker.toBuilder()
.label("/warp " + warp.getMeta().getName())
.position((int) warp.getX(), (int) warp.getY(), (int) warp.getZ())
.icon(warpMarkerIconPath, Vector2i.from(25, 25))
.maxDistance(10000)
.build());
return markerSet;
}))));
this.editWarpsMarkerSet(warp.getWorld(), (markerSet -> {
final String markerId = warp.getUuid().toString();
markerSet.remove(markerId);
markerSet.put(markerId, POIMarker.builder()
.label("/warp " + warp.getName())
.position(warp.getX(), warp.getY(), warp.getZ())
.maxDistance(5000)
.icon(getIcon(WARP_MARKER_IMAGE_NAME), 25, 25)
.build());
}));
}
@Override
public CompletableFuture<Void> removeWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld()))
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().remove(warp.getUuid().toString());
return markerSet;
})));
return CompletableFuture.completedFuture(null);
public void removeWarp(@NotNull Warp warp) {
editWarpsMarkerSet(warp.getWorld(), markerSet -> markerSet.remove(warp.getUuid().toString()));
}
@Override
public void clearWarps() {
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
.forEach(blueMapWorld -> blueMapWorld.getMaps()
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
markerSet.getMarkers().clear();
return markerSet;
}))));
CompletableFuture.completedFuture(null);
}
/**
* Get the {@link BlueMapWorld} for a world
*
* @param world The {@link World} to get the {@link BlueMapWorld} for
* @return The {@link BlueMapWorld} of the world
*/
@NotNull
private Optional<BlueMapWorld> getBlueMapWorld(@NotNull BlueMapAPI blueMapAPI, @NotNull World world) {
if (world.getUuid().equals(new UUID(0, 0))) {
return blueMapAPI.getWorld(world.getName());
} else {
return blueMapAPI.getWorld(world.getUuid());
if (warpsMarkerSets != null) {
warpsMarkerSets.values().forEach(markerSet -> markerSet.getMarkers().clear());
}
}
@Nullable
private String getIcon(@NotNull String iconName) {
return BlueMapAPI.getInstance().map(api -> {
final Path icons = api.getWebApp().getWebRoot().resolve("icons").resolve("huskhomes");
if (!icons.toFile().exists() && !icons.toFile().mkdirs()) {
plugin.log(Level.WARNING, "Failed to create BlueMap icons directory");
}
final String iconFileName = iconName + ".png";
final File iconFile = icons.resolve(iconFileName).toFile();
if (!iconFile.exists()) {
try (InputStream readIcon = plugin.getResource("markers/50x/" + iconFileName)) {
if (readIcon == null) {
throw new FileNotFoundException("Could not find icon resource: " + iconFileName);
}
Files.copy(readIcon, iconFile.toPath());
} catch (IOException e) {
plugin.log(Level.WARNING, "Failed to load icon for BlueMap hook", e);
}
}
return "icons/huskhomes/" + iconFileName;
}).orElse(null);
}
private void editPublicHomesMarkerSet(@NotNull World world, @NotNull ThrowingConsumer<MarkerSet> editor) {
editMapWorld(world, (mapWorld -> {
if (publicHomesMarkerSets != null) {
editor.accept(publicHomesMarkerSets.get(world.getName()));
}
}));
}
private void editWarpsMarkerSet(@NotNull World world, @NotNull ThrowingConsumer<MarkerSet> editor) {
editMapWorld(world, (mapWorld -> {
if (warpsMarkerSets != null) {
editor.accept(warpsMarkerSets.get(world.getName()));
}
}));
}
private void editMapWorld(@NotNull World world, @NotNull ThrowingConsumer<BlueMapWorld> editor) {
BlueMapAPI.getInstance().flatMap(api -> api.getWorld(world.getName())).ifPresent(editor);
}
}
@@ -0,0 +1,239 @@
package net.william278.huskhomes.hook;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.user.User;
import org.apache.commons.text.StringEscapeUtils;
import org.dynmap.DynmapCommonAPI;
import org.dynmap.DynmapCommonAPIListener;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* Hook to display warps and public homes on Dynmap
*/
public class DynmapHook extends MapHook {
@Nullable
private DynmapCommonAPI dynmapApi;
@Nullable
private MarkerSet publicHomesMarkers;
@Nullable
private MarkerSet warpsMarkers;
public DynmapHook(@NotNull HuskHomes plugin) {
super(plugin, Plugin.DYNMAP);
}
@Override
public void initialize() {
DynmapCommonAPIListener.register(new DynmapCommonAPIListener() {
@Override
public void apiEnabled(@NotNull DynmapCommonAPI dynmapCommonAPI) {
dynmapApi = dynmapCommonAPI;
if (plugin.getSettings().doPublicHomesOnMap()) {
getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow();
dynmapApi.getMarkerAPI().createMarkerSet(getPublicHomesKey(),
getPublicHomesMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
}
if (plugin.getSettings().doWarpsOnMap()) {
getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow();
dynmapApi.getMarkerAPI().createMarkerSet(getWarpsKey(),
getWarpsMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
}
populateMap();
}
});
}
@Override
public void updateHome(@NotNull Home home) {
if (!isValidPosition(home)) {
return;
}
plugin.runSync(() -> {
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
getPublicHomesMarkerSet().ifPresent(markerSet -> {
markerSet.getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(markerId))
.forEach(Marker::deleteMarker);
markerSet.createMarker(markerId, home.getName(), home.getWorld().getName(),
home.getX(), home.getY(), home.getZ(),
getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow(), false)
.setDescription(MarkerInformationPopup.create(home.getName())
.thumbnail(PUBLIC_HOME_MARKER_IMAGE_NAME)
.field("Owner", home.getOwner().getUsername())
.field("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60))
.field("Command", "/phome " + home.getName())
.toHtml());
});
});
}
@Override
public void removeHome(@NotNull Home home) {
plugin.runSync(() -> {
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
getPublicHomesMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(markerId))
.forEach(Marker::deleteMarker));
});
}
@Override
public void clearHomes(@NotNull User user) {
plugin.runSync(() -> getPublicHomesMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream()
.filter(marker -> marker.getMarkerID().startsWith(user.getUuid().toString()))
.forEach(Marker::deleteMarker)));
}
@Override
public void updateWarp(@NotNull Warp warp) {
if (!isValidPosition(warp)) {
return;
}
plugin.runSync(() -> {
final String markerId = warp.getUuid().toString();
getWarpsMarkerSet().ifPresent(markerSet -> {
markerSet.getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(markerId))
.forEach(Marker::deleteMarker);
markerSet.createMarker(markerId, warp.getName(), warp.getWorld().getName(),
warp.getX(), warp.getY(), warp.getZ(),
getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow(), false)
.setDescription(MarkerInformationPopup.create(warp.getName())
.thumbnail(WARP_MARKER_IMAGE_NAME)
.field("Description", plugin.getLocales().wrapText(warp.getMeta().getDescription(), 60))
.field("Command", "/phome " + warp.getName())
.toHtml());
});
});
}
@Override
public void removeWarp(@NotNull Warp warp) {
plugin.runSync(() -> {
final String markerId = warp.getUuid().toString();
getWarpsMarkerSet().ifPresent(markerSet -> markerSet.getMarkers().stream()
.filter(marker -> marker.getMarkerID().equals(markerId))
.forEach(Marker::deleteMarker));
});
}
@Override
public void clearWarps() {
plugin.runSync(() -> getWarpsMarkerSet().ifPresent(markerSet -> markerSet.getMarkers()
.forEach(Marker::deleteMarker)));
}
private Optional<DynmapCommonAPI> getDynmap() {
return Optional.ofNullable(dynmapApi);
}
private Optional<MarkerSet> getWarpsMarkerSet() {
return getDynmap().map(api -> {
warpsMarkers = api.getMarkerAPI().getMarkerSet(getWarpsKey());
if (warpsMarkers == null) {
warpsMarkers = api.getMarkerAPI().createMarkerSet(getWarpsKey(), getWarpsMarkerSetName(),
api.getMarkerAPI().getMarkerIcons(), false);
} else {
warpsMarkers.setMarkerSetLabel(getWarpsMarkerSetName());
}
return warpsMarkers;
});
}
private Optional<MarkerSet> getPublicHomesMarkerSet() {
return getDynmap().map(api -> {
publicHomesMarkers = api.getMarkerAPI().getMarkerSet(getPublicHomesKey());
if (publicHomesMarkers == null) {
publicHomesMarkers = api.getMarkerAPI().createMarkerSet(getPublicHomesKey(), getPublicHomesMarkerSetName(),
api.getMarkerAPI().getMarkerIcons(), false);
} else {
publicHomesMarkers.setMarkerSetLabel(getPublicHomesMarkerSetName());
}
return publicHomesMarkers;
});
}
private Optional<MarkerIcon> getMarkerIcon(@NotNull String imageName) {
return getDynmap().map(api -> {
MarkerIcon icon = api.getMarkerAPI().getMarkerIcon(imageName);
if (icon == null) {
icon = api.getMarkerAPI().createMarkerIcon(imageName, imageName,
plugin.getResource("markers/16x/" + imageName + ".png"));
}
return icon;
});
}
/**
* Creates an HTML Dynmap marker information popup widget
*/
private static class MarkerInformationPopup {
@NotNull
private final String title;
@Nullable
private String thumbnailMarkerId;
@NotNull
private final Map<String, String> fields;
private MarkerInformationPopup(@NotNull String title) {
this.title = title;
this.fields = new HashMap<>();
}
@NotNull
private static DynmapHook.MarkerInformationPopup create(@NotNull String title) {
return new MarkerInformationPopup(title);
}
@NotNull
private DynmapHook.MarkerInformationPopup thumbnail(@NotNull String thumbnailMarkerId) {
this.thumbnailMarkerId = thumbnailMarkerId;
return this;
}
@NotNull
private DynmapHook.MarkerInformationPopup field(@NotNull String key, @NotNull String value) {
fields.put(key, value);
return this;
}
@NotNull
private String toHtml() {
final StringBuilder html = new StringBuilder();
html.append("<div class=\"infowindow\">");
if (thumbnailMarkerId != null) {
html.append("<img src=\"/tiles/_markers_/")
.append(thumbnailMarkerId)
.append(".png\" class=\"thumbnail\"/>")
.append("&nbsp;");
}
html.append("<span style=\"font-weight: bold;\">")
.append(StringEscapeUtils.escapeHtml4(title))
.append("</span><br/>");
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
.append(StringEscapeUtils.escapeHtml4(key))
.append(": </span><span>")
.append(StringEscapeUtils.escapeHtml4(value))
.append("</span><br/>"));
return html.toString();
}
}
}
@@ -7,10 +7,10 @@ import org.jetbrains.annotations.NotNull;
/**
* A hook that provides economy features
*/
public abstract class EconomyHook extends PluginHook {
public abstract class EconomyHook extends Hook {
protected EconomyHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
super(implementor, hookName);
protected EconomyHook(@NotNull HuskHomes plugin, @NotNull String hookName) {
super(plugin, hookName);
}
/**
@@ -0,0 +1,42 @@
package net.william278.huskhomes.hook;
import net.william278.huskhomes.HuskHomes;
import org.jetbrains.annotations.NotNull;
/**
* A plugin hook, where HuskHomes hooks into another plugin
*/
public abstract class Hook {
/**
* The plugin that this hook is for
*/
protected final HuskHomes plugin;
/**
* The name of the hook
*/
protected final String name;
/**
* Construct a new {@link Hook}
*
* @param plugin the {@link HuskHomes} instance
*/
protected Hook(@NotNull HuskHomes plugin, @NotNull String name) {
this.plugin = plugin;
this.name = name;
}
/**
* Initialize the hook and return {@code true} if it could be enabled
*/
public abstract void initialize() ;
@NotNull
public String getName() {
return name;
}
}
@@ -4,64 +4,50 @@ import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.SavedPosition;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.user.User;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
/**
* A hook for a mapping plugin, such as Dynmap
*/
public abstract class MapHook extends PluginHook {
public abstract class MapHook extends Hook {
protected static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes-public-homes";
protected static final String WARPS_MARKER_SET_ID = "huskhomes-warps";
protected static final String WARP_MARKER_IMAGE_NAME = "warp";
protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home";
protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
super(implementor, hookName);
}
@Override
public final boolean initialize() {
initializeMap().thenRun(() -> {
if (plugin.getSettings().isPublicHomesOnMap()) {
plugin.getDatabase()
.getLocalPublicHomes(plugin)
.forEach(this::updateHome);
}
if (plugin.getSettings().isWarpsOnMap()) {
plugin.getDatabase()
.getLocalWarps(plugin)
.forEach(this::updateWarp);
}
});
return true;
protected MapHook(@NotNull HuskHomes plugin, @NotNull MapHook.Plugin type) {
super(plugin, type.getDisplayName());
}
/**
* Prepare the map plugin for adding homes to
*
* @return a {@link CompletableFuture} that completes when the map plugin is ready
* Populate the map with public homes and warps
*/
protected abstract CompletableFuture<Void> initializeMap();
protected void populateMap() {
if (plugin.getSettings().doPublicHomesOnMap()) {
plugin.getDatabase()
.getLocalPublicHomes(plugin)
.forEach(this::updateHome);
}
if (plugin.getSettings().doWarpsOnMap()) {
plugin.getDatabase()
.getLocalWarps(plugin)
.forEach(this::updateWarp);
}
}
/**
* Update a home, adding it to the map if it exists, or updating it on the map if it doesn't
*
* @param home the home to update
*/
@SuppressWarnings("UnusedReturnValue")
public abstract CompletableFuture<Void> updateHome(@NotNull Home home);
public abstract void updateHome(@NotNull Home home);
/**
* Removes a home from the map
*
* @param home the home to remove
*/
public abstract CompletableFuture<Void> removeHome(@NotNull Home home);
public abstract void removeHome(@NotNull Home home);
/**
* Clears homes owned by a player from the map
@@ -75,15 +61,14 @@ public abstract class MapHook extends PluginHook {
*
* @param warp the warp to update
*/
@SuppressWarnings("UnusedReturnValue")
public abstract CompletableFuture<Void> updateWarp(@NotNull Warp warp);
public abstract void updateWarp(@NotNull Warp warp);
/**
* Removes a warp from the map
*
* @param warp the warp to remove
*/
public abstract CompletableFuture<Void> removeWarp(@NotNull Warp warp);
public abstract void removeWarp(@NotNull Warp warp);
/**
* Clears all warps from the map
@@ -98,30 +83,55 @@ public abstract class MapHook extends PluginHook {
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
protected final boolean isValidPosition(@NotNull SavedPosition position) {
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) return false;
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) return false;
try {
return position.getServer().equals(plugin.getServerName());
} catch (IllegalStateException e) {
return plugin.getWorlds().stream()
.map(World::getUuid)
.anyMatch(uuid -> uuid.equals(position.getWorld().getUuid()));
if (position instanceof Warp && !plugin.getSettings().doWarpsOnMap()) {
return false;
}
if (position instanceof Home && !plugin.getSettings().doPublicHomesOnMap()) {
return false;
}
return !plugin.getSettings().isCrossServer() || position.getServer().equals(plugin.getServerName());
}
@NotNull
protected final String getPublicHomesKey() {
return plugin.getKey(getName().toLowerCase(), "public_home_markers").toString();
}
@NotNull
protected final String getWarpsKey() {
return plugin.getKey(getName().toLowerCase(), "warp_markers").toString();
}
@NotNull
protected final String getPublicHomesMarkerSetName() {
return plugin.getLocales().getRawLocale("map_hook_public_homes_marker_set_name")
.orElse("Public Homes");
}
@NotNull
protected final String getWarpsMarkerSetName() {
return plugin.getLocales().getRawLocale("map_hook_warps_marker_set_name")
.orElse("Warps");
}
/**
* Identifies types of supported Map plugins
*/
public enum MappingPlugin {
public enum Plugin {
DYNMAP("Dynmap"),
BLUEMAP("BlueMap");
@NotNull
public final String displayName;
private final String displayName;
MappingPlugin(@NotNull String displayName) {
Plugin(@NotNull String displayName) {
this.displayName = displayName;
}
@NotNull
public String getDisplayName() {
return displayName;
}
}
}
@@ -20,7 +20,7 @@ import java.util.logging.Level;
/**
* Hooks into Plan to provide the {@link PlanDataExtension} with stats on the web panel
*/
public class PlanHook extends PluginHook {
public class PlanHook extends Hook {
private final HuskHomes plugin;
@@ -30,13 +30,12 @@ public class PlanHook extends PluginHook {
}
@Override
public boolean initialize() {
public void initialize() {
if (!areAllCapabilitiesAvailable()) {
return false;
return;
}
registerDataExtension();
handlePlanReload();
return true;
}
@@ -1,44 +0,0 @@
package net.william278.huskhomes.hook;
import net.william278.huskhomes.HuskHomes;
import org.jetbrains.annotations.NotNull;
/**
* A plugin hook, where HuskHomes hooks into another plugin
*/
public abstract class PluginHook {
/**
* The plugin that this hook is for
*/
protected final HuskHomes plugin;
/**
* The name of the hook
*/
protected final String hookName;
/**
* Construct a new {@link PluginHook}
*
* @param implementor the {@link HuskHomes} instance
*/
protected PluginHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
this.plugin = implementor;
this.hookName = hookName;
}
/**
* Initialize the hook and return {@code true} if it could be enabled
*
* @return {@code true} if the hook could be enabled
*/
public abstract boolean initialize() ;
@NotNull
public String getHookName() {
return hookName;
}
}
@@ -22,8 +22,8 @@ public class EventListener {
@NotNull
protected final HuskHomes plugin;
protected EventListener(@NotNull HuskHomes implementor) {
this.plugin = implementor;
protected EventListener(@NotNull HuskHomes plugin) {
this.plugin = plugin;
}
/**
@@ -89,11 +89,18 @@ public class EventListener {
if (teleport.getType() == Teleport.Type.RESPAWN) {
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
if (bedPosition.isEmpty()) {
plugin.getLocalCachedSpawn()
.map(spawn -> spawn.getPosition(plugin.getServerName()))
.ifPresent(position -> teleporter.teleportLocally(position,
plugin.getSettings().isAsynchronousTeleports()));
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
plugin.getSpawn().ifPresent(spawn -> {
if (plugin.getSettings().isCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
plugin.runLater(() -> Teleport.builder(plugin)
.teleporter(teleporter)
.target(spawn)
.updateLastPosition(false)
.toTeleport().execute(), 40L);
} else {
teleporter.teleportLocally(spawn, plugin.getSettings().isAsynchronousTeleports());
}
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
});
} else {
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
}
@@ -104,8 +111,7 @@ public class EventListener {
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
plugin.getDatabase().setCurrentTeleport(teleporter, null);
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(teleporter::sendMessage);
teleport.displayTeleportingComplete(teleporter);
});
}
@@ -146,7 +152,7 @@ public class EventListener {
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
// Set the player's last position to where they died
if (plugin.getSettings().isBackCommandReturnByDeath()
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
plugin.getDatabase().setLastPosition(onlineUser, onlineUser.getPosition());
}
}
@@ -160,8 +166,8 @@ public class EventListener {
plugin.runAsync(() -> {
// Display the return by death via /back notification
if (plugin.getSettings().isBackCommandReturnByDeath()
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
plugin.getLocales().getLocale("return_by_death_notification")
.ifPresent(onlineUser::sendMessage);
}
@@ -150,7 +150,7 @@ public class HomesManager {
existing.update(position);
return existing;
})
.orElse(new Home(position, new PositionMeta(name, ""), owner));
.orElse(Home.from(position, PositionMeta.create(name, ""), owner));
plugin.getDatabase().saveHome(home);
this.cacheHome(home, true);
}
@@ -248,10 +248,6 @@ public class HomesManager {
}
public void setHomePrivacy(@NotNull Home home, boolean isPublic) {
if (isPublic == home.isPublic()) {
return;
}
if (isPublic && home.getOwner() instanceof OnlineUser online) {
final int publicHomes = plugin.getDatabase().getHomes(home.getOwner()).stream()
.filter(Home::isPublic)
@@ -91,7 +91,7 @@ public class WarpsManager {
existing.setPitch(position.getPitch());
return existing;
})
.orElse(new Warp(position, new PositionMeta(name, "")));
.orElse(Warp.from(position, PositionMeta.create(name, "")));
plugin.getDatabase().saveWarp(warp);
this.cacheWarp(warp, true);
}
@@ -122,16 +122,16 @@ public class WarpsManager {
return deleted;
}
public void relocateWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
public void setWarpPosition(@NotNull String name, @NotNull Position position) throws ValidationException {
final Optional<Warp> optionalWarp = plugin.getDatabase().getWarp(name);
if (optionalWarp.isEmpty()) {
throw new ValidationException(ValidationException.Type.NOT_FOUND);
}
this.relocateWarp(optionalWarp.get(), position);
this.setWarpPosition(optionalWarp.get(), position);
}
public void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
public void setWarpPosition(@NotNull Warp warp, @NotNull Position position) {
warp.update(position);
plugin.getDatabase().saveWarp(warp);
this.cacheWarp(warp, true);
@@ -13,19 +13,30 @@ public class Home extends SavedPosition {
private final User owner;
private boolean isPublic;
public Home(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
private Home(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
this.owner = owner;
this.setPublic(isPublic);
}
public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
private Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
super(position, meta);
this.owner = owner;
this.setPublic(false);
}
@NotNull
public static Home from(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
return new Home(x, y, z, yaw, pitch, world, server, positionMeta, uuid, owner, isPublic);
}
@NotNull
public static Home from(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
return new Home(position, meta, owner);
}
/**
* The {@link User} who owns this home
*/
@@ -1,30 +1,26 @@
package net.william278.huskhomes.position;
import com.google.gson.annotations.Expose;
import org.jetbrains.annotations.NotNull;
/**
* Represents a local position on this server
*/
public class Location {
@Expose
private double x;
@Expose
private double y;
@Expose
private double z;
@Expose
private float yaw;
@Expose
private float pitch;
@Expose
private World world;
public Location(double x, double y, double z, @NotNull World world) {
this.setX(x);
this.setY(y);
this.setZ(z);
this.setYaw(0);
this.setPitch(0);
this.setWorld(world);
}
public Location(double x, double y, double z, float yaw, float pitch,
@NotNull World world) {
protected Location(double x, double y, double z, float yaw, float pitch, @NotNull World world) {
this.setX(x);
this.setY(y);
this.setZ(z);
@@ -36,6 +32,16 @@ public class Location {
public Location() {
}
@NotNull
public static Location at(double x, double y, double z, float yaw, float pitch, @NotNull World world) {
return new Location(x, y, z, yaw, pitch, world);
}
@NotNull
public static Location at(double x, double y, double z, @NotNull World world) {
return Location.at(x, y, z, 0, 0, world);
}
/**
* Update the position to match that of another position
*
@@ -1,5 +1,6 @@
package net.william278.huskhomes.position;
import com.google.gson.annotations.Expose;
import net.william278.huskhomes.teleport.Target;
import org.jetbrains.annotations.NotNull;
@@ -8,15 +9,15 @@ import org.jetbrains.annotations.NotNull;
*/
public class Position extends Location implements Target {
@Expose
private String server;
public Position(double x, double y, double z, float yaw, float pitch,
@NotNull World world, @NotNull String server) {
protected Position(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server) {
super(x, y, z, yaw, pitch, world);
this.setServer(server);
}
public Position(@NotNull Location location, @NotNull String server) {
protected Position(@NotNull Location location, @NotNull String server) {
super(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), location.getWorld());
this.setServer(server);
}
@@ -25,6 +26,21 @@ public class Position extends Location implements Target {
private Position() {
}
@NotNull
public static Position at(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server) {
return new Position(x, y, z, yaw, pitch, world, server);
}
@NotNull
public static Position at(double x, double y, double z, @NotNull World world, @NotNull String server) {
return Position.at(x, y, z, 0, 0, world, server);
}
@NotNull
public static Position at(@NotNull Location location, @NotNull String server) {
return new Position(location, server);
}
@Override
public void update(@NotNull Position newPosition) {
super.update(newPosition);
@@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
@@ -16,24 +15,27 @@ import java.util.Optional;
public class PositionMeta {
private String name;
@Nullable
private String description;
private Map<String, String> tags;
private Instant creationTime;
public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime,
@Nullable String serializedTags) {
private PositionMeta(@NotNull String name, @NotNull String description,
@NotNull Instant creationTime, @Nullable String serializedTags) {
this.setName(name);
this.setDescription(description);
this.setCreationTime(creationTime);
this.setTags(deserializeTags(serializedTags));
}
public PositionMeta(@NotNull String name, @NotNull String description) {
this.setName(name);
this.setDescription(description);
this.setCreationTime(Instant.now());
this.setTags(new HashMap<>());
@NotNull
public static PositionMeta from(@NotNull String name, @NotNull String description,
@NotNull Instant creationTime, @Nullable String serializedTags) {
return new PositionMeta(name, description, creationTime, serializedTags);
}
@NotNull
public static PositionMeta create(@NotNull String name, @NotNull String description) {
return PositionMeta.from(name, description, Instant.now(), "");
}
/**
@@ -42,6 +44,7 @@ public class PositionMeta {
* @param serializedTags The JSON string to deserialize
* @return The deserialized {@link Map}
*/
@NotNull
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
try {
if (serializedTags == null || serializedTags.isBlank()) {
@@ -89,7 +92,7 @@ public class PositionMeta {
*/
@NotNull
public String getDescription() {
return Optional.ofNullable(description).orElse("");
return description;
}
public void setDescription(@Nullable String description) {
@@ -12,9 +12,8 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
private PositionMeta meta;
private final UUID uuid;
protected SavedPosition(double x, double y, double z, float yaw, float pitch,
@NotNull World world, @NotNull String server,
@NotNull PositionMeta meta, @NotNull UUID uuid) {
protected SavedPosition(double x, double y, double z, float yaw, float pitch, @NotNull World world,
@NotNull String server, @NotNull PositionMeta meta, @NotNull UUID uuid) {
super(x, y, z, yaw, pitch, world, server);
this.setMeta(meta);
this.uuid = uuid;
@@ -11,9 +11,8 @@ public class Warp extends SavedPosition {
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
public Warp(double x, double y, double z, float yaw, float pitch,
@NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
private Warp(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
}
@@ -23,10 +22,19 @@ public class Warp extends SavedPosition {
* @param position The {@link Position} to save as a warp
* @param meta {@link PositionMeta} information about this position
*/
public Warp(@NotNull Position position, @NotNull PositionMeta meta) {
private Warp(@NotNull Position position, @NotNull PositionMeta meta) {
super(position, meta);
}
public static Warp from(double x, double y, double z, float yaw, float pitch, @NotNull World world,
@NotNull String server, @NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
return new Warp(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
}
public static Warp from(@NotNull Position position, @NotNull PositionMeta meta) {
return new Warp(position, meta);
}
@NotNull
public static String getPermission(@NotNull String warpName) {
return PERMISSION_PREFIX + warpName.toLowerCase();
@@ -16,12 +16,7 @@ public class World {
@Nullable
private Environment environment;
public World(@NotNull String name, @NotNull UUID uuid) {
this.setName(name);
this.setUuid(uuid);
}
public World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
private World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
this.setName(name);
this.setUuid(uuid);
this.setEnvironment(environment);
@@ -31,14 +26,25 @@ public class World {
public World() {
}
@NotNull
public static World from(@NotNull String name, @NotNull UUID uuid, @NotNull Environment environment) {
return new World(name, uuid, environment);
}
@NotNull
public static World from(@NotNull String name, @NotNull UUID uuid) {
return new World(name, uuid, null);
}
/**
* The name of this world, as defined by the world directory name
*/
@NotNull
public String getName() {
return name;
}
public void setName(String name) {
public void setName(@NotNull String name) {
this.name = name;
}
@@ -50,13 +56,15 @@ public class World {
return uuid;
}
public void setUuid(UUID uuid) {
public void setUuid(@NotNull UUID uuid) {
this.uuid = uuid;
}
/**
* Environment of the world ({@link Environment#OVERWORLD}, {@link Environment#NETHER}, {@link Environment#THE_END},
* or {@link Environment#CUSTOM})
* <p>
* Will return {@link Environment#OVERWORLD} if the environment is null
*/
@NotNull
public Environment getEnvironment() {
@@ -13,19 +13,19 @@ import java.util.concurrent.CompletableFuture;
/**
* A random teleport engine that uses a Gaussian normal distribution to generate random positions.
*/
public class NormalDistributionEngine extends RandomTeleportEngine {
public final class NormalDistributionEngine extends RandomTeleportEngine {
protected final int radius;
protected final int spawnRadius;
private final int radius;
private final int spawnRadius;
private final float mean;
private final float standardDeviation;
public NormalDistributionEngine(@NotNull HuskHomes implementor) {
super(implementor, "Normal Distribution");
this.radius = implementor.getSettings().getRtpRadius();
this.spawnRadius = implementor.getSettings().getRtpSpawnRadius();
this.mean = implementor.getSettings().getRtpDistributionMean();
this.standardDeviation = implementor.getSettings().getRtpDistributionStandardDeviation();
public NormalDistributionEngine(@NotNull HuskHomes plugin) {
super(plugin, "Normal Distribution");
this.radius = plugin.getSettings().getRtpRadius();
this.spawnRadius = plugin.getSettings().getRtpSpawnRadius();
this.mean = plugin.getSettings().getRtpDistributionMean();
this.standardDeviation = plugin.getSettings().getRtpDistributionStandardDeviation();
}
/**
@@ -36,7 +36,7 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
* @return A generated location
*/
@NotNull
protected static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
public static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
float spawnRadius, float maxRadius) {
// Generate random values
final float radius = getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
@@ -46,7 +46,12 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
final float z = (float) (radius * Math.cos(angle));
final float x = (float) (radius * Math.sin(angle));
return new Location(Math.round(origin.getX()) + x, 128d, Math.round(origin.getZ()) + z, origin.getWorld());
return Location.at(
Math.round(origin.getX()) + x,
128d,
Math.round(origin.getZ()) + z,
origin.getWorld()
);
}
/**
@@ -57,7 +62,7 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
*/
private CompletableFuture<Optional<Location>> generateSafeLocation(@NotNull World world) {
return plugin.resolveSafeGroundLocation(generateLocation(
getOrigin(world), mean, standardDeviation, spawnRadius, radius));
getCenterPoint(world), mean, standardDeviation, spawnRadius, radius));
}
/**
@@ -90,10 +95,11 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
int attempts = 0;
while (location.isEmpty()) {
location = generateSafeLocation(world).join();
if (attempts > randomTimeout) {
if (attempts >= maxAttempts) {
return Optional.empty();
}
attempts++;
}
return location.map(resolved -> new Position(resolved, plugin.getServerName()));
return location.map(resolved -> Position.at(resolved, plugin.getServerName()));
}
}
@@ -12,19 +12,9 @@ import java.util.Optional;
*/
public abstract class RandomTeleportEngine {
@NotNull
protected final HuskHomes plugin;
/**
* The name of the random teleport engine
*/
@NotNull
public final String name;
/**
* How many attempts to allow {@link #getRandomPosition} lookups before timing out
*/
public long randomTimeout = 8;
public long maxAttempts = 12;
/**
* Constructor for a random teleport engine
@@ -37,15 +27,21 @@ public abstract class RandomTeleportEngine {
this.name = name;
}
@NotNull
public final String getName() {
return name;
}
/**
* Get the origin position (spawn) of this server
*
* @return The origin position
*/
protected final Position getOrigin(@NotNull World world) {
@NotNull
protected Position getCenterPoint(@NotNull World world) {
return plugin.getLocalCachedSpawn()
.map(s -> s.getPosition(plugin.getServerName()))
.orElse(new Position(0d, 128d, 0d, 0f, 0f,
.orElse(Position.at(0d, 128d, 0d, 0f, 0f,
world, plugin.getServerName()));
}
@@ -56,7 +52,7 @@ public abstract class RandomTeleportEngine {
* @param world The world to find a random position in
* @param args The arguments to pass to the random teleport engine
* @return The position, optionally, which will be empty if the random teleport engine timed out after a
* {@link #randomTimeout configured number of attempts}
* {@link #maxAttempts configured number of attempts}
*/
public abstract Optional<Position> getRandomPosition(@NotNull World world, @NotNull String[] args);
@@ -1,6 +1,7 @@
package net.william278.huskhomes.teleport;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.event.ITeleportEvent;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.network.Message;
@@ -85,8 +86,7 @@ public class Teleport {
fireEvent((event) -> {
executeEconomyActions();
teleporter.teleportLocally(localTarget.get().getPosition(), async);
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(teleporter::sendMessage);
this.displayTeleportingComplete(teleporter);
});
return;
}
@@ -98,8 +98,7 @@ public class Teleport {
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
.target(username.name())
.build().send(plugin.getMessenger(), executor);
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(teleporter::sendMessage);
this.displayTeleportingComplete(teleporter);
});
return;
}
@@ -111,10 +110,9 @@ public class Teleport {
executeEconomyActions();
final Position target = (Position) this.target;
if (plugin.getSettings().isCrossServer() && target.getServer().equals(plugin.getServerName())) {
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
teleporter.teleportLocally(target, async);
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(teleporter::sendMessage);
this.displayTeleportingComplete(teleporter);
return;
}
@@ -123,10 +121,6 @@ public class Teleport {
});
}
private void teleport(@NotNull OnlineUser teleporter, @NotNull Position target) {
}
@NotNull
private Optional<OnlineUser> resolveLocalTeleporter() throws TeleportationException {
if (this.teleporter instanceof Username username) {
@@ -135,6 +129,13 @@ public class Teleport {
return Optional.of((OnlineUser) this.teleporter);
}
public void displayTeleportingComplete(@NotNull OnlineUser teleporter) {
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(teleporter::sendMessage);
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED)
.ifPresent(teleporter::playSound);
}
// Fire the teleport event
private void fireEvent(@NotNull Consumer<ITeleportEvent> afterFired) {
plugin.fireEvent(plugin.getTeleportEvent(this), afterFired);
@@ -132,12 +132,7 @@ public class TimedTeleport extends Teleport {
}
private void sendStatusMessage(@NotNull MineDown message) {
switch (plugin.getSettings().getTeleportWarmupDisplay()) {
case ACTION_BAR -> teleporter.sendActionBar(message);
case SUBTITLE -> teleporter.sendTitle(message, true);
case TITLE -> teleporter.sendTitle(message, false);
case MESSAGE -> teleporter.sendMessage(message);
}
teleporter.sendMessage(message, plugin.getSettings().getTeleportWarmupDisplay());
}
private boolean hasTeleporterMoved() {
@@ -8,6 +8,7 @@ import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.TitlePart;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleportable;
@@ -98,6 +99,24 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
.replace().toComponent());
}
/**
* Dispatch a MineDown-formatted message to this player
*
* @param mineDown the parsed {@link MineDown} to send
* @param slot the {@link Locales.DisplaySlot} to send the message to
*/
public final void sendMessage(@NotNull MineDown mineDown, @NotNull Locales.DisplaySlot slot) {
if (slot == Locales.DisplaySlot.CHAT) {
sendMessage(mineDown);
} else if (slot == Locales.DisplaySlot.ACTION_BAR) {
sendActionBar(mineDown);
} else if (slot == Locales.DisplaySlot.TITLE) {
sendTitle(mineDown, false);
} else if (slot == Locales.DisplaySlot.SUBTITLE) {
sendTitle(mineDown, true);
}
}
/**
* Dispatch a Minecraft translatable keyed-message to this player
*
@@ -144,6 +163,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
/**
* Send a plugin message to the user
*
* @param channel channel to send it on
* @param message byte array of message data
*/
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Spent %1% to make your home public.](gray
economy_action_random_teleport: '[ℹ Spent %1% to randomly teleport.](gray)'
economy_action_back_command: '[ℹ Spent %1% to return to your last position.](gray)'
return_by_death_notification: '[Return to where you died?](gray) [[⏪ Teleport…]](#00fb9a show_text=&#00fb9a&Click to teleport\n&7Return to where you died run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ %1% für das Setzen deines Homes auf öff
economy_action_random_teleport: '[ℹ %1% ausgegeben, um zufällig teleportiert zu werden.](gray)'
economy_action_back_command: '[ℹ %1% ausgegeben, um zu deiner letzten Position zurückzukehren.](gray)'
return_by_death_notification: '[Dorthin zurückkehren, wo du gestorben bist?](gray) [[⏪ Teleportieren…]](#00fb9a show_text=&#00fb9a&Klicke, um dich zu teleportieren\n&7Kehre dorthin zurück, wo du gestorben bist run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Fehler:](#ff3300) [Du hast bereits ein Home mit diesem Namen gesetzt.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Spent %1% to make your home public.](gray
economy_action_random_teleport: '[ℹ Spent %1% to randomly teleport.](gray)'
economy_action_back_command: '[ℹ Spent %1% to return to your last position.](gray)'
return_by_death_notification: '[Return to where you died?](gray) [[⏪ Teleport…]](#00fb9a show_text=&#00fb9a&Click to teleport\n&7Return to where you died run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Paga %1% Para hacer tu casa pública.](gr
economy_action_random_teleport: '[ℹ Paga %1% para teletransportarse aleatoriamente.](gray)'
economy_action_back_command: '[ℹ Paga %1% para volver a su última posición.](gray)'
return_by_death_notification: '[¿Regresar al lugar donde murió?](gray) [[⏪ Teletransportar…]](#00fb9a show_text=&#00fb9a&Clic para teletransportarte\n&7Regresa al lugar donde moriste run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Error:](#ff3300) [Ya tienes una casa con ese nombre.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Hai pagato %1% per impostare la tua home
economy_action_random_teleport: '[ℹ Hai pagato %1% per teletrasportarti randomicamente.](gray)'
economy_action_back_command: '[ℹ Hai pagato %1% per tornare alla posizione precedente.](gray)'
return_by_death_notification: '[Vuoi ritornare dove sei morto?](gray) [[⏪ Teletrasportati…]](#00fb9a show_text=&#00fb9a&Clicca per teletrasportarti\n&7e tornare dove sei morto run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Errore:](#ff3300) [Hai già una home impostata con quel nome.](#ff7e5e)'
+2
View File
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Spent %1% to make your home public.](gray
economy_action_random_teleport: '[ℹ Spent %1% to randomly teleport.](gray)'
economy_action_back_command: '[ℹ Spent %1% to return to your last position.](gray)'
return_by_death_notification: '[Return to where you died?](gray) [[⏪ Teleport…]](#00fb9a show_text=&#00fb9a&Click to teleport\n&7Return to where you died run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Evinizi herkese açık hale getirmek içi
economy_action_random_teleport: '[ℹ Rastgele ışınlanmak için %1% harcadınız.](gray)'
economy_action_back_command: '[ℹ Son konumunuza dönmek için %1% harcadınız.](gray)'
return_by_death_notification: '[Öldüğün yere dön?](gray) [[⏪ Işınlanma…]](#00fb9a show_text=&#00fb9a&Işınlanmak için tıklayın\n&7Öldüğün yere dön run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Hata:](#ff3300) [Bu ada sahip bir eviniz zaten var.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ Spent %1% to make your home public.](gray
economy_action_random_teleport: '[ℹ Spent %1% to randomly teleport.](gray)'
economy_action_back_command: '[ℹ Spent %1% to return to your last position.](gray)'
return_by_death_notification: '[Return to where you died?](gray) [[⏪ Teleport…]](#00fb9a show_text=&#00fb9a&Click to teleport\n&7Return to where you died run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ 花费 %1% 将家设为公开.](gray)'
economy_action_random_teleport: '[ℹ 花费 %1% 使用随机传送.](gray)'
economy_action_back_command: '[ℹ 花费 %1% 回到上一位置.](gray)'
return_by_death_notification: '[回到上一个位置?](gray) [[⏪ 点击传送…]](#00fb9a show_text=&#00fb9a&点击传送\n&7返回上一位置 run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[错误:](#ff3300) [已有一个相同名称的家.](#ff7e5e)'
@@ -94,6 +94,8 @@ economy_action_make_home_public: '[ℹ 花費 %1% 將家設為公開.](gray)'
economy_action_random_teleport: '[ℹ 花費 %1% 使用隨機傳送.](gray)'
economy_action_back_command: '[ℹ 花費 %1% 回到上一位置.](gray)'
return_by_death_notification: '[回到上一個位置?](gray) [[⏪ 傳送…]](#00fb9a show_text=&#00fb9a&點擊傳送\n&7返回上一位置 run_command=/huskhomes:back)'
map_hook_public_homes_marker_set_name: 'Public Homes'
map_hook_warps_marker_set_name: 'Warps'
up_to_date: '[HuskHomes](#00fb9a bold) [| You are running the latest version of HuskHomes (v%1%).](#00fb9a)'
update_available: '[HuskHomes](#ff7e5e bold) [| A new version of HuskHomes is available: v%1% (running: v%2%).](#ff7e5e)'
error_home_name_taken: '[錯誤:](#ff3300) [已有一個相同名稱的家.](#ff7e5e)'
@@ -28,8 +28,8 @@ public class MessageSerializationTests {
.type(Message.Type.TELEPORT_REQUEST)
.target("TestTarget")
.payload(Payload.withPosition(
new Position(63.25, 127.43, -32, 180f, -94.3f,
new World("TestWorld", UUID.randomUUID()), "TestServer")))
Position.at(63.25, 127.43, -32, 180f, -94.3f,
World.from("TestWorld", UUID.randomUUID()), "TestServer")))
.build(),
Message.builder()
.type(Message.Type.TELEPORT_TO_NETWORKED_USER)
@@ -45,8 +45,8 @@ public class MessageSerializationTests {
.type(Message.Type.TELEPORT_TO_POSITION)
.target("TestTarget")
.payload(Payload.withPosition(
new Position(63.25, 127.43, -32, 180f, -94.3f,
new World("TestWorld", UUID.randomUUID()), "TestServer")))
Position.at(63.25, 127.43, -32, 180f, -94.3f,
World.from("TestWorld", UUID.randomUUID()), "TestServer")))
.build()
);
@@ -86,7 +86,7 @@ public class NormalDistributionTests {
final List<Location> locations = new ArrayList<>();
for (int i = 0; i < amount; i++) {
locations.add(NormalDistributionEngine.generateLocation(
new Location(0, 0, 0, 0, 0, new World("TestWorld", UUID.randomUUID())),
Location.at(0, 0, 0, 0, 0, World.from("TestWorld", UUID.randomUUID())),
MEAN, STANDARD_DEVIATION, SPAWN_RADIUS, MAX_RADIUS));
}
return locations;