Compare commits

...

44 Commits
5.0.0 ... 5.4.0

Author SHA1 Message Date
Auxilor
007a579f5a Updated to 5.4.0 2021-06-11 11:37:09 +01:00
Auxilor
9b19cd412a Updated to 1.17 and Java 16 2021-06-11 11:36:58 +01:00
Auxilor
08b5cc1612 Added more null checks to fix incompatibility with paper/adventure 2021-05-18 15:41:45 +01:00
Auxilor
47aa61c7b3 Updated to 5.3.7 2021-05-18 15:34:02 +01:00
Auxilor
ef1ee84358 Added checks for null components due to problem with adventure 2021-05-18 15:33:47 +01:00
Auxilor
49a36a4e81 Updated to 5.3.6 2021-05-06 08:47:51 +01:00
Auxilor
bf76dec28e Added emerald ore in TeamUtils 2021-05-06 08:47:41 +01:00
Auxilor
a0f51d79e8 Updated to 5.3.5 2021-04-26 21:24:45 +01:00
Auxilor
9be516e511 Added villager-display-fix to force remove all hideflags 2021-04-26 21:24:28 +01:00
Auxilor
a130935c62 Fixed Villager Trades for the last time 2021-04-25 15:54:50 +01:00
Auxilor
4359bd17ae Updated to 5.3.4 2021-04-25 15:45:26 +01:00
Auxilor
07726959e9 Fixed MerchantRecipe again 2021-04-25 15:45:16 +01:00
Auxilor
13c8187b3b Updated to 5.3.3 2021-04-25 15:18:51 +01:00
Auxilor
be1267ef0c Fixed config default 2021-04-25 15:18:40 +01:00
Auxilor
e61e9bc0a8 Added disable villager display option 2021-04-24 17:05:07 +01:00
Auxilor
ec801cd776 Updated to 5.3.2 2021-04-24 17:02:23 +01:00
Auxilor
a5b5bc6b46 Fixed ChatComponent 2021-04-24 17:01:53 +01:00
Auxilor
f5efb50d71 Updated to 5.3.1 2021-04-23 21:17:13 +01:00
Auxilor
d65c04aaa7 Hopefully fixed Villager Trades again 2021-04-23 21:16:46 +01:00
Auxilor
aa69d2a1a9 Fixed deprecation still being used 2021-04-20 21:41:04 +01:00
Auxilor
685cd5f998 Deprecated finalization system 2021-04-20 21:39:25 +01:00
Auxilor
bae4b567c8 Updated to 5.3.0 2021-04-20 21:31:05 +01:00
Auxilor
0eb3315d61 Updated to 5.2.2 2021-04-20 21:29:28 +01:00
Auxilor
0a42320b78 Fixed villager trade display 2021-04-20 21:29:19 +01:00
Auxilor
6ce0de8db7 Merge remote-tracking branch 'origin/master' 2021-04-20 21:28:04 +01:00
Auxilor
345d4cd1b5 Reworked villager trade display 2021-04-20 20:21:32 +01:00
Auxilor
950c092025 Added EcoSkills to loadbefore 2021-04-17 10:25:38 +01:00
Auxilor
0c6bb8c1b7 Updated to 5.2.1 2021-04-17 10:24:39 +01:00
Auxilor
0f9cb7db7a Items in menus now translate placeholder lore with respect to a player 2021-04-17 10:24:27 +01:00
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
Auxilor
8fbcf485b3 Renamed PlayerData to Data 2021-04-08 15:03:17 +01:00
Auxilor
6a64be2e25 Removed debug code 2021-04-08 15:01:57 +01:00
Auxilor
3f9f3991d8 Fixed cache on set in configs 2021-04-08 15:00:31 +01:00
Auxilor
54a8d942fa Fixed getSubsectionOrNull 2021-04-08 14:36:07 +01:00
Auxilor
6aa14be577 Updated to 5.1.0 2021-04-08 14:28:53 +01:00
Auxilor
d6db7673d8 Added data.yml 2021-04-08 14:28:19 +01:00
Auxilor
d002073124 Updated to 5.0.2 2021-04-06 18:03:03 +01:00
Auxilor
4bc98cae81 Fixed getVein 2021-04-06 18:02:50 +01:00
Auxilor
2696baf1d6 Updated to 5.0.1 2021-04-05 17:46:30 +01:00
Auxilor
3c3cc36403 Fixed fast sin and cos 2021-04-05 17:46:18 +01:00
43 changed files with 1331 additions and 134 deletions

