Skip to content

Commit

Permalink
potion effect Async fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperRonanCraft committed Oct 7, 2023
1 parent 044054d commit b4dae7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void run() {

//Effects

public void afterTeleport(Player p, Location loc, WorldPlayer wPlayer, int attempts, Location oldLoc, RTP_TYPE type) { //Only a successful rtp should run this OR '/rtp test'
public void afterTeleport(Player p, Location loc, WorldPlayer wPlayer, int attempts, Location oldLoc, RTP_TYPE type) {
//Only a successful rtp should run this OR '/rtp test'
effects.getSounds().playTeleport(p);
effects.getParticles().display(p);
effects.getPotions().giveEffects(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
import me.SuperRonanCraft.BetterRTP.versions.AsyncHandler;
import me.SuperRonanCraft.BetterRTP.versions.FoliaHandler;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -49,18 +51,20 @@ void load() {
}

public void giveEffects(Player p) {
if (invincibleEnabled)
p.setNoDamageTicks(invincibleTime * 20);
if (potionEnabled) {
List<PotionEffect> effects = new ArrayList<>();
for (PotionEffectType e : potionEffects.keySet()) {
Integer[] mods = potionEffects.get(e);
int duration = mods[0];
int amplifier = mods[1];
effects.add(new PotionEffect(e, duration, amplifier, false, false));
AsyncHandler.sync(() -> {
if (invincibleEnabled)
p.setNoDamageTicks(invincibleTime * 20);
if (potionEnabled) {
List<PotionEffect> effects = new ArrayList<>();
for (PotionEffectType e : potionEffects.keySet()) {
Integer[] mods = potionEffects.get(e);
int duration = mods[0];
int amplifier = mods[1];
effects.add(new PotionEffect(e, duration, amplifier, false, false));
}
p.addPotionEffects(effects);
}
p.addPotionEffects(effects);
}
});
}

}

0 comments on commit b4dae7d

Please sign in to comment.