Add a check for creating books with more than 50 pages.

This commit is contained in:
asofold 2015-01-19 02:52:02 +01:00
parent 205b351dff
commit 0fa307a8df
8 changed files with 194 additions and 116 deletions

View File

@ -0,0 +1,45 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.inventory.meta.BookMeta;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
public class Gutenberg extends Check implements Listener {
public static void testAvailability(){
if (!PlayerEditBookEvent.class.getSimpleName().equals("PlayerEditBookEvent")){
throw new RuntimeException("This exception should not even get thrown.");
}
}
public Gutenberg() {
super(CheckType.INVENTORY_GUTENBERG);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEditBook(final PlayerEditBookEvent event) {
final Player player = event.getPlayer();
if (!isEnabled(player)) {
return;
}
final InventoryConfig cc = InventoryConfig.getConfig(player);
final BookMeta newMeta = event.getNewBookMeta();
final int pages = newMeta.getPageCount();
if (pages <= 50) {
// Legitimate.
return;
}
// Violation.
final int vl = pages - 50;
if (executeActions(player, vl, vl, cc.gutenbergActions)) {
event.setCancelled(true);
}
}
}

View File

@ -84,6 +84,7 @@ public enum CheckType {
INVENTORY_DROP(INVENTORY, Permissions.INVENTORY_DROP),
INVENTORY_FASTCLICK(INVENTORY, Permissions.INVENTORY_FASTCLICK),
INVENTORY_FASTCONSUME(INVENTORY, Permissions.INVENTORY_FASTCONSUME),
INVENTORY_GUTENBERG(INVENTORY, Permissions.INVENTORY_GUTENBERG),
INVENTORY_INSTANTBOW(INVENTORY, Permissions.INVENTORY_INSTANTBOW),
INVENTORY_INSTANTEAT(INVENTORY, Permissions.INVENTORY_INSTANTEAT),
INVENTORY_ITEMS(INVENTORY, Permissions.INVENTORY_ITEMS),

View File

@ -25,138 +25,146 @@ import fr.neatmonster.nocheatplus.permissions.Permissions;
*/
public class InventoryConfig extends ACheckConfig {
/** The factory creating configurations. */
public static final CheckConfigFactory factory = new CheckConfigFactory() {
@Override
public final ICheckConfig getConfig(final Player player) {
return InventoryConfig.getConfig(player);
}
};
/** The factory creating configurations. */
public static final CheckConfigFactory factory = new CheckConfigFactory() {
@Override
public final ICheckConfig getConfig(final Player player) {
return InventoryConfig.getConfig(player);
}
};
/** The map containing the configurations per world. */
private static final Map<String, InventoryConfig> worldsMap = new HashMap<String, InventoryConfig>();
/** The map containing the configurations per world. */
private static final Map<String, InventoryConfig> worldsMap = new HashMap<String, InventoryConfig>();
/**
* Clear all the configurations.
*/
public static void clear() {
worldsMap.clear();
}
/**
* Clear all the configurations.
*/
public static void clear() {
worldsMap.clear();
}
/**
* Gets the configuration for a specified player.
*
* @param player
* the player
* @return the configuration
*/
public static InventoryConfig getConfig(final Player player) {
if (!worldsMap.containsKey(player.getWorld().getName()))
worldsMap.put(player.getWorld().getName(), new InventoryConfig(
ConfigManager.getConfigFile(player.getWorld().getName())));
return worldsMap.get(player.getWorld().getName());
}
/**
* Gets the configuration for a specified player.
*
* @param player
* the player
* @return the configuration
*/
public static InventoryConfig getConfig(final Player player) {
if (!worldsMap.containsKey(player.getWorld().getName()))
worldsMap.put(player.getWorld().getName(), new InventoryConfig(
ConfigManager.getConfigFile(player.getWorld().getName())));
return worldsMap.get(player.getWorld().getName());
}
public final boolean dropCheck;
public final int dropLimit;
public final long dropTimeFrame;
public final ActionList dropActions;
public final boolean dropCheck;
public final int dropLimit;
public final long dropTimeFrame;
public final ActionList dropActions;
public final boolean fastClickCheck;
public final boolean fastClickCheck;
public final boolean fastClickSpareCreative;
public final boolean fastClickTweaks1_5;
public final float fastClickShortTermLimit;
public final float fastClickNormalLimit;
public final ActionList fastClickActions;
public final boolean fastConsumeCheck;
public final long fastConsumeDuration;
public final boolean fastConsumeWhitelist;
public final Set<Material> fastConsumeItems = new HashSet<Material>();
public final ActionList fastConsumeActions;
public final boolean fastClickTweaks1_5;
public final float fastClickShortTermLimit;
public final float fastClickNormalLimit;
public final ActionList fastClickActions;
public final boolean instantBowCheck;
public final boolean instantBowStrict;
public final boolean fastConsumeCheck;
public final long fastConsumeDuration;
public final boolean fastConsumeWhitelist;
public final Set<Material> fastConsumeItems = new HashSet<Material>();
public final ActionList fastConsumeActions;
public final boolean gutenbergCheck;
public final ActionList gutenbergActions;
public final boolean instantBowCheck;
public final boolean instantBowStrict;
public final long instantBowDelay;
public final ActionList instantBowActions;
public final ActionList instantBowActions;
public final boolean instantEatCheck;
public final ActionList instantEatActions;
public final boolean instantEatCheck;
public final ActionList instantEatActions;
public final boolean itemsCheck;
public final boolean openCheck;
public final boolean openClose;
public final boolean openCancelOther;
/**
* Instantiates a new inventory configuration.
*
* @param data
* the data
*/
public InventoryConfig(final ConfigFile data) {
super(data, ConfPaths.INVENTORY);
dropCheck = data.getBoolean(ConfPaths.INVENTORY_DROP_CHECK);
dropLimit = data.getInt(ConfPaths.INVENTORY_DROP_LIMIT);
dropTimeFrame = data.getLong(ConfPaths.INVENTORY_DROP_TIMEFRAME);
dropActions = data.getOptimizedActionList(ConfPaths.INVENTORY_DROP_ACTIONS, Permissions.INVENTORY_DROP);
fastClickCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_CHECK);
fastClickSpareCreative = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_SPARECREATIVE);
fastClickTweaks1_5 = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_TWEAKS1_5);
fastClickShortTermLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_SHORTTERM);
fastClickNormalLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_NORMAL);
fastClickActions = data.getOptimizedActionList(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, Permissions.INVENTORY_FASTCLICK);
fastConsumeCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCONSUME_CHECK);
fastConsumeDuration = (long) (1000.0 * data.getDouble(ConfPaths.INVENTORY_FASTCONSUME_DURATION));
fastConsumeWhitelist = data.getBoolean(ConfPaths.INVENTORY_FASTCONSUME_WHITELIST);
data.readMaterialFromList(ConfPaths.INVENTORY_FASTCONSUME_ITEMS, fastConsumeItems);
fastConsumeActions = data.getOptimizedActionList(ConfPaths.INVENTORY_FASTCONSUME_ACTIONS, Permissions.INVENTORY_FASTCONSUME);
/**
* Instantiates a new inventory configuration.
*
* @param data
* the data
*/
public InventoryConfig(final ConfigFile data) {
super(data, ConfPaths.INVENTORY);
dropCheck = data.getBoolean(ConfPaths.INVENTORY_DROP_CHECK);
dropLimit = data.getInt(ConfPaths.INVENTORY_DROP_LIMIT);
dropTimeFrame = data.getLong(ConfPaths.INVENTORY_DROP_TIMEFRAME);
dropActions = data.getOptimizedActionList(ConfPaths.INVENTORY_DROP_ACTIONS, Permissions.INVENTORY_DROP);
instantBowCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_CHECK);
instantBowStrict = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_STRICT);
instantBowDelay = data.getInt(ConfPaths.INVENTORY_INSTANTBOW_DELAY);
instantBowActions = data.getOptimizedActionList(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, Permissions.INVENTORY_INSTANTBOW);
fastClickCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_CHECK);
fastClickSpareCreative = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_SPARECREATIVE);
fastClickTweaks1_5 = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_TWEAKS1_5);
fastClickShortTermLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_SHORTTERM);
fastClickNormalLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_NORMAL);
fastClickActions = data.getOptimizedActionList(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, Permissions.INVENTORY_FASTCLICK);
instantEatCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTEAT_CHECK);
instantEatActions = data.getOptimizedActionList(ConfPaths.INVENTORY_INSTANTEAT_ACTIONS, Permissions.INVENTORY_INSTANTEAT);
itemsCheck = data.getBoolean(ConfPaths.INVENTORY_ITEMS_CHECK);
openCheck = data.getBoolean(ConfPaths.INVENTORY_OPEN_CHECK);
openClose = data.getBoolean(ConfPaths.INVENTORY_OPEN_CLOSE);
openCancelOther = data.getBoolean(ConfPaths.INVENTORY_OPEN_CANCELOTHER);
}
fastConsumeCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCONSUME_CHECK);
fastConsumeDuration = (long) (1000.0 * data.getDouble(ConfPaths.INVENTORY_FASTCONSUME_DURATION));
fastConsumeWhitelist = data.getBoolean(ConfPaths.INVENTORY_FASTCONSUME_WHITELIST);
data.readMaterialFromList(ConfPaths.INVENTORY_FASTCONSUME_ITEMS, fastConsumeItems);
fastConsumeActions = data.getOptimizedActionList(ConfPaths.INVENTORY_FASTCONSUME_ACTIONS, Permissions.INVENTORY_FASTCONSUME);
/*
* (non-Javadoc)
*
* @see
* fr.neatmonster.nocheatplus.checks.ICheckConfig#isEnabled(fr.neatmonster
* .nocheatplus.checks.CheckType)
*/
@Override
public final boolean isEnabled(final CheckType checkType) {
switch (checkType) {
case INVENTORY_FASTCLICK:
return fastClickCheck;
case INVENTORY_ITEMS:
return itemsCheck;
case INVENTORY_OPEN:
return openCheck;
case INVENTORY_DROP:
return dropCheck;
case INVENTORY_INSTANTBOW:
return instantBowCheck;
case INVENTORY_INSTANTEAT:
return instantEatCheck;
case INVENTORY_FASTCONSUME:
return fastConsumeCheck;
default:
return true;
}
}
gutenbergCheck = data.getBoolean(ConfPaths.INVENTORY_GUTENBERG_CHECK);
gutenbergActions = data.getOptimizedActionList(ConfPaths.INVENTORY_GUTENBERG_ACTIONS, Permissions.INVENTORY_GUTENBERG);
instantBowCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_CHECK);
instantBowStrict = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_STRICT);
instantBowDelay = data.getInt(ConfPaths.INVENTORY_INSTANTBOW_DELAY);
instantBowActions = data.getOptimizedActionList(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, Permissions.INVENTORY_INSTANTBOW);
instantEatCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTEAT_CHECK);
instantEatActions = data.getOptimizedActionList(ConfPaths.INVENTORY_INSTANTEAT_ACTIONS, Permissions.INVENTORY_INSTANTEAT);
itemsCheck = data.getBoolean(ConfPaths.INVENTORY_ITEMS_CHECK);
openCheck = data.getBoolean(ConfPaths.INVENTORY_OPEN_CHECK);
openClose = data.getBoolean(ConfPaths.INVENTORY_OPEN_CLOSE);
openCancelOther = data.getBoolean(ConfPaths.INVENTORY_OPEN_CANCELOTHER);
}
/*
* (non-Javadoc)
*
* @see
* fr.neatmonster.nocheatplus.checks.ICheckConfig#isEnabled(fr.neatmonster
* .nocheatplus.checks.CheckType)
*/
@Override
public final boolean isEnabled(final CheckType checkType) {
switch (checkType) {
case INVENTORY_FASTCLICK:
return fastClickCheck;
case INVENTORY_ITEMS:
return itemsCheck;
case INVENTORY_OPEN:
return openCheck;
case INVENTORY_DROP:
return dropCheck;
case INVENTORY_INSTANTBOW:
return instantBowCheck;
case INVENTORY_INSTANTEAT:
return instantEatCheck;
case INVENTORY_FASTCONSUME:
return fastConsumeCheck;
case INVENTORY_GUTENBERG:
return gutenbergCheck;
default:
return true;
}
}
}

