Skip to content

Commit

Permalink
Fix issues with respawning ender dragons (block place reqach+distance).
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Mar 26, 2016
1 parent c138d97 commit a00b6a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Expand Up @@ -443,4 +443,18 @@ public static Object newInstance(Constructor<?> constructor, Object... arguments
return null;
}

/**
* Fail-safe class getting.
* @param fullName
* @return
*/
public static Class<?> getClass(String fullName) {
try {
return Class.forName(fullName);
} catch (ClassNotFoundException e) {
// Ignore.
}
return null;
}

}
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
Expand All @@ -28,6 +29,7 @@
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.stats.Counters;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;

/**
* Central location to listen to events that are relevant for the block place checks.
Expand Down Expand Up @@ -85,6 +87,9 @@ public static int getBlockPlaceHash(final Block block, final Material mat){
private final int idBoatsAnywhere = counters.registerKey("boatsanywhere");
private final int idEnderPearl = counters.registerKey("throwenderpearl");

private final Class<?> blockMultiPlaceEvent = ReflectionUtil.getClass("org.bukkit.event.block.BlockMultiPlaceEvent");
private final boolean hasReplacedState = ReflectionUtil.getMethodNoArgs(BlockPlaceEvent.class, "getReplacedState", BlockState.class) != null;

public BlockPlaceListener(){
super(CheckType.BLOCKPLACE);
}
Expand All @@ -110,12 +115,28 @@ public void onBlockPlace(final BlockPlaceEvent event) {
// TODO: Revise material use (not block.get... ?)
//final Material mat = block.getType();
final Player player = event.getPlayer();
final Material placedMat = player.getItemInHand().getType(); // Safety first.
final Material placedMat = hasReplacedState ? event.getBlockPlaced().getType() : player.getItemInHand().getType(); // Safety first.
boolean cancelled = false;

final BlockPlaceData data = BlockPlaceData.getData(player);
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);

final boolean shouldSkipSome;
if (blockMultiPlaceEvent != null && event.getClass() == blockMultiPlaceEvent) {
if (placedMat == Material.BEDROCK || placedMat == Material.END_CRYSTAL) {
shouldSkipSome = true;
}
else {
if (data.debug) {
debug(player, "Block place " + event.getClass().getName() + " " + placedMat);
}
shouldSkipSome = false;
}
}
else {
shouldSkipSome = false;
}

if (placedMat == Material.SIGN){
// Might move to MONITOR priority.
data.autoSignPlacedTime = System.currentTimeMillis();
Expand All @@ -140,12 +161,12 @@ public void onBlockPlace(final BlockPlaceEvent event) {
}

// Reach check (distance).
if (!cancelled && reach.isEnabled(player) && reach.check(player, block, data, cc)) {
if (!cancelled && !shouldSkipSome && reach.isEnabled(player) && reach.check(player, block, data, cc)) {
cancelled = true;
}

// Direction check.
if (!cancelled && direction.isEnabled(player) && direction.check(player, block, blockAgainst, data, cc)) {
if (!cancelled && !shouldSkipSome && direction.isEnabled(player) && direction.check(player, block, blockAgainst, data, cc)) {
cancelled = true;
}

Expand Down

0 comments on commit a00b6a5

Please sign in to comment.