mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Let's use some more of CommandBase
This commit is contained in:
29 files changed
+541
-643
No files matched your search
@@ -28,192 +28,188 @@ import java.util.List;
|
||||
public class EdithomeCommand extends CommandBase implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (args.length >= 1) {
|
||||
String homeName = args[0];
|
||||
if (DataManager.homeExists(p.getName(), homeName)) {
|
||||
if (args.length >= 2) {
|
||||
switch (args[1]) {
|
||||
case "location":
|
||||
Location newLocation = p.getLocation();
|
||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.settings.getServerID());
|
||||
protected boolean onCommand(Player p, Command command, String label, String[] args) {
|
||||
if (args.length >= 1) {
|
||||
String homeName = args[0];
|
||||
if (DataManager.homeExists(p.getName(), homeName)) {
|
||||
if (args.length >= 2) {
|
||||
switch (args[1]) {
|
||||
case "location":
|
||||
Location newLocation = p.getLocation();
|
||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.settings.getServerID());
|
||||
|
||||
// Remove old marker if on dynmap
|
||||
Home locationMovedHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (locationMovedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
// Remove old marker if on dynmap
|
||||
Home locationMovedHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (locationMovedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
|
||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||
if (relocateHomeEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.updateHomeLocation(p.getName(), homeName, newLocation);
|
||||
MessageManager.sendMessage(p, "edit_home_update_location", homeName);
|
||||
|
||||
// Add new updated marker if using dynmap
|
||||
locationMovedHome.setLocation(newLocation, HuskHomes.settings.getServerID());
|
||||
if (locationMovedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
||||
}
|
||||
return true;
|
||||
case "description":
|
||||
if (args.length >= 3) {
|
||||
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName);
|
||||
|
||||
// Get the new description
|
||||
StringBuilder newDescription = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) {
|
||||
newDescription.append(" ").append(args[i]);
|
||||
} else {
|
||||
newDescription = new StringBuilder(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerRelocateHomeEvent relocateHomeEvent = new PlayerRelocateHomeEvent(p, locationMovedHome, newTeleportLocation);
|
||||
Bukkit.getPluginManager().callEvent(relocateHomeEvent);
|
||||
if (relocateHomeEvent.isCancelled()) {
|
||||
String newDescriptionString = newDescription.toString();
|
||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
// Check the description is valid
|
||||
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
|
||||
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
||||
return true;
|
||||
}
|
||||
|
||||
DataManager.updateHomeLocation(p.getName(), homeName, newLocation);
|
||||
MessageManager.sendMessage(p, "edit_home_update_location", homeName);
|
||||
|
||||
// Add new updated marker if using dynmap
|
||||
locationMovedHome.setLocation(newLocation, HuskHomes.settings.getServerID());
|
||||
if (locationMovedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(locationMovedHome);
|
||||
// Remove old marker if on the Dynmap
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
return true;
|
||||
case "description":
|
||||
if (args.length >= 3) {
|
||||
Home descriptionChangedHome = DataManager.getHome(p.getName(), homeName);
|
||||
|
||||
// Get the new description
|
||||
StringBuilder newDescription = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) {
|
||||
newDescription.append(" ").append(args[i]);
|
||||
} else {
|
||||
newDescription = new StringBuilder(args[i]);
|
||||
}
|
||||
}
|
||||
String newDescriptionString = newDescription.toString();
|
||||
PlayerChangeHomeDescriptionEvent changeHomeDescriptionEvent = new PlayerChangeHomeDescriptionEvent(p, descriptionChangedHome, newDescriptionString);
|
||||
Bukkit.getPluginManager().callEvent(changeHomeDescriptionEvent);
|
||||
if (changeHomeDescriptionEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
// Check the description is valid
|
||||
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
|
||||
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
|
||||
return true;
|
||||
}
|
||||
// Update description
|
||||
DataManager.updateHomeDescription(p.getName(), homeName, newDescriptionString);
|
||||
|
||||
// Remove old marker if on the Dynmap
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
// Add new marker if using Dynmap
|
||||
descriptionChangedHome.setDescription(newDescriptionString);
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(descriptionChangedHome);
|
||||
}
|
||||
|
||||
// Confirmation message
|
||||
MessageManager.sendMessage(p, "edit_home_update_description", homeName, newDescriptionString);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||
}
|
||||
return true;
|
||||
case "rename":
|
||||
if (args.length >= 3) {
|
||||
String newName = args[2];
|
||||
if (newName.length() > 16) {
|
||||
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
||||
return true;
|
||||
}
|
||||
if (!newName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
||||
return true;
|
||||
}
|
||||
if (DataManager.homeExists(p.getName(), newName)) {
|
||||
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
||||
return true;
|
||||
}
|
||||
Home renamedHome = DataManager.getHome(p.getName(), homeName);
|
||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||
if (renameHomeEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
if (renamedHome.isPublic()) {
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
|
||||
// Update description
|
||||
DataManager.updateHomeDescription(p.getName(), homeName, newDescriptionString);
|
||||
|
||||
// Add new marker if using Dynmap
|
||||
descriptionChangedHome.setDescription(newDescriptionString);
|
||||
if (descriptionChangedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(descriptionChangedHome);
|
||||
}
|
||||
|
||||
// Confirmation message
|
||||
MessageManager.sendMessage(p, "edit_home_update_description", homeName, newDescriptionString);
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName);
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName);
|
||||
}
|
||||
return true;
|
||||
case "rename":
|
||||
if (args.length >= 3) {
|
||||
String newName = args[2];
|
||||
if (newName.length() > 16) {
|
||||
MessageManager.sendMessage(p, "error_set_home_invalid_length");
|
||||
return true;
|
||||
}
|
||||
if (!newName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
MessageManager.sendMessage(p, "error_set_home_invalid_characters");
|
||||
return true;
|
||||
}
|
||||
if (DataManager.homeExists(p.getName(), newName)) {
|
||||
MessageManager.sendMessage(p, "error_set_home_name_taken");
|
||||
return true;
|
||||
}
|
||||
Home renamedHome = DataManager.getHome(p.getName(), homeName);
|
||||
PlayerRenameHomeEvent renameHomeEvent = new PlayerRenameHomeEvent(p, renamedHome, newName);
|
||||
Bukkit.getPluginManager().callEvent(renameHomeEvent);
|
||||
if (renameHomeEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
if (renamedHome.isPublic()) {
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(homeName, p.getName());
|
||||
}
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName);
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
DataManager.updateHomeName(p.getName(), homeName, newName);
|
||||
}
|
||||
renamedHome.setName(newName);
|
||||
if (renamedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(renamedHome);
|
||||
}
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
MessageManager.sendMessage(p, "edit_home_update_name", homeName, newName);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
||||
renamedHome.setName(newName);
|
||||
if (renamedHome.isPublic() && HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(renamedHome);
|
||||
}
|
||||
return true;
|
||||
case "public":
|
||||
Home privateHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (!privateHome.isPublic()) {
|
||||
if (HuskHomes.settings.doEconomy()) {
|
||||
double publicHomeCost = HuskHomes.settings.getPublicHomeCost();
|
||||
if (publicHomeCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
||||
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
||||
return true;
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
||||
}
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
MessageManager.sendMessage(p, "edit_home_update_name", homeName, newName);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> rename <new name>");
|
||||
}
|
||||
return true;
|
||||
case "public":
|
||||
Home privateHome = DataManager.getHome(p.getName(), homeName);
|
||||
if (!privateHome.isPublic()) {
|
||||
if (HuskHomes.settings.doEconomy()) {
|
||||
double publicHomeCost = HuskHomes.settings.getPublicHomeCost();
|
||||
if (publicHomeCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(p, publicHomeCost)) {
|
||||
MessageManager.sendMessage(p, "error_insufficient_funds", VaultIntegration.format(publicHomeCost));
|
||||
return true;
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, VaultIntegration.format(publicHomeCost));
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||
}
|
||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||
if (makeHomePublicEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, true);
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(privateHome);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
|
||||
}
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, false);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(publicHome.getName(), publicHome.getOwnerUsername());
|
||||
}
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
||||
PlayerMakeHomePublicEvent makeHomePublicEvent = new PlayerMakeHomePublicEvent(p, privateHome);
|
||||
Bukkit.getPluginManager().callEvent(makeHomePublicEvent);
|
||||
if (makeHomePublicEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Home home = DataManager.getHome(p.getName(), homeName);
|
||||
EditingHandler.showEditHomeOptions(p, home);
|
||||
return true;
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, true);
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.addDynamicMapMarker(privateHome);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_public", homeName);
|
||||
}
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
DataManager.updateHomePrivacy(p.getName(), homeName, false);
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private_success", homeName);
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
DynMapIntegration.removeDynamicMapMarker(publicHome.getName(), publicHome.getOwnerUsername());
|
||||
}
|
||||
PublichomeCommand.updatePublicHomeTabCache();
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_edit_home_privacy_already_private", homeName);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_home_invalid", homeName);
|
||||
Home home = DataManager.getHome(p.getName(), homeName);
|
||||
EditingHandler.showEditHomeOptions(p, home);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
MessageManager.sendMessage(p, "error_home_invalid", homeName);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user