Updated for 1.14

This commit is contained in:
Magnus Ulf 2019-04-26 21:21:08 +02:00
parent dbf5925e0d
commit cb8900d01e
5 changed files with 35 additions and 47 deletions

View File

@ -422,12 +422,12 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Class<?>> getClassesActive(String packageName, final Class<?> superClass, Predicate<Class<?>>... predicates) public List<Class<?>> getClassesActive(String packageName, final Class<?> superClass, Predicate<Class<?>>... predicates)
{ {
if (!Active.class.isAssignableFrom(superClass)) throw new IllegalArgumentException(superClass.getName() + " is not insatnce of Active."); if (!Active.class.isAssignableFrom(superClass)) throw new IllegalArgumentException(superClass.getName() + " is not instance of Active.");
packageName = packageName == null ? "" : "." + packageName; packageName = packageName == null ? "" : "." + packageName;
packageName = this.getClass().getPackage().getName() + packageName; packageName = this.getClass().getPackage().getName() + packageName;
Predicate predicateCombined = MUtil.predicatesAnd(predicates); Predicate predicateCombined = predicates.length > 0 ? MUtil.predicatesAnd(predicates) : x -> true;
Predicate<Class<?>> predicateNotAbstract = type -> !Modifier.isAbstract(type.getModifiers()); Predicate<Class<?>> predicateNotAbstract = type -> !Modifier.isAbstract(type.getModifiers());
Predicate<Class<?>> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers()); Predicate<Class<?>> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers());
Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get(); Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get();

View File

@ -1,11 +1,8 @@
package com.massivecraft.massivecore.command.type.enumeration; package com.massivecraft.massivecore.command.type.enumeration;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.Set;
public class TypeMaterial extends TypeEnum<Material> public class TypeMaterial extends TypeEnum<Material>
{ {
// -------------------------------------------- // // -------------------------------------------- //
@ -22,16 +19,4 @@ public class TypeMaterial extends TypeEnum<Material>
); );
} }
@SuppressWarnings("deprecation")
@Override
public Set<String> getIdsInner(Material value)
{
Set<String> ret = new MassiveSet<>(super.getIdsInner(value));
String id = String.valueOf(value.getId());
ret.add(id);
return ret;
}
} }

View File

