Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Miller <[email protected]>
  • Loading branch information
sovdeeth and APickledWalrus authored Sep 21, 2024
1 parent dc82a4f commit 9aa4289
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/util/ColorRGB.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static ColorRGB fromRGB(int red, int green, int blue) {
* @param bukkit the bukkit color to replicate
* @return ColorRGB
*/
@Contract("_ -> new")
public static ColorRGB fromBukkitColor(org.bukkit.Color bukkit) {
return new ColorRGB(bukkit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
change = -change;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
if (height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
ticks = -ticks;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
if (delay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
change = -change;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
if (radius) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
ticks = -ticks;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
int value = (int) Math2.fit(0, display.getTeleportDuration() + ticks, 59);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
change = -change;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
float value = Math.max(0F, display.getViewRange() + change);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CondTextDisplayHasDropShadow extends PropertyCondition<Display> {

static {
Skript.registerCondition(CondTextDisplayHasDropShadow.class,
"[[the] text of] %displays% (has|have) [a] (drop|text) shadow",
"[[the] text of] %displays% (has|have) [a] (drop|text) shadow",
"%displays%'[s] text (has|have) [a] (drop|text) shadow",
"[[the] text of] %displays% (doesn't|does not|do not|don't) have [a] (drop|text) shadow",
"%displays%'[s] text (doesn't|does not|do not|don't) have [a] (drop|text) shadow"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
switch (mode) {
case REMOVE:
change = -change;
//$FALL-THROUGH$

case ADD:
for (Display display : displays) {
if (display instanceof TextDisplay textDisplay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
case REMOVE_ALL:
case REMOVE:
change = -change;
//$FALL-THROUGH$
case ADD:
for (Display display : displays) {
if (display instanceof TextDisplay textDisplay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public class ExprItemOfEntity extends SimplePropertyExpression<Entity, Slot> {


static {
register(ExprItemOfEntity.class, Slot.class, "[the] item [inside]", "entities");
register(ExprItemOfEntity.class, Slot.class, "item [inside]", "entities");
}

@Override
public @Nullable Slot convert(Entity entity) {
if (entity instanceof ItemFrame) {
return new ItemFrameSlot((ItemFrame) entity);
} else if (entity instanceof Item) {
return new DroppedItemSlot((Item) entity);
} else if (entity instanceof ThrowableProjectile) {
return new ThrowableProjectileSlot((ThrowableProjectile) entity);
} else if (entity instanceof ItemDisplay) {
return new DisplayEntitySlot((ItemDisplay) entity);
if (entity instanceof ItemFrame itemFrame) {
return new ItemFrameSlot(itemFrame);
} else if (entity instanceof Item item) {
return new DroppedItemSlot(item);
} else if (entity instanceof ThrowableProjectile throwableProjectile) {
return new ThrowableProjectileSlot(throwableProjectile);
} else if (entity instanceof ItemDisplay itemDisplay) {
return new DisplayEntitySlot(itemDisplay);
}
return null; // Other entities don't have associated items
}
Expand All @@ -58,7 +58,7 @@ public Class<? extends Slot> getReturnType() {

@Override
protected String getPropertyName() {
return "item of entity";
return "item inside";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ExprQuaternionAxisAngle extends SimplePropertyExpression<Quaternion
register(ExprQuaternionAxisAngle.class, Object.class, "rotation (angle|:axis)", "quaternions");
}

boolean isAxis;
private boolean isAxis;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
Expand All @@ -59,15 +59,13 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
switch (mode) {
return switch (mode) {
case ADD, SET, REMOVE -> {
if (Changer.ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, Quaternionf.class))
return CollectionUtils.array(isAxis ? Vector.class : Number.class);
return null;
}
default -> {
return null;
yield CollectionUtils.array(isAxis ? Vector.class : Number.class);
yield null;
}
default -> null;
}
}

Expand Down Expand Up @@ -103,5 +101,4 @@ protected String getPropertyName() {
return isAxis ? "axis" : "angle";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class ExprTextOf extends SimplePropertyExpression<Object, String> {

@Override
public @Nullable String convert(Object object) {
if (object instanceof TextDisplay)
return ((TextDisplay) object).getText();
if (object instanceof TextDisplay textDisplay)
return textDisplay.getText();
return null;
}

Expand All @@ -61,13 +61,13 @@ public class ExprTextOf extends SimplePropertyExpression<Object, String> {
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
String value = delta == null ? null : (String) delta[0];
for (Object object : getExpr().getArray(event)) {
if (!(object instanceof TextDisplay))
if (!(object instanceof TextDisplay textDisplay))
continue;
if (IS_RUNNING_PAPER && serializer != null && value != null) {
BaseComponent[] components = BungeeConverter.convert(ChatMessages.parseToArray(value));
((TextDisplay) object).text(serializer.deserialize(components));
textDisplay.text(serializer.deserialize(components));
} else {
((TextDisplay) object).setText(value);
textDisplay.setText(value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public NonMutatingQuaternionRotator(Axis axis, Vector3f vector, float angle) {
public Quaternionf rotate(Quaternionf input) {
return rotator.apply(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public NonMutatingVectorRotator(Axis axis, Vector vector, double angle) {
public Vector rotate(Vector input) {
return rotator.apply(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public QuaternionRotator(Axis axis, Vector3f vector, float angle) {
public Quaternionf rotate(Quaternionf input) {
return rotator.apply(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public VectorRotator(Axis axis, Vector vector, double angle) {
public Vector rotate(Vector input) {
return rotator.apply(input);
}

}
1 change: 0 additions & 1 deletion src/test/skript/tests/misc/displays.sk
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

test "spawn displays" when running minecraft "1.19.4":
spawn a text display at spawn of world "world":
set {_display} to event-display
Expand Down

0 comments on commit 9aa4289

Please sign in to comment.