Added lore null check and the lifesteal
This commit is contained in:
7
build.sh
Normal file → Executable file
7
build.sh
Normal file → Executable file
@@ -8,9 +8,8 @@ if [ $? -eq 0 ]; then
|
||||
echo "Gradle build successful."
|
||||
|
||||
# SFTP upload
|
||||
SFTP_HOST="192.168.1.199"
|
||||
SFTP_HOST="server"
|
||||
SFTP_USER="trouper"
|
||||
SFTP_PASSWORD="Trouper12()1"
|
||||
SFTP_REMOTE_DIR="/home/trouper/docker/data/plugins/"
|
||||
|
||||
# Create a temporary file with a unique name
|
||||
@@ -24,9 +23,7 @@ if [ $? -eq 0 ]; then
|
||||
echo "bye" >> "$TEMP_FILE"
|
||||
|
||||
# Use sftp non-interactively with the specified commands
|
||||
sftp -oStrictHostKeyChecking=no -oBatchMode=no -b "$TEMP_FILE" "$SFTP_USER@$SFTP_HOST" <<EOF
|
||||
$SFTP_PASSWORD
|
||||
EOF
|
||||
sftp -oStrictHostKeyChecking=no -oBatchMode=no -b "$TEMP_FILE" "$SFTP_USER@$SFTP_HOST"
|
||||
|
||||
# Remove the temporary file
|
||||
rm -f "$TEMP_FILE"
|
||||
|
||||
@@ -5,10 +5,12 @@ import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
|
||||
import me.trouper.ultrals.cmds.*;
|
||||
import me.trouper.ultrals.data.BankStorage;
|
||||
import me.trouper.ultrals.data.HeartItemStorage;
|
||||
import me.trouper.ultrals.data.MiscStorage;
|
||||
import me.trouper.ultrals.data.config.Config;
|
||||
import me.trouper.ultrals.events.ClickEvent;
|
||||
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.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -19,9 +21,11 @@ public final class UltraLS extends JavaPlugin {
|
||||
|
||||
private static UltraLS instance;
|
||||
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 withdrawfile = new File("plugins/UltraLS/heart-item-storage.json");
|
||||
private static final File bankfile = new File("plugins/UltraLS/storage/banks.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 MiscStorage misc = JsonSerializable.load(miscfile, MiscStorage.class, new MiscStorage());
|
||||
public static BankStorage bank = JsonSerializable.load(bankfile, BankStorage.class, new BankStorage());
|
||||
public static HeartItemStorage hearts = JsonSerializable.load(bankfile, HeartItemStorage.class, new HeartItemStorage());
|
||||
public static final Logger log = Bukkit.getLogger();
|
||||
@@ -59,7 +63,8 @@ public final class UltraLS extends JavaPlugin {
|
||||
// Events
|
||||
new DeathEvent().register();
|
||||
new ClickEvent().register();
|
||||
new JoinEvent().register();
|
||||
new PlayerEvents().register();
|
||||
new TeleportEvent().register();
|
||||
|
||||
log.info("""
|
||||
Finished!
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
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.util.Text;
|
||||
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."));
|
||||
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();
|
||||
String to = args.get(2).toString();
|
||||
String from = args.get(3).toString();
|
||||
@@ -36,6 +41,7 @@ public class GiveHeartCommand implements CustomCommand {
|
||||
}
|
||||
if (to.equals("bank")) {
|
||||
TransferFunctions.barToBank(s,r,amount);
|
||||
return;
|
||||
}
|
||||
TransferFunctions.barToBar(s,r,amount);
|
||||
|
||||
|
||||
@@ -4,17 +4,36 @@ 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.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.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandRegistry(value = "revive")
|
||||
public class ReviveCommand implements CustomCommand {
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Args args) {
|
||||
|
||||
Player s = (Player) commandSender;
|
||||
OfflinePlayer r = Bukkit.getOfflinePlayer(args.get(0).toString());
|
||||
DeathFunctions.revive(s,r);
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class BankStorage implements JsonSerializable<BankStorage> {
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
File file = new File("plugins/UltraLS/banks.json");
|
||||
File file = new File("plugins/UltraLS/storage/banks.json");
|
||||
file.getParentFile().mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class HeartItemStorage implements JsonSerializable<HeartItemStorage> {
|
||||
|
||||
@Override
|
||||
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();
|
||||
return file;
|
||||
}
|
||||
|
||||
21
src/main/java/me/trouper/ultrals/data/MiscStorage.java
Normal file
21
src/main/java/me/trouper/ultrals/data/MiscStorage.java
Normal 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<>();
|
||||
}
|
||||
@@ -2,14 +2,17 @@ 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class JoinEvent implements CustomListener {
|
||||
public class PlayerEvents implements CustomListener {
|
||||
@EventHandler
|
||||
public void onFirstJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
@@ -19,6 +22,28 @@ public class JoinEvent implements CustomListener {
|
||||
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(UltraLS.config.plugin.startingHP);
|
||||
UltraLS.bank.save();
|
||||
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(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/main/java/me/trouper/ultrals/events/TeleportEvent.java
Normal file
19
src/main/java/me/trouper/ultrals/events/TeleportEvent.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class BankFunctions {
|
||||
|
||||
public static void depositItem(Player p, boolean toBank) {
|
||||
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) {
|
||||
p.sendMessage(Text.prefix("&cThat item is not a heart!"));
|
||||
return;
|
||||
|
||||
@@ -1,33 +1,48 @@
|
||||
package me.trouper.ultrals.server.functions;
|
||||
|
||||
import me.trouper.ultrals.UltraLS;
|
||||
import me.trouper.ultrals.server.util.ServerUtils;
|
||||
import me.trouper.ultrals.server.util.Text;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeathFunctions {
|
||||
|
||||
public static void unBan(OfflinePlayer p, String who) {
|
||||
ServerUtils.sendCommand(UltraLS.config.plugin.reviveCommand.formatted(p.getName()));
|
||||
Bukkit.broadcast(Component.text(Text.prefix("&a%s&7 has been revived by &e%s&7!".formatted(p.getName(),who))));
|
||||
public static void revive(Player s, OfflinePlayer r) {
|
||||
if (isAlive(r)) {
|
||||
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) {
|
||||
ServerUtils.sendCommand(UltraLS.config.plugin.deathBanCommand.formatted(p.getName()));
|
||||
Bukkit.broadcast(Component.text(Text.prefix("&a%s&7 is now dead!".formatted(p.getName()))));
|
||||
public static void permaKill(Player v, Player k) {
|
||||
UltraLS.misc.deadPlayers.add(v.getUniqueId().toString());
|
||||
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) {
|
||||
p.addScoreboardTag("ULTRALS_dead");
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
public static boolean isAlive(OfflinePlayer p) {
|
||||
return !UltraLS.misc.deadPlayers.contains(p.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,11 @@ public class StealFunctions {
|
||||
if (vb - UltraLS.config.plugin.heartsFromPlayers <= 0) {
|
||||
// Victim does not have any hearts in the bank
|
||||
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);
|
||||
return;
|
||||
}
|
||||
v.sendMessage("Your bank was empty!");
|
||||
v.sendMessage(Text.prefix("Your bank was empty!"));
|
||||
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) {
|
||||
// Victim does not have any hearts in their health bar, and the plugin is set to not spectator, or not ban them
|
||||
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);
|
||||
return;
|
||||
}
|
||||
v.sendMessage("Your health bar does not have enough hearts to be stolen from.");
|
||||
return;
|
||||
} else if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP && UltraLS.config.plugin.deathBan) {
|
||||
DeathFunctions.ban(v);
|
||||
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);
|
||||
} else if (vh.getBaseValue() - UltraLS.config.plugin.heartsFromPlayers <= UltraLS.config.plugin.minHP ) {
|
||||
DeathFunctions.permaKill(v,k);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,4 +32,11 @@ commands:
|
||||
description: Give hearts to players
|
||||
permission: ultrals.giveheart
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user