View File

@@ -96,4 +96,4 @@ allprojects {
group = 'com.willfp' group = 'com.willfp'
archivesBaseName = project.name archivesBaseName = project.name
version = findProperty("version") version = findProperty("version")
java.sourceCompatibility = JavaVersion.VERSION_1_8 java.sourceCompatibility = JavaVersion.VERSION_16

View File

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

View File

@@ -78,6 +78,32 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
// Empty rather than abstract as implementations don't need both // Empty rather than abstract as implementations don't need both
} }
/**
* The code that should be executed once the packet has been received.
*
* @param packet The packet.
* @param player The player.
* @param event The event.
*/
public void onReceive(@NotNull final PacketContainer packet,
@NotNull final Player player,
@NotNull final PacketEvent event) {
// Empty rather than abstract as implementations don't need both
}
/**
* THe code that should be executed once the packet has been sent.
*
* @param packet The packet.
* @param player The player.
* @param event The event.
*/
public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player,
@NotNull final PacketEvent event) {
// Empty rather than abstract as implementations don't need both
}
/** /**
* Boilerplate to assert that the packet is of the specified type. * Boilerplate to assert that the packet is of the specified type.
* *
@@ -94,6 +120,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
} }
onReceive(event.getPacket(), event.getPlayer()); onReceive(event.getPacket(), event.getPlayer());
onReceive(event.getPacket(), event.getPlayer(), event);
} }
/** /**
@@ -112,6 +139,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
} }
onSend(event.getPacket(), event.getPlayer()); onSend(event.getPacket(), event.getPlayer());
onSend(event.getPacket(), event.getPlayer(), event);
} }
/** /**

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.core; package com.willfp.eco.core;
import com.willfp.eco.core.proxy.ProxyConstants;
import com.willfp.eco.util.ClassUtils; import com.willfp.eco.util.ClassUtils;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -14,6 +15,7 @@ public class Prerequisite {
* All existing prerequisites are registered on creation. * All existing prerequisites are registered on creation.
*/ */
private static final List<Prerequisite> VALUES = new ArrayList<>(); private static final List<Prerequisite> VALUES = new ArrayList<>();
/** /**
* Requires the server to be running an implementation of paper. * Requires the server to be running an implementation of paper.
*/ */
@@ -22,6 +24,14 @@ public class Prerequisite {
"Requires server to be running paper (or a fork)" "Requires server to be running paper (or a fork)"
); );
/**
* Requires the server to be running 1.17
*/
public static final Prerequisite v1_17 = new Prerequisite(
() -> ProxyConstants.NMS_VERSION.contains("17"),
"Requires server to be running 1.17+"
);
/** /**
* If the necessary prerequisite condition has been met. * If the necessary prerequisite condition has been met.
*/ */

View File

@@ -0,0 +1,142 @@
package com.willfp.eco.core.data;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.config.Config;
import com.willfp.eco.internal.config.ConfigSection;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@UtilityClass
public class Data {
/**
* Instance of eco data.yml.
*/
private static BaseConfig dataYml = null;
/**
* All cached player data.
*/
private static final Map<UUID, Config> PLAYER_DATA = new HashMap<>();
/**
* Write an integer to a player's data.
*
* @param player The player.
* @param key The key.
* @param data The data.
*/
public void writeInt(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key,
final int data) {
getPlayerConfig(player).set(key.toString(), data);
}
/**
* Write a string to a player's data.
*
* @param player The player.
* @param key The key.
* @param data The data.
*/
public void writeString(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key,
@NotNull final String data) {
getPlayerConfig(player).set(key.toString(), data);
}
/**
* Write a double to a player's data.
*
* @param player The player.
* @param key The key.
* @param data The data.
*/
public void writeDouble(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key,
final double data) {
getPlayerConfig(player).set(key.toString(), data);
}
/**
* Read an integer from a player's data.
*
* @param player The player.
* @param key The key.
*/
public int readInt(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key) {
return getPlayerConfig(player).getInt(key.toString());
}
/**
* Read a string from a player's data.
*
* @param player The player.
* @param key The key.
*/
public String readString(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key) {
return getPlayerConfig(player).getString(key.toString());
}
/**
* Read a double from a player's data.
*
* @param player The player.
* @param key The key.
*/
public double readDouble(@NotNull final OfflinePlayer player,
@NotNull final NamespacedKey key) {
return getPlayerConfig(player).getDouble(key.toString());
}
/**
* Initialize the player data with an instance of data.yml.
*
* @param config data.yml.
*/
@ApiStatus.Internal
public void init(@NotNull final BaseConfig config) {
dataYml = config;
}
/**
* Save to data.yml.
*
* @param config Instance of data.yml.
* @throws IOException Error during saving.
*/
@ApiStatus.Internal
public void save(@NotNull final BaseConfig config) throws IOException {
for (Map.Entry<UUID, Config> entry : PLAYER_DATA.entrySet()) {
for (String key : entry.getValue().getKeys(false)) {
config.set("player-data." + entry.getKey().toString() + "." + key, entry.getValue().get(key));
}
}
config.save();
}
private Config getPlayerConfig(@NotNull final OfflinePlayer player) {
Config config = PLAYER_DATA.get(player.getUniqueId());
if (config == null) {
config = dataYml.getSubsectionOrNull("player-data." + player.getUniqueId());
if (config == null) {
config = new ConfigSection(new YamlConfiguration());
}
PLAYER_DATA.put(player.getUniqueId(), config);
return getPlayerConfig(player);
}
return config;
}
}

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

