Don't try to modify max health if less than 0

This commit is contained in:
mathiascode 2020-02-27 16:13:24 +02:00
parent f00208d706
commit 145cfcb0c7
3 changed files with 6 additions and 10 deletions

0
.gitignore vendored Normal file → Executable file
View File

View File

@ -1,8 +1,6 @@
package pw.kaboom.icontrolu;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -25,7 +23,7 @@ import org.bukkit.scoreboard.Team;
import pw.kaboom.icontrolu.utilities.PlayerList;
class Tick extends BukkitRunnable {
@Override
@SuppressWarnings("deprecation")
public void run() {
for (Player target: Bukkit.getOnlinePlayers()) {
final Player controller = PlayerList.getController(target.getUniqueId());
@ -45,14 +43,15 @@ class Tick extends BukkitRunnable {
target.teleportAsync(controller.getLocation());
}
AttributeInstance controllerMaxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance targetMaxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH);
targetMaxHealth.setBaseValue(controllerMaxHealth.getBaseValue());
target.setAllowFlight(controller.getAllowFlight());
target.setExhaustion(controller.getExhaustion());
target.setFlying(controller.isFlying());
target.setFoodLevel(controller.getFoodLevel());
if (controller.getMaxHealth() > 0) {
target.setMaxHealth(controller.getMaxHealth());
}
target.setHealth(controller.getHealth());
target.setLevel(controller.getLevel());
target.setSneaking(controller.isSneaking());
@ -172,7 +171,6 @@ class ControlPlayer implements Listener {
final int tickDelay = 200;
new BukkitRunnable() {
@Override
public void run() {
for (Player allPlayers: Bukkit.getOnlinePlayers()) {
allPlayers.showPlayer(JavaPlugin.getPlugin(Main.class), controller);

View File

@ -60,7 +60,6 @@ public final class CommandIcu implements CommandExecutor {
final int tickDelay = 200;
new BukkitRunnable() {
@Override
public void run() {
for (Player player: Bukkit.getOnlinePlayers()) {
player.showPlayer(JavaPlugin.getPlugin(Main.class), controller);
@ -85,7 +84,6 @@ public final class CommandIcu implements CommandExecutor {
}
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player");