mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Finish up refactoring, start fixing
This commit is contained in:
1 parent
a63f1a77ad
commit
cc90d5f15d
36 files changed
+520
-556
No files matched your search
@@ -7,7 +7,7 @@ public class CrossServerListHandler {
|
||||
|
||||
// A HashMap mapping all the HuskHomes servers on the Bungee Network
|
||||
// (with the same Cluster ID) with their list of players
|
||||
private static final HashMap<String,HashSet<String>> playerList = new HashMap<>();
|
||||
/*private static final HashMap<String,HashSet<String>> playerList = new HashMap<>();
|
||||
|
||||
public static HashSet<String> getOtherServerPlayerList() {
|
||||
HashSet<String> players = new HashSet<>();
|
||||
@@ -15,12 +15,12 @@ public class CrossServerListHandler {
|
||||
players.addAll(playerList.get(server));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void updateHashset(String server, HashSet<String> players) {
|
||||
/*public static void updateHashset(String server, HashSet<String> players) {
|
||||
playerList.put(server, players);
|
||||
}
|
||||
|
||||
*/
|
||||
/*public static void updatePlayerList(Player p) {
|
||||
playerList.clear();
|
||||
if (p == null) {
|
||||
|
||||
@@ -34,7 +34,6 @@ import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.listeners.PlayerListener;
|
||||
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
||||
import me.william278.huskhomes2.teleport.SettingHandler;
|
||||
import me.william278.huskhomes2.teleport.TeleportRequestHandler;
|
||||
import org.bstats.bukkit.MetricsLite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -175,15 +174,15 @@ public final class HuskHomes extends JavaPlugin {
|
||||
getLogger().info(getVersionCheckString());
|
||||
}
|
||||
|
||||
// Fetch spawn location if set
|
||||
SettingHandler.fetchSpawnLocation();
|
||||
|
||||
// Initialize the database
|
||||
initializeDatabase();
|
||||
|
||||
// Setup the Dynmap integration if it is enabled
|
||||
if (HuskHomes.getSettings().doDynmap()) {
|
||||
DynMapIntegration.initializeDynmap();
|
||||
// Fetch spawn location if set
|
||||
SettingHandler.fetchSpawnLocation();
|
||||
|
||||
// Setup the DynMap integration if it is enabled
|
||||
if (HuskHomes.getSettings().doDynMap()) {
|
||||
DynMapIntegration.initialize();
|
||||
}
|
||||
|
||||
// Setup economy if it is enabled
|
||||
@@ -196,15 +195,12 @@ public final class HuskHomes extends JavaPlugin {
|
||||
setupBungeeChannels();
|
||||
}
|
||||
|
||||
// Register commands and their associated tab completers
|
||||
// Register commands and tab completion handlers
|
||||
registerCommands();
|
||||
|
||||
// Register events
|
||||
registerEvents(this);
|
||||
|
||||
// Start Loop
|
||||
TeleportRequestHandler.startExpiredChecker(this);
|
||||
|
||||
// bStats initialisation
|
||||
new MetricsLite(this, 8430);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class MessageManager {
|
||||
}
|
||||
|
||||
// Send a message with multiple placeholders
|
||||
public static void sendActionBarMessage(Player p, String messageID, String... placeholderReplacements) {
|
||||
public static void sendActionBar(Player p, String messageID, String... placeholderReplacements) {
|
||||
sendMessage(p, ChatMessageType.ACTION_BAR, messageID, placeholderReplacements);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package me.william278.huskhomes2.api;
|
||||
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The HuskHomes API
|
||||
@@ -15,6 +18,8 @@ import java.util.List;
|
||||
*/
|
||||
public class HuskHomesAPI {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
public HuskHomesAPI() { }
|
||||
|
||||
/**
|
||||
@@ -23,117 +28,117 @@ public class HuskHomesAPI {
|
||||
@param homeName Name of the player's home you wish to retrieve
|
||||
@return the player's Home, or NULL if it does not exist
|
||||
@see Home
|
||||
*/
|
||||
*//*
|
||||
public Home getHome(Player player, String homeName) {
|
||||
return getHome(player.getName(), homeName);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns a Home set by a player, or NULL if it does not exist
|
||||
@param ownerUsername Username of the player
|
||||
@param homeName Name of the player's home you wish to retrieve
|
||||
@return the player's Home, or NULL if it does not exist
|
||||
@see Home
|
||||
*/
|
||||
*//*
|
||||
public Home getHome(String ownerUsername, String homeName) {
|
||||
return DataManager.getHome(ownerUsername, homeName);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns a Warp set on the server, or NULL if it does not exist
|
||||
@param warpName Name of the warp
|
||||
@return a Warp, or NULL if it does not exist
|
||||
@see Warp
|
||||
*/
|
||||
*//*
|
||||
public Warp getWarp(String warpName) {
|
||||
return DataManager.getWarp(warpName);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns an ArrayList of homes set by a Player
|
||||
@param player A Player
|
||||
@return an ArrayList of Homes
|
||||
@see Home
|
||||
*/
|
||||
*//*
|
||||
public List<Home> getHomes(Player player) {
|
||||
return DataManager.getPlayerHomes(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns an ArrayList of homes set by a player
|
||||
@param ownerUsername Username of the player who's homes you want to get
|
||||
@return an ArrayList of Homes
|
||||
@see Home
|
||||
*/
|
||||
*//*
|
||||
public List<Home> getHomes(String ownerUsername) {
|
||||
return DataManager.getPlayerHomes(ownerUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
* Returns how many Homes a given Player has set
|
||||
* @param player the Player being checked
|
||||
* @return an integer of how many homes a player has set
|
||||
* @see Home
|
||||
*/
|
||||
*//*
|
||||
public int getHomeCount(Player player) {
|
||||
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
|
||||
*/
|
||||
*//*
|
||||
public int getMaxSethomes(Player player) {
|
||||
return Home.getSetHomeLimit(player);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
* Returns the number of homes a player can set for free
|
||||
* @param player the Player being checked
|
||||
* @return the number of free homes a player can set
|
||||
*/
|
||||
*//*
|
||||
public int getFreeSethomes(Player player) {
|
||||
return Home.getFreeHomes(player);
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns an ArrayList of all the public homes set
|
||||
@return an ArrayList of Homes
|
||||
@see Home
|
||||
*/
|
||||
*//*
|
||||
public List<Home> getPublicHomes() {
|
||||
return DataManager.getPublicHomes();
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
* Returns how many public Homes there are
|
||||
* @return an integer of how many public homes there are
|
||||
* @see Home
|
||||
*/
|
||||
*//*
|
||||
public int getPublicHomeCount() {
|
||||
return getPublicHomes().size();
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
Returns an ArrayList of all the warps set
|
||||
@return an ArrayList of Warps
|
||||
@see Warp
|
||||
*/
|
||||
*//*
|
||||
public List<Warp> getWarps() {
|
||||
return DataManager.getWarps();
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
* Returns how many Warps have been set
|
||||
* @return an integer of how many warps have been set
|
||||
* @see Warp
|
||||
*/
|
||||
*//*
|
||||
public int getWarpCount() {
|
||||
return getWarps().size();
|
||||
}
|
||||
|
||||
/**
|
||||
*//**
|
||||
* Returns the current spawn position as a TeleportationPoint
|
||||
* @return the spawn position as a TeleportationPoint
|
||||
*/
|
||||
@@ -149,11 +154,18 @@ public class HuskHomesAPI {
|
||||
* @see TeleportationPoint
|
||||
*/
|
||||
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, point);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, point);
|
||||
}
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
try {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, point, connection);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, point, connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "An SQLException occurred timed-teleporting a player via API");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,11 +176,18 @@ public class HuskHomesAPI {
|
||||
* @see TeleportationPoint
|
||||
*/
|
||||
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, targetPlayerName);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, targetPlayerName);
|
||||
}
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
try {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, targetPlayerName, connection);
|
||||
} else {
|
||||
TeleportManager.teleportPlayer(player, targetPlayerName, connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "An SQLException occurred teleporting a player via API");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList;
|
||||
* Fires when a player renames a Home, updates its' location, changes its' name, changes whether or not it is public/private.
|
||||
* Also fires when it is deleted
|
||||
*/
|
||||
public class PlayerHomeUpdateEvent extends Event implements Cancellable {
|
||||
public class PlayerHomeUpdateEvent extends Event {
|
||||
|
||||
private final Player player;
|
||||
private final Home home;
|
||||
@@ -32,16 +32,6 @@ public class PlayerHomeUpdateEvent extends Event implements Cancellable {
|
||||
this.isCancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList;
|
||||
/**
|
||||
* An event, fired when a player sets a new home
|
||||
*/
|
||||
public class PlayerSetHomeEvent extends Event implements Cancellable {
|
||||
public class PlayerSetHomeEvent extends Event {
|
||||
|
||||
private Player player;
|
||||
private Home home;
|
||||
@@ -28,16 +28,6 @@ public class PlayerSetHomeEvent extends Event implements Cancellable {
|
||||
this.isCancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList;
|
||||
/**
|
||||
* An event, fired when a player sets a new warp
|
||||
*/
|
||||
public class PlayerSetWarpEvent extends Event implements Cancellable {
|
||||
public class PlayerSetWarpEvent extends Event {
|
||||
|
||||
private final Player player;
|
||||
private final Warp warp;
|
||||
@@ -28,16 +28,6 @@ public class PlayerSetWarpEvent extends Event implements Cancellable {
|
||||
this.isCancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList;
|
||||
* Fires when a player renames a Warp, updates its' location or changes its' name.
|
||||
* Also fires when a warp is deleted
|
||||
*/
|
||||
public class PlayerWarpUpdateEvent extends Event implements Cancellable {
|
||||
public class PlayerWarpUpdateEvent extends Event {
|
||||
|
||||
private final Player player;
|
||||
private final Warp warp;
|
||||
@@ -32,16 +32,6 @@ public class PlayerWarpUpdateEvent extends Event implements Cancellable {
|
||||
this.isCancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -63,22 +63,20 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
// Remove old marker if on dynmap
|
||||
Home locationMovedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
|
||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||
if (relocateHomeEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(relocateHomeEvent));
|
||||
|
||||
|
||||
DataManager.updateHomeLocation(p.getName(), homeName, newLocation, connection);
|
||||
MessageManager.sendMessage(p, "edit_home_update_location", homeName);
|
||||
|
||||
// Add new updated marker if using dynmap
|
||||
locationMovedHome.setLocation(newLocation, HuskHomes.getSettings().getServerID());
|
||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
||||
}
|
||||
return;
|
||||
@@ -97,10 +95,8 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
String newDescriptionString = newDescription.toString();
|
||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent));
|
||||
|
||||
// Check the description is valid
|
||||
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
||||
@@ -108,7 +104,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
|
||||
// Remove old marker if on the Dynmap
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
|
||||
@@ -117,7 +113,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
// Add new marker if using Dynmap
|
||||
descriptionChangedHome.setDescription(newDescriptionString);
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(descriptionChangedHome);
|
||||
}
|
||||
|
||||
@@ -144,12 +140,10 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
Home renamedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||
if (renameHomeEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(renameHomeEvent));
|
||||
|
||||
if (renamedHome.isPublic()) {
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
||||
@@ -158,7 +152,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
||||
}
|
||||
renamedHome.setName(newName);
|
||||
if (renamedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (renamedHome.isPublic() && HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(renamedHome);
|
||||
}
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
@@ -186,13 +180,11 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||
}
|
||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||
if (makeHomePublicEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(makeHomePublicEvent));
|
||||
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, true, connection);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(privateHome);
|
||||
}
|
||||
} else {
|
||||
@@ -203,13 +195,11 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
Home publicHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||
if (publicHome.isPublic()) {
|
||||
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, publicHome);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
||||
if (makeHomePrivateEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(makeHomePrivateEvent));
|
||||
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, false, connection);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(publicHome.getName(), publicHome.getOwnerUsername());
|
||||
}
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
|
||||
@@ -59,22 +59,19 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
// Remove old marker if on the Dynmap
|
||||
Warp locationMovedWarp = DataManager.getWarp(warpName, connection);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(warpName);
|
||||
}
|
||||
|
||||
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateWarpEvent);
|
||||
if (relocateWarpEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(relocateWarpEvent));
|
||||
|
||||
DataManager.updateWarpLocation(warpName, p.getLocation(), connection);
|
||||
MessageManager.sendMessage(p, "edit_warp_update_location", warpName);
|
||||
|
||||
// Add new updated marker if using Dynmap
|
||||
locationMovedWarp.setLocation(newLocation, HuskHomes.getSettings().getServerID());
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedWarp);
|
||||
}
|
||||
return;
|
||||
@@ -94,10 +91,8 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
String newDescriptionString = newDescription.toString();
|
||||
|
||||
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
||||
Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent);
|
||||
if (changeWarpDescriptionEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent));
|
||||
|
||||
|
||||
// Check the description is valid
|
||||
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||
@@ -105,7 +100,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(warpName);
|
||||
}
|
||||
|
||||
@@ -113,7 +108,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
DataManager.updateWarpDescription(warpName, newDescriptionString, connection);
|
||||
|
||||
descriptionChangedWarp.setDescription(newDescriptionString);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(descriptionChangedWarp);
|
||||
}
|
||||
|
||||
@@ -140,18 +135,15 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameWarpEvent);
|
||||
if (renameWarpEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(renameWarpEvent));
|
||||
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(warpName);
|
||||
}
|
||||
DataManager.updateWarpName(warpName, newName, connection);
|
||||
|
||||
renamedWarp.setName(newName);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(renamedWarp);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
package me.william278.huskhomes2.commands;
|
||||
|
||||
import me.william278.huskhomes2.CrossServerListHandler;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.api.events.PlayerSetHomeEvent;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.integrations.VanishChecker;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.teleport.SettingHandler;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -107,7 +101,7 @@ public class TpCommand extends CommandBase {
|
||||
}
|
||||
}
|
||||
if (HuskHomes.getSettings().doBungee() & HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
||||
players.addAll(CrossServerListHandler.getOtherServerPlayerList());
|
||||
//players.addAll(CrossServerListHandler.getOtherServerPlayerList());
|
||||
}
|
||||
}
|
||||
players.remove(sender.getName());
|
||||
|
||||
@@ -235,7 +235,7 @@ public class Settings {
|
||||
return dynmapWarpMarkerSet;
|
||||
}
|
||||
|
||||
public boolean doDynmap() {
|
||||
public boolean doDynMap() {
|
||||
return doDynmap;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,8 +204,8 @@ public class DataManager {
|
||||
|
||||
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `public`;");
|
||||
rs = ps.executeQuery();
|
||||
final List<Home> publicHomes = new ArrayList<>();
|
||||
if (rs != null) {
|
||||
final List<Home> publicHomes = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
int playerID = rs.getInt("player_id");
|
||||
int locationID = rs.getInt("location_id");
|
||||
@@ -215,10 +215,9 @@ public class DataManager {
|
||||
rs.getString("description"), true));
|
||||
}
|
||||
ps.close();
|
||||
return publicHomes;
|
||||
}
|
||||
ps.close();
|
||||
return null;
|
||||
return publicHomes;
|
||||
}
|
||||
|
||||
// Return an array of all the warps
|
||||
@@ -398,7 +397,7 @@ public class DataManager {
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public static void setPlayerTeleporting(UUID uuid, boolean value, Connection connection) throws SQLException {
|
||||
public static void setPlayerTeleportingData(UUID uuid, boolean value, Connection connection) throws SQLException {
|
||||
PreparedStatement ps;
|
||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `is_teleporting`=? WHERE `user_uuid`=?;");
|
||||
ps.setBoolean(1, value);
|
||||
@@ -507,7 +506,7 @@ public class DataManager {
|
||||
}
|
||||
|
||||
// Update a player's destination teleport point
|
||||
public static void setTeleportationDestination(String username, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
public static void setTeleportationDestinationData(String username, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
PreparedStatement ps;
|
||||
|
||||
// Add the teleportation point
|
||||
@@ -716,7 +715,7 @@ public class DataManager {
|
||||
}
|
||||
|
||||
// Update a player's last position teleport point
|
||||
public static void setTeleportationLastPosition(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
public static void setTeleportationLastPositionData(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
PreparedStatement ps;
|
||||
// Add the teleportation point
|
||||
Integer locationID = addTeleportationPoint(point, connection);
|
||||
@@ -732,13 +731,13 @@ public class DataManager {
|
||||
// Update a player's last position location on SQL
|
||||
public static void setPlayerLastPosition(Player p, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
deletePlayerLastPosition(p, connection);
|
||||
setTeleportationLastPosition(p.getUniqueId(), point, connection);
|
||||
setTeleportationLastPositionData(p.getUniqueId(), point, connection);
|
||||
}
|
||||
|
||||
// Update a player's destination location on SQL
|
||||
public static void setPlayerDestinationLocation(String playerName, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
deletePlayerDestination(playerName, connection);
|
||||
setTeleportationDestination(playerName, point, connection);
|
||||
setTeleportationDestinationData(playerName, point, connection);
|
||||
}
|
||||
|
||||
// Update a player's destination location on SQL
|
||||
@@ -747,12 +746,7 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public static void setPlayerTeleporting(Player p, boolean value, Connection connection) throws SQLException {
|
||||
setPlayerTeleporting(p, value, connection);
|
||||
}
|
||||
|
||||
public static void clearPlayerDestination(String playerName, Connection connection) throws SQLException {
|
||||
deletePlayerDestination(playerName, connection);
|
||||
clearPlayerDestData(playerName, connection);
|
||||
setPlayerTeleportingData(p.getUniqueId(), value, connection);
|
||||
}
|
||||
|
||||
public static void updateRtpCooldown(Player p, Connection connection) throws SQLException {
|
||||
@@ -765,14 +759,10 @@ public class DataManager {
|
||||
Integer destinationID = getPlayerInteger(playerName, "dest_location_id", connection);
|
||||
if (destinationID != null) {
|
||||
deleteTeleportationPoint(destinationID, connection);
|
||||
clearPlayerDestination(playerName, connection);
|
||||
clearPlayerDestData(playerName, connection);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deletePlayerDestination(Player p, Connection connection) throws SQLException {
|
||||
deletePlayerDestination(p.getName(), connection);
|
||||
}
|
||||
|
||||
// Delete a teleportation point from SQL
|
||||
public static void deleteTeleportationPoint(int locationID, Connection connection) throws SQLException {
|
||||
PreparedStatement ps;
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
package me.william278.huskhomes2.data.SQL;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.Error;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,19 @@ import java.util.logging.Level;
|
||||
public class MySQL extends Database {
|
||||
|
||||
final static String[] SQL_SETUP_STATEMENTS = {
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer AUTO_INCREMENT," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
"`x` double NOT NULL," +
|
||||
"`y` double NOT NULL," +
|
||||
"`z` double NOT NULL," +
|
||||
"`yaw` float NOT NULL," +
|
||||
"`pitch` float NOT NULL," +
|
||||
|
||||
"PRIMARY KEY (`location_id`)" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
|
||||
"`player_id` integer AUTO_INCREMENT," +
|
||||
"`user_uuid` char(36) NOT NULL UNIQUE," +
|
||||
@@ -26,19 +39,6 @@ public class MySQL extends Database {
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer AUTO_INCREMENT," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
"`x` double NOT NULL," +
|
||||
"`y` double NOT NULL," +
|
||||
"`z` double NOT NULL," +
|
||||
"`yaw` float NOT NULL," +
|
||||
"`pitch` float NOT NULL," +
|
||||
|
||||
"PRIMARY KEY (`location_id`)" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getHomesDataTable() + " (" +
|
||||
"`player_id` integer NOT NULL," +
|
||||
"`location_id` integer NOT NULL," +
|
||||
|
||||
@@ -15,6 +15,17 @@ public class SQLite extends Database {
|
||||
final static String[] SQL_SETUP_STATEMENTS = {
|
||||
"PRAGMA foreign_keys = ON;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer PRIMARY KEY," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
"`x` double NOT NULL," +
|
||||
"`y` double NOT NULL," +
|
||||
"`z` double NOT NULL," +
|
||||
"`yaw` float NOT NULL," +
|
||||
"`pitch` float NOT NULL" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
|
||||
"`player_id` integer NOT NULL," +
|
||||
"`user_uuid` char(36) NOT NULL UNIQUE," +
|
||||
@@ -29,17 +40,6 @@ public class SQLite extends Database {
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer PRIMARY KEY," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
"`x` double NOT NULL," +
|
||||
"`y` double NOT NULL," +
|
||||
"`z` double NOT NULL," +
|
||||
"`yaw` float NOT NULL," +
|
||||
"`pitch` float NOT NULL" +
|
||||
");",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getHomesDataTable() + " (" +
|
||||
"`player_id` integer NOT NULL," +
|
||||
"`location_id` integer NOT NULL," +
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.william278.huskhomes2.data.pluginmessage;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -77,59 +78,63 @@ public class PluginMessage {
|
||||
* @param sender The player to send the message
|
||||
*/
|
||||
public void send(Player sender) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
// Send a plugin message to the specified player name
|
||||
out.writeUTF("ForwardToPlayer");
|
||||
out.writeUTF(targetPlayerName);
|
||||
// Send a plugin message to the specified player name
|
||||
out.writeUTF("ForwardToPlayer");
|
||||
out.writeUTF(targetPlayerName);
|
||||
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||
|
||||
// Send the message data; output an exception if there's an error
|
||||
try {
|
||||
messageOut.writeUTF(messageData);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Send the message data; output an exception if there's an error
|
||||
try {
|
||||
messageOut.writeUTF(messageData);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Write the messages to the output packet
|
||||
out.writeShort(messageBytes.toByteArray().length);
|
||||
out.write(messageBytes.toByteArray());
|
||||
// Write the messages to the output packet
|
||||
out.writeShort(messageBytes.toByteArray().length);
|
||||
out.write(messageBytes.toByteArray());
|
||||
|
||||
// Send the constructed plugin message packet
|
||||
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
// Send the constructed plugin message packet
|
||||
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
});
|
||||
}
|
||||
|
||||
public void sendToAll(Player sender) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
// Send a plugin message to all players
|
||||
out.writeUTF("Forward");
|
||||
out.writeUTF("ALL");
|
||||
// Send a plugin message to all players
|
||||
out.writeUTF("Forward");
|
||||
out.writeUTF("ALL");
|
||||
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
|
||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||
|
||||
// Send the message data; output an exception if there's an error
|
||||
try {
|
||||
messageOut.writeUTF(messageData);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Send the message data; output an exception if there's an error
|
||||
try {
|
||||
messageOut.writeUTF(messageData);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Write the messages to the output packet
|
||||
out.writeShort(messageBytes.toByteArray().length);
|
||||
out.write(messageBytes.toByteArray());
|
||||
// Write the messages to the output packet
|
||||
out.writeShort(messageBytes.toByteArray().length);
|
||||
out.write(messageBytes.toByteArray());
|
||||
|
||||
// Send the constructed plugin message packet
|
||||
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
// Send the constructed plugin message packet
|
||||
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
});
|
||||
}
|
||||
|
||||
public int getClusterID() {
|
||||
|
||||
@@ -4,21 +4,26 @@ import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.DynmapAPI;
|
||||
import org.dynmap.markers.Marker;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
|
||||
|
||||
public class DynMapIntegration {
|
||||
|
||||
private static Plugin dynmap;
|
||||
private static Plugin dynMap;
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
public static void removeDynamicMapMarker(String warpName) {
|
||||
String markerId = "huskhomes." + warpName;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynmap;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.warps");
|
||||
for (Marker m : markerSet.getMarkers()) {
|
||||
@@ -30,7 +35,7 @@ public class DynMapIntegration {
|
||||
|
||||
public static void removeDynamicMapMarker(String homeName, String ownerName) {
|
||||
String markerId = "huskhomes." + ownerName + "." + homeName;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynmap;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.public_homes");
|
||||
for (Marker m : markerSet.getMarkers()) {
|
||||
@@ -43,7 +48,7 @@ public class DynMapIntegration {
|
||||
public static void addDynamicMapMarker(Warp warp) {
|
||||
try {
|
||||
String markerId = "huskhomes." + warp.getName();
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynmap;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.warps");
|
||||
Marker m = markerSet.createMarker(markerId, warp.getName(), warp.getWorldName(), warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(HuskHomes.getSettings().getDynmapWarpMarkerIconID()), false);
|
||||
@@ -60,7 +65,7 @@ public class DynMapIntegration {
|
||||
public static void addDynamicMapMarker(Home home) {
|
||||
try {
|
||||
String markerId = "huskhomes." + home.getOwnerUsername() + "." + home.getName();
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynmap;
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.public_homes");
|
||||
Marker m = markerSet.createMarker(markerId, home.getName(), home.getWorldName(), home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(HuskHomes.getSettings().getDynmapPublicHomeMarkerIconID()), false);
|
||||
@@ -75,26 +80,38 @@ public class DynMapIntegration {
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeDynmap() {
|
||||
dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
|
||||
public static void initialize() {
|
||||
dynMap = plugin.getServer().getPluginManager().getPlugin("dynmap");
|
||||
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynmap;
|
||||
if (HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
dynmapAPI.getMarkerAPI().createMarkerSet("huskhomes.public_homes", HuskHomes.getSettings().getDynmapPublicHomeMarkerSet(), dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
|
||||
for (Home home : DataManager.getPublicHomes()) {
|
||||
if (!HuskHomes.getSettings().doBungee() || home.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
addDynamicMapMarker(home);
|
||||
}
|
||||
}
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
if (dynmapAPI == null) {
|
||||
return;
|
||||
}
|
||||
if (HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
dynmapAPI.getMarkerAPI().createMarkerSet("huskhomes.warps", HuskHomes.getSettings().getDynmapWarpMarkerSet(), dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
|
||||
for (Warp warp : DataManager.getWarps()) {
|
||||
if (!HuskHomes.getSettings().doBungee() || warp.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
addDynamicMapMarker(warp);
|
||||
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
if (HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
dynmapAPI.getMarkerAPI().createMarkerSet("huskhomes.public_homes", HuskHomes.getSettings().getDynmapPublicHomeMarkerSet(), dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
|
||||
for (Home home : DataManager.getPublicHomes(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || home.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> addDynamicMapMarker(home));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
dynmapAPI.getMarkerAPI().createMarkerSet("huskhomes.warps", HuskHomes.getSettings().getDynmapWarpMarkerSet(), dynmapAPI.getMarkerAPI().getMarkerIcons(), false);
|
||||
for (Warp warp : DataManager.getWarps(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || warp.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> addDynamicMapMarker(warp));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred adding homes and warps to the DynMap");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,12 @@ public class VaultIntegration {
|
||||
private static Economy economy = null;
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
public static boolean initializeEconomy() {
|
||||
public static void initializeEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider =
|
||||
plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
return (economy != null);
|
||||
}
|
||||
|
||||
public static String format(double monetaryValue) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package me.william278.huskhomes2.listeners;
|
||||
|
||||
import me.william278.huskhomes2.CrossServerListHandler;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.data.pluginmessage.PluginMessageHandler;
|
||||
import me.william278.huskhomes2.commands.HomeCommand;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
@@ -14,14 +12,21 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
private static ComponentBuilder backButton() {
|
||||
ComponentBuilder backButton = new ComponentBuilder();
|
||||
TextComponent button = new TextComponent("[Go Back]");
|
||||
@@ -38,9 +43,16 @@ public class PlayerListener implements Listener {
|
||||
public void onPlayerDie(PlayerDeathEvent e) {
|
||||
Player p = e.getEntity();
|
||||
if (p.hasPermission("huskhomes.back.death")) {
|
||||
DataManager.setPlayerLastPosition(p, new TeleportationPoint(p.getLocation(), HuskHomes.getSettings().getServerID()));
|
||||
MessageManager.sendMessage(p, "return_by_death");
|
||||
p.spigot().sendMessage(backButton().create());
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
DataManager.setPlayerLastPosition(p, new TeleportationPoint(p.getLocation(), HuskHomes.getSettings().getServerID()), connection);
|
||||
MessageManager.sendMessage(p, "return_by_death");
|
||||
p.spigot().sendMessage(backButton().create());
|
||||
} catch (SQLException sqlException) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL error occurred updating the last position of a player when they died", sqlException);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,31 +62,39 @@ public class PlayerListener implements Listener {
|
||||
|
||||
// Create player on SQL if they don't exist already
|
||||
try {
|
||||
if (!DataManager.playerExists(p)) {
|
||||
DataManager.createPlayer(p);
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
p.teleport(TeleportManager.getSpawnLocation().getLocation());
|
||||
}
|
||||
} else {
|
||||
// Check if they've changed their name and update if so
|
||||
DataManager.checkPlayerNameChange(p);
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
if (!DataManager.playerExists(p, connection)) {
|
||||
DataManager.createPlayer(p, connection);
|
||||
if (TeleportManager.getSpawnLocation() != null) {
|
||||
p.teleport(TeleportManager.getSpawnLocation().getLocation());
|
||||
}
|
||||
} else {
|
||||
// Check if they've changed their name and update if so
|
||||
DataManager.checkPlayerNameChange(p, connection);
|
||||
|
||||
// Update their TAB cache for /home command
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
}
|
||||
// Update their TAB cache for /home command
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
}
|
||||
|
||||
// If bungee mode, check if the player joined the server from a teleport and act accordingly
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (DataManager.getPlayerTeleporting(p)) {
|
||||
TeleportManager.teleportPlayer(p);
|
||||
}
|
||||
// If bungee mode, check if the player joined the server from a teleport and act accordingly
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (DataManager.getPlayerTeleporting(p)) {
|
||||
TeleportManager.teleportPlayer(p);
|
||||
}
|
||||
|
||||
/*// Update player lists globally
|
||||
if (HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
||||
CrossServerListHandler.updatePlayerList(p);
|
||||
PluginMessageHandler.broadcastPlayerChange(p);
|
||||
}*/
|
||||
}
|
||||
} catch (NullPointerException ignored) { } // Ignore NullPointerExceptions from players that execute this event and return null (e.g Citizens).
|
||||
}
|
||||
} catch (SQLException sqlException) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL error handling a joining player", sqlException);
|
||||
}
|
||||
});
|
||||
} catch (NullPointerException ignored) {
|
||||
} // Ignore NullPointerExceptions from players that execute this event and return null (e.g Citizens).
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,27 @@ import org.bukkit.entity.Player;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PluginMessageListener implements org.bukkit.plugin.messaging.PluginMessageListener {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
private void handlePluginMessage(PluginMessage pluginMessage, Player recipient) {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
switch (pluginMessage.getMessageType()) {
|
||||
case SET_TP_DESTINATION:
|
||||
DataManager.setPlayerDestinationLocation(pluginMessage.getMessageData(),
|
||||
new TeleportationPoint(recipient.getLocation(), HuskHomes.getSettings().getServerID()));
|
||||
new PluginMessage(pluginMessage.getMessageData(), PluginMessageType.CONFIRM_DESTINATION_SET, "confirmed").send(recipient);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
DataManager.setPlayerDestinationLocation(pluginMessage.getMessageData(),
|
||||
new TeleportationPoint(recipient.getLocation(), HuskHomes.getSettings().getServerID()), connection);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred responding to a plugin message teleport destination update");
|
||||
new PluginMessage(pluginMessage.getMessageData(), PluginMessageType.CONFIRM_DESTINATION_SET, "confirmed").send(recipient);
|
||||
}
|
||||
});
|
||||
return;
|
||||
case CONFIRM_DESTINATION_SET:
|
||||
if (pluginMessage.getMessageData().equals("confirmed")) {
|
||||
@@ -53,7 +64,13 @@ public class PluginMessageListener implements org.bukkit.plugin.messaging.Plugin
|
||||
final boolean tpaAccepted = Boolean.parseBoolean(pluginMessage.getMessageDataItems()[1]);
|
||||
if (tpaAccepted) {
|
||||
MessageManager.sendMessage(recipient, "tpa_has_accepted", tpaReplierName);
|
||||
TeleportManager.queueTimedTeleport(recipient, tpaReplierName);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
TeleportManager.queueTimedTeleport(recipient, tpaReplierName, connection);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred responding to a plugin message teleport request reply");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MessageManager.sendMessage(recipient, "tpa_has_declined", tpaReplierName);
|
||||
}
|
||||
@@ -68,7 +85,13 @@ public class PluginMessageListener implements org.bukkit.plugin.messaging.Plugin
|
||||
}
|
||||
return;
|
||||
case TELEPORT_TO_ME:
|
||||
TeleportManager.teleportPlayer(recipient, pluginMessage.getMessageData());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
TeleportManager.teleportPlayer(recipient, pluginMessage.getMessageData(), connection);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred responding to a plugin message teleport-to-me request");
|
||||
}
|
||||
});
|
||||
return;
|
||||
case GET_ONLINE_PLAYERS:
|
||||
/*if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
|
||||
@@ -11,13 +11,18 @@ import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static org.bukkit.configuration.file.YamlConfiguration.loadConfiguration;
|
||||
|
||||
public class EssentialsMigrator {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
// Migrate data from EssentialsX
|
||||
public static void migrate() {
|
||||
String serverID = HuskHomes.getSettings().getServerID();
|
||||
@@ -32,32 +37,44 @@ public class EssentialsMigrator {
|
||||
Bukkit.getLogger().info("- Migrating user data and homes -");
|
||||
|
||||
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
||||
for (File playerFile : playerFiles) {
|
||||
String uuidS = playerFile.getName().split("\\.")[0];
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||
String playerName = playerFileConfig.getString("lastAccountName");
|
||||
Bukkit.getLogger().info("Migrating user data for " + playerName);
|
||||
try {
|
||||
Set<String> essentialsHomes = playerFileConfig.getConfigurationSection("homes").getKeys(false);
|
||||
DataManager.createPlayer(uuid, playerName);
|
||||
for (String home : essentialsHomes) {
|
||||
if (playerFiles != null) {
|
||||
|
||||
// Get
|
||||
String worldName = playerFileConfig.getString("homes." + home + ".world");
|
||||
double x = playerFileConfig.getDouble("homes." + home + ".x");
|
||||
double y = playerFileConfig.getDouble("homes." + home + ".y");
|
||||
double z = playerFileConfig.getDouble("homes." + home + ".z");
|
||||
float pitch = (float) playerFileConfig.getDouble("homes." + home + ".pitch");
|
||||
float yaw = (float) playerFileConfig.getDouble("homes." + home + ".yaw");
|
||||
|
||||
Home playerHome = new Home(new TeleportationPoint(worldName, x, y, z, yaw, pitch, serverID), playerName, uuidS, home, playerName + "'s home", false);
|
||||
for (File playerFile : playerFiles) {
|
||||
String uuidS = playerFile.getName().split("\\.")[0];
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||
String playerName = playerFileConfig.getString("lastAccountName");
|
||||
Bukkit.getLogger().info("Migrating user data for " + playerName);
|
||||
try {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
Set<String> essentialsHomes = playerFileConfig.getConfigurationSection("homes").getKeys(false);
|
||||
DataManager.createPlayer(uuid, playerName, connection);
|
||||
for (String home : essentialsHomes) {
|
||||
|
||||
Bukkit.getLogger().info("> Migrated home " + home);
|
||||
DataManager.addHome(playerHome, uuid);
|
||||
// Get
|
||||
String worldName = playerFileConfig.getString("homes." + home + ".world");
|
||||
double x = playerFileConfig.getDouble("homes." + home + ".x");
|
||||
double y = playerFileConfig.getDouble("homes." + home + ".y");
|
||||
double z = playerFileConfig.getDouble("homes." + home + ".z");
|
||||
float pitch = (float) playerFileConfig.getDouble("homes." + home + ".pitch");
|
||||
float yaw = (float) playerFileConfig.getDouble("homes." + home + ".yaw");
|
||||
|
||||
Home playerHome = new Home(new TeleportationPoint(worldName, x, y, z, yaw, pitch, serverID), playerName, uuidS, home, playerName + "'s home", false);
|
||||
|
||||
Bukkit.getLogger().info("→ Migrated home " + home);
|
||||
DataManager.addHome(playerHome, uuid, connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurredf migrating Essentials data!", e);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("No home data found for " + playerName);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("No home data found for " + playerName);
|
||||
}
|
||||
}
|
||||
Bukkit.getLogger().info("- All homes migrated! -");
|
||||
@@ -67,26 +84,34 @@ public class EssentialsMigrator {
|
||||
File essentialsWarpsFolder = new File(Bukkit.getWorldContainer() + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "warps");
|
||||
if (essentialsWarpsFolder.exists()) {
|
||||
Bukkit.getLogger().info("- Migrating warps -");
|
||||
|
||||
File[] warpFiles = essentialsWarpsFolder.listFiles();
|
||||
for (File warpFile : warpFiles) {
|
||||
FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
||||
try {
|
||||
String warpName = warpFileConfig.getString("name");
|
||||
String worldName = warpFileConfig.getString("world");
|
||||
double x = warpFileConfig.getDouble("x");
|
||||
double y = warpFileConfig.getDouble("y");
|
||||
double z = warpFileConfig.getDouble("z");
|
||||
float yaw = (float) warpFileConfig.getDouble("yaw");
|
||||
float pitch = (float) warpFileConfig.getDouble("pitch");
|
||||
|
||||
Warp warp = new Warp(new TeleportationPoint(worldName, x, y, z, yaw, pitch, serverID), warpName, "A publicly accessible warp");
|
||||
DataManager.addWarp(warp);
|
||||
if (warpFiles != null) {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
for (File warpFile : warpFiles) {
|
||||
FileConfiguration warpFileConfig = loadConfiguration(warpFile);
|
||||
try {
|
||||
try {
|
||||
String warpName = warpFileConfig.getString("name");
|
||||
String worldName = warpFileConfig.getString("world");
|
||||
double x = warpFileConfig.getDouble("x");
|
||||
double y = warpFileConfig.getDouble("y");
|
||||
double z = warpFileConfig.getDouble("z");
|
||||
float yaw = (float) warpFileConfig.getDouble("yaw");
|
||||
float pitch = (float) warpFileConfig.getDouble("pitch");
|
||||
|
||||
Bukkit.getLogger().info("Migrated warp \"" + warpName + "\"");
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().warning("Error obtaining a warp's data!");
|
||||
}
|
||||
Warp warp = new Warp(new TeleportationPoint(worldName, x, y, z, yaw, pitch, serverID), warpName, "A publicly accessible warp");
|
||||
DataManager.addWarp(warp, connection);
|
||||
Bukkit.getLogger().info("Migrated warp \"" + warpName + "\"");
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurredf migrating Essentials data!", e);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().warning("Error obtaining a warp's data!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Bukkit.getLogger().info("- All warps migrated! -");
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class ListHandler {
|
||||
try {
|
||||
ComponentBuilder homeList = new ComponentBuilder();
|
||||
List<Home> homes = DataManager.getPublicHomes(connection);
|
||||
if (homes == null || homes.isEmpty()) {
|
||||
if (homes.isEmpty()) {
|
||||
MessageManager.sendMessage(player, "error_no_public_homes_set");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,9 @@ public class SettingHandler {
|
||||
if (setHomeConditions.areConditionsMet()) {
|
||||
Home home = new Home(location, HuskHomes.getSettings().getServerID(), player, name, false);
|
||||
PlayerSetHomeEvent event = new PlayerSetHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
});
|
||||
DataManager.addHome(home, player, connection);
|
||||
MessageManager.sendMessage(player, "set_home_success", name);
|
||||
HomeCommand.Tab.updatePlayerHomeCache(player);
|
||||
@@ -93,7 +92,7 @@ public class SettingHandler {
|
||||
// Delete the old spawn warp
|
||||
if (DataManager.warpExists(spawnWarpName, connection)) {
|
||||
DataManager.deleteWarp(spawnWarpName, connection);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(spawnWarpName);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +103,7 @@ public class SettingHandler {
|
||||
Warp spawnWarp = new Warp(location, HuskHomes.getSettings().getServerID(), spawnWarpName);
|
||||
spawnWarp.setDescription(MessageManager.getRawMessage("spawn_warp_default_description"));
|
||||
DataManager.addWarp(spawnWarp, connection);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(spawnWarp);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
@@ -124,13 +123,10 @@ public class SettingHandler {
|
||||
if (setWarpConditions.areConditionsMet()) {
|
||||
Warp warp = new Warp(location, HuskHomes.getSettings().getServerID(), name);
|
||||
PlayerSetWarpEvent event = new PlayerSetWarpEvent(player, warp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.addWarp(warp, connection);
|
||||
MessageManager.sendMessage(player, "set_warp_success", name);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(warp);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
@@ -174,14 +170,11 @@ public class SettingHandler {
|
||||
String homeName = home.getName();
|
||||
if (home.isPublic()) {
|
||||
// Delete Dynmap marker if it exists & if the home is public
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, player.getName());
|
||||
}
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteHome(homeName, player, connection);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
@@ -213,14 +206,11 @@ public class SettingHandler {
|
||||
if (home != null) {
|
||||
if (home.isPublic()) {
|
||||
// Delete Dynmap marker if it exists & if the home is public
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, player.getName());
|
||||
}
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteHome(homeName, player, connection);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
@@ -258,12 +248,9 @@ public class SettingHandler {
|
||||
if (warp != null) {
|
||||
String warpName = warp.getName();
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteWarp(warpName, connection);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(warpName);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
@@ -291,13 +278,10 @@ public class SettingHandler {
|
||||
if (DataManager.warpExists(warpName, connection)) {
|
||||
Warp warp = DataManager.getWarp(warpName, connection);
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteWarp(warpName, connection);
|
||||
MessageManager.sendMessage(player, "warp_deleted", warpName);
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
if (HuskHomes.getSettings().doDynMap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(warpName);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
|
||||
@@ -15,18 +15,15 @@ import org.bukkit.entity.Player;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeleportManager {
|
||||
|
||||
private static final Set<TimedTeleport> queuedTeleports = new HashSet<>();
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
private static TeleportationPoint spawnLocation;
|
||||
|
||||
// todo this doesnt seem to work cross server
|
||||
public static void teleportPlayer(Player player, String targetPlayer, Connection connection) throws SQLException {
|
||||
DataManager.setPlayerLastPosition(player, new TeleportationPoint(player.getLocation(),
|
||||
HuskHomes.getSettings().getServerID()), connection);
|
||||
@@ -48,11 +45,13 @@ public class TeleportManager {
|
||||
if (teleportationPoint != null) {
|
||||
String server = teleportationPoint.getServer();
|
||||
if (!HuskHomes.getSettings().doBungee() || server.equals(HuskHomes.getSettings().getServerID())) {
|
||||
PaperLib.teleportAsync(p, teleportationPoint.getLocation());
|
||||
p.playSound(p.getLocation(), HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1);
|
||||
MessageManager.sendMessage(p, "teleporting_complete");
|
||||
DataManager.setPlayerTeleporting(p, false, connection);
|
||||
DataManager.clearPlayerDestination(p.getName(), connection);
|
||||
DataManager.deletePlayerDestination(p.getName(), connection);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PaperLib.teleportAsync(p, teleportationPoint.getLocation());
|
||||
p.playSound(p.getLocation(), HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1);
|
||||
MessageManager.sendMessage(p, "teleporting_complete");
|
||||
});
|
||||
} else if (HuskHomes.getSettings().doBungee()) {
|
||||
DataManager.setPlayerDestinationLocation(p, teleportationPoint, connection);
|
||||
DataManager.setPlayerTeleporting(p, true, connection);
|
||||
@@ -71,7 +70,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
getQueuedTeleports().add(new TimedTeleport(player, targetPlayer));
|
||||
new TimedTeleport(player, targetPlayer).begin();
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, TeleportationPoint point, Connection connection) throws SQLException {
|
||||
@@ -80,7 +79,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
getQueuedTeleports().add(new TimedTeleport(player, point, "point"));
|
||||
new TimedTeleport(player, point, TimedTeleport.TargetType.POINT).begin();
|
||||
}
|
||||
|
||||
public static void queueBackTeleport(Player player, Connection connection) throws SQLException {
|
||||
@@ -107,7 +106,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
getQueuedTeleports().add(new TimedTeleport(player, lastPosition, "back"));
|
||||
new TimedTeleport(player, lastPosition, TimedTeleport.TargetType.BACK).begin();
|
||||
} else {
|
||||
MessageManager.sendMessage(player, "error_no_last_position");
|
||||
}
|
||||
@@ -146,7 +145,7 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
new TimedTeleport(player);
|
||||
new TimedTeleport(player).begin();
|
||||
}
|
||||
|
||||
public static void teleportHere(Player requester, String targetPlayerName, Connection connection) throws SQLException {
|
||||
@@ -193,10 +192,6 @@ public class TeleportManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<TimedTeleport> getQueuedTeleports() {
|
||||
return queuedTeleports;
|
||||
}
|
||||
|
||||
public static TeleportationPoint getSpawnLocation() {
|
||||
return spawnLocation;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class TeleportRequest {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public boolean getExpired() {
|
||||
public boolean isExpired() {
|
||||
long currentUnixTime = Instant.now().getEpochSecond();
|
||||
return currentUnixTime > requestExpiryTime;
|
||||
}
|
||||
|
||||
@@ -3,29 +3,19 @@ package me.william278.huskhomes2.teleport;
|
||||
import de.themoep.minedown.MineDown;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.api.events.PlayerSetHomeEvent;
|
||||
import me.william278.huskhomes2.commands.HomeCommand;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.data.pluginmessage.PluginMessage;
|
||||
import me.william278.huskhomes2.data.pluginmessage.PluginMessageType;
|
||||
import me.william278.huskhomes2.integrations.VanishChecker;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.RandomPoint;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeleportRequestHandler {
|
||||
@@ -35,9 +25,6 @@ public class TeleportRequestHandler {
|
||||
// Target player and teleport request to them hashmap
|
||||
public static Map<Player, TeleportRequest> teleportRequests = new HashMap<>();
|
||||
|
||||
// Timestamp identifying when the global player list should be updated next;
|
||||
private static long nextPlayerListUpdateTime = Instant.now().getEpochSecond() + HuskHomes.getSettings().getCrossServerTabUpdateDelay();
|
||||
|
||||
private static void sendTeleportRequestCrossServer(Player requester, String targetPlayerName, TeleportRequest.RequestType requestType) {
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
new PluginMessage(targetPlayerName, PluginMessageType.TPA_REQUEST, requester.getName()).send(requester);
|
||||
@@ -48,9 +35,9 @@ public class TeleportRequestHandler {
|
||||
|
||||
private static void replyTeleportRequestCrossServer(Player replier, String requesterName, TeleportRequest.RequestType requestType, boolean accepted) {
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
new PluginMessage(requesterName, PluginMessageType.TPA_REQUEST_REPLY, replier.getName(), Boolean.toString(accepted));
|
||||
new PluginMessage(requesterName, PluginMessageType.TPA_REQUEST_REPLY, replier.getName(), Boolean.toString(accepted)).send(replier);
|
||||
} else if (requestType == TeleportRequest.RequestType.TPAHERE) {
|
||||
new PluginMessage(requesterName, PluginMessageType.TPAHERE_REQUEST_REPLY, replier.getName(), Boolean.toString(accepted));
|
||||
new PluginMessage(requesterName, PluginMessageType.TPAHERE_REQUEST_REPLY, replier.getName(), Boolean.toString(accepted)).send(replier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +119,11 @@ public class TeleportRequestHandler {
|
||||
return;
|
||||
}
|
||||
TeleportRequest teleportRequest = teleportRequests.get(p);
|
||||
if (teleportRequest.isExpired()) {
|
||||
teleportRequests.remove(p);
|
||||
MessageManager.sendMessage(p, "error_tp_request_expired");
|
||||
return;
|
||||
}
|
||||
String requesterName = teleportRequest.getSenderName();
|
||||
TeleportRequest.RequestType requestType = teleportRequest.getRequestType();
|
||||
Player requester = Bukkit.getPlayer(requesterName);
|
||||
@@ -157,11 +149,8 @@ public class TeleportRequestHandler {
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
|
||||
if (requestType == TeleportRequest.RequestType.TPA) {
|
||||
replyTeleportRequestCrossServer(p, requesterName, TeleportRequest.RequestType.TPA, true);
|
||||
} else if (requestType == TeleportRequest.RequestType.TPAHERE) {
|
||||
replyTeleportRequestCrossServer(p, requesterName, TeleportRequest.RequestType.TPAHERE, true);
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, true);
|
||||
if (requestType == TeleportRequest.RequestType.TPAHERE) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName, connection);
|
||||
}
|
||||
} else {
|
||||
@@ -178,124 +167,4 @@ public class TeleportRequestHandler {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void startExpiredChecker(Plugin plugin) {
|
||||
Set<Player> expiredTeleportRequests = new HashSet<>();
|
||||
Set<TimedTeleport> completedTeleports = new HashSet<>();
|
||||
|
||||
// Run every second
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
|
||||
// Update active timed teleports
|
||||
if (!TeleportManager.getQueuedTeleports().isEmpty()) {
|
||||
for (TimedTeleport timedTeleport : TeleportManager.getQueuedTeleports()) {
|
||||
Player teleporter = Bukkit.getPlayer(timedTeleport.getTeleporter().getUniqueId());
|
||||
if (teleporter != null) {
|
||||
if (timedTeleport.getTimeRemaining() > 0) {
|
||||
if (!timedTeleport.hasMoved(teleporter)) {
|
||||
if (!timedTeleport.hasLostHealth(teleporter)) {
|
||||
teleporter.playSound(teleporter.getLocation(), HuskHomes.getSettings().getTeleportWarmupSound(), 2, 1);
|
||||
MessageManager.sendActionBarMessage(teleporter, "teleporting_action_bar_countdown",
|
||||
Integer.toString(timedTeleport.getTimeRemaining()));
|
||||
timedTeleport.decrementTimeRemaining();
|
||||
} else {
|
||||
MessageManager.sendActionBarMessage(teleporter, "teleporting_action_bar_cancelled");
|
||||
MessageManager.sendMessage(teleporter, "teleporting_cancelled_damage");
|
||||
teleporter.playSound(teleporter.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
|
||||
completedTeleports.add(timedTeleport);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendActionBarMessage(teleporter, "teleporting_action_bar_cancelled");
|
||||
MessageManager.sendMessage(teleporter, "teleporting_cancelled_movement");
|
||||
teleporter.playSound(teleporter.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
|
||||
completedTeleports.add(timedTeleport);
|
||||
}
|
||||
} else {
|
||||
// Execute the teleport
|
||||
String targetType = timedTeleport.getTargetType();
|
||||
switch (targetType) {
|
||||
case "point":
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPoint());
|
||||
break;
|
||||
case "back":
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getBackCost();
|
||||
if (backCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(teleporter, backCost)) {
|
||||
MessageManager.sendMessage(teleporter, "error_insufficient_funds", VaultIntegration.format(backCost));
|
||||
break;
|
||||
} else {
|
||||
MessageManager.sendMessage(teleporter, "back_spent_money", VaultIntegration.format(backCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPoint());
|
||||
break;
|
||||
case "player":
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPlayerName());
|
||||
break;
|
||||
case "random":
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double rtpCost = HuskHomes.getSettings().getRtpCost();
|
||||
if (rtpCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(teleporter, rtpCost)) {
|
||||
MessageManager.sendMessage(teleporter, "error_insufficient_funds", VaultIntegration.format(rtpCost));
|
||||
break;
|
||||
} else {
|
||||
MessageManager.sendMessage(teleporter, "rtp_spent_money", VaultIntegration.format(rtpCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(teleporter, new RandomPoint(teleporter));
|
||||
DataManager.updateRtpCooldown(teleporter);
|
||||
break;
|
||||
}
|
||||
completedTeleports.add(timedTeleport);
|
||||
}
|
||||
} else {
|
||||
completedTeleports.add(timedTeleport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear completed teleports
|
||||
if (!completedTeleports.isEmpty()) {
|
||||
for (TimedTeleport timedTeleport : completedTeleports) {
|
||||
TeleportManager.getQueuedTeleports().remove(timedTeleport);
|
||||
}
|
||||
}
|
||||
completedTeleports.clear();
|
||||
|
||||
// Clear expired teleport requests
|
||||
clearExpiredRequests(expiredTeleportRequests);
|
||||
|
||||
/*// Update the global player list
|
||||
if (HuskHomes.getSettings().doBungee() & HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
||||
final long currentTimestmap = Instant.now().getEpochSecond();
|
||||
if (currentTimestmap >= nextPlayerListUpdateTime & Bukkit.getOnlinePlayers().size() > 0) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
CrossServerListHandler.updatePlayerList(p);
|
||||
break;
|
||||
}
|
||||
nextPlayerListUpdateTime = currentTimestmap + HuskHomes.getSettings().getCrossServerTabUpdateDelay();
|
||||
}
|
||||
}*/
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
// Cancel expired teleport requests
|
||||
private static void clearExpiredRequests(Set<Player> expiredTeleportRequests) {
|
||||
// Check if any requests have expired
|
||||
for (Player p : teleportRequests.keySet()) {
|
||||
if (teleportRequests.get(p).getExpired()) {
|
||||
expiredTeleportRequests.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear expired requests
|
||||
for (Player p : expiredTeleportRequests) {
|
||||
teleportRequests.remove(p);
|
||||
}
|
||||
expiredTeleportRequests.clear();
|
||||
}
|
||||
}
|
||||
@@ -2,70 +2,151 @@ package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.teleport.points.RandomPoint;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Husk;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TimedTeleport {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
private final String targetType; // "player" or "point"
|
||||
private final TargetType targetType;
|
||||
|
||||
private TeleportationPoint targetPoint;
|
||||
private String targetPlayerName;
|
||||
|
||||
private final Player teleporter;
|
||||
private final Location initialTeleporterLocation;
|
||||
private final double initialTeleporterHealth;
|
||||
private final Player player;
|
||||
private final Location initialLocation;
|
||||
private final double initialHealth;
|
||||
|
||||
private int timeRemaining;
|
||||
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
||||
|
||||
public TimedTeleport(Player teleporter, TeleportationPoint targetPoint, String targetType) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
public TimedTeleport(Player player, TeleportationPoint targetPoint, TargetType targetType) {
|
||||
this.player = player;
|
||||
this.initialLocation = player.getLocation();
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = targetType;
|
||||
this.targetPoint = targetPoint;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(teleporter, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(teleporter, "teleporting_please_stand_still");
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
}
|
||||
|
||||
public TimedTeleport(Player teleporter) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "random";
|
||||
public TimedTeleport(Player player) {
|
||||
this.player = player;
|
||||
this.initialLocation = player.getLocation();
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = TargetType.RANDOM;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(teleporter, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(teleporter, "teleporting_please_stand_still");
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
}
|
||||
|
||||
public TimedTeleport(Player teleporter, String targetPlayerName) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "player";
|
||||
public TimedTeleport(Player player, String targetPlayerName) {
|
||||
this.player = player;
|
||||
this.initialLocation = player.getLocation();
|
||||
this.initialHealth = player.getHealth();
|
||||
this.targetType = TargetType.PLAYER;
|
||||
this.targetPlayerName = targetPlayerName;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
MessageManager.sendMessage(teleporter, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(teleporter, "teleporting_please_stand_still");
|
||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
MessageManager.sendMessage(player, "teleporting_please_stand_still");
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
|
||||
|
||||
});
|
||||
final int[] i = {HuskHomes.getSettings().getTeleportWarmupTime()+1};
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Player executablePlayer = Bukkit.getPlayer(player.getUniqueId());
|
||||
if (executablePlayer == null) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if (hasMoved(executablePlayer)) {
|
||||
cancel();
|
||||
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
|
||||
MessageManager.sendMessage(player, "teleporting_cancelled_movement");
|
||||
MessageManager.sendActionBar(player, "teleporting_action_bar_cancelled");
|
||||
return;
|
||||
}
|
||||
if (hasLostHealth(executablePlayer)) {
|
||||
cancel();
|
||||
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
|
||||
MessageManager.sendMessage(player, "teleporting_cancelled_damage");
|
||||
MessageManager.sendActionBar(player, "teleporting_action_bar_cancelled");
|
||||
return;
|
||||
}
|
||||
i[0] = i[0] -1;
|
||||
if (i[0] == 0) {
|
||||
cancel();
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
// Execute the teleport
|
||||
switch (getTargetType()) {
|
||||
case POINT:
|
||||
TeleportManager.teleportPlayer(player, targetPoint, connection);
|
||||
break;
|
||||
case BACK:
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getBackCost();
|
||||
if (backCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(player, backCost)) {
|
||||
MessageManager.sendMessage(player, "error_insufficient_funds", VaultIntegration.format(backCost));
|
||||
break;
|
||||
} else {
|
||||
MessageManager.sendMessage(player, "back_spent_money", VaultIntegration.format(backCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(player, getTargetPoint(), connection);
|
||||
break;
|
||||
case PLAYER:
|
||||
TeleportManager.teleportPlayer(player, getTargetPlayerName(), connection);
|
||||
break;
|
||||
case RANDOM:
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double rtpCost = HuskHomes.getSettings().getRtpCost();
|
||||
if (rtpCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(player, rtpCost)) {
|
||||
MessageManager.sendMessage(player, "error_insufficient_funds", VaultIntegration.format(rtpCost));
|
||||
break;
|
||||
} else {
|
||||
MessageManager.sendMessage(player, "rtp_spent_money", VaultIntegration.format(rtpCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(player, new RandomPoint(player), connection);
|
||||
DataManager.updateRtpCooldown(player, connection);
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred carrying out a timed teleport");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
MessageManager.sendActionBar(executablePlayer, "teleporting_action_bar_countdown", Integer.toString(i[0]));
|
||||
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportWarmupSound(), 1, 1);
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 20L);
|
||||
}
|
||||
|
||||
public String getTargetType() {
|
||||
public TargetType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
@@ -87,7 +168,7 @@ public class TimedTeleport {
|
||||
|
||||
// This returns if the player has lost health during a timed teleport
|
||||
public boolean hasLostHealth(Player p) {
|
||||
return p.getHealth() < initialTeleporterHealth;
|
||||
return p.getHealth() < initialHealth;
|
||||
}
|
||||
|
||||
// This returns if the player has moved during a timed teleport
|
||||
@@ -95,16 +176,16 @@ public class TimedTeleport {
|
||||
Location currentLocation = p.getLocation();
|
||||
final double movementThreshold = 0.1;
|
||||
|
||||
double xDiff = makePositive(initialTeleporterLocation.getX() - currentLocation.getX());
|
||||
double yDiff = makePositive(initialTeleporterLocation.getY() - currentLocation.getY());
|
||||
double zDiff = makePositive(initialTeleporterLocation.getZ() - currentLocation.getZ());
|
||||
double xDiff = makePositive(initialLocation.getX() - currentLocation.getX());
|
||||
double yDiff = makePositive(initialLocation.getY() - currentLocation.getY());
|
||||
double zDiff = makePositive(initialLocation.getZ() - currentLocation.getZ());
|
||||
double totalDiff = xDiff + yDiff + zDiff;
|
||||
|
||||
return totalDiff > movementThreshold;
|
||||
}
|
||||
|
||||
public Player getTeleporter() {
|
||||
return teleporter;
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getTimeRemaining() {
|
||||
@@ -115,4 +196,11 @@ public class TimedTeleport {
|
||||
timeRemaining = timeRemaining - 1;
|
||||
}
|
||||
|
||||
public enum TargetType {
|
||||
POINT,
|
||||
BACK,
|
||||
PLAYER,
|
||||
RANDOM
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,5 +8,4 @@ public final class RegexUtil {
|
||||
public static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z0-9_\\-]+");
|
||||
public static final Pattern OWNER_NAME_PATTERN = Pattern.compile("[A-Za-z0-9_]+\\.[A-Za-z0-9_\\-]+");
|
||||
|
||||
private RegexUtil() { }
|
||||
}
|
||||
Reference in new issue
Block a user