@@ -9,7 +9,7 @@ public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
* *
* @param section The section. * @param section The section.
*/ */
protected ConfigSection(@NotNull final ConfigurationSection section) { public ConfigSection(@NotNull final ConfigurationSection section) {
this.init(section); this.init(section);
} }
} }

View File

@@ -64,6 +64,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
@Override @Override
public void set(@NotNull final String path, public void set(@NotNull final String path,
@Nullable final Object object) { @Nullable final Object object) {
cache.remove(path);
handle.set(path, object); handle.set(path, object);
} }
@@ -81,7 +82,12 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
if (cache.containsKey(path)) { if (cache.containsKey(path)) {
return (Config) cache.get(path); return (Config) cache.get(path);
} else { } else {
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path)))); ConfigurationSection raw = handle.getConfigurationSection(path);
if (raw == null) {
cache.put(path, null);
} else {
cache.put(path, new ConfigSection(raw));
}
return getSubsectionOrNull(path); return getSubsectionOrNull(path);
} }
} }

View File

@@ -0,0 +1,86 @@
package com.willfp.eco.internal.gui;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.Slot;
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!");
}
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();
ItemMeta meta = slotItem.getItemMeta();
if (meta != null) {
List<String> lore = meta.getLore();
if (lore != null) {
lore.replaceAll(s -> StringUtils.translate(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);
}
}

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

@@ -37,15 +37,6 @@ public class BlockUtils {
if (blocks.size() > limit || blocks.size() > 2500) { if (blocks.size() > limit || blocks.size() > 2500) {
return blocks; return blocks;
} }
}
}
// Running twice to get more spherical shape.
for (BlockFace face : BlockFace.values()) {
Block block = start.getRelative(face);
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
if (blocks.size() > limit || blocks.size() > 2500) {
return blocks;
}
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit)); blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
} }
} }

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

