Skip to content

Commit

Permalink
v11.1.0
Browse files Browse the repository at this point in the history
* The of(String) method of `XParticle` & `XEntityType` now return Optional.
  • Loading branch information
CryptoMorin committed Jun 19, 2024
1 parent 55e91a9 commit 5cfac2c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>11.0.0</version>
<version>11.1.0</version>

<name>XSeries</name>
<description>A set of utilities for Minecraft plugins</description>
Expand Down Expand Up @@ -282,7 +282,7 @@
<profile>
<id>latest</id>
<properties>
<nms>20_R0</nms>
<nms>21_R0</nms>
</properties>
</profile>
<profile>
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/cryptomorin/xseries/XEntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;

public enum XEntityType {
ALLAY,
Expand Down Expand Up @@ -174,25 +171,25 @@ public boolean isSupported() {
return entityType != null;
}

public XEntityType or(XEntityType other) {
return this.isSupported() ? this : other;
}

public static XEntityType of(Entity entity) {
Objects.requireNonNull(entity, "Cannot match entity type from null entity");
return of(entity.getType());
}

public XEntityType or(XEntityType other) {
return this.isSupported() ? this : other;
}

public static XEntityType of(EntityType entityType) {
Objects.requireNonNull(entityType, "Cannot match null entity type");
XEntityType mapping = Data.BUKKIT_MAPPING.get(entityType);
if (mapping != null) return mapping;
throw new UnsupportedOperationException("Unknown entity type: " + entityType);
}

public static XEntityType of(String entityType) {
public static Optional<XEntityType> of(String entityType) {
Objects.requireNonNull(entityType, "Cannot match null entity type");
return Data.NAME_MAPPING.get(entityType);
return Optional.ofNullable(Data.NAME_MAPPING.get(entityType));
}

public EntityType get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.cryptomorin.xseries.abstractions;

import org.jetbrains.annotations.ApiStatus;

/**
* Experimental class for XMaterial Bukkit+Forge abstraction.
*/
@ApiStatus.Experimental
interface Material {
String name();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ public static ParticleDisplay edit(@Nonnull ParticleDisplay display, @Nonnull Co
Objects.requireNonNull(config, "Cannot parse ParticleDisplay from a null config section");

String particleName = config.getString("particle");
XParticle particle = particleName == null ? null : XParticle.of(particleName);
Optional<XParticle> particle = particleName == null ? Optional.empty() : XParticle.of(particleName);

if (particle != null) display.particle = particle;
particle.ifPresent(xParticle -> display.particle = xParticle);
if (config.isSet("count")) display.withCount(config.getInt("count"));
if (config.isSet("extra")) display.withExtra(config.getDouble("extra"));
if (config.isSet("force")) display.forceSpawn(config.getBoolean("force"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
Expand Down Expand Up @@ -151,7 +149,7 @@ private Particles() {
* @return a random particle from the list.
* @since 1.0.0
*/
public static XParticle randomParticle(String... particles) {
public static Optional<XParticle> randomParticle(String... particles) {
int rand = randInt(0, particles.length - 1);
return XParticle.of(particles[rand]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.bukkit.Particle;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;

/**
* <b>XParticle</b> - Particle enum for <b>XSeries</b>
Expand Down Expand Up @@ -281,9 +278,9 @@ public static XParticle of(Particle particle) {
* @param particle the particle name to match
* @return the XParticle associated with the given particle name
*/
public static XParticle of(String particle) {
public static Optional<XParticle> of(String particle) {
Objects.requireNonNull(particle, "Cannot match null particle");
return Data.NAME_MAPPING.get(particle);
return Optional.ofNullable(Data.NAME_MAPPING.get(particle));
}

private static Particle tryGetParticle(String particle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import static com.cryptomorin.xseries.reflection.XReflection.v;

@SuppressWarnings({"unchecked", "UnstableApiUsage"})
@SuppressWarnings("unchecked")
@ApiStatus.Internal
public final class ProfilesCore {
public static final Logger LOGGER = LogManager.getLogger("XSkull");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonReader;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.ApiStatus;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -26,6 +27,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;

@ApiStatus.Internal
public class MinecraftClient {
private static final AtomicInteger SESSION_ID = new AtomicInteger();
private static final Proxy PROXY = ProfilesCore.PROXY == null ? Proxy.NO_PROXY : ProfilesCore.PROXY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import org.jetbrains.annotations.ApiStatus;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -24,6 +25,7 @@
import java.util.*;
import java.util.concurrent.TimeUnit;

@ApiStatus.Internal
public final class MojangAPI {
private static final MojangProfileCache MOJANG_PROFILE_CACHE = ProfilesCore.NULLABILITY_RECORD_UPDATE ?
new MojangProfileCache.GameProfileCache(ProfilesCore.YggdrasilMinecraftSessionService_insecureProfiles) :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.cryptomorin.xseries.profiles.mojang;

import com.cryptomorin.xseries.profiles.ProfilesCore;
import org.jetbrains.annotations.ApiStatus;

import javax.annotation.Nonnull;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

@ApiStatus.Internal
public final class PlayerProfileFetcherThread implements ThreadFactory {
/**
* An executor service with a fixed thread pool of size 2, used for asynchronous operations.
Expand Down

0 comments on commit 5cfac2c

Please sign in to comment.