Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayerExpCooldown #7076

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
27ba1b6
Starter Commit
TheAbsolutionism Sep 13, 2024
6ad8189
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Sep 13, 2024
b3bcd25
Changes + Tests
TheAbsolutionism Sep 13, 2024
14f396c
Requested Changes
TheAbsolutionism Sep 14, 2024
bdb2c82
Requested Changes
TheAbsolutionism Sep 15, 2024
fd34dc4
Requested Changes
TheAbsolutionism Sep 16, 2024
8eb4004
Requested Change
TheAbsolutionism Sep 18, 2024
cfe20fd
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Sep 19, 2024
32bf555
Requested Changes
TheAbsolutionism Sep 20, 2024
df2b647
Requested Changes
TheAbsolutionism Sep 21, 2024
98f3121
Fix Syntax
TheAbsolutionism Sep 21, 2024
1f5908e
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Sep 21, 2024
f793978
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Sep 22, 2024
f0ac978
Conflict
TheAbsolutionism Sep 22, 2024
bda5f80
Requested Changes
TheAbsolutionism Sep 22, 2024
0ac4b26
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Sep 22, 2024
8562a17
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Oct 1, 2024
877f948
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Oct 2, 2024
45c3604
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Oct 6, 2024
612796a
Merge remote-tracking branch 'upstream/dev/feature' into dev/PlayerEx…
TheAbsolutionism Oct 13, 2024
1b1e46a
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Oct 13, 2024
77e2703
Final Fix
TheAbsolutionism Oct 13, 2024
e5d04ce
Merge branch 'dev/PlayerExpCooldown' of https://github.com/TheAbsolut…
TheAbsolutionism Oct 13, 2024
e355dbb
Merge branch 'dev/feature' into dev/PlayerExpCooldown
TheAbsolutionism Oct 15, 2024
d84b411
Remove Specific Player Event Value
TheAbsolutionism Oct 16, 2024
bcf3671
Merge branch 'dev/feature' into dev/PlayerExpCooldown
sovdeeth Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1526,6 +1527,12 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.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 <a href='events.html#experience cooldown change event'>experience cooldown change event</a>.")
.since("INSERT VERSION"));
}

}
33 changes: 33 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1935,5 +1941,32 @@ public RegainReason get(EntityRegainHealthEvent event) {
return event.getRegainReason();
}
}, EventValues.TIME_NOW);

// PlayerExpCooldownChangeEvent
EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Player.class, new Getter<Player, PlayerExpCooldownChangeEvent>() {
@Override
public @Nullable Player get(PlayerExpCooldownChangeEvent event) {
return event.getPlayer();
}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}, EventValues.TIME_NOW);
EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, ChangeReason.class, new Getter<ChangeReason, PlayerExpCooldownChangeEvent>() {
@Override
public @Nullable ChangeReason get(PlayerExpCooldownChangeEvent event) {
return event.getReason();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(PlayerExpCooldownChangeEvent.class, Timespan.class, new Getter<Timespan, PlayerExpCooldownChangeEvent>() {
@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<Timespan, PlayerExpCooldownChangeEvent>() {
@Override
public @Nullable Timespan get(PlayerExpCooldownChangeEvent event) {
return new Timespan(Timespan.TimePeriod.TICK, event.getPlayer().getExpCooldown());
}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}, EventValues.TIME_PAST);

}
}
43 changes: 16 additions & 27 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -820,5 +794,20 @@ 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")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.description(
"Called when a players experience cooldown changes.",
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
"Experience cooldown is how long until a player can pickup another orb of experience"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
)
.examples(
"on player experience cooldown change:",
"\tevent-player",
"\tevent-change reason",
"\tevent-timespan",
"\tpast event-timespan"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
)
.since("INSERT VERSION");

}
}
39 changes: 39 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprChangeReason.java
Original file line number Diff line number Diff line change
@@ -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.jetbrains.annotations.Nullable;

@Name("Experience Change Reason")
@Description({
"The <a href='classes.html#experiencechangereason'>experience change reason</a> within in an" +
"<a href='events.html#experience cooldown change event'>experience cooldown change event</a>."
})
@Examples({
"on player experience cooldown change:",
"\tchange reason is plugin",
"\tchange reason is orb pickup"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
})
@Since("INSERT VERSION")
public class ExprChangeReason extends EventValueExpression<ChangeReason> {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

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";
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package ch.njol.skript.expressions;

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")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
@Description("The experience cooldown of a player")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
@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"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
})
@Since("INSERT VERSION")
public class ExprExperienceCooldown extends SimplePropertyExpression<Player, Timespan> {

static {
register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|exp|xp) cooldown", "players");
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<? extends Player>) exprs[0]);
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return true;
}


@Override
public @Nullable Timespan convert(Player player) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return new Timespan(Timespan.TimePeriod.TICK, player.getExpCooldown());
}

@Override
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
return CollectionUtils.array(Timespan.class);
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public @Nullable void change(Event event, Object[] delta, ChangeMode mode) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
int providedTime = 0;
if (delta[0] != null && delta[0] instanceof Timespan timeSpan) {
providedTime = (int) timeSpan.get(Timespan.TimePeriod.TICK);
}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
switch (mode) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
case ADD -> {
for (Player player : getExpr().getArray(event)) {
player.setExpCooldown(player.getExpCooldown() + providedTime);
}
}
case REMOVE -> {
for (Player player : getExpr().getArray(event)) {
player.setExpCooldown(Math.max(player.getExpCooldown() + providedTime, 0));
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}
}
case SET -> {
for (Player player : getExpr().getArray(event)) {
player.setExpCooldown(providedTime);
}
}
case DELETE, RESET -> {
for (Player player : getExpr().getArray(event)) {
player.setExpCooldown(0);
}
}
default -> {}
}
}

@Override
protected String getPropertyName() {
return "experience cooldown";
}

@Override
public Class<? extends Timespan> getReturnType() {
return Timespan.class;
}

}
6 changes: 6 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,11 @@ transform reasons:
unknown: unknown
infection: infection, villager infection

# -- Change Reasons --
change reasons:
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
plugin: plugin
pickup_orb: orb pickup, pickup orb

# -- Boolean --
boolean:
true:
Expand Down Expand Up @@ -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
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

# Skript
weathertype: weather type¦s @a
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}


TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 16 additions & 0 deletions src/test/skript/junit/EvtExperienceCooldownChangeTest.sk
Original file line number Diff line number Diff line change
@@ -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"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
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"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
if event-timespan is set:
complete objective "got new cooldown" for junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtExperienceCooldownChangeTest"

TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved