Skip to content

Commit

Permalink
Merge pull request #180 from Picono435/development
Browse files Browse the repository at this point in the history
Update to 1.0-beta-6a
  • Loading branch information
Picono435 authored Mar 16, 2022
2 parents b505cbe + 0e3b312 commit 08c8864
Show file tree
Hide file tree
Showing 44 changed files with 664 additions and 635 deletions.
64 changes: 27 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
import org.apache.tools.ant.filters.*

buildscript {
dependencies {
classpath fileTree(dir: './gradle/',
includes: ['versioning.jar'])
}
}

plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'io.github.slimjar' version '1.3.0'
id 'java'
id 'maven-publish'
id 'net.nemerosa.versioning' version '2.14.0'
id 'net.nemerosa.versioning' version '2.15.1'
}

group = 'com.gmail.picono435'
description = 'The best jobs plugin ever! You can customize every single thing on it.'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

versioning {
releaseMode = { nextTag, lastTag, currentTag, extension ->
"1.0-beta-5"
} as Object
}

if (System.getenv("STABLE_BUILD") != null) {
if (System.getenv("STABLE_BUILD") == '1') {
version versioning.info.build + "-DEV"
} else {
version versioning.info.display
version "1.0-beta-6"
}
} else {
version versioning.info.display
version versioning.info.build + "-DEV"
}