View File

@ -473,6 +473,10 @@ public abstract class ConfPaths {
public static final String INVENTORY_FASTCONSUME_ITEMS = INVENTORY_FASTCONSUME + "items";
public static final String INVENTORY_FASTCONSUME_ACTIONS = INVENTORY_FASTCONSUME + "actions";
private static final String INVENTORY_GUTENBERG = INVENTORY + "gutenberg.";
public static final String INVENTORY_GUTENBERG_CHECK = INVENTORY_GUTENBERG + "active";
public static final String INVENTORY_GUTENBERG_ACTIONS = INVENTORY_GUTENBERG + "actions";
private static final String INVENTORY_INSTANTBOW = INVENTORY + "instantbow.";
public static final String INVENTORY_INSTANTBOW_CHECK = INVENTORY_INSTANTBOW + "active";
public static final String INVENTORY_INSTANTBOW_STRICT = INVENTORY_INSTANTBOW + "strict";

View File

@ -341,6 +341,9 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.INVENTORY_FASTCONSUME_ITEMS, new LinkedList<String>());
set(ConfPaths.INVENTORY_FASTCONSUME_ACTIONS, "log:fastconsume:2:5:if cancel");
set(ConfPaths.INVENTORY_GUTENBERG_CHECK, true);
set(ConfPaths.INVENTORY_GUTENBERG_ACTIONS, "cancel log:gutenberg:0:10:icf cmd:kickinvaliddata");
set(ConfPaths.INVENTORY_ITEMS_CHECK, true);
set(ConfPaths.INVENTORY_OPEN_CHECK, true);

