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 39 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
39 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
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
39 changes: 39 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,39 @@
/**
* 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 STM_VALUE = null;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
if (Skript.methodExists(Bukkit.class, "getServerTickManager")) {
STM_VALUE = Bukkit.getServerTickManager();
}
SERVER_TICK_MANAGER = STM_VALUE;
}

public static ServerTickManager getServerTickManager() {
return SERVER_TICK_MANAGER;
}
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
}
55 changes: 55 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,55 @@
/**
* 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:"})
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
@RequiredPlugins("Minecraft 1.20.4+")
public class CondIsTickFrozen extends PropertyCondition<Entity> {


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

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

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

Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
91 changes: 91 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,91 @@
/**
* 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 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 {
private ServerState state;
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved
Asleeepp marked this conversation as resolved.
Show resolved Hide resolved

static {
if (Skript.methodExists(Bukkit.class, "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
}

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) {
if (!parseResult.tags.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should always be true (so it can be removed)

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
@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
67 changes: 67 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,67 @@
/**
* 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 (Skript.methodExists(Bukkit.class, "getServerTickManager"))
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
}
83 changes: 83 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,83 @@
/**
* 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 it has finished 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

static {
if (Skript.methodExists(Bukkit.class, "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");
}

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
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