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 18 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
61 changes: 61 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,61 @@
/**
* 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.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.Server;
import org.bukkit.ServerTickManager;
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:"})
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class CondIsTickFrozen extends PropertyCondition<Entity> {

private static final ServerTickManager SERVER_TICK_MANAGER;

static {
ServerTickManager STM_VALUE = null;
if (Skript.methodExists(Server.class, "getServerTickManager")) {
STM_VALUE = Bukkit.getServerTickManager();
register(CondIsTickFrozen.class, PropertyType.BE, "tick frozen", "entities");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}
SERVER_TICK_MANAGER = STM_VALUE;
}

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

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

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
97 changes: 97 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,97 @@
/**
* 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.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.Server;
import org.bukkit.ServerTickManager;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

@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 server tick state is normal:"})
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class CondServerTickState extends Condition {

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

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

static {
ServerTickManager STM_VALUE = null;
if (Skript.methodExists(Server.class, "getServerTickManager")) {
STM_VALUE = Bukkit.getServerTickManager();
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
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}
SERVER_TICK_MANAGER = STM_VALUE;
}

private ServerState state;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (parseResult.hasTag("stepping")) {
state = ServerState.STEPPING;
} else if (parseResult.hasTag("sprinting")) {
state = ServerState.SPRINTING;
} else if (parseResult.hasTag("frozen")) {
state = ServerState.FROZEN;
} else if (parseResult.hasTag("normal")) {
state = ServerState.NORMAL;
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

@Override
public boolean check(Event event) {
switch (state) {
case FROZEN:
return SERVER_TICK_MANAGER.isFrozen() != isNegated();
case STEPPING:
return SERVER_TICK_MANAGER.isStepping() != isNegated();
case SPRINTING:
return SERVER_TICK_MANAGER.isSprinting() != isNegated();
case NORMAL:
return SERVER_TICK_MANAGER.isRunningNormally() != isNegated();
}
return isNegated();
}

@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
}
}
73 changes: 73 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,73 @@
/**
* 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.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.Server;
import org.bukkit.ServerTickManager;
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
private static final ServerTickManager SERVER_TICK_MANAGER;

static {
ServerTickManager STM_VALUE = null;
if (Skript.methodExists(Server.class, "getServerTickManager")) {
STM_VALUE = Bukkit.getServerTickManager();
Skript.registerEffect(EffFreezeServer.class,
"freeze [the] server",
"unfreeze [the] server");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}
SERVER_TICK_MANAGER = STM_VALUE;
}

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) {
SERVER_TICK_MANAGER.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
}
89 changes: 89 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,89 @@
/**
* 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.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.Server;
import org.bukkit.ServerTickManager;
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 it to what it was after its done sprinting."
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
})
@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
private static final ServerTickManager SERVER_TICK_MANAGER;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

static {
ServerTickManager STM_VALUE = null;
if (Skript.methodExists(Server.class, "getServerTickManager")) {
STM_VALUE = Bukkit.getServerTickManager();
Skript.registerEffect(EffSprintServer.class,
"request [for [the]] server [to] sprint for %timespan%",
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
"make [the] server stop sprinting");
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}
SERVER_TICK_MANAGER = STM_VALUE;
}

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

@SuppressWarnings("unchecked")
@Override
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
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) {
Timespan timespanInstance = timespan.getSingle(event);
long sprintTicks = timespanInstance != null ? timespanInstance.getTicks() : 1;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
SERVER_TICK_MANAGER.requestGameToSprint((int) sprintTicks);
} else {
SERVER_TICK_MANAGER.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
Loading