@@ -10,20 +10,10 @@ import java.util.concurrent.ThreadLocalRandom;
@UtilityClass @UtilityClass
public class NumberUtils { public class NumberUtils {
/**
* Precision.
*/
private static final int FAST_TRIG_PRECISION = 100;
/**
* Modulus.
*/
private static final int FAST_TRIG_MODULUS = 360 * FAST_TRIG_PRECISION;
/** /**
* Sin lookup table. * Sin lookup table.
*/ */
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS]; private static final double[] SIN_LOOKUP = new double[65536];
/** /**
* Set of roman numerals to look up. * Set of roman numerals to look up.
@@ -45,15 +35,11 @@ public class NumberUtils {
NUMERALS.put(4, "IV"); NUMERALS.put(4, "IV");
NUMERALS.put(1, "I"); NUMERALS.put(1, "I");
for (int i = 0; i < SIN_LOOKUP.length; i++) { for (int i = 0; i < 65536; ++i) {
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180)); SIN_LOOKUP[i] = Math.sin((double) i * 3.141592653589793D * 2.0D / 65536.0D);
} }
} }
private static double sinLookup(final int a) {
return a >= 0 ? SIN_LOOKUP[a % FAST_TRIG_MODULUS] : -SIN_LOOKUP[-a % FAST_TRIG_MODULUS];
}
/** /**
* Get the sin of a number. * Get the sin of a number.
* *
@@ -61,7 +47,8 @@ public class NumberUtils {
* @return The sin. * @return The sin.
*/ */
public static double fastSin(final double a) { public static double fastSin(final double a) {
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f)); float f = (float) a;
return SIN_LOOKUP[(int) (f * 10430.378F) & '\uffff'];
} }
/** /**
@@ -71,7 +58,8 @@ public class NumberUtils {
* @return The cosine. * @return The cosine.
*/ */
public static double fastCos(final double a) { public static double fastCos(final double a) {
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f)); float f = (float) a;
return SIN_LOOKUP[(int) (f * 10430.378F + 16384.0F) & '\uffff'];
} }
/** /**

View File

@@ -79,6 +79,7 @@ public class TeamUtils {
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE); MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED); MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA); MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
MATERIAL_COLORS.forcePut(Material.EMERALD_ORE, ChatColor.GREEN);
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED); MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
} }
} }

View File

@@ -27,13 +27,25 @@ public final class ChatComponent implements ChatComponentProxy {
} }
IChatBaseComponent chatComponent = (IChatBaseComponent) object; IChatBaseComponent chatComponent = (IChatBaseComponent) object;
chatComponent.stream().forEach(this::modifyBaseComponent); for (IChatBaseComponent iChatBaseComponent : chatComponent) {
if (iChatBaseComponent == null) {
continue;
}
modifyBaseComponent(iChatBaseComponent);
}
return chatComponent; return chatComponent;
} }
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent); for (IChatBaseComponent sibling : component.getSiblings()) {
if (sibling == null) {
continue;
}
modifyBaseComponent(sibling);
}
if (component instanceof ChatMessage) { if (component instanceof ChatMessage) {
Arrays.stream(((ChatMessage) component).getArgs()) Arrays.stream(((ChatMessage) component).getArgs())
.filter(o -> o instanceof IChatBaseComponent) .filter(o -> o instanceof IChatBaseComponent)

View File

@@ -1,8 +1,7 @@
package com.willfp.eco.proxy.v1_16_R1; package com.willfp.eco.proxy.v1_16_R1;
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.Display;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.MerchantRecipe;
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public final class VillagerTrade implements VillagerTradeProxy { public final class VillagerTrade implements VillagerTradeProxy {
@Override /**
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) { * Handle.
*/
private final Field handle;
/**
* Create new Villager Trade.
*/
public VillagerTrade() {
try { try {
// Bukkit MerchantRecipe result handle = CraftMerchantRecipe.class.getDeclaredField("handle");
Field fResult = MerchantRecipe.class.getDeclaredField("result"); handle.setAccessible(true);
fResult.setAccessible(true); return;
ItemStack result = merchantRecipe.getResult(); } catch (NoSuchFieldException e) {
Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
fHandle.setAccessible(true);
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} }
throw new RuntimeException("Error!");
}
@Override
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
Display.display(recipe.getResult().clone()),
recipe.getUses(),
recipe.getMaxUses(),
recipe.hasExperienceReward(),
recipe.getVillagerExperience(),
recipe.getPriceMultiplier()
);
for (ItemStack ingredient : recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone()));
}
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
return newRecipe;
}
@NotNull
private net.minecraft.server.v1_16_R1.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
try {
return (net.minecraft.server.v1_16_R1.MerchantRecipe) handle.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new IllegalArgumentException("Not CMR");
} }
} }

View File

