9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 02:49:22 +00:00

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java
#	eco-core/core-plugin/src/main/resources/sets.yml
This commit is contained in:
Auxilor
2021-01-23 11:29:16 +00:00
50 changed files with 2046 additions and 717 deletions

View File

@@ -7,7 +7,6 @@ plugins {
dependencies {
implementation project(":eco-core").getSubprojects()
implementation 'com.willfp:eco:1.3.1'
}
allprojects {
@@ -48,7 +47,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:1.3.1'
compileOnly 'com.willfp:eco:3.2.0'
compileOnly 'org.jetbrains:annotations:19.0.0'
@@ -83,9 +82,6 @@ clean.doLast {
}
shadowJar {
relocate('org.apache.maven', 'com.willfp.ecoarmor.eco.shaded.maven')
relocate('org.bstats', 'com.willfp.ecoarmor.eco.shaded.bstats')
relocate('com.willfp.eco.util', 'com.willfp.ecoarmor.eco.util') // Dot is to prevent plugin being shaded into itself
archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar"
}

View File

@@ -1,104 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_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.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.proxy.proxies.ChatComponentProxy;
import net.minecraft.server.v1_16_R1.ChatBaseComponent;
import net.minecraft.server.v1_16_R1.ChatHoverable;
import net.minecraft.server.v1_16_R1.ChatMessage;
import net.minecraft.server.v1_16_R1.ChatModifier;
import net.minecraft.server.v1_16_R1.IChatBaseComponent;
import net.minecraft.server.v1_16_R1.MojangsonParser;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_16_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;
chatComponent.stream().forEach(this::modifyBaseComponent);
return chatComponent;
}
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent);
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);
itemStack = ArmorDisplay.display(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.server.v1_16_R1.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

@@ -1,104 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_R2;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.proxy.proxies.ChatComponentProxy;
import net.minecraft.server.v1_16_R2.ChatBaseComponent;
import net.minecraft.server.v1_16_R2.ChatHoverable;
import net.minecraft.server.v1_16_R2.ChatMessage;
import net.minecraft.server.v1_16_R2.ChatModifier;
import net.minecraft.server.v1_16_R2.IChatBaseComponent;
import net.minecraft.server.v1_16_R2.MojangsonParser;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_16_R2.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;
chatComponent.stream().forEach(this::modifyBaseComponent);
return chatComponent;
}
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent);
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);
itemStack = ArmorDisplay.display(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.server.v1_16_R2.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

@@ -1,104 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_R3;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.proxy.proxies.ChatComponentProxy;
import net.minecraft.server.v1_16_R3.ChatBaseComponent;
import net.minecraft.server.v1_16_R3.ChatHoverable;
import net.minecraft.server.v1_16_R3.ChatMessage;
import net.minecraft.server.v1_16_R3.ChatModifier;
import net.minecraft.server.v1_16_R3.IChatBaseComponent;
import net.minecraft.server.v1_16_R3.MojangsonParser;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_16_R3.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;
chatComponent.stream().forEach(this::modifyBaseComponent);
return chatComponent;
}
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
component.getSiblings().forEach(this::modifyBaseComponent);
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);
itemStack = ArmorDisplay.display(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.server.v1_16_R3.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

@@ -1,21 +1,25 @@
package com.willfp.ecoarmor;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.display.DisplayModule;
import com.willfp.eco.util.integrations.IntegrationLoader;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.commands.CommandEagive;
import com.willfp.ecoarmor.commands.CommandEareload;
import com.willfp.ecoarmor.commands.TabcompleterEagive;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.display.packets.PacketChat;
import com.willfp.ecoarmor.display.packets.PacketSetCreativeSlot;
import com.willfp.ecoarmor.display.packets.PacketSetSlot;
import com.willfp.ecoarmor.display.packets.PacketWindowItems;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.sets.ArmorSets;
import com.willfp.ecoarmor.tiers.CrystalListener;
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener;
import com.willfp.ecoarmor.sets.util.PotionEffectListener;
import com.willfp.ecoarmor.upgrades.advanced.AdvancementShardListener;
import com.willfp.ecoarmor.upgrades.crystal.CrystalListener;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import com.willfp.ecoarmor.util.DiscoverRecipeListener;
import lombok.Getter;
import org.bukkit.event.Listener;
import java.util.ArrayList;
@@ -24,11 +28,18 @@ import java.util.List;
@SuppressWarnings("unused")
public class EcoArmorPlugin extends AbstractEcoPlugin {
/**
* Instance of EcoArmor.
*/
@Getter
private static EcoArmorPlugin instance;
/**
* Internal constructor called by bukkit on plugin load.
*/
public EcoArmorPlugin() {
super("EcoArmor", 0, 10002, "com.willfp.ecoarmor.proxy", "&5");
super("EcoArmor", 0, 10002, "com.willfp.ecoarmor.proxy", "&c");
instance = this;
}
/**
@@ -36,7 +47,10 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
*/
@Override
public void enable() {
Effects.values().forEach(effect -> this.getEventManager().registerListener(effect));
Display.registerDisplayModule(new DisplayModule(ArmorDisplay::display, 1, this.getPluginName()));
Display.registerRevertModule(ArmorDisplay::revertDisplay);
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
ArmorSets.update();
this.onReload();
}
@@ -61,6 +75,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
*/
@Override
public void onReload() {
Effects.values().forEach(effect -> this.getEventManager().unregisterListener(effect));
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
this.getLog().info(ArmorSets.values().size() + " Sets Loaded");
}
@@ -102,12 +118,7 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
*/
@Override
public List<AbstractPacketAdapter> getPacketAdapters() {
return Arrays.asList(
new PacketChat(this),
new PacketSetSlot(this),
new PacketSetCreativeSlot(this),
new PacketWindowItems(this)
);
return new ArrayList<>();
}
/**
@@ -118,14 +129,17 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
@Override
public List<Listener> getListeners() {
return Arrays.asList(
new CrystalListener(this)
new CrystalListener(this),
new AdvancementShardListener(this),
new PotionEffectListener(this),
new EffectiveDurabilityListener(this),
new DiscoverRecipeListener(this)
);
}
@Override
public List<Class<?>> getUpdatableClasses() {
return Arrays.asList(
EcoArmorConfigs.class,
ArmorSets.class,
TabcompleterEagive.class,
UpgradeCrystal.class

View File

@@ -2,17 +2,20 @@ package com.willfp.ecoarmor.commands;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.command.AbstractTabCompleter;
import com.willfp.eco.util.config.Configs;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.ArmorSets;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CommandEagive extends AbstractCommand {
@@ -34,12 +37,12 @@ public class CommandEagive extends AbstractCommand {
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(Configs.LANG.getMessage("needs-player"));
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
return;
}
if (args.size() == 1) {
sender.sendMessage(Configs.LANG.getMessage("needs-set"));
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-item"));
return;
}
@@ -47,22 +50,128 @@ public class CommandEagive extends AbstractCommand {
Player reciever = Bukkit.getPlayer(recieverName);
if (reciever == null) {
sender.sendMessage(Configs.LANG.getMessage("invalid-player"));
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
String setName = args.get(1);
ArmorSet set = ArmorSets.getByName(setName);
if (set == null) {
sender.sendMessage(Configs.LANG.getMessage("invalid-set"));
String fullItemKey = args.get(1);
if (!fullItemKey.contains(":")) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String[] fullItemSplit = fullItemKey.split(":");
if (fullItemSplit.length == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String itemNamespace = fullItemSplit[0];
String itemKey = fullItemSplit[1];
List<ItemStack> items = new ArrayList<>();
int amount = 1;
if (itemNamespace.equalsIgnoreCase("set")) {
ArmorSet set = ArmorSets.getByName(itemKey);
if (set == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%item%", set.getName() + " Set").replace("%recipient%", reciever.getName());
sender.sendMessage(message);
boolean advanced = false;
List<ArmorSlot> slots = new ArrayList<>();
if (args.size() >= 3) {
ArmorSlot slot = ArmorSlot.getSlot(args.get(2));
if (slot == null) {
if (!args.get(2).equalsIgnoreCase("full")) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
}
if (slot == null) {
slots.addAll(Arrays.asList(ArmorSlot.values()));
} else {
slots.add(slot);
}
} else {
slots.addAll(Arrays.asList(ArmorSlot.values()));
}
if (args.size() >= 4) {
advanced = Boolean.parseBoolean(args.get(3));
}
if (args.size() >= 5) {
try {
amount = Integer.parseInt(args.get(4));
} catch (NumberFormatException ignored) {
// do nothing
}
}
for (ArmorSlot slot : slots) {
items.add(advanced ? set.getAdvancedItemStack(slot) : set.getItemStack(slot));
}
}
if (itemNamespace.equalsIgnoreCase("crystal")) {
UpgradeCrystal crystal = UpgradeCrystal.getByName(itemKey);
if (crystal == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%item%", crystal.getItemStack().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
items.add(crystal.getItemStack());
if (args.size() >= 3) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
}
if (itemNamespace.equalsIgnoreCase("shard")) {
ArmorSet set = ArmorSets.getByName(itemKey);
if (set == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%item%", set.getAdvancementShardItem().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
items.add(set.getAdvancementShardItem());
if (args.size() >= 3) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
}
if (items.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String message = Configs.LANG.getMessage("give-success");
message = message.replace("%set%", set.getName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
for (ArmorSlot slot : ArmorSlot.values()) {
reciever.getInventory().addItem(set.getItemStack(slot));
for (ItemStack item : items) {
item.setAmount(amount);
reciever.getInventory().addItem(item);
}
}
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.commands;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.config.Configs;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -22,6 +21,6 @@ public class CommandEareload extends AbstractCommand {
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
this.getPlugin().reload();
sender.sendMessage(Configs.LANG.getMessage("reloaded"));
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
}
}

View File

@@ -3,8 +3,9 @@ package com.willfp.ecoarmor.commands;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.command.AbstractTabCompleter;
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.ArmorSets;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -12,6 +13,7 @@ import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -19,15 +21,35 @@ import java.util.stream.Collectors;
public class TabcompleterEagive extends AbstractTabCompleter {
/**
* The cached enchantment names.
* The cached names.
*/
private static final List<String> SET_NAMES = ArmorSets.values().stream().map(ArmorSet::getName).collect(Collectors.toList());
private static final List<String> SET_NAMES = new ArrayList<>();
/**
* The cached slots.
*/
private static final List<String> SLOTS = new ArrayList<>();
/**
* The cached numbers.
*/
private static final List<String> NUMBERS = Arrays.asList(
"1",
"2",
"3",
"4",
"5",
"10",
"32",
"64"
);
/**
* Instantiate a new tab-completer for /eagive.
*/
public TabcompleterEagive() {
super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("eagive")).getExecutor());
reload();
}
/**
@@ -36,7 +58,11 @@ public class TabcompleterEagive extends AbstractTabCompleter {
@ConfigUpdater
public static void reload() {
SET_NAMES.clear();
SET_NAMES.addAll(ArmorSets.values().stream().map(ArmorSet::getName).collect(Collectors.toList()));
SET_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "set:" + armorSet.getName()).collect(Collectors.toList()));
SET_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "shard:" + armorSet.getName()).collect(Collectors.toList()));
SET_NAMES.addAll(UpgradeCrystal.values().stream().map(crystal -> "crystal:" + crystal.getTier()).collect(Collectors.toList()));
SLOTS.addAll(Arrays.stream(ArmorSlot.values()).map(slot -> slot.name().toLowerCase()).collect(Collectors.toList()));
SLOTS.add("full");
}
/**
@@ -68,6 +94,34 @@ public class TabcompleterEagive extends AbstractTabCompleter {
return completions;
}
if (args.get(1).startsWith("set:")) {
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), SLOTS, completions);
Collections.sort(completions);
return completions;
}
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), Arrays.asList("true", "false"), completions);
Collections.sort(completions);
return completions;
}
if (args.size() == 5) {
StringUtil.copyPartialMatches(args.get(4), NUMBERS, completions);
return completions;
}
} else {
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
return completions;
}
}
return new ArrayList<>(0);
}
}

View File

@@ -1,7 +1,7 @@
package com.willfp.ecoarmor.config;
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.ecoarmor.config.configs.Sets;
import com.willfp.ecoarmor.config.configs.Tiers;
import lombok.experimental.UtilityClass;
@UtilityClass
@@ -11,11 +11,9 @@ public class EcoArmorConfigs {
*/
public static final Sets SETS = new Sets();
/**
* Update all configs.
* tiers.yml.
*/
@ConfigUpdater
public void updateConfigs() {
SETS.update();
}
public static final Tiers TIERS = new Tiers();
}

