mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-04 17:49:49 +01:00
Elaborate hotfix for books slightly (aggressive!).
This commit is contained in:
parent
b0f54dae3f
commit
b0e33ef9dc
@ -89,6 +89,7 @@ public enum CheckType {
|
||||
INVENTORY_FASTCLICK(INVENTORY, Permissions.INVENTORY_FASTCLICK),
|
||||
INVENTORY_INSTANTBOW(INVENTORY, Permissions.INVENTORY_INSTANTBOW),
|
||||
INVENTORY_INSTANTEAT(INVENTORY, Permissions.INVENTORY_INSTANTEAT),
|
||||
INVENTORY_ITEMS(INVENTORY, Permissions.INVENTORY_ITEMS),
|
||||
|
||||
MOVING(MovingConfig.factory, MovingData.factory),
|
||||
MOVING_CREATIVEFLY(MOVING, Permissions.MOVING_CREATIVEFLY),
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.Items;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
@ -77,7 +78,12 @@ public class BlockBreakListener implements Listener {
|
||||
* | |_) | | (_) | (__| < | |_) | | | __/ (_| | <
|
||||
* |____/|_|\___/ \___|_|\_\ |____/|_| \___|\__,_|_|\_\
|
||||
*/
|
||||
// System.out.println("Break("+event.isCancelled()+"): " + event.getBlock());
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Illegal enchantments hotfix check.
|
||||
if (Items.checkIllegalEnchantments(player, player.getItemInHand())) event.setCancelled(true);
|
||||
|
||||
// Cancelled events only leads to resetting insta break.
|
||||
if (event.isCancelled()){
|
||||
isInstaBreak = false;
|
||||
@ -86,7 +92,7 @@ public class BlockBreakListener implements Listener {
|
||||
|
||||
// TODO: maybe invalidate instaBreak on some occasions.
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
final Block block = event.getBlock();
|
||||
|
||||
boolean cancelled = false;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.combined.Combined;
|
||||
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.Items;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
|
||||
@ -78,9 +78,8 @@ public class FightListener implements Listener {
|
||||
// Hotfix attempt for enchanted books.
|
||||
// TODO: maybe a generaluzed version for the future...
|
||||
final ItemStack stack = player.getItemInHand();
|
||||
if (stack != null && stack.getType() == Material.WRITTEN_BOOK){
|
||||
if (!stack.getEnchantments().isEmpty()) return true;
|
||||
}
|
||||
// Illegal enchantments hotfix check.
|
||||
if (Items.checkIllegalEnchantments(player, stack)) return true;
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
|
@ -88,6 +88,8 @@ public class InventoryConfig extends ACheckConfig {
|
||||
public final boolean instantEatCheck;
|
||||
public final ActionList instantEatActions;
|
||||
|
||||
public final boolean itemsCheck;
|
||||
|
||||
/**
|
||||
* Instantiates a new inventory configuration.
|
||||
*
|
||||
@ -117,6 +119,8 @@ public class InventoryConfig extends ACheckConfig {
|
||||
instantEatActions = data.getActionList(
|
||||
ConfPaths.INVENTORY_INSTANTEAT_ACTIONS,
|
||||
Permissions.INVENTORY_INSTANTEAT);
|
||||
|
||||
itemsCheck = data.getBoolean(ConfPaths.INVENTORY_ITEMS_CHECK);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -137,6 +141,8 @@ public class InventoryConfig extends ACheckConfig {
|
||||
return instantBowCheck;
|
||||
case INVENTORY_INSTANTEAT:
|
||||
return instantEatCheck;
|
||||
case INVENTORY_ITEMS:
|
||||
return itemsCheck;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package fr.neatmonster.nocheatplus.checks.inventory;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -15,6 +16,7 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.combined.Combined;
|
||||
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
|
||||
@ -143,6 +145,12 @@ public class InventoryListener implements Listener {
|
||||
*/
|
||||
if (event.getWhoClicked() instanceof Player) {
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
|
||||
// Illegal enchantments hotfixes
|
||||
if (Items.checkIllegalEnchantments(player, event.getCurrentItem())) event.setCancelled(true);
|
||||
if (Items.checkIllegalEnchantments(player, event.getCursor())) event.setCancelled(true);
|
||||
|
||||
// Fast inventory manipulation check.
|
||||
if (fastClick.isEnabled(player)){
|
||||
if (fastClick.check(player))
|
||||
// The check requested the event to be cancelled.
|
||||
@ -171,6 +179,16 @@ public class InventoryListener implements Listener {
|
||||
* |_| |_|\__,_|\__, |\___|_| |____/|_| \___/| .__/
|
||||
* |___/ |_|
|
||||
*/
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Illegal enchantments hotfix check.
|
||||
final Item item = event.getItemDrop();
|
||||
if (item != null){
|
||||
// No cancel here.
|
||||
Items.checkIllegalEnchantments(player, item.getItemStack());
|
||||
}
|
||||
|
||||
// If the player died, all his items are dropped so ignore him.
|
||||
if (event.getPlayer().isDead())
|
||||
return;
|
||||
@ -210,8 +228,9 @@ public class InventoryListener implements Listener {
|
||||
// Only interested in right-clicks while holding an item.
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
final InventoryData data = InventoryData.getData(event.getPlayer());
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
boolean resetAll = false;
|
||||
|
||||
@ -231,6 +250,9 @@ public class InventoryListener implements Listener {
|
||||
data.instantEatInteract = (data.instantEatInteract > 0 && now - data.instantEatInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantEatInteract) : System.currentTimeMillis();
|
||||
data.instantBowInteract = 0;
|
||||
} else resetAll = true;
|
||||
|
||||
// Illegal enchantments hotfix check.
|
||||
if (Items.checkIllegalEnchantments(player, item)) event.setCancelled(true);
|
||||
}
|
||||
else resetAll = true;
|
||||
|
||||
@ -249,5 +271,10 @@ public class InventoryListener implements Listener {
|
||||
data.instantBowInteract = 0;
|
||||
data.instantEatInteract = 0;
|
||||
data.instantEatFood = null;
|
||||
|
||||
// Illegal enchantments hotfix check.
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
Items.checkIllegalEnchantments(player, inv.getItem(event.getNewSlot()));
|
||||
Items.checkIllegalEnchantments(player, inv.getItem(event.getPreviousSlot()));
|
||||
}
|
||||
}
|
||||
|
44
src/fr/neatmonster/nocheatplus/checks/inventory/Items.java
Normal file
44
src/fr/neatmonster/nocheatplus/checks/inventory/Items.java
Normal file
@ -0,0 +1,44 @@
|
||||
package fr.neatmonster.nocheatplus.checks.inventory;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
public class Items extends Check{
|
||||
|
||||
private static Items instance = null;
|
||||
|
||||
public Items() {
|
||||
super(CheckType.INVENTORY_ITEMS);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param stack
|
||||
* @return True if the check is failed.
|
||||
*/
|
||||
public static final boolean checkIllegalEnchantments(final Player player, final ItemStack stack){
|
||||
if (stack == null) return false;
|
||||
final Material type = stack.getType();
|
||||
// Fastest checks first.
|
||||
// TODO: Make stuff configurable.
|
||||
if (type == Material.WRITTEN_BOOK){
|
||||
if (!stack.getEnchantments().isEmpty() && instance.isEnabled(player)){
|
||||
// TODO: differentiate sub checks maybe or add extra permissions, later.
|
||||
for (final Enchantment ench : stack.getEnchantments().keySet()){
|
||||
stack.removeEnchantment(ench);
|
||||
}
|
||||
// TODO: actions and similar.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -423,6 +423,9 @@ public abstract class ConfPaths {
|
||||
private static final String INVENTORY_INSTANTEAT = INVENTORY + "instanteat.";
|
||||
public static final String INVENTORY_INSTANTEAT_CHECK = INVENTORY_INSTANTEAT + "active";
|
||||
public static final String INVENTORY_INSTANTEAT_ACTIONS = INVENTORY_INSTANTEAT + "actions";
|
||||
|
||||
private static final String INVENTORY_ITEMS = INVENTORY + ".items";
|
||||
public static final String INVENTORY_ITEMS_CHECK = INVENTORY_ITEMS + ".active";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
|
@ -154,6 +154,7 @@ public class Permissions {
|
||||
public static final String INVENTORY_FASTCLICK = INVENTORY + ".fastclick";
|
||||
public static final String INVENTORY_INSTANTBOW = INVENTORY + ".instantbow";
|
||||
public static final String INVENTORY_INSTANTEAT = INVENTORY + ".instanteat";
|
||||
public static final String INVENTORY_ITEMS = INVENTORY + ".items";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
|
Loading…
Reference in New Issue
Block a user