Skip to content

Commit

Permalink
Merge pull request #17 from Aquerr/mateov
Browse files Browse the repository at this point in the history
Fix for removing - hint with container name to be removed
  • Loading branch information
mateo9x authored Apr 17, 2024
2 parents 8a10feb + f9cac16 commit 41747b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void initCommands(final RegisterCommandEvent<Command.Parameterized> even
registerCommand(singletonList("help"), "command.help.desc", PluginPermissions.HELP_COMMAND, new HelpCommand(this), Parameter.integerNumber().key("page").optional().build());
registerCommand(asList("c", "create"), "command.create.desc", PluginPermissions.CREATE_COMMAND, new CreateCommand(this), Parameter.string().key("name").optional().build());
registerCommand(singletonList("copy"), "command.copy.desc", PluginPermissions.COPY_COMMAND, new CopyCommand(this));
registerCommand(asList("r", "remove"), "command.remove.desc", PluginPermissions.REMOVE_COMMAND, new RemoveCommand(this), Parameter.string().key("name").optional().build());
registerCommand(asList("r", "remove"), "command.remove.desc", PluginPermissions.REMOVE_COMMAND, new RemoveCommand(this), ChestRefillCommandParameters.refillableContainer());
registerCommand(singletonList("remove_all"), "command.removeall.desc", PluginPermissions.REMOVEALL_COMMAND, new RemoveAllCommand(this));
registerCommand(asList("u", "update"), "command.removeall.desc", PluginPermissions.UPDATE_COMMAND, new UpdateCommand(this));
registerCommand(singletonList("info"), "command.info.desc", PluginPermissions.INFO_COMMAND, new InfoCommand(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.aquerr.chestrefill.commands;

import io.github.aquerr.chestrefill.ChestRefill;
import io.github.aquerr.chestrefill.entities.ContainerLocation;
import io.github.aquerr.chestrefill.commands.arguments.ChestRefillCommandParameters;
import io.github.aquerr.chestrefill.entities.ModeExecutionParams;
import io.github.aquerr.chestrefill.entities.RefillableContainer;
import io.github.aquerr.chestrefill.entities.SelectionMode;
Expand All @@ -10,7 +10,6 @@
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.exception.CommandException;
import org.spongepowered.api.command.parameter.CommandContext;
import org.spongepowered.api.command.parameter.Parameter;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;

import java.util.Collections;
Expand All @@ -29,11 +28,11 @@ public RemoveCommand(ChestRefill plugin)
@Override
public CommandResult execute(CommandContext context) throws CommandException
{
final Optional<String> optionalChestNameToRemove = context.one(Parameter.string().key("name").build());
final Optional<RefillableContainer> containerToRemoveFound = context.one(ChestRefillCommandParameters.refillableContainer());
ServerPlayer serverPlayer = requirePlayerSource(context);
if (optionalChestNameToRemove.isPresent())
if (containerToRemoveFound.isPresent())
{
removeContainerByName(serverPlayer, optionalChestNameToRemove.get());
removeContainer(serverPlayer, containerToRemoveFound.get());
}
else
{
Expand All @@ -57,21 +56,10 @@ private void toggleRemoveMode(ServerPlayer serverPlayer)
}
}

private void removeContainerByName(ServerPlayer player, String chestName)
private void removeContainer(ServerPlayer player, RefillableContainer container)
{
Optional<ContainerLocation> foundContainerLocationToRemove = super.getPlugin().getContainerManager().getRefillableContainers().stream()
.filter(container -> chestName.equals(container.getName()))
.map(RefillableContainer::getContainerLocation)
.findFirst();
if (foundContainerLocationToRemove.isPresent())
{
boolean didSuccess = super.getPlugin().getContainerManager().removeRefillableContainer(foundContainerLocationToRemove.get());
handleDidSuccess(player, didSuccess);
}
else
{
player.sendMessage(messageSource.resolveMessageWithPrefix("command.remove-by-name.not-found"));
}
boolean didSuccess = super.getPlugin().getContainerManager().removeRefillableContainer(container.getContainerLocation());
handleDidSuccess(player, didSuccess);
}

private SelectionParams prepareParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ command.removeall.success=&eAll containers have been removed!
command.remove.turned-on=&eTurned on removal mode
command.remove.turned-off=&eTurned off removal mode
command.remove.successful-remove=&aSuccessfully removed a refilling container!
command.remove-by-name.not-found=&aContainer to be removed by name has not been found!

command.removekit.success=&aSuccessfully removed the kit!
command.removekit.error.kit-does-not-exist=Kit with given name does not exist!
Expand Down

0 comments on commit 41747b8

Please sign in to comment.