Update to Chroma-Core 1.0
This commit is contained in:
parent
9d07c7bf2b
commit
71d1a652b4
8 changed files with 37 additions and 40 deletions
4
pom.xml
4
pom.xml
|
@ -119,8 +119,8 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
|
||||
<artifactId>Chroma-Core</artifactId>
|
||||
<version>${branch}-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -301,7 +301,7 @@ public class AcmeClient {
|
|||
*/
|
||||
public static void main(String... args) {
|
||||
if (args.length == 0) {
|
||||
TBMCCoreAPI.SendException("Error while doing ACME!", new Exception("No domains given"));
|
||||
LOG.error("Error while doing ACME!", new Exception("No domains given"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package buttondevteam.website;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.website.io.IOHelper;
|
||||
import buttondevteam.website.page.*;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
@ -13,7 +13,6 @@ import org.bouncycastle.openssl.PEMKeyPair;
|
|||
import org.bouncycastle.openssl.PEMParser;
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
|
@ -29,7 +28,7 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ButtonWebsiteModule extends JavaPlugin {
|
||||
public class ButtonWebsiteModule extends ButtonPlugin {
|
||||
private static HttpsServer server;
|
||||
/**
|
||||
* For ACME validation and user redirection
|
||||
|
@ -110,13 +109,13 @@ public class ButtonWebsiteModule extends JavaPlugin {
|
|||
});
|
||||
enabled = true;
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occurred while starting the webserver!", e);
|
||||
TBMCCoreAPI.SendException("An error occurred while starting the webserver!", e, this);
|
||||
enabled = false; //It's not even enabled yet, so we need a variable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void pluginEnable() {
|
||||
if (!enabled) {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
|
@ -126,8 +125,8 @@ public class ButtonWebsiteModule extends JavaPlugin {
|
|||
addPage(new ProfilePage());
|
||||
addPage(new BuildNotificationsPage());
|
||||
addPage(new BridgePage());
|
||||
TBMCCoreAPI.RegisterUserClass(WebUser.class);
|
||||
TBMCChatAPI.AddCommand(this, LoginCommand.class);
|
||||
TBMCCoreAPI.RegisterUserClass(WebUser.class, WebUser::new);
|
||||
getCommand2MC().registerCommand(new LoginCommand());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
this.getLogger().info("Starting webserver...");
|
||||
server.setExecutor(
|
||||
|
@ -145,6 +144,10 @@ public class ButtonWebsiteModule extends JavaPlugin {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void pluginDisable() {
|
||||
}
|
||||
|
||||
private static boolean httpstarted = false;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,27 +1,23 @@
|
|||
package buttondevteam.website;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.PlayerCommandBase;
|
||||
import buttondevteam.lib.chat.ICommand2;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import buttondevteam.website.page.LoginPage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass
|
||||
public class LoginCommand extends PlayerCommandBase {
|
||||
@Override //TODO: Ask about linking already existing accounts, to prevent linking someone else's
|
||||
public boolean OnCommand(Player player, String s, String[] strings) {
|
||||
@CommandClass(helpText = {//
|
||||
"§6---- Login ----", //
|
||||
"This command allows you to log in to our website using your Minecraft account.", //
|
||||
"If you are already logged in to the site, you can connect your MC account to it.", //
|
||||
"This is good for getting Minecraft rewards if you're a patron for example." //
|
||||
})
|
||||
public class LoginCommand extends ICommand2MC {
|
||||
//TODO: Ask about linking already existing accounts, to prevent linking someone else's
|
||||
public boolean def(Player player) {
|
||||
String state = LoginPage.generateState("minecraft", player.getUniqueId().toString()).toString();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " [\"\",{\"text\":\"Please \",\"color\":\"aqua\"},{\"text\":\"Click Here\",\"color\":\"aqua\",\"bold\":true,\"underlined\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://server.figytuna.com/login?type=minecraft&state=" + state + "\"}},{\"text\":\" to log in to our site using your Minecraft account.\",\"color\":\"aqua\",\"bold\":false,\"underlined\":false}]");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String s) {
|
||||
return new String[]{//
|
||||
"§6---- Login ----", //
|
||||
"This command allows you to log in to our website using your Minecraft account.", //
|
||||
"If you are already logged in to the site, you can connect your MC account to it.", //
|
||||
"This is good for getting Minecraft rewards if you're a patron for example." //
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package buttondevteam.website;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import buttondevteam.lib.player.UserClass;
|
||||
|
||||
@UserClass(foldername = "web")
|
||||
|
@ -16,7 +16,6 @@ public class WebUser extends ChromaGamerBase {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
public PlayerData<UUID> sessionID() {
|
||||
return data(new UUID(0, 0)); //It's used with toString() directly, so can't be null
|
||||
}
|
||||
//It's used with toString() directly, so can't be null
|
||||
public ConfigData<UUID> sessionID = getConfig().getData("sessionID", new UUID(0, 0));
|
||||
}
|
||||
|
|
|
@ -84,16 +84,14 @@ public class IOHelper {
|
|||
*/
|
||||
public static void LoginUser(HttpExchange exchange, WebUser user) {
|
||||
Bukkit.getLogger().fine("Logging in user: " + user);
|
||||
user.sessionID().set(UUID.randomUUID());
|
||||
user.save();
|
||||
user.sessionID.set(UUID.randomUUID());
|
||||
new Cookies(2).add(new Cookie("user_id", user.getUUID() + ""))
|
||||
.add(new Cookie("session_id", user.sessionID().get().toString())).AddHeaders(exchange);
|
||||
.add(new Cookie("session_id", user.sessionID.get().toString())).AddHeaders(exchange);
|
||||
Bukkit.getLogger().fine("Logged in user.");
|
||||
}
|
||||
|
||||
public static void LogoutUser(HttpExchange exchange, WebUser user) {
|
||||
user.sessionID().set(new UUID(0, 0));
|
||||
user.save();
|
||||
user.sessionID.set(new UUID(0, 0));
|
||||
SendLogoutHeaders(exchange);
|
||||
}
|
||||
|
||||
|
@ -147,7 +145,7 @@ public class IOHelper {
|
|||
return null;
|
||||
WebUser user = ChromaGamerBase.getUser(cookies.get("user_id").getValue(), WebUser.class);
|
||||
if (user != null && cookies.get("session_id") != null
|
||||
&& cookies.get("session_id").getValue().equals(user.sessionID().get().toString())) {
|
||||
&& cookies.get("session_id").getValue().equals(user.sessionID.get().toString())) {
|
||||
if (cookies.getExpireTimeParsed().minusYears(1).isBefore(ZonedDateTime.now(ZoneId.of("GMT"))))
|
||||
LoginUser(exchange, user);
|
||||
return user;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package buttondevteam.website.page;
|
||||
|
||||
import buttondevteam.core.component.updater.PluginUpdater;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.website.io.IOHelper;
|
||||
import buttondevteam.website.io.Response;
|
||||
|
@ -52,8 +51,8 @@ public class BuildNotificationsPage extends Page {
|
|||
if (signatures != null && signatures.size() > 0 && post.containsKey("payload")
|
||||
&& verifySignature(payload.getBytes(StandardCharsets.UTF_8),
|
||||
Base64.getDecoder().decode(signatures.get(0)))) {
|
||||
Bukkit.getPluginManager()
|
||||
.callEvent(new PluginUpdater.UpdatedEvent(gson.fromJson(payload, JsonObject.class)));
|
||||
/*Bukkit.getPluginManager()
|
||||
.callEvent(new PluginUpdater.UpdatedEvent(gson.fromJson(payload, JsonObject.class)));*/
|
||||
return new Response(200, "All right", exchange);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.website.page;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.website.ButtonWebsiteModule;
|
||||
import buttondevteam.website.io.IOHelper;
|
||||
import buttondevteam.website.io.Response;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
@ -25,7 +26,8 @@ public abstract class Page implements HttpHandler {
|
|||
IOHelper.SendResponse(404, "404 Not found: " + exchange.getRequestURI().getPath(), exchange);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e);
|
||||
ButtonWebsiteModule module = ButtonWebsiteModule.getPlugin(ButtonWebsiteModule.class);
|
||||
TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e, module);
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream str = new PrintStream(baos);
|
||||
|
@ -34,7 +36,7 @@ public abstract class Page implements HttpHandler {
|
|||
str.print("</pre>");
|
||||
IOHelper.SendResponse(500, baos.toString("UTF-8"), exchange);
|
||||
} catch (Exception e1) {
|
||||
TBMCCoreAPI.SendException("Exception while sending Internal Server Error in ButtonWebsiteModule!", e1);
|
||||
TBMCCoreAPI.SendException("Exception while sending Internal Server Error in ButtonWebsiteModule!", e1, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue