commit
This commit is contained in:
@@ -18,7 +18,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT"
|
||||
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
def targetJavaVersion = 16
|
||||
|
||||
@@ -2,9 +2,7 @@ package io.github.itzispyder.ogredupealias;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.commands.commands.*;
|
||||
import io.github.itzispyder.ogredupealias.data.Config;
|
||||
import io.github.itzispyder.ogredupealias.events.ChatEventListener;
|
||||
import io.github.itzispyder.ogredupealias.events.CommandEventListener;
|
||||
import io.github.itzispyder.ogredupealias.events.PlayerEventListener;
|
||||
import io.github.itzispyder.ogredupealias.events.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -37,6 +35,10 @@ public final class OgreDupeAlias extends JavaPlugin {
|
||||
pm.registerEvents(new ChatEventListener(),this);
|
||||
pm.registerEvents(new PlayerEventListener(),this);
|
||||
pm.registerEvents(new CommandEventListener(),this);
|
||||
pm.registerEvents(new BlockActionListener(),this);
|
||||
pm.registerEvents(new EntityDeathListener(),this);
|
||||
pm.registerEvents(new InteractionListener(),this);
|
||||
pm.registerEvents(new InventoryActionListener(),this);
|
||||
|
||||
// Commands
|
||||
getCommand("config").setExecutor(new ConfigCommand());
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.github.itzispyder.ogredupealias.data;
|
||||
|
||||
public enum Direction {
|
||||
|
||||
UP,
|
||||
DOWN,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
EAST,
|
||||
WEST,
|
||||
CENTER
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.github.itzispyder.ogredupealias.data;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.data.builder.BlockPosMatcher;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public abstract class PlacedStructures {
|
||||
|
||||
public static boolean isCustomTable(Block block) {
|
||||
return BlockPosMatcher.of(block)
|
||||
.center(Material.DROPPER)
|
||||
.check(0,2,0, Material.SPRUCE_TRAPDOOR)
|
||||
.up(Material.GLASS)
|
||||
.west(Material.LEVER)
|
||||
.east(Material.LEVER)
|
||||
.north(Material.LEVER)
|
||||
.south(Material.LEVER)
|
||||
.isAcceptable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.github.itzispyder.ogredupealias.data.builder;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.data.Direction;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class BlockPosMatcher {
|
||||
|
||||
private final Location origin;
|
||||
private boolean acceptable;
|
||||
|
||||
private BlockPosMatcher(Block block) {
|
||||
this.origin = block.getLocation();
|
||||
this.acceptable = true;
|
||||
}
|
||||
|
||||
public BlockPosMatcher up(Material type) {
|
||||
return check(Direction.UP, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher down(Material type) {
|
||||
return check(Direction.DOWN, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher north(Material type) {
|
||||
return check(Direction.NORTH, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher south(Material type) {
|
||||
return check(Direction.SOUTH, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher east(Material type) {
|
||||
return check(Direction.EAST, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher west(Material type) {
|
||||
return check(Direction.WEST, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher center(Material type) {
|
||||
return check(Direction.CENTER, type);
|
||||
}
|
||||
|
||||
public BlockPosMatcher check(Direction dir, Material type) {
|
||||
if (acceptable) {
|
||||
switch (dir) {
|
||||
case UP -> acceptable = origin.clone().add(0,1,0).getBlock().getType().equals(type);
|
||||
case DOWN -> acceptable = origin.clone().add(0,-1,0).getBlock().getType().equals(type);
|
||||
case NORTH -> acceptable = origin.clone().add(0,0,-1).getBlock().getType().equals(type);
|
||||
case SOUTH -> acceptable = origin.clone().add(0,0,1).getBlock().getType().equals(type);
|
||||
case EAST -> acceptable = origin.clone().add(1,0,0).getBlock().getType().equals(type);
|
||||
case WEST -> acceptable = origin.clone().add(-1,0,0).getBlock().getType().equals(type);
|
||||
case CENTER -> acceptable = origin.clone().add(0,0,0).getBlock().getType().equals(type);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPosMatcher check(int relativeX, int relativeY, int relativeZ, Material type) {
|
||||
if (acceptable) {
|
||||
acceptable = origin.clone().add(relativeX,relativeY,relativeZ).getBlock().getType().equals(type);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isAcceptable() {
|
||||
return acceptable;
|
||||
}
|
||||
|
||||
public static BlockPosMatcher of(Block block) {
|
||||
return new BlockPosMatcher(block);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.github.itzispyder.ogredupealias.data;
|
||||
package io.github.itzispyder.ogredupealias.data.builder;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@@ -9,13 +9,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final ItemMeta meta;
|
||||
private ItemStack stack;
|
||||
private ItemMeta meta;
|
||||
|
||||
public ItemBuilder() {
|
||||
this(new ItemStack(Material.STONE));
|
||||
@@ -78,8 +78,26 @@ public class ItemBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder runTaskItem(Function<ItemStack, ItemStack> task) {
|
||||
this.stack = task.apply(build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder runTaskMeta(Function<ItemMeta, ItemMeta> task) {
|
||||
this.meta = task.apply(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemBuilder create() {
|
||||
return new ItemBuilder();
|
||||
}
|
||||
|
||||
public static ItemBuilder create(ItemStack item) {
|
||||
return new ItemBuilder(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockActionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlace(BlockPlaceEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlockPlaced();
|
||||
final Block f = e.getBlockAgainst();
|
||||
|
||||
}
|
||||
|
||||
public void onBreak(BlockBreakEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlock();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.utils.ItemUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
public class EntityDeathListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(EntityDeathEvent e) {
|
||||
final LivingEntity ent = e.getEntity();
|
||||
final EntityType type = ent.getType();
|
||||
final Location loc = ent.getLocation();
|
||||
|
||||
if (type == EntityType.WARDEN) {
|
||||
loc.getWorld().dropItemNaturally(loc, ItemUtils.skullOf("DeepWarden"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.data.PlacedStructures;
|
||||
import io.github.itzispyder.ogredupealias.plugin.InventoryPresets;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
final Action action = e.getAction();
|
||||
|
||||
try {
|
||||
final Block b = e.getClickedBlock();
|
||||
final ItemStack item = e.getItem();
|
||||
|
||||
if (PlacedStructures.isCustomTable(b)) {
|
||||
e.setCancelled(true);
|
||||
p.openInventory(InventoryPresets.createCustomTable());
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.plugin.custom.CustomTable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class InventoryActionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent e) {
|
||||
final Inventory inv = e.getInventory();
|
||||
final Player p = (Player) e.getPlayer();
|
||||
|
||||
try {
|
||||
CustomTable table = new CustomTable(inv);
|
||||
table.getGrid().forEach(item -> {
|
||||
p.sendMessage(item.getType().name());
|
||||
});
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.itzispyder.ogredupealias.plugin;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.data.builder.ItemBuilder;
|
||||
import io.github.itzispyder.ogredupealias.utils.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InventoryPresets {
|
||||
|
||||
public static Inventory createCustomTable() {
|
||||
final Inventory inv = Bukkit.createInventory(null,27, Text.color("&eForging Table"));
|
||||
ItemStack x = ItemBuilder.create()
|
||||
.material(Material.CYAN_STAINED_GLASS_PANE)
|
||||
.name(" ")
|
||||
.build();
|
||||
ItemStack craft = ItemBuilder.create()
|
||||
.material(Material.CRAFTING_TABLE)
|
||||
.name(Text.color("&aCraft Contents"))
|
||||
.build();
|
||||
ItemStack a = new ItemStack(Material.AIR);
|
||||
|
||||
inv.setContents(new ItemStack[]{
|
||||
x,a,a,a,x,x,x,x,x,
|
||||
x,a,a,a,x,craft,x,a,x,
|
||||
x,a,a,a,x,x,x,x,x,
|
||||
});
|
||||
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package io.github.itzispyder.ogredupealias.plugin;
|
||||
|
||||
public abstract class ItemPresets {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package io.github.itzispyder.ogredupealias.plugin.custom;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.utils.ArrayUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CraftingKey {
|
||||
|
||||
private static final Map<String,ItemStack> REGISTERED_KEYS = new HashMap<>();
|
||||
public final String key;
|
||||
|
||||
public static void register(CraftingKey key, ItemStack result) {
|
||||
REGISTERED_KEYS.put(key.getKey(),result);
|
||||
}
|
||||
|
||||
public static ItemStack getResult(CraftingKey key) {
|
||||
ItemStack result = REGISTERED_KEYS.get(key.getKey());
|
||||
return result != null ? result : new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
public CraftingKey(Iterable<ItemStack> input) {
|
||||
this.key = String.join("-", ArrayUtils.toNewList(input,item -> item.getType().name().toLowerCase() + ":" + item.getItemMeta().getAsString()));
|
||||
}
|
||||
|
||||
public CraftingKey(ItemStack[] input) {
|
||||
this(Arrays.stream(input).toList());
|
||||
}
|
||||
|
||||
public CraftingKey(Material[] input) {
|
||||
this(ArrayUtils.toNewList(Arrays.stream(input).toList(),ItemStack::new));
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CraftingKey comparing) {
|
||||
return comparing.getKey().equals(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.itzispyder.ogredupealias.plugin.custom;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomTable {
|
||||
|
||||
private final Inventory inv;
|
||||
|
||||
public CustomTable(Inventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public void clearGrid() {
|
||||
getGrid().forEach(item -> item.setAmount(0));
|
||||
}
|
||||
|
||||
public List<ItemStack> getGrid() {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int i = 1; i < 4; i++) list.add(inv.getItem(i + (x * 9)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
return inv.getItem(16);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.github.itzispyder.ogredupealias.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class ItemUtils {
|
||||
|
||||
public static boolean isSkullOf(ItemStack item, String name) {
|
||||
if (item == null || item.getType().isAir()) return false;
|
||||
if (item.getType() != Material.PLAYER_HEAD) return false;
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
OfflinePlayer p = meta.getOwningPlayer();
|
||||
if (p == null) return false;
|
||||
return p.getName().equalsIgnoreCase(name);
|
||||
}
|
||||
|
||||
public static ItemStack skullOf(String owner) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack skullOf(UUID owner) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
|
||||
return skullOf(p.getName());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
name: OgreDupeAlias
|
||||
version: '${version}'
|
||||
main: io.github.itzispyder.ogredupealias.OgreDupeAlias
|
||||
api-version: 1.17
|
||||
api-version: 1.19
|
||||
prefix: ODA
|
||||
authors: [ ImproperIssues, TheTrouper ]
|
||||
description: Server utilities for OgreDupe.minehut.gg
|
||||
|
||||
Reference in New Issue
Block a user