Skip to content

Commit b313251

Browse files
committed
Eliminating and transferring hearts to offline players will now work.
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]>
1 parent d2471ea commit b313251

File tree

9 files changed

+98
-11
lines changed

9 files changed

+98
-11
lines changed

.gradle/file-system.probe

0 Bytes
Binary file not shown.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'gq.depixa.lifesteal'
6-
version '1.0.2'
6+
version '1.0.3'
77

88
compileJava.options.encoding = "UTF-8"
99
compileTestJava.options.encoding = "UTF-8"

src/main/java/gq/depixa/lifesteal/CommandEliminate.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package gq.depixa.lifesteal;
22

33
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
45
import org.bukkit.command.Command;
56
import org.bukkit.command.CommandExecutor;
67
import org.bukkit.command.CommandSender;
78
import org.bukkit.configuration.file.FileConfiguration;
89
import org.bukkit.entity.Player;
910

11+
import java.util.UUID;
12+
1013
public class CommandEliminate implements CommandExecutor {
1114
Main plugin = Main.getPlugin();
15+
Utils utils = new Utils();
1216
private Configuration playerData = Main.getPlayerConfig();
1317
FileConfiguration config = playerData.getCustomConfig();
1418
@Override
@@ -19,7 +23,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
1923
if (args[0].equals("all")) {
2024
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
2125
config.set(player.getUniqueId() + ".eliminated", true);
22-
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + player.getDisplayName() + " §ewas eliminated.");
26+
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + player.getDisplayName() + " §ehas been eliminated.");
2327
if (player.hasPermission("dls.bypass")) {
2428
player.sendMessage("§6Depixa Lifesteal §8| §eYou have been eliminated, but you have bypass enabled.");
2529
} else {
@@ -32,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3236
if (target != null) {
3337
if (!config.getBoolean(target.getUniqueId() + ".eliminated")) {
3438
config.set(target.getUniqueId() + ".eliminated", true);
35-
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + target.getDisplayName() + " §ewas eliminated.");
39+
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + target.getDisplayName() + " §ehas been eliminated.");
3640
if (target.hasPermission("dls.bypass")) {
3741
target.sendMessage("§6Depixa Lifesteal §8| §eYou have been eliminated, but you have bypass enabled.");
3842
} else {
@@ -41,6 +45,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4145
} else {
4246
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player is already eliminated.");
4347
}
48+
} else {
49+
UUID targetId = utils.getUniqueId(args[0]);
50+
if (targetId == null) {
51+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
52+
return true;
53+
}
54+
OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(targetId);
55+
if (offlineTarget == null) {
56+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
57+
return true;
58+
}
59+
if (!config.getBoolean(targetId + ".eliminated")) {
60+
config.set(targetId + ".eliminated", true);
61+
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + offlineTarget.getName() + " §ehas been eliminated.");
62+
}
4463
}
4564
}
4665
playerData.saveCustomConfig();

src/main/java/gq/depixa/lifesteal/CommandLifesteal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CommandLifesteal implements CommandExecutor {
1010
@Override
1111
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
1212
if (args.length == 0) {
13-
sender.sendMessage("§6Depixa Lifesteal §8| §eVersion 1.0.0");
13+
sender.sendMessage("§6Depixa Lifesteal §8| §eVersion " + plugin.getDescription().getVersion());
1414
return true;
1515
}
1616
if (args[0].equals("reload")) {

src/main/java/gq/depixa/lifesteal/CommandRevive.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2727
} else {
2828
UUID targetId = utils.getUniqueId(args[0]);
2929
if (targetId == null) {
30-
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player isn't eliminated.");
30+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
3131
return true;
3232
}
3333
OfflinePlayer target = Bukkit.getOfflinePlayer(targetId);
@@ -38,6 +38,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3838
} else {
3939
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player isn't eliminated.");
4040
}
41+
} else {
42+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
4143
}
4244
}
4345
playerData.saveCustomConfig();

src/main/java/gq/depixa/lifesteal/CommandTransfer.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.Material;
5+
import org.bukkit.OfflinePlayer;
56
import org.bukkit.attribute.Attribute;
67
import org.bukkit.attribute.AttributeInstance;
78
import org.bukkit.command.Command;
89
import org.bukkit.command.CommandExecutor;
910
import org.bukkit.command.CommandSender;
11+
import org.bukkit.configuration.file.FileConfiguration;
1012
import org.bukkit.enchantments.Enchantment;
1113
import org.bukkit.entity.Player;
1214
import org.bukkit.inventory.ItemFlag;
@@ -15,17 +17,60 @@
1517

1618
import java.util.ArrayList;
1719
import java.util.List;
20+
import java.util.UUID;
1821

