Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
match DCore update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 5, 2021
1 parent a425a4a commit 7f6cad5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.16.4-R0.1-SNAPSHOT</bukkit.version>
<bukkit.version>1.16.5-R0.1-SNAPSHOT</bukkit.version>
<denizen.version>1.1.9-SNAPSHOT</denizen.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,36 +189,35 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("address")) {
return new ElementTag(httpExchange.getRemoteAddress().toString());
}
else if (name.equals("query")) {
String query = httpExchange.getRequestURI().getQuery();
return new ElementTag(query != null ? query : "");
}
else if (name.equals("query_map")) {
MapTag mappedValues = new MapTag();
String query = httpExchange.getRequestURI().getQuery();
if (query != null) {
for (String value : CoreUtilities.split(query, '&')) {
List<String> split = CoreUtilities.split(value, '=', 2);
try {
String split_key = java.net.URLDecoder.decode(split.get(0), "UTF-8");
String split_value = java.net.URLDecoder.decode(split.get(1), "UTF-8");
mappedValues.putObject(split_key, new ElementTag(split_value));
}
catch (UnsupportedEncodingException e) {
Debug.echoError(e);
switch (name) {
case "address":
return new ElementTag(httpExchange.getRemoteAddress().toString());
case "query": {
String query = httpExchange.getRequestURI().getQuery();
return new ElementTag(query != null ? query : "");
}
case "query_map": {
MapTag mappedValues = new MapTag();
String query = httpExchange.getRequestURI().getQuery();
if (query != null) {
for (String value : CoreUtilities.split(query, '&')) {
List<String> split = CoreUtilities.split(value, '=', 2);
try {
String split_key = java.net.URLDecoder.decode(split.get(0), "UTF-8");
String split_value = java.net.URLDecoder.decode(split.get(1), "UTF-8");
mappedValues.putObject(split_key, new ElementTag(split_value));
}
catch (UnsupportedEncodingException e) {
Debug.echoError(e);
}
}
}
return mappedValues;
}
return mappedValues;
}
else if (name.equals("request")) {
return new ElementTag(httpExchange.getRequestURI().getPath());
}
else if (name.equals("user_info")) {
return new ElementTag(httpExchange.getRequestURI().getUserInfo());
case "request":
return new ElementTag(httpExchange.getRequestURI().getPath());
case "user_info":
return new ElementTag(httpExchange.getRequestURI().getUserInfo());
}
return super.getContext(name);
}
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/space/morphanone/webizen/server/WebServer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package space.morphanone.webizen.server;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import space.morphanone.webizen.events.GetRequestScriptEvent;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;

public class WebServer {

Expand All @@ -16,23 +13,15 @@ public class WebServer {
public static void start(int port) throws IOException {
if (!isRunning()) {
httpServer = HttpServer.create(new InetSocketAddress(port), 0);
httpServer.createContext("/", new HttpHandler() {
@Override
public void handle(HttpExchange httpExchange) throws IOException {
if (httpExchange.getRequestMethod().equalsIgnoreCase("GET")) {
GetRequestScriptEvent.instance.fire(httpExchange);
}
//else if (httpExchange.getRequestMethod().equalsIgnoreCase("POST")) {
// PostRequestScriptEvent.instance.fire(httpExchange);
//}
}
});
httpServer.setExecutor(new Executor() {
@Override
public void execute(final Runnable command) {
command.run();
httpServer.createContext("/", httpExchange -> {
if (httpExchange.getRequestMethod().equalsIgnoreCase("GET")) {
GetRequestScriptEvent.instance.fire(httpExchange);
}
//else if (httpExchange.getRequestMethod().equalsIgnoreCase("POST")) {
// PostRequestScriptEvent.instance.fire(httpExchange);
//}
});
httpServer.setExecutor(Runnable::run);
httpServer.start();
}
}
Expand Down

0 comments on commit 7f6cad5

Please sign in to comment.