mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-10 01:18:07 +01:00
feat(pay): send message to target (#6)
* feat(pay): send message for target * fix: set audience on enable
This commit is contained in:
parent
572738dab5
commit
b1d5ae7c09
9 changed files with 61 additions and 0 deletions
|
@ -3,6 +3,12 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
api("net.kyori:adventure-api:4.12.0") {
|
||||||
|
exclude(module = "adventure-bom")
|
||||||
|
exclude(module = "checker-qual")
|
||||||
|
exclude(module = "annotations")
|
||||||
|
}
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package dev.xhyrom.lighteco.api.model.user;
|
package dev.xhyrom.lighteco.api.model.user;
|
||||||
|
|
||||||
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
@ -59,4 +60,12 @@ public interface User {
|
||||||
* @throws IllegalArgumentException if the amount is negative
|
* @throws IllegalArgumentException if the amount is negative
|
||||||
*/
|
*/
|
||||||
void withdraw(@NonNull Currency currency, @NonNull BigDecimal amount) throws IllegalArgumentException;
|
void withdraw(@NonNull Currency currency, @NonNull BigDecimal amount) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to this user.
|
||||||
|
* Message will be silently dropped if the user is offline.
|
||||||
|
*
|
||||||
|
* @param message the message
|
||||||
|
*/
|
||||||
|
void sendMessage(Component message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
||||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
@ -27,6 +29,7 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
@Getter
|
@Getter
|
||||||
private final SchedulerAdapter scheduler;
|
private final SchedulerAdapter scheduler;
|
||||||
|
private BukkitAudiences audience;
|
||||||
|
|
||||||
public BukkitLightEcoBootstrap(JavaPlugin loader) {
|
public BukkitLightEcoBootstrap(JavaPlugin loader) {
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
|
@ -46,6 +49,8 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
CommandAPI.onEnable();
|
CommandAPI.onEnable();
|
||||||
this.plugin.enable();
|
this.plugin.enable();
|
||||||
|
|
||||||
|
this.audience = BukkitAudiences.create(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,4 +81,9 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
public InputStream getResourceStream(String filename) {
|
public InputStream getResourceStream(String filename) {
|
||||||
return this.loader.getResource(filename);
|
return this.loader.getResource(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Audience getPlayerAudience(UUID uniqueId) {
|
||||||
|
return audience.player(uniqueId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dev.xhyrom.lighteco.common.api.impl;
|
||||||
|
|
||||||
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||||
import dev.xhyrom.lighteco.api.model.user.User;
|
import dev.xhyrom.lighteco.api.model.user.User;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
@ -60,4 +61,9 @@ public class ApiUser implements User {
|
||||||
|
|
||||||
this.handler.withdraw(internal, amount);
|
this.handler.withdraw(internal, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Component message) {
|
||||||
|
this.handler.sendMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class CurrencyMessageConfig extends OkaeriConfig {
|
||||||
|
|
||||||
public String pay = "<currency> <dark_gray>| <gray>Paid <gold><amount> <yellow>to <gold><target>";
|
public String pay = "<currency> <dark_gray>| <gray>Paid <gold><amount> <yellow>to <gold><target>";
|
||||||
public String payWithTax = "<currency> <dark_gray>| <gray>Paid <gold><amount> <yellow>to <gold><target> <dark_gray>(<gold><taxed_amount> <yellow>after tax<dark_gray>)";
|
public String payWithTax = "<currency> <dark_gray>| <gray>Paid <gold><amount> <yellow>to <gold><target> <dark_gray>(<gold><taxed_amount> <yellow>after tax<dark_gray>)";
|
||||||
|
public String payReceived = "<currency> <dark_gray>| <gray>Received <gold><amount> <yellow>from <gold><sender>";
|
||||||
|
public String payReceivedWithTax = "<currency> <dark_gray>| <gray>Received <gold><amount> <yellow>from <gold><sender> <dark_gray>(<gold><taxed_amount> <yellow>after tax<dark_gray>)";
|
||||||
|
|
||||||
public String wait = "<red>Please wait a moment before using this command again.";
|
public String wait = "<red>Please wait a moment before using this command again.";
|
||||||
public String notEnoughMoney = "<red>You don't have enough money!";
|
public String notEnoughMoney = "<red>You don't have enough money!";
|
||||||
|
|
|
@ -242,6 +242,9 @@ public abstract class AbstractCommandManager implements CommandManager {
|
||||||
? this.getConfig(currency).payWithTax
|
? this.getConfig(currency).payWithTax
|
||||||
: this.getConfig(currency).pay;
|
: this.getConfig(currency).pay;
|
||||||
|
|
||||||
|
String templateReceived = tax.compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? this.getConfig(currency).payReceivedWithTax
|
||||||
|
: this.getConfig(currency).payReceived;
|
||||||
|
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
miniMessage.deserialize(
|
miniMessage.deserialize(
|
||||||
|
@ -255,6 +258,18 @@ public abstract class AbstractCommandManager implements CommandManager {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
target.sendMessage(
|
||||||
|
miniMessage.deserialize(
|
||||||
|
templateReceived,
|
||||||
|
Placeholder.parsed("currency", currency.getIdentifier()),
|
||||||
|
Placeholder.parsed("sender", user.getUsername()),
|
||||||
|
Placeholder.parsed("amount", amount.toPlainString()),
|
||||||
|
Placeholder.parsed("taxed_amount", taxedAmount.toPlainString()),
|
||||||
|
Placeholder.parsed("sender_balance", user.getBalance(currency).toPlainString()),
|
||||||
|
Placeholder.parsed("receiver_balance", target.getBalance(currency).toPlainString())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
removeFromMustWait(target.getUniqueId(), sender.getUniqueId());
|
removeFromMustWait(target.getUniqueId(), sender.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -96,4 +97,8 @@ public class User {
|
||||||
|
|
||||||
this.setBalance(currency, this.getBalance(currency).subtract(amount));
|
this.setBalance(currency, this.getBalance(currency).subtract(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessage(@NonNull Component message) {
|
||||||
|
this.plugin.getBootstrap().getPlayerAudience(this.getUniqueId()).sendMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dev.xhyrom.lighteco.common.plugin.bootstrap;
|
||||||
|
|
||||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -16,4 +17,5 @@ public interface LightEcoBootstrap {
|
||||||
boolean isPlayerOnline(UUID uniqueId);
|
boolean isPlayerOnline(UUID uniqueId);
|
||||||
List<UUID> getOnlinePlayers();
|
List<UUID> getOnlinePlayers();
|
||||||
InputStream getResourceStream(String filename);
|
InputStream getResourceStream(String filename);
|
||||||
|
Audience getPlayerAudience(UUID uniqueId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap;
|
||||||
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
||||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||||
|
|
||||||
|
@ -73,4 +74,9 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
public InputStream getResourceStream(String filename) {
|
public InputStream getResourceStream(String filename) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Audience getPlayerAudience(UUID uniqueId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue