Skip to content

Commit

Permalink
Add LuckPerms Context.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Dec 10, 2023
1 parent 1aac66e commit adacd36
Show file tree
Hide file tree
Showing 21 changed files with 509 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .changelog/0.1.2.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- %tne_balance:inventory%
- %tne_balance:ender%
- %tne_balance:virtual%
- Added support for placeholders in messages.yml translations
- Added extensive messaging for currency loading
- This should show the end-user when they have misconfigured a currency.
- This will also show a message when the folder associated isn't found.
- This will also show a message when the folder associated isn't found.

Fixes
- Fixed issue where empty entries in the enchantments/flags fields for currency notes would cause issues.
- Fixed issue where Essentials would send an OfflinePlayer with a null name
- Removed module download functionality from Sponge as requested by Sponge staff
11 changes: 11 additions & 0 deletions Bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>luck-repo</id>
<url>https://repo.lucko.me/</url>
</repository>
</repositories>


Expand Down Expand Up @@ -173,6 +177,13 @@
</build>

<dependencies>
<!-- LuckPerms API -->
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNML-Bukkit</artifactId>
Expand Down
1 change: 1 addition & 0 deletions Bukkit/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ softdepend:
- GUIShop
- DiscordSRV
- Multiverse-Core
- LuckPerms

permissions:
tne.*:
Expand Down
5 changes: 5 additions & 0 deletions Bukkit/src/net/tnemc/bukkit/TNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

import net.tnemc.bukkit.hook.economy.VaultHook;
import net.tnemc.bukkit.hook.misc.LuckPermsHook;
import net.tnemc.bukkit.hook.misc.PAPIHook;
import net.tnemc.bukkit.listeners.player.PlayerClickListener;
import net.tnemc.bukkit.listeners.player.PlayerCloseInventoryListener;
Expand Down Expand Up @@ -87,6 +88,10 @@ public void onEnable() {
new PAPIHook().register();
}

if(Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
LuckPermsHook.register();
}

final Metrics metrics = new Metrics(this, 602);

