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")
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 = 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<?>> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers());
Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get();

View File

@ -1,11 +1,8 @@
package com.massivecraft.massivecore.command.type.enumeration;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Material;
import java.util.Set;
public class TypeMaterial extends TypeEnum<Material>
{
// -------------------------------------------- //
@ -21,17 +18,5 @@ public class TypeMaterial extends TypeEnum<Material>
Txt.parse("<aqua>https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java")
);
}
@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<>();
// Fill
for (Object item : (Iterable<Object>)packed)
for (Object item : (Iterable<?>)packed)
{
// Recurse
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.event.EventMassiveCoreLorePriority;
import com.massivecraft.massivecore.mixin.MixinInventory;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateStringStartsWith;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -31,9 +30,9 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
public class InventoryUtil
{
@ -971,7 +970,7 @@ public class InventoryUtil
InventoryHolder holder = inventory.getHolder();
int size = inventory.getSize();
if (inventory instanceof PlayerInventory) size = SIZE_PLAYER_STORAGE;
String title = inventory.getTitle();
String title = "";
ret = MixinInventory.get().createInventory(holder, size, title);
}
@ -1229,25 +1228,21 @@ public class InventoryUtil
// -------------------------------------------- //
// 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);
if (lore == null) return false;
boolean ret = false;
for (Iterator<String> it = lore.iterator(); it.hasNext();)
List<String> newLore = lore.stream().filter(predicate).collect(Collectors.toList());
if (lore.size() != newLore.size())
{
String line = it.next();
if (!predicate.apply(line)) continue;
it.remove();
ret = true;
setLore(item, lore);
return true;
}
setLore(item, lore);
return ret;
return false;
}
public static boolean removeLoreWithPrefix(ItemStack item, String prefix)
@ -1255,21 +1250,14 @@ public class InventoryUtil
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);
if (lore == null) return null;
for (Iterator<String> it = lore.iterator(); it.hasNext();)
{
String line = it.next();
if (predicate.apply(line)) continue;
it.remove();
}
return lore;
return lore.stream().filter(predicate).collect(Collectors.toList());
}
public static List<String> getLoreWithPrefix(ItemStack item, String prefix)

View File

@ -1,5 +1,6 @@
package com.massivecraft.massivecore.util;
import com.massivecraft.massivecore.collections.BackstringSet;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
@ -238,15 +239,29 @@ public class SignUtil
// -------------------------------------------- //
// 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)
{
if (material == null) throw new NullPointerException("material");
if (material == Material.SIGN) return true;
if (material == Material.WALL_SIGN) return true;
return false;
return MATERIALS_SIGN.contains(material);
}
public static boolean isSign(Block block)