Skip to content

Commit

Permalink
initial: First version of the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
samfces committed Oct 14, 2022
0 parents commit 9d7e702
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea/
/target/
91 changes: 91 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.v4guard</groupId>
<artifactId>v4guard-account-shield</artifactId>
<version>1.0.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>5.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<finalName>v4Guard-account-shield-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.1-SNAPSHOT</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>org.mongodb:bson</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.bson</pattern>
<shadedPattern>io.v4guard.shaded.org.bson</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
7 changes: 7 additions & 0 deletions src/main/java/io/v4guard/shield/core/auth/AuthType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.v4guard.shield.core.auth;

public enum AuthType {

LOGIN, REGISTER, UNKNOWN;

}
27 changes: 27 additions & 0 deletions src/main/java/io/v4guard/shield/core/auth/Authentication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.v4guard.shield.core.auth;

import org.bson.Document;

public class Authentication {

private final String username;
private final AuthType authType;

public Authentication(String username, AuthType authType) {
this.username = username;
this.authType = authType;
}

public String getUsername() {
return username;
}

public AuthType getAuthType() {
return authType;
}

public Document serialize(){
return new Document("username", username)
.append("authType", authType.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.v4guard.shield.core.hook;

public interface AuthenticationHook {


}
16 changes: 16 additions & 0 deletions src/main/java/io/v4guard/shield/core/messaging/PluginMessager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.v4guard.shield.core.messaging;

import io.v4guard.shield.core.auth.Authentication;

public abstract class PluginMessager {

// This is a bit of a "dirty" solution.
// If we place a custom channel name the message does not reach BungeeCord/Velocity.
// We will temporarily use the BungeeCord channel until we find a solution to the problem.
// protected static final String CHANNEL = "v4guard:accountshield";

protected static final String CHANNEL = "BungeeCord";

public abstract void sendMessage(Authentication authentication);

}
7 changes: 7 additions & 0 deletions src/main/java/io/v4guard/shield/core/mode/ShieldMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.v4guard.shield.core.mode;

public enum ShieldMode {

UNKNOWN, SPIGOT;

}
48 changes: 48 additions & 0 deletions src/main/java/io/v4guard/shield/core/v4GuardShieldCore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.v4guard.shield.core;

import io.v4guard.shield.core.messaging.PluginMessager;
import io.v4guard.shield.core.mode.ShieldMode;

import java.util.logging.Logger;

public class v4GuardShieldCore {

private static v4GuardShieldCore INSTANCE;
private PluginMessager messager;
private Logger logger;

private ShieldMode shieldMode;

public static final String pluginVersion = "1.0.0";

public v4GuardShieldCore(ShieldMode mode) {
INSTANCE = this;
this.shieldMode = mode;
initializeLogger();
}

public void initializeLogger(){
logger = Logger.getLogger("v4Guard");
logger.setUseParentHandlers(true);
}

public Logger getLogger() {
return logger;
}

public ShieldMode getShieldMode() {
return shieldMode;
}

public PluginMessager getMessager() {
return messager;
}

public void setMessager(PluginMessager messager) {
this.messager = messager;
}

public static v4GuardShieldCore getInstance() {
return INSTANCE;
}
}
35 changes: 35 additions & 0 deletions src/main/java/io/v4guard/shield/spigot/hooks/AuthMeSpigotHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.v4guard.shield.spigot.hooks;

import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RegisterEvent;
import io.v4guard.shield.core.auth.AuthType;
import io.v4guard.shield.core.auth.Authentication;
import io.v4guard.shield.core.hook.AuthenticationHook;
import io.v4guard.shield.core.v4GuardShieldCore;
import io.v4guard.shield.spigot.v4GuardShieldSpigot;
import org.bson.Document;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

public class AuthMeSpigotHook implements AuthenticationHook, Listener {

public AuthMeSpigotHook(JavaPlugin plugin) {
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
Bukkit.getServer().getConsoleSender().sendMessage("§c[v4guard-account-shield] (Spigot) Hooked into AuthMe");
}

@EventHandler
public void onLogin(LoginEvent event) {
Authentication auth = new Authentication(event.getPlayer().getName(), AuthType.LOGIN);
v4GuardShieldCore.getInstance().getMessager().sendMessage(auth);
}

@EventHandler
public void onRegister(RegisterEvent event) {
Authentication auth = new Authentication(event.getPlayer().getName(), AuthType.REGISTER);
v4GuardShieldCore.getInstance().getMessager().sendMessage(auth);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.v4guard.shield.spigot.messaging;

import io.v4guard.shield.core.auth.Authentication;
import io.v4guard.shield.core.messaging.PluginMessager;
import io.v4guard.shield.spigot.v4GuardShieldSpigot;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class SpigotPluginMessager extends PluginMessager {

public SpigotPluginMessager(JavaPlugin plugin) {
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PluginMessager.CHANNEL);
}

@Override
public void sendMessage(Authentication auth) {
Player player = Bukkit.getPlayer(auth.getUsername());
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {

System.out.println((auth.serialize().toJson()));
System.out.println(PluginMessager.CHANNEL);
System.out.println(v4GuardShieldSpigot.getInstance() != null);

out.writeUTF(auth.serialize().toJson());
player.sendPluginMessage(v4GuardShieldSpigot.getInstance(),
PluginMessager.CHANNEL,
b.toByteArray()
);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/io/v4guard/shield/spigot/v4GuardShieldSpigot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.v4guard.shield.spigot;

import io.v4guard.shield.core.hook.AuthenticationHook;
import io.v4guard.shield.core.mode.ShieldMode;
import io.v4guard.shield.core.v4GuardShieldCore;
import io.v4guard.shield.spigot.hooks.AuthMeSpigotHook;
import io.v4guard.shield.spigot.messaging.SpigotPluginMessager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class v4GuardShieldSpigot extends JavaPlugin {

private static v4GuardShieldCore core;
private static v4GuardShieldSpigot v4GuardSpigot;
private AuthenticationHook authHook;

@Override
public void onEnable(){
this.getServer().getConsoleSender().sendMessage("§e[v4guard-account-shield] (Spigot) Enabling...");
try {
core = new v4GuardShieldCore(ShieldMode.SPIGOT);
core.setMessager(new SpigotPluginMessager(this));
checkForHooks();
} catch (Exception e) {
this.getServer().getConsoleSender().sendMessage("§c[v4guard-account-shield] (Spigot) Enabling... [ERROR]");
this.getServer().getConsoleSender().sendMessage("§cPlease check the console for more information and report this error.");
e.printStackTrace();
Bukkit.getPluginManager().disablePlugin(this);
}
v4GuardSpigot = this;
this.getServer().getConsoleSender().sendMessage("§e[v4guard-account-shield] (Spigot) Enabling... [DONE]");
}

public static v4GuardShieldCore getShieldInstance() {
return core;
}

public static v4GuardShieldSpigot getInstance() {
return v4GuardSpigot;
}

public AuthenticationHook getAuthHook() {
return authHook;
}

private void checkForHooks(){
if(Bukkit.getPluginManager().getPlugin("AuthMe") != null){
this.authHook = new AuthMeSpigotHook(this);
}
//TODO add support for JPremium, nLogin
}
}
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: v4guard-account-shield
version: ${project.version}
main: io.v4guard.shield.spigot.v4GuardShieldSpigot
author: DigitalSynware
softdepend:
- AuthMe
12 changes: 12 additions & 0 deletions v4guard-account-shield.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>

0 comments on commit 9d7e702

Please sign in to comment.