getLogger().log(Level.INFO, "The New Economy has been enabled!");
Expand Down
46 changes: 46 additions & 0 deletions Bukkit/src/net/tnemc/bukkit/hook/misc/LuckBalanceContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.tnemc.bukkit.hook.misc;
/*
* 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.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
import net.tnemc.core.hook.luckperms.BalanceContext;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

/**
* LuckBalanceContext
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class LuckBalanceContext implements ContextCalculator<Player> {

final BalanceContext context = new BalanceContext();

@Override
public void calculate(@NotNull Player player, @NotNull ContextConsumer contextConsumer) {
context.calculate(player.getUniqueId(), contextConsumer);
}

@Override
public ContextSet estimatePotentialContexts() {
return context.estimate();
}
}
37 changes: 37 additions & 0 deletions Bukkit/src/net/tnemc/bukkit/hook/misc/LuckPermsHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.tnemc.bukkit.hook.misc;
/*
* 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.luckperms.api.LuckPerms;
import net.tnemc.bukkit.TNE;

/**
* LuckPermsHook
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class LuckPermsHook {

public static void register() {
final LuckPerms luckAPI = TNE.instance().getServer().getServicesManager().load(LuckPerms.class);
if(luckAPI != null) {
luckAPI.getContextManager().registerCalculator(new LuckBalanceContext());
}
}
}
11 changes: 11 additions & 0 deletions Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>luck-repo</id>
<url>https://repo.lucko.me/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -28,6 +32,13 @@
<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
9 changes: 0 additions & 9 deletions Core/src/net/tnemc/core/TNECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,6 @@ protected void onEnable() {
}
}

if(!MessageConfig.yaml().contains("Messages.Commands.Help.Entry")) {
MessageConfig.yaml().set("Messages.Commands.Help.Entry", "<gold>$command $arguments - <white>$description</white>");
try {
MessageConfig.yaml().save();
} catch(IOException ignore) {
TNECore.log().error("Unable to update MessageConfig to add Help Lines, please do this manually.", DebugLevel.OFF);
}
}

//register our commands
registerCommandHandler();
command.setHelpWriter((command, actor) -> {
Expand Down
69 changes: 69 additions & 0 deletions Core/src/net/tnemc/core/hook/luckperms/BalanceContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.tnemc.core.hook.luckperms;
/*
* 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.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import net.tnemc.core.TNECore;
import net.tnemc.core.account.Account;
import net.tnemc.core.currency.Currency;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Optional;
import java.util.UUID;

/**
* BalanceContext
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class BalanceContext {

final String KEY = "tne:balance-";

public void calculate(@NonNull UUID uuid, @NonNull ContextConsumer contextConsumer) {
final Optional<Account> account = TNECore.eco().account().findAccount(uuid);

if(account.isPresent()) {

final String region = TNECore.eco().region().getMode().region(uuid);
for(Currency currency : TNECore.eco().currency().currencies()) {
contextConsumer.accept(KEY + currency.getIdentifier(), account.get().getHoldingsTotal(region, currency.getUid()).toPlainString());
}
} else {

for(Currency currency : TNECore.eco().currency().currencies()) {
contextConsumer.accept(KEY + currency.getIdentifier(), currency.getStartingHoldings().toPlainString());
}
}
}

public ContextSet estimate() {
final ImmutableContextSet.Builder builder = ImmutableContextSet.builder();

for(Currency currency : TNECore.eco().currency().currencies()) {
builder.add(KEY + currency.getIdentifier(), "0");
builder.add(KEY + currency.getIdentifier(), "100");
builder.add(KEY + currency.getIdentifier(), "500");
builder.add(KEY + currency.getIdentifier(), "1000");
}
return builder.build();
}
}
11 changes: 11 additions & 0 deletions PaperCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>luck-repo</id>
<url>https://repo.lucko.me/</url>
</repository>
</repositories>


Expand Down Expand Up @@ -169,6 +173,13 @@
</build>

<dependencies>
<!-- LuckPerms API -->
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNML-Bukkit</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions PaperCore/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ dependencies:
- name: Towny
required: false
bootstrap: false
- name: LuckPerms
required: false
bootstrap: false
- name: Vault
required: false
bootstrap: false
Expand Down
5 changes: 5 additions & 0 deletions PaperCore/src/net/tnemc/paper/TNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.tnemc.menu.bukkit.listener.BukkitChatListener;
import net.tnemc.menu.bukkit.listener.BukkitInventoryCloseListener;
import net.tnemc.paper.hook.economy.VaultHook;
import net.tnemc.paper.hook.misc.LuckPermsHook;
import net.tnemc.paper.hook.misc.PAPIHook;
import net.tnemc.paper.listeners.player.PlayerClickListener;
import net.tnemc.paper.listeners.player.PlayerCloseInventoryListener;
Expand Down Expand Up @@ -88,6 +89,10 @@ public void onEnable() {
new PAPIHook().register();
}

if(Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
LuckPermsHook.register();
}

final Metrics metrics = new Metrics(this, 602);

getLogger().log(Level.INFO, "The New Economy has been enabled!");
Expand Down
46 changes: 46 additions & 0 deletions PaperCore/src/net/tnemc/paper/hook/misc/LuckBalanceContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.tnemc.paper.hook.misc;
/*
* 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.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
import net.tnemc.core.hook.luckperms.BalanceContext;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

/**
* LuckBalanceContext
*
* @author creatorfromhell
* @since 0.1.2.0
*/
public class LuckBalanceContext implements ContextCalculator<Player> {

final BalanceContext context = new BalanceContext();

@Override
public void calculate(@NotNull Player player, @NotNull ContextConsumer contextConsumer) {
context.calculate(player.getUniqueId(), contextConsumer);
}

@Override
public ContextSet estimatePotentialContexts() {
return context.estimate();
}
}
Loading

0 comments on commit adacd36

Please sign in to comment.