Prevent commands from being executed, except those whitelisted
This commit is contained in:
parent
af58eea360
commit
392b1d94cc
@ -10,7 +10,6 @@ With this being version 3 of this plugin, a couple things have changed but the c
|
||||
* Time can now be entered different formats, 3hours or 15mins or 4days
|
||||
* New language system
|
||||
* 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
|
||||
* Items in the config use item names now, **not** the ids
|
||||
|
||||
ToDo
|
||||
|
@ -7,6 +7,8 @@ public enum LangString {
|
||||
BLOCKBREAKING ("actions"),
|
||||
/** Section for when they place a block. */
|
||||
BLOCKPLACING ("actions"),
|
||||
/** Section for when they try to do a command that isn't whitelisted. */
|
||||
COMMAND ("actions"),
|
||||
|
||||
//Jailing section
|
||||
|
||||
|
@ -10,6 +10,9 @@ public enum Settings {
|
||||
BLOCKPLACEWHITELIST("jailing.during.blockPlaceWhiteList"),
|
||||
COMMANDSONJAIL("jailing.jail.commands"),
|
||||
COMMANDSONRELEASE("jailing.release.commands"),
|
||||
COMMANDPENALTY("jailing.during.commandPenalty"),
|
||||
COMMANDPROTECTION("jailing.during.commandProtection"),
|
||||
COMMANDWHITELIST("jailing.during.commandWhitelist"),
|
||||
COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"),
|
||||
DEBUG("system.debug"),
|
||||
DEFAULTJAIL("jailing.jail.defaultJail"),
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
@ -45,13 +46,14 @@ public class ProtectionListener implements Listener {
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING) });
|
||||
|
||||
//Send the message and then stop the event from happening
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
event.setCancelled(true);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block break penalty's time is in the wrong format, please fix.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,15 +85,55 @@ public class ProtectionListener implements Listener {
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKPLACING) });
|
||||
|
||||
//Send the message and then stop the event from happening
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
event.setCancelled(true);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block place penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void commandProtection(PlayerCommandPreprocessEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.COMMANDPROTECTION.getPath())) {
|
||||
//Let's check if this player is jailed, if so then we continue
|
||||
//otherwise we don't care about commands in here
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
|
||||
boolean match = false;
|
||||
|
||||
for(String whited : pl.getConfig().getStringList(Settings.COMMANDWHITELIST.getPath()))
|
||||
if(event.getMessage().toLowerCase().startsWith(whited.toLowerCase()))
|
||||
match = true;
|
||||
|
||||
//If no match found in the whitelist, then let's block this command.
|
||||
if(!match) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.COMMANDPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add);
|
||||
|
||||
//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
|
||||
String msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.COMMAND) });
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Command Protection penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the command from happening, as it wasn't whitelisted
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ jailing:
|
||||
blockPlacePenalty: 5m
|
||||
blockPlaceProtection: true
|
||||
blockPlaceWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be placed at any time by prisoners
|
||||
commandPenalty: 5m
|
||||
commandProtection: true
|
||||
commandWhitelist: ['/ping', '/list']
|
||||
countDownTimeWhileOffline: false
|
||||
explosionProtection: true
|
||||
ignoreSleeping: true
|
||||
|
@ -2,6 +2,7 @@ language:
|
||||
actions:
|
||||
blockbreaking: 'breaking a block'
|
||||
blockplacing: 'placing a block'
|
||||
command: 'trying to use a command'
|
||||
general:
|
||||
unknowncommand: '&cNo commands registered by the name of %0%.'
|
||||
nopermission: '&cInsufficient permission.'
|
||||
|
Loading…
Reference in New Issue
Block a user