Skip to content

Commit

Permalink
Added the ability to open chests using a param with /is chest (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 5, 2022
1 parent c781a1e commit 6c4c97c
Showing 1 changed file with 35 additions and 4 deletions.
@@ -1,15 +1,21 @@
package com.bgsoftware.superiorskyblock.commands.player;

import com.bgsoftware.superiorskyblock.lang.Message;
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.island.IslandChest;
import com.bgsoftware.superiorskyblock.api.island.IslandPrivilege;
import com.bgsoftware.superiorskyblock.api.objects.Pair;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.commands.CommandArguments;
import com.bgsoftware.superiorskyblock.commands.CommandTabCompletes;
import com.bgsoftware.superiorskyblock.commands.IPermissibleCommand;
import com.bgsoftware.superiorskyblock.island.permissions.IslandPrivileges;
import com.bgsoftware.superiorskyblock.lang.Message;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

public final class CmdChest implements IPermissibleCommand {

Expand All @@ -25,7 +31,7 @@ public String getPermission() {

@Override
public String getUsage(java.util.Locale locale) {
return "chest";
return "chest [" + Message.COMMAND_ARGUMENT_PAGE.getMessage(locale) + "]";
}

@Override
Expand All @@ -40,7 +46,7 @@ public int getMinArgs() {

@Override
public int getMaxArgs() {
return 1;
return 2;
}

@Override
Expand All @@ -60,7 +66,32 @@ public Message getPermissionLackMessage() {

@Override
public void execute(SuperiorSkyblockPlugin plugin, SuperiorPlayer superiorPlayer, Island island, String[] args) {
plugin.getMenus().openIslandChest(superiorPlayer, null, island);
if (args.length == 2) {
Pair<Integer, Boolean> pageArguments = CommandArguments.getPage(superiorPlayer.asPlayer(), args[1]);

if (!pageArguments.getValue())
return;

int page = pageArguments.getKey() - 1;
IslandChest[] islandChests = island.getChest();

if (page < 0 || page >= islandChests.length) {
Message.INVALID_PAGE.send(superiorPlayer, args[1]);
return;
}

islandChests[page].openChest(superiorPlayer);
} else {
plugin.getMenus().openIslandChest(superiorPlayer, null, island);
}
}

@Override
public List<String> tabComplete(SuperiorSkyblockPlugin plugin, SuperiorPlayer superiorPlayer, Island island, String[] args) {
IslandChest[] islandChests = island.getChest();
return args.length == 1 || islandChests.length == 0 ? new ArrayList<>() :
CommandTabCompletes.getCustomComplete(args[1], IntStream.range(1, islandChests.length + 1).boxed()
.map(Object::toString).toArray(String[]::new));
}

}

0 comments on commit 6c4c97c

Please sign in to comment.