From 5726e04bc021ceb0d7d29f4f03f972ea64409208 Mon Sep 17 00:00:00 2001 From: nylhus Date: Wed, 12 Jul 2023 12:41:52 -0300 Subject: [PATCH 01/12] Issue #5082 --- .../ch/njol/skript/events/SimpleEvents.java | 9 ++ .../skript/expressions/ExprExpCooldown.java | 101 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 36a9b2e4fd8..5369ffb7aa1 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -71,6 +71,7 @@ import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerItemBreakEvent; import org.bukkit.event.player.PlayerItemDamageEvent; @@ -731,6 +732,14 @@ public class SimpleEvents { ) .since("INSERT VERSION"); + Skript.registerEvent("Player Exp Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp cooldown change)") + .description("Called when a player's exp cooldown changes") + .examples( + "On player exp cooldown change:", + "\tsend \"Your exp cooldown has changed!\" to player" + ) + .since("INSERT VERSION"); + } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java new file mode 100644 index 00000000000..0c43c8ae074 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -0,0 +1,101 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +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.util.Timespan; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import javax.annotation.Nullable; + +@Name("Exp Cooldown") +@Description("The exp cooldown of a player") +@Examples("") +@Since("") +public class ExprExpCooldown extends SimplePropertyExpression { + + static { + if (Skript.methodExists(Player.class, "getNewCooldown")) + register(ExprExpCooldown.class, Timespan.class, "cooldown change", "players"); + } + + @Override + @Nullable + public Timespan convert(Player player) { return Timespan.fromTicks_i(player.getExpCooldown()); } + + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + return (mode != ChangeMode.REMOVE_ALL) ? CollectionUtils.array(Timespan.class) : null; + } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + int time = delta == null ? 0 : (int) ((Timespan) delta[0]).getTicks_i(); + int newTime; + switch (mode) { + case ADD: + for (Player player : getExpr().getArray(e)) { + newTime = player.getExpCooldown() + time; + setExpCooldown(player, newTime); + } + break; + case REMOVE: + for (Player player : getExpr().getArray(e)) { + newTime = player.getExpCooldown() - time; + setExpCooldown(player, newTime); + } + break; + case SET: + for (Player player : getExpr().getArray(e)) { + setExpCooldown(player, time); + } + break; + case DELETE: + case RESET: + for (Player player : getExpr().getArray(e)) { + setExpCooldown(player, 0); + } + break; + default: + assert false; + } + } + + @Override + public Class getReturnType() { return Timespan.class; } + + @Override + protected String getPropertyName() { return "exp cooldown"; } + + private void setExpCooldown(Player player, int ticks) { + if (ticks < 0) + ticks = 0; + player.setExpCooldown(ticks); + } +} From e8db97aa9d055741a1fb3f4c7c4514dee2c5ce11 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:16:45 -0300 Subject: [PATCH 02/12] Added example. --- .../java/ch/njol/skript/expressions/ExprExpCooldown.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index 0c43c8ae074..d2c8e1139c9 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -35,8 +35,12 @@ @Name("Exp Cooldown") @Description("The exp cooldown of a player") -@Examples("") -@Since("") +@Examples({ + "player's exp cooldown is less than 3 ticks:", + "\tsend \"increasing your exp cooldown!\" to player", + "\t\tset player's exp cooldown to 40 ticks" +}) +@Since("2.7") public class ExprExpCooldown extends SimplePropertyExpression { static { From 3725496800aa437191dbc901e42d75cfb9ed49f0 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:32:52 -0300 Subject: [PATCH 03/12] Fixed SimpleEvents issue --- .../ch/njol/skript/events/SimpleEvents.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 5369ffb7aa1..56ad40ddf19 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -732,13 +732,16 @@ public class SimpleEvents { ) .since("INSERT VERSION"); - Skript.registerEvent("Player Exp Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp cooldown change)") - .description("Called when a player's exp cooldown changes") - .examples( - "On player exp cooldown change:", - "\tsend \"Your exp cooldown has changed!\" to player" - ) - .since("INSERT VERSION"); + if (Skript.classExists("org.bukkit.event.player.PlayerExpCooldownChangeEvent")) { + Skript.registerEvent("Player Exp Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp cooldown change)") + .description("Called when a player's exp cooldown changes") + .examples( + "On player exp cooldown change:", + "\tsend \"Your exp cooldown has changed!\" to player" + ) + .since("INSERT VERSION"); + + } } From ac8a7513311664e58ab2f96aebb96dcbefac1cb5 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:34:39 -0300 Subject: [PATCH 04/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: sovdee --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index d2c8e1139c9..944752c4e79 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -45,7 +45,7 @@ public class ExprExpCooldown extends SimplePropertyExpression static { if (Skript.methodExists(Player.class, "getNewCooldown")) - register(ExprExpCooldown.class, Timespan.class, "cooldown change", "players"); + register(ExprExpCooldown.class, Timespan.class, "exp[erience] [pickup] cooldown change", "players"); } @Override From d45adec5fb2cdcb98b8934f4a7fa6ec81305b3f7 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:35:07 -0300 Subject: [PATCH 05/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: sovdee --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index 944752c4e79..b497a16e237 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -37,8 +37,8 @@ @Description("The exp cooldown of a player") @Examples({ "player's exp cooldown is less than 3 ticks:", - "\tsend \"increasing your exp cooldown!\" to player", - "\t\tset player's exp cooldown to 40 ticks" + "\tsend \"increasing your exp cooldown!\" to player", + "\tset player's exp cooldown to 40 ticks" }) @Since("2.7") public class ExprExpCooldown extends SimplePropertyExpression { From 97960da7127c7fc62c7b282f402c4f3d97f78f2c Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:35:30 -0300 Subject: [PATCH 06/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: sovdee --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index b497a16e237..c6d96d3e66e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -44,7 +44,7 @@ public class ExprExpCooldown extends SimplePropertyExpression { static { - if (Skript.methodExists(Player.class, "getNewCooldown")) + if (Skript.methodExists(Player.class, "getExpCooldown")) register(ExprExpCooldown.class, Timespan.class, "exp[erience] [pickup] cooldown change", "players"); } From 260d313477d0cd028a09d00e699901081c9b6ebd Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:37:57 -0300 Subject: [PATCH 07/12] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- .../java/ch/njol/skript/events/SimpleEvents.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 56ad40ddf19..f6547f258ca 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -734,12 +734,12 @@ public class SimpleEvents { if (Skript.classExists("org.bukkit.event.player.PlayerExpCooldownChangeEvent")) { Skript.registerEvent("Player Exp Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp cooldown change)") - .description("Called when a player's exp cooldown changes") - .examples( - "On player exp cooldown change:", - "\tsend \"Your exp cooldown has changed!\" to player" - ) - .since("INSERT VERSION"); + .description("Called when a player's experience pickup cooldown changes") + .examples( + "on player exp cooldown change:", + "\tsend \"Your experience cooldown has changed!\" to player" + ) + .since("INSERT VERSION"); } From 9fe8a8db55bd23412bf9c15139b3884e4a9ad226 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:38:23 -0300 Subject: [PATCH 08/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index c6d96d3e66e..3f6438bd6d8 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -50,7 +50,9 @@ public class ExprExpCooldown extends SimplePropertyExpression @Override @Nullable - public Timespan convert(Player player) { return Timespan.fromTicks_i(player.getExpCooldown()); } + public Timespan convert(Player player) { + return Timespan.fromTicks_i(player.getExpCooldown()); + } @Override @Nullable From b0770c10bdc5b3b47c613e90bb6a6fad6e2298d4 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:38:41 -0300 Subject: [PATCH 09/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index 3f6438bd6d8..0b1d5fd007f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -97,7 +97,9 @@ public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { public Class getReturnType() { return Timespan.class; } @Override - protected String getPropertyName() { return "exp cooldown"; } + protected String getPropertyName() { + return "exp cooldown"; + } private void setExpCooldown(Player player, int ticks) { if (ticks < 0) From 69c274182b844d5b557415ea0449f8f184b430c6 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:38:48 -0300 Subject: [PATCH 10/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index 0b1d5fd007f..11df60eacf2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -106,4 +106,5 @@ private void setExpCooldown(Player player, int ticks) { ticks = 0; player.setExpCooldown(ticks); } + } From 239df920500f9758c6938fb0d20a71ea36b7a7a1 Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:38:58 -0300 Subject: [PATCH 11/12] Update src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java index 11df60eacf2..30cce854754 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExpCooldown.java @@ -94,7 +94,9 @@ public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { } @Override - public Class getReturnType() { return Timespan.class; } + public Class getReturnType() { + return Timespan.class; + } @Override protected String getPropertyName() { From 5b2cea515f1eedab202ace766e078f7c124aa22f Mon Sep 17 00:00:00 2001 From: Matthew <98179506+nylhus@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:42:05 -0300 Subject: [PATCH 12/12] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index f6547f258ca..a040c0735a4 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -733,7 +733,7 @@ public class SimpleEvents { .since("INSERT VERSION"); if (Skript.classExists("org.bukkit.event.player.PlayerExpCooldownChangeEvent")) { - Skript.registerEvent("Player Exp Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp cooldown change)") + Skript.registerEvent("Player Experience Cooldown Change", SimpleEvent.class, PlayerExpCooldownChangeEvent.class, "[player] (exp[erience] cooldown change)") .description("Called when a player's experience pickup cooldown changes") .examples( "on player exp cooldown change:",