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.
Add a basic equip command. WARNING: SPONGE HASN'T YET IMPLEMENTED EQU…
…IPMENT SOMEHOW
- Loading branch information
1 parent
45b4898
commit 0802dbd
Showing
7 changed files
with
157 additions
and
13 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
68 changes: 68 additions & 0 deletions
68
src/main/java/com/denizenscript/denizen2sponge/commands/entity/EquipCommand.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,68 @@ | ||
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.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.MapTag; | ||
import com.denizenscript.denizen2core.utilities.Tuple; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.ItemTag; | ||
import com.denizenscript.denizen2sponge.utilities.Equipment; | ||
import org.spongepowered.api.entity.living.Living; | ||
|
||
import java.util.Map; | ||
|
||
public class EquipCommand extends AbstractCommand { | ||
|
||
// <--[command] | ||
// @Name equip | ||
// @Arguments <entity> <equipment map> | ||
// @Short equips an entity according to a given equipment map. | ||
// @Updated 2017/03/03 | ||
// @Group Entities | ||
// @Minimum 2 | ||
// @Maximum 2 | ||
// @Description | ||
// Equips an entity according to a given equipment map. | ||
// Valid equipment keys: HEAD, CHESTPLATE, LEGGINGS, BOOTS, HAND, OFF_HAND | ||
// TODO: Saddle, Horse_Armor | ||
// TODO: Explain more! | ||
// @Example | ||
// # This example equips a player with a full set of iron armor. | ||
// - equip <player> head:iron_helmet|chestplate:iron_chestplate|boots:iron_boots|leggings:iron_leggings | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "equip"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<entity> <equipment map>"; | ||
} | ||
|
||
@Override | ||
public int getMinimumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getMaximumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public void execute(CommandQueue queue, CommandEntry entry) { | ||
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); | ||
MapTag map = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1)); | ||
for (Map.Entry<String, AbstractTagObject> mapentry : map.getInternal().entrySet()) { | ||
ItemTag itm = ItemTag.getFor(queue.error, mapentry.getValue()); | ||
Equipment.equippers.get(mapentry.getKey()).run(new Tuple<>((Living) ent.getInternal(), itm)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Equipped " + " on the entity!"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,17 @@ | |
import org.spongepowered.api.data.key.Key; | ||
import org.spongepowered.api.data.property.entity.EyeHeightProperty; | ||
import org.spongepowered.api.data.property.entity.EyeLocationProperty; | ||
import org.spongepowered.api.data.type.HandTypes; | ||
import org.spongepowered.api.entity.ArmorEquipable; | ||
import org.spongepowered.api.entity.Entity; | ||
import org.spongepowered.api.entity.Equipable; | ||
import org.spongepowered.api.entity.living.Living; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.item.ItemType; | ||
import org.spongepowered.api.item.ItemTypes; | ||
import org.spongepowered.api.item.inventory.ItemStack; | ||
import org.spongepowered.api.item.inventory.equipment.EquipmentType; | ||
import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; | ||
import org.spongepowered.api.world.World; | ||
|
||
import java.util.HashMap; | ||
|
@@ -146,6 +154,54 @@ public String friendlyName() { | |
return new NumberTag(ent.health().get() / ent.maxHealth().get()); | ||
}); | ||
// <--[tag] | ||
// @Name EntityTag.helmet | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the helmet currently worn by the entity. | ||
// --> | ||
handlers.put("helmet", (dat, obj) -> new ItemTag(((Equipable) ((EntityTag) obj).internal).getEquipped(EquipmentTypes.HEADWEAR).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
// @Name EntityTag.chestplate | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the chestplate currently worn by the entity. | ||
// --> | ||
handlers.put("chestplate", (dat, obj) -> new ItemTag(((Equipable) ((EntityTag) obj).internal).getEquipped(EquipmentTypes.CHESTPLATE).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
// @Name EntityTag.leggings | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the leggings currently worn by the entity. | ||
// --> | ||
handlers.put("leggings", (dat, obj) -> new ItemTag(((Equipable) ((EntityTag) obj).internal).getEquipped(EquipmentTypes.LEGGINGS).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
// @Name EntityTag.boots | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the boots currently worn by the entity. | ||
// --> | ||
handlers.put("boots", (dat, obj) -> new ItemTag(((Equipable) ((EntityTag) obj).internal).getEquipped(EquipmentTypes.BOOTS).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
// @Name EntityTag.held_item | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the item currently held the entity in its main hand. | ||
// --> | ||
handlers.put("held_item", (dat, obj) -> new ItemTag(((ArmorEquipable) ((EntityTag) obj).internal).getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
// @Name EntityTag.held_item_offhand | ||
// @Updated 2017/03/03 | ||
// @Group Equipment | ||
// @ReturnType ItemTag | ||
// @Returns the item currently held the entity in its off hand. | ||
// --> | ||
handlers.put("held_item_offhand", (dat, obj) -> new ItemTag(((ArmorEquipable) ((EntityTag) obj).internal).getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.of(ItemTypes.NONE, 1)))); | ||
// <--[tag] | ||
This comment has been minimized.
Sorry, something went wrong.
Morphan1
Contributor
|
||
// @Name EntityTag.data | ||
// @Updated 2016/08/28 | ||
// @Group Current Information | ||
|
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/denizenscript/denizen2sponge/utilities/Equipment.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,29 @@ | ||
package com.denizenscript.denizen2sponge.utilities; | ||
|
||
import com.denizenscript.denizen2core.utilities.Action; | ||
import com.denizenscript.denizen2core.utilities.Tuple; | ||
import com.denizenscript.denizen2sponge.tags.objects.ItemTag; | ||
import org.spongepowered.api.data.type.HandTypes; | ||
import org.spongepowered.api.entity.ArmorEquipable; | ||
import org.spongepowered.api.entity.Equipable; | ||
import org.spongepowered.api.entity.living.Living; | ||
import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Helper class for equipping an entity. | ||
*/ | ||
public class Equipment { | ||
|
||
public static final HashMap<String, Action<Tuple<Living, ItemTag>>> equippers = new HashMap<>(); | ||
|
||
static { | ||
equippers.put("head", (tuple) -> ((Equipable) tuple.one).equip(EquipmentTypes.HEADWEAR, tuple.two.getInternal())); | ||
equippers.put("chestplate", (tuple) -> ((Equipable) tuple.one).equip(EquipmentTypes.CHESTPLATE, tuple.two.getInternal())); | ||
equippers.put("leggings", (tuple) -> ((Equipable) tuple.one).equip(EquipmentTypes.LEGGINGS, tuple.two.getInternal())); | ||
equippers.put("boots", (tuple) -> ((Equipable) tuple.one).equip(EquipmentTypes.BOOTS, tuple.two.getInternal())); | ||
equippers.put("hand", (tuple) -> ((ArmorEquipable) tuple.one).setItemInHand(HandTypes.MAIN_HAND, tuple.two.getInternal())); | ||
equippers.put("offhand", (tuple) -> ((ArmorEquipable) tuple.one).setItemInHand(HandTypes.OFF_HAND, tuple.two.getInternal())); | ||
} | ||
} |
Lowercase the key pls