From 27ba1b642eb82b2d71320c4126aaba36628677f3 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:03:24 -0400 Subject: [PATCH 01/13] Starter Commit --- .../skript/classes/data/BukkitClasses.java | 7 ++ .../classes/data/BukkitEventValues.java | 35 ++++++- .../ch/njol/skript/events/SimpleEvents.java | 42 +++------ .../skript/expressions/ExprChangeReason.java | 39 ++++++++ .../expressions/ExprExperienceCooldown.java | 94 +++++++++++++++++++ src/main/resources/lang/default.lang | 6 ++ 6 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprChangeReason.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index ba0a66a1f41..a70514d36e3 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -70,6 +70,7 @@ import org.bukkit.event.player.PlayerQuitEvent.QuitReason; import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; import org.bukkit.inventory.BlockInventoryHolder; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; @@ -1526,6 +1527,12 @@ public String toVariableNameString(EnchantmentOffer eo) { .name("Transform Reason") .description("Represents a transform reason of an entity transform event.") .since("2.8.0")); + + Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "changereason", "change reasons") + .user("[experience|exp|xp] ?change (reason|cause)s?") + .name("Experience Cooldown Change Reason") + .description("Represents a change reason of an experience cooldown change event.") + .since("INSERT VERSION")); } } diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index e430dd472f6..585aeee4f7c 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -18,6 +18,9 @@ */ package ch.njol.skript.classes.data; +import java.time.Duration; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalUnit; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -75,6 +78,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Vehicle; +import org.bukkit.event.Event; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockDamageEvent; @@ -152,6 +156,8 @@ import org.bukkit.event.player.PlayerPickupArrowEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; import org.bukkit.event.player.PlayerQuitEvent.QuitReason; import org.bukkit.event.player.PlayerRiptideEvent; import org.bukkit.event.player.PlayerShearEntityEvent; @@ -181,7 +187,7 @@ import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * @author Peter Güttinger @@ -1935,5 +1941,32 @@ public RegainReason get(EntityRegainHealthEvent event) { return event.getRegainReason(); } }, EventValues.TIME_NOW); + + // PlayerExpCooldownChangeEvent + EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Player.class, new Getter() { + @Override + public @Nullable Player get(PlayerExpCooldownChangeEvent event) { + return event.getPlayer(); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, ChangeReason.class, new Getter() { + @Override + public @Nullable ChangeReason get(PlayerExpCooldownChangeEvent event) { + return event.getReason(); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Timespan.class, new Getter() { + @Override + public @Nullable Timespan get(PlayerExpCooldownChangeEvent event) { + return new Timespan(Timespan.TimePeriod.TICK, event.getNewCooldown()); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Timespan.class, new Getter() { + @Override + public @Nullable Timespan get(PlayerExpCooldownChangeEvent event) { + return new Timespan(Timespan.TimePeriod.TICK, event.getPlayer().getExpCooldown()); + } + }, EventValues.TIME_PAST); + } } diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 36153ae75cb..bd516c0058f 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -77,33 +77,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.inventory.PrepareAnvilEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerItemBreakEvent; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.event.player.PlayerItemHeldEvent; -import org.bukkit.event.player.PlayerItemMendEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerLocaleChangeEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerPickupArrowEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerRiptideEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerToggleFlightEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.player.*; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; @@ -820,5 +794,19 @@ public class SimpleEvents { .since("2.9.0") .requiredPlugins("Paper"); } + + Skript.registerEvent("Player Experience Cooldown Event", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "player (experience|exp|xp) cooldown change") + .description( + "Called when a players experience cooldown changes.", + "
    ", + "
  • event-player : The player whose cooldown was changed.
  • ", + "
  • event-change reason : The reason it was changed.
  • ", + "
  • event-timespan : The new timespan for the player.
  • ", + "
  • past event-timespan : The previous timespan, before being changed.
  • ", + "
