Compare commits

...

5 Commits
5.1.0 ... 5.2.0

Author SHA1 Message Date
Auxilor
7d4262e0ef Finished GUIs 2021-04-16 15:32:42 +01:00
Auxilor
e543be7a13 Updated to 5.2.0 2021-04-16 14:51:47 +01:00
Auxilor
3d7027bf47 Added initial GUI system 2021-04-16 14:51:30 +01:00
Auxilor
632b42ad65 Updated to 5.1.1 2021-04-14 16:02:00 +01:00
Auxilor
bcd79e3886 Added vulcan support 2021-04-14 16:01:51 +01:00
14 changed files with 577 additions and 10 deletions

View File

@@ -8,6 +8,8 @@
<!-- Internals don't need javadoc. -->
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="JavadocVariable"/>
<!-- Modified version of library -->
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>

View File

@@ -0,0 +1,53 @@
package com.willfp.eco.core.gui.menu;
import com.willfp.eco.core.gui.slot.Slot;
import com.willfp.eco.internal.gui.FillerSlot;
import com.willfp.eco.util.ListUtils;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class FillerMask {
@Getter
private final List<List<Slot>> mask;
public FillerMask(@NotNull final Material material,
@NotNull final String... pattern) {
if (material == Material.AIR) {
throw new IllegalArgumentException("Material cannot be air!");
}
mask = ListUtils.create2DList(6, 9);
ItemStack itemStack = new ItemStack(material);
ItemMeta meta = itemStack.getItemMeta();
assert meta != null;
meta.setDisplayName("§r");
itemStack.setItemMeta(meta);
int row = 0;
for (String patternRow : pattern) {
int column = 0;
if (patternRow.length() != 9) {
throw new IllegalArgumentException("Invalid amount of columns in pattern!");
}
for (char c : patternRow.toCharArray()) {
if (c == '0') {
mask.get(row).set(column, null);
} else if (c == '1') {
mask.get(row).set(column, new FillerSlot(itemStack));
} else {
throw new IllegalArgumentException("Invalid character in pattern! (Must only be 0 and 1)");
}
column++;
}
row++;
}
}
}

View File

@@ -0,0 +1,98 @@
package com.willfp.eco.core.gui.menu;
import com.willfp.eco.core.gui.slot.Slot;
import com.willfp.eco.internal.gui.EcoMenu;
import com.willfp.eco.internal.gui.FillerSlot;
import com.willfp.eco.util.ListUtils;
import com.willfp.eco.util.StringUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Consumer;
public interface Menu {
int getRows();
Slot getSlot(int row,
int column);
String getTitle();
Inventory open(@NotNull Player player);
static Builder builder(final int rows) {
return new Builder(rows);
}
class Builder {
private final int rows;
private String title = "Menu";
private List<List<Slot>> maskSlots;
private final List<List<Slot>> slots;
private Consumer<InventoryCloseEvent> onClose = (event) -> {
};
Builder(final int rows) {
this.rows = rows;
this.slots = ListUtils.create2DList(rows, 9);
this.maskSlots = ListUtils.create2DList(rows, 9);
}
public Builder setTitle(@NotNull final String title) {
this.title = StringUtils.translate(title);
return this;
}
public Builder 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;
}
public Builder setMask(@NotNull final FillerMask mask) {
this.maskSlots = mask.getMask();
return this;
}
public Builder onClose(@NotNull final Consumer<InventoryCloseEvent> action) {
this.onClose = action;
return this;
}
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 FillerSlot(new ItemStack(Material.AIR)));
}
}
}
return new EcoMenu(rows, finalSlots, title, onClose);
}
}
}

View File

@@ -0,0 +1,63 @@
package com.willfp.eco.core.gui.slot;
import com.willfp.eco.internal.gui.EcoSlot;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer;
public interface Slot {
ItemStack getItemStack();
static Builder builder(@NotNull final ItemStack itemStack) {
return new Builder(itemStack);
}
class Builder {
private final ItemStack itemStack;
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;
Builder(@NotNull final ItemStack itemStack) {
this.itemStack = itemStack;
}
public Builder onLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
this.onLeftClick = action;
return this;
}
public Builder onRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
this.onRightClick = action;
return this;
}
public Builder onShiftLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
this.onShiftLeftClick = action;
return this;
}
public Builder onShiftRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
this.onShiftRightClick = action;
return this;
}
public Builder onMiddleClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
this.onMiddleClick = action;
return this;
}
public Slot build() {
return new EcoSlot(itemStack, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
}
}
}

View File

@@ -0,0 +1,73 @@
package com.willfp.eco.internal.gui;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.Slot;
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.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!");
}
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;
}
inventory.setItem(i, item.getItemStack());
i++;
}
}
player.openInventory(inventory);
MenuHandler.registerMenu(inventory, this);
return inventory;
}
public void handleClose(@NotNull final InventoryCloseEvent event) {
onClose.accept(event);
}
}

View File

