mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +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 {
|
||||
|
||||
@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);
|
||||
if (lastPosition != null) {
|
||||
TeleportManager.queueTimedTeleport(p, lastPosition);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_no_last_position");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,13 @@ public abstract class CommandBase implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
return onCommand((Player) sender, command, label, args);
|
||||
onCommand((Player) sender, command, label, args);
|
||||
return true;
|
||||
}
|
||||
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
|
||||
|
||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
||||
public class DelhomeCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String homeName = args[0];
|
||||
SettingHandler.deleteHome(p, homeName);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
||||
public class DelwarpCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String warpName = args[0];
|
||||
SettingHandler.deleteWarp(p, warpName);
|
||||
} else {
|
||||
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.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import me.william278.huskhomes2.utils.RegexUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -29,22 +30,22 @@ import java.util.Locale;
|
||||
public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
@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) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
String homeName = args[0];
|
||||
if (!DataManager.homeExists(p.getName(), homeName)) {
|
||||
MessageManager.sendMessage(p, "error_home_invalid", homeName);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
Home home = DataManager.getHome(p.getName(), homeName);
|
||||
EditingHandler.showEditHomeOptions(p, home);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase(Locale.ENGLISH)) {
|
||||
@@ -61,7 +62,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||
if (relocateHomeEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
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()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "description":
|
||||
if (args.length >= 3) {
|
||||
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);
|
||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
// 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");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove old marker if on the Dynmap
|
||||
@@ -117,27 +118,27 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "rename":
|
||||
if (args.length >= 3) {
|
||||
String newName = args[2];
|
||||
if (newName.length() > 16) {
|
||||
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");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (DataManager.homeExists(p.getName(), newName)) {
|
||||
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Home renamedHome = DataManager.getHome(p.getName(), homeName);
|
||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||
if (renameHomeEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (renamedHome.isPublic()) {
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showPublicHomesOnDynmap()) {
|
||||
@@ -157,7 +158,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "public":
|
||||
Home privateHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (!privateHome.isPublic()) {
|
||||
@@ -166,7 +167,7 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
if (publicHomeCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
||||
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
||||
return true;
|
||||
return;
|
||||
} else {
|
||||
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);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||
if (makeHomePublicEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, true);
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
@@ -189,14 +190,14 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "private":
|
||||
Home publicHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (publicHome.isPublic()) {
|
||||
PlayerMakeHomePrivateEvent makeHomePrivateEvent = new PlayerMakeHomePrivateEvent(p, publicHome);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePrivateEvent);
|
||||
if (makeHomePrivateEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, false);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||
@@ -207,10 +208,10 @@ public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
default:
|
||||
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.teleport.points.TeleportationPoint;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import me.william278.huskhomes2.utils.RegexUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -25,22 +26,22 @@ import java.util.List;
|
||||
public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
@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) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
String warpName = args[0];
|
||||
if (!DataManager.warpExists(warpName)) {
|
||||
MessageManager.sendMessage(p, "error_warp_invalid", warpName);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
Warp warp = DataManager.getWarp(warpName);
|
||||
EditingHandler.showEditWarpOptions(p, warp);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[1]) {
|
||||
@@ -57,7 +58,7 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
PlayerRelocateWarpEvent relocateWarpEvent = new PlayerRelocateWarpEvent(p, locationMovedWarp, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateWarpEvent);
|
||||
if (relocateWarpEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
DataManager.updateWarpLocation(warpName, p.getLocation());
|
||||
@@ -68,7 +69,7 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedWarp);
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "description":
|
||||
if (args.length >= 3) {
|
||||
Warp descriptionChangedWarp = DataManager.getWarp(warpName);
|
||||
@@ -87,13 +88,13 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
PlayerChangeWarpDescriptionEvent changeWarpDescriptionEvent = new PlayerChangeWarpDescriptionEvent(p, descriptionChangedWarp, newDescriptionString);
|
||||
Bukkit.getPluginManager().callEvent(changeWarpDescriptionEvent);
|
||||
if (changeWarpDescriptionEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
@@ -113,27 +114,27 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case "rename":
|
||||
if (args.length >= 3) {
|
||||
Warp renamedWarp = DataManager.getWarp(warpName);
|
||||
String newName = args[2];
|
||||
if (newName.length() > 16) {
|
||||
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");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (DataManager.warpExists(newName)) {
|
||||
MessageManager.sendMessage(p, "error_set_warp_name_taken");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
PlayerRenameWarpEvent renameWarpEvent = new PlayerRenameWarpEvent(p, renamedWarp, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameWarpEvent);
|
||||
if (renameWarpEvent.isCancelled()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
|
||||
@@ -150,10 +151,10 @@ public class EditwarpCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> rename <new warp>");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
default:
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.UUID;
|
||||
public class HomeCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String homeName = args[0];
|
||||
if (DataManager.homeExists(p, homeName)) {
|
||||
@@ -36,12 +36,11 @@ public class HomeCommand extends CommandBase {
|
||||
if (homes.size() == 1) {
|
||||
// Teleport the player if they only have one home
|
||||
TeleportManager.queueTimedTeleport(p, homes.get(0));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ListHandler.displayPlayerHomeList(p, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Tab implements TabCompleter {
|
||||
|
||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
||||
public class HomelistCommand extends CommandBase {
|
||||
|
||||
@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;
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
pageNo = Integer.parseInt(args[0]);
|
||||
} catch (Exception e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ListHandler.displayPlayerHomeList(p, pageNo);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -122,8 +122,8 @@ public class HuskhomesCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onCommand(Player player, Command command, String label, String[] args) {
|
||||
return true;
|
||||
protected void onCommand(Player player, Command command, String label, String[] args) {
|
||||
// Console is fine too
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.ListHandler;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.utils.RegexUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@@ -33,15 +34,16 @@ public class PublichomeCommand extends CommandBase implements TabCompleter {
|
||||
}
|
||||
|
||||
@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) {
|
||||
ListHandler.displayPublicHomeList(p, 1);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
String publicHome = args[0];
|
||||
if (publicHome.matches("[A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-]+")) {
|
||||
String ownerName = publicHome.split("\\.")[0];
|
||||
String homeName = publicHome.split("\\.")[1];
|
||||
if (RegexUtil.OWNER_NAME_PATTERN.matcher(publicHome).matches()) {
|
||||
String[] split = publicHome.split("\\.");
|
||||
String ownerName = split[0];
|
||||
String homeName = split[1];
|
||||
if (DataManager.homeExists(ownerName, homeName)) {
|
||||
Home home = DataManager.getHome(ownerName, homeName);
|
||||
if (home.isPublic()) {
|
||||
@@ -55,7 +57,6 @@ public class PublichomeCommand extends CommandBase implements TabCompleter {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
||||
public class PublichomelistCommand extends CommandBase {
|
||||
|
||||
@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;
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
pageNo = Integer.parseInt(args[0]);
|
||||
} catch (Exception e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ListHandler.displayPublicHomeList(p, pageNo);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
||||
public class RtpCommand extends CommandBase {
|
||||
|
||||
@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 (p.getWorld().getEnvironment() == World.Environment.NORMAL) {
|
||||
TeleportManager.queueRandomTeleport(p);
|
||||
@@ -20,6 +20,5 @@ public class RtpCommand extends CommandBase {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_command_disabled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
||||
public class SethomeCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String homeName = args[0];
|
||||
SettingHandler.setHome(p.getLocation(), p, homeName);
|
||||
@@ -21,7 +21,6 @@ public class SethomeCommand extends CommandBase {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
||||
public class SetspawnCommand extends CommandBase {
|
||||
|
||||
@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()) {
|
||||
SettingHandler.setSpawnLocation(p.getLocation());
|
||||
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
|
||||
@@ -17,6 +17,5 @@ public class SetspawnCommand extends CommandBase {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_command_disabled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,13 @@ import org.bukkit.entity.Player;
|
||||
public class SetwarpCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String warpName = args[0];
|
||||
SettingHandler.setWarp(p.getLocation(), p, warpName);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
||||
public class SpawnCommand extends CommandBase {
|
||||
|
||||
@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 (TeleportManager.getSpawnLocation() != null) {
|
||||
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
|
||||
@@ -19,6 +19,5 @@ public class SpawnCommand extends CommandBase {
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_command_disabled");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,15 @@ import java.util.List;
|
||||
public class TpCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
default: case 0:
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
case 1:
|
||||
String targetPlayer = args[0];
|
||||
TeleportManager.teleportPlayer(p, targetPlayer);
|
||||
return true;
|
||||
return;
|
||||
case 3:
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
@@ -38,7 +38,7 @@ public class TpCommand extends CommandBase {
|
||||
} catch (Exception e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case 4:
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
@@ -47,14 +47,14 @@ public class TpCommand extends CommandBase {
|
||||
String worldName = args[3];
|
||||
if (Bukkit.getWorld(worldName) == null) {
|
||||
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());
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||
} catch (Exception e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
case 5:
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
try {
|
||||
@@ -65,7 +65,7 @@ public class TpCommand extends CommandBase {
|
||||
String serverName = args[4];
|
||||
if (Bukkit.getWorld(worldName) == null) {
|
||||
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);
|
||||
TeleportManager.teleportPlayer(p, teleportationPoint);
|
||||
@@ -75,7 +75,7 @@ public class TpCommand extends CommandBase {
|
||||
} else {
|
||||
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 {
|
||||
|
||||
@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) {
|
||||
String targetPlayer = args[0];
|
||||
TeleportRequestHandler.sendTeleportToRequest(p, targetPlayer);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import org.bukkit.entity.Player;
|
||||
public class TpacceptCommand extends CommandBase {
|
||||
|
||||
@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);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,12 @@ import org.bukkit.entity.Player;
|
||||
public class TpahereCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String targetPlayer = args[0];
|
||||
TeleportRequestHandler.sendTeleportHereRequest(p, targetPlayer);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import org.bukkit.entity.Player;
|
||||
public class TpdenyCommand extends CommandBase {
|
||||
|
||||
@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);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,12 @@ import org.bukkit.entity.Player;
|
||||
public class TphereCommand extends CommandBase {
|
||||
|
||||
@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) {
|
||||
String targetPlayer = args[0];
|
||||
TeleportManager.teleportHere(p, targetPlayer);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,10 @@ import java.util.Set;
|
||||
public class WarpCommand extends CommandBase {
|
||||
|
||||
@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()) {
|
||||
MessageManager.sendMessage(p, "error_command_disabled");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
String warpName = args[0];
|
||||
@@ -37,7 +37,6 @@ public class WarpCommand extends CommandBase {
|
||||
} else {
|
||||
ListHandler.displayWarpList(p, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Tab implements TabCompleter {
|
||||
|
||||
@@ -8,18 +8,17 @@ import org.bukkit.entity.Player;
|
||||
public class WarplistCommand extends CommandBase {
|
||||
|
||||
@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;
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
pageNo = Integer.parseInt(args[0]);
|
||||
} catch (Exception e) {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ListHandler.displayWarpList(p, pageNo);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
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
|
||||
public class DataManager {
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
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 {
|
||||
protected HuskHomes plugin;
|
||||
private Connection connection;
|
||||
|
||||
@@ -10,9 +10,14 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
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 {
|
||||
|
||||
private final String SQLiteDatabaseName = "HuskHomesData";
|
||||
private static final String SQLITE_DATABASE_NAME = "HuskHomesData";
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@@ -47,19 +52,19 @@ public class SQL extends Database {
|
||||
|
||||
// Initialise connection via SQLite
|
||||
private void getSQLiteConnection() {
|
||||
File dataFolder = new File(plugin.getDataFolder(), SQLiteDatabaseName + ".db");
|
||||
File dataFolder = new File(plugin.getDataFolder(), SQLITE_DATABASE_NAME + ".db");
|
||||
if (!dataFolder.exists()) {
|
||||
try {
|
||||
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) {
|
||||
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 {
|
||||
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) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An exception occurred initialising the SQLite database", ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class EssentialsMigrator {
|
||||
|
||||
File[] playerFiles = essentialsPlayerDataFolder.listFiles();
|
||||
for (File playerFile : playerFiles) {
|
||||
String uuidS = playerFile.getName().replaceFirst("[.][^.]+$", "");
|
||||
String uuidS = playerFile.getName().split("\\.")[0];
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
FileConfiguration playerFileConfig = loadConfiguration(playerFile);
|
||||
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.TeleportationPoint;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import me.william278.huskhomes2.utils.RegexUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -179,7 +180,7 @@ public class SettingHandler {
|
||||
conditionsNotMetReason = "error_set_warp_invalid_length";
|
||||
return;
|
||||
}
|
||||
if (!warpName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
if (!RegexUtil.NAME_PATTERN.matcher(warpName).matches()) {
|
||||
conditionsNotMetReason = "error_set_warp_invalid_characters";
|
||||
return;
|
||||
}
|
||||
@@ -215,7 +216,7 @@ public class SettingHandler {
|
||||
conditionsNotMetReason = "error_set_home_invalid_length";
|
||||
return;
|
||||
}
|
||||
if (!homeName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
if (!RegexUtil.NAME_PATTERN.matcher(homeName).matches()) {
|
||||
conditionsNotMetReason = "error_set_home_invalid_characters";
|
||||
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