Enable checking the whitelist of breaking and placing.

This commit is contained in:
graywolf336 2014-01-19 15:53:42 -06:00
parent da26bc172e
commit f41ee77092
5 changed files with 72 additions and 41 deletions

View File

@ -11,13 +11,11 @@ With this being version 3 of this plugin, a couple things have changed but the c
* New language system * New language system
* New config system (per jail configs are going to make a come back) * New config system (per jail configs are going to make a come back)
* Only prisoners will be able to place/break blocks on the whitelist * Only prisoners will be able to place/break blocks on the whitelist
* Items in the config use item names now, not the ids * Items in the config use item names now, **not** the ids
ToDo ToDo
=== ===
* About everything * About everything
* Enable a whitelist of blocks which can be broke
* Enabled a whitelist of blocks which can be placed
Done Done
=== ===

View File

@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -73,6 +74,24 @@ public class Util {
return (point1 <= loc) && (loc <= point2); return (point1 <= loc) && (loc <= point2);
} }
/**
* Checks if the given string is inside the list, ignoring the casing.
*
* <p />
*
* @param list of strings to check
* @param value to check
* @return true if the list contains the provided value, false if it doesn't
*/
public static boolean isStringInsideList(List<String> list, String value) {
boolean r = false;
for(String s : list)
if(s.equalsIgnoreCase(value))
return true;
return r;
}
/** Returns a colorful message from the color codes. */ /** Returns a colorful message from the color codes. */
public static String getColorfulMessage(String message) { public static String getColorfulMessage(String message) {
return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1"); return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1");

View File

@ -4,8 +4,10 @@ public enum Settings {
BROADCASTJAILING("jailing.jail.broadcastJailing"), BROADCASTJAILING("jailing.jail.broadcastJailing"),
BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"), BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"),
BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"), BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"),
BLOCKBREAKWHITELIST("jailing.during.blockBreakWhiteList"),
BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"), BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"),
BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"), BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"),
BLOCKPLACEWHITELIST("jailing.during.blockPlaceWhiteList"),
COMMANDSONJAIL("jailing.jail.commands"), COMMANDSONJAIL("jailing.jail.commands"),
COMMANDSONRELEASE("jailing.release.commands"), COMMANDSONRELEASE("jailing.release.commands"),
COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"), COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"),

View File

@ -28,6 +28,10 @@ public class ProtectionListener implements Listener {
//in the BlockListener class will take care of protecting inside //in the BlockListener class will take care of protecting inside
//of the jails. //of the jails.
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
//Get the breaking whitelist, check if the current item is in there
//the list must be lowercase, need to stress that
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()),
event.getBlock().getType().toString().toLowerCase())) {
//As our Util.getTime throws an exception when the time is in an //As our Util.getTime throws an exception when the time is in an
//incorrect format, we catch the exception and don't add any time //incorrect format, we catch the exception and don't add any time
//as a fail safe, don't want us to go crazy adding tons of time. //as a fail safe, don't want us to go crazy adding tons of time.
@ -51,6 +55,7 @@ public class ProtectionListener implements Listener {
} }
} }
} }
}
@EventHandler(ignoreCancelled=true) @EventHandler(ignoreCancelled=true)
public void protectionBlockPlacing(BlockPlaceEvent event) { public void protectionBlockPlacing(BlockPlaceEvent event) {
@ -61,6 +66,10 @@ public class ProtectionListener implements Listener {
//in the BlockListener class will take care of protecting inside //in the BlockListener class will take care of protecting inside
//of the jails. //of the jails.
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
//Get the placing whitelist, check if the current item is in there
//the list must be lowercase, need to stress that
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()),
event.getBlock().getType().toString().toLowerCase())) {
//As our Util.getTime throws an exception when the time is in an //As our Util.getTime throws an exception when the time is in an
//incorrect format, we catch the exception and don't add any time //incorrect format, we catch the exception and don't add any time
//as a fail safe, don't want us to go crazy adding tons of time. //as a fail safe, don't want us to go crazy adding tons of time.
@ -84,4 +93,5 @@ public class ProtectionListener implements Listener {
} }
} }
} }
}
} }

View File

@ -15,8 +15,10 @@ jailing:
during: during:
blockBreakPenalty: 5m blockBreakPenalty: 5m
blockBreakProtection: true blockBreakProtection: true
blockBreakWhiteList: ['wheat', 'carrot'] # these blocks can be broken at any time by prisoners
blockPlacePenalty: 5m blockPlacePenalty: 5m
blockPlaceProtection: true blockPlaceProtection: true
blockPlaceWhiteList: ['seeds', 'carrot'] # these blocks can be placed at any time by prisoners
countDownTimeWhileOffline: false countDownTimeWhileOffline: false
explosionProtection: true explosionProtection: true
ignoreSleeping: true ignoreSleeping: true