Added lore null check and the lifesteal

This commit is contained in:
obvWolf
2024-03-09 09:10:43 -06:00
parent 7ccb8c5579
commit e7e88031ec
14 changed files with 150 additions and 39 deletions

7
build.sh Normal file → Executable file
View File

@@ -8,9 +8,8 @@ if [ $? -eq 0 ]; then
echo "Gradle build successful." echo "Gradle build successful."
# SFTP upload # SFTP upload
SFTP_HOST="192.168.1.199" SFTP_HOST="server"
SFTP_USER="trouper" SFTP_USER="trouper"
SFTP_PASSWORD="Trouper12()1"
SFTP_REMOTE_DIR="/home/trouper/docker/data/plugins/" SFTP_REMOTE_DIR="/home/trouper/docker/data/plugins/"
# Create a temporary file with a unique name # Create a temporary file with a unique name
@@ -24,9 +23,7 @@ if [ $? -eq 0 ]; then
echo "bye" >> "$TEMP_FILE" echo "bye" >> "$TEMP_FILE"
# Use sftp non-interactively with the specified commands # Use sftp non-interactively with the specified commands
sftp -oStrictHostKeyChecking=no -oBatchMode=no -b "$TEMP_FILE" "$SFTP_USER@$SFTP_HOST" <<EOF sftp -oStrictHostKeyChecking=no -oBatchMode=no -b "$TEMP_FILE" "$SFTP_USER@$SFTP_HOST"
$SFTP_PASSWORD
EOF
# Remove the temporary file # Remove the temporary file
rm -f "$TEMP_FILE" rm -f "$TEMP_FILE"

0
gradlew vendored Normal file → Executable file
View File

View File

@@ -5,10 +5,12 @@ import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import me.trouper.ultrals.cmds.*; import me.trouper.ultrals.cmds.*;
import me.trouper.ultrals.data.BankStorage; import me.trouper.ultrals.data.BankStorage;
import me.trouper.ultrals.data.HeartItemStorage; import me.trouper.ultrals.data.HeartItemStorage;
import me.trouper.ultrals.data.MiscStorage;
import me.trouper.ultrals.data.config.Config; import me.trouper.ultrals.data.config.Config;
import me.trouper.ultrals.events.ClickEvent; import me.trouper.ultrals.events.ClickEvent;
import me.trouper.ultrals.events.DeathEvent; import me.trouper.ultrals.events.DeathEvent;
import me.trouper.ultrals.events.JoinEvent; import me.trouper.ultrals.events.PlayerEvents;
import me.trouper.ultrals.events.TeleportEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -19,9 +21,11 @@ public final class UltraLS extends JavaPlugin {
private static UltraLS instance; private static UltraLS instance;
private static final File cfgfile = new File("plugins/UltraLS/main-config.json"); private static final File cfgfile = new File("plugins/UltraLS/main-config.json");
private static final File bankfile = new File("plugins/UltraLS/banks.json"); private static final File bankfile = new File("plugins/UltraLS/storage/banks.json");
private static final File withdrawfile = new File("plugins/UltraLS/heart-item-storage.json"); private static final File withdrawfile = new File("plugins/UltraLS/storage/heart-item-storage.json");
private static final File miscfile = new File("plugins/UltraLS/storage/misc-storage.json");
public static Config config = JsonSerializable.load(cfgfile, Config.class, new Config()); public static Config config = JsonSerializable.load(cfgfile, Config.class, new Config());
public static MiscStorage misc = JsonSerializable.load(miscfile, MiscStorage.class, new MiscStorage());
public static BankStorage bank = JsonSerializable.load(bankfile, BankStorage.class, new BankStorage()); public static BankStorage bank = JsonSerializable.load(bankfile, BankStorage.class, new BankStorage());
public static HeartItemStorage hearts = JsonSerializable.load(bankfile, HeartItemStorage.class, new HeartItemStorage()); public static HeartItemStorage hearts = JsonSerializable.load(bankfile, HeartItemStorage.class, new HeartItemStorage());
public static final Logger log = Bukkit.getLogger(); public static final Logger log = Bukkit.getLogger();
@@ -59,7 +63,8 @@ public final class UltraLS extends JavaPlugin {
// Events // Events
new DeathEvent().register(); new DeathEvent().register();
new ClickEvent().register(); new ClickEvent().register();
new JoinEvent().register(); new PlayerEvents().register();
new TeleportEvent().register();
log.info(""" log.info("""
Finished! Finished!

View File

@@ -5,6 +5,7 @@ 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.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.TransferFunctions; import me.trouper.ultrals.server.functions.TransferFunctions;
import me.trouper.ultrals.server.util.Text; import me.trouper.ultrals.server.util.Text;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -23,6 +24,10 @@ public class GiveHeartCommand implements CustomCommand {
s.sendMessage(Text.prefix("&cYou must provide an online player!&7 Use the /revive command to give hearts to a dead player.")); s.sendMessage(Text.prefix("&cYou must provide an online player!&7 Use the /revive command to give hearts to a dead player."));
return; return;
} }
if (!DeathFunctions.isAlive(r)) {
s.sendMessage(Text.prefix("&cYou must provide an alive player!&7 Use the /revive command to give hearts to a dead player."));
return;
}
int amount = args.get(1).toInt(); int amount = args.get(1).toInt();
String to = args.get(2).toString(); String to = args.get(2).toString();
String from = args.get(3).toString(); String from = args.get(3).toString();
@@ -36,6 +41,7 @@ public class GiveHeartCommand implements CustomCommand {
} }
if (to.equals("bank")) { if (to.equals("bank")) {
TransferFunctions.barToBank(s,r,amount); TransferFunctions.barToBank(s,r,amount);
return;
} }
TransferFunctions.barToBar(s,r,amount); TransferFunctions.barToBar(s,r,amount);

View File

@@ -4,17 +4,36 @@ 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.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.server.functions.DeathFunctions;
import me.trouper.ultrals.server.util.Text;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@CommandRegistry(value = "revive") @CommandRegistry(value = "revive")
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) {
Player s = (Player) commandSender;
OfflinePlayer r = Bukkit.getOfflinePlayer(args.get(0).toString());
DeathFunctions.revive(s,r);
} }
@Override @Override
public void dispatchCompletions(CompletionBuilder completionBuilder) { public void dispatchCompletions(CompletionBuilder b) {
List<String> players = new ArrayList<>();
for (Player player : ServerUtils.players()) {
players.add(player.getName());
}
b.then(b.arg(players));
} }
} }

