Skip to content

Commit

Permalink
TNK Account Types.
Browse files Browse the repository at this point in the history
Signed-off-by: creatorfromhell <[email protected]>
  • Loading branch information
creatorfromhell committed Aug 28, 2023
1 parent 426843d commit 23d05b4
Show file tree
Hide file tree
Showing 16 changed files with 475 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Bukkit/src/net/tnemc/bukkit/command/AdminCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions Core/resources/currency/USD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Formatting:
Major_Separator: ','



#All configurations relating to currency notes.
Note:

Expand Down
2 changes: 1 addition & 1 deletion Core/src/net/tnemc/core/account/PlayerAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
1 change: 1 addition & 0 deletions Core/src/net/tnemc/core/currency/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {

Expand Down
56 changes: 56 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/CampAccount.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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);
}
}
50 changes: 50 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/CampCheck.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<String, Boolean> 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;
}
};
}
}
56 changes: 56 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/KingdomAccount.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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);
}
}
50 changes: 50 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/KingdomCheck.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<String, Boolean> 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;
}
};
}
}
56 changes: 56 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/PactAccount.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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);
}
}
50 changes: 50 additions & 0 deletions Core/src/net/tnemc/core/hook/tnk/PactCheck.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<String, Boolean> 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;
}
};
}
}
Loading

0 comments on commit 23d05b4

Please sign in to comment.