Added a new command, a color string method to StringUtil, and a method to check if a block can be stacked in StackableManager.

This commit is contained in:
Darkmans39 2019-10-08 03:57:22 +00:00 committed by Brianna O'Keefe
parent 419008f04f
commit e5222c6d24
7 changed files with 148 additions and 6 deletions

View File

@ -3,7 +3,7 @@ image: gradle:alpine
variables:
name: "FabledSkyBlock"
path: "/builds/$CI_PROJECT_PATH"
version: "2.0.3"
version: "2.0.4"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle

View File

@ -110,7 +110,8 @@ public class CommandManager implements CommandExecutor, TabCompleter {
new com.songoda.skyblock.command.commands.admin.SetSpawnCommand(),
new com.songoda.skyblock.command.commands.admin.SettingsCommand(),
new StructureCommand(),
new com.songoda.skyblock.command.commands.admin.UpgradeCommand()
new com.songoda.skyblock.command.commands.admin.UpgradeCommand(),
new StackableCommand()
);
}

View File

@ -0,0 +1,120 @@
package com.songoda.skyblock.command.commands.admin;
import java.io.File;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.songoda.skyblock.command.SubCommand;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.stackable.Stackable;
import com.songoda.skyblock.stackable.StackableManager;
import com.songoda.skyblock.utils.StringUtil;
public class StackableCommand extends SubCommand {
@Override
public void onCommandByPlayer(Player player, String[] args) {
final MessageManager messageManager = skyblock.getMessageManager();
if (args.length == 0) {
player.sendMessage(StringUtil.color("&e/island admin stackable setsize <size> &7- &f&osets the target block's stack size if applicable"));
return;
}
final FileConfiguration messageConfig = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration();
if (args[0].equalsIgnoreCase("setsize")) {
if (args.length == 1) {
messageManager.sendMessage(player, messageConfig.getString("Command.Island.Admin.Stackable.Setsize.No-Arguments"));
return;
}
int amount = 0;
try {
amount = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
messageManager.sendMessage(player, (messageConfig.getString("Command.Island.Admin.Stackable.Setsize.Invalid-Number")).replace("%number%", args[1]));
return;
}
final Block block = player.getTargetBlock((Set<Material>) null, 6);
if (block == null) {
messageManager.sendMessage(player, messageConfig.getString("Command.Island.Admin.Stackable.Target.None"));
return;
}
final StackableManager stackableManager = skyblock.getStackableManager();
if (!stackableManager.isStackableMaterial(block.getType())) {
messageManager.sendMessage(player, messageConfig.getString("Command.Island.Admin.Stackable.Target.Unstackable"));
return;
}
final Location loc = block.getLocation();
Stackable stack = stackableManager.getStack(loc, block.getType());
if (amount <= 1) {
messageManager.sendMessage(player, messageConfig.getString("Command.Island.Admin.Stackable.Target.Remove-Stack"));
if (stack != null) stackableManager.removeStack(stack);
return;
}
final int oldSize;
if (stack == null) {
stack = new Stackable(loc, block.getType());
stackableManager.addStack(stack);
oldSize = 0;
} else {
oldSize = stack.getSize();
}
stack.setSize(amount);
String input = messageConfig.getString("Command.Island.Admin.Stackable.Setsize.Success");
input = input.replace("%old_size%", Integer.toString(oldSize));
input = input.replace("%new_size%", Integer.toString(amount));
messageManager.sendMessage(player, input);
} else {
messageManager.sendMessage(player, messageConfig.getString("Command.Island.Argument.Unrecognised.Message"));
}
}
@Override
public void onCommandByConsole(ConsoleCommandSender sender, String[] args) {
sender.sendMessage("SkyBlock | Error: You must be a player to perform that command.");
}
@Override
public String getName() {
return "stackable";
}
@Override
public String getInfoMessagePath() {
return "Command.Island.Admin.Stackable.Info.Message";
}
@Override
public String[] getAliases() {
return new String[] { "stackables" };
}
@Override
public String[] getArguments() {
return new String[] { "setsize" };
}
}

View File

@ -141,7 +141,7 @@ public class Interact implements Listener {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (stackableManager != null
&& stackableManager.getStackableMaterials().contains(event.getMaterial())
&& stackableManager.isStackableMaterial(event.getMaterial())
&& event.getClickedBlock().getType() == event.getMaterial()
&& !player.isSneaking() && islandManager.hasPermission(player, block.getLocation(), "Place")
&& (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Stackable.RequirePermission") || player.hasPermission("fabledskyblock.stackable"))) {

View File

@ -15,7 +15,7 @@ public class StackableManager {
//ToDO: Should pobably be a GUI for this
private final SkyBlock skyblock;
private List<Material> stackableMaterials = new ArrayList<>();
private Set<Material> stackableMaterials = EnumSet.noneOf(Material.class);
private Map<Location, Stackable> stacks = new HashMap<>();
public StackableManager(SkyBlock skyblock) {
@ -66,8 +66,12 @@ public class StackableManager {
stackableMaterials.clear();
}
public List<Material> getStackableMaterials() {
return Collections.unmodifiableList(stackableMaterials);
public Set<Material> getStackableMaterials() {
return Collections.unmodifiableSet(stackableMaterials);
}
public boolean isStackableMaterial(Material material) {
return stackableMaterials.contains(material);
}
public Map<Location, Stackable> getStacks() {

View File

@ -3,6 +3,8 @@ package com.songoda.skyblock.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.md_5.bungee.api.ChatColor;
public final class StringUtil {
public static String capatilizeUppercaseLetters(String string) {
@ -19,4 +21,8 @@ public final class StringUtil {
return stringBuilder.toString();
}
public static String color(String input) {
return input == null ? null : ChatColor.translateAlternateColorCodes('&', input);
}
}

View File

@ -142,6 +142,17 @@ Command:
Message: '&f&oReload all loaded files.'
Reloaded:
Message: '&bSkyBlock &8| &aInfo&8: &eAll loaded files have been reloaded.'
Stackable:
Info:
Message: '&f&oManage stackables'
Target:
None: '&bSkyBlock &8| &cError&8: &eYou must be looking at a block.'
Unstackable: '&bSkyBlock &8| &cError&8: &eUnable to target unstackable block.'
Remove-Stack: '&bSkyBlock &8| &aInfo&8: &eSuccessfully removed stack if one was present.'
Setsize:
No-Arguments: '&bSkyBlock &8| &cError&8: &ePlease input a number that will become the new stack size.'
Invalid-Number: '&bSkyBlock &8| &cError&8: &eFailed to parse a number from %number%'
Success: '&bSkyBlock &8| &aInfo&8: &eSuccessfully changed the target block''s stack size from %old_size% to %new_size%'
RemoveUpgrade:
Invalid:
Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin removeupgrade <player> <upgrade>'