exploit fix

This commit is contained in:
nossr50 2020-12-09 15:34:32 -08:00
parent 958fb6f044
commit 7f213ee305
2 changed files with 20 additions and 83 deletions

View File

@ -158,6 +158,7 @@ public class BlockListener implements Listener {
/**
* Monitor blocks formed by entities (snowmen)
* Does not seem to monitor stuff like a falling block creating a new block
*
* @param event The event to watch
*/
@ -176,6 +177,9 @@ public class BlockListener implements Listener {
}
}
/*
* Does not monitor stuff like a falling block replacing a liquid
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFormEvent(BlockFormEvent event)
{
@ -183,12 +187,12 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return;
if(ExperienceConfig.getInstance().preventStoneLavaFarming())
{
if(event.getNewState().getType() != Material.OBSIDIAN
&& ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, event.getNewState().getBlockData()))
{
mcMMO.getPlaceStore().setTrue(event.getNewState());
BlockState newState = event.getNewState();
if(ExperienceConfig.getInstance().preventStoneLavaFarming()) {
if(newState.getType() != Material.OBSIDIAN
&& ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
mcMMO.getPlaceStore().setTrue(newState);
}
}
}
@ -244,17 +248,6 @@ public class BlockListener implements Listener {
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
mcMMO.getPlaceStore().setTrue(blockState);
}
// /* WORLD BLACKLIST CHECK */
// if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) {
// return;
// }
//
// Player player = event.getPlayer();
//
// if (!UserManager.hasPlayerDataKey(player)) {
// return;
// }
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -265,11 +258,6 @@ public class BlockListener implements Listener {
return;
BlockState blockState = event.getBlock().getState();
// if (!BlockUtils.shouldBeWatched(blockState)) {
// return;
// }
mcMMO.getPlaceStore().setFalse(blockState);
}

View File

@ -196,18 +196,24 @@ public class EntityListener implements Listener {
return;
Block block = event.getBlock();
Entity entity = event.getEntity();
Material notYetReplacedType = block.getState().getType(); //because its from getState() this is the block that hasn't been changed yet, which is likely air/lava/water etc
// When the event is fired for the falling block that changes back to a
// normal block
// event.getBlock().getType() returns AIR
if (!BlockUtils.shouldBeWatched(block.getState())
&& block.getState().getType() != Material.WATER
&& block.getType() != Material.AIR) {
&& notYetReplacedType != Material.WATER && notYetReplacedType != Material.LAVA
&& block.getType() != Material.AIR && block.getType() != Material.CAVE_AIR) {
return;
}
//I could just have it mark all blocks after this but it would potentially cause some really edge case consistency issues that no one would notice
Entity entity = event.getEntity();
/*
* This mess of code tries to avoid marking the moved block as true in our place store
* It's a headache to read but it works, I'm tempted to just remove it
*/
if (entity instanceof FallingBlock || entity instanceof Enderman) {
boolean isTracked = entity.hasMetadata(mcMMO.travelingBlock);
@ -228,63 +234,6 @@ public class EntityListener implements Listener {
}
}
// /**
// * Monitor EntityChangeBlock events.
// *
// * @param event
// * The event to watch
// */
// @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
// public void onEntityChangeBlock(EntityChangeBlockEvent event) {
// /* WORLD BLACKLIST CHECK */
// if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
// return;
//
// Block block = event.getBlock();
//
// // When the event is fired for the falling block that changes back to a
// // normal block
// // event.getBlock().getType() returns AIR
// if (!BlockUtils.shouldBeWatched(block.getState())
// && block.getState().getType() != Material.WATER
// && block.getType() != Material.AIR) {
// return;
// }
//
// Entity entity = event.getEntity();
//
// if (entity instanceof FallingBlock || entity instanceof Enderman) {
// trackMovingBlocks(block, entity); //ignore the IDE warning
// //Apparently redstone ore will throw these events
// } else if ((block.getType() != Material.REDSTONE_ORE)) {
// if (mcMMO.getPlaceStore().isTrue(block)) {
// mcMMO.getPlaceStore().setFalse(block);
// }
// }
// }
// /**
// * This is a complex hack to track blocks for this event
// * This event is called when a block starts its movement, or ends its movement
// * It can start the movement through physics (falling blocks) or through being picked up (endermen)
// * Since this event can be cancelled, its even weirder to track this stuff
// * @param block this will either be the block that was originally picked up, or the block in its final destination
// * @param movementSourceEntity this will either be an Endermen or a Falling Block
// */
// private void trackMovingBlocks(@NotNull Block block, @NotNull Entity movementSourceEntity) {
//
// //A block that has reached its destination, either being placed by endermen or having finished its fall
// if(movementSourceEntity.hasMetadata(mcMMO.travelingBlock)) {
// mcMMO.getPlaceStore().setTrue(block);
// movementSourceEntity.removeMetadata(mcMMO.travelingBlock, pluginRef);
// } else {
// //A block that is starting movement (from either Endermen or Falling/Physics)
// if(mcMMO.getPlaceStore().isTrue(block)) {
// mcMMO.getPlaceStore().setFalse(block);
// movementSourceEntity.setMetadata(mcMMO.blockMetadataKey, mcMMO.metadataValue);
// }
// }
// }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) {