Update major API Version to add some new interfaces.

This commit is contained in:
Aria 2023-03-18 21:01:18 -07:00
parent 1378a6fb21
commit 5d024f425c
26 changed files with 496 additions and 111 deletions

View file

@ -1,5 +1,8 @@
package dev.zontreck.libzontreck.util;
import java.time.Instant;
import java.util.Random;
public class BinUtil {
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
@ -17,4 +20,12 @@ public class BinUtil {
}
return new String(hexChars);
}
/**
* @return A random instance backed by the time including milliseconds as the seed.
*/
public static Random getARandomInstance()
{
return new Random(Instant.now().toEpochMilli());
}
}

View file

@ -1,17 +1,16 @@
package dev.zontreck.libzontreck.util;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;
import dev.zontreck.libzontreck.LibZontreck;
public class DelayedExecutorService {
private static int COUNT = 0;
private static AtomicInteger COUNT = new AtomicInteger(0);
private static final DelayedExecutorService inst;
private static final Timer repeater;
static{
@ -46,6 +45,7 @@ public class DelayedExecutorService {
public void schedule(final Runnable run, int seconds)
{
if(!LibZontreck.ALIVE)return;
//long unix = Instant.now().getEpochSecond()+ (seconds);
TimerTask task = new TimerTask() {
@Override
@ -88,7 +88,6 @@ public class DelayedExecutorService {
public static int getNext()
{
COUNT++;
return COUNT;
return COUNT.getAndIncrement();
}
}

View file

@ -0,0 +1,27 @@
package dev.zontreck.libzontreck.util;
import dev.zontreck.libzontreck.permissions.PermissionStorage;
import dev.zontreck.libzontreck.permissions.PermissionUser;
import java.io.IOException;
import java.util.List;
public class PermissionsWatchdog implements Runnable
{
public List<PermissionUser> perms;
@Override
public void run() {
if(!perms.equals(PermissionStorage.getListOfUsers()))
{
try {
PermissionStorage.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
perms = PermissionStorage.getListOfUsers();
}
DelayedExecutorService.getInstance().schedule(this, 10);
}
}

View file

@ -1,14 +1,77 @@
package dev.zontreck.libzontreck.util;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.networking.ModMessages;
import dev.zontreck.libzontreck.networking.packets.IPacket;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.simple.SimpleChannel;
public class ServerUtilities
{
/**
* This function only exists on the server
* @param id Player ID
* @return The server player associated with the ID
*/
public static ServerPlayer getPlayerByID(String id)
{
return LibZontreck.THE_SERVER.getPlayerList().getPlayer(UUID.fromString(id));
}
/**
* Handles the registration of packets
* @param <X>
* @param channel
* @param type
* @param inst
* @param decoder
*/
public static <X extends IPacket> void registerPacket(SimpleChannel channel, Class<X> type, X inst, Function<FriendlyByteBuf, X> decoder)
{
IPacket packet = (IPacket) inst;
channel.messageBuilder(type, ModMessages.id(), packet.getDirection())
.decoder(decoder)
.encoder(X::toBytes)
.consumer(X::handle)
.add();
}
/**
* Handles the tedious and repetitive actions in the handle packet segment of code
* @param context
* @param run
* @return
*/
public static boolean handlePacket(Supplier<NetworkEvent.Context> context, Runnable run)
{
NetworkEvent.Context ctx = context.get();
ctx.enqueueWork(run);
return true;
}
/**
* Checks if the mod is running on the server
* @return True if the mod is on the server
*/
public static boolean isServer()
{
return (LibZontreck.CURRENT_SIDE == LogicalSide.SERVER);
}
/**
* Checks if the mod is running on the client
* @return True if the mod is on the client
*/
public static boolean isClient()
{
return !isServer();
}
}

View file

@ -1,16 +1,11 @@
package dev.zontreck.libzontreck.util.heads;
import java.util.Properties;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.items.lore.LoreContainer;
import dev.zontreck.libzontreck.items.lore.LoreEntry;
import dev.zontreck.libzontreck.util.heads.HeadCache.HeadCacheItem;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.item.BookItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.WrittenBookItem;
import net.minecraft.world.scores.Team;
public class CreditsEntry {
public HeadCacheItem player;

View file

@ -9,16 +9,13 @@ import java.util.UUID;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.PlayerHeadItem;
import net.minecraftforge.items.ItemStackHandler;
public class HeadCache
{

View file

@ -2,7 +2,6 @@ package dev.zontreck.libzontreck.util.heads;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import java.util.UUID;
import com.google.gson.Gson;

View file

@ -1,7 +1,5 @@
package dev.zontreck.libzontreck.util.heads;
import java.util.UUID;
public class PlayerInfo {
public String name;
public String id;