@@ -27,13 +27,25 @@ public final class ChatComponent implements ChatComponentProxy {
} }
IChatBaseComponent chatComponent = (IChatBaseComponent) object; IChatBaseComponent chatComponent = (IChatBaseComponent) object;
chatComponent.stream().forEach(this::modifyBaseComponent); for (IChatBaseComponent iChatBaseComponent : chatComponent) {
if (iChatBaseComponent == null) {
continue;
}
modifyBaseComponent(iChatBaseComponent);
}
return chatComponent; return chatComponent;
} }
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent); for (IChatBaseComponent sibling : component.getSiblings()) {
if (sibling == null) {
continue;
}
modifyBaseComponent(sibling);
}
if (component instanceof ChatMessage) { if (component instanceof ChatMessage) {
Arrays.stream(((ChatMessage) component).getArgs()) Arrays.stream(((ChatMessage) component).getArgs())
.filter(o -> o instanceof IChatBaseComponent) .filter(o -> o instanceof IChatBaseComponent)

View File

@@ -1,8 +1,7 @@
package com.willfp.eco.proxy.v1_16_R2; package com.willfp.eco.proxy.v1_16_R2;
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.Display;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe; import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.MerchantRecipe;
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public final class VillagerTrade implements VillagerTradeProxy { public final class VillagerTrade implements VillagerTradeProxy {
@Override /**
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) { * Handle.
*/
private final Field handle;
/**
* Create new Villager Trade.
*/
public VillagerTrade() {
try { try {
// Bukkit MerchantRecipe result handle = CraftMerchantRecipe.class.getDeclaredField("handle");
Field fResult = MerchantRecipe.class.getDeclaredField("result"); handle.setAccessible(true);
fResult.setAccessible(true); return;
ItemStack result = merchantRecipe.getResult(); } catch (NoSuchFieldException e) {
Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
fHandle.setAccessible(true);
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} }
throw new RuntimeException("Error!");
}
@Override
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
Display.display(recipe.getResult().clone()),
recipe.getUses(),
recipe.getMaxUses(),
recipe.hasExperienceReward(),
recipe.getVillagerExperience(),
recipe.getPriceMultiplier()
);
for (ItemStack ingredient : recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone()));
}
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
return newRecipe;
}
@NotNull
private net.minecraft.server.v1_16_R2.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
try {
return (net.minecraft.server.v1_16_R2.MerchantRecipe) handle.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new IllegalArgumentException("Not CMR");
} }
} }

View File

@@ -27,13 +27,25 @@ public final class ChatComponent implements ChatComponentProxy {
} }
IChatBaseComponent chatComponent = (IChatBaseComponent) object; IChatBaseComponent chatComponent = (IChatBaseComponent) object;
chatComponent.stream().forEach(this::modifyBaseComponent); for (IChatBaseComponent iChatBaseComponent : chatComponent) {
if (iChatBaseComponent == null) {
continue;
}
modifyBaseComponent(iChatBaseComponent);
}
return chatComponent; return chatComponent;
} }
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent); for (IChatBaseComponent sibling : component.getSiblings()) {
if (sibling == null) {
continue;
}
modifyBaseComponent(sibling);
}
if (component instanceof ChatMessage) { if (component instanceof ChatMessage) {
Arrays.stream(((ChatMessage) component).getArgs()) Arrays.stream(((ChatMessage) component).getArgs())
.filter(o -> o instanceof IChatBaseComponent) .filter(o -> o instanceof IChatBaseComponent)

View File

@@ -1,8 +1,7 @@
package com.willfp.eco.proxy.v1_16_R3; package com.willfp.eco.proxy.v1_16_R3;
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.Display;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.MerchantRecipe;
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public final class VillagerTrade implements VillagerTradeProxy { public final class VillagerTrade implements VillagerTradeProxy {
@Override /**
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) { * Handle.
*/
private final Field handle;
/**
* Create new Villager Trade.
*/
public VillagerTrade() {
try { try {
// Bukkit MerchantRecipe result handle = CraftMerchantRecipe.class.getDeclaredField("handle");
Field fResult = MerchantRecipe.class.getDeclaredField("result"); handle.setAccessible(true);
fResult.setAccessible(true); return;
ItemStack result = merchantRecipe.getResult(); } catch (NoSuchFieldException e) {
Display.displayAndFinalize(result);
fResult.set(merchantRecipe, result);
// Get NMS MerchantRecipe from CraftMerchantRecipe
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
fHandle.setAccessible(true);
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS RecipeR
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
fSelling.setAccessible(true);
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
Display.displayAndFinalize(selling);
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} }
throw new RuntimeException("Error!");
}
@Override
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
Display.display(recipe.getResult().clone()),
recipe.getUses(),
recipe.getMaxUses(),
recipe.hasExperienceReward(),
recipe.getVillagerExperience(),
recipe.getPriceMultiplier()
);
for (ItemStack ingredient : recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone()));
}
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
return newRecipe;
}
@NotNull
private net.minecraft.server.v1_16_R3.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
try {
return (net.minecraft.server.v1_16_R3.MerchantRecipe) handle.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new IllegalArgumentException("Not CMR");
} }
} }

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
}

