mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Simplify CommandBase's onCommand
Added some TODOs to do Replaced "dynamic" regex with cached Patterns
This commit is contained in:
30 files changed
+122
-106
No files matched your search
@@ -10,13 +10,12 @@ import org.bukkit.entity.Player;
|
|||||||
public class BackCommand extends CommandBase {
|
public class BackCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
TeleportationPoint lastPosition = DataManager.getPlayerLastPosition(p);
|
TeleportationPoint lastPosition = DataManager.getPlayerLastPosition(p);
|
||||||
if (lastPosition != null) {
|
if (lastPosition != null) {
|
||||||
TeleportManager.queueTimedTeleport(p, lastPosition);
|
TeleportManager.queueTimedTeleport(p, lastPosition);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_no_last_position");
|
MessageManager.sendMessage(p, "error_no_last_position");
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,12 +15,13 @@ public abstract class CommandBase implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return onCommand((Player) sender, command, label, args);
|
onCommand((Player) sender, command, label, args);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean onCommand(Player player, Command command, String label, String[] args);
|
protected abstract void onCommand(Player player, Command command, String label, String[] args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register base for bukkit command
|
* Register base for bukkit command
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
|||||||
public class DelhomeCommand extends CommandBase {
|
public class DelhomeCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String homeName = args[0];
|
String homeName = args[0];
|
||||||
SettingHandler.deleteHome(p, homeName);
|
SettingHandler.deleteHome(p, homeName);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
|||||||
public class DelwarpCommand extends CommandBase {
|
public class DelwarpCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String warpName = args[0];
|
String warpName = args[0];
|
||||||
SettingHandler.deleteWarp(p, warpName);
|
SettingHandler.deleteWarp(p, warpName);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ import me.william278.huskhomes2.integrations.DynMapIntegration;
|
|||||||
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;
|
||||||
|
import me.william278.huskhomes2.utils.RegexUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@@ -29,22 +30,22 @@ import java.util.Locale;
|
|||||||
public class EdithomeCommand extends CommandBase implements TabCompleter {
|
public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String homeName = args[0];
|
String homeName = args[0];
|
||||||
if (!DataManager.homeExists(p.getName(), homeName)) {
|
if (!DataManager.homeExists(p.getName(), homeName)) {
|
||||||
MessageManager.sendMessage(p, "error_home_invalid", homeName);
|
MessageManager.sendMessage(p, "error_home_invalid", homeName);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
Home home = DataManager.getHome(p.getName(), homeName);
|
Home home = DataManager.getHome(p.getName(), homeName);
|
||||||
EditingHandler.showEditHomeOptions(p, home);
|
EditingHandler.showEditHomeOptions(p, home);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
||||||
@@ -61,7 +62,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||||
if (relocateHomeEvent.isCancelled()) {
|
if (relocateHomeEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataManager.updateHomeLocation(p.getName(), homeName, newLocation);
|
DataManager.updateHomeLocation(p.getName(), homeName, newLocation);
|
||||||
@@ -72,7 +73,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
if (locationMovedHome.isPublic() && HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||||
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "description":
|
case "description":
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName);
|
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName);
|
||||||
@@ -90,12 +91,12 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||||
if (changeHomeDescriptionEvent.isCancelled()) {
|
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
// Check the description is valid
|
// Check the description is valid
|
||||||
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
|
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||||
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove old marker if on the Dynmap
|
// Remove old marker if on the Dynmap
|
||||||
@@ -117,27 +118,27 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "rename":
|
case "rename":
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
String newName = args[2];
|
String newName = args[2];
|
||||||
if (newName.length() > 16) {
|
if (newName.length() > 16) {
|
||||||
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (!newName.matches("[A-Za-z0-9_\\-]+")) {
|
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
||||||
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (DataManager.homeExists(p.getName(), newName)) {
|
if (DataManager.homeExists(p.getName(), newName)) {
|
||||||
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
Home renamedHome = DataManager.getHome(p.getName(), homeName);
|
Home renamedHome = DataManager.getHome(p.getName(), homeName);
|
||||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||||
if (renameHomeEvent.isCancelled()) {
|
if (renameHomeEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (renamedHome.isPublic()) {
|
if (renamedHome.isPublic()) {
|
||||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||||
@@ -157,7 +158,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "public":
|
case "public":
|
||||||
Home privateHome = DataManager.getHome(p.getName(), homeName);
|
Home privateHome = DataManager.getHome(p.getName(), homeName);
|
||||||
if (!privateHome.isPublic()) {
|
if (!privateHome.isPublic()) {
|
||||||
@@ -166,7 +167,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
if (publicHomeCost > 0) {
|
if (publicHomeCost > 0) {
|
||||||
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
||||||
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
||||||
return true;
|
return;
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
||||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||||
if (makeHomePublicEvent.isCancelled()) {
|
if (makeHomePublicEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
DataManager.updateHomePrivacy(p.getName(), homeName, true);
|
DataManager.updateHomePrivacy(p.getName(), homeName, true);
|
||||||
PublichomeCommand.updatePublicHomeTabCache();
|
PublichomeCommand.updatePublicHomeTabCache();
|
||||||
@@ -189,14 +190,14 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "private":
|
case "private":
|
||||||
Home publicHome = DataManager.getHome(p.getName(), homeName);
|
Home publicHome = DataManager.getHome(p.getName(), homeName);
|
||||||
if (publicHome.isPublic()) {
|
if (publicHome.isPublic()) {
|
||||||
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, publicHome);
|
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, publicHome);
|
||||||
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
||||||
if (makeHomePrivateEvent.isCancelled()) {
|
if (makeHomePrivateEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
DataManager.updateHomePrivacy(p.getName(), homeName, false);
|
DataManager.updateHomePrivacy(p.getName(), homeName, false);
|
||||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||||
@@ -207,10 +208,10 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
default:
|
default:
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import me.william278.huskhomes2.data.DataManager;
|
|||||||
import me.william278.huskhomes2.integrations.DynMapIntegration;
|
import me.william278.huskhomes2.integrations.DynMapIntegration;
|
||||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||||
import me.william278.huskhomes2.teleport.points.Warp;
|
import me.william278.huskhomes2.teleport.points.Warp;
|
||||||
|
import me.william278.huskhomes2.utils.RegexUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@@ -25,22 +26,22 @@ import java.util.List;
|
|||||||
public class EditwarpCommand extends CommandBase implements TabCompleter {
|
public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String warpName = args[0];
|
String warpName = args[0];
|
||||||
if (!DataManager.warpExists(warpName)) {
|
if (!DataManager.warpExists(warpName)) {
|
||||||
MessageManager.sendMessage(p, "error_warp_invalid", warpName);
|
MessageManager.sendMessage(p, "error_warp_invalid", warpName);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
Warp warp = DataManager.getWarp(warpName);
|
Warp warp = DataManager.getWarp(warpName);
|
||||||
EditingHandler.showEditWarpOptions(p, warp);
|
EditingHandler.showEditWarpOptions(p, warp);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[1]) {
|
switch (args[1]) {
|
||||||
@@ -57,7 +58,7 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
|||||||
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
||||||
Bukkit.getPluginManager().callEvent(relocateWarpEvent);
|
Bukkit.getPluginManager().callEvent(relocateWarpEvent);
|
||||||
if (relocateWarpEvent.isCancelled()) {
|
if (relocateWarpEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataManager.updateWarpLocation(warpName, p.getLocation());
|
DataManager.updateWarpLocation(warpName, p.getLocation());
|
||||||
@@ -68,7 +69,7 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
|||||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||||
DynMapIntegration.addDynamicMapMarker(locationMovedWarp);
|
DynMapIntegration.addDynamicMapMarker(locationMovedWarp);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "description":
|
case "description":
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Warp descriptionChangedWarp = DataManager.getWarp(warpName);
|
Warp descriptionChangedWarp = DataManager.getWarp(warpName);
|
||||||
@@ -87,13 +88,13 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
|||||||
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
||||||
Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent);
|
Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent);
|
||||||
if (changeWarpDescriptionEvent.isCancelled()) {
|
if (changeWarpDescriptionEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the description is valid
|
// Check the description is valid
|
||||||
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
|
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
|
||||||
MessageManager.sendMessage(p, "error_edit_warp_invalid_description");
|
MessageManager.sendMessage(p, "error_edit_warp_invalid_description");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||||
@@ -113,27 +114,27 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case "rename":
|
case "rename":
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
Warp renamedWarp = DataManager.getWarp(warpName);
|
Warp renamedWarp = DataManager.getWarp(warpName);
|
||||||
String newName = args[2];
|
String newName = args[2];
|
||||||
if (newName.length() > 16) {
|
if (newName.length() > 16) {
|
||||||
MessageManager.sendMessage(p, "error_set_warp_invalid_length");
|
MessageManager.sendMessage(p, "error_set_warp_invalid_length");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (!newName.matches("[A-Za-z0-9_\\-]+")) {
|
if (!RegexUtil.NAME_PATTERN.matcher(newName).matches()) {
|
||||||
MessageManager.sendMessage(p, "error_set_warp_invalid_characters");
|
MessageManager.sendMessage(p, "error_set_warp_invalid_characters");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (DataManager.warpExists(newName)) {
|
if (DataManager.warpExists(newName)) {
|
||||||
MessageManager.sendMessage(p, "error_set_warp_name_taken");
|
MessageManager.sendMessage(p, "error_set_warp_name_taken");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
||||||
Bukkit.getPluginManager().callEvent(renameWarpEvent);
|
Bukkit.getPluginManager().callEvent(renameWarpEvent);
|
||||||
if (renameWarpEvent.isCancelled()) {
|
if (renameWarpEvent.isCancelled()) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||||
@@ -150,10 +151,10 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> rename <new warp>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> rename <new warp>");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
default:
|
default:
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.UUID;
|
|||||||
public class HomeCommand extends CommandBase {
|
public class HomeCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String homeName = args[0];
|
String homeName = args[0];
|
||||||
if (DataManager.homeExists(p, homeName)) {
|
if (DataManager.homeExists(p, homeName)) {
|
||||||
@@ -36,12 +36,11 @@ public class HomeCommand extends CommandBase {
|
|||||||
if (homes.size() == 1) {
|
if (homes.size() == 1) {
|
||||||
// Teleport the player if they only have one home
|
// Teleport the player if they only have one home
|
||||||
TeleportManager.queueTimedTeleport(p, homes.get(0));
|
TeleportManager.queueTimedTeleport(p, homes.get(0));
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListHandler.displayPlayerHomeList(p, 1);
|
ListHandler.displayPlayerHomeList(p, 1);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Tab implements TabCompleter {
|
public static class Tab implements TabCompleter {
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
|||||||
public class HomelistCommand extends CommandBase {
|
public class HomelistCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
int pageNo = 1;
|
int pageNo = 1;
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
pageNo = Integer.parseInt(args[0]);
|
pageNo = Integer.parseInt(args[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListHandler.displayPlayerHomeList(p, pageNo);
|
ListHandler.displayPlayerHomeList(p, pageNo);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -122,8 +122,8 @@ public class HuskhomesCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player player, Command command, String label, String[] args) {
|
protected void onCommand(Player player, Command command, String label, String[] args) {
|
||||||
return true;
|
// Console is fine too
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import me.william278.huskhomes2.data.DataManager;
|
|||||||
import me.william278.huskhomes2.teleport.ListHandler;
|
import me.william278.huskhomes2.teleport.ListHandler;
|
||||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||||
import me.william278.huskhomes2.teleport.points.Home;
|
import me.william278.huskhomes2.teleport.points.Home;
|
||||||
|
import me.william278.huskhomes2.utils.RegexUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
@@ -33,15 +34,16 @@ public class PublichomeCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
ListHandler.displayPublicHomeList(p, 1);
|
ListHandler.displayPublicHomeList(p, 1);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
String publicHome = args[0];
|
String publicHome = args[0];
|
||||||
if (publicHome.matches("[A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-]+")) {
|
if (RegexUtil.OWNER_NAME_PATTERN.matcher(publicHome).matches()) {
|
||||||
String ownerName = publicHome.split("\\.")[0];
|
String[] split = publicHome.split("\\.");
|
||||||
String homeName = publicHome.split("\\.")[1];
|
String ownerName = split[0];
|
||||||
|
String homeName = split[1];
|
||||||
if (DataManager.homeExists(ownerName, homeName)) {
|
if (DataManager.homeExists(ownerName, homeName)) {
|
||||||
Home home = DataManager.getHome(ownerName, homeName);
|
Home home = DataManager.getHome(ownerName, homeName);
|
||||||
if (home.isPublic()) {
|
if (home.isPublic()) {
|
||||||
@@ -55,7 +57,6 @@ public class PublichomeCommand extends CommandBase implements TabCompleter {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
|||||||
public class PublichomelistCommand extends CommandBase {
|
public class PublichomelistCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
int pageNo = 1;
|
int pageNo = 1;
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
pageNo = Integer.parseInt(args[0]);
|
pageNo = Integer.parseInt(args[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListHandler.displayPublicHomeList(p, pageNo);
|
ListHandler.displayPublicHomeList(p, pageNo);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class RtpCommand extends CommandBase {
|
public class RtpCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (HuskHomes.getSettings().doRtpCommand()) {
|
if (HuskHomes.getSettings().doRtpCommand()) {
|
||||||
if (p.getWorld().getEnvironment() == World.Environment.NORMAL) {
|
if (p.getWorld().getEnvironment() == World.Environment.NORMAL) {
|
||||||
TeleportManager.queueRandomTeleport(p);
|
TeleportManager.queueRandomTeleport(p);
|
||||||
@@ -20,6 +20,5 @@ public class RtpCommand extends CommandBase {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_command_disabled");
|
MessageManager.sendMessage(p, "error_command_disabled");
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class SethomeCommand extends CommandBase {
|
public class SethomeCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String homeName = args[0];
|
String homeName = args[0];
|
||||||
SettingHandler.setHome(p.getLocation(), p, homeName);
|
SettingHandler.setHome(p.getLocation(), p, homeName);
|
||||||
@@ -21,7 +21,6 @@ public class SethomeCommand extends CommandBase {
|
|||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class SetspawnCommand extends CommandBase {
|
public class SetspawnCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (HuskHomes.getSettings().doSpawnCommand()) {
|
if (HuskHomes.getSettings().doSpawnCommand()) {
|
||||||
SettingHandler.setSpawnLocation(p.getLocation());
|
SettingHandler.setSpawnLocation(p.getLocation());
|
||||||
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
|
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
|
||||||
@@ -17,6 +17,5 @@ public class SetspawnCommand extends CommandBase {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_command_disabled");
|
MessageManager.sendMessage(p, "error_command_disabled");
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
|||||||
public class SetwarpCommand extends CommandBase {
|
public class SetwarpCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String warpName = args[0];
|
String warpName = args[0];
|
||||||
SettingHandler.setWarp(p.getLocation(), p, warpName);
|
SettingHandler.setWarp(p.getLocation(), p, warpName);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class SpawnCommand extends CommandBase {
|
public class SpawnCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (HuskHomes.getSettings().doSpawnCommand()) {
|
if (HuskHomes.getSettings().doSpawnCommand()) {
|
||||||
if (TeleportManager.getSpawnLocation() != null) {
|
if (TeleportManager.getSpawnLocation() != null) {
|
||||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
||||||
@@ -19,6 +19,5 @@ public class SpawnCommand extends CommandBase {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_command_disabled");
|
MessageManager.sendMessage(p, "error_command_disabled");
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,15 +19,15 @@ import java.util.List;
|
|||||||
public class TpCommand extends CommandBase {
|
public class TpCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
default: case 0:
|
default: case 0:
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
case 1:
|
case 1:
|
||||||
String targetPlayer = args[0];
|
String targetPlayer = args[0];
|
||||||
TeleportManager.teleportPlayer(p, targetPlayer);
|
TeleportManager.teleportPlayer(p, targetPlayer);
|
||||||
return true;
|
return;
|
||||||
case 3:
|
case 3:
|
||||||
try {
|
try {
|
||||||
double x = Double.parseDouble(args[0]);
|
double x = Double.parseDouble(args[0]);
|
||||||
@@ -38,7 +38,7 @@ public class TpCommand extends CommandBase {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case 4:
|
case 4:
|
||||||
try {
|
try {
|
||||||
double x = Double.parseDouble(args[0]);
|
double x = Double.parseDouble(args[0]);
|
||||||
@@ -47,14 +47,14 @@ public class TpCommand extends CommandBase {
|
|||||||
String worldName = args[3];
|
String worldName = args[3];
|
||||||
if (Bukkit.getWorld(worldName) == null) {
|
if (Bukkit.getWorld(worldName) == null) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, HuskHomes.getSettings().getServerID());
|
||||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case 5:
|
case 5:
|
||||||
if (HuskHomes.getSettings().doBungee()) {
|
if (HuskHomes.getSettings().doBungee()) {
|
||||||
try {
|
try {
|
||||||
@@ -65,7 +65,7 @@ public class TpCommand extends CommandBase {
|
|||||||
String serverName = args[4];
|
String serverName = args[4];
|
||||||
if (Bukkit.getWorld(worldName) == null) {
|
if (Bukkit.getWorld(worldName) == null) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, serverName);
|
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, serverName);
|
||||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||||
@@ -75,7 +75,7 @@ public class TpCommand extends CommandBase {
|
|||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import org.bukkit.entity.Player;
|
|||||||
public class TpaCommand extends CommandBase {
|
public class TpaCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String targetPlayer = args[0];
|
String targetPlayer = args[0];
|
||||||
TeleportRequestHandler.sendTeleportToRequest(p, targetPlayer);
|
TeleportRequestHandler.sendTeleportToRequest(p, targetPlayer);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class TpacceptCommand extends CommandBase {
|
public class TpacceptCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
TeleportRequestHandler.replyTpRequest(p, true);
|
TeleportRequestHandler.replyTpRequest(p, true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,12 @@ import org.bukkit.entity.Player;
|
|||||||
public class TpahereCommand extends CommandBase {
|
public class TpahereCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String targetPlayer = args[0];
|
String targetPlayer = args[0];
|
||||||
TeleportRequestHandler.sendTeleportHereRequest(p, targetPlayer);
|
TeleportRequestHandler.sendTeleportHereRequest(p, targetPlayer);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class TpdenyCommand extends CommandBase {
|
public class TpdenyCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
TeleportRequestHandler.replyTpRequest(p, false);
|
TeleportRequestHandler.replyTpRequest(p, false);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,12 @@ import org.bukkit.entity.Player;
|
|||||||
public class TphereCommand extends CommandBase {
|
public class TphereCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String targetPlayer = args[0];
|
String targetPlayer = args[0];
|
||||||
TeleportManager.teleportHere(p, targetPlayer);
|
TeleportManager.teleportHere(p, targetPlayer);
|
||||||
} else {
|
} else {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,10 +21,10 @@ import java.util.Set;
|
|||||||
public class WarpCommand extends CommandBase {
|
public class WarpCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
if (!HuskHomes.getSettings().doWarpCommand()) {
|
if (!HuskHomes.getSettings().doWarpCommand()) {
|
||||||
MessageManager.sendMessage(p, "error_command_disabled");
|
MessageManager.sendMessage(p, "error_command_disabled");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String warpName = args[0];
|
String warpName = args[0];
|
||||||
@@ -37,7 +37,6 @@ public class WarpCommand extends CommandBase {
|
|||||||
} else {
|
} else {
|
||||||
ListHandler.displayWarpList(p, 1);
|
ListHandler.displayWarpList(p, 1);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Tab implements TabCompleter {
|
public static class Tab implements TabCompleter {
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
|||||||
public class WarplistCommand extends CommandBase {
|
public class WarplistCommand extends CommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||||
int pageNo = 1;
|
int pageNo = 1;
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
pageNo = Integer.parseInt(args[0]);
|
pageNo = Integer.parseInt(args[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListHandler.displayWarpList(p, pageNo);
|
ListHandler.displayWarpList(p, pageNo);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,11 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO Should not be an utility class for SQL class
|
||||||
|
Instead of doing everything here, all methods should be moved into corresponding classes
|
||||||
|
|
||||||
|
*/
|
||||||
// This class handles the saving of data; whether that be through SQLite or mySQL
|
// This class handles the saving of data; whether that be through SQLite or mySQL
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ import java.sql.Statement;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO Should not relay on SQL
|
||||||
|
Instead should contain abstract getters and setters etc, so some alternative way of storing data may exist
|
||||||
|
Current method should possibly go into the SQL class
|
||||||
|
*/
|
||||||
public abstract class Database {
|
public abstract class Database {
|
||||||
protected HuskHomes plugin;
|
protected HuskHomes plugin;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|||||||
@@ -10,9 +10,14 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO Split into SQLite, MySQL and abstract SQL classes
|
||||||
|
Even tho both are using pretty much the same syntax and stuff, their initializations are too different and should
|
||||||
|
not co-exist in the same class.
|
||||||
|
*/
|
||||||
public class SQL extends Database {
|
public class SQL extends Database {
|
||||||
|
|
||||||
private final String SQLiteDatabaseName = "HuskHomesData";
|
private static final String SQLITE_DATABASE_NAME = "HuskHomesData";
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@@ -47,19 +52,19 @@ public class SQL extends Database {
|
|||||||
|
|
||||||
// Initialise connection via SQLite
|
// Initialise connection via SQLite
|
||||||
private void getSQLiteConnection() {
|
private void getSQLiteConnection() {
|
||||||
File dataFolder = new File(plugin.getDataFolder(), SQLiteDatabaseName + ".db");
|
File dataFolder = new File(plugin.getDataFolder(), SQLITE_DATABASE_NAME + ".db");
|
||||||
if (!dataFolder.exists()) {
|
if (!dataFolder.exists()) {
|
||||||
try {
|
try {
|
||||||
if (!dataFolder.createNewFile()) {
|
if (!dataFolder.createNewFile()) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to write new file: " + SQLiteDatabaseName + ".db (file already exists)");
|
plugin.getLogger().log(Level.SEVERE, "Failed to write new file: " + SQLITE_DATABASE_NAME + ".db (file already exists)");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An error occurred writing a file: " + SQLiteDatabaseName + ".db (" + e.getCause() + ")");
|
plugin.getLogger().log(Level.SEVERE, "An error occurred writing a file: " + SQLITE_DATABASE_NAME + ".db (" + e.getCause() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
setConnection(DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/" + SQLiteDatabaseName + ".db"));
|
setConnection(DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/" + SQLITE_DATABASE_NAME + ".db"));
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An exception occurred initialising the SQLite database", ex);
|
plugin.getLogger().log(Level.SEVERE, "An exception occurred initialising the SQLite database", ex);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class EssentialsMigrator {
|
|||||||
|
|
||||||
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
||||||
for (File playerFile : playerFiles) {
|
for (File playerFile : playerFiles) {
|
||||||
String uuidS = playerFile.getName().replaceFirst("[.][^.]+$", "");
|
String uuidS = playerFile.getName().split("\\.")[0];
|
||||||
UUID uuid = UUID.fromString(uuidS);
|
UUID uuid = UUID.fromString(uuidS);
|
||||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||||
String playerName = playerFileConfig.getString("lastAccountName");
|
String playerName = playerFileConfig.getString("lastAccountName");
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ 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;
|
||||||
import me.william278.huskhomes2.teleport.points.Warp;
|
import me.william278.huskhomes2.teleport.points.Warp;
|
||||||
|
import me.william278.huskhomes2.utils.RegexUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@@ -179,7 +180,7 @@ public class SettingHandler {
|
|||||||
conditionsNotMetReason = "error_set_warp_invalid_length";
|
conditionsNotMetReason = "error_set_warp_invalid_length";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!warpName.matches("[A-Za-z0-9_\\-]+")) {
|
if (!RegexUtil.NAME_PATTERN.matcher(warpName).matches()) {
|
||||||
conditionsNotMetReason = "error_set_warp_invalid_characters";
|
conditionsNotMetReason = "error_set_warp_invalid_characters";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -215,7 +216,7 @@ public class SettingHandler {
|
|||||||
conditionsNotMetReason = "error_set_home_invalid_length";
|
conditionsNotMetReason = "error_set_home_invalid_length";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!homeName.matches("[A-Za-z0-9_\\-]+")) {
|
if (!RegexUtil.NAME_PATTERN.matcher(homeName).matches()) {
|
||||||
conditionsNotMetReason = "error_set_home_invalid_characters";
|
conditionsNotMetReason = "error_set_home_invalid_characters";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package me.william278.huskhomes2.utils;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public final class RegexUtil {
|
||||||
|
|
||||||
|
public static final Pattern DESCRIPTION_PATTERN = Pattern.compile("[a-zA-Z0-9\\d\\-_\\s]+");
|
||||||
|
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() {
|
||||||
|
// No object for you
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user