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

Adds support for modifying the tick rate #6592

Open
wants to merge 45 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
937feca
start
Asleeepp Apr 19, 2024
69dab63
start
Asleeepp Apr 19, 2024
2e2b1ca
fixes build failure, hopefully
Asleeepp Apr 19, 2024
0baa016
2nd time lucky
Asleeepp Apr 19, 2024
b097852
freeze, sprint and step
Asleeepp Apr 19, 2024
dc6d158
Merge branch 'dev/feature' into addition-modify-tick
sovdeeth Apr 19, 2024
8939d76
Merge remote-tracking branch 'origin/addition-modify-tick' into addit…
Asleeepp Apr 20, 2024
d9d887e
e
Asleeepp Apr 20, 2024
a79700e
e
Asleeepp Apr 20, 2024
a536e61
changed ExprTick to simpleexpression
Asleeepp Apr 20, 2024
dc282d8
Fixes and additions
Asleeepp Apr 21, 2024
cc51f01
Fix
Asleeepp Apr 21, 2024
3d07f89
license moment
Asleeepp Apr 21, 2024
2c5a132
Additions + Docs
Asleeepp Apr 21, 2024
7a037d7
sigh
Asleeepp Apr 21, 2024
f5d1f0e
Leaving BukkitClasses.java as it was
Asleeepp Apr 21, 2024
22826fe
jesus christ
Asleeepp Apr 22, 2024
5a80a00
Suggested changes.
Asleeepp Apr 26, 2024
b890d94
Have i done this right? (probably not)
Asleeepp May 1, 2024
e4faa7d
forgot license again
Asleeepp May 1, 2024
f98bb10
consistency + suggested changes
Asleeepp May 1, 2024
6fdcd28
Merge branch 'dev/feature' into addition-modify-tick
Moderocky May 2, 2024
3a9cca6
suggested changes
Asleeepp May 5, 2024
af2ac12
ServerTickState
Asleeepp May 7, 2024
84f2f23
Merge remote-tracking branch 'origin/addition-modify-tick' into addit…
Asleeepp May 7, 2024
7bbf510
suggested changes x95954865
Asleeepp May 7, 2024
3bd296f
Merge branch 'dev/feature' into addition-modify-tick
Moderocky May 8, 2024
3cec433
Merge branch 'dev/feature' into addition-modify-tick
Asleeepp Jun 21, 2024
8fdfed6
Changes + tests
Asleeepp Jun 21, 2024
2308449
WORKING tests
Asleeepp Jun 21, 2024
53dabc9
ACTUAL working tests
Asleeepp Jun 21, 2024
8d35f8e
Number -> float + Server tick rate test
Asleeepp Jun 21, 2024
9f205f4
Suggested
Asleeepp Jun 27, 2024
3b0272e
Merge branch 'dev/feature' into addition-modify-tick
Asleeepp Jun 27, 2024
8295cb9
Merge remote-tracking branch 'origin/addition-modify-tick' into addit…
Asleeepp Jun 27, 2024
936f566
Slight syntax change
Asleeepp Jun 28, 2024
9b6124e
stuff
Asleeepp Jul 2, 2024
936ebb9
Merge branch 'dev/feature' into addition-modify-tick
Asleeepp Sep 4, 2024
44dd920
suggested changes
Asleeepp Sep 4, 2024
8065883
Merge branch 'dev/feature' into addition-modify-tick
Asleeepp Oct 30, 2024
6f66682
jetbrains
Asleeepp Oct 30, 2024
243a2bb
Merge remote-tracking branch 'origin/addition-modify-tick' into addit…
Asleeepp Oct 30, 2024
02897e4
Merge branch 'dev/feature' into addition-modify-tick
Asleeepp Nov 22, 2024
fc81783
Apply suggestions from code review
Asleeepp Dec 7, 2024
e3d2e79
Apply suggestions from code review
Asleeepp Dec 7, 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
46 changes: 46 additions & 0 deletions src/main/java/ch/njol/skript/bukkitutil/ServerUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.bukkitutil;

import ch.njol.skript.Skript;
import org.bukkit.Bukkit;
import org.bukkit.ServerTickManager;

