Switched most event listeners to kotlin
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.willfp.eco.spigot.arrows;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrowDataListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
public ArrowDataListener(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onLaunch(final ProjectileLaunchEvent event) {
|
||||
if (!(event.getEntity() instanceof Arrow arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(arrow.getShooter() instanceof LivingEntity entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.getEquipment() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = entity.getEquipment().getItemInMainHand();
|
||||
|
||||
if (item.getType().equals(Material.AIR) || !item.hasItemMeta() || item.getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
arrow.setMetadata("shot-from", this.getPlugin().getMetadataValueFactory().create(item));
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.AutoCraftProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class PacketAutoRecipe extends AbstractPacketAdapter {
|
||||
public PacketAutoRecipe(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.AUTO_RECIPE, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
if (!EcoPlugin.getPluginNames().contains(packet.getMinecraftKeys().getValues().get(0).getFullKey().split(":")[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.getMinecraftKeys().getValues().get(0).getFullKey().split(":")[1].contains("displayed")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.getPlugin().getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PacketContainer newAutoRecipe = new PacketContainer(PacketType.Play.Server.AUTO_RECIPE);
|
||||
newAutoRecipe.getMinecraftKeys().write(0, packet.getMinecraftKeys().read(0));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.ChatComponentProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketChat extends AbstractPacketAdapter {
|
||||
public PacketChat(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
for (int i = 0; i < packet.getChatComponents().size(); i++) {
|
||||
WrappedChatComponent component = packet.getChatComponents().read(i);
|
||||
if (component == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (component.getHandle() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(this.getPlugin().getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle(), player));
|
||||
packet.getChatComponents().write(i, newComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.VillagerTradeProxy;
|
||||
import com.willfp.eco.util.NamespacedKeyUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
public PacketOpenWindowMerchant(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, ListenerPriority.MONITOR, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
List<MerchantRecipe> recipes = new ArrayList<>();
|
||||
|
||||
|
||||
/*
|
||||
This awful, awful bit of code exists to fix a bug that existed in EcoEnchants
|
||||
for too many versions.
|
||||
*/
|
||||
if (this.getPlugin().getConfigYml().getBool("villager-display-fix")) {
|
||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||
ItemStack result = recipe.getResult();
|
||||
ItemMeta meta = result.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
|
||||
meta.getPersistentDataContainer().remove(NamespacedKeyUtils.create("ecoenchants", "ecoenchantlore-skip"));
|
||||
result.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||
MerchantRecipe newRecipe = this.getPlugin().getProxy(VillagerTradeProxy.class).displayTrade(recipe, player);
|
||||
recipes.add(newRecipe);
|
||||
}
|
||||
|
||||
packet.getMerchantRecipeLists().write(0, recipes);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
|
||||
public PacketSetCreativeSlot(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
packet.getItemModifier().modify(0, Display::revert);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetSlot extends AbstractPacketAdapter {
|
||||
public PacketSetSlot(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.SET_SLOT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
packet.getItemModifier().modify(0, item -> Display.display(item, player));
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.eco.spigot.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketWindowItems extends AbstractPacketAdapter {
|
||||
public PacketWindowItems(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.WINDOW_ITEMS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
packet.getItemListModifier().modify(0, itemStacks -> {
|
||||
if (itemStacks == null) {
|
||||
return null;
|
||||
}
|
||||
itemStacks.forEach(item -> Display.display(item, player));
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class EntityDeathByEntityBuilder {
|
||||
@Getter
|
||||
@Setter
|
||||
private LivingEntity victim = null;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Entity damager;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private EntityDeathEvent deathEvent;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private List<ItemStack> drops;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int xp = 0;
|
||||
|
||||
public void push() {
|
||||
Validate.notNull(victim);
|
||||
Validate.notNull(damager);
|
||||
Validate.notNull(drops);
|
||||
Validate.notNull(deathEvent);
|
||||
|
||||
EntityDeathByEntityEvent event = new EntityDeathByEntityEvent(victim, damager, drops, xp, deathEvent);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class EntityDeathByEntityListeners extends PluginDependent<EcoPlugin> implements Listener {
|
||||
private final Set<EntityDeathByEntityBuilder> events = new HashSet<>();
|
||||
|
||||
public EntityDeathByEntityListeners(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (victim.getHealth() > event.getFinalDamage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDeathByEntityBuilder builtEvent = new EntityDeathByEntityBuilder();
|
||||
builtEvent.setVictim(victim);
|
||||
builtEvent.setDamager(event.getDamager());
|
||||
events.add(builtEvent);
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> events.remove(builtEvent), 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(@NotNull final EntityDeathEvent event) {
|
||||
LivingEntity victim = event.getEntity();
|
||||
|
||||
List<ItemStack> drops = event.getDrops();
|
||||
int xp = event.getDroppedExp();
|
||||
|
||||
AtomicReference<EntityDeathByEntityBuilder> atomicBuiltEvent = new AtomicReference<>(null);
|
||||
EntityDeathByEntityBuilder builtEvent;
|
||||
|
||||
events.forEach(deathByEntityEvent -> {
|
||||
if (deathByEntityEvent.getVictim().equals(victim)) {
|
||||
atomicBuiltEvent.set(deathByEntityEvent);
|
||||
}
|
||||
});
|
||||
|
||||
if (atomicBuiltEvent.get() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
builtEvent = atomicBuiltEvent.get();
|
||||
events.remove(builtEvent);
|
||||
builtEvent.setDrops(drops);
|
||||
builtEvent.setXp(xp);
|
||||
builtEvent.setDeathEvent(event);
|
||||
|
||||
builtEvent.push();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.core.events.NaturalExpGainEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class NaturalExpGainBuilder {
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private PlayerExpChangeEvent event;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Location location;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private BuildReason reason;
|
||||
|
||||
NaturalExpGainBuilder(@NotNull final BuildReason reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public void push() {
|
||||
Validate.notNull(event);
|
||||
if (this.cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
NaturalExpGainEvent naturalExpGainEvent = new NaturalExpGainEvent(event);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(naturalExpGainEvent);
|
||||
}
|
||||
|
||||
public enum BuildReason {
|
||||
BOTTLE,
|
||||
PLAYER
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ExpBottleEvent;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class NaturalExpGainListeners implements Listener {
|
||||
private final Set<NaturalExpGainBuilder> events = new HashSet<>();
|
||||
|
||||
@EventHandler
|
||||
public void playerChange(@NotNull final PlayerExpChangeEvent event) {
|
||||
NaturalExpGainBuilder builder = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.PLAYER);
|
||||
builder.setEvent(event);
|
||||
|
||||
NaturalExpGainBuilder toRemove = null;
|
||||
for (NaturalExpGainBuilder searchBuilder : events) {
|
||||
if (!Objects.equals(searchBuilder.getLocation().getWorld(), event.getPlayer().getLocation().getWorld())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52) {
|
||||
toRemove = searchBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove != null) {
|
||||
events.remove(toRemove);
|
||||
return;
|
||||
}
|
||||
|
||||
builder.setEvent(event);
|
||||
builder.push();
|
||||
|
||||
events.remove(builder);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExpBottle(@NotNull final ExpBottleEvent event) {
|
||||
NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.BOTTLE);
|
||||
builtEvent.setLocation(event.getEntity().getLocation());
|
||||
|
||||
events.add(builtEvent);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.core.events.PlayerJumpEvent;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PlayerJumpListeners implements Listener {
|
||||
private static final Set<UUID> PREVIOUS_PLAYERS_ON_GROUND = new HashSet<>();
|
||||
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.00");
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onJump(@NotNull final PlayerMoveEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player.getVelocity().getY() > 0) {
|
||||
float jumpVelocity = 0.42f;
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F;
|
||||
}
|
||||
jumpVelocity = Float.parseFloat(FORMAT.format(jumpVelocity).replace(',', '.'));
|
||||
if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER
|
||||
&& PREVIOUS_PLAYERS_ON_GROUND.contains(player.getUniqueId())
|
||||
&& !player.isOnGround()
|
||||
&& Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerJumpEvent(event));
|
||||
}
|
||||
}
|
||||
if (player.isOnGround()) {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.add(player.getUniqueId());
|
||||
} else {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.willfp.eco.spigot.arrows
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Arrow
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent
|
||||
|
||||
class ArrowDataListener(
|
||||
plugin: EcoPlugin
|
||||
) : PluginDependent<EcoPlugin>(plugin), Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
fun onLaunch(event:ProjectileLaunchEvent) {
|
||||
val arrow = event.entity
|
||||
|
||||
if (arrow !is Arrow) {
|
||||
return
|
||||
}
|
||||
|
||||
if (arrow.shooter !is LivingEntity) {
|
||||
return
|
||||
}
|
||||
|
||||
val entity = arrow.shooter as LivingEntity
|
||||
|
||||
if (entity.equipment == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val item = entity.equipment!!.itemInMainHand
|
||||
|
||||
if (item.type == Material.AIR || !item.hasItemMeta() || item.itemMeta == null) {
|
||||
return
|
||||
}
|
||||
|
||||
arrow.setMetadata("shot-from", this.plugin.metadataValueFactory.create(item))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.ProtocolLibrary
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.proxy.AutoCraftProxy
|
||||
import org.bukkit.entity.Player
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
class PacketAutoRecipe(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.AUTO_RECIPE, false) {
|
||||
override fun onSend(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
if (!EcoPlugin.getPluginNames()
|
||||
.contains(packet.minecraftKeys.values[0].fullKey.split(":".toRegex()).toTypedArray()[0])
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (packet.minecraftKeys.values[0].fullKey.split(":".toRegex()).toTypedArray()[1].contains("displayed")) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
getPlugin().getProxy(AutoCraftProxy::class.java).modifyPacket(packet.handle)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
val newAutoRecipe = PacketContainer(PacketType.Play.Server.AUTO_RECIPE)
|
||||
newAutoRecipe.minecraftKeys.write(0, packet.minecraftKeys.read(0))
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe)
|
||||
} catch (e: InvocationTargetException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.ListenerPriority
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.proxy.ChatComponentProxy
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class PacketChat(plugin: EcoPlugin) :
|
||||
AbstractPacketAdapter(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true) {
|
||||
override fun onSend(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
for (i in 0 until packet.chatComponents.size()) {
|
||||
val component = packet.chatComponents.read(i) ?: continue
|
||||
if (component.handle == null) {
|
||||
return
|
||||
}
|
||||
val newComponent = WrappedChatComponent.fromHandle(
|
||||
getPlugin().getProxy(
|
||||
ChatComponentProxy::class.java
|
||||
).modifyComponent(component.handle, player)
|
||||
)
|
||||
packet.chatComponents.write(i, newComponent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.ListenerPriority
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.proxy.VillagerTradeProxy
|
||||
import com.willfp.eco.util.NamespacedKeyUtils
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
|
||||
class PacketOpenWindowMerchant(plugin: EcoPlugin) :
|
||||
AbstractPacketAdapter(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, ListenerPriority.MONITOR, true) {
|
||||
override fun onSend(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
val recipes: MutableList<MerchantRecipe> = ArrayList()
|
||||
|
||||
|
||||
/*
|
||||
This awful, awful bit of code exists to fix a bug that existed in EcoEnchants
|
||||
for too many versions.
|
||||
*/
|
||||
if (getPlugin().configYml.getBool("villager-display-fix")) {
|
||||
for (recipe in packet.merchantRecipeLists.read(0)) {
|
||||
val result = recipe.result
|
||||
val meta = result.itemMeta
|
||||
if (meta != null) {
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS)
|
||||
meta.persistentDataContainer.remove(NamespacedKeyUtils.create("ecoenchants", "ecoenchantlore-skip"))
|
||||
result.itemMeta = meta
|
||||
}
|
||||
}
|
||||
}
|
||||
for (recipe in packet.merchantRecipeLists.read(0)) {
|
||||
val newRecipe = getPlugin().getProxy(VillagerTradeProxy::class.java).displayTrade(
|
||||
recipe!!, player
|
||||
)
|
||||
recipes.add(newRecipe)
|
||||
}
|
||||
packet.merchantRecipeLists.write(0, recipes)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.display.Display
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class PacketSetCreativeSlot(plugin: EcoPlugin) :
|
||||
AbstractPacketAdapter(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false) {
|
||||
override fun onReceive(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
packet.itemModifier.modify(0) { itemStack: ItemStack? ->
|
||||
Display.revert(
|
||||
itemStack!!
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.display.Display
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class PacketSetSlot(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.SET_SLOT, false) {
|
||||
override fun onSend(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
packet.itemModifier.modify(0) { item: ItemStack? ->
|
||||
Display.display(
|
||||
item!!, player
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.spigot.display
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.display.Display
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Consumer
|
||||
|
||||
class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) {
|
||||
override fun onSend(
|
||||
packet: PacketContainer,
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
packet.itemListModifier.modify(0) { itemStacks: List<ItemStack>? ->
|
||||
if (itemStacks == null) {
|
||||
return@modify null
|
||||
}
|
||||
itemStacks.forEach(Consumer { item: ItemStack ->
|
||||
Display.display(
|
||||
item, player
|
||||
)
|
||||
})
|
||||
itemStacks
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.eco.spigot.eventlisteners
|
||||
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent
|
||||
import org.apache.commons.lang.Validate
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
internal class EntityDeathByEntityBuilder {
|
||||
var victim: LivingEntity? = null
|
||||
|
||||
var damager: Entity? = null
|
||||
|
||||
var deathEvent: EntityDeathEvent? = null
|
||||
|
||||
var drops: List<ItemStack>? = null
|
||||
|
||||
var xp = 0
|
||||
fun push() {
|
||||
|
||||
Validate.notNull(victim)
|
||||
Validate.notNull(damager)
|
||||
Validate.notNull(drops)
|
||||
Validate.notNull(deathEvent)
|
||||
val event = EntityDeathByEntityEvent(victim!!, damager!!, drops!!, xp, deathEvent!!)
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.willfp.eco.spigot.eventlisteners
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class EntityDeathByEntityListeners(
|
||||
plugin: EcoPlugin
|
||||
) : PluginDependent<EcoPlugin>(plugin), Listener {
|
||||
private val events = HashSet<EntityDeathByEntityBuilder>();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
fun onEntityDamage(event: EntityDamageByEntityEvent) {
|
||||
if ((event.entity !is LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
val victim = event.entity as LivingEntity
|
||||
|
||||
if (victim.health > event.finalDamage) {
|
||||
return;
|
||||
}
|
||||
|
||||
val builtEvent = EntityDeathByEntityBuilder()
|
||||
builtEvent.victim = victim
|
||||
builtEvent.damager = event.damager
|
||||
events.add(builtEvent)
|
||||
this.plugin.scheduler.runLater({
|
||||
events.remove(builtEvent)
|
||||
}, 1)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onEntityDeath(event: EntityDeathEvent) {
|
||||
val victim = event.entity
|
||||
val drops = event.drops
|
||||
val xp = event.droppedExp
|
||||
|
||||
val atomicBuiltEvent = AtomicReference<EntityDeathByEntityBuilder>(null)
|
||||
|
||||
for (builder in events) {
|
||||
if (builder.victim == victim) {
|
||||
atomicBuiltEvent.set(builder)
|
||||
}
|
||||
}
|
||||
|
||||
if (atomicBuiltEvent.get() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
val builtEvent = atomicBuiltEvent.get();
|
||||
events.remove(builtEvent);
|
||||
builtEvent.drops = drops
|
||||
builtEvent.xp = xp
|
||||
builtEvent.deathEvent = event
|
||||
|
||||
builtEvent.push();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.spigot.eventlisteners
|
||||
|
||||
import com.willfp.eco.core.events.NaturalExpGainEvent
|
||||
import org.apache.commons.lang.Validate
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent
|
||||
|
||||
internal class NaturalExpGainBuilder(var reason: BuildReason) {
|
||||
var cancelled = false
|
||||
var event: PlayerExpChangeEvent? = null
|
||||
var location: Location? = null
|
||||
|
||||
fun push() {
|
||||
Validate.notNull(event)
|
||||
if (cancelled) {
|
||||
return
|
||||
}
|
||||
val naturalExpGainEvent = NaturalExpGainEvent(event!!)
|
||||
Bukkit.getPluginManager().callEvent(naturalExpGainEvent)
|
||||
}
|
||||
|
||||
enum class BuildReason {
|
||||
BOTTLE, PLAYER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.willfp.eco.spigot.eventlisteners
|
||||
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.ExpBottleEvent
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent
|
||||
|
||||
class NaturalExpGainListeners : Listener {
|
||||
private val events: MutableSet<NaturalExpGainBuilder> = HashSet()
|
||||
|
||||
@EventHandler
|
||||
fun playerChange(event: PlayerExpChangeEvent) {
|
||||
val builder = NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.PLAYER)
|
||||
builder.event = event
|
||||
var toRemove: NaturalExpGainBuilder? = null
|
||||
for (searchBuilder in events) {
|
||||
if (searchBuilder.location!!.world != event.player.location.world) {
|
||||
continue
|
||||
}
|
||||
if (searchBuilder.reason == NaturalExpGainBuilder.BuildReason.BOTTLE && searchBuilder.location!!.distanceSquared(
|
||||
event.player.location
|
||||
) > 52
|
||||
) {
|
||||
toRemove = searchBuilder
|
||||
}
|
||||
}
|
||||
if (toRemove != null) {
|
||||
events.remove(toRemove)
|
||||
return
|
||||
}
|
||||
builder.event = event
|
||||
builder.push()
|
||||
events.remove(builder)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onExpBottle(event: ExpBottleEvent) {
|
||||
val builtEvent = NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.BOTTLE)
|
||||
builtEvent.location = event.entity.location
|
||||
events.add(builtEvent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.spigot.eventlisteners
|
||||
|
||||
import com.willfp.eco.core.events.PlayerJumpEvent
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.player.PlayerMoveEvent
|
||||
import org.bukkit.potion.PotionEffectType
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class PlayerJumpListeners : Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
fun onJump(event: PlayerMoveEvent) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return
|
||||
}
|
||||
val player = event.player
|
||||
if (player.velocity.y > 0) {
|
||||
var jumpVelocity = 0.42f
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
jumpVelocity += (player.getPotionEffect(PotionEffectType.JUMP)!!.amplifier.toFloat() + 1) * 0.1f
|
||||
}
|
||||
jumpVelocity = FORMAT.format(jumpVelocity.toDouble()).replace(',', '.').toFloat()
|
||||
if (event.player.location.block.type != Material.LADDER && PREVIOUS_PLAYERS_ON_GROUND.contains(player.uniqueId)
|
||||
&& !player.isOnGround
|
||||
&& java.lang.Float.compare(player.velocity.y.toFloat(), jumpVelocity) == 0
|
||||
) {
|
||||
Bukkit.getPluginManager().callEvent(PlayerJumpEvent(event))
|
||||
}
|
||||
}
|
||||
if (player.isOnGround) {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.add(player.uniqueId)
|
||||
} else {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.remove(player.uniqueId)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PREVIOUS_PLAYERS_ON_GROUND: MutableSet<UUID> = HashSet()
|
||||
private val FORMAT = DecimalFormat("0.00")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user