mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
@@ -93,7 +93,7 @@ public class BEffect {
|
|||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
duration /= type.getDurationModifier();
|
duration /= type.getDurationModifier();
|
||||||
}
|
}
|
||||||
type.createEffect(duration, lvl - 1).apply(player);
|
Util.reapplyPotionEffect(player, type.createEffect(duration, lvl - 1), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calcDuration(float quality) {
|
public int calcDuration(float quality) {
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ public class BPlayer {
|
|||||||
duration *= 4;
|
duration *= 4;
|
||||||
}
|
}
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
PotionEffectType.POISON.createEffect(duration, 0).apply(player);
|
Util.reapplyPotionEffect(player, PotionEffectType.POISON.createEffect(duration, 0), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brewAlc > 10) {
|
if (brewAlc > 10) {
|
||||||
@@ -511,7 +511,7 @@ public class BPlayer {
|
|||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
duration *= 4;
|
duration *= 4;
|
||||||
}
|
}
|
||||||
PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player);
|
Util.reapplyPotionEffect(player, PotionEffectType.BLINDNESS.createEffect(duration, 0), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,12 +531,12 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
int amplifier = getHangoverQuality() / 3;
|
int amplifier = getHangoverQuality() / 3;
|
||||||
|
|
||||||
PotionEffectType.SLOW.createEffect(duration, amplifier).apply(player);
|
Util.reapplyPotionEffect(player, PotionEffectType.SLOW.createEffect(duration, amplifier), true);
|
||||||
PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player);
|
Util.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(duration, amplifier), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #### Sheduled ####
|
// #### Scheduled ####
|
||||||
|
|
||||||
public static void drunkeness() {
|
public static void drunkeness() {
|
||||||
for (Map.Entry<String, BPlayer> entry : players.entrySet()) {
|
for (Map.Entry<String, BPlayer> entry : players.entrySet()) {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -54,6 +56,26 @@ public class Util {
|
|||||||
return Bukkit.getPlayerExact(name);
|
return Bukkit.getPlayerExact(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply a Potion Effect, if player already has this effect, overwrite the existing effect.
|
||||||
|
// Optionally only overwrite if the new one is stronger, i.e. has higher level or longer duration
|
||||||
|
public static void reapplyPotionEffect(Player player, PotionEffect effect, boolean onlyIfStronger) {
|
||||||
|
final PotionEffectType type = effect.getType();
|
||||||
|
if (player.hasPotionEffect(type)) {
|
||||||
|
PotionEffect plEffect;
|
||||||
|
if (P.use1_11) {
|
||||||
|
plEffect = player.getPotionEffect(type);
|
||||||
|
} else {
|
||||||
|
plEffect = player.getActivePotionEffects().stream().filter(e -> e.getType().equals(type)).findAny().get();
|
||||||
|
}
|
||||||
|
if (plEffect.getAmplifier() < effect.getAmplifier() || (plEffect.getAmplifier() == effect.getAmplifier() && plEffect.getDuration() < effect.getDuration())) {
|
||||||
|
player.removePotionEffect(type);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
effect.apply(player);
|
||||||
|
}
|
||||||
|
|
||||||
/********** Other Utils **********/
|
/********** Other Utils **********/
|
||||||
|
|
||||||
// prints a list of Strings at the specified page
|
// prints a list of Strings at the specified page
|
||||||
|
|||||||
Reference in New Issue
Block a user