Fixed console bug in admin command
This commit is contained in:
@@ -59,6 +59,7 @@ public final class UltraLS extends JavaPlugin {
|
|||||||
new WithdrawCommand().register();
|
new WithdrawCommand().register();
|
||||||
new ReviveCommand().register();
|
new ReviveCommand().register();
|
||||||
new DepositCommand().register();
|
new DepositCommand().register();
|
||||||
|
new BankCommand().register();
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
new DeathEvent().register();
|
new DeathEvent().register();
|
||||||
@@ -103,4 +104,4 @@ public final class UltraLS extends JavaPlugin {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
27
src/main/java/me/trouper/ultrals/cmds/BankCommand.java
Normal file
27
src/main/java/me/trouper/ultrals/cmds/BankCommand.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package me.trouper.ultrals.cmds;
|
||||||
|
|
||||||
|
import io.github.itzispyder.pdk.commands.Args;
|
||||||
|
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||||
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
|
import me.trouper.ultrals.UltraLS;
|
||||||
|
import me.trouper.ultrals.server.util.Text;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandRegistry(value = "bank",permission = @Permission(value = "ultrals.bank"), playersOnly = true)
|
||||||
|
public class BankCommand implements CustomCommand {
|
||||||
|
@Override
|
||||||
|
public void dispatchCommand(CommandSender commandSender, Args args) {
|
||||||
|
commandSender.sendMessage(Text.prefix("Your balance is &a%s&7."
|
||||||
|
.formatted(
|
||||||
|
UltraLS.bank.balances.get(((Player) (commandSender)).getUniqueId().toString())
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchCompletions(CompletionBuilder completionBuilder) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,14 @@ package me.trouper.ultrals.cmds;
|
|||||||
import io.github.itzispyder.pdk.commands.Args;
|
import io.github.itzispyder.pdk.commands.Args;
|
||||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
import me.trouper.ultrals.server.functions.BankFunctions;
|
import me.trouper.ultrals.server.functions.BankFunctions;
|
||||||
|
import me.trouper.ultrals.server.util.Text;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandRegistry(value = "deposit",printStackTrace = true)
|
@CommandRegistry(value = "deposit", permission = @Permission(value = "ultrals.deposit"),printStackTrace = true)
|
||||||
public class DepositCommand implements CustomCommand {
|
public class DepositCommand implements CustomCommand {
|
||||||
@Override
|
@Override
|
||||||
public void dispatchCommand(CommandSender sender, Args args) {
|
public void dispatchCommand(CommandSender sender, Args args) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.trouper.ultrals.cmds;
|
|||||||
import io.github.itzispyder.pdk.commands.Args;
|
import io.github.itzispyder.pdk.commands.Args;
|
||||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
import io.github.itzispyder.pdk.utils.ServerUtils;
|
import io.github.itzispyder.pdk.utils.ServerUtils;
|
||||||
import me.trouper.ultrals.server.functions.DeathFunctions;
|
import me.trouper.ultrals.server.functions.DeathFunctions;
|
||||||
@@ -14,7 +15,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@CommandRegistry(value = "giveheart",printStackTrace = true)
|
@CommandRegistry(value = "giveheart",permission = @Permission(value = "ultrals.giveheart"),printStackTrace = true)
|
||||||
public class GiveHeartCommand implements CustomCommand {
|
public class GiveHeartCommand implements CustomCommand {
|
||||||
@Override
|
@Override
|
||||||
public void dispatchCommand(CommandSender sender, Args args) {
|
public void dispatchCommand(CommandSender sender, Args args) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.trouper.ultrals.cmds;
|
|||||||
import io.github.itzispyder.pdk.commands.Args;
|
import io.github.itzispyder.pdk.commands.Args;
|
||||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
import io.github.itzispyder.pdk.utils.ServerUtils;
|
import io.github.itzispyder.pdk.utils.ServerUtils;
|
||||||
import me.trouper.ultrals.UltraLS;
|
import me.trouper.ultrals.UltraLS;
|
||||||
@@ -18,7 +19,7 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandRegistry(value = "revive")
|
@CommandRegistry(value = "revive",permission = @Permission("ultrals.revive"),printStackTrace = true)
|
||||||
public class ReviveCommand implements CustomCommand {
|
public class ReviveCommand implements CustomCommand {
|
||||||
@Override
|
@Override
|
||||||
public void dispatchCommand(CommandSender commandSender, Args args) {
|
public void dispatchCommand(CommandSender commandSender, Args args) {
|
||||||
|
|||||||
@@ -5,11 +5,18 @@ import io.github.itzispyder.pdk.commands.CommandRegistry;
|
|||||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
import io.github.itzispyder.pdk.commands.Permission;
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
|
import io.github.itzispyder.pdk.utils.ServerUtils;
|
||||||
import me.trouper.ultrals.UltraLS;
|
import me.trouper.ultrals.UltraLS;
|
||||||
|
import me.trouper.ultrals.server.functions.AdminFunctions;
|
||||||
import me.trouper.ultrals.server.util.Text;
|
import me.trouper.ultrals.server.util.Text;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandRegistry(value = "ultrals", permission = @Permission("ultrals.admin"), printStackTrace = true)
|
@CommandRegistry(value = "ultrals", permission = @Permission("ultrals.admin"), printStackTrace = true)
|
||||||
public class UltraLSCommand implements CustomCommand {
|
public class UltraLSCommand implements CustomCommand {
|
||||||
|
|
||||||
@@ -18,6 +25,47 @@ public class UltraLSCommand implements CustomCommand {
|
|||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
|
|
||||||
switch (args.get(0).toString()) {
|
switch (args.get(0).toString()) {
|
||||||
|
case "hearts" -> {
|
||||||
|
OfflinePlayer target = Bukkit.getOfflinePlayer(args.get(1).toString());
|
||||||
|
|
||||||
|
switch (args.get(2).toString()) {
|
||||||
|
case "add" -> {
|
||||||
|
if (!target.isConnected()) {
|
||||||
|
p.sendMessage(Text.prefix("&cNull Error. &7Target is not online."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int amount = args.get(3).toInt();
|
||||||
|
AdminFunctions.addHearts(sender,target.getPlayer(),amount,args.get(4).toBool());
|
||||||
|
}
|
||||||
|
case "subtract" -> {
|
||||||
|
if (!target.isConnected()) {
|
||||||
|
p.sendMessage(Text.prefix("&cNull Error. &7Target is not online."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int amount = args.get(3).toInt();
|
||||||
|
AdminFunctions.subtractHearts(sender,target.getPlayer(),amount,args.get(4).toBool());
|
||||||
|
}
|
||||||
|
case "reset" -> {
|
||||||
|
AdminFunctions.reset(sender,target,args.get(3).toBool());
|
||||||
|
}
|
||||||
|
case "set" -> {
|
||||||
|
switch (args.get(3).toString()) {
|
||||||
|
case "bank" -> {
|
||||||
|
int amount = args.get(4).toInt();
|
||||||
|
AdminFunctions.setBank(sender,target,amount,args.get(5).toBool());
|
||||||
|
}
|
||||||
|
case "bar" -> {
|
||||||
|
int amount = args.get(4).toInt();
|
||||||
|
if (!target.isConnected()) {
|
||||||
|
p.sendMessage(Text.prefix("&cNull Error. &7Target is not online."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AdminFunctions.setHearts(sender,target.getPlayer(),amount,args.get(5).toBool());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
case "toggle" -> {
|
case "toggle" -> {
|
||||||
switch (args.get(1).toString()) {
|
switch (args.get(1).toString()) {
|
||||||
case "debug" -> {
|
case "debug" -> {
|
||||||
@@ -32,8 +80,30 @@ public class UltraLSCommand implements CustomCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispatchCompletions(CompletionBuilder b) {
|
public void dispatchCompletions(CompletionBuilder b) {
|
||||||
|
List<String> players = new ArrayList<>();
|
||||||
|
for (Player player : ServerUtils.players()) {
|
||||||
|
players.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
b.then(b.arg("toggle")
|
b.then(b.arg("toggle")
|
||||||
.then(b.arg("debug")));
|
.then(b.arg("debug"))
|
||||||
|
).then(b.arg("hearts")
|
||||||
|
.then(b.arg(players)
|
||||||
|
.then(b.arg("add","remove")
|
||||||
|
.then(b.arg("<int>")
|
||||||
|
.then(b.arg("<bool: anonymous>"))))
|
||||||
|
.then(b.arg("reset")
|
||||||
|
.then(b.arg("<bool: anonymous>")))
|
||||||
|
.then(b.arg("set")
|
||||||
|
.then(b.arg("bank","bar")
|
||||||
|
.then(b.arg("<int>")
|
||||||
|
.then(b.arg("<bool: anonymous>")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package me.trouper.ultrals.cmds;
|
|||||||
import io.github.itzispyder.pdk.commands.Args;
|
import io.github.itzispyder.pdk.commands.Args;
|
||||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||||
|
import io.github.itzispyder.pdk.commands.Permission;
|
||||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||||
import me.trouper.ultrals.server.functions.BankFunctions;
|
import me.trouper.ultrals.server.functions.BankFunctions;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@CommandRegistry(value = "withdraw",printStackTrace = true)
|
@CommandRegistry(value = "withdraw",permission = @Permission(value = "ultrals.withdraw"),printStackTrace = true)
|
||||||
public class WithdrawCommand implements CustomCommand {
|
public class WithdrawCommand implements CustomCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package me.trouper.ultrals.events;
|
|||||||
import io.github.itzispyder.pdk.events.CustomListener;
|
import io.github.itzispyder.pdk.events.CustomListener;
|
||||||
import me.trouper.ultrals.UltraLS;
|
import me.trouper.ultrals.UltraLS;
|
||||||
import me.trouper.ultrals.server.functions.BankFunctions;
|
import me.trouper.ultrals.server.functions.BankFunctions;
|
||||||
|
import me.trouper.ultrals.server.util.ServerUtils;
|
||||||
|
import me.trouper.ultrals.server.util.Text;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -11,11 +14,24 @@ public class ClickEvent implements CustomListener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClick(PlayerInteractEvent e) {
|
public void onClick(PlayerInteractEvent e) {
|
||||||
ItemStack i = e.getItem();
|
ItemStack i = e.getItem();
|
||||||
|
ServerUtils.verbose("Click ");
|
||||||
|
if (i == null) return;
|
||||||
|
ServerUtils.verbose("Click 0");
|
||||||
|
if (!i.getType().equals(Material.RED_DYE)) return;
|
||||||
|
ServerUtils.verbose("Click 2");
|
||||||
if (!i.isEmpty() &&
|
if (!i.isEmpty() &&
|
||||||
i.hasItemMeta() &&
|
i.hasItemMeta() &&
|
||||||
i.getItemMeta().hasCustomModelData()
|
i.getItemMeta().hasCustomModelData()
|
||||||
&& i.getItemMeta().hasLore()
|
&& i.getItemMeta().hasLore()
|
||||||
&& i.getItemMeta().getCustomModelData() != UltraLS.config.plugin.heartModelData) return;
|
&& i.getItemMeta().getCustomModelData() != UltraLS.config.plugin.heartModelData) return;
|
||||||
|
ServerUtils.verbose("Click 2");
|
||||||
|
|
||||||
|
if (i.getLore() == null) return;
|
||||||
|
ServerUtils.verbose("Click 3");
|
||||||
|
|
||||||
|
if (!i.getItemMeta().hasDisplayName()) return;
|
||||||
|
|
||||||
|
ServerUtils.verbose("Click 4");
|
||||||
|
|
||||||
switch (e.getAction()) {
|
switch (e.getAction()) {
|
||||||
case LEFT_CLICK_AIR, LEFT_CLICK_BLOCK -> BankFunctions.depositItem(e.getPlayer(),false);
|
case LEFT_CLICK_AIR, LEFT_CLICK_BLOCK -> BankFunctions.depositItem(e.getPlayer(),false);
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package me.trouper.ultrals.server.functions;
|
||||||
|
|
||||||
|
import me.trouper.ultrals.UltraLS;
|
||||||
|
import me.trouper.ultrals.server.util.Text;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class AdminFunctions {
|
||||||
|
|
||||||
|
public static boolean addHearts(CommandSender s, Player r, int amount, boolean anonymous) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cInvalid Input.&7 Could not subtract hearts from &c%s&7. You must provide a value above &e0&7."
|
||||||
|
.formatted(r.getName())
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AttributeInstance healthAttribute = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
int balance = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
||||||
|
double health = healthAttribute.getBaseValue();
|
||||||
|
double compositeMax = UltraLS.config.bank.maxBalance + UltraLS.config.plugin.maxHP;
|
||||||
|
double compositeHearts = balance + health;
|
||||||
|
double emptyHearts = UltraLS.config.plugin.maxHP - health;
|
||||||
|
double emptyBal = UltraLS.config.bank.maxBalance - balance;
|
||||||
|
double compositeEmpty = emptyBal + emptyHearts;
|
||||||
|
double leftToGive;
|
||||||
|
|
||||||
|
if (compositeEmpty - amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cOverflow error. &7Cannot add hearts to &e%s&7. Result would be over max health.".formatted(r.getName())));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Confirmed space is available.
|
||||||
|
|
||||||
|
if (emptyHearts - amount < 1) {
|
||||||
|
healthAttribute.setBaseValue(UltraLS.config.plugin.maxHP);
|
||||||
|
leftToGive = amount - emptyHearts;
|
||||||
|
UltraLS.bank.balances.put(r.getUniqueId().toString(), (int) (balance + Math.floor(leftToGive)));
|
||||||
|
UltraLS.bank.save();
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
r.sendMessage(Text.prefix("&e%s&7 has added &a%s&7 hearts to your player.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully added &a%s&7 hearts to &e%s&7.".formatted(amount,r.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
healthAttribute.setBaseValue(health + amount);
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
r.sendMessage(Text.prefix("&e%s&7 has added &a%s&7 hearts to your player.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully added &a%s&7 hearts to &e%s&7.".formatted(amount,r.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean subtractHearts(CommandSender s, Player r, int amount, boolean anonymous) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cInvalid Input.&7 Could not subtract hearts from &c%s&7. You must provide a value above &e0&7."
|
||||||
|
.formatted(r.getName())
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AttributeInstance healthAttribute = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
int balance = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
||||||
|
double availableBarHealth = healthAttribute.getBaseValue() - UltraLS.config.plugin.minHP;
|
||||||
|
double compositeHearts = balance + availableBarHealth;
|
||||||
|
double leftToTake = amount;
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
|
||||||
|
if (compositeHearts < amount) {
|
||||||
|
s.sendMessage(Text.prefix("&cInsufficient Balance. &7There are not enough total hearts on &e%s&7."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// There are enough total hearts
|
||||||
|
|
||||||
|
if (amount > availableBarHealth) {
|
||||||
|
// Take as much as possible from the bar, then update the left to take which will be subtracted from the bank
|
||||||
|
healthAttribute.setBaseValue(UltraLS.config.plugin.minHP);
|
||||||
|
leftToTake = amount - availableBarHealth;
|
||||||
|
UltraLS.bank.balances.put(r.getUniqueId().toString(), (int) (balance - leftToTake));
|
||||||
|
UltraLS.bank.save();
|
||||||
|
r.sendMessage(Text.prefix("&e%s&7 has subtracted &c%s&7 hearts from your player.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully subtracted &c%s&7 hearts from &e%s&7.".formatted(amount,r.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
healthAttribute.setBaseValue(healthAttribute.getBaseValue() + amount);
|
||||||
|
r.sendMessage(Text.prefix("&e%s&7 has subtracted &c%s&7 hearts from your player.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully subtracted &c%s&7 hearts from &e%s&7.".formatted(amount,r.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setHearts(CommandSender s, Player r, int amount, boolean anonymous) {
|
||||||
|
if (amount > UltraLS.config.plugin.maxHP || amount < UltraLS.config.plugin.minHP) {
|
||||||
|
s.sendMessage(Text.prefix("&cInvalid Input.&7 Could not set the hearts of &c%s&7. You must provide a value between &e%s&7 and &e%s&7."
|
||||||
|
.formatted(r.getName(),UltraLS.config.plugin.minHP,UltraLS.config.plugin.maxHP)
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AttributeInstance healthAttribute = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
|
||||||
|
// Value is possible
|
||||||
|
healthAttribute.setBaseValue(amount);
|
||||||
|
r.sendMessage(Text.prefix("&e%s&7 has set your hearts to &a%s&7.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully set &e%s&7's hearts to &a%s&7.".formatted(r.getName(),amount)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setBank(CommandSender s, OfflinePlayer r, int amount, boolean anonymous) {
|
||||||
|
if (amount > UltraLS.config.bank.maxBalance || amount < 0) {
|
||||||
|
s.sendMessage(Text.prefix("&cInvalid Input.&7 Could not set the hearts of &c%s&7. You must provide a value between &e%s&7 and &e%s&7."
|
||||||
|
.formatted(r.getName(),0,UltraLS.config.bank.maxBalance)
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
// Value is possible
|
||||||
|
|
||||||
|
UltraLS.bank.balances.put(r.getUniqueId().toString(), amount);
|
||||||
|
UltraLS.bank.save();
|
||||||
|
if (r.isConnected()) r.getPlayer().sendMessage(Text.prefix("&e%s&7 has set your hearts to &a%s&7.".formatted(who,amount)));
|
||||||
|
s.sendMessage(Text.prefix("Successfully set &e%s&7's hearts to &a%s&7.".formatted(r.getName(),amount)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset(CommandSender s, OfflinePlayer r, boolean anonymous) {
|
||||||
|
UltraLS.bank.balances.remove(r.getUniqueId().toString());
|
||||||
|
UltraLS.bank.save();
|
||||||
|
String who = s.getName();
|
||||||
|
if (anonymous) who = "Console";
|
||||||
|
|
||||||
|
s.sendMessage(Text.prefix("Successfully reset &c%s&7.".formatted(r.getName())));
|
||||||
|
if (r.isConnected()) {
|
||||||
|
r.getPlayer().kick(Component.text(Text.color("&4&lHeart Reset\n&7Your hearts have been reset by &e%s&7.\n\nYou may now rejoin.".formatted(who))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,11 @@ import java.util.UUID;
|
|||||||
public class BankFunctions {
|
public class BankFunctions {
|
||||||
|
|
||||||
public static void withdraw(Player p, int amount) {
|
public static void withdraw(Player p, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
p.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int bal = UltraLS.bank.balances.get(p.getUniqueId().toString());
|
int bal = UltraLS.bank.balances.get(p.getUniqueId().toString());
|
||||||
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
@@ -41,6 +46,10 @@ public class BankFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void withdrawItem(Player p, int amount) {
|
public static void withdrawItem(Player p, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
p.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
int bal = UltraLS.bank.balances.get(p.getUniqueId().toString());
|
int bal = UltraLS.bank.balances.get(p.getUniqueId().toString());
|
||||||
|
|
||||||
if (bal - amount < 0) {
|
if (bal - amount < 0) {
|
||||||
@@ -76,8 +85,12 @@ public class BankFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void depositItem(Player p, boolean toBank) {
|
public static void depositItem(Player p, boolean toBank) {
|
||||||
|
ServerUtils.verbose("Dep 1");
|
||||||
ItemStack i = p.getInventory().getItemInMainHand();
|
ItemStack i = p.getInventory().getItemInMainHand();
|
||||||
if (i.getLore() == null) return;
|
if (i.getLore() == null) return;
|
||||||
|
ServerUtils.verbose("Dep 2");
|
||||||
|
if (!i.getItemMeta().hasDisplayName()) return;
|
||||||
|
ServerUtils.verbose("Dep 4");
|
||||||
if (i.hasItemMeta() && i.getItemMeta().hasCustomModelData() && i.getItemMeta().hasLore() && i.getItemMeta().getCustomModelData() != UltraLS.config.plugin.heartModelData) {
|
if (i.hasItemMeta() && i.getItemMeta().hasCustomModelData() && i.getItemMeta().hasLore() && i.getItemMeta().getCustomModelData() != UltraLS.config.plugin.heartModelData) {
|
||||||
p.sendMessage(Text.prefix("&cThat item is not a heart!"));
|
p.sendMessage(Text.prefix("&cThat item is not a heart!"));
|
||||||
return;
|
return;
|
||||||
@@ -108,19 +121,27 @@ public class BankFunctions {
|
|||||||
|
|
||||||
int amount = UltraLS.hearts.withdrawn.get(typeID.toString());
|
int amount = UltraLS.hearts.withdrawn.get(typeID.toString());
|
||||||
|
|
||||||
p.getInventory().removeItem(i);
|
|
||||||
UltraLS.hearts.withdrawn.remove(typeID.toString());
|
|
||||||
UltraLS.hearts.save();
|
|
||||||
|
|
||||||
|
|
||||||
if (toBank) {
|
if (toBank) {
|
||||||
addToBank(p,amount);
|
if (addToBank(p,amount)) {
|
||||||
|
p.getInventory().removeItem(i);
|
||||||
|
UltraLS.hearts.withdrawn.remove(typeID.toString());
|
||||||
|
UltraLS.hearts.save();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addToBar(p,amount);
|
if (addToBar(p,amount)) {
|
||||||
|
p.getInventory().removeItem(i);
|
||||||
|
UltraLS.hearts.withdrawn.remove(typeID.toString());
|
||||||
|
UltraLS.hearts.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void depositHeart(Player p, int amount) {
|
public static void depositHeart(Player p, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
p.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
if (h.getBaseValue() - amount < UltraLS.config.plugin.minHP) {
|
if (h.getBaseValue() - amount < UltraLS.config.plugin.minHP) {
|
||||||
@@ -130,18 +151,23 @@ public class BankFunctions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
h.setBaseValue(h.getBaseValue() - amount);
|
if (addToBank(p,amount)) {
|
||||||
addToBank(p,amount);
|
h.setBaseValue(h.getBaseValue() - amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToBar(Player p, int amount) {
|
public static boolean addToBar(Player p, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
p.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance h = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
if (h.getBaseValue() + amount > UltraLS.config.plugin.maxHP) {
|
if (h.getBaseValue() + amount > UltraLS.config.plugin.maxHP) {
|
||||||
p.sendMessage(Text.prefix("&cInsufficient Space. &7You would go over the maximum health. (&e%s&7)"
|
p.sendMessage(Text.prefix("&cInsufficient Space. &7You would go over the maximum health. (&e%s&7)"
|
||||||
.formatted(UltraLS.config.plugin.maxHP)
|
.formatted(UltraLS.config.plugin.maxHP)
|
||||||
));
|
));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
h.setBaseValue(h.getBaseValue() + amount);
|
h.setBaseValue(h.getBaseValue() + amount);
|
||||||
@@ -149,14 +175,19 @@ public class BankFunctions {
|
|||||||
p.sendMessage(Text.prefix("Deposited &c%s&7 hearts into your health bar."
|
p.sendMessage(Text.prefix("Deposited &c%s&7 hearts into your health bar."
|
||||||
.formatted(amount)
|
.formatted(amount)
|
||||||
));
|
));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToBank(Player p, int amount) {
|
public static boolean addToBank(Player p, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
p.sendMessage(Text.prefix("Data validation error. Input value above 0"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (UltraLS.bank.balances.get(p.getUniqueId().toString()) + amount > UltraLS.config.bank.maxBalance) {
|
if (UltraLS.bank.balances.get(p.getUniqueId().toString()) + amount > UltraLS.config.bank.maxBalance) {
|
||||||
p.sendMessage(Text.prefix("&cInsufficient Space. &7You would go over the maximum balance. (&e%s&7)"
|
p.sendMessage(Text.prefix("&cInsufficient Space. &7You would go over the maximum balance. (&e%s&7)"
|
||||||
.formatted(UltraLS.config.bank.maxBalance)
|
.formatted(UltraLS.config.bank.maxBalance)
|
||||||
));
|
));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UltraLS.bank.balances.put(p.getUniqueId().toString(), UltraLS.bank.balances.get(p.getUniqueId().toString()) + amount);
|
UltraLS.bank.balances.put(p.getUniqueId().toString(), UltraLS.bank.balances.get(p.getUniqueId().toString()) + amount);
|
||||||
@@ -165,5 +196,6 @@ public class BankFunctions {
|
|||||||
p.sendMessage(Text.prefix("Deposited &c%s&7 hearts into your heart bank. Your new balance is &c%s&7."
|
p.sendMessage(Text.prefix("Deposited &c%s&7 hearts into your heart bank. Your new balance is &c%s&7."
|
||||||
.formatted(amount,UltraLS.bank.balances.get(p.getUniqueId().toString()))
|
.formatted(amount,UltraLS.bank.balances.get(p.getUniqueId().toString()))
|
||||||
));
|
));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package me.trouper.ultrals.server.functions;
|
|||||||
|
|
||||||
import me.trouper.ultrals.UltraLS;
|
import me.trouper.ultrals.UltraLS;
|
||||||
import me.trouper.ultrals.server.util.Text;
|
import me.trouper.ultrals.server.util.Text;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -9,6 +10,10 @@ import org.bukkit.entity.Player;
|
|||||||
public class TransferFunctions {
|
public class TransferFunctions {
|
||||||
|
|
||||||
public static void bankToBank(Player s, Player r, int amount) {
|
public static void bankToBank(Player s, Player r, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
int sb = UltraLS.bank.balances.get(s.getUniqueId().toString());
|
int sb = UltraLS.bank.balances.get(s.getUniqueId().toString());
|
||||||
int rb = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
int rb = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
||||||
|
|
||||||
@@ -37,6 +42,10 @@ public class TransferFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void bankToBar(Player s, Player r, int amount) {
|
public static void bankToBar(Player s, Player r, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
int sb = UltraLS.bank.balances.get(s.getUniqueId().toString());
|
int sb = UltraLS.bank.balances.get(s.getUniqueId().toString());
|
||||||
AttributeInstance ra = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance ra = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
@@ -66,6 +75,10 @@ public class TransferFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void barToBank(Player s, Player r, int amount) {
|
public static void barToBank(Player s, Player r, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
int rb = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
int rb = UltraLS.bank.balances.get(r.getUniqueId().toString());
|
||||||
AttributeInstance sa = s.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance sa = s.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
@@ -95,6 +108,10 @@ public class TransferFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void barToBar(Player s, Player r, int amount) {
|
public static void barToBar(Player s, Player r, int amount) {
|
||||||
|
if (amount < 1) {
|
||||||
|
s.sendMessage(Text.prefix("&cData validation error. Input value above 0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
AttributeInstance ra = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance ra = r.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
AttributeInstance sa = s.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance sa = s.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
@@ -104,7 +121,7 @@ public class TransferFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ra.getBaseValue() + amount > UltraLS.config.plugin.maxHP) {
|
if (ra.getBaseValue() + amount > UltraLS.config.plugin.maxHP) {
|
||||||
s.sendMessage(Text.prefix("&cCould not give &e%s&7 hearts! Their health bar would overflow.".formatted(r.getName())));
|
s.sendMessage(Text .prefix("&cCould not give &e%s&7 hearts! Their health bar would overflow.".formatted(r.getName())));
|
||||||
r.sendMessage(Text.prefix("&e%s&7 tried to give &c%s&7 hearts to you, but your health bar was full!".formatted(s.getName(),amount)));
|
r.sendMessage(Text.prefix("&e%s&7 tried to give &c%s&7 hearts to you, but your health bar was full!".formatted(s.getName(),amount)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,21 @@ permissions:
|
|||||||
ultrals.admin:
|
ultrals.admin:
|
||||||
default: op
|
default: op
|
||||||
description: Access to give and take hearts from players
|
description: Access to give and take hearts from players
|
||||||
|
ultrals.deposit:
|
||||||
|
default: op
|
||||||
|
description: access to the command to place hearts from bar into bank
|
||||||
|
ultrals.withdraw:
|
||||||
|
default: op
|
||||||
|
description: allows withdrawing hearts to bar or item
|
||||||
|
ultrals.revive:
|
||||||
|
default: op
|
||||||
|
description: allows player to revive for a cost
|
||||||
|
ultrals.giveheart:
|
||||||
|
default: op
|
||||||
|
description: allows player to transfer hearts
|
||||||
|
ultrals.bal:
|
||||||
|
default: op
|
||||||
|
description: Allow viewing of balance
|
||||||
commands:
|
commands:
|
||||||
ultrals:
|
ultrals:
|
||||||
description: Admin command to edit people's hearts
|
description: Admin command to edit people's hearts
|
||||||
@@ -40,3 +54,7 @@ commands:
|
|||||||
description: Revive a player for the cost of a player death
|
description: Revive a player for the cost of a player death
|
||||||
permission: ultrals.revive
|
permission: ultrals.revive
|
||||||
usage: /revive <dead player>
|
usage: /revive <dead player>
|
||||||
|
bank:
|
||||||
|
description: View your balance
|
||||||
|
permission: ultrals.bal
|
||||||
|
usage: /bank
|
||||||
|
|||||||
Reference in New Issue
Block a user