mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Escape home and warp descriptions properly in lists; allow warp update events to be cancelled
Signed-off-by: BuildTools <[email protected]>
This commit is contained in:
1 parent
3b5140f794
commit
7bf23541ef
5 files changed
+149
-97
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2;
|
package me.william278.huskhomes2;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
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;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -8,7 +9,7 @@ public class EditingHandler {
|
|||||||
|
|
||||||
public static void showEditHomeOptions(Player p, Home home) {
|
public static void showEditHomeOptions(Player p, Home home) {
|
||||||
MessageManager.sendMessage(p, "edit_home_title", home.getName());
|
MessageManager.sendMessage(p, "edit_home_title", home.getName());
|
||||||
MessageManager.sendMessage(p, "edit_description", home.getDescription());
|
p.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("edit_description")).replaceFirst(false).replace("%1%", home.getDescription()).toComponent());
|
||||||
MessageManager.sendMessage(p, "edit_location",
|
MessageManager.sendMessage(p, "edit_location",
|
||||||
Integer.toString((int) home.getX()),
|
Integer.toString((int) home.getX()),
|
||||||
Integer.toString((int) home.getY()),
|
Integer.toString((int) home.getY()),
|
||||||
@@ -36,7 +37,7 @@ public class EditingHandler {
|
|||||||
|
|
||||||
public static void showEditWarpOptions(Player p, Warp warp) {
|
public static void showEditWarpOptions(Player p, Warp warp) {
|
||||||
MessageManager.sendMessage(p, "edit_warp_title", warp.getName());
|
MessageManager.sendMessage(p, "edit_warp_title", warp.getName());
|
||||||
MessageManager.sendMessage(p, "edit_description", warp.getDescription());
|
p.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("edit_description")).replaceFirst(false).replace("%1%", warp.getDescription()).toComponent());
|
||||||
MessageManager.sendMessage(p, "edit_location",
|
MessageManager.sendMessage(p, "edit_location",
|
||||||
Integer.toString((int) warp.getX()),
|
Integer.toString((int) warp.getX()),
|
||||||
Integer.toString((int) warp.getY()),
|
Integer.toString((int) warp.getY()),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2.commands;
|
package me.william278.huskhomes2.commands;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
import me.william278.huskhomes2.EditingHandler;
|
import me.william278.huskhomes2.EditingHandler;
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
@@ -51,6 +52,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
Home home = DataManager.getHome(p.getName(), homeName, connection);
|
Home home = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
assert home != null;
|
||||||
EditingHandler.showEditHomeOptions(p, home);
|
EditingHandler.showEditHomeOptions(p, home);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,6 +98,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
||||||
|
|
||||||
Home locationMovedHome = DataManager.getHome(p.getName(), homeName, connection);
|
Home locationMovedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
assert locationMovedHome != null;
|
||||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||||
@@ -124,6 +127,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
|
|
||||||
private void editHomeDescription(Player p, String homeName, String newDescriptionString, Connection connection) throws SQLException {
|
private void editHomeDescription(Player p, String homeName, String newDescriptionString, Connection connection) throws SQLException {
|
||||||
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName, connection);
|
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
assert descriptionChangedHome != null;
|
||||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||||
@@ -159,7 +163,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Confirmation message
|
// Confirmation message
|
||||||
MessageManager.sendMessage(p, "edit_home_update_description", homeName, newDescriptionString);
|
MessageManager.sendMessage(p, "edit_home_update_description", homeName, MineDown.escape(newDescriptionString));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home description.");
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home description.");
|
||||||
}
|
}
|
||||||
@@ -181,6 +185,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Home renamedHome = DataManager.getHome(p.getName(), homeName, connection);
|
Home renamedHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
assert renamedHome != null;
|
||||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||||
@@ -212,10 +217,11 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void editHomePrivacy(Player p, String homeName, boolean makingHomePublic, Connection connection) throws SQLException {
|
private void editHomePrivacy(Player p, String homeName, boolean makingHomePublic, Connection connection) throws SQLException {
|
||||||
Home home = DataManager.getHome(p.getName(), homeName, connection);
|
Home privacyUpdatingHome = DataManager.getHome(p.getName(), homeName, connection);
|
||||||
|
assert privacyUpdatingHome != null;
|
||||||
if (makingHomePublic) {
|
if (makingHomePublic) {
|
||||||
// Making a private home
|
// Making a private home
|
||||||
if (!home.isPublic()) {
|
if (!privacyUpdatingHome.isPublic()) {
|
||||||
if (HuskHomes.getSettings().doEconomy()) {
|
if (HuskHomes.getSettings().doEconomy()) {
|
||||||
double publicHomeCost = HuskHomes.getSettings().getPublicHomeCost();
|
double publicHomeCost = HuskHomes.getSettings().getPublicHomeCost();
|
||||||
if (publicHomeCost > 0) {
|
if (publicHomeCost > 0) {
|
||||||
@@ -231,7 +237,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||||
}
|
}
|
||||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, home);
|
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privacyUpdatingHome);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||||
if (makeHomePublicEvent.isCancelled()) {
|
if (makeHomePublicEvent.isCancelled()) {
|
||||||
@@ -242,7 +248,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
DataManager.updateHomePrivacy(p.getName(), homeName, true, connection);
|
DataManager.updateHomePrivacy(p.getName(), homeName, true, connection);
|
||||||
PublicHomeCommand.updatePublicHomeTabCache();
|
PublicHomeCommand.updatePublicHomeTabCache();
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
HuskHomes.getMap().addPublicHomeMarker(home);
|
HuskHomes.getMap().addPublicHomeMarker(privacyUpdatingHome);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home's privacy.");
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a home's privacy.");
|
||||||
@@ -253,8 +259,8 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (home.isPublic()) {
|
if (privacyUpdatingHome.isPublic()) {
|
||||||
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, home);
|
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, privacyUpdatingHome);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
||||||
if (makeHomePrivateEvent.isCancelled()) {
|
if (makeHomePrivateEvent.isCancelled()) {
|
||||||
@@ -265,7 +271,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
|||||||
DataManager.updateHomePrivacy(p.getName(), homeName, false, connection);
|
DataManager.updateHomePrivacy(p.getName(), homeName, false, connection);
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||||
HuskHomes.getMap().removePublicHomeMarker(home.getName(), home.getOwnerUsername());
|
HuskHomes.getMap().removePublicHomeMarker(privacyUpdatingHome.getName(), privacyUpdatingHome.getOwnerUsername());
|
||||||
}
|
}
|
||||||
PublicHomeCommand.updatePublicHomeTabCache();
|
PublicHomeCommand.updatePublicHomeTabCache();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2.commands;
|
package me.william278.huskhomes2.commands;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
import me.william278.huskhomes2.EditingHandler;
|
import me.william278.huskhomes2.EditingHandler;
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
@@ -23,6 +24,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class EditWarpCommand extends CommandBase implements TabCompleter {
|
public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||||
@@ -46,36 +48,16 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
Warp warp = DataManager.getWarp(warpName, connection);
|
final Warp warp = DataManager.getWarp(warpName, connection);
|
||||||
|
assert warp != null;
|
||||||
EditingHandler.showEditWarpOptions(p, warp);
|
EditingHandler.showEditWarpOptions(p, warp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[1]) {
|
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
||||||
case "location" -> {
|
case "location" -> editWarpLocation(p, warpName, connection);
|
||||||
Location newLocation = p.getLocation();
|
|
||||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
|
||||||
|
|
||||||
// Remove old marker if on the Dynmap
|
|
||||||
Warp locationMovedWarp = DataManager.getWarp(warpName, connection);
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
|
||||||
}
|
|
||||||
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
|
||||||
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().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().addWarpMarker(locationMovedWarp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "description" -> {
|
case "description" -> {
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Warp descriptionChangedWarp = DataManager.getWarp(warpName, 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++) {
|
||||||
@@ -86,83 +68,144 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String newDescriptionString = newDescription.toString();
|
String newDescriptionString = newDescription.toString();
|
||||||
|
editWarpDescription(p, warpName, newDescriptionString, connection);
|
||||||
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent));
|
|
||||||
|
|
||||||
|
|
||||||
// Check the description is valid
|
|
||||||
if (newDescriptionString.length() > 255) {
|
|
||||||
MessageManager.sendMessage(p, "error_edit_warp_description_length");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!HuskHomes.getSettings().doUnicodeInDescriptions()) {
|
|
||||||
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
|
||||||
MessageManager.sendMessage(p, "error_edit_warp_description_characters");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update description
|
|
||||||
DataManager.updateWarpDescription(warpName, newDescriptionString, connection);
|
|
||||||
|
|
||||||
descriptionChangedWarp.setDescription(newDescriptionString);
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().addWarpMarker(descriptionChangedWarp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Confirmation message
|
|
||||||
MessageManager.sendMessage(p, "edit_warp_update_description", warpName, newDescriptionString);
|
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "rename" -> {
|
case "rename" -> {
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Warp renamedWarp = DataManager.getWarp(warpName, connection);
|
editWarpName(p, warpName, args[2], connection);
|
||||||
String newName = args[2];
|
|
||||||
if (newName.length() > 16) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_warp_invalid_length");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_warp_invalid_characters");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (DataManager.warpExists(newName, connection)) {
|
|
||||||
MessageManager.sendMessage(p, "error_set_warp_name_taken");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(renameWarpEvent));
|
|
||||||
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().removeWarpMarker(warpName);
|
|
||||||
}
|
|
||||||
DataManager.updateWarpName(warpName, newName, connection);
|
|
||||||
|
|
||||||
renamedWarp.setName(newName);
|
|
||||||
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
|
||||||
HuskHomes.getMap().addWarpMarker(renamedWarp);
|
|
||||||
}
|
|
||||||
WarpCommand.Tab.updateWarpsTabCache();
|
|
||||||
MessageManager.sendMessage(p, "edit_warp_update_name", warpName, newName);
|
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> rename <new warp>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> rename <new name>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default -> MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
default -> MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL exception occured editing a warp.", e);
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a warp.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void editWarpLocation(Player p, String warpName, Connection connection) throws SQLException {
|
||||||
|
Location newLocation = p.getLocation();
|
||||||
|
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
||||||
|
|
||||||
|
Warp locationMovedWarp = DataManager.getWarp(warpName, connection);
|
||||||
|
assert locationMovedWarp != null;
|
||||||
|
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(relocateWarpEvent);
|
||||||
|
if (relocateWarpEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Remove old marker on map
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataManager.updateWarpLocation(warpName, newLocation, connection);
|
||||||
|
MessageManager.sendMessage(p, "edit_warp_update_location", warpName);
|
||||||
|
|
||||||
|
// Add new updated marker on map
|
||||||
|
locationMovedWarp.setLocation(newLocation, HuskHomes.getSettings().getServerID());
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().addWarpMarker(locationMovedWarp);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred updating a warp's location.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editWarpDescription(Player p, String warpName, String newDescriptionString, Connection connection) throws SQLException {
|
||||||
|
Warp descriptionChangedWarp = DataManager.getWarp(warpName, connection);
|
||||||
|
assert descriptionChangedWarp != null;
|
||||||
|
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent);
|
||||||
|
if (changeWarpDescriptionEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
// Check the description is valid
|
||||||
|
if (newDescriptionString.length() > 255) {
|
||||||
|
MessageManager.sendMessage(p, "error_edit_warp_description_length");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!HuskHomes.getSettings().doUnicodeInDescriptions()) {
|
||||||
|
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||||
|
MessageManager.sendMessage(p, "error_edit_warp_description_characters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old marker if on map
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update description
|
||||||
|
DataManager.updateWarpDescription(warpName, newDescriptionString, connection);
|
||||||
|
|
||||||
|
// Add new marker to map if applicable
|
||||||
|
descriptionChangedWarp.setDescription(newDescriptionString);
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().addWarpMarker(descriptionChangedWarp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation message
|
||||||
|
MessageManager.sendMessage(p, "edit_warp_update_description", warpName, MineDown.escape(newDescriptionString));
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a warp's description.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editWarpName(Player p, String warpName, String newName, Connection connection) throws SQLException {
|
||||||
|
if (newName.length() > 16) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_warp_invalid_length");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_warp_invalid_characters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (DataManager.warpExists(newName, connection)) {
|
||||||
|
MessageManager.sendMessage(p, "error_set_warp_name_taken");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Warp renamedWarp = DataManager.getWarp(warpName, connection);
|
||||||
|
assert renamedWarp != null;
|
||||||
|
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(renameWarpEvent);
|
||||||
|
if (renameWarpEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
try {
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().removeWarpMarker(warpName);
|
||||||
|
}
|
||||||
|
DataManager.updateWarpName(warpName, newName, connection);
|
||||||
|
WarpCommand.Tab.updateWarpsTabCache();
|
||||||
|
renamedWarp.setName(newName);
|
||||||
|
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
|
||||||
|
HuskHomes.getMap().addWarpMarker(renamedWarp);
|
||||||
|
}
|
||||||
|
MessageManager.sendMessage(p, "edit_warp_update_name", warpName, newName);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "An SQL exception occurred editing a warp name.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@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,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2.commands;
|
package me.william278.huskhomes2.commands;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
import me.william278.huskhomes2.data.DataManager;
|
import me.william278.huskhomes2.data.DataManager;
|
||||||
@@ -45,7 +46,7 @@ public class HomeListCommand extends CommandBase {
|
|||||||
|
|
||||||
ArrayList<String> homeList = new ArrayList<>();
|
ArrayList<String> homeList = new ArrayList<>();
|
||||||
for (Home home : homes) {
|
for (Home home : homes) {
|
||||||
homeList.add(MessageManager.getRawMessage("home_list_item", home.getName(), home.getDescription()));
|
homeList.add(MessageManager.getRawMessage("home_list_item", home.getName(), MineDown.escape(home.getDescription())));
|
||||||
}
|
}
|
||||||
|
|
||||||
final int itemsPerPage = HuskHomes.getSettings().getPrivateHomesPerPage();
|
final int itemsPerPage = HuskHomes.getSettings().getPrivateHomesPerPage();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2.commands;
|
package me.william278.huskhomes2.commands;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
import me.william278.huskhomes2.data.DataManager;
|
import me.william278.huskhomes2.data.DataManager;
|
||||||
@@ -47,7 +48,7 @@ public class WarpListCommand extends CommandBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
warpList.add(MessageManager.getRawMessage("warp_list_item", warp.getName(), warp.getDescription()));
|
warpList.add(MessageManager.getRawMessage("warp_list_item", warp.getName(), MineDown.escape(warp.getDescription()))); //todo escape formatting on warp desc
|
||||||
}
|
}
|
||||||
if (warpList.isEmpty()) {
|
if (warpList.isEmpty()) {
|
||||||
MessageManager.sendMessage(player, "error_no_warps_set");
|
MessageManager.sendMessage(player, "error_no_warps_set");
|
||||||
|
|||||||
Reference in new issue
Block a user