Skip to content

Commit

Permalink
fix: fix effect command
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 27, 2024
1 parent b93c37b commit 104dd1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public void prepareCommandTree(CommandTree tree) {
.exec(context -> {
Collection<EntityPlayer> players = context.getResult(0);
EffectType effectType = context.getResult(1);
int seconds = (int) context.getResult(2) * 20; // because effect duration in ticks
int seconds = context.getResult(2);
int time = seconds * 20; // because effect duration in ticks
int amplifier = context.getResult(3);
boolean hideParticles = context.getResult(4);

players.forEach(player -> {
player.addEffect(effectType.createInstance(amplifier, seconds, !hideParticles));
player.addEffect(effectType.createInstance(amplifier, time, !hideParticles));
context.addOutput(
TrKeys.M_COMMANDS_EFFECT_SUCCESS,
effectType.getIdentifier().path(), // TODO: I18N
Expand All @@ -46,8 +47,7 @@ public void prepareCommandTree(CommandTree tree) {

return context.success();
})
.root()
.playerTarget("player")
.up(4)
.key("clear")
.exec(context -> {
Collection<EntityPlayer> players = context.getResult(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,10 @@ protected void sendMobEffectPacket(MobEffectPacket packet) {

@Override
public void removeAllEffects() {
this.effects.keySet().forEach(this::removeEffect);
// Use for-each instead of forEach() to prevent ConcurrentModificationException
for (EffectType effectType : this.effects.keySet()) {
removeEffect(effectType);
}
}

protected void calculateEffectColor() {
Expand Down

0 comments on commit 104dd1e

Please sign in to comment.