--- a/net/minecraft/server/commands/EffectCommands.java +++ b/net/minecraft/server/commands/EffectCommands.java @@ -13,7 +13,6 @@ import javax.annotation.Nullable; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.core.Holder; @@ -32,60 +31,60 @@ public EffectCommands() {} - public static void register(CommandDispatcher commanddispatcher, CommandBuildContext commandbuildcontext) { - commanddispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) Commands.literal("effect").requires((commandsourcestack) -> { - return commandsourcestack.hasPermission(2); - })).then(((LiteralArgumentBuilder) Commands.literal("clear").executes((commandcontext) -> { + public static void register(CommandDispatcher dispatcher, CommandBuildContext context) { + dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("effect").requires((commandlistenerwrapper) -> { + return commandlistenerwrapper.hasPermission(2); + })).then(((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("clear").executes((commandcontext) -> { return clearEffects((CommandSourceStack) commandcontext.getSource(), ImmutableList.of(((CommandSourceStack) commandcontext.getSource()).getEntityOrException())); - })).then(((RequiredArgumentBuilder) Commands.argument("targets", EntityArgument.entities()).executes((commandcontext) -> { + })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("targets", EntityArgument.entities()).executes((commandcontext) -> { return clearEffects((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets")); - })).then(Commands.argument("effect", ResourceArgument.resource(commandbuildcontext, Registries.MOB_EFFECT)).executes((commandcontext) -> { + })).then(net.minecraft.commands.Commands.argument("effect", ResourceArgument.resource(context, Registries.MOB_EFFECT)).executes((commandcontext) -> { return clearEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect")); - }))))).then(Commands.literal("give").then(Commands.argument("targets", EntityArgument.entities()).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) Commands.argument("effect", ResourceArgument.resource(commandbuildcontext, Registries.MOB_EFFECT)).executes((commandcontext) -> { + }))))).then(net.minecraft.commands.Commands.literal("give").then(net.minecraft.commands.Commands.argument("targets", EntityArgument.entities()).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("effect", ResourceArgument.resource(context, Registries.MOB_EFFECT)).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), (Integer) null, 0, true); - })).then(((RequiredArgumentBuilder) Commands.argument("seconds", IntegerArgumentType.integer(1, 1000000)).executes((commandcontext) -> { + })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("seconds", IntegerArgumentType.integer(1, 1000000)).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), IntegerArgumentType.getInteger(commandcontext, "seconds"), 0, true); - })).then(((RequiredArgumentBuilder) Commands.argument("amplifier", IntegerArgumentType.integer(0, 255)).executes((commandcontext) -> { + })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("amplifier", IntegerArgumentType.integer(0, 255)).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), IntegerArgumentType.getInteger(commandcontext, "seconds"), IntegerArgumentType.getInteger(commandcontext, "amplifier"), true); - })).then(Commands.argument("hideParticles", BoolArgumentType.bool()).executes((commandcontext) -> { + })).then(net.minecraft.commands.Commands.argument("hideParticles", BoolArgumentType.bool()).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), IntegerArgumentType.getInteger(commandcontext, "seconds"), IntegerArgumentType.getInteger(commandcontext, "amplifier"), !BoolArgumentType.getBool(commandcontext, "hideParticles")); - }))))).then(((LiteralArgumentBuilder) Commands.literal("infinite").executes((commandcontext) -> { + }))))).then(((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("infinite").executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), -1, 0, true); - })).then(((RequiredArgumentBuilder) Commands.argument("amplifier", IntegerArgumentType.integer(0, 255)).executes((commandcontext) -> { + })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("amplifier", IntegerArgumentType.integer(0, 255)).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), -1, IntegerArgumentType.getInteger(commandcontext, "amplifier"), true); - })).then(Commands.argument("hideParticles", BoolArgumentType.bool()).executes((commandcontext) -> { + })).then(net.minecraft.commands.Commands.argument("hideParticles", BoolArgumentType.bool()).executes((commandcontext) -> { return giveEffect((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ResourceArgument.getMobEffect(commandcontext, "effect"), -1, IntegerArgumentType.getInteger(commandcontext, "amplifier"), !BoolArgumentType.getBool(commandcontext, "hideParticles")); })))))))); } - private static int giveEffect(CommandSourceStack commandsourcestack, Collection collection, Holder holder, @Nullable Integer integer, int i, boolean flag) throws CommandSyntaxException { - MobEffect mobeffect = (MobEffect) holder.value(); + private static int giveEffect(CommandSourceStack source, Collection targets, Holder effect, @Nullable Integer seconds, int amplifier, boolean showParticles) throws CommandSyntaxException { + MobEffect mobeffectlist = (MobEffect) effect.value(); int j = 0; int k; - if (integer != null) { - if (mobeffect.isInstantenous()) { - k = integer; - } else if (integer == -1) { + if (seconds != null) { + if (mobeffectlist.isInstantenous()) { + k = seconds; + } else if (seconds == -1) { k = -1; } else { - k = integer * 20; + k = seconds * 20; } - } else if (mobeffect.isInstantenous()) { + } else if (mobeffectlist.isInstantenous()) { k = 1; } else { k = 600; } - Iterator iterator = collection.iterator(); + Iterator iterator = targets.iterator(); while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); if (entity instanceof LivingEntity) { - MobEffectInstance mobeffectinstance = new MobEffectInstance(mobeffect, k, i, false, flag); + MobEffectInstance mobeffect = new MobEffectInstance(mobeffectlist, k, amplifier, false, showParticles); - if (((LivingEntity) entity).addEffect(mobeffectinstance, commandsourcestack.getEntity())) { + if (((LivingEntity) entity).addEffect(mobeffect, source.getEntity(), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit ++j; } } @@ -94,13 +93,13 @@ if (j == 0) { throw EffectCommands.ERROR_GIVE_FAILED.create(); } else { - if (collection.size() == 1) { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.give.success.single", mobeffect.getDisplayName(), ((Entity) collection.iterator().next()).getDisplayName(), k / 20); + if (targets.size() == 1) { + source.sendSuccess(() -> { + return Component.translatable("commands.effect.give.success.single", mobeffectlist.getDisplayName(), ((Entity) targets.iterator().next()).getDisplayName(), k / 20); }, true); } else { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.give.success.multiple", mobeffect.getDisplayName(), collection.size(), k / 20); + source.sendSuccess(() -> { + return Component.translatable("commands.effect.give.success.multiple", mobeffectlist.getDisplayName(), targets.size(), k / 20); }, true); } @@ -108,14 +107,14 @@ } } - private static int clearEffects(CommandSourceStack commandsourcestack, Collection collection) throws CommandSyntaxException { + private static int clearEffects(CommandSourceStack source, Collection targets) throws CommandSyntaxException { int i = 0; - Iterator iterator = collection.iterator(); + Iterator iterator = targets.iterator(); while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); - if (entity instanceof LivingEntity && ((LivingEntity) entity).removeAllEffects()) { + if (entity instanceof LivingEntity && ((LivingEntity) entity).removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit ++i; } } @@ -123,13 +122,13 @@ if (i == 0) { throw EffectCommands.ERROR_CLEAR_EVERYTHING_FAILED.create(); } else { - if (collection.size() == 1) { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.clear.everything.success.single", ((Entity) collection.iterator().next()).getDisplayName()); + if (targets.size() == 1) { + source.sendSuccess(() -> { + return Component.translatable("commands.effect.clear.everything.success.single", ((Entity) targets.iterator().next()).getDisplayName()); }, true); } else { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.clear.everything.success.multiple", collection.size()); + source.sendSuccess(() -> { + return Component.translatable("commands.effect.clear.everything.success.multiple", targets.size()); }, true); } @@ -137,15 +136,15 @@ } } - private static int clearEffect(CommandSourceStack commandsourcestack, Collection collection, Holder holder) throws CommandSyntaxException { - MobEffect mobeffect = (MobEffect) holder.value(); + private static int clearEffect(CommandSourceStack source, Collection targets, Holder effect) throws CommandSyntaxException { + MobEffect mobeffectlist = (MobEffect) effect.value(); int i = 0; - Iterator iterator = collection.iterator(); + Iterator iterator = targets.iterator(); while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); - if (entity instanceof LivingEntity && ((LivingEntity) entity).removeEffect(mobeffect)) { + if (entity instanceof LivingEntity && ((LivingEntity) entity).removeEffect(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit ++i; } } @@ -153,13 +152,13 @@ if (i == 0) { throw EffectCommands.ERROR_CLEAR_SPECIFIC_FAILED.create(); } else { - if (collection.size() == 1) { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.clear.specific.success.single", mobeffect.getDisplayName(), ((Entity) collection.iterator().next()).getDisplayName()); + if (targets.size() == 1) { + source.sendSuccess(() -> { + return Component.translatable("commands.effect.clear.specific.success.single", mobeffectlist.getDisplayName(), ((Entity) targets.iterator().next()).getDisplayName()); }, true); } else { - commandsourcestack.sendSuccess(() -> { - return Component.translatable("commands.effect.clear.specific.success.multiple", mobeffect.getDisplayName(), collection.size()); + source.sendSuccess(() -> { + return Component.translatable("commands.effect.clear.specific.success.multiple", mobeffectlist.getDisplayName(), targets.size()); }, true); }