public class ServerUtils {

private static final ServerTickManager SERVER_TICK_MANAGER;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

static {
ServerTickManager serverTickManager = null;
if (Skript.methodExists(Bukkit.class, "getServerTickManager")) {
serverTickManager = Bukkit.getServerTickManager();
}
SERVER_TICK_MANAGER = serverTickManager;
}

public static ServerTickManager getServerTickManager() {
return SERVER_TICK_MANAGER;
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

public static boolean isServerTickManagerPresent() {
return SERVER_TICK_MANAGER != null;
}

}

56 changes: 56 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsTickFrozen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.ServerUtils;
import ch.njol.skript.conditions.base.PropertyCondition;
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 org.bukkit.Bukkit;
import org.bukkit.entity.Entity;

@Name("Is Entity Tick Frozen")
@Description("Checks if the specified entities are frozen due to the server's ticking state.")
@Examples("if target entity is tick frozen:")
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class CondIsTickFrozen extends PropertyCondition<Entity> {


static {
if (ServerUtils.isServerTickManagerPresent())
register(CondIsTickFrozen.class, "tick frozen", "entities");
}

@Override
public boolean check(Entity entity) {
return ServerUtils.getServerTickManager().isFrozen(entity);
}

@Override
protected String getPropertyName() {
return "tick frozen";
}

}

93 changes: 93 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondServerTickState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.ServerUtils;
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.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.ServerTickManager;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import java.util.Locale;

@Name("Server Tick State")
@Description("Represents the ticking state of the server, for example, if the server is frozen, or running normally.")
@Examples({
"if server's tick state is currently frozen:",
"if the server is sprinting:"
})
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class CondServerTickState extends Condition {

static {
if (ServerUtils.isServerTickManagerPresent())
Skript.registerCondition(CondServerTickState.class,
"[the] server['s tick[ing] state] is [currently] (:frozen|:stepping|:sprinting|:normal)",
"[the] server['s tick[ing] state] is(n't| not) [currently] (:frozen|:stepping|:sprinting|:normal)");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}

private ServerState state;

public enum ServerState {
FROZEN, STEPPING, SPRINTING, NORMAL
}

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
String tag = parseResult.tags.get(0).toUpperCase(Locale.ENGLISH);
state = ServerState.valueOf(tag);
return true;
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved



Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Override
public boolean check(Event event) {
ServerTickManager serverTickManager = ServerUtils.getServerTickManager();
switch (state) {
case FROZEN:
return serverTickManager.isFrozen() != isNegated();
case STEPPING:
return serverTickManager.isStepping() != isNegated();
case SPRINTING:
return serverTickManager.isSprinting() != isNegated();
case NORMAL:
return serverTickManager.isRunningNormally() != isNegated();
}
return isNegated();
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "the server's tick state is " + state;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}

}

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
70 changes: 70 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffFreezeServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.ServerUtils;
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.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
@Name("Freeze/Unfreeze Server")
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Description("Freezes or unfreezes the server.")
@Examples({
"freeze server",
"unfreeze server"
})
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class EffFreezeServer extends Effect {

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
static {
if (ServerUtils.isServerTickManagerPresent())
Skript.registerEffect(EffFreezeServer.class,
"freeze [the] server",
"unfreeze [the] server");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean freeze;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
freeze = matchedPattern == 0;
return true;
}

@Override
protected void execute(Event event) {
ServerUtils.getServerTickManager().setFrozen(freeze);
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return freeze ? "freeze server" : "unfreeze server";
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

}
84 changes: 84 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffSprintServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.ServerUtils;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Sprint Server")
@Description({
"Requests the server to sprint for a certain amount of time, or stops the server from sprinting.",
"Sprinting is where the server increases the tick rate depending on the time you input, and resets the tick rate to what it was after the server has finished sprinting."
})
@Examples({
"request server to sprint for 10 seconds",
"make server stop sprinting"
})
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class EffSprintServer extends Effect {

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
static {
if (ServerUtils.isServerTickManagerPresent())
Skript.registerEffect(EffSprintServer.class,
"(make|request) [for] [the] server [to] sprint for %timespan%",
"make [the] server stop sprinting");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean sprint;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
private Expression<Timespan> timespan;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
sprint = matchedPattern == 0;
if (sprint)
timespan = (Expression<Timespan>) exprs[0];
return true;
}

@Override
protected void execute(Event event) {
if (sprint) {
long sprintTicks = timespan.getOptionalSingle(event).map(Timespan::getTicks).orElse(1L);
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
ServerUtils.getServerTickManager().requestGameToSprint((int) sprintTicks);
} else {
ServerUtils.getServerTickManager().stopSprinting();
}
}

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Override
public String toString(@Nullable Event event, boolean debug) {
return sprint ? "request to sprint server for" + timespan.toString(event, debug) : "stop sprinting server";
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

}
Loading