@@ -0,0 +1,61 @@
package com.willfp.eco.internal.gui;
import com.willfp.eco.core.gui.slot.Slot;
import lombok.Getter;
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;
public class EcoSlot implements Slot {
@Getter
private final ItemStack itemStack;
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 ItemStack itemStack,
@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.itemStack = itemStack;
this.onLeftClick = onLeftClick == null ? ((event, slot) -> { }) : onLeftClick;
this.onRightClick = onRightClick == null ? ((event, slot) -> { }) : onRightClick;
this.onShiftLeftClick = onShiftLeftClick == null ? ((event, slot) -> { }) : onShiftLeftClick;
this.onShiftRightClick = onShiftRightClick == null ? ((event, slot) -> { }) : onShiftRightClick;
this.onMiddleClick = onMiddleClick == null ? ((event, slot) -> { }) : onMiddleClick;
}
public void handleInventoryClick(@NotNull final InventoryClickEvent event) {
switch (event.getClick()) {
case LEFT:
this.onLeftClick.accept(event, this);
break;
case RIGHT:
this.onRightClick.accept(event, this);
break;
case SHIFT_LEFT:
this.onShiftLeftClick.accept(event, this);
break;
case SHIFT_RIGHT:
this.onShiftRightClick.accept(event, this);
break;
case MIDDLE:
this.onMiddleClick.accept(event, this);
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,15 @@
package com.willfp.eco.internal.gui;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class FillerSlot extends EcoSlot {
/**
* Create new filler slot.
*
* @param itemStack The ItemStack.
*/
public FillerSlot(@NotNull final ItemStack itemStack) {
super(itemStack, null, null, null, null, null);
}
}

View File

@@ -0,0 +1,29 @@
package com.willfp.eco.internal.gui;
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);
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.List;
@UtilityClass
public class ListUtils {
/**
* Initialize 2D list of a given size.
*
* @param rows The amount of rows.
* @param columns The amount of columns.
* @param <T> The type of the object stored in the list.
* @return The list, filled will null objects.
*/
public <T> List<List<T>> create2DList(final int rows,
final int columns) {
List<List<T>> list = new ArrayList<>(rows);
while (list.size() < rows) {
List<T> row = new ArrayList<>(columns);
while (row.size() < columns) {
row.add(null);
}
list.add(row);
}
return list;
}
}

View File

@@ -25,9 +25,8 @@ import com.willfp.eco.spigot.eventlisteners.ArmorListener;
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
import com.willfp.eco.spigot.gui.GUIListener;
import com.willfp.eco.spigot.integrations.anticheat.*;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
@@ -85,11 +84,6 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Override
public void enable() {
new CollatedRunnable(this);
this.getEventManager().registerListener(new NaturalExpGainListeners());
this.getEventManager().registerListener(new ArmorListener());
this.getEventManager().registerListener(new DispenserArmorListener());
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
this.getEventManager().registerListener(new ShapedRecipeListener());
}
@Override
@@ -132,6 +126,8 @@ public class EcoSpigotPlugin extends EcoPlugin {
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
new IntegrationLoader("Spartan", () -> AnticheatManager.register(this, new AnticheatSpartan())),
new IntegrationLoader("Vulcan", () -> AnticheatManager.register(this, new AnticheatVulcan())),
// Misc
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
@@ -157,7 +153,14 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Override
public List<Listener> getListeners() {
return new ArrayList<>();
return Arrays.asList(
new NaturalExpGainListeners(),
new ArmorListener(),
new DispenserArmorListener(),
new EntityDeathByEntityListeners(this),
new ShapedRecipeListener(),
new GUIListener(this)
);
}
@Override

View File

@@ -0,0 +1,95 @@
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.FillerMask;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.Slot;
import com.willfp.eco.internal.gui.EcoMenu;
import com.willfp.eco.internal.gui.EcoSlot;
import com.willfp.eco.internal.gui.MenuHandler;
import org.bukkit.Material;
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.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class GUIListener extends PluginDependent implements Listener {
/**
* Pass an {@link EcoPlugin} in order to interface with it.
*
* @param plugin The plugin to manage.
*/
public GUIListener(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@EventHandler
public void handleSlotClick(@NotNull final InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof 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);
EcoSlot slot = (EcoSlot) menu.getSlot(row, column);
event.setCancelled(true);
slot.handleInventoryClick(event);
}
@EventHandler
public void handleClose(@NotNull final InventoryCloseEvent event) {
if (!(event.getPlayer() instanceof Player)) {
return;
}
EcoMenu menu = (EcoMenu) MenuHandler.getMenu(event.getInventory());
if (menu == null) {
return;
}
menu.handleClose(event);
this.getPlugin().getScheduler().run(() -> MenuHandler.unregisterMenu(event.getInventory()));
}
@EventHandler
public void test(@NotNull final AsyncPlayerChatEvent event) {
String message = event.getMessage();
if (!message.equals("guitest")) {
return;
}
this.getPlugin().getScheduler().run(() -> {
Menu.builder(5)
.setMask(new FillerMask(
Material.BLACK_STAINED_GLASS_PANE,
"111111111",
"100000001",
"100000001",
"100000001",
"111111111"
))
.setSlot(1, 3, Slot.builder(new ItemStack(Material.TNT))
.onLeftClick((event1, slot) -> event1.getWhoClicked().sendMessage("CLICK"))
.build())
.setTitle("Poggers")
.onClose(event1 -> event1.getPlayer().sendMessage("CLOSED"))
.build()
.open(event.getPlayer());
});
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.eco.spigot.integrations.anticheat;
import com.willfp.eco.core.integrations.anticheat.AnticheatWrapper;
import me.frep.vulcan.api.event.VulcanFlagEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class AnticheatVulcan implements AnticheatWrapper, Listener {
/**
* Currently exempt players.
*/
private final Set<UUID> exempt = new HashSet<>();
@Override
public String getPluginName() {
return "Vulcan";
}
@Override
public void exempt(@NotNull final Player player) {
this.exempt.add(player.getUniqueId());
}
@Override
public void unexempt(@NotNull final Player player) {
this.exempt.remove(player.getUniqueId());
}
@EventHandler(priority = EventPriority.LOWEST)
private void onViolate(@NotNull final VulcanFlagEvent event) {
if (!exempt.contains(event.getPlayer().getUniqueId())) {
return;
}
event.setCancelled(true);
}
}

View File

@@ -1,2 +1,2 @@
version = 5.1.0
version = 5.2.0
plugin-name = eco

BIN
lib/VulcanAPI.jar Normal file

Binary file not shown.