mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Make events cancellable again
Signed-off-by: BuildTools <[email protected]>
This commit is contained in:
1 parent
0d8b2dce5b
commit
6ee2b2ce4d
11 files changed
+272
-151
No files matched your search
@@ -6,9 +6,9 @@ import me.william278.huskhomes2.config.Settings;
|
|||||||
import me.william278.huskhomes2.data.SQL.Database;
|
import me.william278.huskhomes2.data.SQL.Database;
|
||||||
import me.william278.huskhomes2.data.SQL.MySQL;
|
import me.william278.huskhomes2.data.SQL.MySQL;
|
||||||
import me.william278.huskhomes2.data.SQL.SQLite;
|
import me.william278.huskhomes2.data.SQL.SQLite;
|
||||||
import me.william278.huskhomes2.integrations.Map.BlueMap;
|
import me.william278.huskhomes2.integrations.map.BlueMap;
|
||||||
import me.william278.huskhomes2.integrations.Map.DynMap;
|
import me.william278.huskhomes2.integrations.map.DynMap;
|
||||||
import me.william278.huskhomes2.integrations.Map.Map;
|
import me.william278.huskhomes2.integrations.map.Map;
|
||||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||||
import me.william278.huskhomes2.listeners.PlayerListener;
|
import me.william278.huskhomes2.listeners.PlayerListener;
|
||||||
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
import me.william278.huskhomes2.listeners.PluginMessageListener;
|
||||||
|
|||||||
@@ -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.
|
* 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
|
* Also fires when it is deleted
|
||||||
*/
|
*/
|
||||||
public class PlayerHomeUpdateEvent extends Event {
|
public class PlayerHomeUpdateEvent extends Event implements Cancellable {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Home home;
|
private final Home home;
|
||||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
@@ -57,4 +57,14 @@ public class PlayerHomeUpdateEvent extends Event {
|
|||||||
public Home getHome() {
|
public Home getHome() {
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
isCancelled = cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ import org.bukkit.event.HandlerList;
|
|||||||
/**
|
/**
|
||||||
* An event, fired when a player sets a new home
|
* An event, fired when a player sets a new home
|
||||||
*/
|
*/
|
||||||
public class PlayerSetHomeEvent extends Event {
|
public class PlayerSetHomeEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private Player player;
|
private final Player player;
|
||||||
private Home home;
|
private final Home home;
|
||||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
|
|
||||||
@@ -54,4 +54,14 @@ public class PlayerSetHomeEvent extends Event {
|
|||||||
public Home getHome() {
|
public Home getHome() {
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
isCancelled = cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList;
|
|||||||
/**
|
/**
|
||||||
* An event, fired when a player sets a new warp
|
* An event, fired when a player sets a new warp
|
||||||
*/
|
*/
|
||||||
public class PlayerSetWarpEvent extends Event {
|
public class PlayerSetWarpEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Warp warp;
|
private final Warp warp;
|
||||||
@@ -54,4 +54,14 @@ public class PlayerSetWarpEvent extends Event {
|
|||||||
public Warp getWarp() {
|
public Warp getWarp() {
|
||||||
return warp;
|
return warp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
isCancelled = cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList;
|
|||||||
* Fires when a player renames a Warp, updates its' location or changes its' name.
|
* Fires when a player renames a Warp, updates its' location or changes its' name.
|
||||||
* Also fires when a warp is deleted
|
* Also fires when a warp is deleted
|
||||||
*/
|
*/
|
||||||
public class PlayerWarpUpdateEvent extends Event {
|
public class PlayerWarpUpdateEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Warp warp;
|
private final Warp warp;
|
||||||
@@ -58,4 +58,14 @@ public class PlayerWarpUpdateEvent extends Event {
|
|||||||
public Warp getWarp() {
|
public Warp getWarp() {
|
||||||
return warp;
|
return warp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
isCancelled = cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ import me.william278.huskhomes2.api.events.PlayerMakeHomePublicEvent;
|
|||||||
import me.william278.huskhomes2.api.events.PlayerRelocateHomeEvent;
|
import me.william278.huskhomes2.api.events.PlayerRelocateHomeEvent;
|
||||||
import me.william278.huskhomes2.api.events.PlayerRenameHomeEvent;
|
import me.william278.huskhomes2.api.events.PlayerRenameHomeEvent;
|
||||||
import me.william278.huskhomes2.data.DataManager;
|
import me.william278.huskhomes2.data.DataManager;
|
||||||
import me.william278.huskhomes2.integrations.Map.DynMap;
|
|
||||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||||
import me.william278.huskhomes2.teleport.points.Home;
|
import me.william278.huskhomes2.teleport.points.Home;
|
||||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||||
@@ -57,30 +56,11 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
||||||
case "location" -> {
|
case "location" -> editHomeLocation(p, homeName, connection);
|
||||||
Location newLocation = p.getLocation();
|
case "public" -> editHomePrivacy(p, homeName, true, connection);
|
||||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
case "private" -> editHomePrivacy(p, homeName, false, connection);
|
||||||
|
|
||||||
// Remove old marker if on dynmap
|
|
||||||
Home locationMovedHome = DataManager.getHome(p.getName(), homeName, connection);
|
|
||||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
|
||||||
}
|
|
||||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
|
||||||
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().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().addPublicHomeMarker(locationMovedHome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "description" -> {
|
case "description" -> {
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName, connection);
|
|
||||||
|
|
||||||
// Get the new description
|
// Get the new description
|
||||||
StringBuilder newDescription = new StringBuilder();
|
StringBuilder newDescription = new StringBuilder();
|
||||||
for (int i = 2; i < args.length; i++) {
|
for (int i = 2; i < args.length; i++) {
|
||||||
@@ -91,119 +71,18 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String newDescriptionString = newDescription.toString();
|
String newDescriptionString = newDescription.toString();
|
||||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
editHomeDescription(p, homeName, newDescriptionString, connection);
|
||||||
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");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old marker if on the Dynmap
|
|
||||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update description
|
|
||||||
DataManager.updateHomeDescription(p.getName(), homeName, newDescriptionString, connection);
|
|
||||||
|
|
||||||
// Add new marker if using Dynmap
|
|
||||||
descriptionChangedHome.setDescription(newDescriptionString);
|
|
||||||
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().addPublicHomeMarker(descriptionChangedHome);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Confirmation message
|
|
||||||
MessageManager.sendMessage(p, "edit_home_update_description", homeName, newDescriptionString);
|
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "rename" -> {
|
case "rename" -> {
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
String newName = args[2];
|
editHomeName(p, homeName, args[2], connection);
|
||||||
if (newName.length() > 16) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (DataManager.homeExists(p.getName(), newName, connection)) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Home renamedHome = DataManager.getHome(p.getName(), homeName, connection);
|
|
||||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(renameHomeEvent));
|
|
||||||
|
|
||||||
if (renamedHome.isPublic()) {
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
|
||||||
}
|
|
||||||
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
|
||||||
PublicHomeCommand.updatePublicHomeTabCache();
|
|
||||||
} else {
|
|
||||||
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
|
||||||
}
|
|
||||||
renamedHome.setName(newName);
|
|
||||||
if (renamedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().addPublicHomeMarker(renamedHome);
|
|
||||||
}
|
|
||||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
|
||||||
MessageManager.sendMessage(p, "edit_home_update_name", homeName, newName);
|
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "public" -> {
|
|
||||||
Home privateHome = DataManager.getHome(p.getName(), homeName, connection);
|
|
||||||
if (!privateHome.isPublic()) {
|
|
||||||
if (HuskHomes.getSettings().doEconomy()) {
|
|
||||||
double publicHomeCost = HuskHomes.getSettings().getPublicHomeCost();
|
|
||||||
if (publicHomeCost > 0) {
|
|
||||||
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
|
||||||
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
|
||||||
}
|
|
||||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(makeHomePublicEvent));
|
|
||||||
|
|
||||||
DataManager.updateHomePrivacy(p.getName(), homeName, true, connection);
|
|
||||||
PublicHomeCommand.updatePublicHomeTabCache();
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().addPublicHomeMarker(privateHome);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "private" -> {
|
|
||||||
Home publicHome = DataManager.getHome(p.getName(), homeName, connection);
|
|
||||||
if (publicHome.isPublic()) {
|
|
||||||
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, publicHome);
|
|
||||||
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().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
|
||||||
HuskHomes.getMap().removePublicHomeMarker(publicHome.getName(), publicHome.getOwnerUsername());
|
|
||||||
}
|
|
||||||
PublicHomeCommand.updatePublicHomeTabCache();
|
|
||||||
} else {
|
|
||||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default -> MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
default -> MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -212,6 +91,188 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void editHomeLocation(Player p, String homeName, Connection connection) throws SQLException {
|
||||||
|
Location newLocation = p.getLocation();
|
||||||
|
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
||||||
|
|
||||||
|
Home locationMovedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||||
|
if (relocateHomeEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Remove old marker on map
|
||||||
|
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
DataManager.updateHomeLocation(p.getName(), homeName, newLocation, connection);
|
||||||
|
MessageManager.sendMessage(p, "edit_home_update_location", homeName);
|
||||||
|
|
||||||
|
// Add new updated marker on map
|
||||||
|
locationMovedHome.setLocation(newLocation, HuskHomes.getSettings().getServerID());
|
||||||
|
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().addPublicHomeMarker(locationMovedHome);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred updating a home's location.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editHomeDescription(Player p, String homeName, String newDescriptionString, Connection connection) throws SQLException {
|
||||||
|
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||||
|
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
// Check the description is valid
|
||||||
|
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||||
|
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old marker if on the Dynmap
|
||||||
|
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update description
|
||||||
|
DataManager.updateHomeDescription(p.getName(), homeName, newDescriptionString, connection);
|
||||||
|
|
||||||
|
// Add new marker if using Dynmap
|
||||||
|
descriptionChangedHome.setDescription(newDescriptionString);
|
||||||
|
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().addPublicHomeMarker(descriptionChangedHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation message
|
||||||
|
MessageManager.sendMessage(p, "edit_home_update_description", homeName, newDescriptionString);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home description.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editHomeName(Player p, String homeName, String newName, Connection connection) throws SQLException {
|
||||||
|
if (newName.length() > 16) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (DataManager.homeExists(p.getName(), newName, connection)) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Home renamedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||||
|
if (renameHomeEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
if (renamedHome.isPublic()) {
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().removePublicHomeMarker(homeName, p.getName());
|
||||||
|
}
|
||||||
|
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
||||||
|
PublicHomeCommand.updatePublicHomeTabCache();
|
||||||
|
} else {
|
||||||
|
DataManager.updateHomeName(p.getName(), homeName, newName, connection);
|
||||||
|
}
|
||||||
|
renamedHome.setName(newName);
|
||||||
|
if (renamedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().addPublicHomeMarker(renamedHome);
|
||||||
|
}
|
||||||
|
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||||
|
MessageManager.sendMessage(p, "edit_home_update_name", homeName, newName);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home name.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editHomePrivacy(Player p, String homeName, boolean makingHomePublic, Connection connection) throws SQLException {
|
||||||
|
Home home = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
if (makingHomePublic) {
|
||||||
|
// Making a private home
|
||||||
|
if (!home.isPublic()) {
|
||||||
|
if (HuskHomes.getSettings().doEconomy()) {
|
||||||
|
double publicHomeCost = HuskHomes.getSettings().getPublicHomeCost();
|
||||||
|
if (publicHomeCost > 0) {
|
||||||
|
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
||||||
|
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||||
|
}
|
||||||
|
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, home);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||||
|
if (makeHomePublicEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
DataManager.updateHomePrivacy(p.getName(), homeName, true, connection);
|
||||||
|
PublicHomeCommand.updatePublicHomeTabCache();
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().addPublicHomeMarker(home);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home's privacy.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (home.isPublic()) {
|
||||||
|
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, home);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
||||||
|
if (makeHomePrivateEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
DataManager.updateHomePrivacy(p.getName(), homeName, false, connection);
|
||||||
|
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
|
HuskHomes.getMap().removePublicHomeMarker(home.getName(), home.getOwnerUsername());
|
||||||
|
}
|
||||||
|
PublicHomeCommand.updatePublicHomeTabCache();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home's privacy.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.william278.huskhomes2.integrations.Map;
|
package me.william278.huskhomes2.integrations.map;
|
||||||
|
|
||||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||||
import de.bluecolored.bluemap.api.BlueMapMap;
|
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.william278.huskhomes2.integrations.Map;
|
package me.william278.huskhomes2.integrations.map;
|
||||||
|
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.data.DataManager;
|
import me.william278.huskhomes2.data.DataManager;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package me.william278.huskhomes2.integrations.Map;
|
package me.william278.huskhomes2.integrations.map;
|
||||||
|
|
||||||
import me.william278.huskhomes2.teleport.points.Home;
|
import me.william278.huskhomes2.teleport.points.Home;
|
||||||
import me.william278.huskhomes2.teleport.points.Warp;
|
import me.william278.huskhomes2.teleport.points.Warp;
|
||||||
@@ -68,7 +68,7 @@ public class EssentialsMigrator {
|
|||||||
DataManager.addHome(playerHome, uuid, connection);
|
DataManager.addHome(playerHome, uuid, connection);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurredf migrating Essentials data!", e);
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred migrating Essentials home data!", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public class EssentialsMigrator {
|
|||||||
DataManager.addWarp(warp, connection);
|
DataManager.addWarp(warp, connection);
|
||||||
Bukkit.getLogger().info("Migrated warp \"" + warpName + "\"");
|
Bukkit.getLogger().info("Migrated warp \"" + warpName + "\"");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurredf migrating Essentials data!", e);
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred migrating Essentials warp data!", e);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
Bukkit.getLogger().warning("Error obtaining a warp's data!");
|
Bukkit.getLogger().warning("Error obtaining a warp's data!");
|
||||||
|
|||||||
@@ -40,10 +40,19 @@ public class SettingHandler {
|
|||||||
PlayerSetHomeEvent event = new PlayerSetHomeEvent(player, home);
|
PlayerSetHomeEvent event = new PlayerSetHomeEvent(player, home);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
DataManager.addHome(home, player, connection);
|
||||||
|
MessageManager.sendMessage(player, "set_home_success", name);
|
||||||
|
HomeCommand.Tab.updatePlayerHomeCache(player);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
DataManager.addHome(home, player, connection);
|
|
||||||
MessageManager.sendMessage(player, "set_home_success", name);
|
|
||||||
HomeCommand.Tab.updatePlayerHomeCache(player);
|
|
||||||
} else {
|
} else {
|
||||||
switch (setHomeConditions.getConditionsNotMetReason()) {
|
switch (setHomeConditions.getConditionsNotMetReason()) {
|
||||||
case "error_set_home_maximum_homes" -> {
|
case "error_set_home_maximum_homes" -> {
|
||||||
@@ -113,14 +122,25 @@ public class SettingHandler {
|
|||||||
SetWarpConditions setWarpConditions = new SetWarpConditions(name, connection);
|
SetWarpConditions setWarpConditions = new SetWarpConditions(name, connection);
|
||||||
if (setWarpConditions.areConditionsMet()) {
|
if (setWarpConditions.areConditionsMet()) {
|
||||||
Warp warp = new Warp(location, HuskHomes.getSettings().getServerID(), name);
|
Warp warp = new Warp(location, HuskHomes.getSettings().getServerID(), name);
|
||||||
PlayerSetWarpEvent event = new PlayerSetWarpEvent(player, warp);
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(event));
|
PlayerSetWarpEvent event = new PlayerSetWarpEvent(player, warp);
|
||||||
DataManager.addWarp(warp, connection);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
MessageManager.sendMessage(player, "set_warp_success", name);
|
if (event.isCancelled()) {
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
return;
|
||||||
HuskHomes.getMap().addWarpMarker(warp);
|
}
|
||||||
}
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
WarpCommand.Tab.updateWarpsTabCache();
|
try {
|
||||||
|
DataManager.addWarp(warp, connection);
|
||||||
|
MessageManager.sendMessage(player, "set_warp_success", name);
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().addWarpMarker(warp);
|
||||||
|
}
|
||||||
|
WarpCommand.Tab.updateWarpsTabCache();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred!", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(player, setWarpConditions.getConditionsNotMetReason());
|
MessageManager.sendMessage(player, setWarpConditions.getConditionsNotMetReason());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user