Skip to content

Commit 651c939

Browse files
committed
Init commit
0 parents  commit 651c939

File tree

7 files changed

+600
-0
lines changed

7 files changed

+600
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
.idea/*
3+
target/*

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Functions
2+
3+
## Executes
4+
5+
A set of functions for specific execution of closures
6+
7+
### mixed execute\_current([values...], closure):
8+
9+
Executes the given closure like execute(), but with current environment. WARNING: the closure must use already defined variables and procedures to avoid compilation errors.
10+
11+
## Threading
12+
13+
A set of functions for interacting with threads.
14+
15+
### array dump\_keys\_threads():
16+
17+
Returns an array of all threads keys that are currently running in the JVM.
18+
19+
### void x\_safe\_execute([values...], closure):
20+
21+
Executes the given closure. You can also send arguments to the closure, which it may or may not use, depending on the particular closure's definition. Unlike closure, it returns only void and will be executed even if the thread was stopped by a functionx_stop_thread().
22+
23+
### boolean x\_stop\_thread(string id):
24+
25+
Stopping tracked thread named 'id'. If successful, returns true, else false. If the thread performs a x_safe_execute() function, the interrupting thread will wait for execution.
26+
27+
## Echo
28+
29+
A set of functions for logs
30+
31+
### void print(message):
32+
33+
Prints a message.
34+
35+
### void println(message):
36+
37+
Prints a message and then terminate the line.

pom.xml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>me.anatoliy57</groupId>
8+
<artifactId>chunit</artifactId>
9+
<version>1.0.0</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
</properties>
14+
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>3.5.1</version>
21+
<configuration>
22+
<source>1.8</source>
23+
<target>1.8</target>
24+
<compilerArgument>-XDignore.symbol.file</compilerArgument>
25+
</configuration>
26+
</plugin>
27+
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-jar-plugin</artifactId>
31+
32+
<configuration>
33+
<archive>
34+
<addMavenDescriptor>false</addMavenDescriptor>
35+
36+
<manifest>
37+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
38+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
39+
</manifest>
40+
41+
</archive>
42+
</configuration>
43+
44+
<version>2.4</version>
45+
</plugin>
46+
47+
<plugin>
48+
<groupId>org.bsc.maven</groupId>
49+
<artifactId>maven-processor-plugin</artifactId>
50+
<version>2.2.4</version>
51+
52+
<executions>
53+
<execution>
54+
<id>process</id>
55+
<phase>process-classes</phase>
56+
57+
<goals>
58+
<goal>process</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
63+
<configuration>
64+
<outputDirectory>src/main/generated</outputDirectory>
65+
66+
<processors>
67+
<processor>com.laytonsmith.core.extensions.ExtensionAnnotationProcessor</processor>
68+
</processors>
69+
</configuration>
70+
</plugin>
71+
72+
<plugin>
73+
<groupId>org.codehaus.mojo</groupId>
74+
<artifactId>exec-maven-plugin</artifactId>
75+
<version>1.2.1</version>
76+
77+
<executions>
78+
<execution>
79+
<id>cache-annotations</id>
80+
<phase>process-classes</phase>
81+
<goals>
82+
<goal>java</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
87+
<configuration>
88+
<mainClass>com.laytonsmith.PureUtilities.ClassLoading.Annotations.CacheAnnotations</mainClass>
89+
90+
<arguments>
91+
<argument>${basedir}/target/classes</argument>
92+
<argument>${basedir}/target/classes</argument>
93+
</arguments>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
99+
<repositories>
100+
<repository>
101+
<id>enginehub-maven</id>
102+
<url>https://maven.enginehub.org/repo/</url>
103+
</repository>
104+
</repositories>
105+
106+
<dependencies>
107+
<dependency>
108+
<groupId>com.sk89q</groupId>
109+
<artifactId>commandhelper</artifactId>
110+
<version>3.3.4-SNAPSHOT</version>
111+
</dependency>
112+
</dependencies>
113+
114+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.anatoliy57.chunit;
2+
3+
import com.laytonsmith.PureUtilities.SimpleVersion;
4+
import com.laytonsmith.PureUtilities.Version;
5+
import com.laytonsmith.abstraction.Implementation;
6+
import com.laytonsmith.core.extensions.AbstractExtension;
7+
import com.laytonsmith.core.extensions.MSExtension;
8+
9+
@MSExtension("CHUnit")
10+
public class LifeCycle extends AbstractExtension {
11+
public Version getVersion() {
12+
return new SimpleVersion(1, 0, 0);
13+
}
14+
15+
@Override
16+
public void onStartup() {
17+
if(!Implementation.GetServerType().equals(Implementation.Type.SHELL)) {
18+
System.out.println("CHUnit " + getVersion() + " loaded.");
19+
}
20+
}
21+
22+
@Override
23+
public void onShutdown() {
24+
if(!Implementation.GetServerType().equals(Implementation.Type.SHELL)) {
25+
System.out.println("CHUnit " + getVersion() + " unloaded.");
26+
}
27+
}
28+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package me.anatoliy57.chunit.functions;
2+
3+
import com.laytonsmith.PureUtilities.TermColors;
4+
import com.laytonsmith.annotations.api;
5+
import com.laytonsmith.core.MSVersion;
6+
import com.laytonsmith.core.Static;
7+
import com.laytonsmith.core.constructs.CVoid;
8+
import com.laytonsmith.core.constructs.Target;
9+
import com.laytonsmith.core.environments.Environment;
10+
import com.laytonsmith.core.exceptions.CRE.CRECastException;
11+
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
12+
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
13+
import com.laytonsmith.core.functions.AbstractFunction;
14+
import com.laytonsmith.core.natives.interfaces.Mixed;
15+
16+
import java.io.*;
17+
import java.nio.charset.StandardCharsets;
18+
19+
public class Echo {
20+
public static String docs() {
21+
return "A set of functions for logs";
22+
}
23+
24+
public static BufferedWriter out;
25+
26+
static {
27+
out = new BufferedWriter(new OutputStreamWriter(new
28+
FileOutputStream(java.io.FileDescriptor.out), StandardCharsets.US_ASCII), 512);
29+
}
30+
31+
@api
32+
public static class print extends AbstractFunction {
33+
34+
public print() {
35+
}
36+
37+
public String getName() {
38+
return "print";
39+
}
40+
41+
public Integer[] numArgs() {
42+
return new Integer[]{1};
43+
}
44+
45+
public String docs() {
46+
return "void {message} Prints a message";
47+
}
48+
49+
public Class<? extends CREThrowable>[] thrown() {
50+
return new Class[]{CRECastException.class};
51+
}
52+
53+
public boolean isRestricted() {
54+
return true;
55+
}
56+
57+
public MSVersion since() {
58+
return MSVersion.V3_0_2;
59+
}
60+
61+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
62+
String mes = Static.MCToANSIColors(args[0].val());
63+
64+
if (mes.contains("\u001b")) {
65+
mes = mes + TermColors.reset();
66+
}
67+
68+
try {
69+
Echo.out.write(mes);
70+
out.flush();
71+
} catch (IOException ignored) {}
72+
73+
return CVoid.VOID;
74+
}
75+
76+
public Boolean runAsync() {
77+
return null;
78+
}
79+
}
80+
81+
@api
82+
public static class println extends AbstractFunction {
83+
84+
public println() {
85+
}
86+
87+
public String getName() {
88+
return "println";
89+
}
90+
91+
public Integer[] numArgs() {
92+
return new Integer[]{0, 1};
93+
}
94+
95+
public String docs() {
96+
return "void {message} Prints a message and then terminate the line.";
97+
}
98+
99+
public Class<? extends CREThrowable>[] thrown() {
100+
return new Class[]{CRECastException.class};
101+
}
102+
103+
public boolean isRestricted() {
104+
return true;
105+
}
106+
107+
public MSVersion since() {
108+
return MSVersion.V3_0_2;
109+
}
110+
111+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
112+
String mes;
113+
if (args.length != 0) {
114+
mes = Static.MCToANSIColors(args[0].val());
115+
} else {
116+
mes = "";
117+
}
118+
119+
if (mes.contains("\u001b")) {
120+
mes = mes + TermColors.reset();
121+
}
122+
123+
try {
124+
Echo.out.write(mes);
125+
Echo.out.write('\n');
126+
out.flush();
127+
} catch (IOException ignored) {}
128+
return CVoid.VOID;
129+
}
130+
131+
public Boolean runAsync() {
132+
return null;
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)