mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Fix connection closure with cancelled events, and fix delete home / warp event not actually cancelling.
This commit is contained in:
1 parent
7ef9159daf
commit
2efc190d53
3 files changed
+96
-53
No files matched your search
@@ -74,13 +74,13 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
||||
case "location" -> editHomeLocation(p, home, connection);
|
||||
case "public" -> editHomePrivacy(p, home, true, connection);
|
||||
case "private" -> editHomePrivacy(p, home, false, connection);
|
||||
case "location" -> editHomeLocation(p, home);
|
||||
case "public" -> editHomePrivacy(p, home, true);
|
||||
case "private" -> editHomePrivacy(p, home, false);
|
||||
case "description" -> {
|
||||
if (args.length >= 3) {
|
||||
// Get the new description
|
||||
editHomeDescription(p, home, buildDescription(args), connection);
|
||||
editHomeDescription(p, home, buildDescription(args));
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
return newDescription.toString();
|
||||
}
|
||||
|
||||
private void editHomeLocation(Player p, Home locationMovedHome, Connection connection) throws SQLException {
|
||||
private void editHomeLocation(Player p, Home locationMovedHome) throws SQLException {
|
||||
Location newLocation = p.getLocation();
|
||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
||||
|
||||
@@ -123,7 +123,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
if (relocateHomeEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
// Remove old marker on map
|
||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
HuskHomes.getMap().removePublicHomeMarker(locationMovedHome.getName(), locationMovedHome.getOwnerUsername());
|
||||
@@ -143,7 +143,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
private void editHomeDescription(Player p, Home descriptionChangedHome, String newDescriptionString, Connection connection) throws SQLException {
|
||||
private void editHomeDescription(Player p, Home descriptionChangedHome, String newDescriptionString) throws SQLException {
|
||||
assert descriptionChangedHome != null;
|
||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
@@ -152,7 +152,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
// Check the description is valid
|
||||
if (newDescriptionString.length() > 255) {
|
||||
MessageManager.sendMessage(p, "error_edit_home_description_length");
|
||||
@@ -209,15 +209,15 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
if (renamedHome.isPublic()) {
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
HuskHomes.getMap().removePublicHomeMarker(oldHomeName, renamedHome.getOwnerUsername());
|
||||
}
|
||||
DataManager.updateHomeName(renamedHome.getOwnerUsername(), oldHomeName, newName, connection);
|
||||
DataManager.updateHomeName(renamedHome.getOwnerUsername(), oldHomeName, newName, connection1);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
DataManager.updateHomeName(renamedHome.getOwnerUsername(), oldHomeName, newName, connection);
|
||||
DataManager.updateHomeName(renamedHome.getOwnerUsername(), oldHomeName, newName, connection1);
|
||||
}
|
||||
renamedHome.setName(newName);
|
||||
if (renamedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
@@ -232,7 +232,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
private void editHomePrivacy(Player p, Home privacyUpdatingHome, boolean makingHomePublic, Connection connection) throws SQLException {
|
||||
private void editHomePrivacy(Player p, Home privacyUpdatingHome, boolean makingHomePublic) throws SQLException {
|
||||
assert privacyUpdatingHome != null;
|
||||
if (makingHomePublic) {
|
||||
// Making a private home
|
||||
@@ -259,7 +259,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
DataManager.updateHomePrivacy(privacyUpdatingHome.getOwnerUsername(), privacyUpdatingHome.getName(), true, connection);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
@@ -282,7 +282,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
DataManager.updateHomePrivacy(privacyUpdatingHome.getOwnerUsername(), privacyUpdatingHome.getName(), false, connection);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", privacyUpdatingHome.getName());
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
String warpName = args[0];
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try(Connection connection = HuskHomes.getConnection()) {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (!DataManager.warpExists(warpName, connection)) {
|
||||
MessageManager.sendMessage(p, "error_warp_invalid", warpName);
|
||||
return;
|
||||
@@ -91,13 +91,13 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
if (relocateWarpEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
// Remove old marker on map
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
|
||||
DataManager.updateWarpLocation(warpName, newLocation, connection);
|
||||
DataManager.updateWarpLocation(warpName, newLocation, connection1);
|
||||
MessageManager.sendMessage(p, "edit_warp_update_location", warpName);
|
||||
|
||||
// Add new updated marker on map
|
||||
@@ -121,7 +121,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
// Check the description is valid
|
||||
if (newDescriptionString.length() > 255) {
|
||||
MessageManager.sendMessage(p, "error_edit_warp_description_length");
|
||||
@@ -140,7 +140,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
|
||||
// Update description
|
||||
DataManager.updateWarpDescription(warpName, newDescriptionString, connection);
|
||||
DataManager.updateWarpDescription(warpName, newDescriptionString, connection1);
|
||||
|
||||
// Add new marker to map if applicable
|
||||
descriptionChangedWarp.setDescription(newDescriptionString);
|
||||
@@ -179,11 +179,11 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
DataManager.updateWarpName(warpName, newName, connection);
|
||||
DataManager.updateWarpName(warpName, newName, connection1);
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
renamedWarp.setName(newName);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
|
||||
@@ -36,15 +36,15 @@ public class SettingHandler {
|
||||
SetHomeConditions setHomeConditions = new SetHomeConditions(player, name, connection);
|
||||
if (setHomeConditions.areConditionsMet()) {
|
||||
Home home = new Home(location, HuskHomes.getSettings().getServerID(), player, name, false);
|
||||
PlayerSetHomeEvent event = new PlayerSetHomeEvent(player, home);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PlayerSetHomeEvent event = new PlayerSetHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
DataManager.addHome(home, player, connection);
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
DataManager.addHome(home, player, connection1);
|
||||
MessageManager.sendMessage(player, "set_home_success", name);
|
||||
HomeCommand.Tab.updatePlayerHomeCache(player);
|
||||
} catch (SQLException e) {
|
||||
@@ -122,8 +122,8 @@ public class SettingHandler {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
DataManager.addWarp(warp, connection);
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
DataManager.addWarp(warp, connection1);
|
||||
MessageManager.sendMessage(player, "set_warp_success", name);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().addWarpMarker(warp);
|
||||
@@ -150,7 +150,19 @@ public class SettingHandler {
|
||||
int homesDeleted = 0;
|
||||
for (Home home : DataManager.getPlayerHomes(player.getName(), connection)) {
|
||||
if (home != null) {
|
||||
deleteHomeData(player, home, connection);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
deleteHomeData(player, home, connection1);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
homesDeleted++;
|
||||
}
|
||||
@@ -184,17 +196,29 @@ public class SettingHandler {
|
||||
if (DataManager.homeExists(ownerName, homeName, connection)) {
|
||||
Home home = DataManager.getHome(ownerName, homeName, connection);
|
||||
if (home != null) {
|
||||
deleteHomeData(player, home, connection);
|
||||
if (home.getOwnerUsername().equalsIgnoreCase(player.getName())) {
|
||||
HomeCommand.Tab.updatePlayerHomeCache(player);
|
||||
MessageManager.sendMessage(player, "home_deleted", homeName);
|
||||
} else {
|
||||
Player homeOwner = Bukkit.getPlayerExact(ownerName);
|
||||
if (homeOwner != null) {
|
||||
HomeCommand.Tab.updatePlayerHomeCache(homeOwner);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
deleteHomeData(player, home, connection1);
|
||||
if (home.getOwnerUsername().equalsIgnoreCase(player.getName())) {
|
||||
HomeCommand.Tab.updatePlayerHomeCache(player);
|
||||
MessageManager.sendMessage(player, "home_deleted", homeName);
|
||||
} else {
|
||||
Player homeOwner = Bukkit.getPlayerExact(ownerName);
|
||||
if (homeOwner != null) {
|
||||
HomeCommand.Tab.updatePlayerHomeCache(homeOwner);
|
||||
}
|
||||
MessageManager.sendMessage(player, "home_deleted_other", ownerName, homeName);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
MessageManager.sendMessage(player, "home_deleted_other", ownerName, homeName);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!ownerName.equalsIgnoreCase(player.getName())) {
|
||||
MessageManager.sendMessage(player, "error_home_invalid_other", ownerName, homeName);
|
||||
@@ -229,8 +253,6 @@ public class SettingHandler {
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
HuskHomes.getMap().removePublicHomeMarker(home.getName(), home.getOwnerUsername());
|
||||
}
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteHome(player, home.getOwnerUsername(), home.getName(), connection);
|
||||
PublicHomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
@@ -246,12 +268,22 @@ public class SettingHandler {
|
||||
for (Warp warp : DataManager.getWarps(connection)) {
|
||||
if (warp != null) {
|
||||
String warpName = warp.getName();
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteWarp(warpName, connection);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
DataManager.deleteWarp(warpName, connection1);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
}
|
||||
warpsDeleted++;
|
||||
@@ -275,14 +307,25 @@ public class SettingHandler {
|
||||
try (Connection connection = HuskHomes.getConnection()) {
|
||||
if (DataManager.warpExists(warpName, connection)) {
|
||||
Warp warp = DataManager.getWarp(warpName, connection);
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
||||
DataManager.deleteWarp(warpName, connection);
|
||||
MessageManager.sendMessage(player, "warp_deleted", warpName);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
PlayerDeleteWarpEvent event = new PlayerDeleteWarpEvent(player, warp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection1 = HuskHomes.getConnection()) {
|
||||
DataManager.deleteWarp(warpName, connection1);
|
||||
MessageManager.sendMessage(player, "warp_deleted", warpName);
|
||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||
}
|
||||
WarpCommand.Tab.updateWarpsTabCache();
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
if (warpName.equalsIgnoreCase("all")) {
|
||||
if (!player.hasPermission("huskhomes.delwarp.all")) {
|
||||
|
||||
Reference in new issue
Block a user