View File

@ -109,6 +109,7 @@ public class Permissions {
public static final String INVENTORY_DROP = INVENTORY + ".drop";
public static final String INVENTORY_FASTCLICK = INVENTORY + ".fastclick";
public static final String INVENTORY_FASTCONSUME = INVENTORY + ".fastconsume";
public static final String INVENTORY_GUTENBERG = INVENTORY + ".gutenberg";
public static final String INVENTORY_INSTANTBOW = INVENTORY + ".instantbow";
public static final String INVENTORY_INSTANTEAT = INVENTORY + ".instanteat";
public static final String INVENTORY_ITEMS = INVENTORY + ".items";

View File

@ -8,6 +8,7 @@ import java.util.List;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.inventory.FastConsume;
import fr.neatmonster.nocheatplus.checks.inventory.Gutenberg;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.logging.StaticLog;
@ -29,6 +30,8 @@ public class DefaultComponentFactory {
final List<Object> available = new LinkedList<Object>();
// Add components (try-catch).
// TODO: catch ClassNotFound, incompatibleXY rather !?
// Check: inventory.fastconsume.
try{
// TODO: Static test methods !?
@ -41,6 +44,17 @@ public class DefaultComponentFactory {
catch (Throwable t){
StaticLog.logInfo("[NoCheatPlus] Inventory checks: FastConsume is not available.");
}
// Check: inventory.gutenberg.
try {
Gutenberg.testAvailability();
available.add(new Gutenberg());
if (ConfigManager.isTrueForAnyConfig(ConfPaths.INVENTORY_GUTENBERG_CHECK)) {
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("checks", Arrays.asList(Gutenberg.class.getSimpleName()));
}
} catch (Throwable t) {
StaticLog.logInfo("[NoCheatPlus] Inventory checks: Gutenberg is not available.");
}
// ProtocolLib dependencies.
try {

View File

@ -15,7 +15,7 @@ softdepend:
commands:
nocheatplus:
aliases: [ncp]
aliases: [ncp]f
description: NoCheatPlus command(s).
# permissions: nocheatplus.admin.(...)
usage: |
@ -149,6 +149,8 @@ permissions:
description: Allow the player to bypass the FastClick check.
nocheatplus.checks.inventory.fastconsume:
description: Allow to bypass the FastConsume check.
nocheatplus.checks.inventory.gutenberg:
description: Allow to bypass the Gutenberg check.
nocheatplus.checks.inventory.instantbow:
description: Allow the player to bypass the InstantBow check.
nocheatplus.checks.inventory.instanteat: