Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TheBusyBiscuit/CS-CoreLib2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.31.0
Choose a base ref
...
head repository: TheBusyBiscuit/CS-CoreLib2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.32.0
Choose a head ref

Commits on May 3, 2021

  1. Refactoring

    TheBusyBiscuit committed May 3, 2021
    Copy the full SHA
    d12f7e7 View commit details
  2. Copy the full SHA
    9c20cc5 View commit details

Commits on May 5, 2021

  1. Merge pull request #180 from TheBusyBiscuit/renovate/com.github.anges…

    …chossen-landsapi-5.x
    
    Update dependency com.github.angeschossen:LandsAPI to v5.7.2
    TheBusyBiscuit authored May 5, 2021
    Copy the full SHA
    f79716c View commit details

Commits on May 11, 2021

  1. Copy the full SHA
    bc9d45d View commit details
  2. Add CopyUtils

    md5sha256 committed May 11, 2021
    Copy the full SHA
    18f09d0 View commit details
  3. Remove final modifiers

    md5sha256 committed May 11, 2021
    Copy the full SHA
    8998ab2 View commit details
  4. Copy the full SHA
    766d054 View commit details
  5. Copy the full SHA
    430f50a View commit details
  6. Merge pull request #181 from TheBusyBiscuit/renovate/com.github.anges…

    …chossen-landsapi-5.x
    
    Update dependency com.github.angeschossen:LandsAPI to v5.7.4
    TheBusyBiscuit authored May 11, 2021
    Copy the full SHA
    edec728 View commit details

Commits on May 13, 2021

  1. Copy the full SHA
    f960ab0 View commit details
  2. Copy the full SHA
    61a478d View commit details

Commits on May 15, 2021

  1. Copy the full SHA
    30c7299 View commit details

Commits on May 16, 2021

  1. Merge pull request #184 from TheBusyBiscuit/renovate/world.bentobox-b…

    …entobox-1.x
    
    Update dependency world.bentobox:bentobox to v1.16.2
    TheBusyBiscuit authored May 16, 2021
    Copy the full SHA
    36a41eb View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    davidmc24 David M. Carr
    Copy the full SHA
    b7bcd46 View commit details
  3. Merge pull request #185 from md5sha256/feature/collections-utils

    Use the lombok non-null annotation in CopyUtils
    TheBusyBiscuit authored May 16, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    davidmc24 David M. Carr
    Copy the full SHA
    abec32f View commit details

Commits on May 17, 2021

  1. Copy the full SHA
    dc45407 View commit details

Commits on Jun 8, 2021

  1. Copy the full SHA
    613345e View commit details
  2. Merge pull request #189 from TheBusyBiscuit/renovate/com.sk89q.worldg…

    …uard-worldguard-bukkit-7.x
    
    Update dependency com.sk89q.worldguard:worldguard-bukkit to v7.0.5
    TheBusyBiscuit authored Jun 8, 2021
    Copy the full SHA
    88573c2 View commit details
  3. Merge pull request #186 from TheBusyBiscuit/renovate/actions-setup-ja…

    …va-2.x
    
    Update actions/setup-java action to v2.1.0
    TheBusyBiscuit authored Jun 8, 2021
    Copy the full SHA
    0f1645b View commit details
  4. Copy the full SHA
    c721faf View commit details

Commits on Jun 11, 2021

  1. 1.17 support

    WalshyDev committed Jun 11, 2021
    Copy the full SHA
    892a2e9 View commit details
  2. Final ver

    WalshyDev committed Jun 11, 2021
    Copy the full SHA
    aa246d8 View commit details
  3. Fix SF unit test

    WalshyDev committed Jun 11, 2021
    Copy the full SHA
    52a4ec5 View commit details
  4. Remove debug

    WalshyDev committed Jun 11, 2021
    Copy the full SHA
    34bc166 View commit details
  5. Copy the full SHA
    2e2307e View commit details
  6. Copy the full SHA
    40ec4be View commit details
  7. Merge pull request #190 from TheBusyBiscuit/renovate/net.dzikoysk-fun…

    …nyguilds-4.x
    
    Update dependency net.dzikoysk:funnyguilds to v4.9.7
    TheBusyBiscuit authored Jun 11, 2021
    Copy the full SHA
    1193703 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4
- name: Set up Java 11
uses: actions/setup-java@v2.0.0
uses: actions/setup-java@v2.1.0
with:
java-version: '11'
distribution: 'adopt'
18 changes: 7 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
<groupId>com.github.thebusybiscuit</groupId>
<artifactId>cscorelib2</artifactId>

<version>0.31.0</version>
<version>0.32.0</version>

<packaging>jar</packaging>
<url>https://github.com/TheBusyBiscuit/CS-CoreLib2</url>
@@ -49,10 +49,6 @@
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>tastybento-repo</id>
<url>https://dl.bintray.com/tastybento/maven-repo</url>
</repository>
<repository>
<id>coreprotect-repo</id>
<url>https://maven.playpro.com/</url>
@@ -63,7 +59,7 @@
</repository>
<repository>
<id>FactionsUUID-repo</id>
<url>https://ci.ender.zone/job/FactionsUUID/122/maven-repository/repository</url>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
<repository>
<id>plotsquared-repo</id>
@@ -143,7 +139,7 @@
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.4</version>
<version>7.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -185,7 +181,7 @@
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-U0.2.2</version>
<version>1.6.9.5-U0.5.20</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -227,7 +223,7 @@
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>1.16.1</version>
<version>1.16.2</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -239,7 +235,7 @@
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>5.6.0</version>
<version>5.7.4</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -251,7 +247,7 @@
<dependency>
<groupId>net.dzikoysk</groupId>
<artifactId>funnyguilds</artifactId>
<version>4.9.5</version>
<version>4.9.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package io.github.thebusybiscuit.cscorelib2.collections;

import lombok.NonNull;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;