View File

@@ -0,0 +1,19 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
import net.minecraft.network.protocol.game.PacketPlayOutAutoRecipe;
import net.minecraft.resources.MinecraftKey;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
public final class AutoCraft implements AutoCraftProxy {
@Override
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
Field fKey = recipePacket.getClass().getDeclaredField("b");
fKey.setAccessible(true);
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
}
}

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
import net.minecraft.core.BlockPosition;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public final class BlockBreak implements BlockBreakProxy {
@Override
public void breakBlock(@NotNull final Player player,
@NotNull final Block block) {
((CraftPlayer) player).getHandle().d.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
}
}

View File

@@ -0,0 +1,116 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
import com.willfp.eco.core.display.Display;
import net.minecraft.nbt.MojangsonParser;
import net.minecraft.network.chat.ChatBaseComponent;
import net.minecraft.network.chat.ChatHoverable;
import net.minecraft.network.chat.ChatMessage;
import net.minecraft.network.chat.ChatModifier;
import net.minecraft.network.chat.IChatBaseComponent;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
public final class ChatComponent implements ChatComponentProxy {
@Override
public Object modifyComponent(@NotNull final Object object) {
if (!(object instanceof IChatBaseComponent)) {
return object;
}
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
if (iChatBaseComponent == null) {
continue;
}
modifyBaseComponent(iChatBaseComponent);
}
return chatComponent;
}
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
for (IChatBaseComponent sibling : component.getSiblings()) {
if (sibling == null) {
continue;
}
modifyBaseComponent(sibling);
}
if (component instanceof ChatMessage) {
Arrays.stream(((ChatMessage) component).getArgs())
.filter(o -> o instanceof IChatBaseComponent)
.map(o -> (IChatBaseComponent) o)
.forEach(this::modifyBaseComponent);
}
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
if (hoverable == null) {
return;
}
JsonObject jsonObject = hoverable.b();
JsonElement json = hoverable.b().get("contents");
if (json.getAsJsonObject().get("id") == null) {
return;
}
if (json.getAsJsonObject().get("tag") == null) {
return;
}
String id = json.getAsJsonObject().get("id").toString();
String tag = json.getAsJsonObject().get("tag").toString();
ItemStack itemStack = getFromTag(tag, id);
Display.displayAndFinalize(itemStack);
json.getAsJsonObject().remove("tag");
String newTag = toJson(itemStack);
json.getAsJsonObject().add("tag", new JsonPrimitive(newTag));
jsonObject.remove("contents");
jsonObject.add("contents", json);
ChatHoverable newHoverable = ChatHoverable.a(jsonObject);
ChatModifier modifier = component.getChatModifier();
modifier = modifier.setChatHoverable(newHoverable);
((ChatBaseComponent) component).setChatModifier(modifier);
}
private static ItemStack getFromTag(@NotNull final String jsonTag,
@NotNull final String id) {
String processedId = id;
String processedJsonTag = jsonTag;
processedId = processedId.replace("minecraft:", "");
processedId = processedId.toUpperCase();
processedId = processedId.replace("\"", "");
processedJsonTag = processedJsonTag.substring(1, processedJsonTag.length() - 1);
processedJsonTag = processedJsonTag.replace("id:", "\"id\":");
processedJsonTag = processedJsonTag.replace("\\", "");
Material material = Material.getMaterial(processedId);
assert material != null;
ItemStack itemStack = new ItemStack(material);
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
try {
nmsStack.setTag(MojangsonParser.parse(processedJsonTag));
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
return CraftItemStack.asBukkitCopy(nmsStack);
}
private static String toJson(@NotNull final ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString();
}
}

View File

