Switched most internals to kotlin
This commit is contained in:
@@ -99,7 +99,7 @@ Here's a list of some (not all) of the features of eco:
|
||||
- ArmorEquipEvent
|
||||
- EntityDeathByEntityEvent
|
||||
- NaturalExpGainEvent
|
||||
- Plugin extensions (Plugins for plugins)
|
||||
- Plugin extensions (com.willfp.eco.internal.Plugins for plugins)
|
||||
- GUI System
|
||||
- Integration system for external plugins
|
||||
- Anticheat support
|
||||
|
||||
@@ -4,5 +4,6 @@ version rootProject.version
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(":eco-api")
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.21'
|
||||
}
|
||||
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.items.CustomItem;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.internal.proxy.EcoProxyFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class EcoCleaner implements Cleaner {
|
||||
@Override
|
||||
public void clean(@NotNull final EcoPlugin plugin) {
|
||||
if (!plugin.getProxyPackage().equalsIgnoreCase("")) {
|
||||
EcoProxyFactory factory = (EcoProxyFactory) plugin.getProxyFactory();
|
||||
factory.clean();
|
||||
}
|
||||
|
||||
Plugins.LOADED_ECO_PLUGINS.remove(plugin.getName().toLowerCase());
|
||||
|
||||
for (CustomItem customItem : Items.getCustomItems()) {
|
||||
if (customItem.getKey().getNamespace().equalsIgnoreCase(plugin.getName().toLowerCase())) {
|
||||
Items.removeCustomItem(customItem.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getClass().getClassLoader() instanceof URLClassLoader urlClassLoader) {
|
||||
try {
|
||||
urlClassLoader.close();
|
||||
} catch (IOException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class Plugins {
|
||||
public static final Map<String, EcoPlugin> LOADED_ECO_PLUGINS = new HashMap<>();
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public final class DropManager {
|
||||
@Getter
|
||||
private DropQueueType type = DropQueueType.COLLATED;
|
||||
|
||||
@ConfigUpdater
|
||||
public static void update(@NotNull final EcoPlugin plugin) {
|
||||
type = plugin.getConfigYml().getBool("use-fast-collated-drops") ? DropQueueType.COLLATED : DropQueueType.STANDARD;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
public enum DropQueueType {
|
||||
STANDARD,
|
||||
COLLATED
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueueFactory;
|
||||
import com.willfp.eco.core.drops.InternalDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.EcoDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoDropQueueFactory implements DropQueueFactory {
|
||||
@Override
|
||||
public InternalDropQueue create(@NotNull final Player player) {
|
||||
return DropManager.getType() == DropQueueType.COLLATED ? new EcoFastCollatedDropQueue(player) : new EcoDropQueue(player);
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.core.drops.InternalDropQueue;
|
||||
import com.willfp.eco.util.TelekinesisUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EcoDropQueue implements InternalDropQueue {
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final List<ItemStack> items;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private int xp;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final Player player;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private Location loc;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private boolean hasTelekinesis = false;
|
||||
|
||||
public EcoDropQueue(@NotNull final Player player) {
|
||||
this.items = new ArrayList<>();
|
||||
this.xp = 0;
|
||||
this.player = player;
|
||||
this.loc = player.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalDropQueue addItem(@NotNull final ItemStack item) {
|
||||
this.items.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalDropQueue addItems(@NotNull final Collection<ItemStack> itemStacks) {
|
||||
this.items.addAll(itemStacks);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalDropQueue addXP(final int amount) {
|
||||
this.xp += amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalDropQueue setLocation(@NotNull final Location location) {
|
||||
this.loc = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalDropQueue forceTelekinesis() {
|
||||
this.hasTelekinesis = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push() {
|
||||
if (!hasTelekinesis) {
|
||||
hasTelekinesis = TelekinesisUtils.testPlayer(player);
|
||||
}
|
||||
|
||||
World world = loc.getWorld();
|
||||
assert world != null;
|
||||
loc = loc.add(0.5, 0.5, 0.5);
|
||||
|
||||
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
|
||||
if (items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasTelekinesis) {
|
||||
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
||||
for (ItemStack drop : leftover.values()) {
|
||||
world.dropItem(loc, drop).setVelocity(new Vector());
|
||||
}
|
||||
if (xp > 0) {
|
||||
PlayerExpChangeEvent event = new PlayerExpChangeEvent(player, xp);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
ExperienceOrb orb = (ExperienceOrb) world.spawnEntity(player.getLocation().add(0, 0.2, 0), EntityType.EXPERIENCE_ORB);
|
||||
orb.setVelocity(new Vector(0, 0, 0));
|
||||
orb.setExperience(event.getAmount());
|
||||
}
|
||||
} else {
|
||||
for (ItemStack drop : items) {
|
||||
world.dropItem(loc, drop).setVelocity(new Vector());
|
||||
}
|
||||
if (xp > 0) {
|
||||
ExperienceOrb orb = (ExperienceOrb) world.spawnEntity(loc, EntityType.EXPERIENCE_ORB);
|
||||
orb.setExperience(xp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EcoFastCollatedDropQueue extends EcoDropQueue {
|
||||
public static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
public EcoFastCollatedDropQueue(@NotNull final Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push() {
|
||||
CollatedDrops fetched = COLLATED_MAP.get(getPlayer());
|
||||
CollatedDrops collatedDrops = fetched == null ? new CollatedDrops(getItems(), getLoc(), getXp()) : fetched.addDrops(getItems()).setLocation(getLoc()).addXp(getXp());
|
||||
COLLATED_MAP.put(this.getPlayer(), collatedDrops);
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class CollatedDrops {
|
||||
@Getter
|
||||
private final List<ItemStack> drops;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
private Location location;
|
||||
|
||||
@Getter
|
||||
private int xp;
|
||||
|
||||
private CollatedDrops(@NotNull final List<ItemStack> drops,
|
||||
@NotNull final Location location,
|
||||
final int xp) {
|
||||
this.drops = drops;
|
||||
this.location = location;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
public CollatedDrops addDrops(@NotNull final List<ItemStack> toAdd) {
|
||||
drops.addAll(toAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CollatedDrops addXp(final int xp) {
|
||||
this.xp += xp;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.willfp.eco.internal.events;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.events.EventManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoEventManager extends PluginDependent<EcoPlugin> implements EventManager {
|
||||
@ApiStatus.Internal
|
||||
public EcoEventManager(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(@NotNull final Listener listener) {
|
||||
Bukkit.getPluginManager().registerEvents(listener, this.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterListener(@NotNull final Listener listener) {
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterAllListeners() {
|
||||
HandlerList.unregisterAll(this.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.factory.MetadataValueFactory;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoMetadataValueFactory extends PluginDependent<EcoPlugin> implements MetadataValueFactory {
|
||||
public EcoMetadataValueFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedMetadataValue create(@NotNull final Object value) {
|
||||
return new FixedMetadataValue(this.getPlugin(), value);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.factory.NamespacedKeyFactory;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoNamespacedKeyFactory extends PluginDependent<EcoPlugin> implements NamespacedKeyFactory {
|
||||
public EcoNamespacedKeyFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey create(@NotNull final String key) {
|
||||
return new NamespacedKey(this.getPlugin(), key);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.factory.RunnableFactory;
|
||||
import com.willfp.eco.core.scheduling.RunnableTask;
|
||||
import com.willfp.eco.internal.scheduling.EcoRunnableTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EcoRunnableFactory extends PluginDependent<EcoPlugin> implements RunnableFactory {
|
||||
public EcoRunnableFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunnableTask create(@NotNull final Consumer<RunnableTask> consumer) {
|
||||
return new EcoRunnableTask(this.getPlugin()) {
|
||||
@Override
|
||||
public void run() {
|
||||
consumer.accept(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.willfp.eco.internal.gui;
|
||||
|
||||
import com.willfp.eco.core.gui.GUIFactory;
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder;
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder;
|
||||
import com.willfp.eco.internal.gui.menu.EcoMenuBuilder;
|
||||
import com.willfp.eco.internal.gui.slot.EcoSlotBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoGUIFactory implements GUIFactory {
|
||||
@Override
|
||||
public SlotBuilder createSlotBuilder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
return new EcoSlotBuilder(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuBuilder createMenuBuilder(final int rows) {
|
||||
return new EcoMenuBuilder(rows);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import com.willfp.eco.core.gui.slot.FillerSlot;
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.internal.gui.slot.EcoFillerSlot;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EcoMenu implements Menu {
|
||||
@Getter
|
||||
private final int rows;
|
||||
|
||||
private final List<List<Slot>> slots;
|
||||
|
||||
@Getter
|
||||
private final String title;
|
||||
|
||||
private final Consumer<InventoryCloseEvent> onClose;
|
||||
|
||||
public EcoMenu(final int rows,
|
||||
@NotNull final List<List<Slot>> slots,
|
||||
@NotNull final String title,
|
||||
@NotNull final Consumer<InventoryCloseEvent> onClose) {
|
||||
this.rows = rows;
|
||||
this.slots = slots;
|
||||
this.title = title;
|
||||
this.onClose = onClose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(final int row,
|
||||
final int column) {
|
||||
if (row < 1 || row > this.rows) {
|
||||
throw new IllegalArgumentException("Invalid row number!");
|
||||
}
|
||||
|
||||
if (column < 1 || column > 9) {
|
||||
throw new IllegalArgumentException("Invalid column number!");
|
||||
}
|
||||
|
||||
Slot slot = slots.get(row - 1).get(column - 1);
|
||||
if (slot instanceof FillerSlot fillerSlot) {
|
||||
slots.get(row - 1).set(
|
||||
column - 1,
|
||||
new EcoFillerSlot(fillerSlot.getItemStack())
|
||||
);
|
||||
|
||||
return getSlot(row, column);
|
||||
}
|
||||
|
||||
return slots.get(row - 1).get(column - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory open(@NotNull final Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, rows * 9, title);
|
||||
int i = 0;
|
||||
for (List<Slot> row : slots) {
|
||||
for (Slot item : row) {
|
||||
if (i == rows * 9) {
|
||||
break;
|
||||
}
|
||||
ItemStack slotItem = item.getItemStack(player);
|
||||
ItemMeta meta = slotItem.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore != null) {
|
||||
lore.replaceAll(s -> StringUtils.format(s, player));
|
||||
meta.setLore(lore);
|
||||
}
|
||||
slotItem.setItemMeta(meta);
|
||||
}
|
||||
inventory.setItem(i, slotItem);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
player.openInventory(inventory);
|
||||
MenuHandler.registerMenu(inventory, this);
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void handleClose(@NotNull final InventoryCloseEvent event) {
|
||||
onClose.accept(event);
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder;
|
||||
import com.willfp.eco.core.gui.slot.FillerMask;
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.internal.gui.slot.EcoFillerSlot;
|
||||
import com.willfp.eco.util.ListUtils;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EcoMenuBuilder implements MenuBuilder {
|
||||
private final int rows;
|
||||
|
||||
private String title = "Menu";
|
||||
|
||||
private List<List<Slot>> maskSlots;
|
||||
|
||||
private final List<List<Slot>> slots;
|
||||
|
||||
private Consumer<InventoryCloseEvent> onClose = (event) -> {
|
||||
};
|
||||
|
||||
public EcoMenuBuilder(final int rows) {
|
||||
this.rows = rows;
|
||||
this.slots = ListUtils.create2DList(rows, 9);
|
||||
this.maskSlots = ListUtils.create2DList(rows, 9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuBuilder setTitle(@NotNull final String title) {
|
||||
this.title = StringUtils.format(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuBuilder setSlot(final int row,
|
||||
final int column,
|
||||
@NotNull final Slot slot) {
|
||||
if (row < 1 || row > this.rows) {
|
||||
throw new IllegalArgumentException("Invalid row number!");
|
||||
}
|
||||
|
||||
if (column < 1 || column > 9) {
|
||||
throw new IllegalArgumentException("Invalid column number!");
|
||||
}
|
||||
|
||||
slots.get(row - 1).set(column - 1, slot);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuBuilder setMask(@NotNull final FillerMask mask) {
|
||||
this.maskSlots = mask.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuBuilder onClose(@NotNull final Consumer<InventoryCloseEvent> action) {
|
||||
this.onClose = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menu build() {
|
||||
List<List<Slot>> finalSlots = maskSlots;
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
for (int j = 0; j < slots.get(i).size(); j++) {
|
||||
Slot slot = slots.get(i).get(j);
|
||||
if (slot != null) {
|
||||
finalSlots.get(i).set(j, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (List<Slot> finalSlot : finalSlots) {
|
||||
for (int j = 0; j < finalSlot.size(); j++) {
|
||||
if (finalSlot.get(j) == null) {
|
||||
finalSlot.set(j, new EcoFillerSlot(new ItemStack(Material.AIR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new EcoMenu(rows, finalSlots, title, onClose);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class MenuHandler {
|
||||
private static final Map<Inventory, Menu> MENUS = new HashMap<>();
|
||||
|
||||
public void registerMenu(@NotNull final Inventory inventory,
|
||||
@NotNull final Menu menu) {
|
||||
MENUS.put(inventory, menu);
|
||||
}
|
||||
|
||||
public void unregisterMenu(@NotNull final Inventory inventory) {
|
||||
MENUS.remove(inventory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Menu getMenu(@NotNull final Inventory inventory) {
|
||||
return MENUS.get(inventory);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.slot;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoFillerSlot extends EcoSlot {
|
||||
public EcoFillerSlot(@NotNull final ItemStack itemStack) {
|
||||
super((player) -> itemStack, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.slot;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoSlot implements Slot {
|
||||
private static final BiConsumer<InventoryClickEvent, Slot> NOOP = ((event, slot) -> { });
|
||||
|
||||
@Getter
|
||||
private final Function<Player, ItemStack> provider;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onLeftClick;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onRightClick;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onShiftRightClick;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onMiddleClick;
|
||||
|
||||
public EcoSlot(@NotNull final Function<Player, ItemStack> provider,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onLeftClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onRightClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftRightClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onMiddleClick) {
|
||||
this.provider = provider;
|
||||
this.onLeftClick = onLeftClick == null ? NOOP : onLeftClick;
|
||||
this.onRightClick = onRightClick == null ? NOOP : onRightClick;
|
||||
this.onShiftLeftClick = onShiftLeftClick == null ? NOOP : onShiftLeftClick;
|
||||
this.onShiftRightClick = onShiftRightClick == null ? NOOP : onShiftRightClick;
|
||||
this.onMiddleClick = onMiddleClick == null ? NOOP : onMiddleClick;
|
||||
}
|
||||
|
||||
public void handleInventoryClick(@NotNull final InventoryClickEvent event) {
|
||||
switch (event.getClick()) {
|
||||
case LEFT -> this.onLeftClick.accept(event, this);
|
||||
case RIGHT -> this.onRightClick.accept(event, this);
|
||||
case SHIFT_LEFT -> this.onShiftLeftClick.accept(event, this);
|
||||
case SHIFT_RIGHT -> this.onShiftRightClick.accept(event, this);
|
||||
case MIDDLE -> this.onMiddleClick.accept(event, this);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(@NotNull final Player player) {
|
||||
return provider.apply(player);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.willfp.eco.internal.gui.slot;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoSlotBuilder implements SlotBuilder {
|
||||
private final Function<Player, ItemStack> provider;
|
||||
|
||||
private BiConsumer<InventoryClickEvent, Slot> onLeftClick = null;
|
||||
|
||||
private BiConsumer<InventoryClickEvent, Slot> onRightClick = null;
|
||||
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick = null;
|
||||
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftRightClick = null;
|
||||
|
||||
private BiConsumer<InventoryClickEvent, Slot> onMiddleClick = null;
|
||||
|
||||
public EcoSlotBuilder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public SlotBuilder onLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onLeftClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SlotBuilder onRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onRightClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SlotBuilder onShiftLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onShiftLeftClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SlotBuilder onShiftRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onShiftRightClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SlotBuilder onMiddleClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onMiddleClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Slot build() {
|
||||
return new EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.willfp.eco.internal.logging;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EcoLogger extends Logger {
|
||||
public EcoLogger(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin.getName(), (String) null);
|
||||
String prefix = plugin.getDescription().getPrefix();
|
||||
this.setParent(plugin.getServer().getLogger());
|
||||
this.setLevel(Level.ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(@NotNull final String msg) {
|
||||
super.info(StringUtils.format(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(@NotNull final String msg) {
|
||||
super.warning(StringUtils.format(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(@NotNull final String msg) {
|
||||
super.severe(StringUtils.format(msg));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.willfp.eco.internal.scheduling;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.scheduling.RunnableTask;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class EcoRunnableTask extends BukkitRunnable implements RunnableTask {
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public EcoRunnableTask(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected final EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTask() {
|
||||
return super.runTask(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskAsynchronously() {
|
||||
return super.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskLater(final long delay) {
|
||||
return super.runTaskLater(plugin, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskLaterAsynchronously(final long delay) {
|
||||
return super.runTaskLaterAsynchronously(plugin, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskTimer(final long delay, final long period) {
|
||||
return super.runTaskTimer(plugin, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskTimerAsynchronously(final long delay, final long period) {
|
||||
return super.runTaskTimerAsynchronously(plugin, delay, period);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.willfp.eco.internal.scheduling;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoScheduler extends PluginDependent<EcoPlugin> implements Scheduler {
|
||||
@ApiStatus.Internal
|
||||
public EcoScheduler(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runLater(@NotNull final Runnable runnable,
|
||||
final long ticksLater) {
|
||||
return Bukkit.getScheduler().runTaskLater(this.getPlugin(), runnable, ticksLater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runTimer(@NotNull final Runnable runnable,
|
||||
final long delay,
|
||||
final long repeat) {
|
||||
return Bukkit.getScheduler().runTaskTimer(this.getPlugin(), runnable, delay, repeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runAsyncTimer(@NotNull final Runnable runnable,
|
||||
final long delay,
|
||||
final long repeat) {
|
||||
return Bukkit.getScheduler().runTaskTimerAsynchronously(this.getPlugin(), runnable, delay, repeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask run(@NotNull final Runnable runnable) {
|
||||
return Bukkit.getScheduler().runTask(this.getPlugin(), runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runAsync(@NotNull final Runnable runnable) {
|
||||
return Bukkit.getScheduler().runTaskAsynchronously(this.getPlugin(), runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int syncRepeating(@NotNull final Runnable runnable,
|
||||
final long delay,
|
||||
final long repeat) {
|
||||
return Bukkit.getScheduler().scheduleSyncRepeatingTask(this.getPlugin(), runnable, delay, repeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAll() {
|
||||
Bukkit.getScheduler().cancelTasks(this.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.internal
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.proxy.Cleaner
|
||||
import com.willfp.eco.internal.proxy.EcoProxyFactory
|
||||
import java.net.URLClassLoader
|
||||
|
||||
class EcoCleaner: Cleaner {
|
||||
override fun clean(plugin: EcoPlugin) {
|
||||
if (plugin.proxyPackage.isNotEmpty()) {
|
||||
val factory = plugin.proxyFactory as EcoProxyFactory;
|
||||
factory.clean()
|
||||
}
|
||||
|
||||
Plugins.LOADED_ECO_PLUGINS.remove(plugin.name.lowercase())
|
||||
|
||||
for (customItem in Items.getCustomItems()) {
|
||||
if (customItem.key.namespace.equals(plugin.name.lowercase(), ignoreCase = true)) {
|
||||
Items.removeCustomItem(customItem.key)
|
||||
}
|
||||
}
|
||||
|
||||
val classLoader = plugin::class.java.classLoader
|
||||
|
||||
if (classLoader is URLClassLoader) {
|
||||
classLoader.close()
|
||||
}
|
||||
|
||||
System.gc()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.willfp.eco.internal
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import lombok.experimental.UtilityClass
|
||||
|
||||
@UtilityClass
|
||||
object Plugins {
|
||||
val LOADED_ECO_PLUGINS = HashMap<String, EcoPlugin>()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.internal.drops
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
|
||||
object DropManager {
|
||||
var type = DropQueueType.COLLATED
|
||||
|
||||
@ConfigUpdater
|
||||
@JvmStatic
|
||||
fun update(plugin: EcoPlugin) {
|
||||
type = if (plugin.configYml.getBool("use-fast-collated-drops")) DropQueueType.COLLATED else DropQueueType.STANDARD
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.willfp.eco.internal.drops
|
||||
|
||||
enum class DropQueueType {
|
||||
STANDARD, COLLATED
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.internal.drops
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueueFactory
|
||||
import com.willfp.eco.core.drops.InternalDropQueue
|
||||
import com.willfp.eco.internal.drops.impl.EcoDropQueue
|
||||
import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class EcoDropQueueFactory : DropQueueFactory {
|
||||
override fun create(player: Player): InternalDropQueue {
|
||||
return if (DropManager.type == DropQueueType.COLLATED) EcoFastCollatedDropQueue(player) else EcoDropQueue(
|
||||
player
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.willfp.eco.internal.drops.impl
|
||||
|
||||
import com.willfp.eco.core.drops.InternalDropQueue
|
||||
import com.willfp.eco.util.TelekinesisUtils
|
||||
import lombok.AccessLevel
|
||||
import lombok.Getter
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.EntityType
|
||||
import org.bukkit.entity.ExperienceOrb
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.util.Vector
|
||||
|
||||
open class EcoDropQueue(player: Player) : InternalDropQueue {
|
||||
val items: MutableList<ItemStack>
|
||||
var xp: Int
|
||||
val player: Player
|
||||
var loc: Location
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private var hasTelekinesis = false
|
||||
override fun addItem(item: ItemStack): InternalDropQueue {
|
||||
items.add(item)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun addItems(itemStacks: Collection<ItemStack>): InternalDropQueue {
|
||||
items.addAll(itemStacks)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun addXP(amount: Int): InternalDropQueue {
|
||||
xp += amount
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setLocation(location: Location): InternalDropQueue {
|
||||
loc = location
|
||||
return this
|
||||
}
|
||||
|
||||
override fun forceTelekinesis(): InternalDropQueue {
|
||||
hasTelekinesis = true
|
||||
return this
|
||||
}
|
||||
|
||||
override fun push() {
|
||||
if (!hasTelekinesis) {
|
||||
hasTelekinesis = TelekinesisUtils.testPlayer(player)
|
||||
}
|
||||
val world = loc.world!!
|
||||
loc = loc.add(0.5, 0.5, 0.5)
|
||||
items.removeIf { itemStack: ItemStack -> itemStack.type == Material.AIR }
|
||||
if (items.isEmpty()) {
|
||||
return
|
||||
}
|
||||
if (hasTelekinesis) {
|
||||
val leftover = player.inventory.addItem(*items.toTypedArray())
|
||||
for (drop in leftover.values) {
|
||||
world.dropItem(loc, drop!!).velocity = Vector()
|
||||
}
|
||||
if (xp > 0) {
|
||||
val event = PlayerExpChangeEvent(player, xp)
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
val orb =
|
||||
world.spawnEntity(player.location.add(0.0, 0.2, 0.0), EntityType.EXPERIENCE_ORB) as ExperienceOrb
|
||||
orb.velocity = Vector(0, 0, 0)
|
||||
orb.experience = event.amount
|
||||
}
|
||||
} else {
|
||||
for (drop in items) {
|
||||
world.dropItem(loc, drop).velocity = Vector()
|
||||
}
|
||||
if (xp > 0) {
|
||||
val orb = world.spawnEntity(loc, EntityType.EXPERIENCE_ORB) as ExperienceOrb
|
||||
orb.experience = xp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
items = ArrayList()
|
||||
xp = 0
|
||||
this.player = player
|
||||
loc = player.location
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.willfp.eco.internal.drops.impl
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class EcoFastCollatedDropQueue(player: Player) : EcoDropQueue(player) {
|
||||
override fun push() {
|
||||
val fetched = COLLATED_MAP[player]
|
||||
|
||||
if (fetched == null) {
|
||||
COLLATED_MAP[player] = CollatedDrops(items, loc, xp)
|
||||
} else {
|
||||
fetched.addDrops(items)
|
||||
fetched.location = loc
|
||||
fetched.addXp(xp)
|
||||
|
||||
COLLATED_MAP[player] = fetched
|
||||
}
|
||||
}
|
||||
|
||||
class CollatedDrops(
|
||||
val drops: MutableList<ItemStack>,
|
||||
var location: Location,
|
||||
var xp: Int
|
||||
) {
|
||||
fun addDrops(toAdd: List<ItemStack>): CollatedDrops {
|
||||
drops.addAll(toAdd)
|
||||
return this
|
||||
}
|
||||
|
||||
fun addXp(xp: Int): CollatedDrops {
|
||||
this.xp += xp
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val COLLATED_MAP: MutableMap<Player, CollatedDrops> = ConcurrentHashMap()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.internal.events
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.events.EventManager
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.HandlerList
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
class EcoEventManager constructor(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), EventManager {
|
||||
override fun registerListener(listener: Listener) {
|
||||
Bukkit.getPluginManager().registerEvents(listener, plugin)
|
||||
}
|
||||
|
||||
override fun unregisterListener(listener: Listener) {
|
||||
HandlerList.unregisterAll(listener)
|
||||
}
|
||||
|
||||
override fun unregisterAllListeners() {
|
||||
HandlerList.unregisterAll(plugin)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.factory
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.factory.MetadataValueFactory
|
||||
import org.bukkit.metadata.FixedMetadataValue
|
||||
|
||||
class EcoMetadataValueFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), MetadataValueFactory {
|
||||
override fun create(value: Any): FixedMetadataValue {
|
||||
return FixedMetadataValue(plugin, value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.factory
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.factory.NamespacedKeyFactory
|
||||
import org.bukkit.NamespacedKey
|
||||
|
||||
class EcoNamespacedKeyFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), NamespacedKeyFactory {
|
||||
override fun create(key: String): NamespacedKey {
|
||||
return NamespacedKey(plugin, key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.internal.factory
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.factory.RunnableFactory
|
||||
import com.willfp.eco.core.scheduling.RunnableTask
|
||||
import com.willfp.eco.internal.scheduling.EcoRunnableTask
|
||||
import java.util.function.Consumer
|
||||
|
||||
class EcoRunnableFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), RunnableFactory {
|
||||
override fun create(consumer: Consumer<RunnableTask>): RunnableTask {
|
||||
return object : EcoRunnableTask(plugin) {
|
||||
override fun run() {
|
||||
consumer.accept(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.internal.gui
|
||||
|
||||
import com.willfp.eco.core.gui.GUIFactory
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
import com.willfp.eco.internal.gui.menu.EcoMenuBuilder
|
||||
import com.willfp.eco.internal.gui.slot.EcoSlotBuilder
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Function
|
||||
|
||||
class EcoGUIFactory : GUIFactory {
|
||||
override fun createSlotBuilder(provider: Function<Player, ItemStack>): SlotBuilder {
|
||||
return EcoSlotBuilder(provider)
|
||||
}
|
||||
|
||||
override fun createMenuBuilder(rows: Int): MenuBuilder {
|
||||
return EcoMenuBuilder(rows)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.willfp.eco.internal.gui.menu
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.slot.FillerSlot
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.internal.gui.slot.EcoFillerSlot
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.Inventory
|
||||
import java.util.function.Consumer
|
||||
|
||||
class EcoMenu(
|
||||
private val rows: Int,
|
||||
val slots: MutableList<MutableList<Slot>>,
|
||||
private val title: String,
|
||||
val onClose: Consumer<InventoryCloseEvent>
|
||||
): Menu {
|
||||
|
||||
override fun getSlot(row: Int, column: Int): Slot {
|
||||
if (row < 1 || row > this.rows) {
|
||||
throw IllegalArgumentException("Invalid row number!");
|
||||
}
|
||||
|
||||
if (column < 1 || column > 9) {
|
||||
throw IllegalArgumentException("Invalid column number!");
|
||||
}
|
||||
|
||||
val slot = slots[row - 1][column - 1]
|
||||
if (slot is FillerSlot) {
|
||||
slots[row - 1][column - 1] = EcoFillerSlot(slot.itemStack)
|
||||
|
||||
return getSlot(row, column)
|
||||
}
|
||||
|
||||
return slot
|
||||
}
|
||||
|
||||
override fun open(player: Player): Inventory {
|
||||
val inventory = Bukkit.createInventory(null, rows * 9, title)
|
||||
|
||||
var i = 0
|
||||
for (row in slots) {
|
||||
for (item in row) {
|
||||
if (i == rows * 9) {
|
||||
break
|
||||
}
|
||||
val slotItem = item.getItemStack(player)
|
||||
val meta = slotItem.itemMeta
|
||||
if (meta != null) {
|
||||
val lore = meta.lore
|
||||
if (lore != null) {
|
||||
lore.replaceAll{ s -> StringUtils.format(s, player) }
|
||||
meta.lore = lore
|
||||
}
|
||||
slotItem.itemMeta = meta
|
||||
}
|
||||
inventory.setItem(i, slotItem)
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
player.openInventory(inventory)
|
||||
MenuHandler.registerMenu(inventory, this)
|
||||
return inventory
|
||||
}
|
||||
|
||||
fun handleClose(event: InventoryCloseEvent) {
|
||||
onClose.accept(event)
|
||||
}
|
||||
|
||||
override fun getRows(): Int {
|
||||
return rows
|
||||
}
|
||||
|
||||
override fun getTitle(): String {
|
||||
return title
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.internal.gui.menu
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder
|
||||
import com.willfp.eco.core.gui.slot.FillerMask
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.internal.gui.slot.EcoFillerSlot
|
||||
import com.willfp.eco.util.ListUtils
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Consumer
|
||||
|
||||
class EcoMenuBuilder(private val rows: Int) : MenuBuilder {
|
||||
private var title = "Menu"
|
||||
private var maskSlots: List<MutableList<Slot?>>
|
||||
private val slots: List<MutableList<Slot>> = ListUtils.create2DList(rows, 9)
|
||||
private var onClose = Consumer { _: InventoryCloseEvent -> }
|
||||
|
||||
override fun setTitle(title: String): MenuBuilder {
|
||||
this.title = StringUtils.format(title)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setSlot(
|
||||
row: Int,
|
||||
column: Int,
|
||||
slot: Slot
|
||||
): MenuBuilder {
|
||||
require(!(row < 1 || row > rows)) { "Invalid row number!" }
|
||||
require(!(column < 1 || column > 9)) { "Invalid column number!" }
|
||||
slots[row - 1][column - 1] = slot
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setMask(mask: FillerMask): MenuBuilder {
|
||||
maskSlots = mask.mask
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onClose(action: Consumer<InventoryCloseEvent>): MenuBuilder {
|
||||
onClose = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun build(): Menu {
|
||||
val finalSlots = maskSlots
|
||||
for (i in slots.indices) {
|
||||
for (j in slots[i].indices) {
|
||||
val slot = slots[i][j]
|
||||
if (slot != null) {
|
||||
finalSlots[i][j] = slot
|
||||
}
|
||||
}
|
||||
}
|
||||
for (finalSlot in finalSlots) {
|
||||
for (j in finalSlot.indices) {
|
||||
if (finalSlot[j] == null) {
|
||||
finalSlot[j] = EcoFillerSlot(ItemStack(Material.AIR))
|
||||
}
|
||||
}
|
||||
}
|
||||
return EcoMenu(rows, finalSlots, title, onClose)
|
||||
}
|
||||
|
||||
init {
|
||||
maskSlots = ListUtils.create2DList(rows, 9)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.internal.gui.menu
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
object MenuHandler {
|
||||
private val MENUS: MutableMap<Inventory, Menu> = HashMap();
|
||||
|
||||
fun registerMenu(
|
||||
inventory: Inventory,
|
||||
menu: Menu
|
||||
) {
|
||||
MENUS[inventory] = menu
|
||||
}
|
||||
|
||||
fun unregisterMenu(inventory: Inventory) {
|
||||
MENUS.remove(inventory)
|
||||
}
|
||||
|
||||
fun getMenu(inventory: Inventory): Menu? {
|
||||
return MENUS[inventory]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Function
|
||||
|
||||
class EcoFillerSlot(itemStack: ItemStack) :
|
||||
EcoSlot(Function { itemStack }, null, null, null, null, null)
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.ClickType
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.BiConsumer
|
||||
import java.util.function.Function
|
||||
|
||||
class EcoSlot(
|
||||
val provider: Function<Player, ItemStack>,
|
||||
private val onLeftClick: BiConsumer<InventoryClickEvent, Slot>,
|
||||
private val onRightClick: BiConsumer<InventoryClickEvent, Slot>,
|
||||
private val onShiftLeftClick: BiConsumer<InventoryClickEvent, Slot>,
|
||||
private val onShiftRightClick: BiConsumer<InventoryClickEvent, Slot>,
|
||||
private val onMiddleClick: BiConsumer<InventoryClickEvent, Slot>
|
||||
) : Slot {
|
||||
|
||||
fun handleInventoryClick(event: InventoryClickEvent) {
|
||||
when (event.click) {
|
||||
ClickType.LEFT -> this.onLeftClick.accept(event, this)
|
||||
ClickType.RIGHT -> this.onRightClick.accept(event, this)
|
||||
ClickType.SHIFT_LEFT -> this.onShiftLeftClick.accept(event, this)
|
||||
ClickType.SHIFT_RIGHT -> this.onShiftRightClick.accept(event, this)
|
||||
ClickType.MIDDLE -> this.onMiddleClick.accept(event, this)
|
||||
else -> { }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemStack(player: Player): ItemStack {
|
||||
return provider.apply(player)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.BiConsumer
|
||||
import java.util.function.Function
|
||||
|
||||
class EcoSlotBuilder(private val provider: Function<Player, ItemStack>) : SlotBuilder {
|
||||
private var onLeftClick: BiConsumer<InventoryClickEvent, Slot> = BiConsumer { _, _ -> run { } }
|
||||
private var onRightClick: BiConsumer<InventoryClickEvent, Slot> = BiConsumer { _, _ -> run { } }
|
||||
private var onShiftLeftClick: BiConsumer<InventoryClickEvent, Slot> = BiConsumer { _, _ -> run { } }
|
||||
private var onShiftRightClick: BiConsumer<InventoryClickEvent, Slot> = BiConsumer { _, _ -> run { } }
|
||||
private var onMiddleClick: BiConsumer<InventoryClickEvent, Slot> = BiConsumer { _, _ -> run { } }
|
||||
|
||||
override fun onLeftClick(action: BiConsumer<InventoryClickEvent, Slot>): SlotBuilder {
|
||||
onLeftClick = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onRightClick(action: BiConsumer<InventoryClickEvent, Slot>): SlotBuilder {
|
||||
onRightClick = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onShiftLeftClick(action: BiConsumer<InventoryClickEvent, Slot>): SlotBuilder {
|
||||
onShiftLeftClick = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onShiftRightClick(action: BiConsumer<InventoryClickEvent, Slot>): SlotBuilder {
|
||||
onShiftRightClick = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onMiddleClick(action: BiConsumer<InventoryClickEvent, Slot>): SlotBuilder {
|
||||
onMiddleClick = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun build(): Slot {
|
||||
return EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.internal.logging
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.Logger
|
||||
|
||||
class EcoLogger(plugin: EcoPlugin) : Logger(plugin.name, null as String?) {
|
||||
override fun info(msg: String) {
|
||||
super.info(StringUtils.format(msg))
|
||||
}
|
||||
|
||||
override fun warning(msg: String) {
|
||||
super.warning(StringUtils.format(msg))
|
||||
}
|
||||
|
||||
override fun severe(msg: String) {
|
||||
super.severe(StringUtils.format(msg))
|
||||
}
|
||||
|
||||
init {
|
||||
val prefix = plugin.description.prefix
|
||||
parent = plugin.server.logger
|
||||
this.level = Level.ALL
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.willfp.eco.internal.scheduling
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.scheduling.RunnableTask
|
||||
import org.bukkit.scheduler.BukkitRunnable
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
|
||||
abstract class EcoRunnableTask(protected val plugin: EcoPlugin) : BukkitRunnable(), RunnableTask {
|
||||
@Synchronized
|
||||
override fun runTask(): BukkitTask {
|
||||
return super.runTask(plugin)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun runTaskAsynchronously(): BukkitTask {
|
||||
return super.runTaskAsynchronously(plugin)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun runTaskLater(delay: Long): BukkitTask {
|
||||
return super.runTaskLater(plugin, delay)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun runTaskLaterAsynchronously(delay: Long): BukkitTask {
|
||||
return super.runTaskLaterAsynchronously(plugin, delay)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun runTaskTimer(delay: Long, period: Long): BukkitTask {
|
||||
return super.runTaskTimer(plugin, delay, period)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun runTaskTimerAsynchronously(delay: Long, period: Long): BukkitTask {
|
||||
return super.runTaskTimerAsynchronously(plugin, delay, period)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.eco.internal.scheduling
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.scheduling.Scheduler
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
|
||||
class EcoScheduler(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Scheduler {
|
||||
override fun runLater(
|
||||
runnable: Runnable,
|
||||
ticksLater: Long
|
||||
): BukkitTask {
|
||||
return Bukkit.getScheduler().runTaskLater(plugin, runnable, ticksLater)
|
||||
}
|
||||
|
||||
override fun runTimer(
|
||||
runnable: Runnable,
|
||||
delay: Long,
|
||||
repeat: Long
|
||||
): BukkitTask {
|
||||
return Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, repeat)
|
||||
}
|
||||
|
||||
override fun runAsyncTimer(
|
||||
runnable: Runnable,
|
||||
delay: Long,
|
||||
repeat: Long
|
||||
): BukkitTask {
|
||||
return Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, repeat)
|
||||
}
|
||||
|
||||
override fun run(runnable: Runnable): BukkitTask {
|
||||
return Bukkit.getScheduler().runTask(plugin, runnable)
|
||||
}
|
||||
|
||||
override fun runAsync(runnable: Runnable): BukkitTask {
|
||||
return Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable)
|
||||
}
|
||||
|
||||
override fun syncRepeating(
|
||||
runnable: Runnable,
|
||||
delay: Long,
|
||||
repeat: Long
|
||||
): Int {
|
||||
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, runnable, delay, repeat)
|
||||
}
|
||||
|
||||
override fun cancelAll() {
|
||||
Bukkit.getScheduler().cancelTasks(plugin)
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ dependencies {
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.willfp:Oraxen:e1f4003d8d'
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
|
||||
|
||||
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.3.8'
|
||||
|
||||
|
||||
@@ -10,11 +10,9 @@ 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.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrowDataListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
@ApiStatus.Internal
|
||||
public ArrowDataListener(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ 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.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -20,7 +19,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class EntityDeathByEntityListeners extends PluginDependent<EcoPlugin> implements Listener {
|
||||
private final Set<EntityDeathByEntityBuilder> events = new HashSet<>();
|
||||
|
||||
@ApiStatus.Internal
|
||||
public EntityDeathByEntityListeners(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.bukkit.inventory.ItemStack
|
||||
import java.util.logging.Logger
|
||||
|
||||
class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
private var cleaner: Cleaner? = null
|
||||
private val cleaner = EcoCleaner()
|
||||
|
||||
override fun createScheduler(plugin: EcoPlugin): Scheduler {
|
||||
return EcoScheduler(plugin)
|
||||
@@ -91,10 +91,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
}
|
||||
|
||||
override fun getCleaner(): Cleaner {
|
||||
if (cleaner == null) {
|
||||
cleaner = EcoCleaner()
|
||||
}
|
||||
return cleaner as Cleaner
|
||||
return cleaner
|
||||
}
|
||||
|
||||
override fun createProxyFactory(plugin: EcoPlugin): ProxyFactory {
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
package com.willfp.eco.spigot.drops;
|
||||
package com.willfp.eco.spigot.drops
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.internal.drops.impl.EcoDropQueue
|
||||
import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.drops.impl.EcoDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CollatedRunnable {
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
public CollatedRunnable(@NotNull final EcoPlugin plugin) {
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, EcoFastCollatedDropQueue.CollatedDrops> entry : EcoFastCollatedDropQueue.COLLATED_MAP.entrySet()) {
|
||||
new EcoDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
EcoFastCollatedDropQueue.COLLATED_MAP.remove(entry.getKey());
|
||||
}
|
||||
EcoFastCollatedDropQueue.COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
class CollatedRunnable(plugin: EcoPlugin) {
|
||||
private val runnableTask: BukkitTask = plugin.scheduler.runTimer({
|
||||
for ((key, value) in EcoFastCollatedDropQueue.COLLATED_MAP) {
|
||||
EcoDropQueue(key!!)
|
||||
.setLocation(value.location)
|
||||
.addItems(value.drops)
|
||||
.addXP(value.xp)
|
||||
.push()
|
||||
EcoFastCollatedDropQueue.COLLATED_MAP.remove(key)
|
||||
}
|
||||
EcoFastCollatedDropQueue.COLLATED_MAP.clear()
|
||||
}, 0, 1)
|
||||
}
|
||||
@@ -1,69 +1,45 @@
|
||||
package com.willfp.eco.spigot.gui;
|
||||
package com.willfp.eco.spigot.gui
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.internal.gui.menu.EcoMenu;
|
||||
import com.willfp.eco.internal.gui.menu.MenuHandler;
|
||||
import com.willfp.eco.internal.gui.slot.EcoSlot;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.internal.gui.menu.EcoMenu
|
||||
import com.willfp.eco.internal.gui.menu.MenuHandler
|
||||
import com.willfp.eco.internal.gui.slot.EcoSlot
|
||||
import org.apache.commons.lang.Validate
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
|
||||
public class GUIListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
public GUIListener(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
class GUIListener(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Listener {
|
||||
@EventHandler
|
||||
fun handleSlotClick(event: InventoryClickEvent) {
|
||||
if (event.whoClicked !is Player) {
|
||||
return
|
||||
}
|
||||
if (event.clickedInventory == null) {
|
||||
return
|
||||
}
|
||||
val menu = MenuHandler.getMenu(event.clickedInventory!!) ?: return
|
||||
val row = Math.floorDiv(event.slot, 9)
|
||||
val column = event.slot - row * 9
|
||||
val slot = menu.getSlot(row, column)
|
||||
Validate.isTrue(slot is EcoSlot, "Slot not instance of EcoSlot!")
|
||||
val ecoSlot = menu.getSlot(row, column) as EcoSlot
|
||||
event.isCancelled = true
|
||||
ecoSlot.handleInventoryClick(event)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleSlotClick(@NotNull final InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
fun handleClose(event: InventoryCloseEvent) {
|
||||
if (event.player !is Player) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.getClickedInventory() == null) {
|
||||
return;
|
||||
}
|
||||
Menu menu = MenuHandler.getMenu(event.getClickedInventory());
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = Math.floorDiv(event.getSlot(), 9);
|
||||
int column = event.getSlot() - (row * 9);
|
||||
|
||||
Slot slot = menu.getSlot(row, column);
|
||||
|
||||
Validate.isTrue(slot instanceof EcoSlot, "Slot not instance of EcoSlot!");
|
||||
|
||||
EcoSlot ecoSlot = (EcoSlot) menu.getSlot(row, column);
|
||||
event.setCancelled(true);
|
||||
ecoSlot.handleInventoryClick(event);
|
||||
val menu = MenuHandler.getMenu(event.inventory) ?: return
|
||||
Validate.isTrue(menu is EcoMenu, "Menu not instance of EcoMenu!")
|
||||
val ecoMenu = menu as EcoMenu
|
||||
ecoMenu.handleClose(event)
|
||||
plugin.scheduler.run { MenuHandler.unregisterMenu(event.inventory) }
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleClose(@NotNull final InventoryCloseEvent event) {
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Menu menu = MenuHandler.getMenu(event.getInventory());
|
||||
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Validate.isTrue(menu instanceof EcoMenu, "Menu not instance of EcoMenu!");
|
||||
|
||||
EcoMenu ecoMenu = (EcoMenu) menu;
|
||||
|
||||
ecoMenu.handleClose(event);
|
||||
|
||||
this.getPlugin().getScheduler().run(() -> MenuHandler.unregisterMenu(event.getInventory()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user