all functions mostly converted to new structure and server call method
Some checks failed
build / build (21) (push) Has been cancelled
Some checks failed
build / build (21) (push) Has been cancelled
This commit is contained in:
parent
b84ebee289
commit
494c74ea6f
@ -13,7 +13,7 @@ import net.minecraft.server.PlayerManager;
|
|||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
public class BankManager {
|
public class BankManager {
|
||||||
BankManagerFile bankInfo = new BankManagerFile(); // not sure why we make another one but i guess so we
|
BankManagerFile bankInfo = new BankManagerFile();
|
||||||
ConfigManager config = new ConfigManager(); // for read and write privs
|
ConfigManager config = new ConfigManager(); // for read and write privs
|
||||||
CommonServerUtils commonServerUtils = new CommonServerUtils();
|
CommonServerUtils commonServerUtils = new CommonServerUtils();
|
||||||
|
|
||||||
@ -97,153 +97,110 @@ public class BankManager {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//https://maven.fabricmc.net/docs/fabric-api-0.34.8+1.17/net/fabricmc/fabric/api/networking/v1/PlayerLookup.html maybe this for getting the players im still not sure
|
|
||||||
public void SetBalance(Integer newBalance, String reason, String otherParty) {
|
|
||||||
Integer transactionNumber = bankInfo.bank.size();
|
|
||||||
bankInfo.bank.put(transactionNumber.toString(),
|
|
||||||
new BankManagerMetaData(newBalance, reason, newBalance, otherParty, 0));
|
|
||||||
|
|
||||||
FlashConfig(PlayerListNameChecker(otherParty));
|
public void SetBalance(long payment, String reason, ServerPlayerEntity otherParty) {
|
||||||
|
bankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(payment, reason, payment, "SERVER", 0));
|
||||||
|
FlashConfig(bankInfo.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddMoney(String reason, long payment, String otherParty) {
|
public void AddMoney(ServerPlayerEntity otherParty, long payment, ServerPlayerEntity player, String reason) {
|
||||||
|
bankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
bankInfo.bank = DoesBankAccountExist(otherParty);
|
||||||
if (bankInfo.bank.size() > 0) {
|
if (bankInfo.bank.size() > 0) {
|
||||||
for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
|
for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
|
||||||
entry.getValue().balance += payment;
|
entry.getValue().balance += payment;
|
||||||
entry.getValue().reason = "SERVER: " + reason;
|
entry.getValue().reason = "SERVER: " + reason;
|
||||||
entry.getValue().payment = payment;
|
entry.getValue().payment = payment;
|
||||||
entry.getValue().otherParty = otherParty;
|
entry.getValue().otherParty = "SERVER";
|
||||||
entry.getValue().time = 0;
|
entry.getValue().time = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(payment, reason, payment, otherParty, 0));
|
bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(payment, reason, payment, "SERVER", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
FlashConfig(PlayerListNameChecker(otherParty));
|
FlashConfig(otherParty.getUuidAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SubtractBalance(String reason, long payment, String otherParty) {
|
public void SubtractBalance(String reason, long payment, ServerPlayerEntity otherParty) {
|
||||||
if (bankInfo.bank.size() > 0) {
|
bankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
bankInfo.bank = DoesBankAccountExist(otherParty);
|
||||||
for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
|
for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
|
||||||
entry.getValue().balance -= payment;//not working?
|
entry.getValue().balance -= payment;//not working?
|
||||||
entry.getValue().reason = "SERVER: " + reason;
|
entry.getValue().reason = "SERVER: " + reason;
|
||||||
entry.getValue().payment = payment;
|
entry.getValue().payment = payment;
|
||||||
entry.getValue().otherParty = otherParty;
|
entry.getValue().otherParty = "SERVER";
|
||||||
entry.getValue().time = 0;
|
entry.getValue().time = 0;
|
||||||
}
|
}
|
||||||
} else {
|
FlashConfig(bankInfo.uuid);
|
||||||
bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(0, reason, payment, otherParty, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
FlashConfig(PlayerListNameChecker(otherParty));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Wire(String reason, long payment, String otherParty) {
|
public void Wire(ServerPlayerEntity otherParty, long payment, String reason, ServerPlayerEntity sender) {
|
||||||
if (bankInfo.bank.size() > 0) {
|
|
||||||
for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
|
BankManagerFile sendersBankInfo = new BankManagerFile();
|
||||||
|
BankManagerFile otherPartyBankInfo = new BankManagerFile();
|
||||||
|
sendersBankInfo.uuid = sender.getUuidAsString();
|
||||||
|
otherPartyBankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
sendersBankInfo.bank = DoesBankAccountExist(sender);
|
||||||
|
otherPartyBankInfo.bank = DoesBankAccountExist(otherParty);
|
||||||
|
|
||||||
|
|
||||||
|
//check to make sure they can afford to send the money
|
||||||
|
for (Entry<String, BankManagerMetaData> entry : sendersBankInfo.bank.entrySet()) {
|
||||||
|
if (entry.getValue().balance > payment) {
|
||||||
entry.getValue().balance -= payment;
|
entry.getValue().balance -= payment;
|
||||||
entry.getValue().reason = reason;
|
entry.getValue().reason = reason;
|
||||||
entry.getValue().payment = payment;
|
entry.getValue().payment = payment;
|
||||||
entry.getValue().otherParty = otherParty;
|
entry.getValue().otherParty = otherParty.getUuidAsString();
|
||||||
entry.getValue().time = 0;
|
entry.getValue().time = 0;
|
||||||
|
} else {
|
||||||
if (payment <= 0) {
|
System.out.println(ChatUtil.ColoredString("You ain't the goverment: " + otherParty, CONSOLE_COLOR.RED));
|
||||||
// add a error for the PLAYER not the server
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// make a server instance
|
|
||||||
MinecraftServer server = CommonServerUtils.GetServerInstance();
|
|
||||||
String[] playerList = server.getPlayerNames();
|
|
||||||
//NOT SURE IF THIS FOR LOOP IS ONE OFF COULD POSSIBLEY BE SO IF NO ONE IS GETTING MONEY DOUBLE CHECK FOR LOOP
|
|
||||||
for (int i = 0; i < playerList.length; i++) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("PLAYERS: " + playerList, CONSOLE_COLOR.YELLOW));
|
|
||||||
if (playerList[i] == otherParty) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Found Player: " + otherParty, CONSOLE_COLOR.GREEN));
|
|
||||||
// we will use getuuidbyname then set the other VALID players bank BE SURE TO
|
|
||||||
// MAKE THEM A BANK FIRST IF THEY DONT HAVE ONE fortnite forever
|
|
||||||
if (config.GetFile("bank/" + GetUuidByName(server, otherParty) + ".json").size() < 1) {
|
|
||||||
BankManagerFile newBankInfo = new BankManagerFile();
|
|
||||||
BankManagerMetaData newBank = new BankManagerMetaData(0, "Account Created", 0, "Server", 0);
|
|
||||||
newBankInfo.bank.put(GetUuidByName(server, otherParty).toString(), newBank);
|
|
||||||
try {
|
|
||||||
config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", newBankInfo);
|
|
||||||
} catch (FILE_WRITE_EXCEPTION e) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//since the other player has a account now and we have access to it we can start fucking around
|
|
||||||
BankManagerFile newBankInfo = new BankManagerFile();
|
|
||||||
newBankInfo = config.GetJsonObjectFromFile("bank/" + GetUuidByName(server, otherParty) + ".json", BankManagerFile.class);
|
|
||||||
// for now we will only use adding valance and not subtracting since that dosent make any sense
|
|
||||||
for (Entry<String, BankManagerMetaData> entry : newBankInfo.bank.entrySet()) {
|
|
||||||
entry.getValue().balance += payment;
|
|
||||||
entry.getValue().reason = reason;
|
|
||||||
entry.getValue().payment = payment;
|
|
||||||
entry.getValue().otherParty = otherParty;
|
|
||||||
entry.getValue().time = 0;
|
|
||||||
}
|
|
||||||
//cannot use regular flash config since the hard coded values need to add agurment for the uuid
|
|
||||||
//needs to be inside the player check
|
|
||||||
FlashConfig(newBankInfo.uuid);
|
|
||||||
try {
|
|
||||||
config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", bankInfo);
|
|
||||||
} catch (FILE_WRITE_EXCEPTION e) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Player Not Found: " + otherParty, CONSOLE_COLOR.RED));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println(ChatUtil.ColoredString("You need to finance better", CONSOLE_COLOR.RED));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String GetUuidByName(MinecraftServer server, String playerName) {
|
|
||||||
PlayerManager playerManager = server.getPlayerManager();
|
|
||||||
ServerPlayerEntity player = playerManager.getPlayer(playerName);
|
|
||||||
if (player.getUuid() != null) {
|
|
||||||
return player.getUuidAsString();
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String PlayerListNameChecker(String otherParty) {
|
|
||||||
MinecraftServer server = CommonServerUtils.GetServerInstance();
|
|
||||||
String[] playerList = server.getPlayerNames();
|
|
||||||
|
|
||||||
for (int i = 0; i < playerList.length; i++) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("PLAYERS: " + playerList, CONSOLE_COLOR.YELLOW));
|
|
||||||
if (playerList[i] == otherParty) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Found Player: " + otherParty, CONSOLE_COLOR.GREEN));
|
|
||||||
// we will use getuuidbyname then set the other VALID players bank BE SURE TO
|
|
||||||
// MAKE THEM A BANK FIRST IF THEY DONT HAVE ONE fortnite forever
|
|
||||||
if (config.GetFile("bank/" + GetUuidByName(server, otherParty) + ".json").size() < 1) {
|
|
||||||
BankManagerFile newBankInfo = new BankManagerFile();
|
|
||||||
BankManagerMetaData newBank = new BankManagerMetaData(0, "Account Created", 0, "Server", 0);
|
|
||||||
newBankInfo.bank.put(GetUuidByName(server, otherParty).toString(), newBank);
|
|
||||||
try {
|
|
||||||
config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", newBankInfo);
|
|
||||||
} catch (FILE_WRITE_EXCEPTION e) {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.out.println(ChatUtil.ColoredString("Bank Account Found", CONSOLE_COLOR.GREEN));
|
|
||||||
}
|
|
||||||
return GetUuidByName(server, otherParty);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(ChatUtil.ColoredString("For Loop condition bypassed Null Playerlist or Null Server instance", CONSOLE_COLOR.RED));
|
for (Entry<String, BankManagerMetaData> entry : otherPartyBankInfo.bank.entrySet()) {
|
||||||
return "";
|
entry.getValue().balance += payment;
|
||||||
|
entry.getValue().reason = reason;
|
||||||
|
entry.getValue().payment = payment;
|
||||||
|
entry.getValue().otherParty = otherParty.getUuidAsString();
|
||||||
|
entry.getValue().time = 0;
|
||||||
|
}
|
||||||
|
//needs to be inside the player check flash config has a write check
|
||||||
|
FlashConfig(otherPartyBankInfo.uuid);
|
||||||
|
FlashConfig(sendersBankInfo.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, BankManagerMetaData> DoesBankAccountExist(ServerPlayerEntity otherParty) {
|
||||||
|
Boolean existingFile = false;
|
||||||
|
try {
|
||||||
|
bankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
bankInfo = config.GetJsonObjectFromFile("bank/" + otherParty.getUuidAsString() + ".json", BankManagerFile.class);
|
||||||
|
existingFile = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Do nothing. This means the file does not exist
|
||||||
|
}
|
||||||
|
if (!existingFile) {
|
||||||
|
System.out.println("Procced no account exisiting");
|
||||||
|
BankManagerFile newBankInfo = new BankManagerFile();
|
||||||
|
BankManagerMetaData newBank = new BankManagerMetaData(0, "Account Created", 0, "Server", 0);
|
||||||
|
newBankInfo.uuid = otherParty.getUuidAsString();
|
||||||
|
newBankInfo.bank.put(newBankInfo.uuid, newBank);
|
||||||
|
try {
|
||||||
|
config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", newBankInfo);
|
||||||
|
} catch (FILE_WRITE_EXCEPTION e) {
|
||||||
|
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
||||||
|
return newBankInfo.bank;
|
||||||
|
}
|
||||||
|
return newBankInfo.bank;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
bankInfo = config.GetJsonObjectFromFile("bank/" + bankInfo.uuid + ".json", BankManagerFile.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Do nothing. This means the file does not exist
|
||||||
|
System.out.println("How did this fail Function: DoesBankAccountExist try catch statement -first if failed incorrectly");
|
||||||
|
}
|
||||||
|
return bankInfo.bank;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FlashConfig(String uuid) {
|
public void FlashConfig(String uuid) {
|
||||||
|
@ -7,6 +7,7 @@ import com.mojang.brigadier.context.CommandContext;
|
|||||||
|
|
||||||
import jesse.keeblarcraft.BankMgr.BankManager;
|
import jesse.keeblarcraft.BankMgr.BankManager;
|
||||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||||
|
import net.minecraft.command.argument.EntityArgumentType;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@ -17,68 +18,94 @@ public class BankCommands {
|
|||||||
ConfigManager config = new ConfigManager();
|
ConfigManager config = new ConfigManager();
|
||||||
|
|
||||||
public void RegisterCommands(){
|
public void RegisterCommands(){
|
||||||
// Command: "/getbalance"
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
dispatcher.register(CommandManager.literal("getbalance")
|
var rootBank = CommandManager.literal("bank").build();
|
||||||
.executes(context -> GetBalance(context)));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Command: "/setbalance || rootSetBalance"
|
//second layer of tree
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
var balance = CommandManager.literal("balance").build();
|
||||||
final var rootSetBalance = dispatcher.register(CommandManager.literal("setbalance")
|
var wire = CommandManager.literal("wire").build();
|
||||||
.then(CommandManager.argument("newBalance", IntegerArgumentType.integer())
|
|
||||||
.then(CommandManager.argument("reason", StringArgumentType.string())
|
|
||||||
.then(CommandManager.argument("otherParty", StringArgumentType.string())
|
|
||||||
.executes(context -> SetBalance(
|
|
||||||
IntegerArgumentType.getInteger(context, "newBalance"),
|
|
||||||
StringArgumentType.getString(context, "reason"),
|
|
||||||
StringArgumentType.getString(context, "otherParty"),
|
|
||||||
context))))));
|
|
||||||
|
|
||||||
dispatcher.register(CommandManager.literal("setbalance").redirect(rootSetBalance));
|
//third layer of tree
|
||||||
});
|
var setBalance = CommandManager.literal("setBalance").build();
|
||||||
|
var getBalance = CommandManager.literal("getBalance").build();
|
||||||
|
var addMoney = CommandManager.literal("addMoney").build();
|
||||||
|
var subtractBalance = CommandManager.literal("subtractBalance").build();
|
||||||
|
|
||||||
// Command: "/AddMoney"
|
var playerArgAdd = CommandManager.argument("otherParty", EntityArgumentType.player()).build();
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
var paymentArg = CommandManager.argument("payment", LongArgumentType.longArg()).build();
|
||||||
dispatcher.register(CommandManager.literal("AddMoney")
|
|
||||||
.then(CommandManager.argument("reason", StringArgumentType.string())
|
|
||||||
.then(CommandManager.argument("payment", LongArgumentType.longArg())
|
|
||||||
.then(CommandManager.argument("otherParty", StringArgumentType.string())
|
|
||||||
.executes(context -> AddMoney(
|
|
||||||
StringArgumentType.getString(context, "reason"),
|
|
||||||
LongArgumentType.getLong(context, "payment"),
|
|
||||||
StringArgumentType.getString(context, "otherParty"),
|
|
||||||
context))))));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Command: "/subtractbalance || /SubtractBalance"
|
var wireFunction = CommandManager.argument("reason", StringArgumentType.greedyString())
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
.executes(context -> Wire
|
||||||
final var SubtractBalance = dispatcher.register(CommandManager.literal("subtractbalance")
|
(
|
||||||
.then(CommandManager.argument("reason", StringArgumentType.string())
|
EntityArgumentType.getPlayer(context, "otherParty"),
|
||||||
.then(CommandManager.argument("payment", LongArgumentType.longArg())
|
LongArgumentType.getLong(context, "payment"),
|
||||||
.then(CommandManager.argument("otherParty", StringArgumentType.string())
|
StringArgumentType.getString(context, "reason"),
|
||||||
.executes(context -> SubtractBalance(
|
context)
|
||||||
StringArgumentType.getString(context, "reason"),
|
)
|
||||||
LongArgumentType.getLong(context, "payment"),
|
.build();
|
||||||
StringArgumentType.getString(context, "otherParty"),
|
|
||||||
context))))));
|
|
||||||
|
|
||||||
dispatcher.register(CommandManager.literal("subtractbalance").redirect(SubtractBalance));
|
var setBalanceFunction = CommandManager.argument("reason", StringArgumentType.greedyString())
|
||||||
});
|
.executes(context -> SetBalance
|
||||||
|
(
|
||||||
|
EntityArgumentType.getPlayer(context, "otherParty"),
|
||||||
|
LongArgumentType.getLong(context, "payment"),
|
||||||
|
StringArgumentType.getString(context, "reason"),
|
||||||
|
context)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var addMoneyFunction = CommandManager.argument("reason", StringArgumentType.greedyString())
|
||||||
|
.executes(context -> AddMoney
|
||||||
|
(
|
||||||
|
EntityArgumentType.getPlayer(context, "otherParty"),
|
||||||
|
LongArgumentType.getLong(context, "payment"),
|
||||||
|
StringArgumentType.getString(context, "reason"),
|
||||||
|
context)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Command: "/wire || /sendmoney"
|
var subtractMoneyFunction = CommandManager.argument("reason", StringArgumentType.greedyString())
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
.executes(context -> SubtractBalance
|
||||||
final var sendmoney = dispatcher.register(CommandManager.literal("wire")
|
(
|
||||||
.then(CommandManager.argument("reason", StringArgumentType.string())
|
EntityArgumentType.getPlayer(context, "otherParty"),
|
||||||
.then(CommandManager.argument("payment", LongArgumentType.longArg())
|
LongArgumentType.getLong(context, "payment"),
|
||||||
.then(CommandManager.argument("otherParty", StringArgumentType.string())
|
StringArgumentType.getString(context, "reason"),
|
||||||
.executes(context -> Wire(
|
context)
|
||||||
StringArgumentType.getString(context, "reason"),
|
)
|
||||||
LongArgumentType.getLong(context, "payment"),
|
.build();
|
||||||
StringArgumentType.getString(context, "otherParty"),
|
|
||||||
context))))));
|
|
||||||
|
|
||||||
dispatcher.register(CommandManager.literal("wire").redirect(sendmoney));
|
|
||||||
|
// Build out the argument tree here
|
||||||
|
dispatcher.getRoot().addChild(rootBank);
|
||||||
|
rootBank.addChild(wire);
|
||||||
|
rootBank.addChild(balance);
|
||||||
|
|
||||||
|
// Subcommands of balance node "/getbalance", [ADMIN->] "/setbalance", "/subtractbalance", "/addmoney"
|
||||||
|
balance.addChild(getBalance);
|
||||||
|
balance.addChild(setBalance);
|
||||||
|
balance.addChild(subtractBalance);
|
||||||
|
balance.addChild(addMoney);
|
||||||
|
|
||||||
|
//subcommands of wire node "/playernamehere"
|
||||||
|
wire.addChild(playerArgAdd);
|
||||||
|
playerArgAdd.addChild(paymentArg);
|
||||||
|
paymentArg.addChild(wireFunction);
|
||||||
|
|
||||||
|
//subcommands of setBalance
|
||||||
|
setBalance.addChild(playerArgAdd);
|
||||||
|
playerArgAdd.addChild(paymentArg);
|
||||||
|
paymentArg.addChild(setBalanceFunction);
|
||||||
|
|
||||||
|
//subcommands of addMoney
|
||||||
|
addMoney.addChild(playerArgAdd);
|
||||||
|
playerArgAdd.addChild(paymentArg);
|
||||||
|
paymentArg.addChild(addMoneyFunction);
|
||||||
|
|
||||||
|
//subcommands for subtractbalance
|
||||||
|
subtractBalance.addChild(playerArgAdd);
|
||||||
|
playerArgAdd.addChild(paymentArg);
|
||||||
|
paymentArg.addChild(subtractMoneyFunction);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,28 +123,27 @@ public class BankCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//SetBalance will be a ServerCommand only Perm level Op
|
//SetBalance will be a ServerCommand only Perm level Op
|
||||||
public Integer SetBalance(Integer newBalance, String reason, String otherParty, CommandContext<ServerCommandSource> context) {
|
public Integer SetBalance(ServerPlayerEntity otherParty, long payment, String reason, CommandContext<ServerCommandSource> context) {
|
||||||
Integer ret = -1;
|
Integer ret = -1;
|
||||||
|
|
||||||
if (context.getSource().hasPermissionLevel(1)) {
|
if (context.getSource().hasPermissionLevel(1)) {
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
BankManager playerBank = new BankManager(otherParty.getUuidAsString());
|
||||||
BankManager playerBank = new BankManager(player.getUuidAsString());
|
System.out.println("UUID TEST IN COMMANDS " + otherParty.getUuidAsString());
|
||||||
playerBank.SetBalance(newBalance, reason, otherParty);
|
playerBank.SetBalance(payment, reason, otherParty);
|
||||||
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddMoney will be a ServerCommand Only Perm level Op
|
//AddMoney will be a ServerCommand Only Perm level Op
|
||||||
public Integer AddMoney(String reason, long payment, String otherParty, CommandContext<ServerCommandSource> context) {
|
public Integer AddMoney(ServerPlayerEntity otherParty, long payment, String reason, CommandContext<ServerCommandSource> context) {
|
||||||
Integer ret = -1;
|
Integer ret = -1;
|
||||||
|
|
||||||
if (context.getSource().hasPermissionLevel(1)) {
|
if (context.getSource().hasPermissionLevel(1)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
BankManager playerBank = new BankManager(player.getUuidAsString());
|
BankManager playerBank = new BankManager(player.getUuidAsString());
|
||||||
playerBank.AddMoney(reason, payment, otherParty);
|
playerBank.AddMoney(otherParty, payment, player, reason);
|
||||||
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,31 +151,34 @@ public class BankCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//SubtractBalance will be a ServerCommand Perm leve Op
|
//SubtractBalance will be a ServerCommand Perm leve Op
|
||||||
public Integer SubtractBalance(String reason, long payment, String otherParty, CommandContext<ServerCommandSource> context) {
|
public Integer SubtractBalance(ServerPlayerEntity otherParty, long payment, String reason, CommandContext<ServerCommandSource> context) {
|
||||||
Integer ret = -1;
|
Integer ret = -1;
|
||||||
|
|
||||||
if (context.getSource().hasPermissionLevel(1)) {
|
if (context.getSource().hasPermissionLevel(1)) {
|
||||||
ret = 0;
|
BankManager playerBank = new BankManager(otherParty.getUuidAsString());
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
||||||
BankManager playerBank = new BankManager(player.getUuidAsString());
|
|
||||||
playerBank.SubtractBalance(reason, payment, otherParty);
|
playerBank.SubtractBalance(reason, payment, otherParty);
|
||||||
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
otherParty.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer Wire(String reason, long payment, String otherParty, CommandContext<ServerCommandSource> context) {
|
public Integer Wire(ServerPlayerEntity otherParty, long payment, String reason, CommandContext<ServerCommandSource> context) {
|
||||||
Integer ret = -1;
|
Integer ret = -1;
|
||||||
|
|
||||||
if (context.getSource().isExecutedByPlayer()) {
|
if (context.getSource().isExecutedByPlayer()) {
|
||||||
|
ServerPlayerEntity sender = context.getSource().getPlayer();
|
||||||
|
BankManager playerBank = new BankManager(sender.getUuidAsString());
|
||||||
|
if (sender.getUuidAsString() == otherParty.getUuidAsString()) {
|
||||||
|
sender.sendMessage(Text.of("you aint congress"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
playerBank.Wire(otherParty, payment, reason, sender);
|
||||||
|
sender.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
||||||
ret = 0;
|
ret = 0;
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
||||||
BankManager playerBank = new BankManager(player.getUuidAsString());
|
|
||||||
playerBank.Wire(reason, payment, otherParty);
|
|
||||||
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user