View File

@@ -1,12 +1,13 @@
package com.willfp.ecoarmor.config.configs;
import com.willfp.eco.util.config.BaseConfig;
import com.willfp.eco.util.config.StaticBaseConfig;
import com.willfp.ecoarmor.EcoArmorPlugin;
public class Sets extends BaseConfig {
public class Sets extends StaticBaseConfig {
/**
* sets.yml.
*/
public Sets() {
super("sets", false);
super("sets", EcoArmorPlugin.getInstance());
}
}

View File

@@ -0,0 +1,13 @@
package com.willfp.ecoarmor.config.configs;
import com.willfp.eco.util.config.StaticBaseConfig;
import com.willfp.ecoarmor.EcoArmorPlugin;
public class Tiers extends StaticBaseConfig {
/**
* sets.yml.
*/
public Tiers() {
super("tiers", EcoArmorPlugin.getInstance());
}
}

View File

@@ -1,10 +1,13 @@
package com.willfp.ecoarmor.display;
import com.willfp.eco.util.config.Configs;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.proxy.proxies.SkullProxy;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import com.willfp.ecoarmor.util.ProxyUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -17,6 +20,11 @@ import java.util.List;
@UtilityClass
public class ArmorDisplay {
/**
* Instance of EcoArmor.
*/
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
/**
* The prefix for all EcoArmor lines to have in lore.
*/
@@ -65,11 +73,6 @@ public class ArmorDisplay {
return itemStack;
}
ArmorSlot slot = ArmorSlot.getSlot(itemStack);
if (slot == null) {
return itemStack;
}
revertDisplay(itemStack);
ItemMeta meta = itemStack.getItemMeta();
@@ -83,16 +86,32 @@ public class ArmorDisplay {
String crystalTier = ArmorUtils.getCrystalTier(itemStack);
UpgradeCrystal crystal = UpgradeCrystal.getByName(crystalTier);
if (crystalTier == null || crystal == null) {
return itemStack;
if (crystalTier != null && crystal != null) {
meta.setLore(UpgradeCrystal.getByName(crystalTier).getItemStack().getItemMeta().getLore());
itemStack.setItemMeta(meta);
}
ArmorSet shardSet = ArmorUtils.getShardSet(itemStack);
if (shardSet != null) {
itemStack.setItemMeta(shardSet.getAdvancementShardItem().getItemMeta());
}
meta.setLore(UpgradeCrystal.getByName(crystalTier).getItemStack().getItemMeta().getLore());
itemStack.setItemMeta(meta);
return itemStack;
}
ItemStack slotStack = set.getItemStack(slot);
ArmorSlot slot = ArmorSlot.getSlot(itemStack);
if (slot == null) {
return itemStack;
}
ItemStack slotStack;
if (ArmorUtils.isAdvanced(itemStack)) {
slotStack = set.getAdvancedItemStack(slot);
} else {
slotStack = set.getItemStack(slot);
}
ItemMeta slotMeta = slotStack.getItemMeta();
assert slotMeta != null;
@@ -101,14 +120,15 @@ public class ArmorDisplay {
List<String> lore = new ArrayList<>();
for (String s : slotMeta.getLore()) {
lore.add(s.replace("%tier%", Configs.CONFIG.getString("tier." + tier + ".display")));
lore.add(s.replace("%tier%", EcoArmorConfigs.TIERS.getString(tier + ".display")));
}
meta.setLore(lore);
meta.setDisplayName(slotMeta.getDisplayName());
if (meta instanceof SkullMeta && slotMeta instanceof SkullMeta) {
((SkullMeta) meta).setOwningPlayer(((SkullMeta) slotMeta).getOwningPlayer());
String base64 = EcoArmorConfigs.SETS.getString(set.getName() + "." + slot.name().toLowerCase() + ".skull-texture");
ProxyUtils.getProxy(SkullProxy.class).setTexture((SkullMeta) meta, base64);
}
if (meta instanceof LeatherArmorMeta && slotMeta instanceof LeatherArmorMeta) {

View File

@@ -1,40 +0,0 @@
package com.willfp.ecoarmor.display.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.willfp.eco.util.ProxyUtils;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.proxy.proxies.ChatComponentProxy;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PacketChat extends AbstractPacketAdapter {
/**
* Instantiate a new listener for {@link PacketType.Play.Server#CHAT}.
*
* @param plugin The plugin to listen through.
*/
public PacketChat(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.NORMAL, true);
}
@Override
public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) {
for (int i = 0; i < packet.getChatComponents().size(); i++) {
WrappedChatComponent component = packet.getChatComponents().read(i);
if (component == null) {
continue;
}
if (component.getHandle() == null) {
return;
}
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
packet.getChatComponents().write(i, newComponent);
}
}
}

View File

@@ -1,26 +0,0 @@
package com.willfp.ecoarmor.display.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.display.ArmorDisplay;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
/**
* Instantiate a new listener for {@link PacketType.Play.Client#SET_CREATIVE_SLOT}.
*
* @param plugin The plugin to listen through.
*/
public PacketSetCreativeSlot(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Client.ITEM_NAME, false);
}
@Override
public void onReceive(@NotNull final PacketContainer packet,
@NotNull final Player player) {
packet.getItemModifier().modify(0, ArmorDisplay::revertDisplay);
}
}

View File

@@ -1,27 +0,0 @@
package com.willfp.ecoarmor.display.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.display.ArmorDisplay;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PacketSetSlot extends AbstractPacketAdapter {
/**
* Instantiate a new listener for {@link PacketType.Play.Server#SET_SLOT}.
*
* @param plugin The plugin to listen through.
*/
public PacketSetSlot(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.SET_SLOT, ListenerPriority.NORMAL, false);
}
@Override
public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) {
packet.getItemModifier().modify(0, ArmorDisplay::display);
}
}

View File