" + ) + .examples("on player experience cooldown change:") + .since("INSERT VERSION"); + } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java new file mode 100644 index 00000000000..113b27b8e18 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java @@ -0,0 +1,39 @@ +package ch.njol.skript.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.EventValueExpression; +import org.bukkit.event.Event; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Experience Change Reason") +@Description({ + "The experience change reason within in an" + + "experience cooldown change event." +}) +@Examples({ + "on player experience cooldown change:", + "\tchange reason is plugin", + "\tchange reason is orb pickup" +}) +@Since("INSERT VERSION") +public class ExprChangeReason extends EventValueExpression { + + static { + register(ExprChangeReason.class, ChangeReason.class, "[the] [experience|exp|xp] change (reason|cause|type)"); + } + + public ExprChangeReason() { + super(ChangeReason.class); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "change reason"; + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java new file mode 100644 index 00000000000..bebb7d99757 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -0,0 +1,94 @@ +package ch.njol.skript.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.util.Timespan; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Experience Cooldown") +@Description("The experience cooldown of a player") +@Examples({ + "send experience cooldown of player", + "set experience cooldown of player to 1 hour", + "if experience cooldown of player >= 10 minutes:", + "\tclear experience cooldown of player" +}) +@Since("INSERT VERSION") +public class ExprExperienceCooldown extends SimplePropertyExpression { + + static { + register(ExprExperienceCooldown.class, Timespan.class, "(experience|exp|xp) cooldown", "players"); + } + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + setExpr((Expression) exprs[0]); + return true; + } + + + @Override + public @Nullable Timespan convert(Player player) { + return new Timespan(Timespan.TimePeriod.TICK, player.getExpCooldown()); + } + + @Override + public Class @Nullable [] acceptChange(ChangeMode mode) { + return CollectionUtils.array(Timespan.class); + } + + @Override + public @Nullable void change(Event event, Object[] delta, ChangeMode mode) { + int providedTime = 0; + if (delta[0] != null && delta[0] instanceof Timespan span) { + providedTime = (int) span.get(Timespan.TimePeriod.TICK); + } + switch (mode) { + case ADD: + for (Player player : getExpr().getArray(event)) { + player.setExpCooldown(player.getExpCooldown() + providedTime); + } + return; + case REMOVE: + for (Player player : getExpr().getArray(event)) { + player.setExpCooldown(Math.max(player.getExpCooldown() + providedTime, 0)); + } + return; + case SET: + for (Player player : getExpr().getArray(event)) { + player.setExpCooldown(providedTime); + } + return; + case DELETE, RESET: + for (Player player : getExpr().getArray(event)) { + player.setExpCooldown(0); + } + return; + default: + return; + } + } + + @Override + protected String getPropertyName() { + return "experience cooldown"; + } + + @Override + public Class getReturnType() { + return Timespan.class; + } + +} diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index fec454c2ac5..83685e1de22 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -2275,6 +2275,11 @@ transform reasons: unknown: unknown infection: infection, villager infection +# -- Change Reasons -- +change reasons: + plugin: plugin + pickup_orb: orb, orb pickup, pickup, pickup orb + # -- Boolean -- boolean: true: @@ -2354,6 +2359,7 @@ types: quitreason: quit reason¦s @a inventoryclosereason: inventory close reason¦s @an transformreason: transform reason¦s @a + changereason: change reason¦s @a # Skript weathertype: weather type¦s @a From b3bcd2504c06773506428f8f56b269d569c079bd Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 13 Sep 2024 19:14:38 -0400 Subject: [PATCH 02/13] Changes + Tests --- .../ch/njol/skript/events/SimpleEvents.java | 15 +++++----- .../skript/expressions/ExprChangeReason.java | 2 +- .../expressions/ExprExperienceCooldown.java | 26 ++++++++--------- src/main/resources/lang/default.lang | 2 +- .../EvtExperienceCooldownChangeTest.java | 28 +++++++++++++++++++ .../junit/EvtExperienceCooldownChangeTest.sk | 16 +++++++++++ 6 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java create mode 100644 src/test/skript/junit/EvtExperienceCooldownChangeTest.sk diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index bd516c0058f..9c8f6494011 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -798,14 +798,15 @@ public class SimpleEvents { Skript.registerEvent("Player Experience Cooldown Event", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "player (experience|exp|xp) cooldown change") .description( "Called when a players experience cooldown changes.", - "
    ", - "
  • event-player : The player whose cooldown was changed.
  • ", - "
  • event-change reason : The reason it was changed.
  • ", - "
  • event-timespan : The new timespan for the player.
  • ", - "
  • past event-timespan : The previous timespan, before being changed.
  • ", - "
" + "Experience cooldown is how long until a player can pickup another orb of experience" + ) + .examples( + "on player experience cooldown change:", + "\tevent-player", + "\tevent-change reason", + "\tevent-timespan", + "\tpast event-timespan" ) - .examples("on player experience cooldown change:") .since("INSERT VERSION"); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java index 113b27b8e18..c3418c77c33 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java @@ -8,7 +8,7 @@ import ch.njol.skript.expressions.base.EventValueExpression; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Experience Change Reason") @Description({ diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index bebb7d99757..85181acb518 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -1,6 +1,5 @@ package ch.njol.skript.expressions; -import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -28,7 +27,7 @@ public class ExprExperienceCooldown extends SimplePropertyExpression { static { - register(ExprExperienceCooldown.class, Timespan.class, "(experience|exp|xp) cooldown", "players"); + register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|exp|xp) cooldown", "players"); } @Override @@ -52,32 +51,31 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public @Nullable void change(Event event, Object[] delta, ChangeMode mode) { int providedTime = 0; - if (delta[0] != null && delta[0] instanceof Timespan span) { - providedTime = (int) span.get(Timespan.TimePeriod.TICK); + if (delta[0] != null && delta[0] instanceof Timespan timeSpan) { + providedTime = (int) timeSpan.get(Timespan.TimePeriod.TICK); } switch (mode) { - case ADD: + case ADD -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(player.getExpCooldown() + providedTime); } - return; - case REMOVE: + } + case REMOVE -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(Math.max(player.getExpCooldown() + providedTime, 0)); } - return; - case SET: + } + case SET -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(providedTime); } - return; - case DELETE, RESET: + } + case DELETE, RESET -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(0); } - return; - default: - return; + } + default -> {} } } diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index 83685e1de22..d37cd6ac51f 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -2278,7 +2278,7 @@ transform reasons: # -- Change Reasons -- change reasons: plugin: plugin - pickup_orb: orb, orb pickup, pickup, pickup orb + pickup_orb: orb pickup, pickup orb # -- Boolean -- boolean: diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java new file mode 100644 index 00000000000..14b61fe9972 --- /dev/null +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java @@ -0,0 +1,28 @@ +package org.skriptlang.skript.test.tests.syntaxes.events; + +import ch.njol.skript.test.runner.SkriptJUnitTest; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +public class EvtExperienceCooldownChangeTest extends SkriptJUnitTest { + + private Player easyMockPlayer; + + @Before + public void setUp() { + easyMockPlayer = EasyMock.niceMock(Player.class); + } + + @Test + public void testEvent() { + PlayerExpCooldownChangeEvent event = new PlayerExpCooldownChangeEvent(easyMockPlayer, 200, ChangeReason.PLUGIN); + Bukkit.getPluginManager().callEvent(event); + } + + +} diff --git a/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk new file mode 100644 index 00000000000..c211d4c7ca9 --- /dev/null +++ b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk @@ -0,0 +1,16 @@ +on load: + set {_test::1} to "got player" + set {_test::2} to "got reason" + set {_test::3} to "got new cooldown" + + ensure junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" completes {_test::*} + +on player experience cooldown change: + junit test is "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + if event-player is set: + complete objective "got player" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + if change reason is plugin: + complete objective "got reason" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + if event-timespan is set: + complete objective "got new cooldown" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + From 14f396c2fba620f6fccf3fa8c12303222d5f7324 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:03:40 -0400 Subject: [PATCH 03/13] Requested Changes --- .../skript/classes/data/BukkitClasses.java | 4 ++-- .../ch/njol/skript/events/SimpleEvents.java | 14 +++++++------- ...n.java => ExprExperienceChangeReason.java} | 15 ++++++++------- .../expressions/ExprExperienceCooldown.java | 19 +++++++++++-------- src/main/resources/lang/default.lang | 4 ++-- .../EvtExperienceCooldownChangeTest.java | 3 +-- .../junit/EvtExperienceCooldownChangeTest.sk | 14 +++++++------- 7 files changed, 38 insertions(+), 35 deletions(-) rename src/main/java/ch/njol/skript/expressions/{ExprChangeReason.java => ExprExperienceChangeReason.java} (65%) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index a70514d36e3..b856a49b9e9 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1528,8 +1528,8 @@ public String toVariableNameString(EnchantmentOffer eo) { .description("Represents a transform reason of an entity transform event.") .since("2.8.0")); - Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "changereason", "change reasons") - .user("[experience|exp|xp] ?change (reason|cause)s?") + Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencechangereason", "experience change reasons") + .user("(experience|[e]xp) ?change (reason|cause)s?") .name("Experience Cooldown Change Reason") .description("Represents a change reason of an experience cooldown change event.") .since("INSERT VERSION")); diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 9c8f6494011..16569f4efa5 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -795,17 +795,17 @@ public class SimpleEvents { .requiredPlugins("Paper"); } - Skript.registerEvent("Player Experience Cooldown Event", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "player (experience|exp|xp) cooldown change") + Skript.registerEvent("Experience Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "player (experience|[e]xp) cooldown change") .description( - "Called when a players experience cooldown changes.", - "Experience cooldown is how long until a player can pickup another orb of experience" + "Called when a player's experience cooldown changes.", + "Experience cooldown is how long until a player can pick up another orb of experience." ) .examples( "on player experience cooldown change:", - "\tevent-player", - "\tevent-change reason", - "\tevent-timespan", - "\tpast event-timespan" + "\tbroadcast event-player", + "\tbroadcast event-timespan", + "\tbroadcast past event-timespan", + "\tbroadcast xp change reason" ) .since("INSERT VERSION"); diff --git a/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java similarity index 65% rename from src/main/java/ch/njol/skript/expressions/ExprChangeReason.java rename to src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java index c3418c77c33..c3e99da3511 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChangeReason.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java @@ -1,6 +1,5 @@ package ch.njol.skript.expressions; -import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -17,23 +16,25 @@ }) @Examples({ "on player experience cooldown change:", - "\tchange reason is plugin", - "\tchange reason is orb pickup" + "\tif xp change reason is plugin:", + "\t\t#Changed by a plugin", + "\telse if xp change reason is orb pickup:", + "\t\t#Changed by picking up xp orb" }) @Since("INSERT VERSION") -public class ExprChangeReason extends EventValueExpression { +public class ExprExperienceChangeReason extends EventValueExpression { static { - register(ExprChangeReason.class, ChangeReason.class, "[the] [experience|exp|xp] change (reason|cause|type)"); + register(ExprExperienceChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) change (reason|cause|type)"); } - public ExprChangeReason() { + public ExprExperienceChangeReason() { super(ChangeReason.class); } @Override public String toString(@Nullable Event event, boolean debug) { - return "change reason"; + return "experience change reason"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index 85181acb518..5986a2d66f3 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -16,7 +16,10 @@ import org.jetbrains.annotations.Nullable; @Name("Experience Cooldown") -@Description("The experience cooldown of a player") +@Description({ + "The experience cooldown of a player.", + "Experience cooldown is how long until a player can pick up another orb of experience." +}) @Examples({ "send experience cooldown of player", "set experience cooldown of player to 1 hour", @@ -27,13 +30,13 @@ public class ExprExperienceCooldown extends SimplePropertyExpression { static { - register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|exp|xp) cooldown", "players"); + register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|[e]xp) cooldown", "players"); } @Override @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - setExpr((Expression) exprs[0]); + setExpr((Expression) exprs[0]); return true; } @@ -49,11 +52,11 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - public @Nullable void change(Event event, Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { int providedTime = 0; - if (delta[0] != null && delta[0] instanceof Timespan timeSpan) { + if (delta[0] != null && delta[0] instanceof Timespan timeSpan) providedTime = (int) timeSpan.get(Timespan.TimePeriod.TICK); - } + switch (mode) { case ADD -> { for (Player player : getExpr().getArray(event)) { @@ -62,7 +65,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } case REMOVE -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(Math.max(player.getExpCooldown() + providedTime, 0)); + player.setExpCooldown(Math.max(player.getExpCooldown() - providedTime, 0)); } } case SET -> { @@ -70,7 +73,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye player.setExpCooldown(providedTime); } } - case DELETE, RESET -> { + case DELETE, RESET, REMOVE_ALL -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(0); } diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index d37cd6ac51f..787694c199c 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -2276,7 +2276,7 @@ transform reasons: infection: infection, villager infection # -- Change Reasons -- -change reasons: +experience change reasons: plugin: plugin pickup_orb: orb pickup, pickup orb @@ -2359,7 +2359,7 @@ types: quitreason: quit reason¦s @a inventoryclosereason: inventory close reason¦s @an transformreason: transform reason¦s @a - changereason: change reason¦s @a + experiencechangereason: experience change reason¦s @a # Skript weathertype: weather type¦s @a diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java index 14b61fe9972..b63951a862e 100644 --- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java @@ -24,5 +24,4 @@ public void testEvent() { Bukkit.getPluginManager().callEvent(event); } - -} +} \ No newline at end of file diff --git a/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk index c211d4c7ca9..dd2ec3032f0 100644 --- a/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk +++ b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk @@ -1,16 +1,16 @@ on load: set {_test::1} to "got player" - set {_test::2} to "got reason" + set {_test::2} to "change reason is plugin" set {_test::3} to "got new cooldown" ensure junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" completes {_test::*} on player experience cooldown change: - junit test is "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + junit test is {_test} if event-player is set: - complete objective "got player" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" - if change reason is plugin: - complete objective "got reason" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" + complete objective "got player" for junit test {_test} + if xp change reason is plugin: + complete objective "change reason is plugin" for junit test {_test} if event-timespan is set: - complete objective "got new cooldown" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest" - + complete objective "got new cooldown" for junit test {_test} From bdb2c8224222c1850a0df3baed61b2d2238e6efb Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 15 Sep 2024 03:04:48 -0400 Subject: [PATCH 04/13] Requested Changes --- .../java/ch/njol/skript/classes/data/BukkitClasses.java | 2 +- .../njol/skript/expressions/ExprExperienceCooldown.java | 9 ++++++--- ...ason.java => ExprExperienceCooldownChangeReason.java} | 8 ++++---- src/main/resources/lang/default.lang | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) rename src/main/java/ch/njol/skript/expressions/{ExprExperienceChangeReason.java => ExprExperienceCooldownChangeReason.java} (76%) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index b856a49b9e9..3b73d4b4420 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1528,7 +1528,7 @@ public String toVariableNameString(EnchantmentOffer eo) { .description("Represents a transform reason of an entity transform event.") .since("2.8.0")); - Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencechangereason", "experience change reasons") + Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencecooldownchangereason", "experience cooldown change reasons") .user("(experience|[e]xp) ?change (reason|cause)s?") .name("Experience Cooldown Change Reason") .description("Represents a change reason of an experience cooldown change event.") diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index 5986a2d66f3..ab81d10c325 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -48,14 +48,17 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public Class @Nullable [] acceptChange(ChangeMode mode) { + switch (mode) { + case REMOVE_ALL, DELETE, REMOVE -> {return null;} + } return CollectionUtils.array(Timespan.class); } @Override public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { int providedTime = 0; - if (delta[0] != null && delta[0] instanceof Timespan timeSpan) - providedTime = (int) timeSpan.get(Timespan.TimePeriod.TICK); + if (delta[0] != null) + providedTime = (int) ((Timespan) delta[0]).get(Timespan.TimePeriod.TICK); switch (mode) { case ADD -> { @@ -73,7 +76,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { player.setExpCooldown(providedTime); } } - case DELETE, RESET, REMOVE_ALL -> { + case RESET -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(0); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java similarity index 76% rename from src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java rename to src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java index c3e99da3511..16f087c812a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceChangeReason.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java @@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason; import org.jetbrains.annotations.Nullable; -@Name("Experience Change Reason") +@Name("Experience Cooldown Change Reason") @Description({ "The experience change reason within in an" + "experience cooldown change event." @@ -22,13 +22,13 @@ "\t\t#Changed by picking up xp orb" }) @Since("INSERT VERSION") -public class ExprExperienceChangeReason extends EventValueExpression { +public class ExprExperienceCooldownChangeReason extends EventValueExpression { static { - register(ExprExperienceChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) change (reason|cause|type)"); + register(ExprExperienceCooldownChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) change (reason|cause|type)"); } - public ExprExperienceChangeReason() { + public ExprExperienceCooldownChangeReason() { super(ChangeReason.class); } diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index 787694c199c..b91f8df4e57 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -2276,7 +2276,7 @@ transform reasons: infection: infection, villager infection # -- Change Reasons -- -experience change reasons: +experience cooldown change reasons: plugin: plugin pickup_orb: orb pickup, pickup orb @@ -2359,7 +2359,7 @@ types: quitreason: quit reason¦s @a inventoryclosereason: inventory close reason¦s @an transformreason: transform reason¦s @a - experiencechangereason: experience change reason¦s @a + experiencecooldownchangereason: experience cooldown change reason¦s @a # Skript weathertype: weather type¦s @a From fd34dc40124064e6902ec131db35ed202860254b Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Mon, 16 Sep 2024 15:25:25 -0400 Subject: [PATCH 05/13] Requested Changes --- .../ch/njol/skript/expressions/ExprExperienceCooldown.java | 4 ++-- .../syntaxes/events/EvtExperienceCooldownChangeTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index ab81d10c325..3c9f53bdd01 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -49,9 +49,9 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public Class @Nullable [] acceptChange(ChangeMode mode) { switch (mode) { - case REMOVE_ALL, DELETE, REMOVE -> {return null;} + case ADD, SET, RESET -> {return CollectionUtils.array(Timespan.class);} } - return CollectionUtils.array(Timespan.class); + return null; } @Override diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java index b63951a862e..6f743af8d29 100644 --- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtExperienceCooldownChangeTest.java @@ -24,4 +24,4 @@ public void testEvent() { Bukkit.getPluginManager().callEvent(event); } -} \ No newline at end of file +} From 8eb4004c4f8ac84d6597d1959c2b0f13391cbe0c Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:42:33 -0400 Subject: [PATCH 06/13] Requested Change --- .../njol/skript/expressions/ExprExperienceCooldown.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index 3c9f53bdd01..e94c8fdae0d 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -48,10 +48,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public Class @Nullable [] acceptChange(ChangeMode mode) { - switch (mode) { - case ADD, SET, RESET -> {return CollectionUtils.array(Timespan.class);} - } - return null; + return switch (mode) { + case ADD, SET, RESET -> CollectionUtils.array(Timespan.class); + default -> null; + }; } @Override From 32bf5550ea3d1e0579e982f29cb321063a7fe2f2 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:09:07 -0400 Subject: [PATCH 07/13] Requested Changes --- .../skript/classes/data/BukkitClasses.java | 2 +- .../classes/data/BukkitEventValues.java | 2 +- .../expressions/ExprExperienceCooldown.java | 28 +++++++------------ .../ExprExperienceCooldownChangeReason.java | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 3b73d4b4420..72ba507d82e 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1529,7 +1529,7 @@ public String toVariableNameString(EnchantmentOffer eo) { .since("2.8.0")); Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencecooldownchangereason", "experience cooldown change reasons") - .user("(experience|[e]xp) ?change (reason|cause)s?") + .user("(experience|[e]xp) cooldown change (reason|cause)s?") .name("Experience Cooldown Change Reason") .description("Represents a change reason of an experience cooldown change event.") .since("INSERT VERSION")); diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 585aeee4f7c..e42b8bb8244 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1945,7 +1945,7 @@ public RegainReason get(EntityRegainHealthEvent event) { // PlayerExpCooldownChangeEvent EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Player.class, new Getter() { @Override - public @Nullable Player get(PlayerExpCooldownChangeEvent event) { + public Player get(PlayerExpCooldownChangeEvent event) { return event.getPlayer(); } }, EventValues.TIME_NOW); diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index e94c8fdae0d..318f7899dee 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -6,19 +6,17 @@ import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.util.Timespan; -import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; -@Name("Experience Cooldown") +@Name("Experience Pickup Cooldown") @Description({ "The experience cooldown of a player.", - "Experience cooldown is how long until a player can pick up another orb of experience." + "Experience cooldown is how long until a player can pick up another orb of experience.", + "The cooldown of a player must be 0 to pick up another orb of experience." }) @Examples({ "send experience cooldown of player", @@ -30,16 +28,10 @@ public class ExprExperienceCooldown extends SimplePropertyExpression { static { - register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|[e]xp) cooldown", "players"); - } - - @Override - @SuppressWarnings("unchecked") - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - setExpr((Expression) exprs[0]); - return true; + register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|[e]xp) [pickup|collection] cooldown", "players"); } + private static final int maxTicks = Integer.MAX_VALUE; @Override public @Nullable Timespan convert(Player player) { @@ -49,7 +41,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public Class @Nullable [] acceptChange(ChangeMode mode) { return switch (mode) { - case ADD, SET, RESET -> CollectionUtils.array(Timespan.class); + case ADD, SET, RESET, DELETE -> CollectionUtils.array(Timespan.class); default -> null; }; } @@ -63,20 +55,20 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case ADD -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(player.getExpCooldown() + providedTime); + player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(player.getExpCooldown() + providedTime, -1))); } } case REMOVE -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(Math.max(player.getExpCooldown() - providedTime, 0)); + player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(player.getExpCooldown() - providedTime, -1))); } } case SET -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(providedTime); + player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(providedTime, -1))); } } - case RESET -> { + case RESET, DELETE -> { for (Player player : getExpr().getArray(event)) { player.setExpCooldown(0); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java index 16f087c812a..9f619dfb14a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java @@ -12,7 +12,7 @@ @Name("Experience Cooldown Change Reason") @Description({ "The experience change reason within in an" + - "experience cooldown change event." + "experience cooldown change event." }) @Examples({ "on player experience cooldown change:", From df2b647e4db03fd4dff3a98f13f802a0f53a19c7 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:31:28 -0400 Subject: [PATCH 08/13] Requested Changes --- .../ch/njol/skript/classes/data/BukkitEventValues.java | 6 +++--- .../njol/skript/expressions/ExprExperienceCooldown.java | 8 ++++---- .../expressions/ExprExperienceCooldownChangeReason.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index e42b8bb8244..9b8edba9380 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1951,19 +1951,19 @@ public Player get(PlayerExpCooldownChangeEvent event) { }, EventValues.TIME_NOW); EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, ChangeReason.class, new Getter() { @Override - public @Nullable ChangeReason get(PlayerExpCooldownChangeEvent event) { + public ChangeReason get(PlayerExpCooldownChangeEvent event) { return event.getReason(); } }, EventValues.TIME_NOW); EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Timespan.class, new Getter() { @Override - public @Nullable Timespan get(PlayerExpCooldownChangeEvent event) { + public Timespan get(PlayerExpCooldownChangeEvent event) { return new Timespan(Timespan.TimePeriod.TICK, event.getNewCooldown()); } }, EventValues.TIME_NOW); EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Timespan.class, new Getter() { @Override - public @Nullable Timespan get(PlayerExpCooldownChangeEvent event) { + public Timespan get(PlayerExpCooldownChangeEvent event) { return new Timespan(Timespan.TimePeriod.TICK, event.getPlayer().getExpCooldown()); } }, EventValues.TIME_PAST); diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index 318f7899dee..4773e1fc4e5 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -20,9 +20,9 @@ }) @Examples({ "send experience cooldown of player", - "set experience cooldown of player to 1 hour", - "if experience cooldown of player >= 10 minutes:", - "\tclear experience cooldown of player" + "set the xp pickup cooldown of player to 1 hour", + "if exp collection cooldown of player >= 10 minutes:", + "\tclear the experience pickup cooldown of player" }) @Since("INSERT VERSION") public class ExprExperienceCooldown extends SimplePropertyExpression { @@ -34,7 +34,7 @@ public class ExprExperienceCooldown extends SimplePropertyExpression { static { - register(ExprExperienceCooldownChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) change (reason|cause|type)"); + register(ExprExperienceCooldownChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) cooldown change (reason|cause|type)"); } public ExprExperienceCooldownChangeReason() { From 98f3121ec5d5f7476075544600474454967a2773 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:54:16 -0400 Subject: [PATCH 09/13] Fix Syntax --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- src/test/skript/junit/EvtExperienceCooldownChangeTest.sk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 16569f4efa5..d0d0c7cd446 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -805,7 +805,7 @@ public class SimpleEvents { "\tbroadcast event-player", "\tbroadcast event-timespan", "\tbroadcast past event-timespan", - "\tbroadcast xp change reason" + "\tbroadcast xp cooldown change reason" ) .since("INSERT VERSION"); diff --git a/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk index dd2ec3032f0..6ec6844fb4a 100644 --- a/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk +++ b/src/test/skript/junit/EvtExperienceCooldownChangeTest.sk @@ -10,7 +10,7 @@ on player experience cooldown change: junit test is {_test} if event-player is set: complete objective "got player" for junit test {_test} - if xp change reason is plugin: + if xp cooldown change reason is plugin: complete objective "change reason is plugin" for junit test {_test} if event-timespan is set: complete objective "got new cooldown" for junit test {_test} From f0ac9785cec8533cfa14c6ca356332e7b8781898 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:56:52 -0400 Subject: [PATCH 10/13] Conflict --- .../ch/njol/skript/classes/data/BukkitClasses.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index e6346cd0ccf..f84e9c7f8ba 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1529,18 +1529,17 @@ public String toVariableNameString(EnchantmentOffer eo) { .description("Represents a transform reason of an entity transform event.") .since("2.8.0")); - Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencecooldownchangereason", "experience cooldown change reasons") - .user("(experience|[e]xp) cooldown change (reason|cause)s?") - .name("Experience Cooldown Change Reason") - .description("Represents a change reason of an experience cooldown change event.") - .since("INSERT VERSION")); - Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes") .user("(entity )?potion ?effect ?cause") .name("Entity Potion Cause") .description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command") .since("INSERT VERSION")); - + + Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencecooldownchangereason", "experience cooldown change reasons") + .user("(experience|[e]xp) cooldown change (reason|cause)s?") + .name("Experience Cooldown Change Reason") + .description("Represents a change reason of an experience cooldown change event.") + .since("INSERT VERSION")); } } From bda5f80b747faa5e8e0dc841cf47de64e89c1eab Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 22 Sep 2024 15:22:53 -0400 Subject: [PATCH 11/13] Requested Changes --- .../njol/skript/expressions/ExprExperienceCooldown.java | 8 +++++--- .../expressions/ExprExperienceCooldownChangeReason.java | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java index 4773e1fc4e5..abd44281317 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldown.java @@ -7,6 +7,7 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.skript.util.Timespan; +import ch.njol.util.Math2; import ch.njol.util.coll.CollectionUtils; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -52,20 +53,21 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if (delta[0] != null) providedTime = (int) ((Timespan) delta[0]).get(Timespan.TimePeriod.TICK); + switch (mode) { case ADD -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(player.getExpCooldown() + providedTime, -1))); + player.setExpCooldown(Math2.fit(-1, player.getExpCooldown() + providedTime, Integer.MAX_VALUE)); } } case REMOVE -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(player.getExpCooldown() - providedTime, -1))); + player.setExpCooldown(Math2.fit(-1, player.getExpCooldown() - providedTime, Integer.MAX_VALUE)); } } case SET -> { for (Player player : getExpr().getArray(event)) { - player.setExpCooldown(Math.min(Integer.MAX_VALUE, Math.max(providedTime, -1))); + player.setExpCooldown(Math2.fit(-1, providedTime, Integer.MAX_VALUE)); } } case RESET, DELETE -> { diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java index e26df31c78f..81c8ba6e2c8 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperienceCooldownChangeReason.java @@ -34,7 +34,7 @@ public ExprExperienceCooldownChangeReason() { @Override public String toString(@Nullable Event event, boolean debug) { - return "experience change reason"; + return "experience cooldown change reason"; } } From 77e27039925ab966eb817dd10b2530ff68928d0c Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 13 Oct 2024 13:14:49 -0400 Subject: [PATCH 12/13] Final Fix --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index b8d7ae3b918..65d2c4eb4d4 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -104,6 +104,7 @@ import org.bukkit.event.player.PlayerToggleFlightEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; From d84b411004726e8853b6b20248f029ca3a13c267 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:42:06 -0400 Subject: [PATCH 13/13] Remove Specific Player Event Value --- .../java/ch/njol/skript/classes/data/BukkitEventValues.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 74819e50bbe..f7cfcff0f11 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1999,12 +1999,6 @@ public Entity[] get(BlockDropItemEvent event) { }, EventValues.TIME_NOW); // PlayerExpCooldownChangeEvent - EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Player.class, new Getter() { - @Override - public Player get(PlayerExpCooldownChangeEvent event) { - return event.getPlayer(); - } - }, EventValues.TIME_NOW); EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, ChangeReason.class, new Getter() { @Override public ChangeReason get(PlayerExpCooldownChangeEvent event) {