@ -25,7 +25,7 @@ public class FlattenUtil
List<Object> ret = new MassiveList<>(); List<Object> ret = new MassiveList<>();
// Fill // Fill
for (Object item : (Iterable<Object>)packed) for (Object item : (Iterable<?>)packed)
{ {
// Recurse // Recurse
ret.addAll(flatten(item)); ret.addAll(flatten(item));

View File

@ -6,7 +6,6 @@ import com.massivecraft.massivecore.comparator.ComparatorComparable;
import com.massivecraft.massivecore.comparator.ComparatorEntryValue; import com.massivecraft.massivecore.comparator.ComparatorEntryValue;
import com.massivecraft.massivecore.event.EventMassiveCoreLorePriority; import com.massivecraft.massivecore.event.EventMassiveCoreLorePriority;
import com.massivecraft.massivecore.mixin.MixinInventory; import com.massivecraft.massivecore.mixin.MixinInventory;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateStringStartsWith; import com.massivecraft.massivecore.predicate.PredicateStringStartsWith;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -31,9 +30,9 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors;
public class InventoryUtil public class InventoryUtil
{ {
@ -971,7 +970,7 @@ public class InventoryUtil
InventoryHolder holder = inventory.getHolder(); InventoryHolder holder = inventory.getHolder();
int size = inventory.getSize(); int size = inventory.getSize();
if (inventory instanceof PlayerInventory) size = SIZE_PLAYER_STORAGE; if (inventory instanceof PlayerInventory) size = SIZE_PLAYER_STORAGE;
String title = inventory.getTitle(); String title = "";
ret = MixinInventory.get().createInventory(holder, size, title); ret = MixinInventory.get().createInventory(holder, size, title);
} }
@ -1229,25 +1228,21 @@ public class InventoryUtil
// -------------------------------------------- // // -------------------------------------------- //
// Return true on change // Return true on change
public static boolean removeLoreMatching(ItemStack item, Predicate<String> predicate) public static boolean removeLoreMatching(ItemStack item, java.util.function.Predicate<String> predicate)
{ {
if (predicate == null) throw new NullPointerException("prefix"); if (predicate == null) throw new NullPointerException("predicate");
List<String> lore = getLore(item); List<String> lore = getLore(item);
if (lore == null) return false; if (lore == null) return false;
boolean ret = false; List<String> newLore = lore.stream().filter(predicate).collect(Collectors.toList());
for (Iterator<String> it = lore.iterator(); it.hasNext();) if (lore.size() != newLore.size())
{ {
String line = it.next(); setLore(item, lore);
if (!predicate.apply(line)) continue; return true;
it.remove();
ret = true;
} }
setLore(item, lore); return false;
return ret;
} }
public static boolean removeLoreWithPrefix(ItemStack item, String prefix) public static boolean removeLoreWithPrefix(ItemStack item, String prefix)
@ -1255,21 +1250,14 @@ public class InventoryUtil
return removeLoreMatching(item, PredicateStringStartsWith.get(prefix)); return removeLoreMatching(item, PredicateStringStartsWith.get(prefix));
} }
public static List<String> getLoreMatching(ItemStack item, Predicate<String> predicate) public static List<String> getLoreMatching(ItemStack item, java.util.function.Predicate<String> predicate)
{ {
if (predicate == null) throw new NullPointerException("prefix"); if (predicate == null) throw new NullPointerException("predicate");
List<String> lore = getLore(item); List<String> lore = getLore(item);
if (lore == null) return null; if (lore == null) return null;
for (Iterator<String> it = lore.iterator(); it.hasNext();) return lore.stream().filter(predicate).collect(Collectors.toList());
{
String line = it.next();
if (predicate.apply(line)) continue;
it.remove();
}
return lore;
} }
public static List<String> getLoreWithPrefix(ItemStack item, String prefix) public static List<String> getLoreWithPrefix(ItemStack item, String prefix)

View File

@ -1,5 +1,6 @@
package com.massivecraft.massivecore.util; package com.massivecraft.massivecore.util;
import com.massivecraft.massivecore.collections.BackstringSet;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -239,14 +240,28 @@ public class SignUtil
// IS SIGN // IS SIGN
// -------------------------------------------- // // -------------------------------------------- //
public static final BackstringSet<Material> MATERIALS_SIGN = new BackstringSet<>(Material.class,
"SIGN", // Minecraft 1.?
"WALL_SIGN", // Minecraft 1.?
"ACACIA_SIGN", // Minecraft 1.14
"ACACIA_WALL_SIGN", // Minecraft 1.14
"BIRCH_SIGN", // Minecraft 1.14
"BIRCH_WALL_SIGN", // Minecraft 1.14
"DARK_OAK_SIGN", // Minecraft 1.14
"DARK_OAK_WALL_SIGN", // Minecraft 1.14
"JUNGLE_SIGN", // Minecraft 1.14
"JUNGLE_WALL_SIGN", // Minecraft 1.14
"OAK_SIGN", // Minecraft 1.14
"OAK_WALL_SIGN", // Minecraft 1.14
"SPRUCE_SIGN", // Minecraft 1.14
"SPRUCE_WALL_SIGN" // Minecraft 1.14
);
public static boolean isSign(Material material) public static boolean isSign(Material material)
{ {
if (material == null) throw new NullPointerException("material"); if (material == null) throw new NullPointerException("material");
if (material == Material.SIGN) return true; return MATERIALS_SIGN.contains(material);
if (material == Material.WALL_SIGN) return true;
return false;
} }
public static boolean isSign(Block block) public static boolean isSign(Block block)