Archived
0

Added invalid strength values check

This commit is contained in:
Pepich
2018-01-01 18:13:38 +01:00
parent edf93f5272
commit 13f6a3babb

View File

@@ -1,10 +1,9 @@
package com.redstoner.modules.signalstrength;
import com.nemez.cmdmgr.Command;
import com.redstoner.annotations.Commands;
import com.redstoner.annotations.Version;
import com.redstoner.misc.CommandHolderType;
import com.redstoner.modules.Module;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -22,16 +21,19 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import com.nemez.cmdmgr.Command;
import com.redstoner.annotations.Commands;
import com.redstoner.annotations.Version;
import com.redstoner.misc.CommandHolderType;
import com.redstoner.modules.Module;
@Commands(CommandHolderType.File)
@Version(major = 4, minor = 0, revision = 1, compatible = 4)
@Version(major = 4, minor = 0, revision = 2, compatible = 4)
public class SignalStrength implements Module
{
private static final String namePrefix = ChatColor.GREEN.toString() + ChatColor.RESET + ChatColor.DARK_PURPLE + "Signal Strength: " + ChatColor.RED + ChatColor.BOLD;
private static final String namePrefix = ChatColor.GREEN.toString() + ChatColor.RESET + ChatColor.DARK_PURPLE
+ "Signal Strength: " + ChatColor.RED + ChatColor.BOLD;
private static String nameForSignalStrength(int strength)
{
@@ -52,8 +54,15 @@ public class SignalStrength implements Module
@Command(hook = "ssm")
public boolean ssm(CommandSender sender, int strength, String material)
{
if (strength < 0 || strength > 15)
{
getLogger().message(sender, true, "The strength must be between 0 and 15!");
return true;
}
Player player = (Player) sender;
if (player.getGameMode() != GameMode.CREATIVE) {
if (player.getGameMode() != GameMode.CREATIVE)
{
getLogger().message(sender, true, "You must be in creative mode to do that");
return true;
}
@@ -97,10 +106,8 @@ public class SignalStrength implements Module
Material blockType = targetBlock.getType();
if (inventory.getType() == InventoryType.CHEST)
{
Arrays.stream(new BlockFace[]{BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH})
.map(targetBlock::getRelative)
.filter(b -> b.getType() == blockType)
.forEach(containerBlocks::add);
Arrays.stream(new BlockFace[] {BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH})
.map(targetBlock::getRelative).filter(b -> b.getType() == blockType).forEach(containerBlocks::add);
}
for (Block containerBlock : containerBlocks)
@@ -118,7 +125,8 @@ public class SignalStrength implements Module
{
// Below checks should evaluate to false, but let's be safe.
BlockState blockState = containerBlock.getState();
if (!(blockState instanceof InventoryHolder)) continue;
if (!(blockState instanceof InventoryHolder))
continue;
if (blockState instanceof Nameable && isSignalStrengthNameOrEmpty(((Nameable) blockState).getCustomName()))
{
@@ -127,7 +135,8 @@ public class SignalStrength implements Module
}
Inventory inv = ((InventoryHolder) blockState).getInventory();
if (inv == null) continue;
if (inv == null)
continue;
inv.clear();
for (int i = 0; i < fullStackCount; i++)
@@ -182,5 +191,4 @@ public class SignalStrength implements Module
return enumName.toLowerCase().replace('_', ' ');
}
}