-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to island homes from player homes. (#1689)
* Switch to island homes from player homes. Stores home locations and max homes in the Island object. Adds commands required to manage home names, specifically rename and delete. I did not add list as there is tab complete on island go, but it may be required.
- Loading branch information
1 parent
a8473c2
commit b6a69d0
Showing
19 changed files
with
885 additions
and
697 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/world/bentobox/bentobox/api/commands/admin/conversations/NamePrompt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package world.bentobox.bentobox.api.commands.admin.conversations; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.conversations.ConversationContext; | ||
import org.bukkit.conversations.Prompt; | ||
import org.bukkit.conversations.StringPrompt; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
|
||
/** | ||
* Renames a home | ||
* @author tastybento | ||
* | ||
*/ | ||
public class NamePrompt extends StringPrompt { | ||
|
||
private @NonNull final Island island; | ||
private @NonNull final User user; | ||
private final String oldName; | ||
private final BentoBox plugin; | ||
|
||
public NamePrompt(BentoBox plugin, @NonNull Island island, User user, String oldName) { | ||
this.plugin = plugin; | ||
this.island = island; | ||
this.user = user; | ||
this.oldName = oldName; | ||
} | ||
|
||
@Override | ||
public String getPromptText(ConversationContext context) { | ||
return user.getTranslation("commands.island.renamehome.enter-new-name"); | ||
} | ||
|
||
@Override | ||
public Prompt acceptInput(ConversationContext context, String input) { | ||
if (island.renameHome(oldName, input)) { | ||
plugin.getIslands().save(island); | ||
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("general.success")); | ||
} else { | ||
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("commands.island.renamehome.already-exists")); | ||
} | ||
return Prompt.END_OF_CONVERSATION; | ||
} | ||
|
||
} |
47 changes: 0 additions & 47 deletions
47
src/main/java/world/bentobox/bentobox/api/commands/island/CustomIslandMultiHomeHelp.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/world/bentobox/bentobox/api/commands/island/IslandDeletehomeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package world.bentobox.bentobox.api.commands.island; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.commands.ConfirmableCommand; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
/** | ||
* Deletes a home | ||
* @author tastybento | ||
* | ||
*/ | ||
public class IslandDeletehomeCommand extends ConfirmableCommand { | ||
|
||
private @Nullable Island island; | ||
|
||
public IslandDeletehomeCommand(CompositeCommand islandCommand) { | ||
super(islandCommand, "deletehome"); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
setPermission("island.deletehome"); | ||
setOnlyPlayer(true); | ||
setParametersHelp("commands.island.deletehome.parameters"); | ||
setDescription("commands.island.deletehome.description"); | ||
} | ||
|
||
@Override | ||
public boolean canExecute(User user, String label, List<String> args) { | ||
if (args.isEmpty()) { | ||
this.showHelp(this, user); | ||
return false; | ||
} | ||
island = getIslands().getIsland(getWorld(), user); | ||
// Check island | ||
if (island == null) { | ||
user.sendMessage("general.errors.no-island"); | ||
return false; | ||
} | ||
// Check if the name is known | ||
if (!getIslands().isHomeLocation(island, String.join(" ", args))) { | ||
user.sendMessage("commands.island.go.unknown-home"); | ||
user.sendMessage("commands.island.sethome.homes-are"); | ||
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("home-list-syntax", TextVariables.NAME, s)); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
this.askConfirmation(user, () -> delete(island, user, String.join(" ", args))); | ||
return true; | ||
} | ||
|
||
|
||
private void delete(Island island, User user, String name) { | ||
island.removeHome(name); | ||
user.sendMessage("general.success"); | ||
} | ||
|
||
@Override | ||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) { | ||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; | ||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId()); | ||
if (island != null) { | ||
return Optional.of(Util.tabLimit(new ArrayList<>(island.getHomes().keySet()), lastArg)); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/world/bentobox/bentobox/api/commands/island/IslandRenamehomeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package world.bentobox.bentobox.api.commands.island; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.bukkit.conversations.ConversationFactory; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.commands.ConfirmableCommand; | ||
import world.bentobox.bentobox.api.commands.admin.conversations.NamePrompt; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
/** | ||
* Renames a home | ||
* @author tastybento | ||
* | ||
*/ | ||
public class IslandRenamehomeCommand extends ConfirmableCommand { | ||
|
||
private @Nullable Island island; | ||
|
||
public IslandRenamehomeCommand(CompositeCommand islandCommand) { | ||
super(islandCommand, "renamehome"); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
setPermission("island.renamehome"); | ||
setOnlyPlayer(true); | ||
setParametersHelp("commands.island.renamehome.parameters"); | ||
setDescription("commands.island.renamehome.description"); | ||
} | ||
|
||
@Override | ||
public boolean canExecute(User user, String label, List<String> args) { | ||
if (args.isEmpty()) { | ||
this.showHelp(this, user); | ||
return false; | ||
} | ||
island = getIslands().getIsland(getWorld(), user); | ||
// Check island | ||
if (island == null) { | ||
user.sendMessage("general.errors.no-island"); | ||
return false; | ||
} | ||
// Check if the name is known | ||
if (!getIslands().isHomeLocation(island, String.join(" ", args))) { | ||
user.sendMessage("commands.island.go.unknown-home"); | ||
user.sendMessage("commands.island.sethome.homes-are"); | ||
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s)); | ||
this.showHelp(this, user); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
new ConversationFactory(BentoBox.getInstance()) | ||
.withModality(true) | ||
.withLocalEcho(false) | ||
.withTimeout(90) | ||
.withFirstPrompt(new NamePrompt(getPlugin(), island, user, String.join(" ", args))) | ||
.buildConversation(user.getPlayer()).begin(); | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) { | ||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; | ||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId()); | ||
if (island != null) { | ||
return Optional.of(Util.tabLimit(new ArrayList<>(island.getHomes().keySet()), lastArg)); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
Oops, something went wrong.