Fix warnings and stuff

This commit is contained in:
Marc Baloup 2022-07-22 18:37:15 +02:00
parent c827027e77
commit c7a470e391
18 changed files with 46 additions and 30 deletions

View File

@ -1,2 +1,5 @@
jdk: jdk:
- openjdk17 - openjdk17
before_install:
- sdk install java 17.0.2-open
- sdk use java 17.0.2-open

View File

@ -25,7 +25,6 @@
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-players-permissible</artifactId> <artifactId>pandalib-players-permissible</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>

View File

@ -121,7 +121,7 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, StandaloneOnlinePla
class BungeeClientOptions implements StandaloneOnlinePlayer.ClientOptions { class BungeeClientOptions implements StandaloneOnlinePlayer.ClientOptions {
BungeeOnlinePlayer op; private final BungeeOnlinePlayer op;
public BungeeClientOptions(BungeeOnlinePlayer op) { public BungeeClientOptions(BungeeOnlinePlayer op) {
this.op = op; this.op = op;
} }

View File

@ -189,7 +189,7 @@ public interface SuggestionsSupplier<S> {
public static <S> SuggestionsSupplier<S> suggestDuration() { static <S> SuggestionsSupplier<S> suggestDuration() {
final List<String> emptyTokenSuggestions = TimeUtil.DURATION_SUFFIXES.stream().map(p -> "1" + p).collect(Collectors.toList()); final List<String> emptyTokenSuggestions = TimeUtil.DURATION_SUFFIXES.stream().map(p -> "1" + p).collect(Collectors.toList());
return (s, ti, token, args) -> { return (s, ti, token, args) -> {
if (token.isEmpty()) { if (token.isEmpty()) {

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import fr.pandacube.lib.util.Log; import fr.pandacube.lib.util.Log;
@ -144,10 +145,12 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
public <T, P extends SQLElement<P>> Map<T, P> getReferencedEntriesInGroups(SQLFKField<E, T, P> foreignKey) throws DBException { public <T, P extends SQLElement<P>> Map<T, P> getReferencedEntriesInGroups(SQLFKField<E, T, P> foreignKey) throws DBException {
SQLElementList<P> foreignElemts = getReferencedEntries(foreignKey, null); SQLElementList<P> foreignElemts = getReferencedEntries(foreignKey, null);
Map<T, P> ret = new HashMap<>(); return foreignElemts.stream()
foreignElemts.forEach(foreignVal -> ret.put(foreignVal.get(foreignKey.getPrimaryField()), foreignVal)); .collect(Collectors.toMap(
return ret; foreignVal -> foreignVal.get(foreignKey.getPrimaryField()),
Function.identity(), (a, b) -> b)
);
} }

View File

@ -45,6 +45,7 @@ public final class ByteBuffer implements Cloneable {
/** /**
* This clone method also clone the underlying array. * This clone method also clone the underlying array.
*/ */
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override @Override
public ByteBuffer clone() { public ByteBuffer clone() {
return new ByteBuffer(Arrays.copyOf(buff.array(), buff.array().length)); return new ByteBuffer(Arrays.copyOf(buff.array(), buff.array().length));

View File

@ -7,7 +7,6 @@ import java.util.Objects;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -77,11 +76,11 @@ public class PandalibPaperPermissions implements Listener {
/* package */ static Function<String, List<Permission>> SUPERPERMS_PARENT_PERMISSION_GETTER = childPerm -> { /* package */ static final Function<String, List<Permission>> SUPERPERMS_PARENT_PERMISSION_GETTER = childPerm -> Bukkit.getPluginManager()
return Bukkit.getPluginManager().getPermissions().stream() .getPermissions()
.filter(p -> p.getChildren().containsKey(childPerm)) .stream()
.collect(Collectors.toList()); .filter(p -> p.getChildren().containsKey(childPerm))
}; .toList();
/* package */ static ServerOperator dummyOperator(boolean isOp) { /* package */ static ServerOperator dummyOperator(boolean isOp) {
return new ServerOperator() { return new ServerOperator() {

View File

@ -113,10 +113,14 @@ public class PermissionsInjectorBukkit
private final CommandSender sender; private final CommandSender sender;
private final Permissible oldPermissible; private final Permissible oldPermissible;
/* package */ LoadingCache<String, List<Permission>> superPermsPermissionCache = CacheBuilder.newBuilder() /* package */ final LoadingCache<String, List<Permission>> superPermsPermissionCache = CacheBuilder.newBuilder()
.build(CacheLoader.from(PandalibPaperPermissions.SUPERPERMS_PARENT_PERMISSION_GETTER::apply)); .build(CacheLoader.from(PandalibPaperPermissions.SUPERPERMS_PARENT_PERMISSION_GETTER::apply));
@SuppressWarnings("UnusedAssignment")
private boolean init = false; private boolean init = false;
/* assigment to false is necessary because of super class constructor calling the method recalculatePermission()
* and we dont want that.
*/
private PandaPermissible(CommandSender sender, Permissible oldPermissible) private PandaPermissible(CommandSender sender, Permissible oldPermissible)
{ {
@ -175,7 +179,7 @@ public class PermissionsInjectorBukkit
res = PandalibPaperPermissions.hasSuperPermsPermission(sender, permission.getName(), this::hasPermission, this); // supports negative permission res = PandalibPaperPermissions.hasSuperPermsPermission(sender, permission.getName(), this::hasPermission, this); // supports negative permission
if (res != null) if (res != null)
return res; return res;
return oldPermissible.hasPermission(permission); // doesnt need to manage negative permission (should not happend) return oldPermissible.hasPermission(permission); // doesnt need to manage negative permission (should not happend)
} }

View File

@ -64,6 +64,7 @@ public interface PaperOffPlayer extends StandaloneOffPlayer {
default String getDisplayName() { default String getDisplayName() {
String name = getName(); String name = getName();
Player p = getBukkitPlayer(); Player p = getBukkitPlayer();
@SuppressWarnings("deprecation")
String bukkitDispName = p != null ? p.getDisplayName() : name; String bukkitDispName = p != null ? p.getDisplayName() : name;
if (!name.equals(bukkitDispName)) if (!name.equals(bukkitDispName))
return bukkitDispName; return bukkitDispName;
@ -80,8 +81,11 @@ public interface PaperOffPlayer extends StandaloneOffPlayer {
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(name); Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(name);
if (team == null) if (team == null)
return null; return null;
@SuppressWarnings("deprecation")
String teamPrefix = team.getPrefix(); String teamPrefix = team.getPrefix();
@SuppressWarnings("deprecation")
String teamSuffix = team.getSuffix(); String teamSuffix = team.getSuffix();
@SuppressWarnings("deprecation")
String teamColor = team.getColor().toString(); String teamColor = team.getColor().toString();
return teamPrefix + teamColor + name + teamSuffix; return teamPrefix + teamColor + name + teamSuffix;

View File

@ -104,7 +104,7 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, StandaloneOnlinePlaye
@Override @Override
PaperClientOptions getClientOptions(); PaperClientOptions getClientOptions();
public abstract class PaperClientOptions implements StandaloneOnlinePlayer.ClientOptions { abstract class PaperClientOptions implements StandaloneOnlinePlayer.ClientOptions {
private final PaperOnlinePlayer op; private final PaperOnlinePlayer op;

View File

@ -404,8 +404,8 @@ public class NMSReflect {
private void printHTML(PrintStream out) { private void printHTML(PrintStream out) {
String modifiersHTML = classModifiersToHTML(runtimeClass()); String modifiersHTML = classModifiersToHTML(runtimeClass());
out.println("<tr id='c" + id + "'><th>" + modifiersHTML + "</th><th>" + nameToHTML(true) + "</th><th>" + nameToHTML(false) + "</th></tr>"); out.println("<tr id='c" + id + "'><th>" + modifiersHTML + "</th><th>" + nameToHTML(true) + "</th><th>" + nameToHTML(false) + "</th></tr>");
fieldsByObf.values().stream().filter(mm -> mm.isStatic()).forEach(f -> f.printHTML(out)); fieldsByObf.values().stream().filter(MemberMapping::isStatic).forEach(f -> f.printHTML(out));
methodsByObf.values().stream().filter(mm -> mm.isStatic()).forEach(m -> m.printHTML(out)); methodsByObf.values().stream().filter(MemberMapping::isStatic).forEach(m -> m.printHTML(out));
printConstructorsHTML(out); printConstructorsHTML(out);
fieldsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(f -> f.printHTML(out)); fieldsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(f -> f.printHTML(out));
methodsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(m -> m.printHTML(out)); methodsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(m -> m.printHTML(out));

View File

@ -54,10 +54,6 @@ import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
return cl; return cl;
} }
public NMSTypeWrapper arrayType() {
return new NMSTypeWrapper(type, arrayDepth + 1);
}
/* package */ static NMSTypeWrapper of(Class<?> cl) { /* package */ static NMSTypeWrapper of(Class<?> cl) {
int arrayDepth = 0; int arrayDepth = 0;
while (cl.isArray()) { while (cl.isArray()) {

View File

@ -65,6 +65,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putByteArray(String key, byte[] value) { public void putByteArray(String key, byte[] value) {
wrapReflectEx(() -> putByteArray.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putByteArray.invoke(__getRuntimeInstance(), key, value));
} }
public void putByteArray(String key, List<Byte> value) {
wrapReflectEx(() -> putByteArray_List.invoke(__getRuntimeInstance(), key, value));
}
public void putDouble(String key, double value) { public void putDouble(String key, double value) {
wrapReflectEx(() -> putDouble.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putDouble.invoke(__getRuntimeInstance(), key, value));
} }
@ -77,6 +80,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putIntArray(String key, int[] value) { public void putIntArray(String key, int[] value) {
wrapReflectEx(() -> putIntArray.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putIntArray.invoke(__getRuntimeInstance(), key, value));
} }
public void putIntArray(String key, List<Integer> value) {
wrapReflectEx(() -> putIntArray_List.invoke(__getRuntimeInstance(), key, value));
}
public void putString(String key, String value) { public void putString(String key, String value) {
wrapReflectEx(() -> putString.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putString.invoke(__getRuntimeInstance(), key, value));
} }
@ -89,6 +95,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putLongArray(String key, long[] value) { public void putLongArray(String key, long[] value) {
wrapReflectEx(() -> putLongArray.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putLongArray.invoke(__getRuntimeInstance(), key, value));
} }
public void putLongArray(String key, List<Long> value) {
wrapReflectEx(() -> putLongArray_List.invoke(__getRuntimeInstance(), key, value));
}
public void putShort(String key, short value) { public void putShort(String key, short value) {
wrapReflectEx(() -> putShort.invoke(__getRuntimeInstance(), key, value)); wrapReflectEx(() -> putShort.invoke(__getRuntimeInstance(), key, value));
} }

View File

@ -13,7 +13,6 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
public class ChunkStorage extends ReflectWrapper { public class ChunkStorage extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.chunk.storage.ChunkStorage")); public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.chunk.storage.ChunkStorage"));
private static final Reflect.ReflectMethod<?> read = wrapEx(() -> MAPPING.mojMethod("read", ChunkPos.MAPPING));
private static final Reflect.ReflectMethod<?> readSync = wrapEx(() -> MAPPING.runtimeReflect().method("readSync", ChunkPos.MAPPING.runtimeReflect().get())); // spigot/paper method private static final Reflect.ReflectMethod<?> readSync = wrapEx(() -> MAPPING.runtimeReflect().method("readSync", ChunkPos.MAPPING.runtimeReflect().get())); // spigot/paper method
public CompoundTag readSync(ChunkPos pos) { public CompoundTag readSync(ChunkPos pos) {

View File

@ -46,7 +46,7 @@ public class ScoreboardUtil {
obj.displayName(title); obj.displayName(title);
} }
// fix display slot if someone else changed it // fix display slot if someone else changed it
if (DisplaySlot.SIDEBAR != obj.getDisplaySlot()) { if (obj.getDisplaySlot() != DisplaySlot.SIDEBAR) {
obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplaySlot(DisplaySlot.SIDEBAR);
} }
} }

View File

@ -90,7 +90,7 @@ public class PermissionExpressionParser {
} }
/* /* TODO move to test code
public static void main(String[] args) { public static void main(String[] args) {
java.util.List<String> pList = java.util.Arrays.asList("p1.cmd", "p1.toto", "p2.lol"); java.util.List<String> pList = java.util.Arrays.asList("p1.cmd", "p1.toto", "p2.lol");
LitteralPermissionTester tester = p -> pList.contains(p); LitteralPermissionTester tester = p -> pList.contains(p);

View File

@ -196,7 +196,7 @@ public class PermissionsResolver {
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof DataCacheKey o return obj instanceof DataCacheKey o
&& Objects.equals(name, o.name) && Objects.equals(name, o.name)
&& Objects.equals(type, o.type) && type == o.type
&& dataType == o.dataType; && dataType == o.dataType;
} }
} }
@ -538,8 +538,8 @@ public class PermissionsResolver {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof PermCacheKey o return obj instanceof PermCacheKey o
&& type == o.type
&& Objects.equals(name, o.name) && Objects.equals(name, o.name)
&& Objects.equals(type, o.type)
&& Objects.equals(permission, o.permission) && Objects.equals(permission, o.permission)
&& Objects.equals(server, o.server) && Objects.equals(server, o.server)
&& Objects.equals(world, o.world); && Objects.equals(world, o.world);

View File

@ -8,7 +8,6 @@ import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.ComponentLike;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.chat.ChatStatic; import fr.pandacube.lib.chat.ChatStatic;
public interface StandaloneOnlinePlayer extends StandaloneOffPlayer { public interface StandaloneOnlinePlayer extends StandaloneOffPlayer {