mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-28 10:21:22 +01:00
Quick fix for item eggs on entities, allow item frames.
This commit is contained in:
parent
aa126bf731
commit
7dc6a5d482
@ -3,8 +3,11 @@ package fr.neatmonster.nocheatplus.checks.inventory;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ComplexEntityPart;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -53,21 +56,21 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
|
||||
/** The instant eat check. */
|
||||
private final InstantEat instantEat = addCheck(new InstantEat());
|
||||
|
||||
|
||||
protected final Items items = addCheck(new Items());
|
||||
|
||||
|
||||
private final Open open = addCheck(new Open());
|
||||
|
||||
|
||||
/** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */
|
||||
private final Location useLoc = new Location(null, 0, 0, 0);
|
||||
|
||||
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
|
||||
private final Location useLoc = new Location(null, 0, 0, 0);
|
||||
|
||||
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
|
||||
private final int idCancelDead = counters.registerKey("canceldead");
|
||||
private final int idIllegalItem = counters.registerKey("illegalitem");
|
||||
private final int idEggOnEntity = counters.registerKey("eggonentity");
|
||||
|
||||
|
||||
public InventoryListener(){
|
||||
super(CheckType.INVENTORY);
|
||||
super(CheckType.INVENTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,15 +93,15 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
event.setCancelled(true);
|
||||
}
|
||||
// Still check instantBow, whatever yawrate says.
|
||||
if (instantBow.check(player, event.getForce(), now)){
|
||||
// The check requested the event to be cancelled.
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (Improbable.check(player, 0.6f, now, "inventory.instantbow")){
|
||||
if (instantBow.check(player, event.getForce(), now)){
|
||||
// The check requested the event to be cancelled.
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (Improbable.check(player, 0.6f, now, "inventory.instantbow")){
|
||||
// Combined fighting speed (Else if: Matter of taste, preventing extreme cascading and actions spam).
|
||||
event.setCancelled(true);
|
||||
}
|
||||
useLoc.setWorld(null);
|
||||
}
|
||||
useLoc.setWorld(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,12 +120,12 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
if (event.getEntity() instanceof Player) {
|
||||
final Player player = (Player) event.getEntity();
|
||||
if (instantEat.isEnabled(player) && instantEat.check(player, event.getFoodLevel())){
|
||||
event.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
|
||||
// Eat after death.
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idCancelDead, 1);
|
||||
// Eat after death.
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idCancelDead, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,39 +140,39 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
if (event.getWhoClicked() instanceof Player) {
|
||||
final long now = System.currentTimeMillis();
|
||||
final HumanEntity entity = event.getWhoClicked();
|
||||
if (!(entity instanceof Player)){
|
||||
return;
|
||||
}
|
||||
final long now = System.currentTimeMillis();
|
||||
final HumanEntity entity = event.getWhoClicked();
|
||||
if (!(entity instanceof Player)){
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) entity;
|
||||
final int slot = event.getSlot();
|
||||
if (slot == InventoryView.OUTSIDE || slot < 0){
|
||||
InventoryData.getData(player).lastClickTime = now;
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack cursor = event.getCursor();
|
||||
final ItemStack clicked = event.getCurrentItem();
|
||||
if (slot == InventoryView.OUTSIDE || slot < 0){
|
||||
InventoryData.getData(player).lastClickTime = now;
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack cursor = event.getCursor();
|
||||
final ItemStack clicked = event.getCurrentItem();
|
||||
boolean cancel = false;
|
||||
// Illegal enchantment checks.
|
||||
try{
|
||||
if (!cancel && Items.checkIllegalEnchantments(player, clicked)) {
|
||||
cancel = true;
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
cancel = true;
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
}
|
||||
}
|
||||
catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB)
|
||||
try{
|
||||
if (!cancel && Items.checkIllegalEnchantments(player, cursor)) {
|
||||
cancel = true;
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
cancel = true;
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
}
|
||||
}
|
||||
catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB)
|
||||
|
||||
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
|
||||
// Fast inventory manipulation check.
|
||||
if (fastClick.isEnabled(player)){
|
||||
final InventoryConfig cc = InventoryConfig.getConfig(player);
|
||||
@ -184,7 +187,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
}
|
||||
data.lastClickTime = now;
|
||||
if (cancel) {
|
||||
event.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,27 +201,27 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
@EventHandler(
|
||||
ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
protected void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
|
||||
|
||||
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 their items are dropped so ignore them.
|
||||
if (event.getPlayer().isDead())
|
||||
return;
|
||||
|
||||
if (drop.isEnabled(event.getPlayer())){
|
||||
if (drop.check(event.getPlayer())){
|
||||
// TODO: Is the following command still correct? If so, adapt actions.
|
||||
if (drop.check(event.getPlayer())){
|
||||
// TODO: Is the following command still correct? If so, adapt actions.
|
||||
// Cancelling drop events is not save (in certain circumstances items will disappear completely). So don't
|
||||
// do it and kick players instead by default.
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -235,12 +238,12 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
// Only interested in right-clicks while holding an item.
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
|
||||
boolean resetAll = false;
|
||||
|
||||
|
||||
if (event.hasItem()){
|
||||
final ItemStack item = event.getItem();
|
||||
final Material type = item.getType();
|
||||
@ -257,17 +260,17 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
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);
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idIllegalItem, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resetAll = true;
|
||||
resetAll = true;
|
||||
}
|
||||
|
||||
|
||||
if (resetAll){
|
||||
// Nothing that we are interested in, reset data.
|
||||
data.instantBowInteract = 0;
|
||||
@ -275,27 +278,31 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
data.instantEatFood = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
|
||||
public final void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
return;
|
||||
}
|
||||
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
|
||||
// No zombies.
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idCancelDead, 1);
|
||||
return;
|
||||
}
|
||||
final ItemStack stack = player.getItemInHand();
|
||||
if (stack != null && stack.getType() == Material.MONSTER_EGG && items.isEnabled(player)){
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idEggOnEntity, 1);
|
||||
return;
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
return;
|
||||
}
|
||||
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
|
||||
// No zombies.
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idCancelDead, 1);
|
||||
return;
|
||||
}
|
||||
// TODO: Activate mob-egg check only for specific server versions.
|
||||
final ItemStack stack = player.getItemInHand();
|
||||
Entity entity = event.getRightClicked();
|
||||
if (stack != null && stack.getType() == Material.MONSTER_EGG
|
||||
&& (entity == null || entity instanceof LivingEntity || entity instanceof ComplexEntityPart)
|
||||
&& items.isEnabled(player)){
|
||||
event.setCancelled(true);
|
||||
counters.addPrimaryThread(idEggOnEntity, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onItemHeldChange(final PlayerItemHeldEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
@ -303,68 +310,68 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event){
|
||||
open.check(event.getPlayer());
|
||||
open.check(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerPortal(final PlayerPortalEvent event){
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(event.getPlayer());
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEntityPortal(final EntityPortalEnterEvent event){
|
||||
final Player player = InventoryUtil.getPlayerPassengerRecursively(event.getEntity());
|
||||
if (player != null) {
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(player);
|
||||
}
|
||||
final Player player = InventoryUtil.getPlayerPassengerRecursively(event.getEntity());
|
||||
if (player != null) {
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event){
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(event.getPlayer());
|
||||
// Note: ignore cancelother setting.
|
||||
open.check(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerJoins(Player player) {
|
||||
// Ignore
|
||||
}
|
||||
@Override
|
||||
public void playerJoins(Player player) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLeaves(Player player) {
|
||||
open.check(player);
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.MONITOR)
|
||||
// public void onVehicleDestroy(final VehicleDestroyEvent event) {
|
||||
// final Entity entity = event.getVehicle();
|
||||
// if (entity instanceof InventoryHolder) { // Fail on 1.4 ?
|
||||
// checkInventoryHolder((InventoryHolder) entity);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EventHandler(priority = EventPriority.MONITOR)
|
||||
// public void onBlockBreak(final BlockBreakEvent event) {
|
||||
// final Block block = event.getBlock();
|
||||
// if (block == null) {
|
||||
// return;
|
||||
// }
|
||||
// // TODO: + explosions !? + entity change block + ...
|
||||
// }
|
||||
//
|
||||
// private void checkInventoryHolder(InventoryHolder entity) {
|
||||
// // TODO Auto-generated method stub
|
||||
//
|
||||
// }
|
||||
@Override
|
||||
public void playerLeaves(Player player) {
|
||||
open.check(player);
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.MONITOR)
|
||||
// public void onVehicleDestroy(final VehicleDestroyEvent event) {
|
||||
// final Entity entity = event.getVehicle();
|
||||
// if (entity instanceof InventoryHolder) { // Fail on 1.4 ?
|
||||
// checkInventoryHolder((InventoryHolder) entity);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EventHandler(priority = EventPriority.MONITOR)
|
||||
// public void onBlockBreak(final BlockBreakEvent event) {
|
||||
// final Block block = event.getBlock();
|
||||
// if (block == null) {
|
||||
// return;
|
||||
// }
|
||||
// // TODO: + explosions !? + entity change block + ...
|
||||
// }
|
||||
//
|
||||
// private void checkInventoryHolder(InventoryHolder entity) {
|
||||
// // TODO Auto-generated method stub
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user