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

⚒ Fix fake player count paper check error #6090

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,44 @@
*/
package ch.njol.skript.expressions;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
import org.eclipse.jdt.annotation.Nullable;

import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.PlayerUtils;
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.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
import org.eclipse.jdt.annotation.Nullable;

@Name("Online Player Count")
@Description({"The amount of online players. This can be changed in a",
@Description({
"The amount of online players. This can be changed in a " +
"<a href='events.html#server_list_ping'>server list ping</a> event only to show fake online player amount.",
"'real online player count' always returns the real count of online players and can't be changed.",
"",
"Fake online player count requires PaperSpigot 1.12.2+."})
@Examples({"on server list ping:",
" # This will make the max players count 5 if there are 4 players online.",
" set the fake max players count to (online players count + 1)"})
"<code>real online player count</code> always return the real count of online players and can't be changed."
})
@Examples({
"on server list ping:",
"\t# This will make the max players count 5 if there are 4 players online.",
"\tset the fake max players count to (online players count + 1)"
AyhamAl-Ali marked this conversation as resolved.
Show resolved Hide resolved
AyhamAl-Ali marked this conversation as resolved.
Show resolved Hide resolved
})
@RequiredPlugins("Paper (fake count)")
@Since("2.3")
public class ExprOnlinePlayersCount extends SimpleExpression<Long> {

static {
Skript.registerExpression(ExprOnlinePlayersCount.class, Long.class, ExpressionType.PROPERTY,
"[the] [(1¦(real|default)|2¦(fake|shown|displayed))] [online] player (count|amount|number)",
"[the] [(1¦(real|default)|2¦(fake|shown|displayed))] (count|amount|number|size) of online players");
"[the] [(1:(real|default)|2:(fake|shown|displayed))] [online] player (count|amount|number)",
"[the] [(1:(real|default)|2:(fake|shown|displayed))] (count|amount|number|size) of online players");
}

private static final boolean PAPER_EVENT_EXISTS = Skript.classExists("com.destroystokyo.paper.event.server.PaperServerListPingEvent");
Expand All @@ -64,7 +66,7 @@ public class ExprOnlinePlayersCount extends SimpleExpression<Long> {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
boolean isPaperEvent = PAPER_EVENT_EXISTS && getParser().isCurrentEvent(PaperServerListPingEvent.class);
if (parseResult.mark == 2) {
if (getParser().isCurrentEvent(ServerListPingEvent.class)) {
if (!PAPER_EVENT_EXISTS && getParser().isCurrentEvent(ServerListPingEvent.class)) {
Skript.error("The 'fake' online players count expression requires Paper 1.12.2 or newer");
return false;
} else if (!isPaperEvent) {
Expand Down Expand Up @@ -146,4 +148,4 @@ public String toString(@Nullable Event e, boolean debug) {
return "the count of " + (isReal ? "real max players" : "max players");
}

}
}