repositories {
Expand Down Expand Up @@ -80,45 +67,46 @@ repositories {

dependencies {
// Slimjar
implementation slimjar("1.2.6")
shadow implementation(slimjar("1.2.6"))
// Spigot
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
// Storage Methods
slim 'org.mongodb:mongodb-driver-sync:4.4.0'
slim 'org.mongodb:mongodb-driver-sync:4.5.0'
slim 'com.zaxxer:HikariCP:4.0.3'
slim 'com.h2database:h2:1.4.200'
slim 'org.xerial:sqlite-jdbc:3.36.0.3'
slim 'org.mariadb.jdbc:mariadb-java-client:2.7.4'
slim 'mysql:mysql-connector-java:8.0.27'
implementation 'org.spongepowered:configurate-core:4.1.2'
implementation 'org.spongepowered:configurate-gson:4.1.2'
implementation 'org.spongepowered:configurate-yaml:4.1.2'
implementation 'org.spongepowered:configurate-hocon:4.1.2'
slim 'org.mariadb.jdbc:mariadb-java-client:3.0.3'
slim 'mysql:mysql-connector-java:8.0.28'
shadow implementation('org.spongepowered:configurate-core:4.1.2')
shadow implementation('org.spongepowered:configurate-gson:4.1.2')
shadow implementation('org.spongepowered:configurate-yaml:4.1.2')
shadow implementation('org.spongepowered:configurate-hocon:4.1.2')
// Plugins API
compileOnly('me.clip:placeholderapi:2.10.10') { transitive = false }
compileOnly('me.clip:placeholderapi:2.11.1') { transitive = false }
compileOnly('com.github.MilkBowl:VaultAPI:1.7.1') { transitive = false }
compileOnly('org.black_ixx:playerpoints:3.1.0') { transitive = false }
compileOnly('org.black_ixx:playerpoints:3.2.0') { transitive = false }
compileOnly('com.github.Realizedd:TokenManager:3.2.4') { transitive = false }
// Other libraries
implementation 'com.github.mkremins:fanciful:18dc039f5b'
slim 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
slim 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.0'
implementation 'org.apache.maven:maven-artifact:3.8.4'
implementation 'org.bstats:bstats-bukkit:2.2.1'
slim 'org.slf4j:slf4j-simple:1.7.32'
slim 'org.slf4j:slf4j-api:1.7.32'
shadow implementation('com.github.mkremins:fanciful:18dc039f5b')
slim 'com.fasterxml.jackson.core:jackson-databind:2.13.1'
slim 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.1'
shadow implementation('org.apache.maven:maven-artifact:3.8.4')
shadow implementation('org.bstats:bstats-bukkit:3.0.0')
slim 'org.slf4j:slf4j-simple:1.7.36'
slim 'org.slf4j:slf4j-api:1.7.36'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testCompileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
testCompileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
testCompileOnly('me.clip:placeholderapi:2.10.10') { transitive = false }
testCompileOnly('com.github.MilkBowl:VaultAPI:1.7') { transitive = false }
testCompileOnly('org.black_ixx:playerpoints:3.0.3') { transitive = false }
testCompileOnly('org.black_ixx:playerpoints:3.1.1') { transitive = false }
testCompileOnly('com.github.Realizedd:TokenManager:3.2.4') { transitive = false }
}

slimJar {
relocate 'org.mongodb', 'com.gmail.picono435.picojobs.libs.mongodb'
relocate 'com.zaxxer', 'com.gmail.picono435.picojobs.libs.zaxxer'
relocate 'org.h2', 'com.gmail.picono435.picojobs.libs.h2'
relocate 'com.h2database', 'com.gmail.picono435.picojobs.libs.h2database'
relocate 'org.xerial', 'com.gmail.picono435.picojobs.libs.xerial'
relocate 'org.mariadb.jbdc', 'com.gmail.picono435.picojobs.libs.mariadb'
Expand Down Expand Up @@ -177,3 +165,5 @@ publishing {
mavenLocal()
}
}

compileTestJava.dependsOn(shadowJar)
Binary file removed gradle/versioning.jar
Binary file not shown.
148 changes: 88 additions & 60 deletions src/main/java/com/gmail/picono435/picojobs/PicoJobsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import java.io.*;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.*;

import com.gmail.picono435.picojobs.storage.sql.file.H2Storage;
import com.gmail.picono435.picojobs.hooks.economy.CommandImplementation;
import com.gmail.picono435.picojobs.hooks.economy.ItemImplementation;
import com.gmail.picono435.picojobs.listeners.jobs.*;
import com.gmail.picono435.picojobs.storage.sql.H2Storage;
import com.gmail.picono435.picojobs.utils.GitHubAPI;
import io.github.slimjar.resolver.data.Mirror;
import io.github.slimjar.resolver.data.Repository;
import io.github.slimjar.resolver.mirrors.MirrorSelector;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.DrilldownPie;
Expand Down Expand Up @@ -46,28 +45,15 @@
import com.gmail.picono435.picojobs.listeners.ClickInventoryListener;
import com.gmail.picono435.picojobs.listeners.CreatePlayerListener;
import com.gmail.picono435.picojobs.listeners.ExecuteCommandListener;
import com.gmail.picono435.picojobs.listeners.jobs.FisherListener;
import com.gmail.picono435.picojobs.listeners.jobs.KillEntityListener;
import com.gmail.picono435.picojobs.listeners.jobs.KillerListener;
import com.gmail.picono435.picojobs.listeners.jobs.MilkListener;
import com.gmail.picono435.picojobs.listeners.jobs.PlaceListener;
import com.gmail.picono435.picojobs.listeners.jobs.RepairListener;
import com.gmail.picono435.picojobs.listeners.jobs.ShearListener;
import com.gmail.picono435.picojobs.listeners.jobs.SmeltListener;
import com.gmail.picono435.picojobs.listeners.jobs.TameListener;
import com.gmail.picono435.picojobs.listeners.jobs.BreakListener;
import com.gmail.picono435.picojobs.listeners.jobs.CraftListener;
import com.gmail.picono435.picojobs.listeners.jobs.EatListener;
import com.gmail.picono435.picojobs.listeners.jobs.EnchantListener;
import com.gmail.picono435.picojobs.listeners.jobs.FillListener;
import com.gmail.picono435.picojobs.api.managers.LanguageManager;
import com.gmail.picono435.picojobs.utils.FileCreator;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import io.github.slimjar.app.builder.ApplicationBuilder;
import org.codehaus.plexus.util.FileUtils;
import org.h2.tools.RunScript;
import org.h2.tools.Script;

public class PicoJobsPlugin extends JavaPlugin {

Expand Down Expand Up @@ -101,12 +87,7 @@ public void onLoad() {
sendConsoleMessage(Level.INFO, "Loading dependencies, this might take some minutes when ran for the first time...");
ApplicationBuilder
.appending("PicoJobs")
.mirrorSelector(new MirrorSelector() {
@Override
public Collection<Repository> select(Collection<Repository> collection, Collection<Mirror> collection1) throws MalformedURLException {
return collection;
}
})
.mirrorSelector((collection, collection1) -> collection)
.downloadDirectoryPath(getDataFolder().toPath().resolve("libraries"))
.internalRepositories(Collections.singleton(new Repository(new URL("https://repo.maven.apache.org/maven2/"))))
.build();
Expand All @@ -125,7 +106,7 @@ public void onEnable() {
if(checkLegacy() ) {
sendConsoleMessage(Level.WARNING, "Checked that you are using a LEGACY spigot/bukkit version. We will use the old Material Support.");
}

// CREATING AND CONFIGURING INTERNAL FILES
saveDefaultConfig();
loggingHandler = new ConsoleHandler();
Expand Down Expand Up @@ -162,6 +143,8 @@ public synchronized String format(LogRecord record) {

// SETTING UP AND REQUIRED AND OPTIONAL DEPENDENCIES
PicoJobsAPI.registerEconomy(new ExpImplementation());
PicoJobsAPI.registerEconomy(new CommandImplementation());
PicoJobsAPI.registerEconomy(new ItemImplementation());
VaultHook.setupVault();
PlayerPointsHook.setupPlayerPoints();
PicoJobsAPI.registerEconomy(new TokenManagerImplementation());
Expand All @@ -175,6 +158,22 @@ public void run() {
// GENERATE JOBS FROM CONFIGURATION
sendConsoleMessage(Level.INFO, "Generating jobs from configuration...");
if(!generateJobsFromConfig()) return;

// Fix my dumb way to migrate the database! This will be removed asap.
if(PicoJobsAPI.getSettingsManager().getStorageMethod().equalsIgnoreCase("H2")) {
try {
if(PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("script").toFile().exists()) {
RunScript.main("-url jdbc:h2:$f -script $script"
.replace("$f", PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("picojobs-h2").toAbsolutePath().toString())
.replace("$script", PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("script").toString())
.split(" "));
PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("script").toFile().deleteOnExit();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}

PicoJobsAPI.getStorageManager().initializeStorageFactory();
if(!isTestEnvironment) {
metrics.addCustomChart(new SingleLineChart("created_jobs", new Callable<Integer>() {
Expand Down Expand Up @@ -204,38 +203,32 @@ public Integer call() throws Exception {
Bukkit.getPluginManager().registerEvents(new EatListener(), this);
Bukkit.getPluginManager().registerEvents(new EnchantListener(), this);
Bukkit.getPluginManager().registerEvents(new MilkListener(), this);
Bukkit.getPluginManager().registerEvents(new MoveListener(), this);
Bukkit.getPluginManager().registerEvents(new TradeListener(), this);
Bukkit.getPluginManager().registerEvents(new RepairListener(), this);
Bukkit.getPluginManager().registerEvents(new SmeltListener(), this);
Bukkit.getPluginManager().registerEvents(new KillEntityListener(), this);

sendConsoleMessage(Level.INFO, "The plugin was succefully enabled.");

checkVersion();

if(getConfig().getBoolean("update-checker")) {
checkVersion();
}
}

public void onDisable() {
sendConsoleMessage(Level.INFO, "Disconnecting connection to storage...");
jobs.clear();

PicoJobsAPI.getStorageManager().destroyStorageFactory();

if(wasUpdated && PicoJobsAPI.getStorageManager().getStorageFactory() instanceof H2Storage) {
try {
// Copy the current database to a -old file
FileUtils.copyFile(PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("picojobs-h2.mv.db").toFile(), PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("picojobs-h2-old.mv.db").toFile());
// Set the path where the script file will be located
Path scriptFile = PicoJobsPlugin.getInstance().getDataFolder().toPath().resolve("storage").resolve("script").toAbsolutePath();
// Backup database to script
((H2Storage) PicoJobsAPI.getStorageManager().getStorageFactory()).backupDataTo(scriptFile.toFile());
PicoJobsAPI.getStorageManager().destroyStorageFactory();
// Delete the current database
PicoJobsPlugin.getInstance().getDataFolder().toPath().toAbsolutePath().resolve("storage").resolve("picojobs-h2.mv.db").toFile().delete();
sendConsoleMessage(Level.INFO, "The plugin was succefully disabled.");
return;
} catch (Exception e) {
Script.main("-url jdbc:h2:$f -script $f.zip -options compression zip".replace("$f", PicoJobsPlugin.getInstance().getDataFolder().toPath().toAbsolutePath().resolve("storage").resolve("picojobs-h2").toAbsolutePath().toString()).split(" "));
} catch (SQLException e) {
e.printStackTrace();
}
}

PicoJobsAPI.getStorageManager().destroyStorageFactory();

sendConsoleMessage(Level.INFO, "The plugin was succefully disabled.");
}
Expand All @@ -254,21 +247,35 @@ public void debugMessage(String message) {
public Handler getLoggingHandler() {
return loggingHandler;
}

public boolean isNewerThan(String version) {

/*
* Same as having serverVersion >= specifiedVersion
* Example: 1.18.1 >= 1.12.2
*
* @param version
* @return
*/
public boolean isMoreThan(String version) {
DefaultArtifactVersion legacyVersion = new DefaultArtifactVersion(version);
DefaultArtifactVersion serverVersionArt = new DefaultArtifactVersion(serverVersion);
if(legacyVersion.compareTo(serverVersionArt) >= 0) {
if(serverVersionArt.compareTo(legacyVersion) >= 0) {
return true;
} else {
return false;
}
}

public boolean isOlderThan(String version) {

/*
* Same as having serverVersion <= specifiedVersion
* Example: 1.18.1 <= 1.12.2
*
* @param version
* @return
*/
public boolean isLessThan(String version) {
DefaultArtifactVersion legacyVersion = new DefaultArtifactVersion(version);
DefaultArtifactVersion serverVersionArt = new DefaultArtifactVersion(serverVersion);
if(legacyVersion.compareTo(serverVersionArt) <= 0) {
if(serverVersionArt.compareTo(legacyVersion) <= 0) {
return true;
} else {
return false;
Expand Down Expand Up @@ -298,17 +305,18 @@ public boolean generateJobsFromConfig() {
debugMessage("Display name: " + displayname);
String tag = jobc.getString("tag");
debugMessage("Tag: " + tag);
List<Type> types;
if(jobc.contains("types")) {
types = Type.getTypes(jobc.getStringList("types"));
} else {
types = new ArrayList<Type>();
}
if(jobc.contains("type")) {
String typeString = jobc.getString("type");
types.add(Type.getType(typeString.toUpperCase(Locale.ROOT)));
jobc.set("types", Collections.singletonList(typeString));
jobc.set("type", null);
try {
FileCreator.getJobsConfig().save(FileCreator.getJobsFile());
} catch (IOException e) {
e.printStackTrace();
}
}
debugMessage("Types: " + types);
List<Type> types = Type.getTypes(jobc.getStringList("types"));
debugMessage("Types: " + Arrays.toString(types.toArray()));
double method = jobc.getDouble("method");
debugMessage("Method: " + method);
double salary = jobc.getDouble("salary");
Expand All @@ -331,13 +339,33 @@ public boolean generateJobsFromConfig() {
String item = guic.getString("item");
int itemData = guic.getInt("item-data");
boolean enchanted = guic.getBoolean("enchanted");
List<String> lore = guic.getStringList("lore");

// CALCULATING OPTIONALS

boolean useWhitelist = jobc.getBoolean("use-whitelist");
List<String> whitelist = jobc.getStringList("whitelist");
Map<Type, List<String>> whitelist = new HashMap<>();
if(jobc.contains("whitelist")) {
// Legacy: Will be removed in future update
if(jobc.get("whitelist") instanceof List) {
List<String> white = jobc.getStringList("whitelist");
for(Type type : types) {
whitelist.put(type, white);
jobc.set("whitelist." + type.name(), white);
try {
FileCreator.getJobsConfig().save(FileCreator.getJobsFile());
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
for(String type : jobc.getConfigurationSection("whitelist").getKeys(false)) {
whitelist.put(Type.getType(type), jobc.getConfigurationSection("whitelist").getStringList(type));
}
}
}

Job job = new Job(jobid, displayname, tag, types, method, salary, maxSalary, requiresPermission, salaryFrequency, methodFrequency, economy, workMessage, slot, item, itemData, enchanted, useWhitelist, whitelist);
Job job = new Job(jobid, displayname, tag, types, method, salary, maxSalary, requiresPermission, salaryFrequency, methodFrequency, economy, workMessage, slot, item, itemData, enchanted, lore, useWhitelist, whitelist);

jobs.put(jobid, job);

Expand Down
Loading

0 comments on commit 08c8864

Please sign in to comment.