Fixing a shit ton of warning / code style and stuff (code inspector from IDEA)

This commit is contained in:
2022-07-10 00:55:56 +02:00
parent 276b1d323a
commit b6104a76c1
118 changed files with 1116 additions and 1574 deletions

View File

@@ -30,13 +30,13 @@ import fr.pandacube.lib.paper.util.BukkitEvent;
*/
public class GUIHotBar implements Listener {
private Map<ItemStack, BiConsumer<PlayerInventory, ItemStack>> itemsAndSetters = new HashMap<>();
private final Map<ItemStack, BiConsumer<PlayerInventory, ItemStack>> itemsAndSetters = new HashMap<>();
private Map<ItemStack, Consumer<Player>> itemsAndRunnables = new HashMap<>();
private final Map<ItemStack, Consumer<Player>> itemsAndRunnables = new HashMap<>();
private final int defltSlot;
private List<Player> currentPlayers = new ArrayList<>();
private final List<Player> currentPlayers = new ArrayList<>();
public GUIHotBar(int defaultSlot) {
defltSlot = Math.max(0, Math.min(8, defaultSlot));
@@ -50,7 +50,6 @@ public class GUIHotBar implements Listener {
* @param i the item stack
* @param setter code executed to put the item in the inventory. Additionally check for permission before doing the addition.
* @param run the Runnable to run when the user right click on the item in the hotbar.
* @return
*/
public GUIHotBar addItem(ItemStack i, BiConsumer<PlayerInventory, ItemStack> setter, Consumer<Player> run) {
itemsAndSetters.put(i, setter);
@@ -65,8 +64,7 @@ public class GUIHotBar implements Listener {
/**
* Add the hotbar elements to this player.
*
* The players is automatically removed when it quit. You can remove it before by calling {@link #removePlayer(Player)}.
* @param p
* The players is automatically removed when they quit. You can remove it before by calling {@link #removePlayer(Player)}.
*/
public void addPlayer(Player p) {
if (!currentPlayers.contains(p))
@@ -81,7 +79,6 @@ public class GUIHotBar implements Listener {
/**
* Detach this player from this hotbar manager and removes the managed items from the players inventory.
* @param p
*/
public void removePlayer(Player p) {
if (!currentPlayers.contains(p))
@@ -134,7 +131,7 @@ public class GUIHotBar implements Listener {
ItemStack item = event.getItemDrop().getItemStack();
for (ItemStack managed : itemsAndSetters.keySet()) {
if (item != null && item.isSimilar(managed)) {
if (item.isSimilar(managed)) {
event.setCancelled(true);
return;
}
@@ -173,12 +170,10 @@ public class GUIHotBar implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (event.getClickedInventory() == null || !(event.getClickedInventory() instanceof PlayerInventory))
if (event.getClickedInventory() == null || !(event.getClickedInventory() instanceof PlayerInventory inv))
return;
PlayerInventory inv = (PlayerInventory) event.getClickedInventory();
if (!currentPlayers.contains(inv.getHolder()))
if (!currentPlayers.contains((Player) inv.getHolder()))
return;
ItemStack item = event.getCurrentItem();

View File

@@ -30,11 +30,11 @@ public class GUIInventory implements Listener {
public static final Map<Enchantment, Integer> FAKE_ENCHANT = ImmutableMap.of(Enchantment.DURABILITY, 1);
private Player player;
private Inventory inv;
private final Player player;
private final Inventory inv;
private Consumer<InventoryCloseEvent> onCloseEvent;
private boolean isOpened = false;
private Map<Integer, Consumer<InventoryClickEvent>> onClickEvents;
private final Map<Integer, Consumer<InventoryClickEvent>> onClickEvents;
public GUIInventory(Player p, int nbLines, Chat title, Consumer<InventoryCloseEvent> closeEventAction,
Plugin pl) {

View File

@@ -139,9 +139,8 @@ public class NMSReflect {
/**
* @param mojName the binary name of the desired class, on the mojang mapping.
* @throws NullPointerException if there is no mapping for the provided Mojang mapped class.
* @throws ClassNotFoundException if there is a mapping, but the runtime class was not found.
*/
public static ClassMapping mojClass(String mojName) throws ClassNotFoundException {
public static ClassMapping mojClass(String mojName) {
return Objects.requireNonNull(CLASSES_BY_MOJ.get(mojName), "Unable to find the Mojang mapped class '" + mojName + "'");
}
@@ -339,7 +338,6 @@ public class NMSReflect {
* @param mojParametersType the list of parameters of the method.
* Each parameter type must be an instance of one of the following type:
* {@link Type}, {@link Class}, {@link ReflectClass} or {@link ClassMapping}.
* @return
* @throws IllegalArgumentException if one of the parameter has an invalid type
* @throws NullPointerException if one of the parameter is null, or if there is no mapping for the provided Mojang mapped method.
* @throws ClassNotFoundException if there is no runtime class to represent one of the provided parametersType.
@@ -368,7 +366,6 @@ public class NMSReflect {
/**
*
* @param mojName the Mojang mapped name of the field.
* @return
* @throws NullPointerException if there is no mapping for the provided Mojang mapped field.
* @throws NoSuchFieldException if there is no runtime method to represent the provided method.
*/
@@ -393,9 +390,7 @@ public class NMSReflect {
String classToPrint = isObfClass ? obfName : mojName;
String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1);
String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'");
String typeHTML = "<a href='#c" + id + "'" + htmlTitle + " class='cl'>" + classSimpleName + "</a>";
return typeHTML;
return "<a href='#c" + id + "'" + htmlTitle + " class='cl'>" + classSimpleName + "</a>";
}
@@ -420,7 +415,7 @@ public class NMSReflect {
String classToPrint = obf ? obfName : mojName;
int packageSep = classToPrint.lastIndexOf('.');
String classSimpleName = classToPrint.substring(packageSep + 1);
String classPackages = classToPrint.substring(0, packageSep > 0 ? packageSep : 0);
String classPackages = classToPrint.substring(0, Math.max(packageSep, 0));
String classHTML = (packageSep >= 0 ? (classPackages + ".") : "") + "<b class='cl'>" + classSimpleName + "</b>";
Type superClass = superClass(obf);
@@ -487,7 +482,7 @@ public class NMSReflect {
private static record MethodId(String name, List<Type> parametersType) implements Comparable<MethodId> {
private record MethodId(String name, List<Type> parametersType) implements Comparable<MethodId> {
@Override
public int compareTo(MethodId o) {
int cmp = name.compareTo(o.name);
@@ -497,14 +492,13 @@ public class NMSReflect {
}
private String toHTML(boolean isObfClass, boolean isStatic, boolean isFinal) {
String paramsHTML = parametersType.stream().map(p -> p.toHTML(isObfClass)).collect(Collectors.joining(", "));
String cl = "mtd";
if (isStatic)
cl += " st";
if (isFinal)
cl += " fn";
String identifierHTML = "<span class='" + cl + "'>" + name + "</span>(" + paramsHTML + ")";
return identifierHTML;
String paramsHTML = parametersType.stream().map(p -> p.toHTML(isObfClass)).collect(Collectors.joining(", "));
String cl = "mtd";
if (isStatic)
cl += " st";
if (isFinal)
cl += " fn";
return "<span class='" + cl + "'>" + name + "</span>(" + paramsHTML + ")";
}
public String toString() {
@@ -516,7 +510,7 @@ public class NMSReflect {
private static record MemberDesc<I extends Comparable<I>>(I identifier, Type returnType) {
private record MemberDesc<I extends Comparable<I>>(I identifier, Type returnType) {
private String toHTML(boolean isObfClass, boolean isStatic, boolean isFinal) {
String identifierHTML = "";
if (identifier instanceof MethodId mId)
@@ -541,7 +535,7 @@ public class NMSReflect {
List<Type> paramsType = new ArrayList<>();
while ((r = (char) descReader.read()) != ')') {
while (((char) descReader.read()) != ')') {
descReader.skip(-1);
paramsType.add(Type.parse(descReader));
}
@@ -565,8 +559,8 @@ public class NMSReflect {
private static abstract class MemberMapping<I extends Comparable<I>, R extends ReflectMember<?, ?, ?, ?>> {
private String htmlTypeChar;
/* package */ MemberDesc<I> obfDesc, mojDesc;
private final String htmlTypeChar;
/* package */ final MemberDesc<I> obfDesc, mojDesc;
/* package */ ClassMapping declaringClass;
private MemberMapping(String htmlType, MemberDesc<I> obfDesc, MemberDesc<I> mojDesc) {
htmlTypeChar = htmlType;

View File

@@ -141,14 +141,11 @@ public class Type implements Comparable<Type> {
/* package */ static Type parse(StringReader desc) {
try {
StringBuilder sbRaw = new StringBuilder();
int arrayDepth = 0;
char c;
while ((c = (char) desc.read()) == '[') {
sbRaw.append(c);
arrayDepth++;
}
sbRaw.append(c);
String type = switch(c) {
case 'Z' -> "boolean";
case 'B' -> "byte";
@@ -162,10 +159,8 @@ public class Type implements Comparable<Type> {
StringBuilder sbClass = new StringBuilder();
char r;
while ((r = (char) desc.read()) != ';') {
sbRaw.append(c);
sbClass.append(r);
}
sbRaw.append(c);
yield NMSReflect.binaryClassName(sbClass.toString());
}
default -> "void";

View File

@@ -1,18 +1,13 @@
package fr.pandacube.lib.paper.reflect.wrapper;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.function.Supplier;
import static fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper.unwrap;
import fr.pandacube.lib.core.util.MappedListView;
public class ReflectListWrapper<W extends ReflectWrapperI> extends AbstractList<W> implements ReflectWrapperTypedI<List<Object>> {
public class ReflectListWrapper<W extends ReflectWrapperI> extends MappedListView<Object, W> implements ReflectWrapperTypedI<List<Object>> {
private final List<Object> wrappedList;
private final Class<W> expectedWrapperClass;
/* package */ ReflectListWrapper(Class<W> expectedWrapperClass) {
@@ -25,159 +20,23 @@ public class ReflectListWrapper<W extends ReflectWrapperI> extends AbstractList<
this((List<Object>) (listCreator == null ? new ArrayList<>() : listCreator.get()), expectedWrapperClass);
}
/* package */ ReflectListWrapper(List<Object> wrappedList, Class<W> expectedWrapperClass) {
this.wrappedList = Objects.requireNonNull(wrappedList);
super(wrappedList, el -> ReflectWrapper.wrap(el, expectedWrapperClass), ReflectWrapper::unwrap);
this.expectedWrapperClass = expectedWrapperClass;
}
@SuppressWarnings("unchecked")
@Override
public Class<List<Object>> __getRuntimeClass() {
return (Class<List<Object>>) wrappedList.getClass();
return (Class<List<Object>>) backend.getClass();
}
@Override
public List<Object> __getRuntimeInstance() {
return wrappedList;
}
private W wrap(Object el) {
return ReflectWrapper.wrap(el, expectedWrapperClass);
}
@Override
public W get(int index) {
return wrap(wrappedList.get(index));
}
@Override
public int size() {
return wrappedList.size();
}
@Override
public boolean add(W w) {
return wrappedList.add(unwrap(w));
}
@Override
public W set(int index, W element) {
return wrap(wrappedList.set(index, unwrap(element)));
}
@Override
public void add(int index, W element) {
wrappedList.add(index, unwrap(element));
}
@Override
public W remove(int index) {
return wrap(wrappedList.remove(index));
}
@Override
public int indexOf(Object o) {
return wrappedList.indexOf(o instanceof ReflectWrapperI w ? w.__getRuntimeInstance() : o);
}
@Override
public int lastIndexOf(Object o) {
return wrappedList.lastIndexOf(o instanceof ReflectWrapperI w ? w.__getRuntimeInstance() : o);
}
@Override
public void clear() {
wrappedList.clear();
}
@Override
public Iterator<W> iterator() {
return new Iterator<W>() {
final Iterator<Object> wrappedIt = wrappedList.iterator();
@Override
public boolean hasNext() {
return wrappedIt.hasNext();
}
@Override
public W next() {
return wrap(wrappedIt.next());
}
@Override
public void remove() {
wrappedIt.remove();
}
};
}
@Override
public ListIterator<W> listIterator() {
return listIterator(0);
}
@Override
public ListIterator<W> listIterator(int index) {
return new ListIterator<W>() {
final ListIterator<Object> wrappedIt = wrappedList.listIterator(index);
@Override
public boolean hasNext() {
return wrappedIt.hasNext();
}
@Override
public W next() {
return wrap(wrappedIt.next());
}
@Override
public boolean hasPrevious() {
return wrappedIt.hasPrevious();
}
@Override
public W previous() {
return wrap(wrappedIt.previous());
}
@Override
public int nextIndex() {
return wrappedIt.nextIndex();
}
@Override
public int previousIndex() {
return wrappedIt.previousIndex();
}
@Override
public void remove() {
wrappedIt.remove();
}
@Override
public void set(W w) {
wrappedIt.set(unwrap(w));
}
@Override
public void add(W w) {
wrappedIt.add(unwrap(w));
}
};
return backend;
}
@Override
public List<W> subList(int fromIndex, int toIndex) {
return new ReflectListWrapper<>(wrappedList.subList(fromIndex, toIndex), expectedWrapperClass);
}
@Override
public boolean equals(Object o) {
return wrappedList.equals(o);
}
@Override
public int hashCode() {
return wrappedList.hashCode();
return new ReflectListWrapper<>(backend.subList(fromIndex, toIndex), expectedWrapperClass);
}
}

View File

@@ -25,6 +25,9 @@ public abstract class ReflectWrapper implements ReflectWrapperI {
public static <W extends ReflectWrapperI> W wrap(Object runtimeObj) {
return wrap(runtimeObj, null);
}
public static <T, W extends ReflectWrapperTypedI<T>> W wrapTyped(T runtimeObj, Class<W> expectedWrapperClass) {
return wrap(runtimeObj, expectedWrapperClass);
}
public static <W extends ReflectWrapperI> W wrap(Object runtimeObj, Class<W> expectedWrapperClass) {
if (runtimeObj == null)
return null;

View File

@@ -214,23 +214,10 @@ public class WrapperRegistry {
}
private static class RegistryEntry {
Class<?> runtimeClass;
Class<? extends ReflectWrapperI> wrapperClass;
Class<? extends ReflectWrapperI> concreteWrapperClass;
ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor;
public RegistryEntry(Class<?> runtimeClass, Class<? extends ReflectWrapperI> wrapperClass, Class<? extends ReflectWrapperI> concreteWrapperClass, ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor) {
this.runtimeClass = runtimeClass;
this.wrapperClass = wrapperClass;
this.concreteWrapperClass = concreteWrapperClass;
this.objectWrapperConstructor = objectWrapperConstructor;
}
private record RegistryEntry(Class<?> runtimeClass,
Class<? extends ReflectWrapperI> wrapperClass,
Class<? extends ReflectWrapperI> concreteWrapperClass,
ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor) {
}
}

View File

@@ -1,7 +1,6 @@
package fr.pandacube.lib.paper.reflect.wrapper.brigadier;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;

View File

@@ -10,11 +10,11 @@ import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(WorldVersion.__concrete.class)
public interface WorldVersion extends ReflectWrapperI {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
public static class __concrete extends ReflectWrapper implements WorldVersion {
class __concrete extends ReflectWrapper implements WorldVersion {
private __concrete(Object obj) {
super(obj);
}

View File

@@ -12,8 +12,9 @@ public class BlockPosArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.BlockPosArgument"));
private static final Reflect.ReflectMethod<?> blockPos = wrapEx(() -> MAPPING.mojMethod("blockPos"));
public static ArgumentType<?> blockPos() {
return (ArgumentType<?>) wrapReflectEx(() -> blockPos.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> blockPos() {
return (ArgumentType<Object>) wrapReflectEx(() -> blockPos.invokeStatic());
}
protected BlockPosArgument(Object obj) {

View File

@@ -12,8 +12,9 @@ public class ComponentArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ComponentArgument"));
private static final Reflect.ReflectMethod<?> textComponent = wrapEx(() -> MAPPING.mojMethod("textComponent"));
public static ArgumentType<?> textComponent() {
return (ArgumentType<?>) wrapReflectEx(() -> textComponent.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> textComponent() {
return (ArgumentType<Object>) wrapReflectEx(() -> textComponent.invokeStatic());
}
protected ComponentArgument(Object obj) {

View File

@@ -15,19 +15,19 @@ import static fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper.wrap;
@ConcreteWrapper(Coordinates.__concrete.class)
public interface Coordinates extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Coordinates"));
public static final Reflect.ReflectMethod<?> getPosition = wrapEx(() -> MAPPING.mojMethod("getPosition", CommandSourceStack.MAPPING));
public static final Reflect.ReflectMethod<?> getBlockPos = wrapEx(() -> MAPPING.mojMethod("getBlockPos", CommandSourceStack.MAPPING));
NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Coordinates"));
Reflect.ReflectMethod<?> getPosition = wrapEx(() -> MAPPING.mojMethod("getPosition", CommandSourceStack.MAPPING));
Reflect.ReflectMethod<?> getBlockPos = wrapEx(() -> MAPPING.mojMethod("getBlockPos", CommandSourceStack.MAPPING));
public default Vec3 getPosition(BukkitBrigadierCommandSource source) {
default Vec3 getPosition(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> getPosition.invoke(__getRuntimeInstance(), source)), Vec3.class);
}
public default BlockPos getBlockPos(BukkitBrigadierCommandSource source) {
default BlockPos getBlockPos(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> getBlockPos.invoke(__getRuntimeInstance(), source)), BlockPos.class);
}
static class __concrete extends ReflectWrapper implements Coordinates {
class __concrete extends ReflectWrapper implements Coordinates {
protected __concrete(Object obj) {
super(obj);
}

View File

@@ -15,20 +15,24 @@ public class EntityArgument extends ReflectWrapperTyped<ArgumentType<?>> {
private static final Reflect.ReflectMethod<?> player = wrapEx(() -> MAPPING.mojMethod("player"));
private static final Reflect.ReflectMethod<?> players = wrapEx(() -> MAPPING.mojMethod("players"));
public static ArgumentType<?> entity() {
return (ArgumentType<?>) wrapReflectEx(() -> entity.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> entity() {
return (ArgumentType<Object>) wrapReflectEx(() -> entity.invokeStatic());
}
public static ArgumentType<?> entities() {
return (ArgumentType<?>) wrapReflectEx(() -> entities.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> entities() {
return (ArgumentType<Object>) wrapReflectEx(() -> entities.invokeStatic());
}
public static ArgumentType<?> player() {
return (ArgumentType<?>) wrapReflectEx(() -> player.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> player() {
return (ArgumentType<Object>) wrapReflectEx(() -> player.invokeStatic());
}
public static ArgumentType<?> players() {
return (ArgumentType<?>) wrapReflectEx(() -> players.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> players() {
return (ArgumentType<Object>) wrapReflectEx(() -> players.invokeStatic());
}

View File

@@ -12,8 +12,9 @@ public class GameProfileArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.GameProfileArgument"));
private static final Reflect.ReflectMethod<?> gameProfile = wrapEx(() -> MAPPING.mojMethod("gameProfile"));
public static ArgumentType<?> gameProfile() {
return (ArgumentType<?>) wrapReflectEx(() -> gameProfile.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> gameProfile() {
return (ArgumentType<Object>) wrapReflectEx(() -> gameProfile.invokeStatic());
}
protected GameProfileArgument(Object obj) {

View File

@@ -12,8 +12,9 @@ public class ResourceLocationArgument extends ReflectWrapperTyped<ArgumentType<?
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ResourceLocationArgument"));
private static final Reflect.ReflectMethod<?> id = wrapEx(() -> MAPPING.mojMethod("id"));
public static ArgumentType<?> id() {
return (ArgumentType<?>) wrapReflectEx(() -> id.invokeStatic());
@SuppressWarnings("unchecked")
public static ArgumentType<Object> id() {
return (ArgumentType<Object>) wrapReflectEx(() -> id.invokeStatic());
}
protected ResourceLocationArgument(Object obj) {

View File

@@ -12,8 +12,9 @@ public class Vec3Argument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Vec3Argument"));
private static final Reflect.ReflectMethod<?> vec3 = wrapEx(() -> MAPPING.mojMethod("vec3", boolean.class));
public static ArgumentType<?> vec3(boolean centerIntegers) {
return (ArgumentType<?>) wrapReflectEx(() -> vec3.invokeStatic(centerIntegers));
@SuppressWarnings("unchecked")
public static ArgumentType<Object> vec3(boolean centerIntegers) {
return (ArgumentType<Object>) wrapReflectEx(() -> vec3.invokeStatic(centerIntegers));
}

View File

@@ -1,8 +1,6 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.core;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;

View File

@@ -12,17 +12,17 @@ import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
@ConcreteWrapper(Tag.__concrete.class)
public interface Tag extends ReflectWrapperI {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.Tag"));
public static final ReflectMethod<?> getAsString = wrapEx(() -> MAPPING.mojMethod("getAsString"));
ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.Tag"));
ReflectMethod<?> getAsString = wrapEx(() -> MAPPING.mojMethod("getAsString"));
public default String getAsString() {
default String getAsString() {
return wrapReflectEx(() -> (String) getAsString.invoke(__getRuntimeInstance()));
}
public static class __concrete extends ReflectWrapper implements Tag {
class __concrete extends ReflectWrapper implements Tag {
private __concrete(Object obj) {
super(obj);
}

View File

@@ -9,10 +9,10 @@ import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(Component.__concrete.class)
public interface Component extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.chat.Component"));
NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.chat.Component"));
public class __concrete extends ReflectWrapper implements Component {
class __concrete extends ReflectWrapper implements Component {
protected __concrete(Object obj) {
super(obj);
}

View File

@@ -9,9 +9,9 @@ import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(Packet.__concrete.class)
public interface Packet extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.Packet"));
NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.Packet"));
public class __concrete extends ReflectWrapper implements Packet {
class __concrete extends ReflectWrapper implements Packet {
protected __concrete(Object obj) {
super(obj);
}

View File

@@ -1,5 +1,7 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import org.bukkit.entity.Player;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
@@ -31,6 +33,11 @@ public class ServerPlayer extends Entity { // in NMS, ServerPlayer is not a dire
return wrap(wrapReflectEx(() -> connection.getValue(__getRuntimeInstance())), ServerGamePacketListenerImpl.class);
}
@Override
public Player getBukkitEntity() {
return (Player) super.getBukkitEntity();
}
protected ServerPlayer(Object obj) {
super(obj);
}

View File

@@ -9,10 +9,10 @@ import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(ProgressListener.__concrete.class)
public interface ProgressListener extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.util.ProgressListener"));
NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.util.ProgressListener"));
public class __concrete extends ReflectWrapper implements ProgressListener {
class __concrete extends ReflectWrapper implements ProgressListener {
protected __concrete(Object obj) {
super(obj);
}

View File

@@ -9,13 +9,13 @@ import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class SavedData extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.saveddata.SavedData"));
public static final Reflect.ReflectMethod<?> setDirty = wrapEx(() -> MAPPING.mojMethod("setDirty"));
private static final Reflect.ReflectMethod<?> setDirty = wrapEx(() -> MAPPING.mojMethod("setDirty"));
protected SavedData(Object obj) {
super(obj);
}
public void setDirty(boolean dirty) {
wrapReflectEx(() -> setDirty.invoke(__getRuntimeInstance(), dirty));
public void setDirty() {
wrapReflectEx(() -> setDirty.invoke(__getRuntimeInstance()));
}
}

View File

@@ -11,11 +11,11 @@ import org.bukkit.scheduler.BukkitTask;
import fr.pandacube.lib.paper.PandaLibPaper;
public class AutoUpdatedObject {
private static Plugin plugin = PandaLibPaper.getPlugin();
private static final Plugin plugin = PandaLibPaper.getPlugin();
private Runnable updater;
private List<BukkitTask> tasks = new ArrayList<>();
private final List<BukkitTask> tasks = new ArrayList<>();
protected AutoUpdatedObject() { }
@@ -52,7 +52,7 @@ public class AutoUpdatedObject {
}
public synchronized void cancel() {
tasks.forEach(t -> t.cancel());
tasks.forEach(BukkitTask::cancel);
tasks.clear();
}

View File

@@ -53,7 +53,7 @@ public class AABBBlock implements Iterable<BlockVector> {
center = new Vector((p1x_ + p2x_) / 2d, (p1y_ + p2y_) / 2d, (p1z_ + p2z_) / 2d);
volume = Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_);
volume = (long) Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_);
}
public boolean overlaps(Entity e) {
@@ -96,11 +96,11 @@ public class AABBBlock implements Iterable<BlockVector> {
@Override
public Iterator<BlockVector> iterator() {
return new Iterator<BlockVector>() {
return new Iterator<>() {
private int x = pos1.getBlockX(),
y = pos1.getBlockY(),
z = pos1.getBlockZ();
@Override
public boolean hasNext() {
return x < pos2.getBlockX();
@@ -108,7 +108,7 @@ public class AABBBlock implements Iterable<BlockVector> {
@Override
public BlockVector next() {
BlockVector bv = new BlockVector(x, y, z);
z++;
if (z >= pos2.getBlockZ()) {
y++;
@@ -118,7 +118,7 @@ public class AABBBlock implements Iterable<BlockVector> {
y = pos1.getBlockY();
}
}
return bv;
}
};
@@ -126,21 +126,16 @@ public class AABBBlock implements Iterable<BlockVector> {
public Iterable<Block> asBlockIterable(World w) {
return new Iterable<Block>() {
return () -> new Iterator<>() {
final Iterator<BlockVector> nested = AABBBlock.this.iterator();
@Override
public Iterator<Block> iterator() {
return new Iterator<Block>() {
Iterator<BlockVector> nested = AABBBlock.this.iterator();
@Override
public boolean hasNext() {
return nested.hasNext();
}
@Override
public Block next() {
BlockVector bv = nested.next();
return w.getBlockAt(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ());
}
};
public boolean hasNext() {
return nested.hasNext();
}
@Override
public Block next() {
BlockVector bv = nested.next();
return w.getBlockAt(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ());
}
};
}

View File

@@ -1,9 +1,6 @@
package fr.pandacube.lib.paper.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -20,11 +17,11 @@ public class AABBBlockGroup implements Iterable<BlockVector> {
public final List<AABBBlock> aabbBlocks;
public AABBBlockGroup(Collection<AABBBlock> in) {
aabbBlocks = Collections.unmodifiableList(new ArrayList<>(in));
aabbBlocks = List.copyOf(in);
}
public AABBBlockGroup(AABBBlock... in) {
aabbBlocks = Collections.unmodifiableList(Arrays.asList(in));
aabbBlocks = List.of(in);
}
@@ -42,7 +39,7 @@ public class AABBBlockGroup implements Iterable<BlockVector> {
}
public Vector getRandomPosition() {
double[] freq = aabbBlocks.stream().mapToDouble(b -> b.getVolume()).toArray();
double[] freq = aabbBlocks.stream().mapToDouble(AABBBlock::getVolume).toArray();
int i = RandomUtil.randomIndexOfFrequencies(freq);
return aabbBlocks.get(i).getRandomPosition();
}
@@ -56,7 +53,7 @@ public class AABBBlockGroup implements Iterable<BlockVector> {
@Override
public Iterator<BlockVector> iterator() {
return IteratorIterator.ofCollectionOfIterator(aabbBlocks.stream().map(b -> b.iterator()).toList());
return IteratorIterator.ofCollectionOfIterator(aabbBlocks.stream().map(AABBBlock::iterator).toList());
}
}

View File

@@ -95,17 +95,15 @@ public class AutoUpdatedBossBar implements Listener {
public synchronized void followLoginLogout(Predicate<Player> condition) {
playerCondition = condition;
if (followPlayerList == true)
if (followPlayerList)
return;
followPlayerList = true;
BukkitEvent.register(this);
Bukkit.getServer().getOnlinePlayers().forEach(p -> {
onPlayerJoin(new PlayerJoinEvent(p, Component.text("")));
});
Bukkit.getServer().getOnlinePlayers().forEach(p -> onPlayerJoin(new PlayerJoinEvent(p, Component.text(""))));
}
public synchronized void unfollowPlayerList() {
if (followPlayerList == false)
if (!followPlayerList)
return;
followPlayerList = false;
playerCondition = null;
@@ -115,7 +113,7 @@ public class AutoUpdatedBossBar implements Listener {
@EventHandler(priority=EventPriority.MONITOR)
public synchronized void onPlayerJoin(PlayerJoinEvent event) {
if (followPlayerList == false)
if (!followPlayerList)
return;
if (playerCondition != null && !playerCondition.test(event.getPlayer()))
return;
@@ -126,17 +124,13 @@ public class AutoUpdatedBossBar implements Listener {
@EventHandler(priority=EventPriority.HIGH)
public synchronized void onPlayerQuit(PlayerQuitEvent event) {
if (followPlayerList == false)
if (!followPlayerList)
return;
synchronized (bar) {
event.getPlayer().hideBossBar(bar);
}
}
/**
* Utility method to update the progress of the bossbar without unnecessary packet.
* @param title
*/
public void removeAll() {
synchronized (bar) {
for (Player p : Bukkit.getOnlinePlayers())
@@ -164,14 +158,13 @@ public class AutoUpdatedBossBar implements Listener {
@FunctionalInterface
public interface BarUpdater {
public void update(AutoUpdatedBossBar bar);
void update(AutoUpdatedBossBar bar);
}
/**
* Utility method to update the title of the bossbar without unnecessary packet.
* @param title
*/
public void setTitle(Chat title) {
synchronized (bar) {
@@ -179,14 +172,8 @@ public class AutoUpdatedBossBar implements Listener {
}
}
@Deprecated
public void setTitle(String title) {
setTitle(Chat.legacyText(title));
}
/**
* Utility method to update the color of the bossbar without unnecessary packet.
* @param title
*/
public void setColor(Color color) {
synchronized (bar) {
@@ -196,7 +183,6 @@ public class AutoUpdatedBossBar implements Listener {
/**
* Utility method to update the progress of the bossbar without unnecessary packet.
* @param title
*/
public void setProgress(double progress) {
synchronized (bar) {

View File

@@ -24,41 +24,24 @@ public class BukkitChatColorUtil {
// hmmm this is not that simple, of course
// black
switch (dye) {
case BLACK:
return ChatColor.of("#000000");
case RED:
return ChatColor.of("#650000");
case GREEN:
return ChatColor.of("#006500");
case BROWN:
return ChatColor.of("#361B07");
case BLUE:
return ChatColor.of("#000065");
case PURPLE:
return ChatColor.of("#3F0C5F");
case CYAN:
return ChatColor.of("#006565");
case LIGHT_GRAY:
return ChatColor.of("#535353");
case GRAY:
return ChatColor.of("#323232");
case PINK:
return ChatColor.of("#652947");
case LIME:
return ChatColor.of("#4B6500");
case YELLOW:
return ChatColor.of("#656500");
case LIGHT_BLUE:
return ChatColor.of("#3C4B51");
case MAGENTA:
return ChatColor.of("#650065");
case ORANGE:
return ChatColor.of("#65280C");
case WHITE:
return ChatColor.of("#656565");
}
throw new IllegalArgumentException("Unknown DyeColor: " + dye);
return switch (dye) {
case BLACK -> ChatColor.of("#000000");
case RED -> ChatColor.of("#650000");
case GREEN -> ChatColor.of("#006500");
case BROWN -> ChatColor.of("#361B07");
case BLUE -> ChatColor.of("#000065");
case PURPLE -> ChatColor.of("#3F0C5F");
case CYAN -> ChatColor.of("#006565");
case LIGHT_GRAY -> ChatColor.of("#535353");
case GRAY -> ChatColor.of("#323232");
case PINK -> ChatColor.of("#652947");
case LIME -> ChatColor.of("#4B6500");
case YELLOW -> ChatColor.of("#656500");
case LIGHT_BLUE -> ChatColor.of("#3C4B51");
case MAGENTA -> ChatColor.of("#650065");
case ORANGE -> ChatColor.of("#65280C");
case WHITE -> ChatColor.of("#656565");
};
}

View File

@@ -1,9 +1,7 @@
package fr.pandacube.lib.paper.util;
import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.PandaLibPaper;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
@@ -11,12 +9,11 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.RegisteredListener;
import org.bukkit.scheduler.BukkitTask;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.PandaLibPaper;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class BukkitEvent {
@@ -58,21 +55,19 @@ public class BukkitEvent {
// method retrieved from OB.plugin.SimplePluginManager#getEventListeners
public static HandlerList getHandlerList(Class<? extends Event> type) throws IllegalPluginAccessException {
public static HandlerList getHandlerList(Class<? extends Event> type) {
try {
Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList", new Class[0]);
method.setAccessible(true);
return (HandlerList)method.invoke(null, new Object[0]);
return (HandlerList) Reflect.ofClass(getRegistrationClass(type)).method("getHandlerList").invokeStatic();
}
catch (Exception e) {
catch (ReflectiveOperationException e) {
return null;
}
}
// method retrieved from OB.plugin.SimplePluginManager
private static Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) throws IllegalPluginAccessException {
private static Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) {
try {
clazz.getDeclaredMethod("getHandlerList", new Class[0]);
clazz.getDeclaredMethod("getHandlerList");
return clazz;
}
catch (NoSuchMethodException e) {
@@ -87,7 +82,7 @@ public class BukkitEvent {
public interface EventListener<E extends Event> extends Listener, EventExecutor {
public abstract void onEvent(E event);
void onEvent(E event);
@SuppressWarnings("unchecked")
@Override
@@ -123,13 +118,16 @@ public class BukkitEvent {
}
private AtomicReference<BukkitTask> listenerCheckTask = new AtomicReference<>();
private final AtomicReference<BukkitTask> listenerCheckTask = new AtomicReference<>();
private void checkIfListenerIsLast() {
synchronized (listenerCheckTask) {
if (listenerCheckTask.get() != null)
return;
RegisteredListener[] listeners = BukkitEvent.getHandlerList(eventClass).getRegisteredListeners();
HandlerList hList = BukkitEvent.getHandlerList(eventClass);
if (hList == null)
return;
RegisteredListener[] listeners = hList.getRegisteredListeners();
if (listeners[listeners.length - 1].getListener() != this) {
listenerCheckTask.set(Bukkit.getScheduler().runTask(PandaLibPaper.getPlugin(), () -> {
// need to re-register the event so we are last

View File

@@ -10,13 +10,12 @@ public class ColorUtil {
/*
* Rainbow
*/
private static List<Color> rainbowColors = new ArrayList<>();
private static final List<Color> rainbowColors = new ArrayList<>();
/**
* Get a rainbow color
* @param variation from 0 (include) to 1 (exclude).
* 0 is red, 1/6 is yellow, 2/6 is green, 3/6 is cyan, 4/6 is blue, 5/6 is magenta
* @return
*/
public static Color getRainbowColor(double variation) {
synchronized (rainbowColors) {

View File

@@ -4,7 +4,7 @@ import org.bukkit.entity.Player;
/**
* A utility for managing Player experience properly.<br/>
* https://gist.github.com/Jikoo/30ec040443a4701b8980
* <a href="https://gist.github.com/Jikoo/30ec040443a4701b8980">Github Gist - Jikoo</a>
*
* @author Jikoo
*/
@@ -13,7 +13,7 @@ public class ExperienceUtil {
/**
* Calculates a player's total exp based on level and progress to next.
*
* @see http://minecraft.gamepedia.com/Experience#Leveling_up
* @see <a href="http://minecraft.gamepedia.com/Experience#Leveling_up">Experience (#leveling up) - Minecraft Wiki</a>
*
* @param player the Player
*
@@ -26,14 +26,7 @@ public class ExperienceUtil {
/**
* Calculates total experience based on level.
*
* @see http://minecraft.gamepedia.com/Experience#Leveling_up
*
* "One can determine how much experience has been collected to reach a
* level using the equations:
*
* Total Experience = [Level]2 + 6[Level] (at levels 0-15)
* 2.5[Level]2 - 40.5[Level] + 360 (at levels 16-30)
* 4.5[Level]2 - 162.5[Level] + 2220 (at level 31+)"
* @see <a href="http://minecraft.gamepedia.com/Experience#Leveling_up">Experience (#leveling up) - Minecraft Wiki</a>
*
* @param level the level
*
@@ -60,7 +53,7 @@ public class ExperienceUtil {
}
/**
* @see http://minecraft.gamepedia.com/Experience#Leveling_up
* @see <a href="http://minecraft.gamepedia.com/Experience#Leveling_up">Experience (#leveling up) - Minecraft Wiki</a>
*
* "The formulas for figuring out how many experience orbs you need to
* get to the next level are as follows:

View File

@@ -17,7 +17,7 @@ import fr.pandacube.lib.core.util.RandomUtil;
public class GameWorldUtils implements Listener {
private static BiMap<String, World> gameWorld = new BiMap<>();
private static final BiMap<String, World> gameWorld = new BiMap<>();
public static World getOrLoadGameWorld(String world, Consumer<World> operationOnLoad) throws IOException {

View File

@@ -127,11 +127,6 @@ public class GeometryUtil {
/**
* Check if the path from <i>start</i> location to <i>end</i> pass through
* the axis aligned bounding box defined by <i>min</i> and <i>max</i>.
* @param start
* @param end
* @param min
* @param max
* @return
*/
public static boolean hasIntersection(Vector start, Vector end, Vector min, Vector max) {
final double epsilon = 0.0001f;
@@ -144,30 +139,30 @@ public class GeometryUtil {
ad.setY(Math.abs(ad.getY()));
ad.setZ(Math.abs(ad.getZ()));
if(Math.abs(c.getX()) > e.getX() + ad.getX()){
if (Math.abs(c.getX()) > e.getX() + ad.getX()){
return false;
}
if(Math.abs(c.getY()) > e.getY() + ad.getY()){
if (Math.abs(c.getY()) > e.getY() + ad.getY()){
return false;
}
if(Math.abs(c.getZ()) > e.getX() + ad.getZ()){
if (Math.abs(c.getZ()) > e.getX() + ad.getZ()){
return false;
}
if(Math.abs(d.getY() * c.getZ() - d.getZ() * c.getY()) > e.getY() * ad.getZ() + e.getZ() * ad.getY() + epsilon){
if (Math.abs(d.getY() * c.getZ() - d.getZ() * c.getY()) > e.getY() * ad.getZ() + e.getZ() * ad.getY() + epsilon){
return false;
}
if(Math.abs(d.getZ() * c.getX() - d.getX() * c.getZ()) > e.getZ() * ad.getX() + e.getX() * ad.getZ() + epsilon){
if (Math.abs(d.getZ() * c.getX() - d.getX() * c.getZ()) > e.getZ() * ad.getX() + e.getX() * ad.getZ() + epsilon){
return false;
}
if(Math.abs(d.getX() * c.getY() - d.getY() * c.getX()) > e.getX() * ad.getY() + e.getY() * ad.getX() + epsilon){
if (Math.abs(d.getX() * c.getY() - d.getY() * c.getX()) > e.getX() * ad.getY() + e.getY() * ad.getX() + epsilon){
return false;
}
return true;
}
@@ -243,7 +238,6 @@ public class GeometryUtil {
* contained in the provided {@link Location}.
* {@link Location#getYaw()} and {@link Location#getPitch()} values are automatically
* converted to conform {@link #yaw} and {@link #pitch} specification.
* @param l
*/
public DirectionalVector(Location l) {
this(
@@ -322,7 +316,6 @@ public class GeometryUtil {
* Set the yaw and the pitch of the provided {@link Location}
* with the values inside the current {@link DirectionalVector}
* after conversion of these values
* @param l
*/
public void putIntoLocation(Location l) {
/* std : -PI/2 : <0 ? +2PI : MC
@@ -352,7 +345,6 @@ public class GeometryUtil {
* If the current direction is the player face direction,
* this method return the direction of the back of the head.
* This is an alias of {@link #getOpposite()}
* @return
*/
public DirectionalVector getBackDirection() {
return getOpposite();
@@ -361,7 +353,6 @@ public class GeometryUtil {
/**
* If the current direction is the player face direction,
* this method return the direction of the bottom of the head.
* @return
*/
public DirectionalVector getBottomDirection() {
return new DirectionalVector(
@@ -373,7 +364,6 @@ public class GeometryUtil {
/**
* If the current direction is the player face direction,
* this method return the direction of the top of the head.
* @return
*/
public DirectionalVector getTopDirection() {
return new DirectionalVector(
@@ -387,7 +377,6 @@ public class GeometryUtil {
/**
* If the current direction is the player face direction,
* this method return the direction of the left of the head.
* @return
*/
public DirectionalVector getLeftDirection() {
return new DirectionalVector(
@@ -401,7 +390,6 @@ public class GeometryUtil {
/**
* If the current direction is the player face direction,
* this method return the direction of the right of the head.
* @return
*/
public DirectionalVector getRightDirection() {
return new DirectionalVector(

View File

@@ -52,7 +52,6 @@ public class ItemStackBuilder {
* of ItemStack as the parameter of this method.
*
* To create a builder that doesnt modify the provided ItemStack, use {@link #of(ItemStack)}.
* @param stack
* @return the builder
*/
public static ItemStackBuilder wrap(ItemStack stack) {
@@ -70,7 +69,7 @@ public class ItemStackBuilder {
private ItemStack stack;
private final ItemStack stack;
private ItemMeta cachedMeta;
private ItemStackBuilder(ItemStack base) {
@@ -91,10 +90,7 @@ public class ItemStackBuilder {
}
public ItemStackBuilder rawDisplayName(Component displayName) {
if (displayName != null)
getOrInitMeta().displayName(displayName);
else
getOrInitMeta().displayName(null);
getOrInitMeta().displayName(displayName);
updateMeta();
return this;
}
@@ -106,7 +102,7 @@ public class ItemStackBuilder {
return rawDisplayName(displayName.getAdv());
}
else
return rawDisplayName((Component) null);
return rawDisplayName(null);
}
public ItemStackBuilder rawLore(List<Component> lore) {

View File

@@ -29,9 +29,8 @@ public class LocationUtil {
/**
* Return a random secure location in the provided world, inside the current
* WorldBorder. Will be on the surface, for non-nether world, or below the roof of the nether world
* @param w
* @param checkCubo true if the returned location can't be in a /cubo
* @return
* @param w the world in which to pick a location
* @param extraSecureCheck provides extra checks to determine location security
*/
public static CompletableFuture<Location> getRandomSecureLocation(World w, Predicate<Location> extraSecureCheck) {
@@ -51,7 +50,7 @@ public class LocationUtil {
private static final int maxTryBeforeCancelRandomLocation = 75;
public static CompletableFuture<Location> getRandomSecureLocation(World w, Location min, Location max, Predicate<Location> extraSecureCheck) {
CompletableFuture<Location> future = new CompletableFuture<Location>();
CompletableFuture<Location> future = new CompletableFuture<>();
AtomicReference<BukkitTask> t = new AtomicReference<>();
AtomicInteger count = new AtomicInteger(0);
@@ -100,7 +99,7 @@ public class LocationUtil {
/**
*
* @param l
* @param l the source location
* @return a secure location with the same X and Z coordinate as the
* provided location, but Y modified to ensure security for player
* who will be teleported to this location.
@@ -128,7 +127,7 @@ public class LocationUtil {
public static boolean isAir(Block b) { return b.getType() == Material.AIR; }
public static boolean isSecureFloor(Block b) { return !isAir(b) && !dangerousBlocks.contains(b.getType()); }
public static Set<Material> dangerousBlocks = EnumSet.of(
public static final Set<Material> dangerousBlocks = EnumSet.of(
Material.LAVA,
Material.WATER,
Material.COBWEB,
@@ -141,7 +140,7 @@ public class LocationUtil {
Material.END_PORTAL,
Material.NETHER_PORTAL,
Material.END_GATEWAY
);
);
@@ -150,9 +149,6 @@ public class LocationUtil {
/**
* Check if the {@link Location} l is inside the cuboïd formed by the 2 others
* Locations min and max.
* @param l
* @param min
* @param max
* @return true if l is inside the cuboid min-max
*/
public static boolean isIn(Location l, Location min, Location max) {
@@ -168,8 +164,6 @@ public class LocationUtil {
/**
* Return a new location based on the linear interpolation between p0 and p1, according to the value c.
* @param p0
* @param p1
* @param c between 0 and 1. If 0, it returns p0 and if 1, returns p1. Other finite numbers are allowed, but the returned location wont be part of the {@code [p0;p1]} segment.
* @return The location, linearly interpolated between p0 and p1 with the value c. The yaw and pitch in the returned location are those of p0.
* @throws IllegalArgumentException if the provided locations are not in the same world.

View File

@@ -19,8 +19,8 @@ import fr.pandacube.lib.core.chat.Chat;
* Represents some special mob heads, also support creating player skulls and custom skulls.
*
* @author xigsag, SBPrime
*
* @see https://github.com/TigerHix/Hex-Utils/blob/9954159a323d12733b29c287a56980991cee2948/hex/util/Skull.java
*
* @see <a href="https://github.com/TigerHix/Hex-Utils/blob/9954159a323d12733b29c287a56980991cee2948/hex/util/Skull.java">github.com/TigerHix/Hex-Utils/hex/util/Skull.java</a>
*/
public enum Skull {
@@ -60,9 +60,9 @@ public enum Skull {
TNT("MHF_TNT"),
DYNAMITE("MHF_TNT2");
private String name;
private final String name;
private Skull(String mcName) {
Skull(String mcName) {
name = mcName;
}
@@ -102,7 +102,7 @@ public enum Skull {
meta.displayName(dispName.getAdv());
if (lore != null)
meta.lore(lore.stream().map(c -> c.getAdv()).collect(Collectors.toList()));
meta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
itemStack.setItemMeta(meta);
return itemStack;
@@ -175,7 +175,7 @@ public enum Skull {
headMeta.displayName(dispName.getAdv());
if (lore != null)
headMeta.lore(lore.stream().map(c -> c.getAdv()).collect(Collectors.toList()));
headMeta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
head.setItemMeta(headMeta);