mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Fix #143
This commit is contained in:
1 parent
415f892035
commit
b67b66a2b0
8 files changed
+156
-99
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.William278</groupId>
|
||||
<artifactId>HuskHomes</artifactId>
|
||||
<version>2.12-dev</version>
|
||||
<version>2.12</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HuskHomes</name>
|
||||
@@ -16,7 +16,6 @@
|
||||
<properties>
|
||||
<java.version>16</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<jedis.version>4.1.1</jedis.version>
|
||||
</properties>
|
||||
|
||||
<pluginRepositories>
|
||||
@@ -31,7 +30,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
<version>3.10.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -40,25 +39,29 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.jetbrains</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.annotations</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.hikaricp</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.papermc</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.themoep.minedown</pattern>
|
||||
<pattern>de.themoep</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.minedown</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>me.william278.huskhomes2.libraries.hikari</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -80,6 +83,7 @@
|
||||
<configuration>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
<additionalJOption>-Xdoclint:none</additionalJOption>
|
||||
<encoding>UTF-8</encoding>
|
||||
<staleDataPath>
|
||||
${project.build.directory}/javadoc-bundle-options/maven-javadoc-plugin-stale-data.txt
|
||||
</staleDataPath>
|
||||
@@ -189,7 +193,7 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis.version}</version>
|
||||
<version>4.1.1</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package me.william278.huskhomes2.api;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
@@ -13,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
@@ -117,18 +117,6 @@ public class HuskHomesAPI {
|
||||
return getHomes(player).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of homes a player can set
|
||||
*
|
||||
* @param player the Player being checked
|
||||
* @return the maximum homes a player can set
|
||||
* @deprecated Use getMaxSetHomes instead (capitalized H)
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxSethomes(Player player) {
|
||||
return getMaxSetHomes(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of homes a player can set
|
||||
*
|
||||
@@ -139,18 +127,6 @@ public class HuskHomesAPI {
|
||||
return Home.getSetHomeLimit(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of homes a player can set
|
||||
*
|
||||
* @param player the Player being checked
|
||||
* @return the maximum homes a player can set
|
||||
* @deprecated Use getFreeSetHomes instead (capitalized H)
|
||||
*/
|
||||
@Deprecated
|
||||
public int getFreeSethomes(Player player) {
|
||||
return getFreeSetHomes(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of homes a player can set for free
|
||||
*
|
||||
@@ -211,13 +187,30 @@ public class HuskHomesAPI {
|
||||
return getWarps().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@link Optional} that will contain the spawn position set on the server, as a {@link TeleportationPoint}.
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>To check if the spawn position is present: {@code #getServerSpawnPosition().isPresent()}</li>
|
||||
* <li>To get the spawn position, if it is present: {@code #getServerSpawnPosition().get()}</li>
|
||||
* <li>To get a runnable, if it is present: {@code #getServerSpawnPosition().get()}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return an {@link Optional} that will contain the server's {@link TeleportationPoint} spawn position if it has been set (empty otherwise)
|
||||
*/
|
||||
public Optional<TeleportationPoint> getServerSpawnPosition() {
|
||||
return TeleportManager.getSpawnLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current spawn position as a TeleportationPoint
|
||||
*
|
||||
* @return the spawn position as a TeleportationPoint
|
||||
* @return the spawn position as a {@link TeleportationPoint}; {@code null otherwise}
|
||||
* @deprecated Use {@link #getServerSpawnPosition()} that returns an {@code Optional<TeleportationPoint>} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public TeleportationPoint getSpawnPosition() {
|
||||
return TeleportManager.getSpawnLocation();
|
||||
return TeleportManager.getSpawnLocation().isPresent() ? TeleportManager.getSpawnLocation().get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,12 +230,11 @@ public class HuskHomesAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a specific TeleportationPoint
|
||||
* Teleport a {@link Player} to a specific {@link TeleportationPoint}
|
||||
*
|
||||
* @param player The player to be teleported
|
||||
* @param point The target teleportationPoint
|
||||
* @param timed Whether to do a warmup countdown
|
||||
* @see TeleportationPoint
|
||||
* @param player The {@link Player} to be teleported
|
||||
* @param point The target {@link TeleportationPoint}
|
||||
* @param timed Whether the teleport should be timed; have a warmup countdown
|
||||
*/
|
||||
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
@@ -255,12 +247,11 @@ public class HuskHomesAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a specific TeleportationPoint
|
||||
* Teleport a {@link Player} to a specific {@link TeleportationPoint}
|
||||
*
|
||||
* @param player The player to be teleported
|
||||
* @param targetPlayerName The target player's name
|
||||
* @param timed Whether to do a warmup countdown
|
||||
* @see TeleportationPoint
|
||||
* @param player The {@link Player} to be teleported
|
||||
* @param targetPlayerName The target {@link Player}'s username
|
||||
* @param timed Whether the teleport should be timed; have a warmup countdown
|
||||
*/
|
||||
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.william278.huskhomes2.commands;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.util.MessageManager;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
import me.william278.huskhomes2.util.MessageManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -32,12 +32,9 @@ public class SpawnCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
// Server-based spawn teleport
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_spawn_undefined");
|
||||
}
|
||||
// Teleport the player to spawn if it has been set
|
||||
TeleportManager.getSpawnLocation().ifPresentOrElse(teleportationPoint -> TeleportManager.queueTimedTeleport(p, teleportationPoint),
|
||||
() -> MessageManager.sendMessage(p, "error_spawn_undefined"));
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An exception occurred returning back to spawn");
|
||||
}
|
||||
|
||||
@@ -77,6 +77,9 @@ public class Settings {
|
||||
// Vanished player checks
|
||||
private boolean checkVanishedPlayers;
|
||||
|
||||
// Use PaperLib if available
|
||||
private boolean usePaperLibIfAvailable;
|
||||
|
||||
// Time and maximum home settings
|
||||
private int maximumHomes;
|
||||
private int teleportRequestExpiryTime;
|
||||
@@ -253,6 +256,8 @@ public class Settings {
|
||||
|
||||
this.checkVanishedPlayers = config.getBoolean("handle_vanished_players", true);
|
||||
|
||||
this.usePaperLibIfAvailable = config.getBoolean("general.use_paperlib_if_available", true);
|
||||
|
||||
this.doSpawnCommand = config.getBoolean("spawn_command.enabled", true);
|
||||
this.doCrossServerSpawn = config.getBoolean("spawn_command.bungee_network_spawn.enabled", false);
|
||||
this.crossServerSpawnWarpName = config.getString("spawn_command.bungee_network_spawn.warp_name", "Spawn");
|
||||
@@ -454,14 +459,17 @@ public class Settings {
|
||||
public int getWarpsPerPage() {
|
||||
return warpsPerPage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sound getTeleportationCompleteSound() {
|
||||
return teleportationCompleteSound;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sound getTeleportWarmupSound() {
|
||||
return teleportWarmupSound;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sound getTeleportCancelledSound() {
|
||||
return teleportCancelledSound;
|
||||
@@ -523,9 +531,13 @@ public class Settings {
|
||||
return redisPassword;
|
||||
}
|
||||
|
||||
public boolean getRedisSSL() { return redisSSL; }
|
||||
public boolean getRedisSSL() {
|
||||
return redisSSL;
|
||||
}
|
||||
|
||||
public boolean getDoBackCommand() { return doBackCommand; }
|
||||
public boolean getDoBackCommand() {
|
||||
return doBackCommand;
|
||||
}
|
||||
|
||||
public int getHikariMaximumPoolSize() {
|
||||
return hikariMaximumPoolSize;
|
||||
@@ -555,14 +567,33 @@ public class Settings {
|
||||
return homeLimitPermissionStacking;
|
||||
}
|
||||
|
||||
public boolean doUsePaperLibIfAvailable() {
|
||||
return usePaperLibIfAvailable;
|
||||
}
|
||||
|
||||
public DisplayStyle getWarmupDisplayStyle() {
|
||||
return teleportWarmupDisplayStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to define where messages should appear
|
||||
*/
|
||||
public enum DisplayStyle {
|
||||
/**
|
||||
* In the action bar (above the hotbar)
|
||||
*/
|
||||
ACTION_BAR,
|
||||
/**
|
||||
* In the title slot in the middle of the player's screen
|
||||
*/
|
||||
TITLE,
|
||||
/**
|
||||
* In the subtitle slot, just below the title
|
||||
*/
|
||||
SUBTITLE,
|
||||
/**
|
||||
* In chat
|
||||
*/
|
||||
CHAT
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.william278.huskhomes2.listeners;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.util.MessageManager;
|
||||
import me.william278.huskhomes2.commands.HomeCommand;
|
||||
@@ -50,7 +49,7 @@ public class PlayerListener implements Listener {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (!DataManager.playerExists(p, connection)) {
|
||||
DataManager.createPlayer(p, connection);
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
if (TeleportManager.getSpawnLocation().isPresent()) {
|
||||
teleportToSpawn(p);
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +83,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.getSettings().doForceSpawnOnLogin()) {
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
if (TeleportManager.getSpawnLocation().isPresent()) {
|
||||
teleportToSpawn(p);
|
||||
}
|
||||
}
|
||||
@@ -109,14 +108,12 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
private void teleportToSpawn(Player player) {
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!player.isEmpty()) {
|
||||
player.eject(); // Eject passengers before teleporting
|
||||
}
|
||||
PaperLib.teleportAsync(player, TeleportManager.getSpawnLocation().getLocation());
|
||||
});
|
||||
}
|
||||
TeleportManager.getSpawnLocation().ifPresent(teleportationPoint -> {
|
||||
final Location spawnLocation = teleportationPoint.getLocation();
|
||||
if (spawnLocation.isWorldLoaded()) {
|
||||
TeleportManager.teleportLocally(player, spawnLocation, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeleportManager {
|
||||
@@ -99,18 +100,9 @@ public class TeleportManager {
|
||||
if (!HuskHomes.getSettings().doBungee() || server.equals(HuskHomes.getSettings().getServerID())) {
|
||||
DataManager.setPlayerTeleporting(player, false, connection);
|
||||
DataManager.deletePlayerDestination(player.getName(), connection);
|
||||
Location targetLocation = targetPoint[0].getLocation();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!player.isEmpty()) {
|
||||
player.eject(); // Eject passengers before teleporting
|
||||
}
|
||||
PaperLib.teleportAsync(player, targetLocation).thenRun(() -> {
|
||||
if (HuskHomes.getSettings().getTeleportationCompleteSound() != null) {
|
||||
player.playSound(targetLocation, HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1);
|
||||
}
|
||||
MessageManager.sendMessage(player, "teleporting_complete");
|
||||
});
|
||||
});
|
||||
|
||||
final Location targetLocation = targetPoint[0].getLocation();
|
||||
teleportLocally(player, targetLocation, true);
|
||||
} else if (HuskHomes.getSettings().doBungee()) {
|
||||
DataManager.setPlayerDestinationLocation(player, targetPoint[0], connection);
|
||||
DataManager.setPlayerTeleporting(player, true, connection);
|
||||
@@ -127,6 +119,44 @@ public class TeleportManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player locally on the server via PaperLib
|
||||
*
|
||||
* @param player The {@link Player} to teleport
|
||||
* @param targetLocation The target {@link Location}
|
||||
* @param notify Whether to notify the player of teleportation completion or failure through sounds and messages
|
||||
*/
|
||||
public static void teleportLocally(Player player, Location targetLocation, boolean notify) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!player.isEmpty()) {
|
||||
player.eject(); // Eject passengers before teleporting
|
||||
}
|
||||
if (!targetLocation.isWorldLoaded()) {
|
||||
if (notify) {
|
||||
MessageManager.sendMessage(player, "error_invalid_on_arrival");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (HuskHomes.getSettings().doUsePaperLibIfAvailable()) {
|
||||
PaperLib.teleportAsync(player, targetLocation).thenAccept(succeeded -> {
|
||||
if (!succeeded) {
|
||||
player.teleport(targetLocation); // Teleport normally if paperlib fails
|
||||
}
|
||||
});
|
||||
} else {
|
||||
player.teleport(targetLocation);
|
||||
}
|
||||
|
||||
// Send teleportation complete sound
|
||||
if (notify) {
|
||||
if (HuskHomes.getSettings().getTeleportationCompleteSound() != null) {
|
||||
player.playSound(targetLocation, HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1);
|
||||
}
|
||||
MessageManager.sendMessage(player, "teleporting_complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, String targetPlayer) {
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
teleportPlayer(player, targetPlayer);
|
||||
@@ -294,11 +324,15 @@ public class TeleportManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static TeleportationPoint getSpawnLocation() {
|
||||
return spawnLocation;
|
||||
public static Optional<TeleportationPoint> getSpawnLocation() {
|
||||
if (spawnLocation == null) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(spawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSpawnLocation(TeleportationPoint spawnLocation) {
|
||||
TeleportManager.spawnLocation = spawnLocation;
|
||||
public static void setSpawnLocation(TeleportationPoint spawnPoint) {
|
||||
spawnLocation = spawnPoint;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* @author William
|
||||
* HuskHomes' position representation object; represents an in-game location on a server
|
||||
*/
|
||||
public class TeleportationPoint {
|
||||
@@ -26,8 +23,14 @@ public class TeleportationPoint {
|
||||
*
|
||||
* @param location a new Bukkit location
|
||||
* @param server a new Bungee server ID
|
||||
* @throws IllegalStateException if the location supplied has an unloaded world
|
||||
*/
|
||||
public void setLocation(Location location, String server) {
|
||||
public void setLocation(Location location, String server) throws IllegalStateException {
|
||||
if (!location.isWorldLoaded()) {
|
||||
throw new IllegalStateException("The location provided has a world not loaded");
|
||||
}
|
||||
assert location.getWorld() != null;
|
||||
|
||||
worldName = location.getWorld().getName();
|
||||
x = location.getX();
|
||||
y = location.getY();
|
||||
@@ -44,8 +47,8 @@ public class TeleportationPoint {
|
||||
* @param server The Bungee server ID which the location is on
|
||||
*/
|
||||
public TeleportationPoint(Location location, String server) {
|
||||
if (location.getWorld() == null) {
|
||||
throw new IllegalStateException("The location provided has an invalid world");
|
||||
if (!location.isWorldLoaded()) {
|
||||
throw new IllegalStateException("The location provided has a world not loaded");
|
||||
}
|
||||
setLocation(location, server);
|
||||
}
|
||||
@@ -72,18 +75,17 @@ public class TeleportationPoint {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit location from a TeleportationPoint
|
||||
* Get the Bukkit {@link Location} from a TeleportationPoint
|
||||
*
|
||||
* @return the Bukkit location on the server from a TeleportationPoint
|
||||
* @throws IllegalStateException if the location is not valid on the server
|
||||
*/
|
||||
public Location getLocation() {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
throw new IllegalStateException(worldName + " is not a valid world on the server; failed to return location");
|
||||
if (world == null) {
|
||||
throw new IllegalStateException(worldName + " is not loaded on this server; failed to fetch location");
|
||||
}
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,6 +35,7 @@ general:
|
||||
teleport_request_expiry_time: 60
|
||||
allow_unicode_descriptions: true
|
||||
enable_back_command: true
|
||||
use_paperlib_if_available: true
|
||||
sounds:
|
||||
teleportation_complete: 'ENTITY_ENDERMAN_TELEPORT'
|
||||
teleportation_warmup: 'BLOCK_NOTE_BLOCK_BANJO'
|
||||
@@ -94,4 +95,4 @@ economy_integration:
|
||||
random_teleport: 20
|
||||
back: 0
|
||||
handle_vanished_players: true
|
||||
config_file_version: 8
|
||||
config_file_version: 9
|
||||
Reference in new issue
Block a user