11.1.0 release

This commit is contained in:
mfnalex 2021-07-18 11:25:25 +02:00
parent 194a4f0a7a
commit 4719772e5e
4 changed files with 65 additions and 9 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
## 11.1.0
- Improved sorting for items enchanted with different types of Enchantments
## 11.0.3 ## 11.0.3
- Removed message "You are using the latest version of ChestSort" - Removed message "You are using the latest version of ChestSort"
- Updated Korean translation - Updated Korean translation

View File

@ -9,7 +9,7 @@
<name>ChestSort</name> <name>ChestSort</name>
<url>https://www.chestsort.de</url> <url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description> <description>Allows automatic chest sorting!</description>
<version>11.0.3</version> <version>11.1.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>

View File

@ -7,6 +7,7 @@ import de.jeff_media.chestsort.hooks.CrackShotHook;
import de.jeff_media.chestsort.hooks.InventoryPagesHook; import de.jeff_media.chestsort.hooks.InventoryPagesHook;
import de.jeff_media.chestsort.hooks.SlimeFunHook; import de.jeff_media.chestsort.hooks.SlimeFunHook;
import de.jeff_media.chestsort.data.CategoryLinePair; import de.jeff_media.chestsort.data.CategoryLinePair;
import de.jeff_media.chestsort.utils.EnchantmentUtils;
import de.jeff_media.chestsort.utils.TypeMatchPositionPair; import de.jeff_media.chestsort.utils.TypeMatchPositionPair;
import de.jeff_media.chestsort.utils.Utils; import de.jeff_media.chestsort.utils.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -163,7 +164,7 @@ public class ChestSortOrganizer {
return sortableInventories.contains(inv); return sortableInventories.contains(inv);
} }
static int getNumberOfEnchantments(ItemStack is) { /*static int getNumberOfEnchantments(ItemStack is) {
int totalEnchants = 0; int totalEnchants = 0;
@ -182,7 +183,7 @@ public class ChestSortOrganizer {
totalEnchants += level; totalEnchants += level;
} }
return totalEnchants; return totalEnchants;
} }*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted") @SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean doesInventoryContain(Inventory inv, Material mat) { boolean doesInventoryContain(Inventory inv, Material mat) {
@ -439,7 +440,7 @@ public class ChestSortOrganizer {
} }
// Put enchanted items before unenchanted ones // Put enchanted items before unenchanted ones
typeName = typeName + String.format("%05d", 10000 - getNumberOfEnchantments(item)); typeName = typeName + EnchantmentUtils.getEnchantmentString(item); //String.format("%05d", 10000 - getNumberOfEnchantments(item));
// Generate the map of string replacements used to generate a sortableString. // Generate the map of string replacements used to generate a sortableString.
// This map can be edited by ChestSortEvent handlers. See ChestSortEvent.getSortableMaps() // This map can be edited by ChestSortEvent handlers. See ChestSortEvent.getSortableMaps()
@ -490,11 +491,7 @@ public class ChestSortOrganizer {
chestSortEvent.setLocation(inv.getLocation()); chestSortEvent.setLocation(inv.getLocation());
} }
} }
} catch (Throwable throwable) { } catch (Throwable ignored) {
//System.out.println("Exception cought");
// I dont know, but this inv.getLocation() causes a NullPointerException when using EssentialsX's /ec command in 1.12
// Don't ask me why, but everything still works as expected if we catch that Exception.
// TODO Auto-generated catch block
} }

View File

@ -0,0 +1,56 @@
package de.jeff_media.chestsort.utils;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
public class EnchantmentUtils {
public static String getEnchantmentString(ItemStack item) {
StringBuilder builder = new StringBuilder(",");
builder.append(getInversedEnchantmentAmount(item));
if(!item.hasItemMeta()) return builder.toString();
ItemMeta meta = item.getItemMeta();
if(!meta.hasEnchants() && !(meta instanceof EnchantmentStorageMeta)) return builder.toString();
List<Enchantment> sortedEnchants = new ArrayList<>(meta.getEnchants().keySet());
sortedEnchants.sort(Comparator.comparing(o -> o.getKey().getKey()));
for(Enchantment enchantment : sortedEnchants) {
builder.append(",");
builder.append(enchantment.getKey().getKey());
builder.append(",");
builder.append(Integer.MAX_VALUE - meta.getEnchantLevel(enchantment));
}
if(meta instanceof EnchantmentStorageMeta) {
List<Enchantment> sortedStoredEnchants = new ArrayList<>(((EnchantmentStorageMeta)meta).getStoredEnchants().keySet());
for(Enchantment enchantment : sortedStoredEnchants) {
builder.append(",");
builder.append(enchantment.getKey().getKey());
builder.append(",");
builder.append(Integer.MAX_VALUE - meta.getEnchantLevel(enchantment));
}
}
return builder.toString();
}
public static int getInversedEnchantmentAmount(ItemStack item) {
int amount = Integer.MAX_VALUE;
ItemMeta meta = item.getItemMeta();
if(!meta.hasEnchants() && !(meta instanceof EnchantmentStorageMeta)) return amount;
for(int level : meta.getEnchants().values()) {
amount -= level;
}
if(meta instanceof EnchantmentStorageMeta) {
for(int level : ((EnchantmentStorageMeta)meta).getStoredEnchants().values()) {
amount -= level;
}
}
return amount;
}
}