From 121bc9de6c3143de80a5670916066a8e54c1b230 Mon Sep 17 00:00:00 2001 From: fillefilip8 Date: Wed, 2 Mar 2016 11:32:57 +0100 Subject: [PATCH] * Modifyed that fancy message when 1.9 clients try to enter a Minecart or a Boat :) * Renamed the listener to something better. --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 4 +- .../listeners/MinecartListener.java | 25 ------------ .../ViaVersion/listeners/VehicleListener.java | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/us/myles/ViaVersion/listeners/MinecartListener.java create mode 100644 src/main/java/us/myles/ViaVersion/listeners/VehicleListener.java diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 83e620424..f9e2b5fb0 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -16,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin; import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersionAPI; import us.myles.ViaVersion.handlers.ViaVersionInitializer; -import us.myles.ViaVersion.listeners.MinecartListener; +import us.myles.ViaVersion.listeners.VehicleListener; import us.myles.ViaVersion.util.ReflectionUtil; import java.util.Collections; @@ -53,7 +53,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { setPorted(e.getPlayer().getUniqueId(), false); } }, this); - Bukkit.getPluginManager().registerEvents(new MinecartListener(),this); + Bukkit.getPluginManager().registerEvents(new VehicleListener(),this); } public void injectPacketHandler() throws Exception { diff --git a/src/main/java/us/myles/ViaVersion/listeners/MinecartListener.java b/src/main/java/us/myles/ViaVersion/listeners/MinecartListener.java deleted file mode 100644 index 3f95ca6fc..000000000 --- a/src/main/java/us/myles/ViaVersion/listeners/MinecartListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package us.myles.ViaVersion.listeners; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import us.myles.ViaVersion.api.ViaVersion; - -/** - * Created by fillefilip8 on 2016-03-02. - */ -public class MinecartListener implements Listener { - @EventHandler - public void onMinecartEnter(VehicleEnterEvent e){ - if(e.getEntered() instanceof Player) { - Player player = (Player) e.getEntered(); - if(ViaVersion.getInstance().isPorted(player)){ - e.setCancelled(true); - e.getEntered().sendMessage(ChatColor.RED + "Minecarts are not supported. Due to changes on minecarts in 1.9"); - } - } - - } -} diff --git a/src/main/java/us/myles/ViaVersion/listeners/VehicleListener.java b/src/main/java/us/myles/ViaVersion/listeners/VehicleListener.java new file mode 100644 index 000000000..537dde557 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/listeners/VehicleListener.java @@ -0,0 +1,39 @@ +package us.myles.ViaVersion.listeners; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Boat; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; +import us.myles.ViaVersion.api.ViaVersion; + +/** + * Created by fillefilip8 on 2016-03-02. + */ +public class VehicleListener implements Listener { + @EventHandler + public void onVehicleEnter(VehicleEnterEvent e){ + if(e.getEntered() instanceof Player) { + Player player = (Player) e.getEntered(); + if(ViaVersion.getInstance().isPorted(player)){ + + if(e.getVehicle() instanceof Minecart){ + e.getEntered().sendMessage(ChatColor.RED + "Minecarts are not supported. Due to changes on minecarts in 1.9"); + e.setCancelled(true); + }else if(e.getVehicle() instanceof Boat){ + e.getEntered().sendMessage(ChatColor.RED + "Boats are not supported. Due to changes on boats in 1.9"); + e.setCancelled(true); + } + + + } + } + + } + +}