Use a more fork-proof approach to enable Paper block place patch (#2561)
This commit is contained in:
parent
26719169ee
commit
8e1da82793
|
@ -19,6 +19,7 @@ package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -43,18 +44,20 @@ public class PaperPatch extends ViaBukkitListener {
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlace(BlockPlaceEvent e) {
|
public void onPlace(BlockPlaceEvent e) {
|
||||||
if (isOnPipe(e.getPlayer())) {
|
if (isOnPipe(e.getPlayer())) {
|
||||||
Location location = e.getPlayer().getLocation();
|
|
||||||
Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
|
||||||
Material block = e.getBlockPlaced().getType();
|
Material block = e.getBlockPlaced().getType();
|
||||||
if (isPlacable(block)) {
|
if (isPlacable(block)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (location.getBlock().equals(e.getBlock())) {
|
Location location = e.getPlayer().getLocation();
|
||||||
|
Block locationBlock = location.getBlock();
|
||||||
|
|
||||||
|
if (locationBlock.equals(e.getBlock())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
|
if (locationBlock.getRelative(BlockFace.UP).equals(e.getBlock())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
|
Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
||||||
// Within radius of block
|
// Within radius of block
|
||||||
if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) {
|
if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) {
|
||||||
// Are they on the edge / shifting ish
|
// Are they on the edge / shifting ish
|
||||||
|
|
|
@ -117,11 +117,20 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|
if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion() && !Boolean.getBoolean("com.viaversion.ignorePaperBlockPlacePatch")) {
|
||||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|
boolean paper = true;
|
||||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
|
try {
|
||||||
&& serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) {
|
Class.forName("org.github.paperspigot.PaperSpigotConfig"); // Paper 1.8 ?
|
||||||
storeListener(new PaperPatch(plugin)).register();
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
try {
|
||||||
|
Class.forName("com.destroystokyo.paper.PaperConfig"); // Paper 1.9+ ?
|
||||||
|
} catch (ClassNotFoundException alsoIgnored) {
|
||||||
|
paper = false; // Definitely not Paper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (paper) {
|
||||||
|
storeListener(new PaperPatch(plugin)).register();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Providers */
|
/* Providers */
|
||||||
|
|
Loading…
Reference in New Issue