Prevent interaction with items and blocks!

Works just like the old version, they can interact with anything except
what is in the blacklist.
This commit is contained in:
graywolf336 2014-01-21 22:23:26 -06:00
parent 1e3a8cc992
commit fe1db3bb04
5 changed files with 88 additions and 2 deletions

View File

@ -11,6 +11,10 @@ public enum LangString {
COMMAND ("actions"), COMMAND ("actions"),
/** Section for when a player tramples a crop and protection is enabled. */ /** Section for when a player tramples a crop and protection is enabled. */
CROPTRAMPLING ("actions"), CROPTRAMPLING ("actions"),
/** Section for when a player interacts with a block that is blacklisted. */
INTERACTIONBLOCKS ("actions"),
/** Section for when a player interacts with an item that is blacklisted. */
INTERACTIONITEMS ("actions"),
//Jailing section //Jailing section

View File

@ -32,6 +32,10 @@ public enum Settings {
LOGJAILING("jailing.jail.logToConsole"), LOGJAILING("jailing.jail.logToConsole"),
MAXAFKTIME("jailing.during.maxAFKTime"), MAXAFKTIME("jailing.during.maxAFKTime"),
OPENCHEST("jailing.during.openChest"), OPENCHEST("jailing.during.openChest"),
PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"),
PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"),
PREVENTINTERACTIONITEMS("jailing.during.preventInteractionItems"),
PREVENTINTERACTIONITEMSPENALTY("jailing.during.preventInteractionItemsPenalty"),
RECIEVEMESSAGES("jailing.during.recieveMessages"), RECIEVEMESSAGES("jailing.during.recieveMessages"),
RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"), RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"),
RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"), RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"),

View File

@ -34,7 +34,6 @@ public class ProtectionListener implements Listener {
//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 //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()), if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()),
event.getBlock().getType().toString().toLowerCase())) { 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
@ -80,7 +79,6 @@ public class ProtectionListener implements Listener {
//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 //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()), if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()),
event.getBlock().getType().toString().toLowerCase())) { 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
@ -244,4 +242,78 @@ public class ProtectionListener implements Listener {
} }
} }
} }
@EventHandler(ignoreCancelled=true)
public void interactionProtection(PlayerInteractEvent event) {
//As the old version didn't do anything with Physical interactions, we won't either
if (event.getAction() != Action.PHYSICAL) {
//First thing is first, let's be sure the player we're dealing with is in jail
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
//Let's check if they've interacted with a block
if (event.getClickedBlock() != null) {
//Get the interaction blacklist, check if the current block is in there
//if it is, then let's take action
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()),
event.getClickedBlock().getType().toString().toLowerCase())) {
try {
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add);
String msg = "";
if(add == 0L) {
//Generate the protection message, provide the method with one argument
//which is the thing we are protecting against
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS));
}else {
//Generate the protection message, provide the method with two arguments
//First is the time in minutes and second is the thing we are protecting against
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS) });
}
//Send the message
event.getPlayer().sendMessage(msg);
}catch(Exception e) {
pl.getLogger().severe("Prevent Interaction with Blocks penalty's time is in the wrong format, please fix.");
}
event.setCancelled(true);
}
}else if (event.getPlayer().getItemInHand() != null) {
//Otherwise let's check if they have something in hand
//Get the interaction blacklist, check if the current item is in there
//if it is, then let's take action
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()),
event.getClickedBlock().getType().toString().toLowerCase())) {
try {
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath()));
pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add);
String msg = "";
if(add == 0L) {
//Generate the protection message, provide the method with one argument
//which is the thing we are protecting against
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS));
}else {
//Generate the protection message, provide the method with two arguments
//First is the time in minutes and second is the thing we are protecting against
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS) });
}
//Send the message
event.getPlayer().sendMessage(msg);
}catch(Exception e) {
pl.getLogger().severe("Prevent Interaction with Items penalty's time is in the wrong format, please fix.");
}
event.setCancelled(true);
}
}
}
}
}
} }

View File

@ -34,6 +34,10 @@ jailing:
ignoreSleeping: true ignoreSleeping: true
maxAFKTime: 10m #in minutes maxAFKTime: 10m #in minutes
openChest: true openChest: true
preventInteractionBlocks: ['wooden_door', 'iron_door_block']
preventInteractionBlocksPenalty: 5m
preventInteractionItems: []
preventInteractionItemsPenalty: 5m
recieveMessages: true recieveMessages: true
jail: jail:
automaticMute: true automaticMute: true

View File

@ -4,6 +4,8 @@ language:
blockplacing: 'placing a block' blockplacing: 'placing a block'
command: 'trying to use a command' command: 'trying to use a command'
croptrampling: 'trampling crops' croptrampling: 'trampling crops'
interactionBlocks: 'interacting with a block'
interactionItems: 'interacting with an item'
general: general:
alljails: 'all the jails' alljails: 'all the jails'
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.' cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'