19-
public class CommandTransfer implements CommandExecutor {
22+
public class CommandTransfer implements CommandExecutor {
2023
Main plugin = Main.getPlugin();
24+
Utils utils = new Utils();
25+
Configuration playerData = Main.getPlayerConfig();
26+
FileConfiguration config = playerData.getCustomConfig();
2127
@Override
2228
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2329
if (args.length != 2) {
2430
return false;
2531
}
2632
Player player = (Player) sender;
2733
Player target = Bukkit.getPlayerExact(args[0]);
28-
if (target == null) return false;
34+
if (target == null) {
35+
UUID targetId = utils.getUniqueId(args[0]);
36+
if (targetId == null) {
37+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
38+
return true;
39+
}
40+
OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(targetId);
41+
if (offlineTarget == null) {
42+
sender.sendMessage("§6Depixa Lifesteal §8| §cThis player has not joined the server yet.");
43+
return true;
44+
}
45+
if (config.getBoolean(targetId + ".eliminated") && !plugin.getConfig().getBoolean("allow-transfer-revive")) {
46+
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer to an eliminated player.");
47+
return true;
48+
}
49+
AttributeInstance playerHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
50+
Double currentHealth = playerHealth.getBaseValue();
51+
Integer hearts;
52+
try {
53+
hearts = Integer.parseInt(args[1]);
54+
} catch (Exception e) {
55+
return false;
56+
}
57+
Integer health = hearts * 2;
58+
if (currentHealth <= health) {
59+
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer more hearts than you have or the same amount!");
60+
return true;
61+
}
62+
playerHealth.setBaseValue(currentHealth - health);
63+
config.set(targetId + ".maxHealth", health);
64+
if (config.getBoolean(targetId + ".eliminated")) {
65+
config.set(targetId + ".eliminated", null);
66+
config.set(targetId + ".maxHealth", health);
67+
sender.sendMessage("§6Depixa Lifesteal §8| §eYou revived and transferred §a" + args[1] + " §ehearts to §a" + offlineTarget.getName() + "§e.");
68+
} else {
69+
sender.sendMessage("§6Depixa Lifesteal §8| §eYou transferred §a" + args[1] + " §ehearts to §a" + offlineTarget.getName() + "§e.");
70+
}
71+
playerData.saveCustomConfig();
72+
return true;
73+
}
2974
if (target.equals(player)) {
3075
sender.sendMessage("§6Depixa Lifesteal §8| §cYou cannot transfer yourself hearts.");
3176
return true;

src/main/java/gq/depixa/lifesteal/EventListener.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.bukkit.event.inventory.PrepareItemCraftEvent;
1515
import org.bukkit.event.player.PlayerInteractEvent;
1616
import org.bukkit.event.player.PlayerJoinEvent;
17+
import org.bukkit.event.player.PlayerKickEvent;
1718
import org.bukkit.inventory.ItemFlag;
1819
import org.bukkit.inventory.ItemStack;
1920
import org.bukkit.inventory.meta.ItemMeta;
@@ -58,7 +59,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
5859
if (!config.getBoolean(victim.getUniqueId() + ".eliminated")) {
5960
config.set(victim.getUniqueId() + ".eliminated", true);
6061
playerData.saveCustomConfig();
61-
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ewas eliminated.");
62+
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ehas been eliminated.");
6263
}
6364
if (!victim.hasPermission("dls.bypass")) {
6465
victim.kickPlayer("§eYou have been eliminated!");
@@ -89,7 +90,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
8990
if (!config.getBoolean(victim.getUniqueId() + ".eliminated")) {
9091
config.set(victim.getUniqueId() + ".eliminated", true);
9192
playerData.saveCustomConfig();
92-
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ewas eliminated.");
93+
Bukkit.broadcastMessage("§6Depixa Lifesteal §8| §a" + victim.getDisplayName() + " §ehas been eliminated.");
9394
}
9495
if (!victim.hasPermission("dls.bypass")) {
9596
victim.kickPlayer("§eYou have been eliminated!");
@@ -114,6 +115,23 @@ public void onPlayerJoin(PlayerJoinEvent event) {
114115
event.getPlayer().kickPlayer("§eYou have been eliminated!");
115116
}
116117
}
118+
if (config.get(event.getPlayer().getUniqueId() + ".maxHealth") != null) {
119+
AttributeInstance health = event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH);
120+
if (health.getBaseValue() == 2) {
121+
health.setBaseValue(config.getInt(event.getPlayer().getUniqueId() + ".maxHealth"));
122+
} else {
123+
health.setBaseValue(health.getBaseValue() + config.getInt(event.getPlayer().getUniqueId() + ".maxHealth"));
124+
}
125+
config.set(event.getPlayer().getUniqueId() + ".maxHealth", null);
126+
playerData.saveCustomConfig();
127+
}
128+
}
129+
130+
@EventHandler
131+
public void onPlayerKick(PlayerKickEvent event) {
132+
if (event.getReason().equals("§eYou have been eliminated!")) {
133+
event.setLeaveMessage("");
134+
}
117135
}
118136

119137
@EventHandler

src/main/resources/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ heart-item: 'NETHER_STAR'
1010
# Set to 0 to disable. This value must be an integer.
1111
max-hearts: 0
1212

13+
# This setting allows players to revive an eliminated player by transferring hearts to them.
14+
allow-transfer-revive: true
15+
1316
# This is not the same as plugin version.
1417
# Do not touch this value.
15-
version: 0.1
18+
version: 0.2

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Depixa-Lifesteal
2-
version: 1.0.2
2+
version: 1.0.3
33
author: Klxzz
44
main: gq.depixa.lifesteal.Main
55
api-version: 1.17

0 commit comments

Comments
 (0)