@@ -1,33 +0,0 @@
package com.willfp.ecoarmor.display.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.display.ArmorDisplay;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PacketWindowItems extends AbstractPacketAdapter {
/**
* Instantiate a new listener for {@link PacketType.Play.Server#WINDOW_ITEMS}.
*
* @param plugin The plugin to listen through.
*/
public PacketWindowItems(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.WINDOW_ITEMS, ListenerPriority.NORMAL, false);
}
@Override
public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) {
packet.getItemListModifier().modify(0, itemStacks -> {
if (itemStacks == null) {
return null;
}
itemStacks.forEach(ArmorDisplay::display);
return itemStacks;
});
}
}

View File

@@ -1,6 +1,6 @@
package com.willfp.ecoarmor.effects;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.EcoArmorPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.event.Listener;
@@ -11,7 +11,7 @@ public abstract class Effect<T> implements Listener {
* Instance of EcoArmor.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance();
/**
* The name of the effect.
@@ -19,6 +19,12 @@ public abstract class Effect<T> implements Listener {
@Getter
private final String name;
/**
* If the effect is enabled.
*/
@Getter
private boolean enabled;
/**
* Create a new effect.
*
@@ -27,6 +33,14 @@ public abstract class Effect<T> implements Listener {
protected Effect(@NotNull final String name) {
this.name = name;
update();
Effects.addNewEffect(this);
}
/**
* Update if the effect is enabled.
*/
public void update() {
enabled = this.getPlugin().getConfigYml().getBool("effects." + name + ".enabled");
}
}

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoarmor.effects;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.willfp.ecoarmor.effects.effects.AttackSpeedMultiplier;
import com.willfp.ecoarmor.effects.effects.BonusHearts;
import com.willfp.ecoarmor.effects.effects.BowDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.DamageMultiplier;
@@ -10,6 +11,8 @@ import com.willfp.ecoarmor.effects.effects.DamageTakenMultiplier;
import com.willfp.ecoarmor.effects.effects.EvadeChance;
import com.willfp.ecoarmor.effects.effects.ExperienceMultiplier;
import com.willfp.ecoarmor.effects.effects.FallDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.Flight;
import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier;
import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
@@ -26,20 +29,23 @@ public class Effects {
/**
* All registered effects.
*/
private static final BiMap<String, Effect> BY_NAME = HashBiMap.create();
private static final BiMap<String, Effect<?>> BY_NAME = HashBiMap.create();
public static final Effect BOW_DAMAGE_MULTIPLIER = new BowDamageMultiplier();
public static final Effect DAMAGE_MULTIPLIER = new DamageMultiplier();
public static final Effect DAMAGE_TAKEN_MULTIPLIER = new DamageTakenMultiplier();
public static final Effect EVADE_CHANCE = new EvadeChance();
public static final Effect FALL_DAMAGE_MULTIPLIER = new FallDamageMultiplier();
public static final Effect MELEE_DAMAGE_MULTIPLIER = new MeleeDamageMultiplier();
public static final Effect TRIDENT_DAMAGE_MULTIPLIER = new TridentDamageMultiplier();
public static final Effect BONUS_HEARTS = new BonusHearts();
public static final Effect SPEED_MULTIPLIER = new SpeedMutiplier();
public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier();
public static final Effect WARP_CHANCE = new WarpChance();
public static final Effect<?> BOW_DAMAGE_MULTIPLIER = new BowDamageMultiplier();
public static final Effect<?> DAMAGE_MULTIPLIER = new DamageMultiplier();
public static final Effect<?> DAMAGE_TAKEN_MULTIPLIER = new DamageTakenMultiplier();
public static final Effect<?> EVADE_CHANCE = new EvadeChance();
public static final Effect<?> FALL_DAMAGE_MULTIPLIER = new FallDamageMultiplier();
public static final Effect<?> MELEE_DAMAGE_MULTIPLIER = new MeleeDamageMultiplier();
public static final Effect<?> TRIDENT_DAMAGE_MULTIPLIER = new TridentDamageMultiplier();
public static final Effect<?> BONUS_HEARTS = new BonusHearts();
public static final Effect<?> SPEED_MULTIPLIER = new SpeedMutiplier();
public static final Effect<?> EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
public static final Effect<?> REGENERATION_MULTIPLIER = new RegenerationMultiplier();
public static final Effect<?> WARP_CHANCE = new WarpChance();
public static final Effect<?> ATTACK_SPEED_MULTIPLIER = new AttackSpeedMultiplier();
public static final Effect<?> FLIGHT = new Flight();
public static final Effect<?> HUNGER_LOSS_MULTIPLIER = new HungerLossMultiplier();
/**
* Get effect matching name.
@@ -47,7 +53,7 @@ public class Effects {
* @param name The name to query.
* @return The matching effect, or null if not found.
*/
public static Effect getByName(@NotNull final String name) {
public static Effect<?> getByName(@NotNull final String name) {
return BY_NAME.get(name);
}
@@ -56,7 +62,7 @@ public class Effects {
*
* @return The effects.
*/
public static List<Effect> values() {
public static List<Effect<?>> values() {
return ImmutableList.copyOf(BY_NAME.values());
}
@@ -65,7 +71,7 @@ public class Effects {
*
* @param effect The effect to add.
*/
public static void addNewEffect(@NotNull final Effect effect) {
public static void addNewEffect(@NotNull final Effect<?> effect) {
BY_NAME.remove(effect.getName());
BY_NAME.put(effect.getName(), effect);
}

View File

@@ -0,0 +1,41 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class AttackSpeedMultiplier extends Effect<Double> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("attack-speed-multiplier".getBytes());
public AttackSpeedMultiplier() {
super("attack-speed-multiplier");
}
@EventHandler
public void listener(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
assert movementSpeed != null;
this.getPlugin().getScheduler().runLater(() -> {
Double multiplier = ArmorUtils.getEffectStrength(player, this);
if (multiplier == null) {
movementSpeed.removeModifier(new AttributeModifier(MODIFIER_UUID, "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
} else {
AttributeModifier modifier = new AttributeModifier(MODIFIER_UUID, "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
if (!movementSpeed.getModifiers().contains(modifier)) {
movementSpeed.addModifier(modifier);
}
}
}, 1);
}
}

View File

@@ -20,7 +20,7 @@ public class BonusHearts extends Effect<Integer> {
}
@EventHandler
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
public void listener(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);

View File

@@ -16,7 +16,7 @@ public class BowDamageMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
public void listener(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -15,7 +15,7 @@ public class DamageMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
public void listener(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -13,7 +13,7 @@ public class DamageTakenMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageEvent event) {
public void listener(@NotNull final EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -14,7 +14,7 @@ public class DurabilityMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final PlayerItemDamageEvent event) {
public void listener(@NotNull final PlayerItemDamageEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -14,7 +14,7 @@ public class EvadeChance extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageEvent event) {
public void listener(@NotNull final EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -13,7 +13,7 @@ public class FallDamageMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageEvent event) {
public void listener(@NotNull final EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -0,0 +1,33 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
public class Flight extends Effect<Boolean> {
public Flight() {
super("flight");
}
@EventHandler
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
this.getPlugin().getScheduler().runLater(() -> {
Boolean flight = ArmorUtils.getEffectStrength(player, this);
if (flight == null) {
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
player.setAllowFlight(false);
}
} else {
if (flight) {
player.setAllowFlight(true);
}
}
}, 1);
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.jetbrains.annotations.NotNull;
public class HungerLossMultiplier extends Effect<Double> {
public HungerLossMultiplier() {
super("hunger-loss-multiplier");
}
@EventHandler
public void listener(@NotNull final FoodLevelChangeEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
if (multiplier == null) {
return;
}
if (event.getFoodLevel() > player.getFoodLevel()) {
return;
}
if (multiplier < 1) {
if (NumberUtils.randFloat(0, 1) > multiplier) {
event.setCancelled(true);
}
} else {
int difference = player.getFoodLevel() - event.getFoodLevel();
difference = (int) Math.ceil(difference * multiplier);
event.setFoodLevel(player.getFoodLevel() - difference);
}
}
}

View File

@@ -13,7 +13,7 @@ public class MeleeDamageMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
public void listener(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -13,7 +13,7 @@ public class RegenerationMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityRegainHealthEvent event) {
public void listener(@NotNull final EntityRegainHealthEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -20,7 +20,7 @@ public class SpeedMutiplier extends Effect<Double> {
}
@EventHandler
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
public void listener(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);

View File

@@ -16,7 +16,7 @@ public class TridentDamageMultiplier extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
public void listener(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -18,7 +18,7 @@ public class WarpChance extends Effect<Double> {
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
public void listener(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}

View File

@@ -1,16 +1,18 @@
package com.willfp.ecoarmor.sets;
import com.willfp.eco.common.recipes.lookup.RecipePartUtils;
import com.willfp.eco.util.ProxyUtils;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.EcoShapedRecipe;
import com.willfp.eco.util.recipe.lookup.RecipePartUtils;
import com.willfp.eco.util.recipe.parts.ComplexRecipePart;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.proxy.proxies.SkullProxy;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import com.willfp.ecoarmor.util.ProxyUtils;
import lombok.Getter;
import org.bukkit.Color;
import org.bukkit.Material;
@@ -37,7 +39,7 @@ public class ArmorSet {
/**
* Instance of EcoArmor.
*/
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
/**
* The name of the set.
@@ -45,29 +47,46 @@ public class ArmorSet {
@Getter
private final String name;
/**
* If the set is craftable.
*/
@Getter
private final boolean craftable;
/**
* Effects and their strengths.
*/
@Getter
private final Map<Effect<?>, Object> effects = new HashMap<>();
/**
* Effects and their strengths on advanced armor.
*/
@Getter
private final Map<Effect<?>, Object> advancedEffects = new HashMap<>();
/**
* Potion effects to be applied on equip.
*/
@Getter
private final Map<PotionEffectType, Integer> potionEffects = new HashMap<>();
/**
* Potion effects to be applied on equipping advanced.
*/
@Getter
private final Map<PotionEffectType, Integer> advancedPotionEffects = new HashMap<>();
/**
* Items in set.
*/
private final Map<ArmorSlot, ItemStack> items = new HashMap<>();
/**
* Items in advanced set.
*/
private final Map<ArmorSlot, ItemStack> advancedItems = new HashMap<>();
/**
* Advancement shard item.
*/
@Getter
private final ItemStack advancementShardItem;
/**
* Create a new Armor Set.
*
@@ -75,7 +94,6 @@ public class ArmorSet {
*/
public ArmorSet(@NotNull final String name) {
this.name = name;
this.craftable = EcoArmorConfigs.SETS.getBool(name + ".craftable");
for (String effectName : EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".set-bonus").getKeys(false)) {
Effect<?> effect = Effects.getByName(effectName);
@@ -83,15 +101,78 @@ public class ArmorSet {
effects.put(effect, value);
}
for (ArmorSlot slot : ArmorSlot.values()) {
ItemStack item = construct(slot.name().toLowerCase());
items.put(slot, item);
for (String effectName : EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".advanced-set-bonus").getKeys(false)) {
Effect<?> effect = Effects.getByName(effectName);
Object value = EcoArmorConfigs.SETS.getConfig().get(name + ".advanced-set-bonus." + effectName);
advancedEffects.put(effect, value);
}
if (EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".potion-effects") != null) {
for (String effectName : EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".potion-effects").getKeys(false)) {
PotionEffectType type = PotionEffectType.getByName(effectName.toUpperCase());
int strength = EcoArmorConfigs.SETS.getInt(name + ".potion-effects." + effectName);
potionEffects.put(type, strength);
}
}
if (EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".advanced-potion-effects") != null) {
for (String effectName : EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".advanced-potion-effects").getKeys(false)) {
PotionEffectType type = PotionEffectType.getByName(effectName.toUpperCase());
int strength = EcoArmorConfigs.SETS.getInt(name + ".advanced-potion-effects." + effectName);
advancedPotionEffects.put(type, strength);
}
}
for (ArmorSlot slot : ArmorSlot.values()) {
ItemStack item = construct(slot.name().toLowerCase(), false);
items.put(slot, item);
ItemStack advancedItem = construct(slot.name().toLowerCase(), true);
advancedItems.put(slot, advancedItem);
}
this.advancementShardItem = constructShard();
ArmorSets.addNewSet(this);
}
private ItemStack construct(@NotNull final String slot) {
private ItemStack constructShard() {
ItemStack shardItem = new ItemStack(Material.PRISMARINE_SHARD);
ItemMeta shardMeta = shardItem.getItemMeta();
assert shardMeta != null;
shardMeta.setDisplayName(EcoArmorConfigs.SETS.getString(name + ".advancement-shard-name"));
shardMeta.addEnchant(Enchantment.DURABILITY, 3, true);
shardMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
List<String> shardLore = new ArrayList<>();
for (String loreLine : EcoArmorConfigs.SETS.getStrings(name + ".advancement-shard-lore")) {
shardLore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
}
shardMeta.setLore(shardLore);
shardMeta.getPersistentDataContainer().set(PLUGIN.getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING, name);
shardItem.setItemMeta(shardMeta);
if (EcoArmorConfigs.SETS.getBool(name + ".shard-craftable")) {
EcoShapedRecipe.Builder builder = EcoShapedRecipe.builder(PLUGIN, this.getName() + "_shard").setOutput(shardItem);
List<String> recipeStrings = EcoArmorConfigs.SETS.getStrings(name + ".shard-recipe");
for (int i = 0; i < 9; i++) {
builder.setRecipePart(i, RecipePartUtils.lookup(recipeStrings.get(i)));
}
EcoShapedRecipe recipe = builder.build();
recipe.register();
}
return shardItem;
}
private ItemStack construct(@NotNull final String slot,
final boolean advanced) {
String pieceName = slot.toLowerCase();
Material material = Material.getMaterial(EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".material").toUpperCase());
@@ -108,13 +189,24 @@ public class ArmorSet {
assert meta != null;
String displayName = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".name");
String displayName;
if (advanced) {
displayName = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".advanced-name");
} else {
displayName = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".name");
}
List<String> lore = new ArrayList<>();
for (String loreLine : EcoArmorConfigs.SETS.getStrings(name + "." + pieceName + ".lore")) {
lore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
}
if (advanced) {
for (String loreLine : EcoArmorConfigs.SETS.getStrings(name + ".advanced-lore")) {
lore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
}
}
if (meta instanceof SkullMeta) {
String base64 = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".skull-texture");
ProxyUtils.getProxy(SkullProxy.class).setTexture((SkullMeta) meta, base64);
@@ -137,9 +229,21 @@ public class ArmorSet {
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(PLUGIN.getNamespacedKeyFactory().create("set"), PersistentDataType.STRING, name);
container.set(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING, "default");
container.set(PLUGIN.getNamespacedKeyFactory().create("effective-durability"), PersistentDataType.INTEGER, EcoArmorConfigs.SETS.getInt(name + "." + pieceName + ".effective-durability"));
if (advanced) {
container.set(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER, 1);
}
itemStack.setItemMeta(meta);
if (this.isCraftable()) {
RecipePartUtils.registerLookup("ecoarmor:set_" + name.toLowerCase() + "_" + pieceName, s -> new ComplexRecipePart(test -> {
if (ArmorSlot.getSlot(test) != ArmorSlot.getSlot(itemStack)) {
return false;
}
return Objects.equals(this, ArmorUtils.getSetOnItem(test));
}, itemStack));
if (!advanced) {
constructRecipe(slot, itemStack);
}
@@ -170,6 +274,16 @@ public class ArmorSet {
return items.get(slot);
}
/**
* Get item stack from slot.
*
* @param slot The slot.
* @return The item.
*/
public ItemStack getAdvancedItemStack(@NotNull final ArmorSlot slot) {
return advancedItems.get(slot);
}
/**
* Get effect strength of effect.
*
@@ -181,6 +295,17 @@ public class ArmorSet {
return (T) effects.get(effect);
}
/**
* Get effect strength of effect on advanced armor.
*
* @param effect The effect to query.
* @param <T> The type of the effect value.
* @return The strength.
*/
public <T> T getAdvancedEffectStrength(@NotNull final Effect<T> effect) {
return (T) advancedEffects.get(effect);
}
@Override
public boolean equals(final Object o) {
if (this == o) {

View File

@@ -50,7 +50,11 @@ public enum ArmorSlot {
* @return The slot, or null.
*/
@Nullable
public static ArmorSlot getSlot(@NotNull final ItemStack itemStack) {
public static ArmorSlot getSlot(@Nullable final ItemStack itemStack) {
if (itemStack == null) {
return null;
}
Material material = itemStack.getType();
String name = material.name().toLowerCase();
@@ -76,4 +80,35 @@ public enum ArmorSlot {
return null;
}
/**
* Get ArmorSlot from name.
*
* @param name The name.
* @return The slot, or null.
*/
@Nullable
public static ArmorSlot getSlot(@NotNull final String name) {
if (name.equalsIgnoreCase("helmet")) {
return HELMET;
}
if (name.equalsIgnoreCase("chestplate")) {
return CHESTPLATE;
}
if (name.equalsIgnoreCase("elytra")) {
return ELYTRA;
}
if (name.equalsIgnoreCase("leggings")) {
return LEGGINGS;
}
if (name.equalsIgnoreCase("boots")) {
return BOOTS;
}
return null;
}
}

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoarmor.sets.util;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.ArmorSets;
@@ -25,7 +26,7 @@ public class ArmorUtils {
/**
* Instance of EcoArmor.
*/
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
/**
* Get armor set on an item.
@@ -110,7 +111,13 @@ public class ArmorUtils {
return null;
}
return set.getEffectStrength(effect);
T strength = set.getEffectStrength(effect);
if (isAdvanced(player)) {
strength = set.getAdvancedEffectStrength(effect);
}
return strength;
}
/**
@@ -133,6 +140,11 @@ public class ArmorUtils {
*/
@Nullable
public static String getCrystalTier(@NotNull final ItemStack itemStack) {
// I have no idea when null gets passed but it broke crystal crafting so this check goes here.
if (itemStack == null) {
return null;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
@@ -192,44 +204,13 @@ public class ArmorUtils {
return;
}
int armor = 0;
int toughness = 0;
int knockback = 0;
if (tier.equals("iron")) {
if (slot == ArmorSlot.HELMET) {
armor = 2;
} else if (slot == ArmorSlot.CHESTPLATE) {
armor = 6;
} else if (slot == ArmorSlot.LEGGINGS) {
armor = 5;
} else if (slot == ArmorSlot.BOOTS) {
armor = 2;
}
} else if (tier.equals("diamond")) {
toughness = 2;
if (slot == ArmorSlot.HELMET) {
armor = 3;
} else if (slot == ArmorSlot.CHESTPLATE) {
armor = 8;
} else if (slot == ArmorSlot.LEGGINGS) {
armor = 6;
} else if (slot == ArmorSlot.BOOTS) {
armor = 3;
}
} else if (tier.equals("netherite")) {
toughness = 3;
knockback = 1;
if (slot == ArmorSlot.HELMET) {
armor = 3;
} else if (slot == ArmorSlot.CHESTPLATE) {
armor = 8;
} else if (slot == ArmorSlot.LEGGINGS) {
armor = 6;
} else if (slot == ArmorSlot.BOOTS) {
armor = 3;
}
}
int armor = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".armor");
int toughness = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".toughness");
int knockback = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".knockback-resistance");
int speed = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".speed-percentage");
int attackSpeed = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".attack-speed-percentage");
int attackDamage = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".attack-damage-percentage");
int attackKnockback = EcoArmorConfigs.TIERS.getInt(tier + ".properties." + slot.name().toLowerCase() + ".attack-knockback-percentage");
if (armor > 0) {
meta.removeAttributeModifier(Attribute.GENERIC_ARMOR);
@@ -243,7 +224,113 @@ public class ArmorUtils {
meta.removeAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
meta.addAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE, new AttributeModifier(UUID.randomUUID(), "ecoarmor-knockback", (double) knockback / 10, AttributeModifier.Operation.ADD_NUMBER, slot.getSlot()));
}
if (speed != 0) {
meta.removeAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED);
meta.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, new AttributeModifier(UUID.randomUUID(), "ecoarmor-speed", (double) speed / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot()));
}
if (attackSpeed != 0) {
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_SPEED);
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackspeed", (double) attackSpeed / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot()));
}
if (attackDamage != 0) {
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE);
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackdamage", (double) attackDamage / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot()));
}
if (attackKnockback != 0) {
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_KNOCKBACK);
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_KNOCKBACK, new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackknockback", (double) attackKnockback / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot()));
}
itemStack.setItemMeta(meta);
}
/**
* Get if player is wearing advanced set.
*
* @param player The player to check.
* @return If advanced.
*/
public static boolean isAdvanced(@NotNull final Player player) {
if (getSetOnPlayer(player) == null) {
return false;
}
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
if (itemStack == null) {
return false;
}
if (!isAdvanced(itemStack)) {
return false;
}
}
return true;
}
/**
* Get if item is advanced.
*
* @param itemStack The item to check.
* @return If advanced.
*/
public static boolean isAdvanced(@NotNull final ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return false;
}
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER)) {
return meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER) == 1;
}
return false;
}
/**
* Set if item is advanced.
*
* @param itemStack The item to set.
* @param advanced If the item should be advanced.
*/
public static void setAdvanced(@NotNull final ItemStack itemStack,
final boolean advanced) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
if (getSetOnItem(itemStack) == null) {
return;
}
meta.getPersistentDataContainer().set(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER, advanced ? 1 : 0);
itemStack.setItemMeta(meta);
}
/**
* Get the set from a shard.
*
* @param itemStack The item to check.
* @return The set, or null if not a shard.
*/
@Nullable
public static ArmorSet getShardSet(@NotNull final ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return null;
}
String shardSet = meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING);
if (shardSet == null) {
return null;
}
return ArmorSets.getByName(shardSet);
}
}

View File

@@ -0,0 +1,57 @@
package com.willfp.ecoarmor.sets.util;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
public class EffectiveDurabilityListener extends PluginDependent implements Listener {
/**
* Create new effective durability listeners.
*
* @param plugin The plugin.
*/
public EffectiveDurabilityListener(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Make durability act as effective.
*
* @param event The event to listen for.
*/
@EventHandler
public void listener(@NotNull final PlayerItemDamageEvent event) {
ItemStack itemStack = event.getItem();
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
Integer effectiveDurability = container.get(this.getPlugin().getNamespacedKeyFactory().create("effective-durability"), PersistentDataType.INTEGER);
if (effectiveDurability == null) {
return;
}
int maxDurability = itemStack.getType().getMaxDurability();
double ratio = (double) effectiveDurability / maxDurability;
double chance = 1 / ratio;
if (NumberUtils.randFloat(0, 1) > chance) {
event.setCancelled(true);
}
}
}

View File

@@ -0,0 +1,55 @@
package com.willfp.ecoarmor.sets.util;
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.sets.ArmorSet;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
public class PotionEffectListener extends PluginDependent implements Listener {
/**
* Create new potion effect listener for set effects.
*
* @param plugin EcoArmor.
*/
public PotionEffectListener(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Apply set potion effects.
*
* @param event The event to listen for.
*/
@EventHandler
public void onEquip(@NotNull final ArmorEquipEvent event) {
final Player player = event.getPlayer();
this.getPlugin().getScheduler().runLater(() -> {
for (PotionEffect effect : player.getActivePotionEffects()) {
if (effect.getDuration() >= 500000000) {
player.removePotionEffect(effect.getType());
}
}
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
set.getPotionEffects().forEach((potionEffectType, integer) -> {
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
});
if (ArmorUtils.isAdvanced(player)) {
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
});
}
}, 1);
}
}

View File

@@ -0,0 +1,81 @@
package com.willfp.ecoarmor.upgrades.advanced;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.ArmorSets;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
public class AdvancementShardListener extends PluginDependent implements Listener {
/**
* Create new listeners for dragging crystals onto items.
*
* @param plugin The plugin to listen for.
*/
public AdvancementShardListener(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Listen for inventory click event.
*
* @param event The event to handle.
*/
@EventHandler
public void onDrag(@NotNull final InventoryClickEvent event) {
ItemStack current = event.getCurrentItem();
ItemStack cursor = event.getCursor();
if (current == null || cursor == null) {
return;
}
if (cursor.getType() != Material.PRISMARINE_SHARD) {
return;
}
ItemMeta cursorMeta = cursor.getItemMeta();
if (cursorMeta == null) {
return;
}
String shardSet = cursorMeta.getPersistentDataContainer().get(this.getPlugin().getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING);
if (shardSet == null) {
return;
}
ArmorSet set = ArmorUtils.getSetOnItem(current);
if (set == null) {
return;
}
if (!ArmorSets.getByName(shardSet).getName().equals(set.getName())) {
return;
}
if (current.getType() == Material.AIR) {
return;
}
if (ArmorUtils.isAdvanced(current)) {
return;
}
ArmorUtils.setAdvanced(current, true);
event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR));
event.setCancelled(true);
}
}

View File

@@ -1,11 +1,13 @@
package com.willfp.ecoarmor.tiers;
package com.willfp.ecoarmor.upgrades.crystal;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -48,10 +50,41 @@ public class CrystalListener extends PluginDependent implements Listener {
return;
}
String previousTier = ArmorUtils.getTier(current);
String prereq = EcoArmorConfigs.TIERS.getString(tier + ".requires-tier");
boolean allowed = false;
if (prereq.equals("none")) {
allowed = true;
} else if (prereq.equals(previousTier)) {
allowed = true;
}
if (!allowed) {
return;
}
ArmorUtils.setTier(current, tier);
event.getWhoClicked().setItemOnCursor(null);
event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR));
event.setCancelled(true);
}
}
/**
* Prevents placing upgrade crystals.
*
* @param event The event to listen for.
*/
@EventHandler
public void onPlaceCrystal(@NotNull final BlockPlaceEvent event) {
ItemStack item = event.getItemInHand();
if (item.getType() != Material.END_CRYSTAL) {
return;
}
if (ArmorUtils.getCrystalTier(item) != null) {
event.setCancelled(true);
}
}
}

