Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 21, 2022
1 parent 1a1a160 commit fb11979
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 61 deletions.
Expand Up @@ -30,7 +30,7 @@ public class PlayerElytraBoostScriptEvent extends BukkitScriptEvent implements L
// @Switch with:<item> to only process the event if the firework item used matches the specified item.
// @Switch elytra:<item> to only process the event if the elytra used matches the specified item.
//
// @Triggers when a player boosts their elytra with a firework.
// @Triggers when a player boosts their elytra with a firework rocket while gliding.
//
// @Context
// <context.item> returns the firework item used to boost.
Expand Down
Expand Up @@ -84,7 +84,7 @@ public void adjust(Mechanism mechanism) {
// Firework boosts the player with the specified firework rocket.
// The player must be gliding.
// -->
if (mechanism.matches("firework_boost") && mechanism.hasValue()) {
if (mechanism.matches("firework_boost") && mechanism.requireObject(ItemTag.class)) {
if (!player.getPlayerEntity().isGliding()) {
mechanism.echoError("Player must be gliding to use firework_boost.");
return;
Expand Down
Expand Up @@ -27,9 +27,9 @@ public static boolean describes(ObjectTag material) {
return data instanceof Slab
|| data instanceof TechnicalPiston
|| data instanceof Campfire
|| data instanceof Scaffolding
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && (data instanceof PointedDripstone
|| data instanceof CaveVinesPlant))
|| data instanceof Scaffolding;
|| data instanceof CaveVinesPlant));
}

public static MaterialBlockType getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -131,15 +131,15 @@ else if (isCampfire()) {
else if (isPistonHead()) {
return getPistonHead().getType().name();
}
else if (isScaffolding()) {
return getScaffolding().isBottom() ? "BOTTOM" : "NORMAL";
}
else if (isDripstone()) {
return ((PointedDripstone) material.getModernData()).getThickness().name(); // TODO: 1.17
}
else if (isCaveVines()) {
return ((CaveVinesPlant) material.getModernData()).isBerries() ? "BERRIES" : "NORMAL"; // TODO: 1.17
}
else if (isScaffolding()) {
return getScaffolding().isBottom() ? "BOTTOM" : "NORMAL";
}
return null; // Unreachable.
}

Expand Down Expand Up @@ -176,15 +176,15 @@ else if (isCampfire()) {
else if (isPistonHead() && mechanism.requireEnum(false, TechnicalPiston.Type.values())) {
getPistonHead().setType(TechnicalPiston.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isScaffolding()) {
getScaffolding().setBottom(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "bottom"));
}
else if (isDripstone()) {
MultiVersionHelper1_17.materialBlockTypeRunMech(mechanism, this);
}
else if (isCaveVines()) {
((CaveVinesPlant) material.getModernData()).setBerries(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "berries")); // TODO: 1.17
}
else if (isScaffolding()) {
getScaffolding().setBottom(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "bottom"));
}
}
}
}
Expand Up @@ -9,8 +9,6 @@
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.block.data.type.BrewingStand;

import java.util.Set;

public class MaterialBrewingStand implements Property {

public static boolean describes(ObjectTag material) {
Expand Down Expand Up @@ -39,13 +37,15 @@ private MaterialBrewingStand(MaterialTag _material) {
MaterialTag material;

public static void registerTags() {

// <--[tag]
// @attribute <MaterialTag.bottles>
// @returns ListTag(ElementTag)
// @returns ListTag
// @mechanism MaterialTag.bottles
// @group properties
// @description
// Returns a list of booleans that represent whether a slot in a brewing stand has a bottle.
// Under current implementation this always returns exactly 3 values, like "true|false|true".
// -->
PropertyParser.<MaterialBrewingStand, ListTag>registerStaticTag(ListTag.class, "bottles", (attribute, material) -> {
return material.getBottleBooleans();
Expand All @@ -60,32 +60,14 @@ public int getMaxBottles() {
return getBrewingStand().getMaximumBottles();
}

public Set<Integer> getBottles() {
return getBrewingStand().getBottles();
}

public ListTag getBottleBooleans() {
ListTag result = new ListTag();
for (int i = 0; i < getMaxBottles(); i++) {
result.addObject(new ElementTag(hasBottle(i)));
result.addObject(new ElementTag(getBrewingStand().hasBottle(i)));
}
return result;
}

public boolean hasBottle(int index) {
return getBrewingStand().hasBottle(index);
}

public void setBottle(int index, boolean hasBottle) {
getBrewingStand().setBottle(index, hasBottle);
}

public void resetBottles() {
for (int i : getBottles()) {
setBottle(i, false);
}
}

@Override
public String getPropertyString() {
return getBottleBooleans().identify();
Expand All @@ -104,7 +86,7 @@ public void adjust(Mechanism mechanism) {
// @name bottles
// @input ListTag
// @description
// Sets the bottles in a brewing stand. Input is a list of booleans representing whether that slot has a bottle, specifying no value counts as false.
// Sets the bottles in a brewing stand. Input is a list of booleans representing whether that slot has a bottle.
// @tags
// <MaterialTag.bottles>
// -->
Expand All @@ -114,9 +96,8 @@ public void adjust(Mechanism mechanism) {
mechanism.echoError("Too many values specified! Brewing stand has a maximum of " + getMaxBottles() + " bottles.");
return;
}
resetBottles();
for (int i = 0; i < bottles.size(); i++) {
setBottle(i, new ElementTag(bottles.get(i)).asBoolean());
getBrewingStand().setBottle(i, new ElementTag(bottles.get(i)).asBoolean());
}
}
}
Expand Down
Expand Up @@ -33,8 +33,8 @@ public static boolean describes(ObjectTag material) {
|| data instanceof Orientable
|| data instanceof Rotatable
|| data instanceof Rail
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof PointedDripstone)
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16) && data instanceof Jigsaw);
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16) && data instanceof Jigsaw)
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof PointedDripstone);
}

