-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2df03bb
commit 1a3b7b4
Showing
12 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+113 Bytes
(100%)
.../commander-bta.main/net/pedroricardo/commander/content/CommanderClientCommandSource.class
Binary file not shown.
Binary file modified
BIN
+156 Bytes
(100%)
...ction/commander-bta.main/net/pedroricardo/commander/content/CommanderCommandManager.class
Binary file not shown.
Binary file modified
BIN
+34 Bytes
(100%)
...uction/commander-bta.main/net/pedroricardo/commander/content/CommanderCommandSource.class
Binary file not shown.
Binary file modified
BIN
+209 Bytes
(100%)
...commander-bta.main/net/pedroricardo/commander/content/CommanderConsoleCommandSource.class
Binary file not shown.
Binary file modified
BIN
+165 Bytes
(100%)
.../commander-bta.main/net/pedroricardo/commander/content/CommanderServerCommandSource.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/net/pedroricardo/commander/content/commands/HealCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.pedroricardo.commander.content.commands; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import net.minecraft.core.entity.Entity; | ||
import net.minecraft.core.entity.EntityLiving; | ||
import net.minecraft.core.util.helper.MathHelper; | ||
import net.minecraft.core.world.World; | ||
import net.pedroricardo.commander.content.CommanderCommandSource; | ||
import net.pedroricardo.commander.content.arguments.EntityArgumentType; | ||
import net.pedroricardo.commander.content.helpers.EntitySelector; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.List; | ||
|
||
public class HealCommand { | ||
public static void register(CommandDispatcher<CommanderCommandSource> dispatcher) { | ||
dispatcher.register(LiteralArgumentBuilder.<CommanderCommandSource>literal("heal") | ||
.then(RequiredArgumentBuilder.<CommanderCommandSource, EntitySelector>argument("entities", EntityArgumentType.entities()) | ||
.then(RequiredArgumentBuilder.<CommanderCommandSource, Integer>argument("amount", IntegerArgumentType.integer(0, 32768)) | ||
.executes(c -> { | ||
List<? extends Entity> entities = c.getArgument("entities", EntitySelector.class).get(c.getSource()); | ||
int amount = c.getArgument("amount", Integer.class); | ||
|
||
int entitiesAffected = 0; | ||
for (Entity entity : entities) { | ||
if (entity instanceof EntityLiving) { | ||
int maxHealth = 20; | ||
try { | ||
maxHealth = ((EntityLiving)entity.getClass().getConstructor(World.class).newInstance(c.getSource().getWorld())).health; | ||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ignored) { | ||
} | ||
int originalHealth = ((EntityLiving)entity).health; | ||
((EntityLiving)entity).health = MathHelper.clamp(((EntityLiving)entity).health + amount, 0, maxHealth); | ||
if (((EntityLiving)entity).health != originalHealth) ++entitiesAffected; | ||
} | ||
} | ||
c.getSource().sendTranslatableMessage("commands.commander.heal.success_" + (entitiesAffected == 1 ? "single" : "multiple"), entitiesAffected); | ||
return entitiesAffected; | ||
})))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters