Fix fire extinguishing (only on Spigot servers)

Fixes #274
This commit is contained in:
KennyTV 2020-10-21 18:57:54 +02:00
parent b340c7246b
commit 25404d6c92
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 45 additions and 5 deletions

View File

@ -11,6 +11,7 @@
package nl.matsv.viabackwards; package nl.matsv.viabackwards;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform; import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.listener.FireExtinguishListener;
import nl.matsv.viabackwards.listener.LecternInteractListener; import nl.matsv.viabackwards.listener.LecternInteractListener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -27,8 +28,11 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
} }
private void onServerLoaded() { private void onServerLoaded() {
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_14.getId()) { BukkitViaLoader loader = (BukkitViaLoader) Via.getManager().getLoader();
BukkitViaLoader loader = (BukkitViaLoader) Via.getManager().getLoader(); if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_16.getVersion()) {
loader.storeListener(new FireExtinguishListener(this)).register();
}
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_14.getVersion()) {
loader.storeListener(new LecternInteractListener(this)).register(); loader.storeListener(new LecternInteractListener(this)).register();
} }
} }

View File

@ -0,0 +1,36 @@
package nl.matsv.viabackwards.listener;
import nl.matsv.viabackwards.BukkitPlugin;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
public class FireExtinguishListener extends ViaBukkitListener {
public FireExtinguishListener(BukkitPlugin plugin) {
super(plugin, Protocol1_15_2To1_16.class);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLecternInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
Block block = event.getClickedBlock();
if (block == null) return;
Player player = event.getPlayer();
if (!isOnPipe(player)) return;
Block relative = block.getRelative(event.getBlockFace());
if (relative.getType() == Material.FIRE) {
event.setCancelled(true);
relative.setType(Material.AIR);
}
}
}

View File

@ -21,12 +21,12 @@ public class LecternInteractListener extends ViaBukkitListener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLecternInteract(PlayerInteractEvent event) { public void onLecternInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (!isOnPipe(player)) return;
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (block == null || block.getType() != Material.LECTERN) return; if (block == null || block.getType() != Material.LECTERN) return;
Player player = event.getPlayer();
if (!isOnPipe(player)) return;
Lectern lectern = (Lectern) block.getState(); Lectern lectern = (Lectern) block.getState();
ItemStack book = lectern.getInventory().getItem(0); ItemStack book = lectern.getInventory().getItem(0);
if (book == null) return; if (book == null) return;