View File

@@ -11,7 +11,7 @@ public class BankStorage implements JsonSerializable<BankStorage> {
@Override @Override
public File getFile() { public File getFile() {
File file = new File("plugins/UltraLS/banks.json"); File file = new File("plugins/UltraLS/storage/banks.json");
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
return file; return file;
} }

View File

@@ -11,7 +11,7 @@ public class HeartItemStorage implements JsonSerializable<HeartItemStorage> {
@Override @Override
public File getFile() { public File getFile() {
File file = new File("plugins/UltraLS/heart-item-storage.json"); File file = new File("plugins/UltraLS/storage/heart-item-storage.json");
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
return file; return file;
} }

View File

@@ -0,0 +1,21 @@
package me.trouper.ultrals.data;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MiscStorage implements JsonSerializable<MiscStorage> {
@Override
public File getFile() {
File file = new File("plugins/UltraLS/storage/misc-storage.json");
file.getParentFile().mkdirs();
return file;
}
public List<String> deadPlayers = new ArrayList<>();
}

View File

@@ -2,14 +2,17 @@ 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.DeathFunctions;
import me.trouper.ultrals.server.util.Text; import me.trouper.ultrals.server.util.Text;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class JoinEvent implements CustomListener { public class PlayerEvents implements CustomListener {
@EventHandler @EventHandler
public void onFirstJoin(PlayerJoinEvent e) { public void onFirstJoin(PlayerJoinEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
@@ -19,6 +22,28 @@ public class JoinEvent implements CustomListener {
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(UltraLS.config.plugin.startingHP); p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(UltraLS.config.plugin.startingHP);
UltraLS.bank.save(); UltraLS.bank.save();
p.sendMessage(Component.text(Text.prefix("Welcome! Your HeartBank has been initialized correctly."))); p.sendMessage(Component.text(Text.prefix("Welcome! Your HeartBank has been initialized correctly.")));
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (DeathFunctions.isAlive(p)) return;
if (UltraLS.config.plugin.deathBan) {
e.joinMessage(Component.text(""));
p.kick(Component.text(Text.color("&c&lYou are dead!\n&7Have someone to revive you or wait for an unban wave")));
return;
}
p.setGameMode(GameMode.SPECTATOR);
}
@EventHandler
public void onLeave(PlayerQuitEvent e) {
Player p = e.getPlayer();
if (DeathFunctions.isAlive(p)) return;
if (UltraLS.config.plugin.deathBan) {
e.quitMessage(Component.text(""));
}
} }
} }

View File

@@ -0,0 +1,19 @@
package me.trouper.ultrals.events;
import io.github.itzispyder.pdk.events.CustomListener;
import me.trouper.ultrals.UltraLS;
import me.trouper.ultrals.server.functions.DeathFunctions;
import me.trouper.ultrals.server.util.Text;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerTeleportEvent;
public class TeleportEvent implements CustomListener {
@EventHandler
public void onSpectatorTeleport(PlayerTeleportEvent e) {
if (DeathFunctions.isAlive(e.getPlayer())) return;
if (!e.getCause().equals(PlayerTeleportEvent.TeleportCause.SPECTATE) && !UltraLS.config.plugin.preventSpectatorTeleport) return;
e.getPlayer().sendMessage(Text.prefix("Spectator teleportation has been disabled!"));
e.setCancelled(true);
}
}

View File

@@ -77,7 +77,7 @@ public class BankFunctions {
public static void depositItem(Player p, boolean toBank) { public static void depositItem(Player p, boolean toBank) {
ItemStack i = p.getInventory().getItemInMainHand(); ItemStack i = p.getInventory().getItemInMainHand();
if (i.getLore() == null) return;
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;

View File

@@ -1,33 +1,48 @@
package me.trouper.ultrals.server.functions; package me.trouper.ultrals.server.functions;
import me.trouper.ultrals.UltraLS; import me.trouper.ultrals.UltraLS;
import me.trouper.ultrals.server.util.ServerUtils;
import me.trouper.ultrals.server.util.Text; import me.trouper.ultrals.server.util.Text;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class DeathFunctions { public class DeathFunctions {
public static void unBan(OfflinePlayer p, String who) { public static void revive(Player s, OfflinePlayer r) {
ServerUtils.sendCommand(UltraLS.config.plugin.reviveCommand.formatted(p.getName())); if (isAlive(r)) {
Bukkit.broadcast(Component.text(Text.prefix("&a%s&7 has been revived by &e%s&7!".formatted(p.getName(),who)))); s.sendMessage(Text.prefix("You can only revive a dead player!"));
return;
}
AttributeInstance whoa = s.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (whoa.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers < UltraLS.config.plugin.minHP) {
s.sendMessage(Text.prefix("&cYou do not have enough health to revive someone!"));
return;
}
whoa.setBaseValue(whoa.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers);
UltraLS.misc.deadPlayers.remove(r.getUniqueId().toString());
UltraLS.misc.save();
} }
public static void ban(Player p) { public static void permaKill(Player v, Player k) {
ServerUtils.sendCommand(UltraLS.config.plugin.deathBanCommand.formatted(p.getName())); UltraLS.misc.deadPlayers.add(v.getUniqueId().toString());
Bukkit.broadcast(Component.text(Text.prefix("&a%s&7 is now dead!".formatted(p.getName())))); UltraLS.misc.save();
Bukkit.broadcast(Component.text(Text.prefix("&a%s&7 Has been permanently killed by &c%s&7!".formatted(
v.getName(),
k.getName()
))));
Component message = Component.text(Text.color("&7&lYou have been killed by &c%s&7!"));
if (UltraLS.config.plugin.deathSpectator) message = message.append(Component.text(Text.color("\n&aYou may rejoin to spectate")));
v.kick(message);
} }
public static void unSpectator(Player p) {
p.removeScoreboardTag("ULTRALS_dead");
p.setGameMode(GameMode.SURVIVAL);
}
public static void spectator(Player p) { public static boolean isAlive(OfflinePlayer p) {
p.addScoreboardTag("ULTRALS_dead"); return !UltraLS.misc.deadPlayers.contains(p.getUniqueId().toString());
p.setGameMode(GameMode.SPECTATOR);
} }
} }

View File

@@ -38,11 +38,11 @@ public class StealFunctions {
if (vb - UltraLS.config.plugin.heartsFromPlayers <= 0) { if (vb - UltraLS.config.plugin.heartsFromPlayers <= 0) {
// Victim does not have any hearts in the bank // Victim does not have any hearts in the bank
if (defaultBar) { if (defaultBar) {
v.sendMessage("Your bank was empty! Hearts will been taken from your bar."); v.sendMessage(Text.prefix("Your bank was empty! Hearts will been taken from your bar."));
stealFromBar(v,k,false); stealFromBar(v,k,false);
return; return;
} }
v.sendMessage("Your bank was empty!"); v.sendMessage(Text.prefix("Your bank was empty!"));
return; return;
} }
@@ -76,17 +76,14 @@ public class StealFunctions {
if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP && !UltraLS.config.plugin.deathBan && !UltraLS.config.plugin.deathSpectator) { if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP && !UltraLS.config.plugin.deathBan && !UltraLS.config.plugin.deathSpectator) {
// Victim does not have any hearts in their health bar, and the plugin is set to not spectator, or not ban them // Victim does not have any hearts in their health bar, and the plugin is set to not spectator, or not ban them
if (defaultBank) { if (defaultBank) {
v.sendMessage("You dont have enough hearts in your health bar! Hearts will been taken from your bank."); v.sendMessage("You don't have enough hearts in your health bar! Hearts will been taken from your bank.");
stealFromBank(v,k,false); stealFromBank(v,k,false);
return; return;
} }
v.sendMessage("Your health bar does not have enough hearts to be stolen from."); v.sendMessage("Your health bar does not have enough hearts to be stolen from.");
return; return;
} else if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP && UltraLS.config.plugin.deathBan) { } else if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP ) {
DeathFunctions.ban(v); DeathFunctions.permaKill(v,k);
return; // Return, because we don't want to make them have negative hearts when they rejoin
} else if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP && UltraLS.config.plugin.deathSpectator) {
DeathFunctions.spectator(v);
return; return;
} }

View File

@@ -32,4 +32,11 @@ commands:
description: Give hearts to players description: Give hearts to players
permission: ultrals.giveheart permission: ultrals.giveheart
usage: /giveheart <player> <int> [from your; bank|bar] [to their; bank|bar] usage: /giveheart <player> <int> [from your; bank|bar] [to their; bank|bar]
aliases:
- gh
- givelife
- gl
revive:
description: Revive a player for the cost of a player death
permission: ultrals.revive
usage: /revive <dead player>