Fix warnings and stuff

master
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:
- 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>
<artifactId>pandalib-players-permissible</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.pandacube.lib</groupId>

View File

@ -121,7 +121,7 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, StandaloneOnlinePla
class BungeeClientOptions implements StandaloneOnlinePlayer.ClientOptions {
BungeeOnlinePlayer op;
private final BungeeOnlinePlayer op;
public BungeeClientOptions(BungeeOnlinePlayer 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());
return (s, ti, token, args) -> {
if (token.isEmpty()) {

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
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 {
SQLElementList<P> foreignElemts = getReferencedEntries(foreignKey, null);
Map<T, P> ret = new HashMap<>();
foreignElemts.forEach(foreignVal -> ret.put(foreignVal.get(foreignKey.getPrimaryField()), foreignVal));
return ret;
return foreignElemts.stream()
.collect(Collectors.toMap(
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.
*/
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public ByteBuffer clone() {
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.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
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 -> {
return Bukkit.getPluginManager().getPermissions().stream()
.filter(p -> p.getChildren().containsKey(childPerm))
.collect(Collectors.toList());
};
/* package */ static final Function<String, List<Permission>> SUPERPERMS_PARENT_PERMISSION_GETTER = childPerm -> Bukkit.getPluginManager()
.getPermissions()
.stream()
.filter(p -> p.getChildren().containsKey(childPerm))
.toList();
/* package */ static ServerOperator dummyOperator(boolean isOp) {
return new ServerOperator() {

View File

@ -113,10 +113,14 @@ public class PermissionsInjectorBukkit
private final CommandSender sender;
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));
@SuppressWarnings("UnusedAssignment")
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)
{
@ -175,7 +179,7 @@ public class PermissionsInjectorBukkit
res = PandalibPaperPermissions.hasSuperPermsPermission(sender, permission.getName(), this::hasPermission, this); // supports negative permission
if (res != null)
return res;
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() {
String name = getName();
Player p = getBukkitPlayer();
@SuppressWarnings("deprecation")
String bukkitDispName = p != null ? p.getDisplayName() : name;
if (!name.equals(bukkitDispName))
return bukkitDispName;
@ -80,8 +81,11 @@ public interface PaperOffPlayer extends StandaloneOffPlayer {
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(name);
if (team == null)
return null;
@SuppressWarnings("deprecation")
String teamPrefix = team.getPrefix();
@SuppressWarnings("deprecation")
String teamSuffix = team.getSuffix();
@SuppressWarnings("deprecation")
String teamColor = team.getColor().toString();
return teamPrefix + teamColor + name + teamSuffix;

View File

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

View File

@ -404,8 +404,8 @@ public class NMSReflect {
private void printHTML(PrintStream out) {
String modifiersHTML = classModifiersToHTML(runtimeClass());
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));
methodsByObf.values().stream().filter(mm -> mm.isStatic()).forEach(m -> m.printHTML(out));
fieldsByObf.values().stream().filter(MemberMapping::isStatic).forEach(f -> f.printHTML(out));
methodsByObf.values().stream().filter(MemberMapping::isStatic).forEach(m -> m.printHTML(out));
printConstructorsHTML(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));

View File

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

View File

@ -65,6 +65,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putByteArray(String key, byte[] 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) {
wrapReflectEx(() -> putDouble.invoke(__getRuntimeInstance(), key, value));
}
@ -77,6 +80,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putIntArray(String key, int[] 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) {
wrapReflectEx(() -> putString.invoke(__getRuntimeInstance(), key, value));
}
@ -89,6 +95,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
public void putLongArray(String key, long[] 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) {
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 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
public CompoundTag readSync(ChunkPos pos) {

View File

@ -46,7 +46,7 @@ public class ScoreboardUtil {
obj.displayName(title);
}
// fix display slot if someone else changed it
if (DisplaySlot.SIDEBAR != obj.getDisplaySlot()) {
if (obj.getDisplaySlot() != 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) {
java.util.List<String> pList = java.util.Arrays.asList("p1.cmd", "p1.toto", "p2.lol");
LitteralPermissionTester tester = p -> pList.contains(p);

View File

@ -196,7 +196,7 @@ public class PermissionsResolver {
public boolean equals(Object obj) {
return obj instanceof DataCacheKey o
&& Objects.equals(name, o.name)
&& Objects.equals(type, o.type)
&& type == o.type
&& dataType == o.dataType;
}
}
@ -538,8 +538,8 @@ public class PermissionsResolver {
@Override
public boolean equals(Object obj) {
return obj instanceof PermCacheKey o
&& type == o.type
&& Objects.equals(name, o.name)
&& Objects.equals(type, o.type)
&& Objects.equals(permission, o.permission)
&& Objects.equals(server, o.server)
&& 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.ComponentLike;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.chat.ChatStatic;
public interface StandaloneOnlinePlayer extends StandaloneOffPlayer {