View File

@@ -1,14 +1,15 @@
package com.willfp.ecoarmor.tiers;
package com.willfp.ecoarmor.upgrades.crystal;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.willfp.eco.common.recipes.lookup.RecipePartUtils;
import com.willfp.eco.common.recipes.parts.ComplexRecipePart;
import com.google.common.collect.ImmutableList;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.config.Configs;
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.EcoShapedRecipe;
import com.willfp.eco.util.recipe.lookup.RecipePartUtils;
import com.willfp.eco.util.recipe.parts.ComplexRecipePart;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import lombok.Getter;
@@ -32,25 +33,10 @@ public class UpgradeCrystal {
private static final BiMap<String, UpgradeCrystal> BY_NAME = HashBiMap.create();
/**
* Iron crystal.
*/
public static final UpgradeCrystal IRON = new UpgradeCrystal("iron");
/**
* Diamond crystal.
*/
public static final UpgradeCrystal DIAMOND = new UpgradeCrystal("diamond");
/**
* Netherite crystal.
*/
public static final UpgradeCrystal NETHERITE = new UpgradeCrystal("netherite");
/**
* Instance of ItemStats to create keys for.
* Instance of EcoArmor to create keys for.
*/
@Getter
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance();
/**
* The tier of the crystal.
@@ -91,7 +77,7 @@ public class UpgradeCrystal {
* Update the tracker's crafting recipe.
*/
public void update() {
this.enabled = Configs.CONFIG.getBool("tier." + tier + ".crystal-craftable");
this.enabled = EcoArmorConfigs.TIERS.getBool(tier + ".crystal-craftable");
NamespacedKey key = this.getPlugin().getNamespacedKeyFactory().create("upgrade_crystal");
ItemStack out = new ItemStack(Material.END_CRYSTAL);
@@ -100,10 +86,10 @@ public class UpgradeCrystal {
PersistentDataContainer container = outMeta.getPersistentDataContainer();
container.set(key, PersistentDataType.STRING, tier);
outMeta.setDisplayName(Configs.CONFIG.getString("tier." + tier + ".crystal-name"));
outMeta.setDisplayName(EcoArmorConfigs.TIERS.getString(tier + ".crystal-name"));
List<String> lore = new ArrayList<>();
for (String loreLine : Configs.CONFIG.getStrings("tier." + tier + ".crystal-lore")) {
for (String loreLine : EcoArmorConfigs.TIERS.getStrings(tier + ".crystal-lore")) {
lore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
}
outMeta.setLore(lore);
@@ -115,9 +101,14 @@ public class UpgradeCrystal {
EcoShapedRecipe.Builder builder = EcoShapedRecipe.builder(this.getPlugin(), "upgrade_crystal_" + tier)
.setOutput(out);
List<String> recipeStrings = Configs.CONFIG.getStrings("tier." + tier + ".crystal-recipe");
List<String> recipeStrings = EcoArmorConfigs.TIERS.getStrings(tier + ".crystal-recipe");
RecipePartUtils.registerLookup("ecoarmor:upgrade_crystal_" + tier, s -> new ComplexRecipePart(test -> Objects.equals(tier, ArmorUtils.getCrystalTier(test)), out));
RecipePartUtils.registerLookup("ecoarmor:upgrade_crystal_" + tier, s -> new ComplexRecipePart(test -> {
if (ArmorUtils.getCrystalTier(test) == null) {
return false;
}
return Objects.equals(tier, ArmorUtils.getCrystalTier(test));
}, out));
for (int i = 0; i < 9; i++) {
builder.setRecipePart(i, RecipePartUtils.lookup(recipeStrings.get(i)));
@@ -138,11 +129,26 @@ public class UpgradeCrystal {
return BY_NAME.get(name);
}
/**
* Get all registered {@link UpgradeCrystal}s.
*
* @return A list of all {@link UpgradeCrystal}s.
*/
public static List<UpgradeCrystal> values() {
return ImmutableList.copyOf(BY_NAME.values());
}
/**
* Update.
*/
@ConfigUpdater
public static void reload() {
BY_NAME.clear();
for (String key : EcoArmorConfigs.TIERS.getConfig().getKeys(false)) {
new UpgradeCrystal(key);
}
BY_NAME.values().forEach(UpgradeCrystal::update);
}
}

View File

@@ -0,0 +1,46 @@
package com.willfp.ecoarmor.util;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
public class DiscoverRecipeListener extends PluginDependent implements Listener {
/**
* Register listener.
*
* @param plugin Talismans.
*/
public DiscoverRecipeListener(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Unlock all recipes on player join.
*
* @param event The event to listen for.
*/
@EventHandler
public void onJoin(@NotNull final PlayerJoinEvent event) {
Player player = event.getPlayer();
if (this.getPlugin().getConfigYml().getBool("discover-recipes")) {
Bukkit.getServer().recipeIterator().forEachRemaining(recipe -> {
if (recipe instanceof ShapedRecipe) {
NamespacedKey key = ((ShapedRecipe) recipe).getKey();
if (key.getNamespace().equals("ecoarmor")) {
if (!key.getKey().contains("displayed")) {
player.discoverRecipe(key);
}
}
}
});
}
}
}

View File

@@ -0,0 +1,21 @@
package com.willfp.ecoarmor.util;
import com.willfp.eco.util.proxy.AbstractProxy;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.proxy.util.ProxyFactory;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
@UtilityClass
public class ProxyUtils {
/**
* Get the implementation of a specified proxy.
*
* @param proxyClass The proxy interface.
* @param <T> The type of the proxy.
* @return The proxy implementation.
*/
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
return new ProxyFactory<>(EcoArmorPlugin.getInstance(), proxyClass).getProxy();
}
}

View File

@@ -3,70 +3,55 @@
# by Auxilor
#
tier:
default:
display: "&8&lDEFAULT"
# No crystal for default
discover-recipes: true # If all recipes should be automatically discovered.
iron:
display: "&7&lIRON"
crystal-craftable: true
crystal-name: "&7Iron Upgrade Crystal"
crystal-recipe:
- air
- iron_block
- air
- iron_block
- leather_chestplate
- iron_block
- air
- iron_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&7&lIRON"
diamond:
display: "&b&lDIAMOND"
crystal-craftable: true
crystal-name: "&bDiamond Upgrade Crystal"
crystal-recipe:
- air
- diamond_block
- air
- diamond_block
- ecoarmor:upgrade_crystal_iron
- diamond_block
- air
- diamond_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&b&lDIAMOND"
netherite:
display: "&c&lNETHERITE"
crystal-craftable: true
crystal-name: "&cNetherite Upgrade Crystal"
crystal-recipe:
- air
- netherite_block
- air
- netherite_block
- ecoarmor:upgrade_crystal_diamond
- netherite_block
- air
- netherite_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&c&lNETHERITE"
# Effects are passive abilities that happen when wearing a full set with the effect present.
effects:
attack-speed-multiplier:
# Changes attack speed by some multiplier
enabled: true
bonus-hearts:
# Extra hearts given to a player
enabled: true
bow-damage-multipier:
# Changes bow damage by some multiplier
enabled: true
damage-multipier:
# Changes damage from any form by some multiplier
enabled: true
damage-taken-multipier:
# Changes incoming damage by some multiplier
enabled: true
durability-multiplier:
# Changes durability for **all items in inventory** by some multiplier
enabled: true
evade-chance:
# Chance of avoiding attack, as a percentage
enabled: true
experience-multiplier:
# Changes experience gained by some multiplier
enabled: true
fall-damage-multiplier:
# Changes fall damage by some multiplier
enabled: true
flight:
# Allows flight
enabled: true
melee-damage-multiplier:
# Changes melee damage by some multiplier
enabled: true
regeneration-multiplier:
# Changes regeneration by some multiplier
enabled: true
speed-multiplier:
# Changes movement speed by some multiplier
enabled: true
trident-damage-multiplier:
# Changes trident damage by some multiplier
enabled: true
warp-chance:
# Chance to warp behind your opponent after damaging them, as a percentage
enabled: true
hunger-loss-multiplier:
# Modify hunger loss by some multiplier
enabled: true

View File

@@ -1,12 +1,12 @@
messages:
prefix: "&5&lEcoArmor&r &8» &r"
prefix: "&c&lEcoArmor&r &8» &r"
no-permission: "&cYou don't have permission to do this!"
not-player: "&cThis command must be run by a player"
reloaded: "Reloaded! (Restart if you're removed armor sets!)"
needs-player: "&cYou must specify a player"
invalid-player: "&cInvalid player!"
needs-set: "&cYou must specify a set"
invalid-set: "&cInvalid set!"
give-success: "Gave &a%set% Set&r to &a%recipient%"
needs-item: "&cYou must specify an item!"
invalid-item: "&cInvalid item!"
give-success: "Gave &a%item%&r to &a%recipient%"
description-color: "&8"

View File

@@ -6,6 +6,7 @@ authors: [ Auxilor ]
website: willfp.com
load: STARTUP
depend:
- eco
- ProtocolLib
softdepend:
- WorldGuard

View File

@@ -1,7 +1,206 @@
Reaper:
craftable: true
miner:
set-bonus:
experience-multiplier: 1.25
advanced-set-bonus:
hunger-loss-multiplier: 0.5
potion-effects:
fast_digging: 2
advanced-potion-effects:
fast_digging: 3
advanced-lore:
- ""
- "<GRADIENT:f12711>&lADVANCED BONUS</GRADIENT:f5af19>"
- "&8» &6Lose 50% less hunger"
- "&8» &6Permanent Haste III"
- "&8&oRequires full set to be worn"
advancement-shard-name: "<GRADIENT:f12711>Advancement Shard:</GRADIENT:f5af19> &9Miner"
advancement-shard-lore:
- "&8Drop this onto &9Miner Armor"
- "&8to make it <GRADIENT:f12711>Advanced</GRADIENT:f5af19>."
shard-craftable: true
shard-recipe:
- prismarine_shard
- ecoarmor:set_miner_helmet
- prismarine_shard
- ecoarmor:set_miner_chestplate
- nether_star
- ecoarmor:set_miner_leggings
- prismarine_shard
- ecoarmor:set_miner_boots
- prismarine_shard
helmet:
enchants:
fire_protection: 4
unbreaking: 1
material: leather_helmet
leather-color: "#6699cc"
name: "&9Miner Helmet"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&9 Miner Helmet"
effective-durability: 1024
lore:
- "&9&lMINER SET BONUS"
- "&8» &9Gain 50% more experience"
- "&8» &9Permanent Haste II"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- diamond_pickaxe
- air
- diamond_pickaxe
- diamond_helmet
- diamond_pickaxe
- air
- diamond_pickaxe
- air
chestplate:
enchants:
fire_protection: 4
unbreaking: 1
material: leather_chestplate
leather-color: "#6699cc"
name: "&9Miner Chestplate"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&9 Miner Chestplate"
effective-durability: 1024
lore:
- "&9&lMINER SET BONUS"
- "&8» &9Gain 50% more experience"
- "&8» &9Permanent Haste II"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- diamond_pickaxe
- air
- diamond_pickaxe
- diamond_chestplate
- diamond_pickaxe
- air
- diamond_pickaxe
- air
elytra:
enchants:
unbreaking: 1
material: elytra
name: "&9Miner Elytra"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&9 Miner Elytra"
effective-durability: 1024
lore:
- "&9&lMINER SET BONUS"
- "&8» &9Gain 50% more experience"
- "&8» &9Permanent Haste II"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- diamond_pickaxe
- air
- diamond_pickaxe
- elytra
- diamond_pickaxe
- air
- diamond_pickaxe
- air
leggings:
enchants:
fire_protection: 4
unbreaking: 1
material: leather_leggings
leather-color: "#6699cc"
name: "&9Miner Leggings"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&9 Miner Leggings"
effective-durability: 1024
lore:
- "&9&lMINER SET BONUS"
- "&8» &9Gain 50% more experience"
- "&8» &9Permanent Haste II"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- diamond_pickaxe
- air
- diamond_pickaxe
- diamond_leggings
- diamond_pickaxe
- air
- diamond_pickaxe
- air
boots:
enchants:
fire_protection: 4
unbreaking: 1
material: leather_boots
leather-color: "#6699cc"
name: "&9Miner Boots"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&9 Miner Boots"
effective-durability: 1024
lore:
- "&9&lMINER SET BONUS"
- "&8» &9Gain 50% more experience"
- "&8» &9Permanent Haste II"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- diamond_pickaxe
- air
- diamond_pickaxe
- diamond_boots
- diamond_pickaxe
- air
- diamond_pickaxe
- air
reaper:
set-bonus:
damage-multiplier: 1.25
advanced-set-bonus:
damage-taken-multiplier: 0.9
advanced-lore:
- ""
- "<GRADIENT:f12711>&lADVANCED BONUS</GRADIENT:f5af19>"
- "&8» &6Take 10% less damage"
- "&8&oRequires full set to be worn"
advancement-shard-name: "<GRADIENT:f12711>Advancement Shard:</GRADIENT:f5af19> &cReaper"
advancement-shard-lore:
- "&8Drop this onto &cReaper Armor"
- "&8to make it <GRADIENT:f12711>Advanced</GRADIENT:f5af19>."
shard-craftable: true
shard-recipe:
- prismarine_shard
- ecoarmor:set_reaper_helmet
- prismarine_shard
- ecoarmor:set_reaper_chestplate
- nether_star
- ecoarmor:set_reaper_leggings
- prismarine_shard
- ecoarmor:set_reaper_boots
- prismarine_shard
helmet:
enchants:
protection: 4
@@ -9,6 +208,8 @@ Reaper:
material: leather_helmet
leather-color: "#303030"
name: "&cReaper Helmet"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&c Reaper Helmet"
effective-durability: 2048
lore:
- "&c&lREAPER SET BONUS"
- "&8» &cDeal 25% more damage"
@@ -22,7 +223,7 @@ Reaper:
- air
- nether_star
- diamond_helmet
- netherite_helmet
- nether_star
- air
@@ -35,20 +236,22 @@ Reaper:
material: leather_chestplate
leather-color: "#303030"
name: "&cReaper Chestplate"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&c Reaper Chestplate"
effective-durability: 2048
lore:
- "&c&lREAPER SET BONUS"
- "&8» &cDeal 25% more damage"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with a Upgrade Crystal"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- nether_star
- air
- nether_star
- diamond_chestplate
- netherite_chestplate
- nether_star
- air
@@ -56,17 +259,18 @@ Reaper:
- air
elytra:
enchants:
protection: 4
unbreaking: 3
material: elytra
name: "&cReaper Elytra"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&c Reaper Elytra"
effective-durability: 2048
lore:
- "&c&lREAPER SET BONUS"
- "&8» &cDeal 25% more damage"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with a Upgrade Crystal"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- nether_star
@@ -86,20 +290,22 @@ Reaper:
material: leather_leggings
leather-color: "#303030"
name: "&cReaper Leggings"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&c Reaper Leggings"
effective-durability: 2048
lore:
- "&c&lREAPER SET BONUS"
- "&8» &cDeal 25% more damage"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with a Upgrade Crystal"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- nether_star
- air
- nether_star
- diamond_leggings
- netherite_leggings
- nether_star
- air
@@ -112,22 +318,195 @@ Reaper:
material: leather_boots
leather-color: "#303030"
name: "&cReaper Boots"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&c Reaper Boots"
effective-durability: 2048
lore:
- "&c&lREAPER SET BONUS"
- "&8» &cDeal 25% more damage"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with a Upgrade Crystal"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- nether_star
- air
- nether_star
- diamond_boots
- netherite_boots
- nether_star
- air
- nether_star
- air
- air
young:
set-bonus:
speed-multiplier: 1.25
advanced-set-bonus:
speed-multiplier: 1.5
advanced-potion-effects:
jump: 2
advanced-lore:
- ""
- "<GRADIENT:f12711>&lADVANCED BONUS</GRADIENT:f5af19>"
- "&8» &bPermanent Jump Boost II"
- "&8» &bMove 50% faster"
- "&8&oRequires full set to be worn"
advancement-shard-name: "<GRADIENT:f12711>Advancement Shard:</GRADIENT:f5af19> &bYoung"
advancement-shard-lore:
- "&8Drop this onto &bYoung Armor"
- "&8to make it <GRADIENT:f12711>Advanced</GRADIENT:f5af19>."
shard-craftable: true
shard-recipe:
- prismarine_shard
- ecoarmor:set_young_helmet
- prismarine_shard
- ecoarmor:set_young_chestplate
- nether_star
- ecoarmor:set_young_leggings
- prismarine_shard
- ecoarmor:set_young_boots
- prismarine_shard
helmet:
enchants:
protection: 2
unbreaking: 3
material: player_head
skull-texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWM0ODZhZjNiODgyNzY2ZTgyYTBiYzE2NjVmZjAyZWI2ZTg3M2I2ZTBkNzcxZjNhZGFiYzc1OWI3MjAyMjZhIn19fQ==
name: "&bYoung Helmet"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&b Young Helmet"
effective-durability: 768
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- diamond
- redstone
- diamond
- redstone
- air
- redstone
- air
- air
- air
chestplate:
enchants:
protection: 2
unbreaking: 3
material: leather_chestplate
leather-color: "#DDE4F0"
name: "&bYoung Chestplate"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&b Young Chestplate"
effective-durability: 768
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- diamond
- air
- diamond
- redstone
- diamond
- redstone
- diamond
- redstone
- diamond
elytra:
enchants:
unbreaking: 3
material: elytra
name: "&bYoung Elytra"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&b Young Elytra"
effective-durability: 768
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- redstone
- air
- redstone
- elytra
- redstone
- air
- redstone
- air
leggings:
enchants:
protection: 2
unbreaking: 3
material: leather_leggings
leather-color: "#DDE4F0"
name: "&bYoung Leggings"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&b Young Leggings"
effective-durability: 768
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- diamond
- redstone
- diamond
- redstone
- air
- redstone
- diamond
- air
- diamond
boots:
enchants:
protection: 2
unbreaking: 3
depth_strider: 3
material: leather_boots
leather-color: "#DDE4F0"
name: "&bYoung Boots"
advanced-name: "<GRADIENT:f12711>Advanced</GRADIENT:f5af19>&b Young Boots"
effective-durability: 768
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
recipe:
- air
- air
- air
- diamond
- air
- diamond
- redstone
- air
- redstone

View File

@@ -0,0 +1,453 @@
#
# You can make any tiers you want, but you **cannot** remove default
#
default:
display: "&8&lDEFAULT"
# No crystal for default
iron:
display: "&7&lIRON"
requires-tier: default # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "&7Iron Upgrade Crystal"
crystal-recipe:
- air
- iron_block
- air
- iron_block
- leather_chestplate
- iron_block
- air
- iron_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&7&lIRON"
properties:
helmet:
armor: 2
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
chestplate:
armor: 6
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
elytra:
armor: 2
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
leggings:
armor: 5
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
boots:
armor: 2
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
diamond:
display: "&b&lDIAMOND"
requires-tier: iron # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "&bDiamond Upgrade Crystal"
crystal-recipe:
- air
- diamond_block
- air
- diamond_block
- ecoarmor:upgrade_crystal_iron
- diamond_block
- air
- diamond_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&b&lDIAMOND"
properties:
helmet:
armor: 3
toughness: 2
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
chestplate:
armor: 8
toughness: 2
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
elytra:
armor: 3
toughness: 0
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
leggings:
armor: 6
toughness: 2
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
boots:
armor: 3
toughness: 2
knockback-resistance: 0
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
netherite:
display: "&c&lNETHERITE"
requires-tier: diamond # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "&cNetherite Upgrade Crystal"
crystal-recipe:
- air
- netherite_ingot
- air
- netherite_ingot
- ecoarmor:upgrade_crystal_diamond
- netherite_ingot
- air
- netherite_ingot
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&c&lNETHERITE"
properties:
helmet:
armor: 3
toughness: 3
knockback-resistance: 1
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
chestplate:
armor: 8
toughness: 3
knockback-resistance: 1
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
elytra:
armor: 3
toughness: 0
knockback-resistance: 1
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
leggings:
armor: 6
toughness: 3
knockback-resistance: 1
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
boots:
armor: 3
toughness: 3
knockback-resistance: 1
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
manyullyn:
display: "&d&k!!&r <GRADIENT:f953c6>&lMANYULLYN</GRADIENT:b91d73>&r &d&k!!&r"
requires-tier: netherite # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "<GRADIENT:f953c6>Manyullyn Upgrade Crystal</GRADIENT:b91d73>"
crystal-recipe:
- ecoarmor:upgrade_crystal_netherite
- enchanted_golden_apple
- ecoarmor:upgrade_crystal_netherite
- enchanted_golden_apple
- ecoarmor:upgrade_crystal_netherite
- enchanted_golden_apple
- ecoarmor:upgrade_crystal_netherite
- enchanted_golden_apple
- ecoarmor:upgrade_crystal_netherite
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&d&k!!&r <GRADIENT:f953c6>&lMANYULLYN</GRADIENT:b91d73>&r &d&k!!&r"
properties:
helmet:
armor: 3
toughness: 5
knockback-resistance: 2
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
chestplate:
armor: 8
toughness: 5
knockback-resistance: 2
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
elytra:
armor: 3
toughness: 0
knockback-resistance: 2
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
leggings:
armor: 6
toughness: 5
knockback-resistance: 2
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
boots:
armor: 3
toughness: 5
knockback-resistance: 2
speed-percentage: 0
attack-speed-percentage: 0
attack-damage-percentage: 0
attack-knockback-percentage: 0
cobalt:
display: "&#0047ab&lCOBALT"
requires-tier: iron # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "&#0047abCobalt Upgrade Crystal"
crystal-recipe:
- air
- obsidian
- air
- obsidian
- ecoarmor:upgrade_crystal_iron
- obsidian
- air
- obsidian
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&#0047ab&lCOBALT"
properties:
helmet:
armor: 3
toughness: 4
knockback-resistance: 1
speed-percentage: -10
attack-speed-percentage: -10
attack-damage-percentage: 0
attack-knockback-percentage: 10
chestplate:
armor: 8
toughness: 4
knockback-resistance: 1
speed-percentage: -10
attack-speed-percentage: -10
attack-damage-percentage: 0
attack-knockback-percentage: 10
elytra:
armor: 6
toughness: 2
knockback-resistance: 1
speed-percentage: -10
attack-speed-percentage: -10
attack-damage-percentage: 0
attack-knockback-percentage: 10
leggings:
armor: 6
toughness: 4
knockback-resistance: 1
speed-percentage: -10
attack-speed-percentage: -1
attack-damage-percentage: 0
attack-knockback-percentage: 10
boots:
armor: 3
toughness: 4
knockback-resistance: 1
speed-percentage: -10
attack-speed-percentage: -10
attack-damage-percentage: 0
attack-knockback-percentage: 10
osmium:
display: "&b&k!!&r <GRADIENT:c7f1ff>&lOSMIUM</GRADIENT:5c92ff>&r &b&k!!"
requires-tier: cobalt # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "<GRADIENT:c7f1ff>Osmium upgrade crystal</GRADIENT:5c92ff>"
crystal-recipe:
- air
- netherite_block
- air
- netherite_block
- ecoarmor:upgrade_crystal_cobalt
- netherite_block
- air
- netherite_block
- air
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&b&k!!&r <GRADIENT:c7f1ff>&lOSMIUM</GRADIENT:5c92ff>&r &b&k!!"
properties:
helmet:
armor: 3
toughness: 6
knockback-resistance: 3
speed-percentage: -15
attack-speed-percentage: -15
attack-damage-percentage: 5
attack-knockback-percentage: 25
chestplate:
armor: 8
toughness: 6
knockback-resistance: 3
speed-percentage: -15
attack-speed-percentage: -15
attack-damage-percentage: 5
attack-knockback-percentage: 25
elytra:
armor: 8
toughness: 6
knockback-resistance: 3
speed-percentage: -15
attack-speed-percentage: -15
attack-damage-percentage: 5
attack-knockback-percentage: 25
leggings:
armor: 6
toughness: 6
knockback-resistance: 3
speed-percentage: -15
attack-speed-percentage: -15
attack-damage-percentage: 5
attack-knockback-percentage: 25
boots:
armor: 3
toughness: 6
knockback-resistance: 3
speed-percentage: -15
attack-speed-percentage: -15
attack-damage-percentage: 5
attack-knockback-percentage: 25
exotic:
display: "&6&k!!&r <GRADIENT:f79d00>&lEXOTIC</GRADIENT:64f38c>&r &6&k!!&r"
requires-tier: netherite # Set to 'none' to always allow application
crystal-craftable: true
crystal-name: "<GRADIENT:f79d00>Exotic Upgrade Crystal</GRADIENT:64f38c>"
crystal-recipe:
- ecoarmor:upgrade_crystal_netherite
- turtle_egg
- ecoarmor:upgrade_crystal_netherite
- turtle_egg
- ecoarmor:upgrade_crystal_cobalt
- turtle_egg
- ecoarmor:upgrade_crystal_netherite
- turtle_egg
- ecoarmor:upgrade_crystal_netherite
crystal-lore:
- "&8Drop this onto an armor piece"
- "&8to set its tier to:"
- "&6&k!!&r <GRADIENT:f79d00>&lEXOTIC</GRADIENT:64f38c>&r &6&k!!&r"
properties:
helmet:
armor: 3
toughness: 2
knockback-resistance: 0
speed-percentage: 5
attack-speed-percentage: 10
attack-damage-percentage: -5
attack-knockback-percentage: -20
chestplate:
armor: 8
toughness: 2
knockback-resistance: 0
speed-percentage: 5
attack-speed-percentage: 10
attack-damage-percentage: -5
attack-knockback-percentage: -20
elytra:
armor: 3
toughness: 0
knockback-resistance: 0
speed-percentage: 5
attack-speed-percentage: 10
attack-damage-percentage: -5
attack-knockback-percentage: -20
leggings:
armor: 6
toughness: 2
knockback-resistance: 0
speed-percentage: 5
attack-speed-percentage: 10
attack-damage-percentage: -5
attack-knockback-percentage: -20
boots:
armor: 3
toughness: 2
knockback-resistance: 0
speed-percentage: 5
attack-speed-percentage: 10
attack-damage-percentage: -5
attack-knockback-percentage: -20

View File

@@ -1,14 +0,0 @@
package com.willfp.ecoarmor.proxy.proxies;
import com.willfp.eco.util.proxy.AbstractProxy;
import org.jetbrains.annotations.NotNull;
public interface ChatComponentProxy extends AbstractProxy {
/**
* Modify hover {@link org.bukkit.inventory.ItemStack}s using ArmorDisplay.
* @param object The NMS ChatComponent to modify.
* @return The modified ChatComponent.
*/
Object modifyComponent(@NotNull Object object);
}

View File

@@ -0,0 +1,75 @@
package com.willfp.ecoarmor.proxy.util;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.proxy.AbstractProxy;
import com.willfp.eco.util.proxy.ProxyConstants;
import com.willfp.eco.util.proxy.UnsupportedVersionException;
import org.jetbrains.annotations.NotNull;
import java.util.IdentityHashMap;
import java.util.Map;
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent {
/**
* Cached proxy implementations in order to not perform expensive reflective class-finding.
*/
private static final Map<Class<? extends AbstractProxy>, AbstractProxy> CACHE = new IdentityHashMap<>();
/**
* The class of the proxy interface.
*/
private final Class<T> proxyClass;
/**
* Create a new Proxy Factory for a specific type.
*
* @param plugin The plugin to create proxies for.
* @param proxyClass The class of the proxy interface.
*/
public ProxyFactory(@NotNull final AbstractEcoPlugin plugin,
@NotNull final Class<T> proxyClass) {
super(plugin);
this.proxyClass = proxyClass;
}
/**
* Get the implementation of a proxy.
*
* @return The proxy implementation.
*/
public @NotNull T getProxy() {
try {
T cachedProxy = attemptCache();
if (cachedProxy != null) {
return cachedProxy;
}
String className = this.getPlugin().getProxyPackage() + "." + ProxyConstants.NMS_VERSION + "." + proxyClass.getSimpleName().replace("Proxy", "");
final Class<?> class2 = Class.forName(className);
Object instance = class2.getConstructor().newInstance();
if (proxyClass.isAssignableFrom(class2) && proxyClass.isInstance(instance)) {
T proxy = proxyClass.cast(instance);
CACHE.put(proxyClass, proxy);
return proxy;
}
} catch (Exception e) {
// If not returned, then throw error
}
throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
}
private T attemptCache() {
Object proxy = CACHE.get(proxyClass);
if (proxy == null) {
return null;
}
if (proxyClass.isInstance(proxy)) {
return proxyClass.cast(proxy);
}
return null;
}
}