Skip to content

Commit

Permalink
Eliminating and transferring hearts to offline players will now work.
Browse files Browse the repository at this point in the history
You can also transfer hearts to an eliminated player to revive them. (toggleable in config.yml)
/lifesteal will now automatically get the version string from the plugin.
Players being kicked from elimination will not display a leave message.

Signed-off-by: hypil <[email protected]>
  • Loading branch information
fleroviums committed Aug 31, 2022
1 parent d2471ea commit b313251
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 11 deletions.
Binary file modified .gradle/file-system.probe
Binary file not shown.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'gq.depixa.lifesteal'
version '1.0.2'
version '1.0.3'

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/gq/depixa/lifesteal/CommandEliminate.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package gq.depixa.lifesteal;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.UUID;

public class CommandEliminate implements CommandExecutor {
Main plugin = Main.getPlugin();
Utils utils = new Utils();
private Configuration playerData = Main.getPlayerConfig();
FileConfiguration config = playerData.getCustomConfig();
@Override
Expand All @@ -19,7 +23,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (args[0].equals("all")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
config.set(player.getUniqueId() + ".eliminated", true);
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + player.getDisplayName() + " §ewas eliminated.");
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + player.getDisplayName() + " §ehas been eliminated.");
if (player.hasPermission("dls.bypass")) {
player.sendMessage("§6Depixa Lifesteal §8| §eYou have been eliminated, but you have bypass enabled.");
} else {
Expand All @@ -32,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (target != null) {
if (!config.getBoolean(target.getUniqueId() + ".eliminated")) {
config.set(target.getUniqueId() + ".eliminated", true);
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + target.getDisplayName() + " §ewas eliminated.");
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + target.getDisplayName() + " §ehas been eliminated.");
if (target.hasPermission("dls.bypass")) {
target.sendMessage("§6Depixa Lifesteal §8| §eYou have been eliminated, but you have bypass enabled.");
} else {
Expand All @@ -41,6 +45,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player is already eliminated.");
}
} else {
UUID targetId = utils.getUniqueId(args[0]);
if (targetId == null) {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
return true;
}
OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(targetId);
if (offlineTarget == null) {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
return true;
}
if (!config.getBoolean(targetId + ".eliminated")) {
config.set(targetId + ".eliminated", true);
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + offlineTarget.getName() + " §ehas been eliminated.");
}
}
}
playerData.saveCustomConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gq/depixa/lifesteal/CommandLifesteal.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CommandLifesteal implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("§6Depixa Lifesteal §8| §eVersion 1.0.0");
sender.sendMessage("§6Depixa Lifesteal §8| §eVersion " + plugin.getDescription().getVersion());
return true;
}
if (args[0].equals("reload")) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/gq/depixa/lifesteal/CommandRevive.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else {
UUID targetId = utils.getUniqueId(args[0]);
if (targetId == null) {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player isn't eliminated.");
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
return true;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(targetId);
Expand All @@ -38,6 +38,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player isn't eliminated.");
}
} else {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
}
}
playerData.saveCustomConfig();
Expand Down
49 changes: 47 additions & 2 deletions src/main/java/gq/depixa/lifesteal/CommandTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
Expand All @@ -15,17 +17,60 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class CommandTransfer implements CommandExecutor {
public class CommandTransfer implements CommandExecutor {
Main plugin = Main.getPlugin();
Utils utils = new Utils();
Configuration playerData = Main.getPlayerConfig();
FileConfiguration config = playerData.getCustomConfig();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 2) {
return false;
}
Player player = (Player) sender;
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) return false;
if (target == null) {
UUID targetId = utils.getUniqueId(args[0]);
if (targetId == null) {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
return true;
}
OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(targetId);
if (offlineTarget == null) {
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
return true;
}
if (config.getBoolean(targetId + ".eliminated") && !plugin.getConfig().getBoolean("allow-transfer-revive")) {
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer to an eliminated player.");
return true;
}
AttributeInstance playerHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
Double currentHealth = playerHealth.getBaseValue();
Integer hearts;
try {
hearts = Integer.parseInt(args[1]);
} catch (Exception e) {
return false;
}
Integer health = hearts * 2;
if (currentHealth <= health) {
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer more hearts than you have or the same amount!");
return true;
}
playerHealth.setBaseValue(currentHealth - health);
config.set(targetId + ".maxHealth", health);
if (config.getBoolean(targetId + ".eliminated")) {
config.set(targetId + ".eliminated", null);
config.set(targetId + ".maxHealth", health);
sender.sendMessage("§6Depixa Lifesteal §8| §eYou revived and transferred §a" + args[1] + " §ehearts to §a" + offlineTarget.getName() + "§e.");
} else {
sender.sendMessage("§6Depixa Lifesteal §8| §eYou transferred §a" + args[1] + " §ehearts to §a" + offlineTarget.getName() + "§e.");
}
playerData.saveCustomConfig();
return true;
}
if (target.equals(player)) {
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer yourself hearts.");
return true;
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/gq/depixa/lifesteal/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
if (!config.getBoolean(victim.getUniqueId() + ".eliminated")) {
config.set(victim.getUniqueId() + ".eliminated", true);
playerData.saveCustomConfig();
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ewas eliminated.");
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ehas been eliminated.");
}
if (!victim.hasPermission("dls.bypass")) {
victim.kickPlayer("§eYou have been eliminated!");
Expand Down Expand Up @@ -89,7 +90,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
if (!config.getBoolean(victim.getUniqueId() + ".eliminated")) {
config.set(victim.getUniqueId() + ".eliminated", true);
playerData.saveCustomConfig();
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ewas eliminated.");
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ehas been eliminated.");
}
if (!victim.hasPermission("dls.bypass")) {
victim.kickPlayer("§eYou have been eliminated!");
Expand All @@ -114,6 +115,23 @@ public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().kickPlayer("§eYou have been eliminated!");
}
}
if (config.get(event.getPlayer().getUniqueId() + ".maxHealth") != null) {
AttributeInstance health = event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (health.getBaseValue() == 2) {
health.setBaseValue(config.getInt(event.getPlayer().getUniqueId() + ".maxHealth"));
} else {
health.setBaseValue(health.getBaseValue() + config.getInt(event.getPlayer().getUniqueId() + ".maxHealth"));
}
config.set(event.getPlayer().getUniqueId() + ".maxHealth", null);
playerData.saveCustomConfig();
}
}

@EventHandler
public void onPlayerKick(PlayerKickEvent event) {
if (event.getReason().equals("§eYou have been eliminated!")) {
event.setLeaveMessage("");
}
}

@EventHandler
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ heart-item: 'NETHER_STAR'
# Set to 0 to disable. This value must be an integer.
max-hearts: 0

# This setting allows players to revive an eliminated player by transferring hearts to them.
allow-transfer-revive: true

# This is not the same as plugin version.
# Do not touch this value.
version: 0.1
version: 0.2
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Depixa-Lifesteal
version: 1.0.2
version: 1.0.3
author: Klxzz
main: gq.depixa.lifesteal.Main
api-version: 1.17
Expand Down

0 comments on commit b313251

Please sign in to comment.