@@ -0,0 +1,41 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.willfp.eco.proxy.proxies.SkullProxy;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;
public final class Skull implements SkullProxy {
/**
* Cached method to set the gameProfile.
*/
private Method setProfile = null;
@Override
public void setSkullTexture(@NotNull final SkullMeta meta,
@NotNull final String base64) {
try {
if (setProfile == null) {
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
setProfile.setAccessible(true);
}
UUID uuid = new UUID(
base64.substring(base64.length() - 20).hashCode(),
base64.substring(base64.length() - 10).hashCode()
);
GameProfile profile = new GameProfile(uuid, "talismans");
profile.getProperties().put("textures", new Property("textures", base64));
setProfile.invoke(meta, profile);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,13 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.willfp.eco.proxy.proxies.TridentStackProxy;
import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public final class TridentStack implements TridentStackProxy {
@Override
public ItemStack getTridentStack(@NotNull final Trident trident) {
return trident.getItem();
}
}

View File

@@ -0,0 +1,65 @@
package com.willfp.eco.proxy.v1_17_R1;
import com.willfp.eco.core.display.Display;
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
public final class VillagerTrade implements VillagerTradeProxy {
/**
* Handle.
*/
private final Field handle;
/**
* Create new Villager Trade.
*/
public VillagerTrade() {
try {
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
handle.setAccessible(true);
return;
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
throw new RuntimeException("Error!");
}
@Override
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
Display.display(recipe.getResult().clone()),
recipe.getUses(),
recipe.getMaxUses(),
recipe.hasExperienceReward(),
recipe.getVillagerExperience(),
recipe.getPriceMultiplier()
);
for (ItemStack ingredient : recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone()));
}
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
return newRecipe;
}
@NotNull
private net.minecraft.world.item.trading.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
try {
return (net.minecraft.world.item.trading.MerchantRecipe) handle.get(recipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new IllegalArgumentException("Not CMR");
}
}

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.spigot;
import com.willfp.eco.core.AbstractPacketAdapter; import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand; import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.data.Data;
import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.Display;
import com.willfp.eco.core.display.DisplayModule; import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.core.integrations.IntegrationLoader;
@@ -12,6 +13,7 @@ import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
import com.willfp.eco.proxy.proxies.BlockBreakProxy; import com.willfp.eco.proxy.proxies.BlockBreakProxy;
import com.willfp.eco.proxy.proxies.SkullProxy; import com.willfp.eco.proxy.proxies.SkullProxy;
import com.willfp.eco.proxy.proxies.TridentStackProxy; import com.willfp.eco.proxy.proxies.TridentStackProxy;
import com.willfp.eco.spigot.config.DataYml;
import com.willfp.eco.spigot.display.PacketAutoRecipe; import com.willfp.eco.spigot.display.PacketAutoRecipe;
import com.willfp.eco.spigot.display.PacketChat; import com.willfp.eco.spigot.display.PacketChat;
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant; import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
@@ -23,9 +25,8 @@ import com.willfp.eco.spigot.eventlisteners.ArmorListener;
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener; import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners; import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners; import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC; import com.willfp.eco.spigot.gui.GUIListener;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix; import com.willfp.eco.spigot.integrations.anticheat.*;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX; import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID; import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention; import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
@@ -42,6 +43,7 @@ import lombok.Getter;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -53,6 +55,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Getter @Getter
private static EcoSpigotPlugin instance; private static EcoSpigotPlugin instance;
/**
* data.yml.
*/
private final DataYml dataYml;
/** /**
* Create a new instance of eco. * Create a new instance of eco.
*/ */
@@ -69,21 +76,23 @@ public class EcoSpigotPlugin extends EcoPlugin {
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class); TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
TridentUtils.initialize(tridentStackProxy::getTridentStack); TridentUtils.initialize(tridentStackProxy::getTridentStack);
this.dataYml = new DataYml(this);
Data.init(this.dataYml);
} }
@Override @Override
public void enable() { public void enable() {
new CollatedRunnable(this); 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 @Override
public void disable() { public void disable() {
try {
Data.save(this.dataYml);
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
@@ -117,6 +126,8 @@ public class EcoSpigotPlugin extends EcoPlugin {
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())), new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())), new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())), 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 // Misc
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl())) new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
@@ -130,19 +141,31 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Override @Override
public List<AbstractPacketAdapter> getPacketAdapters() { public List<AbstractPacketAdapter> getPacketAdapters() {
return Arrays.asList( List<AbstractPacketAdapter> adapters = new ArrayList<>(Arrays.asList(
new PacketAutoRecipe(this), new PacketAutoRecipe(this),
new PacketChat(this), new PacketChat(this),
new PacketOpenWindowMerchant(this),
new PacketSetCreativeSlot(this), new PacketSetCreativeSlot(this),
new PacketSetSlot(this), new PacketSetSlot(this),
new PacketWindowItems(this) new PacketWindowItems(this)
); ));
if (!this.getConfigYml().getBool("disable-display-on-villagers")) {
adapters.add(new PacketOpenWindowMerchant(this));
}
return adapters;
} }
@Override @Override
public List<Listener> getListeners() { 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 @Override

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.spigot.config;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.spigot.EcoSpigotPlugin;
import org.jetbrains.annotations.NotNull;
public class DataYml extends BaseConfig {
/**
* Init data.yml.
*
* @param plugin EcoSpigotPlugin.
*/
public DataYml(@NotNull final EcoSpigotPlugin plugin) {
super("data", false, plugin);
}
}

View File

@@ -1,17 +1,23 @@
package com.willfp.eco.spigot.display; package com.willfp.eco.spigot.display;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.proxy.proxies.VillagerTradeProxy; import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
import com.willfp.eco.spigot.InternalProxyUtils; import com.willfp.eco.spigot.InternalProxyUtils;
import com.willfp.eco.core.EcoPlugin; import org.bukkit.NamespacedKey;
import com.willfp.eco.core.AbstractPacketAdapter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class PacketOpenWindowMerchant extends AbstractPacketAdapter { public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
/** /**
@@ -20,16 +26,32 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
* @param plugin The plugin to listen through. * @param plugin The plugin to listen through.
*/ */
public PacketOpenWindowMerchant(@NotNull final EcoPlugin plugin) { public PacketOpenWindowMerchant(@NotNull final EcoPlugin plugin) {
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false); super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, ListenerPriority.MONITOR, true);
} }
@Override @Override
public void onSend(@NotNull final PacketContainer packet, public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) { @NotNull final Player player,
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0); @NotNull final PacketEvent event) {
List<MerchantRecipe> recipes = new ArrayList<>();
recipes = recipes.stream().peek(merchantRecipe -> InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(merchantRecipe)).collect(Collectors.toList()); if (((EcoPlugin) this.getPlugin()).getConfigYml().getBool("villager-display-fix")) {
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
packet.getMerchantRecipeLists().writeSafely(0, recipes); ItemStack result = recipe.getResult();
ItemMeta meta = result.getItemMeta();
if (meta != null) {
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
meta.getPersistentDataContainer().remove(NamespacedKey.fromString("ecoenchants:ecoenchantlore-skip"));
result.setItemMeta(meta);
}
}
}
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
MerchantRecipe newRecipe = InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
recipes.add(newRecipe);
}
packet.getMerchantRecipeLists().write(0, recipes);
} }
} }

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

