Update libac version
Update libz version
This commit is contained in:
parent
857d8eaf4a
commit
bddc923eca
6 changed files with 98 additions and 4 deletions
|
@ -5,8 +5,8 @@ org.gradle.daemon=false
|
|||
|
||||
mc_version=1.19.4
|
||||
forge_version=45.0.46
|
||||
myversion=1.0.7.0422230620
|
||||
myversion=1.0.7.0506230341
|
||||
# parchment_version=2023.03.12
|
||||
# luckperms_api_version=5.4
|
||||
|
||||
libac=1.1.3
|
||||
libac=1.1.5
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package dev.zontreck.libzontreck.currency;
|
||||
|
||||
import dev.zontreck.ariaslib.events.EventBus;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.currency.events.TransactionHistoryFlushEvent;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
@ -18,6 +21,9 @@ public class Account
|
|||
public List<Transaction> history;
|
||||
public int balance;
|
||||
|
||||
public String accountName = "";
|
||||
public boolean isPlayer=true;
|
||||
|
||||
public AccountReference getRef()
|
||||
{
|
||||
return new AccountReference(player_id);
|
||||
|
@ -28,6 +34,20 @@ public class Account
|
|||
player_id=ID;
|
||||
history=new ArrayList<>();
|
||||
balance=0;
|
||||
if(isValidPlayer()) {
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(ID.toString());
|
||||
accountName = prof.name_color + prof.nickname;
|
||||
isPlayer=true;
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
accountName = ChatColor.doColors("!Dark_Red!SYSTEM!White!");
|
||||
isPlayer=false;
|
||||
}
|
||||
|
||||
} else {
|
||||
accountName = ChatColor.doColors("!Dark_Red!SYSTEM!White!");
|
||||
isPlayer=false;
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTag save()
|
||||
|
@ -42,6 +62,8 @@ public class Account
|
|||
}
|
||||
|
||||
tag.put("history", txs);
|
||||
tag.putString("name", accountName);
|
||||
tag.putBoolean("player", isPlayer);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -50,6 +72,8 @@ public class Account
|
|||
{
|
||||
player_id = NbtUtils.loadUUID(tag.get("id"));
|
||||
balance = tag.getInt("balance");
|
||||
accountName = tag.getString("name");
|
||||
isPlayer = tag.getBoolean("player");
|
||||
history=new ArrayList<>();
|
||||
ListTag lst = tag.getList("history", Tag.TAG_COMPOUND);
|
||||
for(Tag t : lst){
|
||||
|
@ -80,6 +104,6 @@ public class Account
|
|||
*/
|
||||
public boolean isValidPlayer()
|
||||
{
|
||||
return !player_id.equals(new UUID(0,0));
|
||||
return isPlayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public class Bank
|
|||
* @param tx The transaction being attempted
|
||||
* @return True if the transaction has been accepted. False if the transaction was rejected, or insufficient funds.
|
||||
*/
|
||||
public static boolean postTx(Transaction tx) throws InvalidSideException {
|
||||
protected static boolean postTx(Transaction tx) throws InvalidSideException {
|
||||
if(ServerUtilities.isClient())return false;
|
||||
TransactionEvent ev = new TransactionEvent(tx);
|
||||
if(EventBus.BUS.post(ev))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.libzontreck.currency;
|
||||
|
||||
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
|
||||
|
@ -39,4 +40,16 @@ public class Transaction
|
|||
this.amount=amount;
|
||||
timestamp = ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the transaction to the bank to be processed
|
||||
* @return True if the transaction was successfully submitted.
|
||||
*/
|
||||
public boolean submit(){
|
||||
try {
|
||||
return Bank.postTx(this);
|
||||
} catch (InvalidSideException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package dev.zontreck.libzontreck.util;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BinUtil {
|
||||
|
@ -21,6 +23,32 @@ public class BinUtil {
|
|||
return new String(hexChars);
|
||||
}
|
||||
|
||||
public static byte[] hexToBytes(String hexStr)
|
||||
{
|
||||
List<Byte> bList = new ArrayList<>();
|
||||
for(int i=0;i<hexStr.length();i+=2)
|
||||
{
|
||||
bList.add((byte)(
|
||||
(Character.digit(hexStr.charAt(i), 16)<<4) +
|
||||
(Character.digit(hexStr.charAt(i+1), 16))
|
||||
));
|
||||
}
|
||||
|
||||
return byteArray(bList);
|
||||
}
|
||||
|
||||
public static byte[] byteArray(List<Byte> b)
|
||||
{
|
||||
byte[] ret = new byte[b.size()];
|
||||
int i=0;
|
||||
for(byte bx : b)
|
||||
{
|
||||
ret[i] = bx;
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A random instance backed by the time including milliseconds as the seed.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package dev.zontreck.libzontreck.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
|
@ -74,6 +76,33 @@ public class ChatHelpers {
|
|||
broadcastTo(ID.getUUID(), message, server, true);
|
||||
}
|
||||
|
||||
public static String hashOfMd5(String input) throws NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("md5");
|
||||
md5.update(input.getBytes());
|
||||
return asHex(md5.digest());
|
||||
}
|
||||
public static String hashOfSha256(String input) throws NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("sha-256");
|
||||
md5.update(input.getBytes());
|
||||
return asHex(md5.digest());
|
||||
}
|
||||
|
||||
public static String hashOfMd5(byte[] input) throws NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("md5");
|
||||
md5.update(input);
|
||||
return asHex(md5.digest());
|
||||
}
|
||||
public static String hashOfSha256(byte[] input) throws NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("sha-256");
|
||||
md5.update(input);
|
||||
return asHex(md5.digest());
|
||||
}
|
||||
|
||||
public static String asHex(byte[] input)
|
||||
{
|
||||
return BinUtil.bytesToHex(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output with colors applied, and chat entries replaced using [number] as the format
|
||||
* @param input
|
||||
|
|
Reference in a new issue