Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
commands cleaning
Browse files Browse the repository at this point in the history
- clean weird string mismanagement
- improve ai task docs
- less silly TextTag misuse
- clean code logic a bit
- cleaned spawn command all over
  • Loading branch information
mcmonkey4eva committed Jun 15, 2018
1 parent 05c6a28 commit 8ac76a7
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 215 deletions.
Expand Up @@ -12,11 +12,11 @@
public class AbsorptionCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Since 0.5.5
// @Name absorption
// @Arguments <entity> <value>
// @Short changes the absorption points of an entity.
// @Updated 2018/02/17
// @Updated 2018/06/15
// @Group Entity
// @Minimum 2
// @Maximum 2
Expand Down Expand Up @@ -53,23 +53,15 @@ public int getMaximumArguments() {
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
NumberTag nt = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
boolean set;
boolean set = false;
if (entry.namedArgs.containsKey("operation")) {
String operation = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "operation").toString());
switch (operation) {
case "add":
set = false;
break;
case "set":
set = true;
break;
default:
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
return;
if (operation.equals("set")) {
set = true;
}
else if (!operation.equals("add")) {
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
}
}
else {
set = false;
}
ent.getInternal().offer(Keys.ABSORPTION,
set ? nt.getInternal() : ent.getInternal().get(Keys.ABSORPTION).orElse(0.0) + nt.getInternal());
Expand Down
Expand Up @@ -4,7 +4,6 @@
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.tags.objects.TextTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.utilities.AITaskHelper;
Expand All @@ -15,33 +14,33 @@
public class AddAITaskCommand extends AbstractCommand {

// <--[explanation]
// @Since 0.4.0
// @Since 0.5.5
// @Name AI Goal Types
// @Group Useful Lists
// @Description
// A list of all default AI goal types can be found here:
// <@link url https://jd.spongepowered.org/7.1.0-SNAPSHOT/org/spongepowered/api/entity/ai/GoalTypes.html>AI goal types list<@/link>
// These can be used with the addaitask and removeaitasks commands.
// These can be used with the <@link command addaitask>addaitask<@/link> and <@link command removeaitasks>removeaitasks<@/link> commands.
// Keep in mind that the goal type "normal" is available for most living entities,
// while the "target" goal type is mainly for combat related ones.
// -->

// <--[explanation]
// @Since 0.4.0
// @Since 0.5.5
// @Name AI Task Types
// @Group Useful Lists
// @Description
// The default AI task types are "attack_living", "avoid_entity", "find_target",
// "look_idle", "range", "run_around", "swim", "wander", and "watch_closest".
// These can be used with the addaitask and removeaitasks commands.
// These can be used with the <@link command addaitask>addaitask<@/link> and <@link command removeaitasks>removeaitasks<@/link> commands.
// -->

// <--[command]
// @Since 0.4.0
// @Since 0.5.5
// @Name addaitask
// @Arguments <entity> <task type>
// @Short adds an AI task to an entity's goal.
// @Updated 2018/01/27
// @Updated 2018/06/15
// @Group Entity
// @Minimum 2
// @Maximum 2
Expand Down Expand Up @@ -94,16 +93,16 @@ public int getMaximumArguments() {
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
TextTag type = TextTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
String type = entry.getArgumentObject(queue, 1).toString();
try {
Agent agent = (Agent) entityTag.getInternal();
HashMap<String, AbstractTagObject> properties = new HashMap<>();
for (String key : entry.namedArgs.keySet()) {
properties.put(key, entry.getNamedArgumentObject(queue, key));
}
AITaskHelper.giveAITask(queue, agent, type.toString(), properties);
AITaskHelper.giveAITask(queue, agent, type, properties);
if (queue.shouldShowGood()) {
queue.outGood("Added task of type '" + ColorSet.emphasis + type.debug()
queue.outGood("Added task of type '" + ColorSet.emphasis + type
+ ColorSet.good + "' to entity '" + ColorSet.emphasis + entityTag.debug()
+ ColorSet.good + "'!");
}
Expand Down
Expand Up @@ -12,11 +12,11 @@
public class BurnCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Since 0.5.5
// @Name burn
// @Arguments <entity> <duration>
// @Short sets an entity on fire.
// @Updated 2018/02/17
// @Updated 2018/06/15
// @Group Entity
// @Minimum 2
// @Maximum 2
Expand Down Expand Up @@ -54,23 +54,15 @@ public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
DurationTag dt = DurationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
int ticks = (int) dt.getInternal() * 20;
boolean set;
boolean set = false;
if (entry.namedArgs.containsKey("operation")) {
String operation = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "operation").toString());
switch (operation) {
case "add":
set = false;
break;
case "set":
set = true;
break;
default:
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
return;
if (operation.equals("set")) {
set = true;
}
else if (!operation.equals("add")) {
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
}
}
else {
set = false;
}
ent.getInternal().offer(Keys.FIRE_TICKS,
set ? ticks : ent.getInternal().get(Keys.FIRE_TICKS).orElse(0) + ticks);
Expand Down
Expand Up @@ -11,17 +11,17 @@
public class GlowCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Since 0.5.5
// @Name glow
// @Arguments <entity> <state>
// @Short manages the glowing outline of an entity.
// @Updated 2018/02/18
// @Updated 2018/06/15
// @Group Entity
// @Minimum 2
// @Maximum 2
// @Description
// Manages the glowing outline of an entity.
// TODO: Research how to add colored outlines.
// TODO: Allow setting glow color (might require scoreboard weirdness)
// @Example
// # This example makes the player glow.
// - glow <player> true
Expand Down
Expand Up @@ -57,61 +57,21 @@ 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));
boolean set;
boolean set = false;
if (entry.namedArgs.containsKey("operation")) {
String operation = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "operation").toString());
switch (operation) {
case "add":
set = false;
break;
case "set":
set = true;
break;
default:
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
return;
if (operation.equals("set")) {
set = true;
}
else if (!operation.equals("add")) {
queue.handleError(entry, "Invalid operation: '" + operation + "'!");
}
}
else {
set = false;
}
String type;
String type = "remaining";
if (entry.namedArgs.containsKey("type")) {
type = CoreUtilities.toLowerCase(entry.getNamedArgumentObject(queue, "type").toString());
switch (type) {
case "remaining":
if (set) {
if (amount.getInternal() < 0) {
queue.handleError(entry, "You can't set health to negative values!");
return;
}
ent.offer(Keys.HEALTH, Math.min(amount.getInternal(), ent.maxHealth().get()));
}
else {
ent.offer(Keys.HEALTH, ent.health().transform(
x -> Math.max(Math.min(x + amount.getInternal(), ent.maxHealth().get()), 0)).get());
}
break;
case "maximum":
if (set) {
if (amount.getInternal() < 0) {
queue.handleError(entry, "You can't set max health to negative values!");
return;
}
ent.offer(Keys.MAX_HEALTH, amount.getInternal());
}
else {
ent.offer(Keys.MAX_HEALTH, ent.maxHealth().transform(
x -> Math.max(x + amount.getInternal(), 0)).get());
}
break;
default:
queue.handleError(entry, "Invalid health type: '" + type + "'!");
return;
}
}
else {
type = "remaining";
if (type.equals("remaining")) {
if (set) {
if (amount.getInternal() < 0) {
queue.handleError(entry, "You can't set health to negative values!");
Expand All @@ -124,6 +84,23 @@ public void execute(CommandQueue queue, CommandEntry entry) {
x -> Math.max(Math.min(x + amount.getInternal(), ent.maxHealth().get()), 0)).get());
}
}
else if (type.equals("maximum")) {
if (set) {
if (amount.getInternal() < 0) {
queue.handleError(entry, "You can't set max health to negative values!");
return;
}
ent.offer(Keys.MAX_HEALTH, amount.getInternal());
}
else {
ent.offer(Keys.MAX_HEALTH, ent.maxHealth().transform(
x -> Math.max(x + amount.getInternal(), 0)).get());
}
}
else {
queue.handleError(entry, "Invalid health type: '" + type + "'!");
return;
}
if (queue.shouldShowGood()) {
queue.outGood(ColorSet.emphasis + (set ? "Setting" : "Increasing") + ColorSet.good + " the "
+ ColorSet.emphasis + type + ColorSet.good + " health of entity '" + ColorSet.emphasis
Expand Down

0 comments on commit 8ac76a7

Please sign in to comment.