mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-27 20:56:05 +01:00
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:
parent
419008f04f
commit
e5222c6d24
@ -3,7 +3,7 @@ image: gradle:alpine
|
|||||||
variables:
|
variables:
|
||||||
name: "FabledSkyBlock"
|
name: "FabledSkyBlock"
|
||||||
path: "/builds/$CI_PROJECT_PATH"
|
path: "/builds/$CI_PROJECT_PATH"
|
||||||
version: "2.0.3"
|
version: "2.0.4"
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- export GRADLE_USER_HOME=`pwd`/.gradle
|
- export GRADLE_USER_HOME=`pwd`/.gradle
|
||||||
|
@ -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.SetSpawnCommand(),
|
||||||
new com.songoda.skyblock.command.commands.admin.SettingsCommand(),
|
new com.songoda.skyblock.command.commands.admin.SettingsCommand(),
|
||||||
new StructureCommand(),
|
new StructureCommand(),
|
||||||
new com.songoda.skyblock.command.commands.admin.UpgradeCommand()
|
new com.songoda.skyblock.command.commands.admin.UpgradeCommand(),
|
||||||
|
new StackableCommand()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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" };
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -141,7 +141,7 @@ public class Interact implements Listener {
|
|||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (stackableManager != null
|
if (stackableManager != null
|
||||||
&& stackableManager.getStackableMaterials().contains(event.getMaterial())
|
&& stackableManager.isStackableMaterial(event.getMaterial())
|
||||||
&& event.getClickedBlock().getType() == event.getMaterial()
|
&& event.getClickedBlock().getType() == event.getMaterial()
|
||||||
&& !player.isSneaking() && islandManager.hasPermission(player, block.getLocation(), "Place")
|
&& !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"))) {
|
&& (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Stackable.RequirePermission") || player.hasPermission("fabledskyblock.stackable"))) {
|
||||||
|
@ -15,7 +15,7 @@ public class StackableManager {
|
|||||||
//ToDO: Should pobably be a GUI for this
|
//ToDO: Should pobably be a GUI for this
|
||||||
|
|
||||||
private final SkyBlock skyblock;
|
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<>();
|
private Map<Location, Stackable> stacks = new HashMap<>();
|
||||||
|
|
||||||
public StackableManager(SkyBlock skyblock) {
|
public StackableManager(SkyBlock skyblock) {
|
||||||
@ -66,8 +66,12 @@ public class StackableManager {
|
|||||||
stackableMaterials.clear();
|
stackableMaterials.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Material> getStackableMaterials() {
|
public Set<Material> getStackableMaterials() {
|
||||||
return Collections.unmodifiableList(stackableMaterials);
|
return Collections.unmodifiableSet(stackableMaterials);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStackableMaterial(Material material) {
|
||||||
|
return stackableMaterials.contains(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Location, Stackable> getStacks() {
|
public Map<Location, Stackable> getStacks() {
|
||||||
|
@ -3,6 +3,8 @@ package com.songoda.skyblock.utils;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public final class StringUtil {
|
public final class StringUtil {
|
||||||
|
|
||||||
public static String capatilizeUppercaseLetters(String string) {
|
public static String capatilizeUppercaseLetters(String string) {
|
||||||
@ -19,4 +21,8 @@ public final class StringUtil {
|
|||||||
|
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String color(String input) {
|
||||||
|
return input == null ? null : ChatColor.translateAlternateColorCodes('&', input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,17 @@ Command:
|
|||||||
Message: '&f&oReload all loaded files.'
|
Message: '&f&oReload all loaded files.'
|
||||||
Reloaded:
|
Reloaded:
|
||||||
Message: '&bSkyBlock &8| &aInfo&8: &eAll loaded files have been 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:
|
RemoveUpgrade:
|
||||||
Invalid:
|
Invalid:
|
||||||
Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin removeupgrade <player> <upgrade>'
|
Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin removeupgrade <player> <upgrade>'
|
||||||
|
Loading…
Reference in New Issue
Block a user