|
|
@ -1,22 +1,54 @@ |
|
|
|
package com.benjocraeft.sharehealth; |
|
|
|
package com.benjocraeft.sharehealth; |
|
|
|
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit; |
|
|
|
import org.bukkit.Bukkit; |
|
|
|
|
|
|
|
import org.bukkit.EntityEffect; |
|
|
|
|
|
|
|
import org.bukkit.Material; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
|
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
|
|
|
|
import org.bukkit.potion.PotionEffect; |
|
|
|
|
|
|
|
import org.bukkit.potion.PotionEffectType; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class TotemManager { |
|
|
|
public class TotemManager { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Mode mode; |
|
|
|
private Mode mode = Mode.All; |
|
|
|
|
|
|
|
|
|
|
|
//between 0 and 1
|
|
|
|
//between 0 and 1
|
|
|
|
private double fractionNeeded; |
|
|
|
private double fractionNeeded; |
|
|
|
|
|
|
|
|
|
|
|
//Tries to save the game, return true on success, false otherwise
|
|
|
|
//Determine if enough players hold a totem of undying
|
|
|
|
public boolean tryToSave(){ |
|
|
|
public boolean totemCanBeUsed(){ |
|
|
|
|
|
|
|
return getHolderCount() >= getMinimumPlayerCount(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Activate Totem Effect
|
|
|
|
|
|
|
|
//TODO remove used Totems
|
|
|
|
|
|
|
|
//Finally buy some Falafel for Markus
|
|
|
|
|
|
|
|
public void activate(Player triggeringPlayer){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Remove all effects from Player
|
|
|
|
|
|
|
|
for (PotionEffect e : triggeringPlayer.getActivePotionEffects()) |
|
|
|
|
|
|
|
triggeringPlayer.removePotionEffect(e.getType()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Regeneration II 40sec
|
|
|
|
|
|
|
|
PotionEffect regeneration = new PotionEffect(PotionEffectType.REGENERATION, 40 * 20, 1); |
|
|
|
|
|
|
|
triggeringPlayer.addPotionEffect(regeneration); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Fire Resistance I 40sec
|
|
|
|
|
|
|
|
PotionEffect fireRes = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 40 * 20, 0); |
|
|
|
|
|
|
|
triggeringPlayer.addPotionEffect(fireRes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Absorption II 5sec
|
|
|
|
|
|
|
|
PotionEffect absorption = new PotionEffect(PotionEffectType.ABSORPTION, 5 * 20, 1); |
|
|
|
|
|
|
|
triggeringPlayer.addPotionEffect(absorption); |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
//Play Totem Effect to every Player
|
|
|
|
|
|
|
|
for (Player p : Sharehealth.GetPlayers()) |
|
|
|
|
|
|
|
p.playEffect(EntityEffect.TOTEM_RESURRECT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Calculates how many players are needed at least to trigger the totem for everyone
|
|
|
|
//Calculates how many players are needed at least to trigger the totem for everyone
|
|
|
@ -26,20 +58,26 @@ public class TotemManager { |
|
|
|
case One -> 1; |
|
|
|
case One -> 1; |
|
|
|
case All -> allPlayerCount; |
|
|
|
case All -> allPlayerCount; |
|
|
|
case Disabled -> Bukkit.getMaxPlayers() + 1; |
|
|
|
case Disabled -> Bukkit.getMaxPlayers() + 1; |
|
|
|
case Percentage -> (int) Math.ceil(fractionNeeded * allPlayerCount); |
|
|
|
case Fraction -> (int) Math.ceil(fractionNeeded * allPlayerCount); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Counts how many players hold a totem
|
|
|
|
//Counts how many players hold a totem
|
|
|
|
|
|
|
|
//Markus still is waiting for his Falafel
|
|
|
|
private int getHolderCount(){ |
|
|
|
private int getHolderCount(){ |
|
|
|
List<Player> players = Sharehealth.GetPlayers(); |
|
|
|
List<Player> players = Sharehealth.GetPlayers(); |
|
|
|
return 0; |
|
|
|
return players.stream().mapToInt(p -> { |
|
|
|
|
|
|
|
ItemStack main = p.getInventory().getItemInMainHand(); |
|
|
|
|
|
|
|
ItemStack off = p.getInventory().getItemInOffHand(); |
|
|
|
|
|
|
|
return (main.getType().equals(Material.TOTEM_OF_UNDYING) || |
|
|
|
|
|
|
|
off.getType().equals(Material.TOTEM_OF_UNDYING)) ? 1 : 0; |
|
|
|
|
|
|
|
}).sum(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum Mode { |
|
|
|
enum Mode { |
|
|
|
One, |
|
|
|
One, |
|
|
|
All, |
|
|
|
All, |
|
|
|
Percentage, |
|
|
|
Fraction, |
|
|
|
Disabled |
|
|
|
Disabled |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|