Skip to content

Commit

Permalink
1.8-pre-9, (generate uuid like nms)
Browse files Browse the repository at this point in the history
  • Loading branch information
retrooper committed Mar 11, 2021
1 parent 36b8076 commit c7096d8
Showing 1 changed file with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public final class NMSUtils {
private static final String NMS_DIR = ServerVersion.getNMSDirectory() + ".";
Expand Down Expand Up @@ -287,8 +289,7 @@ public static Entity getEntityById(@Nullable World world, int id) {
}
}
return entity;
}
catch(Exception ex){
} catch (Exception ex) {
return null;
}
}
Expand Down Expand Up @@ -400,8 +401,7 @@ public static Object convertBukkitServerToNMSServer(Server server) {
WrappedPacket wrapper = new WrappedPacket(new NMSPacket(craftServer));
try {
return wrapper.readObject(0, minecraftServerClass);
}
catch (Exception ex) {
} catch (Exception ex) {
wrapper.readObject(0, dedicatedServerClass);
}
return null;
Expand All @@ -416,9 +416,10 @@ public static Object convertBukkitWorldToWorldServer(World world) {
}
return null;
}
@Nullable

@Nullable
public static Object generateIChatBaseComponent(String text) {
if (text== null) {
if (text == null) {
return null;
}
try {
Expand Down Expand Up @@ -526,12 +527,38 @@ public static Object getNMSBlockFromMaterial(Material material) {
}

public static Object generateDataWatcher(Entity entity) {
Object nmsEntity = null;
Object nmsEntity = null;
try {
return dataWatcherConstructor.newInstance(nmsEntity);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}

private static final ThreadLocal<Random> randomThreadLocal = ThreadLocal.withInitial(Random::new);

public static UUID generateUUID() {
long var1 = randomThreadLocal.get().nextLong() & -61441L | 16384L;
long var3 = randomThreadLocal.get().nextLong() & 4611686018427387903L | -9223372036854775808L;
return new UUID(var1, var3);
}

public static int generateEntityId() {
Field field = Reflection.getField(nmsEntityClass, "entityCount");
try {
if (field.getType().equals(AtomicInteger.class)) {
//Newer versions
AtomicInteger atomicInteger = (AtomicInteger) field.get(null);
return atomicInteger.incrementAndGet();
} else {
int id = field.getInt(null) + 1;
field.set(null, id);
return id;
}
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
throw new IllegalStateException("Failed to generate a new unique entity ID!");
}
}

0 comments on commit c7096d8

Please sign in to comment.