@@ -0,0 +1,2 @@
disable-display-on-villagers: false
villager-display-fix: false

View File

@@ -10,6 +10,7 @@ loadbefore:
- StatTrackers - StatTrackers
- EcoArmor - EcoArmor
- EcoBosses - EcoBosses
- EcoSkills
depend: depend:
- ProtocolLib - ProtocolLib
softdepend: softdepend:

View File

@@ -2,12 +2,14 @@ package com.willfp.eco.proxy.proxies;
import com.willfp.eco.core.proxy.AbstractProxy; import com.willfp.eco.core.proxy.AbstractProxy;
import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.MerchantRecipe;
import org.jetbrains.annotations.NotNull;
public interface VillagerTradeProxy extends AbstractProxy { public interface VillagerTradeProxy extends AbstractProxy {
/** /**
* Apply enchant display to the result of trades. * Display a MerchantRecipe.
* *
* @param merchantRecipe The recipe to modify. * @param recipe The recipe.
* @return The new recipe.
*/ */
void displayTrade(MerchantRecipe merchantRecipe); MerchantRecipe displayTrade(@NotNull MerchantRecipe recipe);
} }

View File

@@ -1,2 +1,2 @@
version = 5.0.0 version = 5.4.0
plugin-name = eco plugin-name = eco

BIN
lib/VulcanAPI.jar Normal file

Binary file not shown.

View File

@@ -7,5 +7,6 @@ include ':eco-core:core-nms'
include ':eco-core:core-nms:v1_16_R1' include ':eco-core:core-nms:v1_16_R1'
include ':eco-core:core-nms:v1_16_R2' include ':eco-core:core-nms:v1_16_R2'
include ':eco-core:core-nms:v1_16_R3' include ':eco-core:core-nms:v1_16_R3'
include ':eco-core:core-nms:v1_17_R1'
include ':eco-core:core-proxy' include ':eco-core:core-proxy'
include ':eco-core:core-plugin' include ':eco-core:core-plugin'