Sort villager's products
This commit is contained in:
parent
d9be83ae62
commit
f85f3633fb
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.config;
|
||||
|
||||
import com.alttd.objects.ItemStackComparator;
|
||||
import com.alttd.objects.VillagerType;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.Material;
|
||||
|
|
@ -7,9 +8,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public final class Config extends AbstractConfig {
|
||||
|
||||
|
|
@ -166,8 +165,8 @@ public final class Config extends AbstractConfig {
|
|||
});
|
||||
}
|
||||
|
||||
private static HashSet<ItemStack> loadProducts(ConfigurationSection productsSection) {
|
||||
HashSet<ItemStack> products = new HashSet<>();
|
||||
private static TreeSet<ItemStack> loadProducts(ConfigurationSection productsSection) {
|
||||
TreeSet<ItemStack> products = new TreeSet<>(new ItemStackComparator());
|
||||
if (productsSection == null)
|
||||
return products;
|
||||
|
||||
|
|
|
|||
12
src/main/java/com/alttd/objects/ItemStackComparator.java
Normal file
12
src/main/java/com/alttd/objects/ItemStackComparator.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ItemStackComparator implements Comparator<ItemStack> {
|
||||
@Override
|
||||
public int compare(ItemStack o1, ItemStack o2) {
|
||||
return o1.getType().name().compareTo(o2.getType().name());
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class VillagerType {
|
||||
private static final Set<VillagerType> villagerTypes = new HashSet<>();
|
||||
|
|
@ -30,7 +31,7 @@ public class VillagerType {
|
|||
private final Set<ItemStack> selling;
|
||||
private final Villager.Profession profession;
|
||||
|
||||
public VillagerType(String name, String displayName, Set<ItemStack> buying, Set<ItemStack> selling, String profession) {
|
||||
public VillagerType(String name, String displayName, TreeSet<ItemStack> buying, TreeSet<ItemStack> selling, String profession) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.buying = buying;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user