Added invalid strength values check
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package com.redstoner.modules.signalstrength;
|
package com.redstoner.modules.signalstrength;
|
||||||
|
|
||||||
import com.nemez.cmdmgr.Command;
|
import java.util.ArrayList;
|
||||||
import com.redstoner.annotations.Commands;
|
import java.util.Arrays;
|
||||||
import com.redstoner.annotations.Version;
|
import java.util.Set;
|
||||||
import com.redstoner.misc.CommandHolderType;
|
|
||||||
import com.redstoner.modules.Module;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@@ -22,16 +21,19 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.nemez.cmdmgr.Command;
|
||||||
import java.util.Arrays;
|
import com.redstoner.annotations.Commands;
|
||||||
import java.util.Set;
|
import com.redstoner.annotations.Version;
|
||||||
|
import com.redstoner.misc.CommandHolderType;
|
||||||
|
import com.redstoner.modules.Module;
|
||||||
|
|
||||||
@Commands(CommandHolderType.File)
|
@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
|
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)
|
private static String nameForSignalStrength(int strength)
|
||||||
{
|
{
|
||||||
@@ -52,8 +54,15 @@ public class SignalStrength implements Module
|
|||||||
@Command(hook = "ssm")
|
@Command(hook = "ssm")
|
||||||
public boolean ssm(CommandSender sender, int strength, String material)
|
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;
|
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");
|
getLogger().message(sender, true, "You must be in creative mode to do that");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -98,9 +107,7 @@ public class SignalStrength implements Module
|
|||||||
if (inventory.getType() == InventoryType.CHEST)
|
if (inventory.getType() == InventoryType.CHEST)
|
||||||
{
|
{
|
||||||
Arrays.stream(new BlockFace[] {BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH})
|
Arrays.stream(new BlockFace[] {BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH})
|
||||||
.map(targetBlock::getRelative)
|
.map(targetBlock::getRelative).filter(b -> b.getType() == blockType).forEach(containerBlocks::add);
|
||||||
.filter(b -> b.getType() == blockType)
|
|
||||||
.forEach(containerBlocks::add);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Block containerBlock : containerBlocks)
|
for (Block containerBlock : containerBlocks)
|
||||||
@@ -118,7 +125,8 @@ public class SignalStrength implements Module
|
|||||||
{
|
{
|
||||||
// Below checks should evaluate to false, but let's be safe.
|
// Below checks should evaluate to false, but let's be safe.
|
||||||
BlockState blockState = containerBlock.getState();
|
BlockState blockState = containerBlock.getState();
|
||||||
if (!(blockState instanceof InventoryHolder)) continue;
|
if (!(blockState instanceof InventoryHolder))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (blockState instanceof Nameable && isSignalStrengthNameOrEmpty(((Nameable) blockState).getCustomName()))
|
if (blockState instanceof Nameable && isSignalStrengthNameOrEmpty(((Nameable) blockState).getCustomName()))
|
||||||
{
|
{
|
||||||
@@ -127,7 +135,8 @@ public class SignalStrength implements Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
Inventory inv = ((InventoryHolder) blockState).getInventory();
|
Inventory inv = ((InventoryHolder) blockState).getInventory();
|
||||||
if (inv == null) continue;
|
if (inv == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
inv.clear();
|
inv.clear();
|
||||||
for (int i = 0; i < fullStackCount; i++)
|
for (int i = 0; i < fullStackCount; i++)
|
||||||
@@ -182,5 +191,4 @@ public class SignalStrength implements Module
|
|||||||
return enumName.toLowerCase().replace('_', ' ');
|
return enumName.toLowerCase().replace('_', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user