/**
* Utilities for deep-copying collections, maps and arrays
*
* @author md5sha256
*/
public final class CopyUtils {

private CopyUtils() {}

/**
* Perform a deep copy of all the elements from a given {@link Collection} to another.
* <p>
* If the source collection contains <code>null</code> elements, the cloning function should be
* able to handle null input. Additionally, the sink should also accept any values
* contained by the source collection, null or not.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sink The collection in which to copy to the cloned elements to
* @param <T> The type of elements in the collections
*
*/
public static <T> void deepCopy(@NonNull Collection<T> source, @NonNull Function<T, T> cloningFunction, @NonNull Collection<T> sink) {
for (T original : source) {
T cloned = cloningFunction.apply(original);
sink.add(cloned);
}
}

/**
* Perform a deep copy of all the elements from a given {@link Collection} to another.
* <p>
* If the source collection contains <code>null</code> elements, the cloning function should be
* able to handle null input. Additionally, the sink supplied by the sink supplier
* should also accept any values contained by the source collection, null or not.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sinkSupplier The supplier which consumes the size of the source collection and
* supplies the collection to copy cloned elements to
*
* @param <T> The type of elements in the collections
* @param <C> The type of the returned collection
*
*/
public static <T, C extends Collection<T>> @NonNull C deepCopy(@NonNull Collection<T> source, @NonNull Function<T, T> cloningFunction, @NonNull IntFunction<C> sinkSupplier) {
C sink = sinkSupplier.apply(source.size());
deepCopy(source, cloningFunction, sink);
return sink;
}

/**
* Perform a deep copy of all the elements from a given {@link Map} to another.
* <p>
* If the source map contains <code>null</code> values, the cloning function should be
* able to handle null input. Additionally, the sink should also accept any keys and values
* contained by the source Map, null or not.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sink The map in which to copy to the cloned elements to
* @param <K> The type of keys in the maps
* @param <V> The type of values in the maps
*
*/
public static <K, V> void deepCopy(@NonNull Map<K, V> source, @NonNull Function<V, V> cloningFunction, @NonNull Map<K, V> sink) {
for (Map.Entry<K, V> entry : source.entrySet()) {
V original = entry.getValue();
V cloned = cloningFunction.apply(original);
sink.put(entry.getKey(), cloned);
}
}

/**
* Perform a deep copy of all the elements from a given {@link Map} to another.
* <p>
* If the source map contains <code>null</code> values, the cloning function should be
* able to handle null input. Additionally, the sink should also accept any keys and values
* contained by the source Map, null or not.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sinkSupplier The supplier which consumes the size of the source map and
* supplies the map to copy cloned elements to
* @param <K> The type of keys in the maps
* @param <V> The type of values in the maps
* @param <M> The type of the returned map
*
*/
public static <K, V, M extends Map<K, V>> @NonNull M deepCopy(@NonNull Map<K, V> source, @NonNull Function<V, V> cloningFunction, @NonNull Supplier<M> sinkSupplier) {
M sink = sinkSupplier.get();
deepCopy(source, cloningFunction, sink);
return sink;
}

/**
* Perform a deep-clone transformation on all values in a given {@link Map}
* <p>
* If the source map contains <code>null</code> values, the cloning function should be
* able to handle null input.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param <K> The type of keys in the map
* @param <V> The type of values in the map
*
*/
public static <K, V> void deepCopy(@NonNull Map<K, V> source, @NonNull Function<V, V> cloningFunction) {
for (Map.Entry<K, V> entry : source.entrySet()) {
V original = entry.getValue();
V cloned = cloningFunction.apply(original);
entry.setValue(cloned);
}
}

/**
* Perform a deep copy of all the elements from a given array to another.
* <p>
* If the source array contains <code>null</code> elements, the cloning function should be
* able to handle null input.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sink The array in which to copy to the cloned elements to
* @param <T> The type of elements in the arrays
*
*/
public static <T> void deepCopy(@NonNull T[] source, @NonNull Function<T, T> cloningFunction, @NonNull T[] sink) {
if (source.length > sink.length) {
throw new IllegalArgumentException("Length of sink must be greater than or equal to that of the source!");
}
for (int i = 0; i < source.length; i++) {
sink[i] = cloningFunction.apply(source[i]);
}
}

/**
* Perform a deep copy of all the elements from a given array to another.
* <p>
* If the source array contains <code>null</code> elements, the cloning function should be
* able to handle null input.
*
* @param source The source of the elements
* @param cloningFunction The function which clones the elements
* @param sinkSupplier The supplier which consumes the length of the source array and supplies
* the array to copy the cloned elements to
* @param <T> The type of elements in the arrays
*
*/
public static <T> @NonNull T[] deepCopy(@NonNull T[] source, @NonNull Function<T, T> cloningFunction, @NonNull IntFunction<T[]> sinkSupplier) {
T[] sink = sinkSupplier.apply(source.length);
deepCopy(source, cloningFunction, sink);
return sink;
}

}
Original file line number Diff line number Diff line change
@@ -34,6 +34,10 @@ private ItemUtils() {}
try {
if (ReflectionUtils.isUnitTestEnvironment()) {
System.out.println("MockBukkit detected! Cannot access NMS ItemStack API.");
} else if (ReflectionUtils.getMajorVersion() >= 17) {
copy = ReflectionUtils.getOBCClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
getName = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("world.item.ItemStack"), "getName");
toString = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("network.chat.IChatBaseComponent"), "getString");
} else {
copy = ReflectionUtils.getOBCClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
getName = ReflectionUtils.getMethod(ReflectionUtils.getNMSClass("ItemStack"), "getName");
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -17,7 +19,7 @@

/**
* This class provides some useful static methods to perform reflection.
*
*
* @author TheBusyBiscuit
*
*/
@@ -26,8 +28,10 @@ public final class ReflectionUtils {

private ReflectionUtils() {}

private static String currentVersion;
private static final int MAJOR_VERSION;
private static final String CURRENT_VERSION;
private static final Map<Class<?>, Class<?>> primitiveTypes = new HashMap<>();
private static final Pattern versionPattern = Pattern.compile("v\\d_(\\d+)_R\\d");

static {
primitiveTypes.put(Byte.class, Byte.TYPE);
@@ -38,6 +42,16 @@ private ReflectionUtils() {}
primitiveTypes.put(Float.class, Float.TYPE);
primitiveTypes.put(Double.class, Double.TYPE);
primitiveTypes.put(Boolean.class, Boolean.TYPE);

CURRENT_VERSION = Bukkit.getServer().getClass().getPackage().getName()
.substring(Bukkit.getServer().getClass().getPackage().getName().lastIndexOf('.') + 1);

Matcher matcher = versionPattern.matcher(CURRENT_VERSION);
if (matcher.matches()) {
MAJOR_VERSION = Integer.parseInt(matcher.group(1));
} else {
MAJOR_VERSION = 0;
}
}

/**
@@ -115,7 +129,7 @@ public static Field getField(@NonNull Class<?> c, @NonNull String field) throws
* The Name of that Field
* @param value
* The Value for that Field
*
*
* @throws NoSuchFieldException
* If the field could not be found.
* @throws IllegalAccessException
@@ -138,7 +152,7 @@ public static <T> void setFieldValue(@NonNull T object, @NonNull Class<?> c, @No
* The Name of that Field
* @param value
* The Value for that Field
*
*
* @throws NoSuchFieldException
* If the field could not be found.
* @throws IllegalAccessException
@@ -157,12 +171,12 @@ public static <T> void setFieldValue(@NonNull T object, @NonNull String field, @
* The Object containing the Field
* @param field
* The Name of that Field
*
*
* @throws NoSuchFieldException
* If the field could not be found.
* @throws IllegalAccessException
* If the field could not be queried.
*
*
* @return The Value of a Field
*/
@Nullable
@@ -178,7 +192,7 @@ public static <T> T getFieldValue(@NonNull Object object, @NonNull Class<T> fiel
*
* @param classes
* The Types you want to convert
*
*
* @return An Array of primitive Types
*/
@Nonnull
@@ -202,7 +216,7 @@ public static Class<?>[] toPrimitiveTypeArray(@NonNull Class<?>[] classes) {
*
* @param objects
* The Types you want to convert
*
*
* @return An Array of primitive Types
*/
@Nonnull
@@ -253,31 +267,42 @@ public static <T> Constructor<T> getConstructor(@NonNull Class<T> c, Class<?>...
* The Name of the Class your Inner class is located in
* @param subname
* The Name of the inner Class you are looking for
*
*
* @throws ClassNotFoundException
* If the class could not be found.
*
*
* @return The Class in your specified Class
*/
@Nonnull
public static Class<?> getInnerNMSClass(@NonNull String name, @NonNull String subname) throws ClassNotFoundException {
return getNMSClass(name + '$' + subname);
}

/**
* Returns a `net.minecraft` class via Reflection.
*
* @param name The class name of which to fetch
* @return The `net.minecraft` class.
* @throws ClassNotFoundException If the class does not exist
*/
public static Class<?> getNetMinecraftClass(@Nonnull String name) throws ClassNotFoundException {
return Class.forName("net.minecraft." + (MAJOR_VERSION <= 16 ? getVersion() + '.' : "") + name);
}

/**
* Returns an NMS Class via Reflection
*
* @param name
* The Name of the Class you are looking for
*
*
* @throws ClassNotFoundException
* If the class could not be found.
*
*
* @return The Class in that Package
*/
@Nonnull
public static Class<?> getNMSClass(@NonNull String name) throws ClassNotFoundException {
return Class.forName(new StringBuilder().append("net.minecraft.server.").append(getVersion()).append(".").append(name).toString());
return Class.forName("net.minecraft.server." + (MAJOR_VERSION <= 16 ? getVersion() + '.' : "") + name);
}

/**
@@ -287,10 +312,10 @@ public static Class<?> getNMSClass(@NonNull String name) throws ClassNotFoundExc
* The Name of the Class your Inner class is located in
* @param subname
* The Name of the inner Class you are looking for
*
*
* @throws ClassNotFoundException
* If the class could not be found.
*
*
* @return The Class in your specified Class
*/
@Nonnull
@@ -303,15 +328,15 @@ public static Class<?> getInnerOBCClass(@NonNull String name, @NonNull String su
*
* @param name
* The Name of the Class you are looking for
*
*
* @throws ClassNotFoundException
* If the class could not be found.
*
*
* @return The Class in that Package
*/
@Nonnull
public static Class<?> getOBCClass(@NonNull String name) throws ClassNotFoundException {
return Class.forName(new StringBuilder().append("org.bukkit.craftbukkit.").append(getVersion()).append(".").append(name).toString());
return Class.forName("org.bukkit.craftbukkit." + getVersion() + '.' + name);
}

/**
@@ -321,17 +346,20 @@ public static Class<?> getOBCClass(@NonNull String name) throws ClassNotFoundExc
*/
@Nonnull
private static String getVersion() {
if (currentVersion == null) {
currentVersion = Bukkit.getServer().getClass().getPackage().getName().substring(Bukkit.getServer().getClass().getPackage().getName().lastIndexOf('.') + 1);
}
return CURRENT_VERSION;
}

return currentVersion;
/**
* Return the Minecraft Major Version (15, 16, 17).
*/
public static int getMajorVersion() {
return MAJOR_VERSION;
}

/**
* This checks if the current Server instance is a mock (MockBukkit) and
* whether we are in a Unit Test environment.
*
*
* @return Whether the current Server instance is a mock
*/
public static boolean isUnitTestEnvironment() {
Original file line number Diff line number Diff line change
@@ -10,16 +10,16 @@
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
import lombok.NonNull;

final class FakeProfile extends GameProfile {
final class FakeGameProfile extends GameProfile {

public static final String PROPERTY_KEY = "textures";

public FakeProfile(UUID uuid, String texture) {
FakeGameProfile(@NonNull UUID uuid, @NonNull String texture) {
super(uuid, "CS-CoreLib");
getProperties().put(PROPERTY_KEY, new Property(PROPERTY_KEY, texture));
}

public void inject(@NonNull SkullMeta meta) throws NoSuchFieldException, IllegalAccessException {
void inject(@NonNull SkullMeta meta) throws NoSuchFieldException, IllegalAccessException {
ReflectionUtils.setFieldValue(meta, "profile", this);

// Forces SkullMeta to properly deserialize and serialize the profile
Original file line number Diff line number Diff line change
@@ -25,13 +25,24 @@ public final class SkullBlock {

static {
try {
handle = ReflectionUtils.getOBCClass("CraftWorld").getMethod("getHandle");
if (ReflectionUtils.getMajorVersion() >= 17) {
handle = ReflectionUtils.getOBCClass("CraftWorld").getMethod("getHandle");

setGameProfile = ReflectionUtils.getNMSClass("TileEntitySkull").getMethod("setGameProfile", GameProfile.class);
setGameProfile = ReflectionUtils.getNetMinecraftClass("world.level.block.entity.TileEntitySkull")
.getMethod("setGameProfile", GameProfile.class);

Class<?> blockPosition = ReflectionUtils.getNMSClass("BlockPosition");
newPosition = ReflectionUtils.getConstructor(blockPosition, int.class, int.class, int.class);
getTileEntity = ReflectionUtils.getNMSClass("WorldServer").getMethod("getTileEntity", blockPosition);
Class<?> blockPosition = ReflectionUtils.getNetMinecraftClass("core.BlockPosition");
newPosition = ReflectionUtils.getConstructor(blockPosition, int.class, int.class, int.class);
getTileEntity = ReflectionUtils.getNMSClass("level.WorldServer").getMethod("getTileEntity", blockPosition);
} else {
handle = ReflectionUtils.getOBCClass("CraftWorld").getMethod("getHandle");

setGameProfile = ReflectionUtils.getNMSClass("TileEntitySkull").getMethod("setGameProfile", GameProfile.class);

Class<?> blockPosition = ReflectionUtils.getNMSClass("BlockPosition");
newPosition = ReflectionUtils.getConstructor(blockPosition, int.class, int.class, int.class);
getTileEntity = ReflectionUtils.getNMSClass("WorldServer").getMethod("getTileEntity", blockPosition);
}
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
System.err.println("Perhaps you forgot to shade CS-CoreLib's \"reflection\" package?");
e.printStackTrace();
@@ -88,7 +99,7 @@ public static void setFromBase64(@NonNull Block block, @NonNull UUID uuid, @NonN
}

try {
GameProfile profile = new FakeProfile(uuid, texture);
GameProfile profile = new FakeGameProfile(uuid, texture);
Object world = handle.invoke(block.getWorld());

Object position = newPosition.newInstance(block.getX(), block.getY(), block.getZ());
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public static ItemStack fromBase64(@NonNull UUID uuid, @NonNull String texture)
ItemStack item = new ItemStack(Material.PLAYER_HEAD);

SkullMeta meta = (SkullMeta) item.getItemMeta();
new FakeProfile(uuid, texture).inject(meta);
new FakeGameProfile(uuid, texture).inject(meta);

item.setItemMeta(meta);
return item;
@@ -184,7 +184,7 @@ public static ItemStack fromName(@NonNull String name) throws IOException {
JsonArray properties = new JsonParser().parse(sessionReader).getAsJsonObject().get("properties").getAsJsonArray();

for (JsonElement el : properties) {
if (el.isJsonObject() && el.getAsJsonObject().get("name").getAsString().equals(FakeProfile.PROPERTY_KEY)) {
if (el.isJsonObject() && el.getAsJsonObject().get("name").getAsString().equals(FakeGameProfile.PROPERTY_KEY)) {
return fromBase64(UUID.fromString(uuid), el.getAsJsonObject().get("value").getAsString());
}
}