Skip to content

Commit 209751b

Browse files
v0.3.1 - Automatically rewrite tick values to be > 0.
A warning will automatically be triggered once unless the plugin author manually disables this behavior.
1 parent 391fce1 commit 209751b

4 files changed

Lines changed: 187 additions & 62 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
allprojects {
88
apply plugin: 'java'
99

10-
version = '0.3.0'
10+
version = '0.3.1'
1111

1212
repositories {
1313

common/src/main/java/com/tcoded/folialib/FoliaLib.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.tcoded.folialib.enums.ImplementationType;
44
import com.tcoded.folialib.impl.ServerImplementation;
5+
import com.tcoded.folialib.util.InvalidTickDelayNotifier;
56
import org.bukkit.plugin.java.JavaPlugin;
67

78
import java.lang.reflect.InvocationTargetException;
@@ -41,7 +42,8 @@ public FoliaLib(JavaPlugin plugin) {
4142
}
4243

4344
// Check for valid relocation
44-
// Runtime replace to avoid relocations changing this string too
45+
// Runtime replace commas to avoid compiler relocations changing this string too
46+
// Not beautiful, but functional
4547
String originalLocation = "com,tcoded,folialib,".replace(",", ".");
4648
if (this.getClass().getName().startsWith(originalLocation)) {
4749
Logger logger = this.plugin.getLogger();
@@ -53,20 +55,7 @@ public FoliaLib(JavaPlugin plugin) {
5355
}
5456
}
5557

56-
private ServerImplementation createServerImpl(String implName) {
57-
String basePackage = this.getClass().getPackage().getName() + ".impl.";
58-
59-
try {
60-
return (ServerImplementation) Class.forName(basePackage + implName)
61-
.getConstructor(this.getClass())
62-
.newInstance(this);
63-
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
64-
IllegalAccessException e) {
65-
e.printStackTrace();
66-
}
67-
68-
return null;
69-
}
58+
// Getters
7059

7160
@SuppressWarnings("unused")
7261
public ImplementationType getImplType() {
@@ -85,12 +74,12 @@ public boolean isFolia() {
8574

8675
@SuppressWarnings("unused")
8776
public boolean isPaper() {
88-
return implementationType == ImplementationType.PAPER;
77+
return implementationType == ImplementationType.PAPER || implementationType == ImplementationType.LEGACY_PAPER;
8978
}
9079

9180
@SuppressWarnings("unused")
9281
public boolean isSpigot() {
93-
return implementationType == ImplementationType.SPIGOT;
82+
return implementationType == ImplementationType.SPIGOT || implementationType == ImplementationType.LEGACY_SPIGOT;
9483
}
9584

9685
@SuppressWarnings("unused")
@@ -101,4 +90,33 @@ public boolean isUnsupported() {
10190
public JavaPlugin getPlugin() {
10291
return plugin;
10392
}
93+
94+
// Public Options
95+
96+
@SuppressWarnings("unused")
97+
public void disableInvalidTickValueWarning() {
98+
InvalidTickDelayNotifier.disableNotifications = true;
99+
}
100+
101+
@SuppressWarnings("unused")
102+
public void enableInvalidTickValueDebug() {
103+
InvalidTickDelayNotifier.debugMode = true;
104+
}
105+
106+
// Internal Utils
107+
108+
private ServerImplementation createServerImpl(String implName) {
109+
String basePackage = this.getClass().getPackage().getName() + ".impl.";
110+
111+
try {
112+
return (ServerImplementation) Class.forName(basePackage + implName)
113+
.getConstructor(this.getClass())
114+
.newInstance(this);
115+
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
116+
IllegalAccessException e) {
117+
e.printStackTrace();
118+
}
119+
120+
return null;
121+
}
104122
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.tcoded.folialib.util;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.logging.Logger;
6+
7+
public class InvalidTickDelayNotifier {
8+
9+
public static boolean disableNotifications = false;
10+
public static boolean debugMode = false;
11+
12+
private static boolean notified = false;
13+
14+
public static void notifyOnce(@NotNull Logger logger, long span) {
15+
// Check if the notification was already sent or if the notifications were manually disabled
16+
if (notified || disableNotifications) return;
17+
notified = true;
18+
19+
// Send a warning message if this hasn't been sent before
20+
logger.warning(
21+
String.format("A tick based delay or timer was scheduled with a time span of %d ticks. ", span) +
22+
"The server is already processing the current tick and, as such, won't process new tasks in less than 1 tick. " +
23+
"FoliaLib will automatically change time spans of <= 0 ticks to 1 tick going forward. " +
24+
"This warning is purely informative and won't impact the operation of the plugin. " +
25+
"Plugin developers can disable this warning or enable debug mode to location the source of this warning.");
26+
27+
// If the user enables debug mode, print the stack trace
28+
if (debugMode) {
29+
new Exception("Debugging information to track down the location of the invalid tick input value")
30+
.printStackTrace();
31+
}
32+
}
33+
34+
}

0 commit comments

Comments
 (0)