From 23d05b4a1c9752c2a12e54ddeb6b4793bd774e61 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sun, 27 Aug 2023 21:08:22 -0400 Subject: [PATCH] TNK Account Types. Signed-off-by: creatorfromhell --- .../tnemc/bukkit/command/AdminCommand.java | 4 +- .../tnemc/bukkit/hook/economy/TNEVault.java | 2 + Core/resources/currency/USD.yml | 1 + .../net/tnemc/core/account/PlayerAccount.java | 2 +- .../src/net/tnemc/core/currency/Currency.java | 1 + .../handlers/player/PlayerJoinHandler.java | 2 +- .../net/tnemc/core/hook/tnk/CampAccount.java | 56 +++++++++++++++++++ .../net/tnemc/core/hook/tnk/CampCheck.java | 50 +++++++++++++++++ .../tnemc/core/hook/tnk/KingdomAccount.java | 56 +++++++++++++++++++ .../net/tnemc/core/hook/tnk/KingdomCheck.java | 50 +++++++++++++++++ .../net/tnemc/core/hook/tnk/PactAccount.java | 56 +++++++++++++++++++ .../net/tnemc/core/hook/tnk/PactCheck.java | 50 +++++++++++++++++ .../net/tnemc/core/hook/tnk/TNKHandler.java | 37 ++++++++++++ .../tnemc/core/hook/tnk/VillageAccount.java | 55 ++++++++++++++++++ .../net/tnemc/core/hook/tnk/VillageCheck.java | 51 +++++++++++++++++ changelog.md | 6 ++ 16 files changed, 475 insertions(+), 4 deletions(-) create mode 100644 Core/src/net/tnemc/core/hook/tnk/CampAccount.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/CampCheck.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/KingdomAccount.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/KingdomCheck.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/PactAccount.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/PactCheck.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/TNKHandler.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/VillageAccount.java create mode 100644 Core/src/net/tnemc/core/hook/tnk/VillageCheck.java create mode 100644 changelog.md diff --git a/Bukkit/src/net/tnemc/bukkit/command/AdminCommand.java b/Bukkit/src/net/tnemc/bukkit/command/AdminCommand.java index 9546fe57..2c026c8f 100644 --- a/Bukkit/src/net/tnemc/bukkit/command/AdminCommand.java +++ b/Bukkit/src/net/tnemc/bukkit/command/AdminCommand.java @@ -231,8 +231,8 @@ public static boolean restoreOld(@Nullable final Integer extraction) { } final AccountAPIResponse response = TNECore.eco().account().createAccount(id.toString(), username, nonPlayer); - if(!response.getResponse().success() || response.getAccount().isEmpty()) { - TNECore.log().inform("Couldn't create account for " + username + ". Skipping.", DebugLevel.OFF); + if(response.getAccount().isEmpty()) { + TNECore.log().inform("Couldn't create account for " + username + ". Reason: " + response.getResponse().response(), DebugLevel.OFF); continue; } diff --git a/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java b/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java index 43e0374e..3dcbc6bc 100644 --- a/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java +++ b/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java @@ -543,6 +543,7 @@ public boolean createPlayerAccount(OfflinePlayer player) { */ @Deprecated public boolean createPlayerAccount(String name, String world) { + TNECore.log().debug("Vault Method: Create Player Account!", DebugLevel.STANDARD); return TNECore.eco().account().createAccount(name, name).getResponse().success(); } @@ -554,6 +555,7 @@ public boolean createPlayerAccount(String name, String world) { * @return if the account creation was successful */ public boolean createPlayerAccount(OfflinePlayer player, String world) { + TNECore.log().debug("Vault Method: Create Player Account!", DebugLevel.STANDARD); return TNECore.eco().account().createAccount(player.getUniqueId().toString(), player.getName()).getResponse().success(); } diff --git a/Core/resources/currency/USD.yml b/Core/resources/currency/USD.yml index 6dc55b46..2fecb37e 100644 --- a/Core/resources/currency/USD.yml +++ b/Core/resources/currency/USD.yml @@ -138,6 +138,7 @@ Formatting: Major_Separator: ',' + #All configurations relating to currency notes. Note: diff --git a/Core/src/net/tnemc/core/account/PlayerAccount.java b/Core/src/net/tnemc/core/account/PlayerAccount.java index 9a287334..eed2fcd1 100644 --- a/Core/src/net/tnemc/core/account/PlayerAccount.java +++ b/Core/src/net/tnemc/core/account/PlayerAccount.java @@ -45,7 +45,7 @@ public PlayerAccount(UUID identifier, String name) { this.uuid = identifier; //Defaults - this.lastOnline = new Date().getTime(); + this.lastOnline = creationDate; this.language = "TNE_DEFAULT"; } diff --git a/Core/src/net/tnemc/core/currency/Currency.java b/Core/src/net/tnemc/core/currency/Currency.java index 2c60a07c..5862eed8 100644 --- a/Core/src/net/tnemc/core/currency/Currency.java +++ b/Core/src/net/tnemc/core/currency/Currency.java @@ -62,6 +62,7 @@ public class Currency { private String symbol; private String prefixes; private String decimal; + private String display; private String displayPlural; private String displayMinor; diff --git a/Core/src/net/tnemc/core/handlers/player/PlayerJoinHandler.java b/Core/src/net/tnemc/core/handlers/player/PlayerJoinHandler.java index fb2cccc7..af17df43 100644 --- a/Core/src/net/tnemc/core/handlers/player/PlayerJoinHandler.java +++ b/Core/src/net/tnemc/core/handlers/player/PlayerJoinHandler.java @@ -77,7 +77,7 @@ public HandlerResponse handle(PlayerProvider provider) { final String id = provider.identifier().toString(); if(acc.isPresent()) { - if(firstJoin) { + if(firstJoin || acc.get().getCreationDate() == ((PlayerAccount)acc.get()).getLastOnline()) { final String region = TNECore.eco().region().getMode().region(provider); for(Currency currency : TNECore.eco().currency().currencies()) { diff --git a/Core/src/net/tnemc/core/hook/tnk/CampAccount.java b/Core/src/net/tnemc/core/hook/tnk/CampAccount.java new file mode 100644 index 00000000..38d544f1 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/CampAccount.java @@ -0,0 +1,56 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.NonPlayerAccount; + +/** + * Represents an account linked to a Camp in the TNK Plugin. + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class CampAccount extends NonPlayerAccount { + + public CampAccount(String identifier, String name) { + super(identifier, name); + //this.owner = Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getKing().getUUID(); + } + + /** + * Used to get the type of account that this is. This is for data-purposes only. + * + * @return The account type. + */ + @Override + public String type() { + return "kingdom"; + } + + @Override + public String generateIdentifier(String name) { + + try { + //return Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getUUID().toString(); + } catch(Exception ignore) { + return super.generateIdentifier(name); + } + return super.generateIdentifier(name); + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/CampCheck.java b/Core/src/net/tnemc/core/hook/tnk/CampCheck.java new file mode 100644 index 00000000..40bbc054 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/CampCheck.java @@ -0,0 +1,50 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.AccountTypeCheck; + +import java.util.function.Function; + +/** + * CampCheck + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class CampCheck implements AccountTypeCheck { + /** + * Returns our check function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + * + * @return Our function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + */ + @Override + public Function check() { + return value -> { + try { + return value.contains("camp"); + } catch(Exception e) { + //towny probably isn't enabled yet, or something went wrong enabling it. + return false; + } + }; + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/KingdomAccount.java b/Core/src/net/tnemc/core/hook/tnk/KingdomAccount.java new file mode 100644 index 00000000..e8dd264e --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/KingdomAccount.java @@ -0,0 +1,56 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.NonPlayerAccount; + +/** + * Represents an account linked to a Kingdom in the TNK Plugin. + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class KingdomAccount extends NonPlayerAccount { + + public KingdomAccount(String identifier, String name) { + super(identifier, name); + //this.owner = Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getKing().getUUID(); + } + + /** + * Used to get the type of account that this is. This is for data-purposes only. + * + * @return The account type. + */ + @Override + public String type() { + return "kingdom"; + } + + @Override + public String generateIdentifier(String name) { + + try { + //return Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getUUID().toString(); + } catch(Exception ignore) { + return super.generateIdentifier(name); + } + return super.generateIdentifier(name); + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/KingdomCheck.java b/Core/src/net/tnemc/core/hook/tnk/KingdomCheck.java new file mode 100644 index 00000000..59693e90 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/KingdomCheck.java @@ -0,0 +1,50 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.AccountTypeCheck; + +import java.util.function.Function; + +/** + * KingdomCheck + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class KingdomCheck implements AccountTypeCheck { + /** + * Returns our check function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + * + * @return Our function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + */ + @Override + public Function check() { + return value -> { + try { + return value.contains("kingdom"); + } catch(Exception e) { + //towny probably isn't enabled yet, or something went wrong enabling it. + return false; + } + }; + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/PactAccount.java b/Core/src/net/tnemc/core/hook/tnk/PactAccount.java new file mode 100644 index 00000000..e2309f08 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/PactAccount.java @@ -0,0 +1,56 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.NonPlayerAccount; + +/** + * Represents an account linked to a Pact in the TNK Plugin. + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class PactAccount extends NonPlayerAccount { + + public PactAccount(String identifier, String name) { + super(identifier, name); + //this.owner = Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getKing().getUUID(); + } + + /** + * Used to get the type of account that this is. This is for data-purposes only. + * + * @return The account type. + */ + @Override + public String type() { + return "pact"; + } + + @Override + public String generateIdentifier(String name) { + + try { + //return Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getUUID().toString(); + } catch(Exception ignore) { + return super.generateIdentifier(name); + } + return super.generateIdentifier(name); + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/PactCheck.java b/Core/src/net/tnemc/core/hook/tnk/PactCheck.java new file mode 100644 index 00000000..50bc9275 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/PactCheck.java @@ -0,0 +1,50 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.AccountTypeCheck; + +import java.util.function.Function; + +/** + * PactCheck + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class PactCheck implements AccountTypeCheck { + /** + * Returns our check function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + * + * @return Our function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + */ + @Override + public Function check() { + return value -> { + try { + return value.contains("pact"); + } catch(Exception e) { + //towny probably isn't enabled yet, or something went wrong enabling it. + return false; + } + }; + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/TNKHandler.java b/Core/src/net/tnemc/core/hook/tnk/TNKHandler.java new file mode 100644 index 00000000..b4e2b0f0 --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/TNKHandler.java @@ -0,0 +1,37 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.TNECore; + +/** + * TNKHandler + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class TNKHandler { + + public static void addTypes() { + TNECore.eco().account().addAccountType(PactAccount.class, new PactCheck().check()); + TNECore.eco().account().addAccountType(KingdomAccount.class, new KingdomCheck().check()); + TNECore.eco().account().addAccountType(VillageAccount.class, new VillageCheck().check()); + TNECore.eco().account().addAccountType(CampAccount.class, new CampCheck().check()); + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/VillageAccount.java b/Core/src/net/tnemc/core/hook/tnk/VillageAccount.java new file mode 100644 index 00000000..59a0d8ad --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/VillageAccount.java @@ -0,0 +1,55 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.NonPlayerAccount; + +/** + * Represents an account linked to a Village in the TNK Plugin. + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class VillageAccount extends NonPlayerAccount { + + public VillageAccount(String identifier, String name) { + super(identifier, name); + //this.owner = Objects.requireNonNull(TownyAPI.getInstance().getTown(name)).getMayor().getUUID(); + } + + /** + * Used to get the type of account that this is. This is for data-purposes only. + * + * @return The account type. + */ + @Override + public String type() { + return "town"; + } + + @Override + public String generateIdentifier(String name) { + try { + //return Objects.requireNonNull(TownyAPI.getInstance().getTown(name)).getUUID().toString(); + } catch(Exception ignore) { + return super.generateIdentifier(name); + } + return super.generateIdentifier(name); + } +} \ No newline at end of file diff --git a/Core/src/net/tnemc/core/hook/tnk/VillageCheck.java b/Core/src/net/tnemc/core/hook/tnk/VillageCheck.java new file mode 100644 index 00000000..054b35ee --- /dev/null +++ b/Core/src/net/tnemc/core/hook/tnk/VillageCheck.java @@ -0,0 +1,51 @@ +package net.tnemc.core.hook.tnk; + +/* + * The New Economy + * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import net.tnemc.core.account.AccountTypeCheck; + +import java.util.function.Function; + +/** + * VillageCheck + * + * @author creatorfromhell + * @since 0.1.2.0 + */ +public class VillageCheck implements AccountTypeCheck { + + /** + * Returns our check function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + * + * @return Our function that should be used to check if a given String identifier, usually name, + * is valid for this account type. + */ + @Override + public Function check() { + return value -> { + try { + return value.contains("town"); + } catch(Exception e) { + //towny probably isn't enabled yet, or something went wrong enabling it. + return false; + } + }; + } +} \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..b3d28215 --- /dev/null +++ b/changelog.md @@ -0,0 +1,6 @@ +# 0.1.2.0 Build 29 +- Added message for console that outlines when accounts are loaded with balances of currencies that don't exist. +- Made default last online date be the same as creation date for player accounts + - This is now taken into account for ImportItems config in config.yml +- Add TNK Account Types for alpha testing The New Kings + - Adds Village, Kingdom, Pact, Camp types \ No newline at end of file