Skip to content

Commit 4bacd8c

Browse files
committed
Initial commit
0 parents  commit 4bacd8c

24 files changed

+1464
-0
lines changed

build.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
group 'com.pikachu.webaddon'
2+
version '1.0-SNAPSHOT'
3+
4+
apply plugin: 'java'
5+
6+
sourceCompatibility = 1.8
7+
8+
repositories {
9+
10+
mavenCentral()
11+
12+
maven {
13+
name = 'spigotmc-repo'
14+
url = 'https://hub.spigotmc.org/nexus/content/groups/public/'
15+
}
16+
17+
maven {
18+
url 'https://raw.githubusercontent.com/bensku/mvn-repo/master/'
19+
}
20+
21+
maven {
22+
url 'https://repo.destroystokyo.com/repository/maven-public/'
23+
}
24+
25+
maven {
26+
url 'http://maven.sk89q.com/repo'
27+
}
28+
29+
maven {
30+
url 'http://nexus.hc.to/content/repositories/pub_releases'
31+
}
32+
33+
maven {
34+
url 'https://jitpack.io'
35+
}
36+
37+
}
38+
39+
configurations {
40+
spark
41+
}
42+
43+
dependencies {
44+
compile 'org.spigotmc:spigot-api:1.12.1-R0.1-SNAPSHOT'
45+
testCompile group: 'junit', name: 'junit', version: '4.12'
46+
compile 'ch.njol:skript:2.2-dev33'
47+
spark group: 'com.sparkjava', name: 'spark-core', version: '2.7.2'
48+
configurations.compile.extendsFrom(configurations.spark)
49+
}
50+
51+
jar {
52+
from {
53+
configurations.spark.collect { it.isDirectory() ? it : zipTree(it) }
54+
}
55+
}

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'veba'
2+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.pikachu.webaddon;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.SkriptAddon;
5+
import com.pikachu.webaddon.skript.classinfos.Classinfos;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
import java.io.IOException;
9+
10+
public class WebAddon extends JavaPlugin {
11+
12+
private static SkriptAddon addonInstance;
13+
private static WebAddon instance;
14+
15+
@Override
16+
public void onEnable() {
17+
instance = this;
18+
try {
19+
getAddonInstance().loadClasses("com.pikachu.webaddon", "skript");
20+
Classinfos.register();
21+
} catch (IOException e) {
22+
e.printStackTrace();
23+
}
24+
}
25+
26+
public static SkriptAddon getAddonInstance() {
27+
if (addonInstance == null) {
28+
addonInstance = Skript.registerAddon(getInstance());
29+
}
30+
return addonInstance;
31+
}
32+
33+
public static WebAddon getInstance() {
34+
if (instance == null) {
35+
instance = new WebAddon();
36+
}
37+
return instance;
38+
}
39+
40+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.pikachu.webaddon.bukkit.events;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.event.HandlerList;
5+
import spark.Request;
6+
import spark.Response;
7+
8+
public class HTTPRequestEvent extends Event {
9+
10+
private static HandlerList handlerList = new HandlerList();
11+
12+
public static HandlerList getHandlerList() {
13+
return handlerList;
14+
}
15+
16+
@Override
17+
public HandlerList getHandlers() {
18+
return null;
19+
}
20+
21+
private Request request;
22+
private Response response;
23+
24+
public HTTPRequestEvent(Request request, Response response) {
25+
this.request = request;
26+
this.response = response;
27+
}
28+
29+
public Request getRequest() {
30+
return request;
31+
}
32+
33+
public Response getResponse() {
34+
return response;
35+
}
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.pikachu.webaddon.bukkit.events;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.event.HandlerList;
5+
6+
/**
7+
* A bukkit event that won't ever be called,
8+
* for registration purposes.
9+
*/
10+
public final class StubBukkitEvent extends Event {
11+
12+
private static HandlerList handlerList = new HandlerList();
13+
14+
public static HandlerList getHandlerList() {
15+
return handlerList;
16+
}
17+
18+
@Override
19+
public HandlerList getHandlers() {
20+
return handlerList;
21+
}
22+
23+
private StubBukkitEvent() throws UnsupportedOperationException {
24+
throw new UnsupportedOperationException("This class cannot be instantiated");
25+
}
26+
27+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.pikachu.webaddon.skript.classinfos;
2+
3+
import ch.njol.skript.lang.ParseContext;
4+
import spark.Request;
5+
import spark.Response;
6+
7+
public class Classinfos {
8+
9+
public static void register() {
10+
new SimpleType<Request>(Request.class, "request", "requests?") {
11+
@Override
12+
public Request parse(String arg0, ParseContext arg1) {
13+
return null;
14+
}
15+
16+
@Override
17+
public boolean canParse(ParseContext pc) {
18+
return false;
19+
}
20+
21+
@Override
22+
public String toString(Request request, int context) {
23+
return request.pathInfo();
24+
}
25+
26+
@Override
27+
public String toVariableNameString(Request request) {
28+
return request.pathInfo();
29+
}
30+
31+
};
32+
33+
new SimpleType<Response>(Response.class, "response", "responses?") {
34+
@Override
35+
public Response parse(String arg0, ParseContext arg1) {
36+
return null;
37+
}
38+
39+
@Override
40+
public boolean canParse(ParseContext pc) {
41+
return false;
42+
}
43+
44+
@Override
45+
public String toString(Response response, int context) {
46+
return response.body();
47+
}
48+
49+
@Override
50+
public String toVariableNameString(Response response) {
51+
return response.body();
52+
}
53+
54+
};
55+
}
56+
57+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.pikachu.webaddon.skript.classinfos;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.classes.Changer;
5+
import ch.njol.skript.classes.ClassInfo;
6+
import ch.njol.skript.classes.Parser;
7+
import ch.njol.skript.expressions.base.EventValueExpression;
8+
import ch.njol.skript.lang.ParseContext;
9+
import ch.njol.skript.registrations.Classes;
10+
11+
import javax.annotation.Nullable;
12+
13+
public abstract class SimpleType<T> extends ClassInfo<T> implements Changer<T> {
14+
15+
private String variableName;
16+
private String name;
17+
private String pattern;
18+
private Class<T> clz;
19+
20+
public SimpleType(Class<T> clz, String name) {
21+
this(clz, name, name, ".+");
22+
}
23+
24+
public SimpleType(Class<T> clz, String name, String pattern) {
25+
this(clz, name, pattern, ".+");
26+
}
27+
28+
public SimpleType(Class<T> clz, String name, String pattern, String variableName) {
29+
super(clz, name.toLowerCase().replaceAll("\\s+", ""));
30+
this.clz = clz;
31+
this.name = name;
32+
this.pattern = pattern;
33+
this.variableName = variableName;
34+
register();
35+
}
36+
37+
public abstract String toString(T arg0, int arg1);
38+
39+
public abstract String toVariableNameString(T arg0);
40+
41+
public T parse(String arg0, ParseContext arg1) {
42+
return null;
43+
}
44+
45+
public boolean canParse(ParseContext pc) {
46+
return true;
47+
}
48+
49+
@Override
50+
public Class<?>[] acceptChange(ChangeMode mode) {
51+
return null;
52+
}
53+
54+
@Override
55+
public void change(T[] source, Object[] set, ChangeMode mode) {
56+
57+
}
58+
59+
private void register() {
60+
try {
61+
Classes.registerClass(user(pattern)
62+
.defaultExpression(new EventValueExpression<>(clz))
63+
.parser(new Parser<T>() {
64+
@Override
65+
public String getVariableNamePattern() {
66+
return variableName;
67+
}
68+
69+
@Override
70+
public boolean canParse(ParseContext context) {
71+
return SimpleType.this.canParse(context);
72+
}
73+
74+
@Override
75+
@Nullable
76+
public T parse(String arg0, ParseContext arg1) {
77+
return SimpleType.this.parse(arg0, arg1);
78+
}
79+
80+
@Override
81+
public String toString(T arg0, int arg1) {
82+
return SimpleType.this.toString(arg0, arg1);
83+
}
84+
85+
@Override
86+
public String toVariableNameString(T arg0) {
87+
return SimpleType.this.toVariableNameString(arg0);
88+
}
89+
}));
90+
} catch (Exception e) {
91+
Skript.warning("Couldn't register the type '" + name + "'. Due to: " + (e.getMessage() != null && !e.getMessage().isEmpty() ? e.getMessage() : "unknown"));
92+
}
93+
94+
}
95+
96+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.pikachu.webaddon.skript.effects;
2+
3+
import ch.njol.skript.ScriptLoader;
4+
import ch.njol.skript.Skript;
5+
import ch.njol.skript.lang.Effect;
6+
import ch.njol.skript.lang.Expression;
7+
import ch.njol.skript.lang.SkriptParser;
8+
import ch.njol.skript.registrations.EventValues;
9+
import ch.njol.util.Kleenean;
10+
import org.bukkit.event.Event;
11+
import spark.Response;
12+
13+
import java.util.Arrays;
14+
15+
public class EffSendBack extends Effect {
16+
17+
static {
18+
Skript.registerEffect(EffSendBack.class, "send back %string%", "send %string% back");
19+
}
20+
21+
private Expression<String> response;
22+
23+
@Override
24+
public boolean init(Expression<?>[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
25+
if (ScriptLoader.getCurrentEvents() != null && Arrays.stream(ScriptLoader.getCurrentEvents())
26+
.anyMatch(event -> EventValues.getEventValueGetter(event, Response.class, 0) != null)) {
27+
response = (Expression<String>) exprs[0];
28+
return true;
29+
}
30+
Skript.error("You may only use 'send back' in events with a response");
31+
return false;
32+
}
33+
34+
@Override
35+
protected void execute(Event e) {
36+
Response response = EventValues.getEventValue(e, Response.class, 0);
37+
String body = this.response.getSingle(e);
38+
if (response != null && body != null) {
39+
response.body(body);
40+
}
41+
}
42+
43+
@Override
44+
public String toString(Event e, boolean debug) {
45+
return "send back " + response.toString(e, debug);
46+
}
47+
}

0 commit comments

Comments
 (0)