mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a810f4262c
@ -7,7 +7,6 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation project(":eco-core").getSubprojects()
|
||||
implementation 'com.willfp:eco:1.1.3'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -50,7 +49,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:1.1.3'
|
||||
compileOnly 'com.willfp:eco:3.1.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
@ -72,10 +71,6 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('com.willfp.eco.', 'com.willfp.ecoenchants.eco.') // Dot is to prevent plugin being shaded into itself
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
@ -91,8 +86,6 @@ clean.doLast {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.apache.maven', 'com.willfp.ecoenchants.eco.shaded.maven')
|
||||
relocate('org.bstats', 'com.willfp.ecoenchants.eco.shaded.bstats')
|
||||
archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar"
|
||||
}
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
return object;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult());
|
||||
EnchantDisplay.addV(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
EnchantDisplay.displayEnchantments(selling);
|
||||
EnchantDisplay.addV(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.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.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
assert meta != null;
|
||||
boolean hideEnchants = false;
|
||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = true;
|
||||
}
|
||||
|
||||
itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
|
||||
EnchantDisplay.addV(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();
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult());
|
||||
EnchantDisplay.addV(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
EnchantDisplay.displayEnchantments(selling);
|
||||
EnchantDisplay.addV(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.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.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
assert meta != null;
|
||||
boolean hideEnchants = false;
|
||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = true;
|
||||
}
|
||||
|
||||
itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
|
||||
EnchantDisplay.addV(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();
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult());
|
||||
EnchantDisplay.addV(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
EnchantDisplay.displayEnchantments(selling);
|
||||
EnchantDisplay.addV(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.proxy.proxies.ChatComponentProxy;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
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.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
assert meta != null;
|
||||
boolean hideEnchants = false;
|
||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = true;
|
||||
}
|
||||
|
||||
itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
|
||||
EnchantDisplay.addV(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();
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult());
|
||||
EnchantDisplay.addV(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
EnchantDisplay.displayEnchantments(selling);
|
||||
EnchantDisplay.addV(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package com.willfp.ecoenchants;
|
||||
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
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.drops.telekinesis.TelekinesisUtils;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
||||
@ -14,11 +15,6 @@ import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.packets.PacketChat;
|
||||
import com.willfp.ecoenchants.display.packets.PacketOpenWindowMerchant;
|
||||
import com.willfp.ecoenchants.display.packets.PacketSetCreativeSlot;
|
||||
import com.willfp.ecoenchants.display.packets.PacketSetSlot;
|
||||
import com.willfp.ecoenchants.display.packets.PacketWindowItems;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
@ -37,10 +33,14 @@ import com.willfp.ecoenchants.integrations.mcmmo.plugins.McmmoIntegrationImpl;
|
||||
import com.willfp.ecoenchants.integrations.worldguard.WorldguardManager;
|
||||
import com.willfp.ecoenchants.integrations.worldguard.plugins.WorldguardIntegrationImpl;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -48,11 +48,18 @@ import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
/**
|
||||
* Instance of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private static EcoEnchantsPlugin instance;
|
||||
|
||||
/**
|
||||
* Internal constructor called by bukkit on plugin load.
|
||||
*/
|
||||
public EcoEnchantsPlugin() {
|
||||
super("EcoEnchants", 79573, 7666, "com.willfp.ecoenchants.proxy", "&a");
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,6 +67,21 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void enable() {
|
||||
Display.registerDisplayModule(new DisplayModule(itemStack -> {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
boolean hideEnchants = false;
|
||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = true;
|
||||
}
|
||||
|
||||
return EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
|
||||
}, 500, this.getPluginName()));
|
||||
Display.registerRevertModule(EnchantDisplay::revertDisplay);
|
||||
Display.registerFinalizeModule(EnchantDisplay::addV);
|
||||
|
||||
this.getExtensionLoader().loadExtensions();
|
||||
|
||||
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
||||
@ -88,7 +110,6 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
this.getExtensionLoader().unloadExtensions();
|
||||
}
|
||||
|
||||
@ -126,7 +147,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
@Override
|
||||
public void postLoad() {
|
||||
Bukkit.getServer().getWorlds().forEach(world -> {
|
||||
world.getPopulators().add(new LootPopulator());
|
||||
world.getPopulators().add(new LootPopulator(this));
|
||||
});
|
||||
EssentialsManager.registerEnchantments();
|
||||
}
|
||||
@ -168,13 +189,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
*/
|
||||
@Override
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return Arrays.asList(
|
||||
new PacketChat(this),
|
||||
new PacketOpenWindowMerchant(this),
|
||||
new PacketSetCreativeSlot(this),
|
||||
new PacketSetSlot(this),
|
||||
new PacketWindowItems(this)
|
||||
);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +204,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
new GrindstoneListeners(this),
|
||||
new AnvilListeners(this),
|
||||
new WatcherTriggers(this),
|
||||
new VillagerListeners(),
|
||||
new VillagerListeners(this),
|
||||
new HoldItemListener()
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.willfp.ecoenchants.command.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 CommandEcoreload 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"));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.willfp.ecoenchants.command.commands;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
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.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
@ -39,7 +38,7 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("missing-enchant"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("missing-enchant"));
|
||||
return;
|
||||
}
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
@ -51,7 +50,7 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
|
||||
|
||||
if (enchantment == null || !enchantment.isEnabled()) {
|
||||
String message = Configs.LANG.getMessage("not-found").replace("%name%", searchName);
|
||||
String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName);
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
@ -71,7 +70,7 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
|
||||
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName());
|
||||
} else {
|
||||
conflictNames.add(Configs.LANG.getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
|
||||
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
|
||||
}
|
||||
}));
|
||||
|
||||
@ -81,14 +80,14 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
if (allConflicts.length() >= 2) {
|
||||
allConflicts = allConflicts.substring(0, allConflicts.length() - 2);
|
||||
} else {
|
||||
allConflicts = StringUtils.translate(Configs.LANG.getString("no-conflicts"));
|
||||
allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts"));
|
||||
}
|
||||
|
||||
Set<Material> targets = enchantment.getTargetMaterials();
|
||||
|
||||
Set<String> applicableItemsSet = new HashSet<>();
|
||||
|
||||
if (Configs.CONFIG.getBool("commands.enchantinfo.show-target-group")) {
|
||||
if (this.getPlugin().getConfigYml().getBool("commands.enchantinfo.show-target-group")) {
|
||||
enchantment.getTargets().forEach(target -> {
|
||||
String targetName = target.getName();
|
||||
targetName = targetName.toLowerCase();
|
||||
@ -112,7 +111,7 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
if (allTargets.length() >= 2) {
|
||||
allTargets = allTargets.substring(0, allTargets.length() - 2);
|
||||
} else {
|
||||
allTargets = StringUtils.translate(Configs.LANG.getString("no-targets"));
|
||||
allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets"));
|
||||
}
|
||||
|
||||
String maxLevel = String.valueOf(enchantment.getMaxLevel());
|
||||
@ -122,7 +121,7 @@ public class CommandEnchantinfo extends AbstractCommand {
|
||||
final String finalTargets = allTargets;
|
||||
final String finalConflicts = allConflicts;
|
||||
final String finalMaxLevel = maxLevel;
|
||||
Arrays.asList(Configs.LANG.getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
|
||||
Arrays.asList(this.getPlugin().getLangYml().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
|
||||
string = string.replace("%name%", finalName)
|
||||
.replace("%description%", finalDescription)
|
||||
.replace("%target%", finalTargets)
|
||||
|
@ -2,7 +2,7 @@ package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.eco.util.config.ValueGetter;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@ -64,7 +64,7 @@ public abstract class EnchantmentYamlConfig extends PluginDependent implements V
|
||||
protected EnchantmentYamlConfig(@NotNull final String name,
|
||||
@NotNull final Class<?> source,
|
||||
@NotNull final EnchantmentType type) {
|
||||
super(AbstractEcoPlugin.getInstance());
|
||||
super(EcoEnchantsPlugin.getInstance());
|
||||
this.name = name;
|
||||
this.source = source;
|
||||
this.type = type;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoenchants.config.EnchantmentYamlConfig;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
@ -86,12 +85,12 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
* Load config values from lang.yml.
|
||||
*/
|
||||
public void loadFromLang() {
|
||||
if (!Configs.LANG.getConfig().contains("enchantments." + this.getName())) {
|
||||
if (!this.getPlugin().getLangYml().getConfig().contains("enchantments." + this.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getConfig().set("name", Configs.LANG.getString("enchantments." + this.getName() + ".name"));
|
||||
this.getConfig().set("description", Configs.LANG.getString("enchantments." + this.getName() + ".description"));
|
||||
this.getConfig().set("name", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".name"));
|
||||
this.getConfig().set("description", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".description"));
|
||||
try {
|
||||
this.getConfig().save(this.getConfigFile());
|
||||
} catch (IOException e) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -9,7 +11,7 @@ public class Rarity extends BaseConfig {
|
||||
* Instantiate rarity.yml.
|
||||
*/
|
||||
public Rarity() {
|
||||
super("rarity", false);
|
||||
super("rarity", false, EcoEnchantsPlugin.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -12,7 +14,7 @@ public class Target extends BaseConfig {
|
||||
* Instantiate target.yml.
|
||||
*/
|
||||
public Target() {
|
||||
super("target", false);
|
||||
super("target", false, EcoEnchantsPlugin.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,10 +4,13 @@ import com.google.common.collect.Lists;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -31,7 +34,7 @@ public class EnchantDisplay {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
|
||||
private static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The meta key to hide enchantments in lore.
|
||||
@ -55,7 +58,7 @@ public class EnchantDisplay {
|
||||
/**
|
||||
* The configurable options for displaying enchantments.
|
||||
*/
|
||||
public static final DisplayOptions OPTIONS = new DisplayOptions();
|
||||
public static final DisplayOptions OPTIONS = new DisplayOptions(PLUGIN);
|
||||
|
||||
/**
|
||||
* Update config values.
|
||||
@ -75,7 +78,7 @@ public class EnchantDisplay {
|
||||
* @return The item, with KEY_V.
|
||||
*/
|
||||
public static ItemStack addV(@Nullable final ItemStack item) {
|
||||
if (item == null || item.getItemMeta() == null) {
|
||||
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -228,7 +231,7 @@ public class EnchantDisplay {
|
||||
String name = EnchantmentCache.getEntry(enchantment).getName();
|
||||
|
||||
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||
if (OPTIONS.getNumbersOptions().isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersOptions().getThreshold()) {
|
||||
if (OPTIONS.getNumbersOptions().isUseNumerals() && ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(item, enchantment) < OPTIONS.getNumbersOptions().getThreshold()) {
|
||||
name += " " + NumberUtils.toNumeral(level);
|
||||
} else {
|
||||
name += " " + level;
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
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.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
@ -24,6 +25,11 @@ import java.util.Map;
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The physical cache.
|
||||
*/
|
||||
@ -82,17 +88,17 @@ public class EnchantmentCache {
|
||||
} else {
|
||||
description = Arrays.asList(
|
||||
WordUtils.wrap(
|
||||
String.valueOf(Configs.LANG.getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")),
|
||||
Configs.CONFIG.getInt("lore.describe.wrap"),
|
||||
String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")),
|
||||
PLUGIN.getConfigYml().getInt("lore.describe.wrap"),
|
||||
"\n", false
|
||||
).split("\\r?\\n")
|
||||
);
|
||||
name = String.valueOf(Configs.LANG.getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name"));
|
||||
name = String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name"));
|
||||
type = enchantment.isCursed() ? EnchantmentType.CURSE : EnchantmentType.NORMAL;
|
||||
if (enchantment.isTreasure()) {
|
||||
rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-treasure-rarity"));
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-treasure-rarity"));
|
||||
} else {
|
||||
rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-rarity"));
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +109,7 @@ public class EnchantmentCache {
|
||||
}
|
||||
|
||||
if (rarity == null) {
|
||||
rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-rarity"));
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"));
|
||||
}
|
||||
|
||||
String rawName = name;
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DescriptionOptions {
|
||||
public class DescriptionOptions extends PluginDependent {
|
||||
/**
|
||||
* The threshold below which to describe enchantments.
|
||||
*/
|
||||
@ -23,12 +25,21 @@ public class DescriptionOptions {
|
||||
@Getter
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Create new description options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public DescriptionOptions(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
threshold = Configs.CONFIG.getInt("lore.describe.before-lines");
|
||||
enabled = Configs.CONFIG.getBool("lore.describe.enabled");
|
||||
color = StringUtils.translate(Configs.LANG.getString("description-color"));
|
||||
threshold = this.getPlugin().getConfigYml().getInt("lore.describe.before-lines");
|
||||
enabled = this.getPlugin().getConfigYml().getBool("lore.describe.enabled");
|
||||
color = StringUtils.translate(this.getPlugin().getLangYml().getString("description-color"));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SorterManager;
|
||||
@ -8,6 +9,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -16,7 +18,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayOptions {
|
||||
public class DisplayOptions extends PluginDependent {
|
||||
/**
|
||||
* The enchantment sorter being used.
|
||||
*/
|
||||
@ -27,19 +29,19 @@ public class DisplayOptions {
|
||||
* The description options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions();
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions(this.getPlugin());
|
||||
|
||||
/**
|
||||
* The enchantment level options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions();
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions(this.getPlugin());
|
||||
|
||||
/**
|
||||
* The shrink options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions();
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions(this.getPlugin());
|
||||
|
||||
/**
|
||||
* The enchantment types, sorted according to config.
|
||||
@ -61,9 +63,12 @@ public class DisplayOptions {
|
||||
|
||||
/**
|
||||
* Instantiate new display options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public DisplayOptions() {
|
||||
public DisplayOptions(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
update();
|
||||
}
|
||||
|
||||
@ -76,24 +81,24 @@ public class DisplayOptions {
|
||||
shrinkOptions.update();
|
||||
|
||||
sortedTypes.clear();
|
||||
sortedTypes.addAll(Configs.CONFIG.getStrings("lore.type-ordering").stream()
|
||||
sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream()
|
||||
.map(typeName -> EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedTypes.addAll(EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList()));
|
||||
|
||||
sortedRarities.clear();
|
||||
sortedRarities.addAll(Configs.CONFIG.getStrings("lore.rarity-ordering").stream()
|
||||
sortedRarities.addAll(this.getPlugin().getConfigYml().getStrings("lore.rarity-ordering").stream()
|
||||
.map(rarityName -> EnchantmentRarity.values().stream().filter(rarity -> rarity.getName().equalsIgnoreCase(rarityName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedRarities.addAll(EnchantmentRarity.values().stream().filter(enchantmentRarity -> !sortedRarities.contains(enchantmentRarity)).collect(Collectors.toList()));
|
||||
|
||||
useLoreGetter = Configs.CONFIG.getBool("advanced.lore-getter");
|
||||
useLoreGetter = this.getPlugin().getConfigYml().getBool("advanced.lore-getter");
|
||||
|
||||
boolean byType = Configs.CONFIG.getBool("lore.sort-by-type");
|
||||
boolean byLength = Configs.CONFIG.getBool("lore.sort-by-length");
|
||||
boolean byRarity = Configs.CONFIG.getBool("lore.sort-by-rarity");
|
||||
boolean byType = this.getPlugin().getConfigYml().getBool("lore.sort-by-type");
|
||||
boolean byLength = this.getPlugin().getConfigYml().getBool("lore.sort-by-length");
|
||||
boolean byRarity = this.getPlugin().getConfigYml().getBool("lore.sort-by-rarity");
|
||||
Set<SortParameters> params = new HashSet<>();
|
||||
if (byType) {
|
||||
params.add(SortParameters.TYPE);
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NumbersOptions {
|
||||
public class NumbersOptions extends PluginDependent {
|
||||
/**
|
||||
* If numerals should be used.
|
||||
* <p>
|
||||
@ -18,11 +20,20 @@ public class NumbersOptions {
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
/**
|
||||
* Create new numbers options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public NumbersOptions(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
useNumerals = Configs.CONFIG.getBool("lore.use-numerals");
|
||||
threshold = Configs.CONFIG.getInt("lore.use-numbers-above-threshold");
|
||||
useNumerals = this.getPlugin().getConfigYml().getBool("lore.use-numerals");
|
||||
threshold = this.getPlugin().getConfigYml().getInt("lore.use-numbers-above-threshold");
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ShrinkOptions {
|
||||
public class ShrinkOptions extends PluginDependent {
|
||||
/**
|
||||
* The threshold above which enchantments will be shrunk.
|
||||
*/
|
||||
@ -22,12 +24,21 @@ public class ShrinkOptions {
|
||||
@Getter
|
||||
private int shrinkPerLine;
|
||||
|
||||
/**
|
||||
* Create new shrink options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public ShrinkOptions(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
threshold = Configs.CONFIG.getInt("lore.shrink.after-lines");
|
||||
enabled = Configs.CONFIG.getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = Configs.CONFIG.getInt("lore.shrink.maximum-per-line");
|
||||
threshold = this.getPlugin().getConfigYml().getInt("lore.shrink.after-lines");
|
||||
enabled = this.getPlugin().getConfigYml().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = this.getPlugin().getConfigYml().getInt("lore.shrink.maximum-per-line");
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public class AlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
public class LengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
}
|
||||
|
||||
|
@ -12,15 +12,20 @@ import java.util.List;
|
||||
|
||||
public class RarityAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
toSort.forEach(enchantment -> {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) {
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
});
|
||||
}
|
||||
rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
@ -13,15 +13,19 @@ import java.util.List;
|
||||
|
||||
public class RarityLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
toSort.forEach(enchantment -> {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) {
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
});
|
||||
}
|
||||
rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
@ -9,24 +9,31 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
typeEnchants.forEach(enchantment -> {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) {
|
||||
for (Enchantment enchantment : typeEnchants) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
});
|
||||
}
|
||||
rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
@ -10,25 +10,34 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
typeEnchants.forEach(enchantment -> {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) {
|
||||
for (Enchantment enchantment : typeEnchants) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
});
|
||||
}
|
||||
rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -9,17 +9,24 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
|
@ -8,19 +8,24 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.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.MONITOR, 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#OPEN_WINDOW_MERCHANT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketOpenWindowMerchant(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
|
||||
|
||||
recipes = recipes.stream().peek(merchantRecipe -> {
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(merchantRecipe.getResult().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProxyUtils.getProxy(VillagerTradeProxy.class).displayTradeEnchantments(merchantRecipe);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
packet.getMerchantRecipeLists().writeSafely(0, recipes);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.display.EnchantDisplay;
|
||||
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.SET_CREATIVE_SLOT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
packet.getItemModifier().modify(0, EnchantDisplay::revertDisplay);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
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, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
packet.getItemModifier().modify(0, item -> {
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
item = EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.willfp.ecoenchants.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.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
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, 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(item -> {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if (item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
});
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
}
|
@ -2,10 +2,10 @@ package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
@ -44,7 +44,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
* Instance of EcoEnchants for enchantments to be able to access.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final AbstractEcoPlugin plugin = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The display name of the enchantment.
|
||||
@ -262,7 +262,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
* @return The description.
|
||||
*/
|
||||
public List<String> getWrappedDescription() {
|
||||
return Arrays.asList(WordUtils.wrap(description, Configs.CONFIG.getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
||||
return Arrays.asList(WordUtils.wrap(description, this.getPlugin().getConfigYml().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.VectorUtils;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.VectorUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -28,6 +28,10 @@ public class LuckyCatch extends EcoEnchant {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getItemLevel(item, this);
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -63,7 +63,7 @@ public class Shockwave extends EcoEnchant {
|
||||
.filter(entity1 -> entity1 != player)
|
||||
.filter(entity1 -> !entity1.hasMetadata("shockwaved"))
|
||||
.forEach((mob -> {
|
||||
((LivingEntity) mob).damage(finalDamage, player);
|
||||
((LivingEntity) mob).damage(finalDamage, entity);
|
||||
mob.setMetadata("shockwaved", this.getPlugin().getMetadataValueFactory().create(true));
|
||||
this.getPlugin().getScheduler().runLater(() -> mob.removeMetadata("shockwaved", this.getPlugin()), 10);
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.drops.DropQueue;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Spearfishing extends EcoEnchant {
|
||||
public Spearfishing() {
|
||||
super(
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.drops.DropQueue;
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
@ -10,6 +8,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -38,9 +37,10 @@ public class Telekinesis extends EcoEnchant {
|
||||
"telekinesis", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postUpdate() {
|
||||
always = Configs.CONFIG.getBool("drops.force-dropqueue");
|
||||
always = this.getPlugin().getConfigYml().getBool("drops.force-dropqueue");
|
||||
}
|
||||
|
||||
// For block drops
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.LightningUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.LightningUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
@ -2,10 +2,10 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -66,11 +66,24 @@ public class Soulbound extends EcoEnchant {
|
||||
player.setMetadata("soulbound-items", this.getPlugin().getMetadataValueFactory().create(soulboundItems));
|
||||
}
|
||||
|
||||
public boolean hasEmptyInventory(@NotNull final Player player) {
|
||||
for (ItemStack itemStack : player.getInventory().getContents()) {
|
||||
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
if (!hasEmptyInventory(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.hasMetadata("soulbound-items")) {
|
||||
return;
|
||||
}
|
||||
@ -97,7 +110,7 @@ public class Soulbound extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onDeath(@NotNull final EntityDeathEvent event) {
|
||||
public void onDeath(@NotNull final PlayerDeathEvent event) {
|
||||
event.getDrops().removeIf(itemStack -> itemStack.getItemMeta().getPersistentDataContainer().has(this.getPlugin().getNamespacedKeyFactory().create("soulbound"), PersistentDataType.INTEGER));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.spell;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.enchantments.itemtypes;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.willfp.ecoenchants.enchantments.itemtypes;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
@ -129,13 +128,13 @@ public abstract class Spell extends EcoEnchant {
|
||||
}
|
||||
|
||||
if (cooldown > 0) {
|
||||
String message = Configs.LANG.getMessage("on-cooldown").replace("%seconds%", String.valueOf(cooldown)).replace("%name%", EnchantmentCache.getEntry(this).getRawName());
|
||||
String message = this.getPlugin().getLangYml().getMessage("on-cooldown").replace("%seconds%", String.valueOf(cooldown)).replace("%name%", EnchantmentCache.getEntry(this).getRawName());
|
||||
player.sendMessage(message);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 0.5f);
|
||||
return;
|
||||
}
|
||||
|
||||
String message = Configs.LANG.getMessage("used-spell").replace("%name%", EnchantmentCache.getEntry(this).getRawName());
|
||||
String message = this.getPlugin().getLangYml().getMessage("used-spell").replace("%name%", EnchantmentCache.getEntry(this).getRawName());
|
||||
player.sendMessage(message);
|
||||
player.playSound(player.getLocation(), this.getActivationSound(), SoundCategory.PLAYERS, 1, 1);
|
||||
runnable.run();
|
||||
|
@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -119,6 +120,23 @@ public class EnchantmentRarity implements Registerable {
|
||||
return this.customColor != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@NotNull final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof EnchantmentRarity)) {
|
||||
return false;
|
||||
}
|
||||
EnchantmentRarity that = (EnchantmentRarity) o;
|
||||
return Objects.equals(getName(), that.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantmentRarity matching name.
|
||||
*
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
@ -12,9 +13,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EnchantmentType {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* All registered types.
|
||||
*/
|
||||
@ -28,7 +35,7 @@ public class EnchantmentType {
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType(
|
||||
"normal",
|
||||
false,
|
||||
() -> Configs.LANG.getString("not-curse-color")
|
||||
() -> PLUGIN.getLangYml().getString("not-curse-color")
|
||||
);
|
||||
|
||||
/**
|
||||
@ -39,7 +46,7 @@ public class EnchantmentType {
|
||||
public static final EnchantmentType CURSE = new EnchantmentType(
|
||||
"curse",
|
||||
false,
|
||||
() -> Configs.LANG.getString("curse-color")
|
||||
() -> PLUGIN.getLangYml().getString("curse-color")
|
||||
);
|
||||
|
||||
/**
|
||||
@ -49,8 +56,8 @@ public class EnchantmentType {
|
||||
*/
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType(
|
||||
"special",
|
||||
() -> !Configs.CONFIG.getBool("types.special.allow-multiple"),
|
||||
() -> Configs.LANG.getString("special-color")
|
||||
() -> !PLUGIN.getConfigYml().getBool("types.special.allow-multiple"),
|
||||
() -> PLUGIN.getLangYml().getString("special-color")
|
||||
);
|
||||
|
||||
/**
|
||||
@ -60,8 +67,8 @@ public class EnchantmentType {
|
||||
*/
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType(
|
||||
"artifact",
|
||||
() -> !Configs.CONFIG.getBool("types.artifact.allow-multiple"),
|
||||
() -> Configs.LANG.getString("artifact-color"),
|
||||
() -> !PLUGIN.getConfigYml().getBool("types.artifact.allow-multiple"),
|
||||
() -> PLUGIN.getLangYml().getString("artifact-color"),
|
||||
Artifact.class
|
||||
);
|
||||
|
||||
@ -73,7 +80,7 @@ public class EnchantmentType {
|
||||
public static final EnchantmentType SPELL = new EnchantmentType(
|
||||
"spell",
|
||||
true,
|
||||
() -> Configs.LANG.getString("spell-color"),
|
||||
() -> PLUGIN.getLangYml().getString("spell-color"),
|
||||
Spell.class
|
||||
);
|
||||
|
||||
@ -200,6 +207,23 @@ public class EnchantmentType {
|
||||
this.singular = singularSupplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@NotNull final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof EnchantmentType)) {
|
||||
return false;
|
||||
}
|
||||
EnchantmentType that = (EnchantmentType) o;
|
||||
return Objects.equals(getName(), that.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update suppliers of all types.
|
||||
*/
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.anvil;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.proxy.ProxyConstants;
|
||||
import com.willfp.eco.util.tuplets.Pair;
|
||||
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy;
|
||||
import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -110,7 +109,7 @@ public class AnvilListeners extends PluginDependent implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configs.CONFIG.getBool("anvil.rework-cost")) {
|
||||
if (this.getPlugin().getConfigYml().getBool("anvil.rework-cost")) {
|
||||
int repairCost = ProxyUtils.getProxy(RepairCostProxy.class).getRepairCost(item);
|
||||
int reworkCount = NumberUtils.log2(repairCost + 1);
|
||||
if (repairCost == 0) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.anvil;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.tuplets.Pair;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
@ -23,6 +23,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@UtilityClass
|
||||
public class AnvilMerge {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* Config key for allowing unsafe levels.
|
||||
*/
|
||||
@ -126,8 +131,8 @@ public class AnvilMerge {
|
||||
if (rightLevel > level) {
|
||||
level = rightLevel;
|
||||
} else if (rightLevel == level
|
||||
&& ((rightLevel > enchantment.getMaxLevel() && Configs.CONFIG.getBool("anvil.allow-combining-unsafe"))
|
||||
|| ((rightLevel + 1) <= enchantment.getMaxLevel() || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY)))) {
|
||||
&& ((rightLevel > enchantment.getMaxLevel() && PLUGIN.getConfigYml().getBool("anvil.allow-combining-unsafe"))
|
||||
|| ((rightLevel + 1) <= enchantment.getMaxLevel() || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY)))) {
|
||||
level++;
|
||||
}
|
||||
rightEnchants.remove(enchantment);
|
||||
@ -164,7 +169,7 @@ public class AnvilMerge {
|
||||
}
|
||||
|
||||
if (canEnchantItem && !doesConflict.get()) {
|
||||
if (Configs.CONFIG.getBool("anvil.hard-cap.enabled") && !player.hasPermission("ecoenchants.anvil.bypasshardcap") && outEnchants.size() >= Configs.CONFIG.getInt("anvil.hard-cap.cap")) {
|
||||
if (PLUGIN.getConfigYml().getBool("anvil.hard-cap.enabled") && !player.hasPermission("ecoenchants.anvil.bypasshardcap") && outEnchants.size() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) {
|
||||
return;
|
||||
}
|
||||
outEnchants.put(enchantment, integer);
|
||||
@ -189,7 +194,7 @@ public class AnvilMerge {
|
||||
}));
|
||||
|
||||
outEnchants.forEach(((enchantment, integer) -> {
|
||||
meta.addStoredEnchant(enchantment, integer, Configs.CONFIG.getBool("anvil.allow-existing-unsafe-levels") || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY));
|
||||
meta.addStoredEnchant(enchantment, integer, PLUGIN.getConfigYml().getBool("anvil.allow-existing-unsafe-levels") || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY));
|
||||
}));
|
||||
|
||||
meta.setDisplayName(name);
|
||||
@ -202,7 +207,7 @@ public class AnvilMerge {
|
||||
}));
|
||||
|
||||
outEnchants.forEach(((enchantment, integer) -> {
|
||||
meta.addEnchant(enchantment, integer, Configs.CONFIG.getBool("anvil.allow-existing-unsafe-levels") || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY));
|
||||
meta.addEnchant(enchantment, integer, PLUGIN.getConfigYml().getBool("anvil.allow-existing-unsafe-levels") || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY));
|
||||
}));
|
||||
|
||||
if (output.getItemMeta() instanceof Damageable) {
|
||||
@ -237,8 +242,8 @@ public class AnvilMerge {
|
||||
return new Pair<>(null, null);
|
||||
}
|
||||
|
||||
if (Configs.CONFIG.getBool("anvil.cost-exponent.enabled")) {
|
||||
double exponent = Configs.CONFIG.getDouble("anvil.cost-exponent.exponent");
|
||||
if (PLUGIN.getConfigYml().getBool("anvil.cost-exponent.enabled")) {
|
||||
double exponent = PLUGIN.getConfigYml().getDouble("anvil.cost-exponent.exponent");
|
||||
int prevDelta = totalEnchantLevelDelta;
|
||||
|
||||
double costMultiplier = Math.pow(exponent, totalEnchantLevelDelta);
|
||||
|
@ -2,7 +2,6 @@ package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
@ -76,7 +75,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
int cost = event.getExpLevelCost();
|
||||
|
||||
Map<Enchantment, Integer> toAdd = event.getEnchantsToAdd();
|
||||
if (!Configs.CONFIG.getBool("enchanting-table.enabled")) {
|
||||
if (!this.getPlugin().getConfigYml().getBool("enchanting-table.enabled")) {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
ItemStack item0 = event.getInventory().getItem(0);
|
||||
event.getInventory().setItem(0, item0);
|
||||
@ -105,11 +104,11 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
|
||||
double multiplier = 0.01;
|
||||
if (item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
multiplier /= Configs.CONFIG.getInt("enchanting-table.book-times-less-likely");
|
||||
multiplier /= this.getPlugin().getConfigYml().getInt("enchanting-table.book-times-less-likely");
|
||||
}
|
||||
|
||||
if (Configs.CONFIG.getBool("enchanting-table.reduce-probability.enabled")) {
|
||||
multiplier /= Configs.CONFIG.getDouble("enchanting-table.reduce-probability.factor");
|
||||
if (this.getPlugin().getConfigYml().getBool("enchanting-table.reduce-probability.enabled")) {
|
||||
multiplier /= this.getPlugin().getConfigYml().getDouble("enchanting-table.reduce-probability.factor");
|
||||
}
|
||||
|
||||
ArrayList<EcoEnchant> enchantments = new ArrayList<>(EcoEnchants.values());
|
||||
@ -164,11 +163,11 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
|
||||
if (enchantment.getType().equals(EnchantmentType.SPECIAL)) {
|
||||
double enchantlevel1 = NumberUtils.randFloat(0, 1);
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel3 = 1 / maxLevelDouble;
|
||||
level = (int) Math.ceil(enchantlevel2 / enchantlevel3);
|
||||
} else {
|
||||
int maxLevel = Configs.CONFIG.getInt("enchanting-table.maximum-obtainable-level");
|
||||
int maxLevel = this.getPlugin().getConfigYml().getInt("enchanting-table.maximum-obtainable-level");
|
||||
double enchantlevel1 = (cost / (double) enchantment.getRarity().getMinimumLevel()) / (maxLevel / (double) enchantment.getRarity().getMinimumLevel());
|
||||
double enchantlevel2 = NumberUtils.triangularDistribution(0, 1, enchantlevel1);
|
||||
double enchantlevel3 = 1 / maxLevelDouble;
|
||||
@ -178,7 +177,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
level = NumberUtils.equalIfOver(level, enchantment.getMaxLevel());
|
||||
toAdd.put(enchantment, level);
|
||||
|
||||
if (Configs.CONFIG.getBool("enchanting-table.cap-amount.enabled") && toAdd.size() >= Configs.CONFIG.getInt("enchanting-table.cap-amount.limit")) {
|
||||
if (this.getPlugin().getConfigYml().getBool("enchanting-table.cap-amount.enabled") && toAdd.size() >= this.getPlugin().getConfigYml().getInt("enchanting-table.cap-amount.limit")) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -186,8 +185,8 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
gotSpecial = true;
|
||||
}
|
||||
|
||||
if (Configs.CONFIG.getBool("enchanting-table.reduce-probability.enabled")) {
|
||||
multiplier /= Configs.CONFIG.getDouble("enchanting-table.reduce-probability.factor");
|
||||
if (this.getPlugin().getConfigYml().getBool("enchanting-table.reduce-probability.enabled")) {
|
||||
multiplier /= this.getPlugin().getConfigYml().getDouble("enchanting-table.reduce-probability.factor");
|
||||
}
|
||||
}
|
||||
toAdd.forEach(event.getEnchantsToAdd()::putIfAbsent);
|
||||
@ -197,8 +196,8 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
CURRENTLY_ENCHANTING_SECONDARY.remove(player);
|
||||
}
|
||||
|
||||
if (gotSpecial && Configs.CONFIG.getBool("enchanting-table.notify-on-special")) {
|
||||
player.sendMessage(Configs.LANG.getMessage("got-special"));
|
||||
if (gotSpecial && this.getPlugin().getConfigYml().getBool("enchanting-table.notify-on-special")) {
|
||||
player.sendMessage(this.getPlugin().getLangYml().getMessage("got-special"));
|
||||
}
|
||||
|
||||
// Ew
|
||||
@ -227,7 +226,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void secondaryEnchant(@NotNull final PrepareItemEnchantEvent event) {
|
||||
int maxLevel = Configs.CONFIG.getInt("enchanting-table.maximum-obtainable-level");
|
||||
int maxLevel = this.getPlugin().getConfigYml().getInt("enchanting-table.maximum-obtainable-level");
|
||||
|
||||
try {
|
||||
event.getOffers()[2].setCost(NumberUtils.equalIfOver(event.getOffers()[2].getCost(), maxLevel));
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
@ -28,6 +27,20 @@ import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class LootPopulator extends BlockPopulator {
|
||||
/**
|
||||
* Instance of ecoenchants.
|
||||
*/
|
||||
private final EcoEnchantsPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new loot populator.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public LootPopulator(@NotNull final EcoEnchantsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate a chunk's loot chests.
|
||||
*
|
||||
@ -38,7 +51,7 @@ public class LootPopulator extends BlockPopulator {
|
||||
public void populate(@NotNull final World world,
|
||||
@NotNull final Random random,
|
||||
@NotNull final Chunk chunk) {
|
||||
if (!Configs.CONFIG.getBool("loot.enabled")) {
|
||||
if (!plugin.getConfigYml().getBool("loot.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -69,11 +82,11 @@ public class LootPopulator extends BlockPopulator {
|
||||
|
||||
double multiplier = 0.01;
|
||||
if (item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
multiplier /= Configs.CONFIG.getInt("loot.book-times-less-likely");
|
||||
multiplier /= plugin.getConfigYml().getInt("loot.book-times-less-likely");
|
||||
}
|
||||
|
||||
if (Configs.CONFIG.getBool("loot.reduce-probability.enabled")) {
|
||||
multiplier /= Configs.CONFIG.getDouble("loot.reduce-probability.factor");
|
||||
if (plugin.getConfigYml().getBool("loot.reduce-probability.enabled")) {
|
||||
multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor");
|
||||
}
|
||||
|
||||
for (EcoEnchant enchantment : enchantments) {
|
||||
@ -119,7 +132,7 @@ public class LootPopulator extends BlockPopulator {
|
||||
|
||||
if (enchantment.getType().equals(EnchantmentType.SPECIAL)) {
|
||||
double enchantlevel1 = NumberUtils.randFloat(0, 1);
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, plugin.getConfigYml().getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel3 = 1 / (double) enchantment.getMaxLevel();
|
||||
level = (int) Math.ceil(enchantlevel2 / enchantlevel3);
|
||||
} else {
|
||||
@ -130,8 +143,8 @@ public class LootPopulator extends BlockPopulator {
|
||||
|
||||
toAdd.put(enchantment, level);
|
||||
|
||||
if (Configs.CONFIG.getBool("loot.reduce-probability.enabled")) {
|
||||
multiplier /= Configs.CONFIG.getDouble("loot.reduce-probability.factor");
|
||||
if (plugin.getConfigYml().getBool("loot.reduce-probability.enabled")) {
|
||||
multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@ package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
@ -24,7 +25,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class VillagerListeners implements Listener {
|
||||
public class VillagerListeners extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Create new villager listeners.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public VillagerListeners(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on villager gain trade.
|
||||
*
|
||||
@ -36,7 +46,7 @@ public class VillagerListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Configs.CONFIG.getBool("villager.enabled")) {
|
||||
if (!this.getPlugin().getConfigYml().getBool("villager.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -57,7 +67,7 @@ public class VillagerListeners implements Listener {
|
||||
ArrayList<EcoEnchant> enchantments = new ArrayList<>(EcoEnchants.values());
|
||||
Collections.shuffle(enchantments); // Prevent list bias towards early enchantments like telekinesis
|
||||
|
||||
double multiplier = 0.01 / Configs.CONFIG.getDouble("villager.book-times-less-likely");
|
||||
double multiplier = 0.01 / this.getPlugin().getConfigYml().getDouble("villager.book-times-less-likely");
|
||||
|
||||
for (EcoEnchant enchantment : enchantments) {
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) {
|
||||
@ -76,7 +86,7 @@ public class VillagerListeners implements Listener {
|
||||
|
||||
if (enchantment.getType().equals(EnchantmentType.SPECIAL)) {
|
||||
double enchantlevel1 = NumberUtils.randFloat(0, 1);
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel3 = 1 / (double) enchantment.getMaxLevel();
|
||||
level = (int) Math.ceil(enchantlevel2 / enchantlevel3);
|
||||
} else {
|
||||
@ -116,7 +126,7 @@ public class VillagerListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Configs.CONFIG.getBool("villager.enabled")) {
|
||||
if (!this.getPlugin().getConfigYml().getBool("villager.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,7 +193,7 @@ public class VillagerListeners implements Listener {
|
||||
|
||||
if (enchantment.getType().equals(EnchantmentType.SPECIAL)) {
|
||||
double enchantlevel1 = NumberUtils.randFloat(0, 1);
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias"));
|
||||
double enchantlevel3 = 1 / (double) enchantment.getMaxLevel();
|
||||
level = (int) Math.ceil(enchantlevel2 / enchantlevel3);
|
||||
} else {
|
||||
@ -196,8 +206,8 @@ public class VillagerListeners implements Listener {
|
||||
|
||||
toAdd.put(enchantment, level);
|
||||
|
||||
if (Configs.CONFIG.getBool("villager.reduce-probability.enabled")) {
|
||||
multiplier /= Configs.CONFIG.getDouble("villager.reduce-probability.factor");
|
||||
if (this.getPlugin().getConfigYml().getBool("villager.reduce-probability.enabled")) {
|
||||
multiplier /= this.getPlugin().getConfigYml().getDouble("villager.reduce-probability.factor");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.willfp.ecoenchants.util;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.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<>(EcoEnchantsPlugin.getInstance(), proxyClass).getProxy();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ authors: [Auxilor]
|
||||
website: willfp.com
|
||||
load: STARTUP
|
||||
depend:
|
||||
- eco
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
- WorldGuard
|
||||
|
@ -1,14 +0,0 @@
|
||||
package com.willfp.ecoenchants.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 EnchantDisplay#displayEnchantments.
|
||||
* @param object The NMS ChatComponent to modify.
|
||||
* @return The modified ChatComponent.
|
||||
*/
|
||||
Object modifyComponent(@NotNull Object object);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.willfp.ecoenchants.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public interface VillagerTradeProxy extends AbstractProxy {
|
||||
/**
|
||||
* Apply enchant display to the result of trades.
|
||||
*
|
||||
* @param merchantRecipe The recipe to modify.
|
||||
*/
|
||||
void displayTradeEnchantments(MerchantRecipe merchantRecipe);
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.willfp.ecoenchants.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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Alchemy Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.willfp.ecoenchants.alchemy;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AlchemyMain extends Extension {
|
||||
/**
|
||||
@ -9,6 +11,10 @@ public class AlchemyMain extends Extension {
|
||||
*/
|
||||
public static final EcoEnchant ALCHEMY = new Alchemy();
|
||||
|
||||
public AlchemyMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Handled by super
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Biomes Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -2,6 +2,7 @@ package com.willfp.ecoenchants.biomes;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.biomes.enchants.defensive.Elevation;
|
||||
import com.willfp.ecoenchants.biomes.enchants.defensive.Glacial;
|
||||
import com.willfp.ecoenchants.biomes.enchants.defensive.HeatTreated;
|
||||
@ -13,6 +14,7 @@ import com.willfp.ecoenchants.biomes.enchants.offensive.Dehydration;
|
||||
import com.willfp.ecoenchants.biomes.enchants.offensive.Icelord;
|
||||
import com.willfp.ecoenchants.biomes.enchants.offensive.Rainforest;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BiomesMain extends Extension {
|
||||
public static final EcoEnchant ELEVATION = new Elevation();
|
||||
@ -26,6 +28,10 @@ public class BiomesMain extends Extension {
|
||||
public static final EcoEnchant ICELORD = new Icelord();
|
||||
public static final EcoEnchant RAINFOREST = new Rainforest();
|
||||
|
||||
public BiomesMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Handled by super
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Effects Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -2,12 +2,14 @@ package com.willfp.ecoenchants.effects;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.effects.enchants.JumpBoost;
|
||||
import com.willfp.ecoenchants.effects.enchants.NightVision;
|
||||
import com.willfp.ecoenchants.effects.enchants.Regeneration;
|
||||
import com.willfp.ecoenchants.effects.enchants.Speed;
|
||||
import com.willfp.ecoenchants.effects.enchants.WaterBreathing;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EffectsMain extends Extension {
|
||||
public static final EcoEnchant JUMP_BOOST = new JumpBoost();
|
||||
@ -16,6 +18,10 @@ public class EffectsMain extends Extension {
|
||||
public static final EcoEnchant SPEED = new Speed();
|
||||
public static final EcoEnchant WATER_BREATHING = new WaterBreathing();
|
||||
|
||||
public EffectsMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Handled by super
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Endershot Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -2,11 +2,17 @@ package com.willfp.ecoenchants.endershot;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EndershotMain extends Extension {
|
||||
public static final EcoEnchant ENDERSHOT = new Endershot();
|
||||
|
||||
public EndershotMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Handled by super
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Firewand Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -1,11 +1,17 @@
|
||||
package com.willfp.ecoenchants.firewand;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FirewandMain extends Extension {
|
||||
public static final EcoEnchant FIREWAND = new Firewand();
|
||||
|
||||
public FirewandMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Handled by super
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'MMO Extension'
|
||||
|
||||
repositories {
|
||||
@ -9,7 +9,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'net.Indyuce:MMOCore:1.6'
|
||||
compileOnly 'net.Indyuce:MMOCore:1.6.2'
|
||||
compileOnly 'net.Indyuce:MMOItems:6.5'
|
||||
compileOnly 'net.Indyuce:MMOLib:1.7.3'
|
||||
}
|
||||
@ -18,6 +18,6 @@ configurations.all {
|
||||
exclude group: 'com.mojang', module: 'authlib'
|
||||
}
|
||||
|
||||
jar {
|
||||
shadowJar {
|
||||
archiveFileName = project.getDescription() + " v" + project.version + ".jar"
|
||||
}
|
@ -1,20 +1,10 @@
|
||||
package com.willfp.ecoenchants.mmo;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.mmo.enchants.abilities.Discounted;
|
||||
import com.willfp.ecoenchants.mmo.enchants.abilities.Recover;
|
||||
import com.willfp.ecoenchants.mmo.enchants.mana.Augment;
|
||||
import com.willfp.ecoenchants.mmo.enchants.mana.Drain;
|
||||
import com.willfp.ecoenchants.mmo.enchants.mana.Elixir;
|
||||
import com.willfp.ecoenchants.mmo.enchants.mana.Siphon;
|
||||
import com.willfp.ecoenchants.mmo.enchants.mana.Spirituality;
|
||||
import com.willfp.ecoenchants.mmo.enchants.misc.Strengthening;
|
||||
import com.willfp.ecoenchants.mmo.enchants.stamina.Athletic;
|
||||
import com.willfp.ecoenchants.mmo.enchants.stamina.Endurance;
|
||||
import com.willfp.ecoenchants.mmo.enchants.stamina.Fortitude;
|
||||
import com.willfp.ecoenchants.mmo.enchants.stamina.Motivate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MMOMain extends Extension {
|
||||
public static final EcoEnchant ELIXIR = new Elixir();
|
||||
@ -30,6 +20,10 @@ public class MMOMain extends Extension {
|
||||
public static final EcoEnchant ATHLETIC = new Athletic();
|
||||
public static final EcoEnchant STRENGTHENING = new Strengthening();
|
||||
|
||||
public MMOMain(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {
|
||||
if (!MMOPrerequisites.HAS_MMOCORE.isMet()) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.willfp.ecoenchants.mmo;
|
||||
|
||||
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.willfp.ecoenchants.mmo.enchants.mana;
|
||||
|
||||
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager;
|
||||
|
@ -1,14 +1,8 @@
|
||||
package com.willfp.ecoenchants.mmo.enchants.misc;
|
||||
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.mmo.structure.MMOEnchantment;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
import net.mmogroup.mmolib.api.stat.SharedStat;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Strengthening extends MMOEnchantment {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.willfp.ecoenchants.mmo.enchants.stamina;
|
||||
|
||||
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager;
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.willfp.ecoenchants.mmo.structure;
|
||||
|
||||
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.mmo.MMOPrerequisites;
|
||||
|
||||
public abstract class MMOEnchantment extends EcoEnchant implements MMOEnchant {
|
||||
protected MMOEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '3.0.1'
|
||||
version '4.0.0'
|
||||
description = 'Precision Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.willfp.ecoenchants.precision;
|
||||
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user