public static MaterialDirectional getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -118,6 +118,7 @@ else if (material.isJigsaw()) {
// @group properties
// @description
// Returns the current facing direction for a directional material (like a door or a bed).
// This includes materials that Spigot classifies as "directional", "orientable", or "rotatable", as well as rails, dripstone, and jigsaw blocks.
// Output is a direction name like "NORTH", or an axis like "X", or a rail direction like "ASCENDING_NORTH".
// -->
PropertyParser.<MaterialDirectional, ElementTag>registerStaticTag(ElementTag.class, "direction", (attribute, material) -> {
Expand Down Expand Up @@ -271,10 +272,10 @@ public void setFacing(BlockFace face) {
if (isOrientable()) {
Axis axis;
Vector vec = face.getDirection();
if (vec.getX() >= 0.5) {
if (Math.abs(vec.getX()) >= 0.5) {
axis = Axis.X;
}
else if (vec.getY() >= 0.5) {
else if (Math.abs(vec.getY()) >= 0.5) {
axis = Axis.Y;
}
else {
Expand Down
Expand Up @@ -46,22 +46,14 @@ public static void registerTags() {
// Returns the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold.
// -->
PropertyParser.<MaterialDistance, ElementTag>registerStaticTag(ElementTag.class, "distance", (attribute, material) -> {
return new ElementTag(material.getDistance());
return new ElementTag(material.getScaffolding().getDistance());
});
}

public Scaffolding getScaffolding() {
return (Scaffolding) material.getModernData();
}

public int getDistance() {
return getScaffolding().getDistance();
}

public int getMaxDistance() {
return getScaffolding().getMaximumDistance();
}

@Override
public String getPropertyString() {
return String.valueOf(getScaffolding().getDistance());
Expand All @@ -86,11 +78,11 @@ public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("distance") && mechanism.requireInteger()) {
int distance = mechanism.getValue().asInt();
if (distance >= 0 && distance <= getMaxDistance()) {
if (distance >= 0 && distance <= getScaffolding().getMaximumDistance()) {
getScaffolding().setDistance(distance);
}
else {
mechanism.echoError("Distance must be between 0 and " + getMaxDistance());
mechanism.echoError("Distance must be between 0 and " + getScaffolding().getMaximumDistance());
}
}
}
Expand Down
Expand Up @@ -28,10 +28,10 @@ public static boolean describes(ObjectTag material) {
|| data instanceof PistonHead
|| data instanceof BubbleColumn
|| data instanceof StructureBlock
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && (data instanceof SculkSensor
|| data instanceof BigDripleaf))
|| data instanceof DaylightDetector
|| data instanceof CommandBlock;
|| data instanceof CommandBlock
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && (data instanceof SculkSensor
|| data instanceof BigDripleaf));
}

public static MaterialMode getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -154,19 +154,19 @@ else if (isPistonHead()) {
else if (isStructureBlock()) {
return getStructureBlock().getMode().name();
}
else if (isSculkSensor()) {
return ((SculkSensor) material.getModernData()).getPhase().name(); // TODO: 1.17
}
else if (isDaylightDetector()) {
return getDaylightDetector().isInverted() ? "INVERTED" : "NORMAL";
}
else if (isCommandBlock()) {
return getCommandBlock().isConditional() ? "CONDITIONAL" : "NORMAL";
}
else if (isSculkSensor()) {
return ((SculkSensor) material.getModernData()).getPhase().name(); // TODO: 1.17
}
else if (isBigDripleaf()) {
return ((BigDripleaf) material.getModernData()).getTilt().name(); // TODO: 1.17
}
return null; //Unreachable
return null; // Unreachable
}

@Override
Expand Down Expand Up @@ -207,15 +207,15 @@ else if (isPistonHead()) {
else if (isStructureBlock() && mechanism.requireEnum(false, StructureBlock.Mode.values())) {
getStructureBlock().setMode(StructureBlock.Mode.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isSculkSensor() || isBigDripleaf()) {
MultiVersionHelper1_17.materialModeRunMech(mechanism, this);
}
else if (isDaylightDetector()) {
getDaylightDetector().setInverted(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "inverted"));
}
else if (isCommandBlock()) {
getCommandBlock().setConditional(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "conditional"));
}
else if (isSculkSensor() || isBigDripleaf()) {
MultiVersionHelper1_17.materialModeRunMech(mechanism, this);
}
}
}
}
Expand Up @@ -70,7 +70,6 @@ public NPCCommandHandler(Citizens citizens) {
@Requirements(selected = true, ownership = true)
public void pushable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PushableTrait trait = npc.getOrAddTrait(PushableTrait.class);

if (args.hasFlag('r') && !args.hasFlag('t')) {
trait.setReturnable(!trait.isReturnable());
Messaging.sendInfo(sender, npc.getName() + (trait.isReturnable() ? " will " : " will not ") + "return when being pushed"
Expand Down

0 comments on commit fb11979

Please sign in to comment.