This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also improved air command.
- Loading branch information
Showing
4 changed files
with
246 additions
and
22 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
103 changes: 103 additions & 0 deletions
103
src/main/java/com/denizenscript/denizen2sponge/commands/entity/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,103 @@ | ||
package com.denizenscript.denizen2sponge.commands.entity; | ||
|
||
import com.denizenscript.denizen2core.commands.AbstractCommand; | ||
import com.denizenscript.denizen2core.commands.CommandEntry; | ||
import com.denizenscript.denizen2core.commands.CommandQueue; | ||
import com.denizenscript.denizen2core.tags.objects.NumberTag; | ||
import com.denizenscript.denizen2core.utilities.CoreUtilities; | ||
import com.denizenscript.denizen2core.utilities.debugging.ColorSet; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import org.spongepowered.api.data.key.Keys; | ||
import org.spongepowered.api.entity.living.Living; | ||
|
||
public class HealCommand extends AbstractCommand { | ||
|
||
// <--[command] | ||
// @Name heal | ||
// @Arguments <entity> <amount> | ||
// @Short changes the health of the entity. | ||
// @Updated 2017/04/19 | ||
// @Group Player | ||
// @Minimum 2 | ||
// @Maximum 2 | ||
// @Named type (TextTag) Sets of what type the health will be. | ||
// @Named operation (TextTag) Sets whether the command will add or set the value. | ||
// @Description | ||
// Changes the health of the entity. Optionally specify a type ('remaining' or 'maximum') | ||
// to adjust the specified health type. Defaults to 'remaining'. Also specify whether | ||
// the command will 'add' or 'set' the value. Defaults to 'add'. | ||
// @Example | ||
// # This example heals the player for 4 points (2 hearts) | ||
// - heal <player> 4 | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "heal"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<entity> <amount>"; | ||
} | ||
|
||
@Override | ||
public int getMinimumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getMaximumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public void execute(CommandQueue queue, CommandEntry entry) { | ||
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); | ||
Living ent = (Living) entityTag.getInternal(); | ||
NumberTag amount = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 1)); | ||
String operation; | ||
if (entry.namedArgs.containsKey("operation")) { | ||
operation = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "operation").toString()); | ||
if (!(operation.equals("add") || operation.equals("set"))) { | ||
queue.handleError(entry, "Invalid operation: '" + operation + "'!"); | ||
return; | ||
} | ||
} | ||
else { | ||
operation = "add"; | ||
} | ||
String type; | ||
double value; | ||
if (entry.namedArgs.containsKey("type")) { | ||
type = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "type").toString()); | ||
switch (type) { | ||
case "remaining": | ||
value = ent.health().transform(operation.equals("add") ? | ||
x -> x + amount.getInternal() : x -> amount.getInternal()).get(); | ||
ent.offer(Keys.HEALTH, value); | ||
break; | ||
case "maximum": | ||
value = ent.maxHealth().transform(operation.equals("add") ? | ||
x -> x + amount.getInternal() : x -> amount.getInternal()).get(); | ||
ent.offer(Keys.MAX_HEALTH, value); | ||
break; | ||
default: | ||
queue.handleError(entry, "Invalid health type: '" + type + "'!"); | ||
return; | ||
} | ||
} | ||
else { | ||
type = "remaining"; | ||
value = ent.health().transform(operation.equals("add") ? | ||
x -> x + amount.getInternal() : x -> amount.getInternal()).get(); | ||
ent.offer(Keys.HEALTH, value); | ||
} | ||
if (queue.shouldShowGood()) { | ||
queue.outGood(ColorSet.emphasis + (operation.equals("add") ? "Increasing" : "Setting") + | ||
ColorSet.good + " the " + ColorSet.emphasis + type + ColorSet.good + " health of " + | ||
ColorSet.emphasis + entityTag.debug() + ColorSet.good + (operation.equals("add") ? " by " : " to ") + | ||
ColorSet.emphasis + amount.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/com/denizenscript/denizen2sponge/commands/player/FeedCommand.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,105 @@ | ||
package com.denizenscript.denizen2sponge.commands.player; | ||
|
||
import com.denizenscript.denizen2core.commands.AbstractCommand; | ||
import com.denizenscript.denizen2core.commands.CommandEntry; | ||
import com.denizenscript.denizen2core.commands.CommandQueue; | ||
import com.denizenscript.denizen2core.tags.objects.NumberTag; | ||
import com.denizenscript.denizen2core.utilities.CoreUtilities; | ||
import com.denizenscript.denizen2core.utilities.debugging.ColorSet; | ||
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag; | ||
import org.spongepowered.api.data.key.Keys; | ||
|
||
public class FeedCommand extends AbstractCommand { | ||
|
||
// <--[command] | ||
// @Name feed | ||
// @Arguments <player> <amount> | ||
// @Short changes the food level of the player. | ||
// @Updated 2017/04/19 | ||
// @Group Player | ||
// @Minimum 2 | ||
// @Maximum 2 | ||
// @Named type (TextTag) Sets of what type the food level will be. | ||
// @Named operation (TextTag) Sets whether the command will add or set the value. | ||
// @Description | ||
// Changes the food level of the player. Optionally specify a type ('hunger', 'saturation' | ||
// or 'exhaustion') to adjust the specified food level type. Defaults to 'hunger'. Also | ||
// specify whether the command will 'add' or 'set' the value. Defaults to 'add'. | ||
// @Example | ||
// # This example completely fills the hunger bar of the player | ||
// - feed <player> 20 --operation set | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "feed"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<player> <amount>"; | ||
} | ||
|
||
@Override | ||
public int getMinimumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getMaximumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public void execute(CommandQueue queue, CommandEntry entry) { | ||
PlayerTag player = PlayerTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); | ||
NumberTag amount = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 1)); | ||
String operation; | ||
if (entry.namedArgs.containsKey("operation")) { | ||
operation = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "operation").toString()); | ||
if (!(operation.equals("add") || operation.equals("set"))) { | ||
queue.handleError(entry, "Invalid operation: '" + operation + "'!"); | ||
return; | ||
} | ||
} | ||
else { | ||
operation = "add"; | ||
} | ||
String type; | ||
if (entry.namedArgs.containsKey("type")) { | ||
type = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "type").toString()); | ||
switch (type) { | ||
case "hunger": | ||
int food_level = player.getInternal().foodLevel().transform(operation.equals("add") ? | ||
x -> x + (int) amount.getInternal() : x -> (int) amount.getInternal()).get(); | ||
player.getInternal().offer(Keys.FOOD_LEVEL, food_level); | ||
break; | ||
case "saturation": | ||
double saturation = player.getInternal().saturation().transform(operation.equals("add") ? | ||
x -> x + amount.getInternal() : x -> amount.getInternal()).get(); | ||
player.getInternal().offer(Keys.SATURATION, saturation); | ||
break; | ||
case "exhaustion": | ||
double exhaustion = player.getInternal().exhaustion().transform(operation.equals("add") ? | ||
x -> x + amount.getInternal() : x -> amount.getInternal()).get(); | ||
player.getInternal().offer(Keys.EXHAUSTION, exhaustion); | ||
break; | ||
default: | ||
queue.handleError(entry, "Invalid food level type: '" + type + "'!"); | ||
return; | ||
} | ||
} | ||
else { | ||
type = "hunger"; | ||
int food_level = player.getInternal().foodLevel().transform(operation.equals("add") ? | ||
x -> x + (int) amount.getInternal() : x -> (int) amount.getInternal()).get(); | ||
player.getInternal().offer(Keys.FOOD_LEVEL, food_level); | ||
} | ||
if (queue.shouldShowGood()) { | ||
queue.outGood(ColorSet.emphasis + (operation.equals("add") ? "Increasing" : "Setting") + | ||
ColorSet.good + " the " + ColorSet.emphasis + type + ColorSet.good + " level of " + | ||
ColorSet.emphasis + player.debug() + ColorSet.good + (operation.equals("add") ? " by " : " to ") + | ||
ColorSet.emphasis + amount.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
} |