Skip to content

Commit

Permalink
feat: remove advancedcore (#4)
Browse files Browse the repository at this point in the history
* feat: remove advancedcore

* feat: remove advancedcore
  • Loading branch information
rexlManu authored Feb 12, 2024
1 parent 622a6ff commit 4571a04
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 227 deletions.
8 changes: 0 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ repositories {
maven {
url 'https://repo.papermc.io/repository/maven-public/'
}
maven {
url 'https://nexus.bencodez.com/repository/maven-public/'
}
maven {
url 'https://nexuslite.gcnt.net/repos/other/'
}
}

dependencies {
compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'

implementation 'com.bencodez:advancedcore:3.7.3'
}

processResources {
Expand Down
276 changes: 101 additions & 175 deletions src/main/java/net/simplyvanilla/simplyvotifier/SimplyVotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,217 +18,143 @@

package net.simplyvanilla.simplyvotifier;

import com.bencodez.advancedcore.AdvancedCorePlugin;
import com.bencodez.advancedcore.folialib.FoliaLib;
import java.io.File;
import java.security.KeyPair;
import lombok.Getter;
import lombok.Setter;
import net.simplyvanilla.simplyvotifier.config.Config;
import net.simplyvanilla.simplyvotifier.crypto.RSAIO;
import net.simplyvanilla.simplyvotifier.crypto.RSAKeygen;
import net.simplyvanilla.simplyvotifier.model.Vote;
import net.simplyvanilla.simplyvotifier.model.VotifierEvent;
import net.simplyvanilla.simplyvotifier.net.VoteReceiver;
import org.bukkit.Bukkit;

import java.io.File;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.security.KeyPair;
import org.bukkit.plugin.java.JavaPlugin;

/**
* The main Votifier plugin class.
*
* @author Blake Beaupain
* @author Kramer Campbell
*/
public class SimplyVotifier extends AdvancedCorePlugin {
public class SimplyVotifier extends JavaPlugin {

/**
* The Votifier instance.
*/
@Getter
private static SimplyVotifier instance;
/** The Votifier instance. */
@Getter private static SimplyVotifier instance;

@Getter
private FoliaLib foliaLib;
/** The vote receiver. */
@Getter private VoteReceiver voteReceiver;

public Config config;
/** The RSA key pair. */
@Getter @Setter private KeyPair keyPair;

/**
* The vote receiver.
*/
@Getter
private VoteReceiver voteReceiver;
@Override
public void onEnable() {
this.saveDefaultConfig();
this.reloadConfig();
File rsaDirectory = new File(this.getDataFolder() + "/rsa");

/**
* The RSA key pair.
/*
* Create RSA directory and keys if it does not exist; otherwise, read keys.
*/
@Getter
@Setter
private KeyPair keyPair;


@Override
public void onPostLoad() {
this.foliaLib = new FoliaLib(this);

File rsaDirectory = new File(getDataFolder() + "/rsa");

/*
* Create RSA directory and keys if it does not exist; otherwise, read keys.
*/
try {
if (!rsaDirectory.exists()) {
rsaDirectory.mkdir();
keyPair = RSAKeygen.generate(2048);
RSAIO.save(rsaDirectory, keyPair);
} else {
keyPair = RSAIO.load(rsaDirectory);
}
} catch (Exception ex) {
getLogger().severe("Error reading configuration file or RSA keys");
gracefulExit();
return;
}

loadVoteReceiver();
try {
if (!rsaDirectory.exists()) {
rsaDirectory.mkdir();
this.keyPair = RSAKeygen.generate(2048);
RSAIO.save(rsaDirectory, this.keyPair);
} else {
this.keyPair = RSAIO.load(rsaDirectory);
}
} catch (Exception ex) {
this.getLogger().severe("Error reading configuration file or RSA keys");
return;
}

private void loadVoteReceiver() {
try {
voteReceiver = new VoteReceiver(config.getHost(), config.getPort()) {

@Override
public void logWarning(String warn) {
getLogger().warning(warn);
}

@Override
public void logSevere(String msg) {
getLogger().severe(msg);
}

@Override
public void log(String msg) {
getLogger().info(msg);
}

@Override
public String getVersion() {
return getDescription().getVersion();
}

@Override
public KeyPair getKeyPair() {
return instance.getKeyPair();
}

@Override
public void debug(Exception e) {
instance.debug(e);
}

@Override
public void debug(String debug) {
instance.debug(debug);
}

@Override
public void callEvent(Vote vote) {
foliaLib.getImpl().runAsync(new Runnable() {
public void run() {
Bukkit.getServer().getPluginManager().callEvent(new VotifierEvent(vote));
}
});
}
};
voteReceiver.start();

getLogger().info("Votifier enabled.");
} catch (Exception ex) {
gracefulExit();
return;
}
}
this.loadVoteReceiver();
}

@Override
public void onDisable() {
// Interrupt the vote receiver.
if (voteReceiver != null) {
voteReceiver.shutdown();
}
getLogger().info("Votifier disabled.");
}
private void loadVoteReceiver() {
try {
this.voteReceiver =
new VoteReceiver(this.getConfig().getString("host"), this.getConfig().getInt("port")) {

private void gracefulExit() {
getLogger().severe("Votifier did not initialize properly!");
}
@Override
public void logWarning(String warn) {
SimplyVotifier.this.getLogger().warning(warn);
}

@Override
public void onPreLoad() {
instance = this;
@Override
public void logSevere(String msg) {
SimplyVotifier.this.getLogger().severe(msg);
}

config = new Config(this);
config.setup();
@Override
public void log(String msg) {
SimplyVotifier.this.getLogger().info(msg);
}

if (config.isJustCreated()) {
int openPort = 8192;
try {
ServerSocket s = new ServerSocket();
s.bind(new InetSocketAddress("0.0.0.0", 0));
openPort = s.getLocalPort();
s.close();
} catch (Exception e) {
@Override
public String getVersion() {
return SimplyVotifier.this.getDescription().getVersion();
}

@Override
public KeyPair getKeyPair() {
return instance.getKeyPair();
}
try {
// First time run - do some initialization.
getLogger().info("Configuring Votifier for the first time...");
config.getData().set("port", openPort);
config.saveData();

/*
* Remind hosted server admins to be sure they have the right port number.
*/
getLogger().info("------------------------------------------------------------------------------");
getLogger().info("Assigning Votifier to listen on an open port " + openPort
+ ". If you are hosting server on a");
getLogger().info("shared server please check with your hosting provider to verify that this port");
getLogger().info("is available for your use. Chances are that your hosting provider will assign");
getLogger().info("a different port, which you need to specify in config.yml");
getLogger().info("------------------------------------------------------------------------------");

} catch (Exception ex) {
getLogger().severe("Error creating configuration file");
debug(ex);

@Override
public void debug(Exception e) {
SimplyVotifier.this.getSLF4JLogger().error("Error in Votifier", e);
}
}
config.loadValues();

updateAdvancedCoreHook();
}
@Override
public void debug(String debug) {
SimplyVotifier.this.getSLF4JLogger().info(debug);
}

@Override
public void onUnLoad() {
@Override
public void callEvent(Vote vote) {
if (isFolia()) {
Bukkit.getAsyncScheduler()
.runNow(
SimplyVotifier.this,
scheduledTask -> {
Bukkit.getServer().getPluginManager().callEvent(new VotifierEvent(vote));
});
} else {
Bukkit.getScheduler()
.runTask(
SimplyVotifier.this,
() ->
Bukkit.getServer()
.getPluginManager()
.callEvent(new VotifierEvent(vote)));
}
}
};
this.voteReceiver.start();

this.getLogger().info("Votifier enabled.");
} catch (Exception e) {
this.getSLF4JLogger().error("Error in Votifier", e);
}
}

@Override
public void reload() {
config.reloadData();
updateAdvancedCoreHook();
voteReceiver.shutdown();
loadVoteReceiver();
@Override
public void onDisable() {
// Interrupt the vote receiver.
if (this.voteReceiver != null) {
this.voteReceiver.shutdown();
}

@SuppressWarnings("deprecation")
public void updateAdvancedCoreHook() {
setConfigData(config.getData());
setLoadRewards(false);
setLoadServerData(false);
setLoadUserData(false);
setLoadGeyserAPI(false);
setLoadLuckPerms(false);
this.getLogger().info("Votifier disabled.");
}

public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}

}
}
39 changes: 0 additions & 39 deletions src/main/java/net/simplyvanilla/simplyvotifier/config/Config.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
# Debug levels:
# NONE
# INFO
# EXTRA
DebugLevel: NONE
host: 0.0.0.0
port: 8192

0 comments on commit 4571a04

Please sign in to comment.