Skip to content

Commit

Permalink
Potion fixes, Experience level currency type.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 3, 2024
1 parent c2f25e4 commit c44cf03
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 175 deletions.
1 change: 0 additions & 1 deletion Bukkit/src/net/tnemc/bukkit/command/ShortCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import revxrsal.commands.annotation.Default;
import revxrsal.commands.annotation.Description;
import revxrsal.commands.annotation.Named;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.annotation.Usage;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.annotation.CommandPermission;
Expand Down
7 changes: 0 additions & 7 deletions Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
<version>32.1.1-jre</version>
<scope>provided</scope>
</dependency>
<!-- LuckPerms API -->
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.tnemc</groupId>
Expand Down
3 changes: 3 additions & 0 deletions Core/src/net/tnemc/core/EconomyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.tnemc.core.account.holdings.HoldingsHandler;
import net.tnemc.core.account.holdings.handlers.EnderChestHandler;
import net.tnemc.core.account.holdings.handlers.ExperienceHandler;
import net.tnemc.core.account.holdings.handlers.ExperienceLevelHandler;
import net.tnemc.core.account.holdings.handlers.InventoryHandler;
import net.tnemc.core.account.holdings.handlers.VirtualHandler;
import net.tnemc.core.config.MainConfig;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class EconomyManager {

public static final Identifier VIRTUAL = new Identifier("tne", "VIRTUAL_HOLDINGS");
public static final Identifier EXPERIENCE = new Identifier("tne", "EXPERIENCE_HOLDINGS");
public static final Identifier EXPERIENCE_LEVEL = new Identifier("tne", "EXPERIENCE_LEVEL_HOLDINGS");
public static final Identifier ITEM_ONLY = new Identifier("tne", "ITEM_ONLY");

public static final Identifier INVENTORY_ONLY = new Identifier("tne", "INVENTORY_HOLDINGS");
Expand Down Expand Up @@ -113,6 +115,7 @@ public void init() {
//Add our core handlers
addHandler(new VirtualHandler());
addHandler(new ExperienceHandler());
addHandler(new ExperienceLevelHandler());
addHandler(new InventoryHandler());
addHandler(new EnderChestHandler());
}
Expand Down
1 change: 0 additions & 1 deletion Core/src/net/tnemc/core/TNECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.tnemc.core.account.Account;
import net.tnemc.core.account.AccountStatus;
Expand Down
2 changes: 0 additions & 2 deletions Core/src/net/tnemc/core/account/holdings/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import net.tnemc.core.EconomyManager;
import net.tnemc.core.account.holdings.modify.HoldingsModifier;
import net.tnemc.core.utils.Identifier;
import net.tnemc.plugincore.PluginCore;
import net.tnemc.plugincore.core.compatibility.log.DebugLevel;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public boolean supports(CurrencyType type) {
*/
@Override
public boolean setHoldings(Account account, String region, Currency currency, CurrencyType type, BigDecimal amount) {
account.getWallet().setHoldings(new HoldingsEntry(region, currency.getUid(), amount, identifier()));
if(account.isPlayer() && ((PlayerAccount)account).isOnline()) {
Experience.setExperience(((PlayerAccount)account).getPlayer().get(), amount.intValueExact());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package net.tnemc.core.account.holdings.handlers;

/*
* The New Economy
* Copyright (C) 2022 - 2024 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.Account;
import net.tnemc.core.account.PlayerAccount;
import net.tnemc.core.account.holdings.HoldingsEntry;
import net.tnemc.core.account.holdings.HoldingsHandler;
import net.tnemc.core.currency.Currency;
import net.tnemc.core.currency.CurrencyType;
import net.tnemc.core.currency.type.ExperienceLevelType;
import net.tnemc.core.currency.type.ExperienceType;
import net.tnemc.core.utils.Identifier;
import net.tnemc.plugincore.core.utils.Experience;

import java.math.BigDecimal;
import java.util.Optional;

import static net.tnemc.core.EconomyManager.EXPERIENCE;
import static net.tnemc.core.EconomyManager.EXPERIENCE_LEVEL;

/**
* ExperienceHandler
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class ExperienceLevelHandler implements HoldingsHandler {
/**
* The identifier for this handler.
*
* @return The identifier that represents this handler.
*/
@Override
public Identifier identifier() {
return EXPERIENCE_LEVEL;
}

/**
* Used to determine if this handler may be used for the specified {@link CurrencyType}.
*
* @param type The currency type.
*
* @return True if it supports the currency type, otherwise false.
*/
@Override
public boolean supports(CurrencyType type) {
return (type instanceof ExperienceLevelType);
}

/**
* Used to set the holdings for a specific account.
*
* @param account The account.
* @param region The name of the region involved. This is usually a world, but could be something
* else such as a world guard region name/identifier.
* @param currency The instance of the currency to use.
* @param type The currency type.
* @param amount The amount to set the player's holdings to.
*
* @return True if the holdings have been set, otherwise false.
*/
@Override
public boolean setHoldings(Account account, String region, Currency currency, CurrencyType type, BigDecimal amount) {
account.getWallet().setHoldings(new HoldingsEntry(region, currency.getUid(), amount, identifier()));

if(account instanceof PlayerAccount player && player.isOnline() && player.getPlayer().isPresent()) {
Experience.setLevel(player.getPlayer().get(), amount.intValueExact());
}
return true;
}

/**
* Used to get the holdings for a specific account from this handler.
*
* @param account The Account.
* @param region The name of the region involved. This is usually a world, but could be something
* else such as a world guard region name/identifier.
* @param currency The instance of the currency to use.
* @param type The currency type.
*
* @return The holdings for the specific account.
*/
@Override
public HoldingsEntry getHoldings(Account account, String region, Currency currency, CurrencyType type) {
if(account instanceof PlayerAccount player && player.isOnline() && player.getPlayer().isPresent()) {

final BigDecimal amount = new BigDecimal(player.getPlayer().get().getExpLevel());
final HoldingsEntry entry = new HoldingsEntry(region, currency.getUid(), amount, EXPERIENCE);

account.getWallet().setHoldings(entry);
return entry;
}

final Optional<HoldingsEntry> holdings = account.getWallet().getHoldings(region,
currency.getUid(),
EXPERIENCE_LEVEL
);

return holdings.orElseGet(()->new HoldingsEntry(region,
currency.getUid(),
BigDecimal.ZERO,
EXPERIENCE_LEVEL
));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tnemc.sponge.hook.misc;
package net.tnemc.core.currency.type;

/*
* The New Economy
Expand All @@ -18,22 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.luckperms.api.LuckPerms;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.service.ServiceRegistration;

import java.util.Optional;
import net.tnemc.core.EconomyManager;
import net.tnemc.core.currency.CurrencyType;
import net.tnemc.core.utils.Identifier;

/**
* LuckPermsHook
* ExperienceType
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class LuckPermsHook {
public class ExperienceLevelType implements CurrencyType {
/**
* @return The name of this currency type. Examples: Virtual, Item
*/
@Override
public String name() {
return "experience-level";
}

@Override
public String description() {
return "A simple currency based on experience. Not the most accurate...";
}

@Override
public boolean supportsVirtual() {
return false;
}

public static void register() {
final Optional<ServiceRegistration<LuckPerms>> provider = Sponge.serviceProvider().registration(LuckPerms.class);
//provider.ifPresent(luckPermsServiceRegistration->luckPermsServiceRegistration.service().getContextManager().registerCalculator(new LuckBalanceContext()));
@Override
public Identifier defaultHandler() {
return EconomyManager.EXPERIENCE_LEVEL;
}
}
}
70 changes: 0 additions & 70 deletions Core/src/net/tnemc/core/hook/luckperms/BalanceContext.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import net.tnemc.core.api.callback.account.AccountLoadCallback;
import net.tnemc.core.api.callback.account.AccountSaveCallback;
import net.tnemc.core.api.response.AccountAPIResponse;
import net.tnemc.core.currency.Currency;
import net.tnemc.plugincore.PluginCore;
import net.tnemc.plugincore.core.compatibility.PlayerProvider;
import net.tnemc.plugincore.core.compatibility.log.DebugLevel;
import net.tnemc.plugincore.core.id.UUIDPair;
import net.tnemc.plugincore.core.io.storage.Datable;
Expand Down
2 changes: 2 additions & 0 deletions Core/src/net/tnemc/core/manager/CurrencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.tnemc.core.currency.item.ItemDenomination;
import net.tnemc.core.currency.loader.DefaultCurrencyLoader;
import net.tnemc.core.currency.saver.DefaultCurrencySaver;
import net.tnemc.core.currency.type.ExperienceLevelType;
import net.tnemc.core.currency.type.ExperienceType;
import net.tnemc.core.currency.type.ItemType;
import net.tnemc.core.currency.type.MixedType;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class CurrencyManager {

public CurrencyManager() {
addType(new ExperienceType());
addType(new ExperienceLevelType());
addType(new ItemType());
addType(new MixedType());
addType(new VirtualType());
Expand Down
8 changes: 0 additions & 8 deletions Folia/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
</repository>
</repositories>



<build>
<defaultGoal>clean package</defaultGoal>
<directory>target</directory>
Expand Down Expand Up @@ -129,12 +127,6 @@
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>${tne.relocation}.kyori</shadedPattern>
<includes>
<include>net.kyori.adventure.key.*</include>
<include>net.kyori.adventure.text.*</include>
<include>net.kyori.option.*</include>
<include>net.kyori.examination.*</include>
</includes>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
Expand Down
Loading

0 comments on commit c44cf03

Please sign in to comment.