build: Rearrange to multi project build
This commit is contained in:
parent
4fa4a1f8bf
commit
2c5b124cae
|
@ -1,8 +1,9 @@
|
||||||
*.class
|
*.class
|
||||||
.*
|
.gradle
|
||||||
!.github
|
.idea
|
||||||
/build/
|
/build/
|
||||||
/target/
|
/target/
|
||||||
|
*/build/
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.war
|
*.war
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
let versionRegex = /(\nversion:\s)([0-9.-]+)/;
|
||||||
|
let velocityVersionRegex = /(\sversion\s=\s")([0-9.-]+)("\))/;
|
||||||
|
|
||||||
|
|
||||||
|
const ymlUpdater = {
|
||||||
|
updater: {
|
||||||
|
'readVersion': (contents) => {
|
||||||
|
return versionRegex.exec(contents)[2];
|
||||||
|
},
|
||||||
|
'writeVersion': (contents, version) => {
|
||||||
|
return contents.replace(versionRegex, `$1${version}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bungee = {
|
||||||
|
filename: 'src/main/resources/bungee.yml',
|
||||||
|
...ymlUpdater,
|
||||||
|
}
|
||||||
|
|
||||||
|
const plugin = {
|
||||||
|
filename: 'src/main/resources/plugin.yml',
|
||||||
|
...ymlUpdater,
|
||||||
|
}
|
||||||
|
|
||||||
|
const velocity_plugin = {
|
||||||
|
filename: 'src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java',
|
||||||
|
updater: {
|
||||||
|
'readVersion': (contents) => {
|
||||||
|
return velocityVersionRegex.exec(contents)[2];
|
||||||
|
},
|
||||||
|
'writeVersion': (contents, version) => {
|
||||||
|
return contents.replace(velocityVersionRegex, `$1${version}$3`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = [plugin, velocity_plugin, bungee];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
bumpFiles: files,
|
||||||
|
packageFiles: files,
|
||||||
|
// In case you need to force a version change (mostly due to change of scope of the update e.g. major now instead of patch)
|
||||||
|
//releaseAs: '1.0.0',
|
||||||
|
header:"# Changelog\n" +
|
||||||
|
"\n" +
|
||||||
|
"All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n" +
|
||||||
|
"\n" +
|
||||||
|
"For the release changelogs see [CHANGELOG.md](CHANGELOG.md) \n" +
|
||||||
|
"For the snapshot changelogs see [SNAPSHOT_CHANGELOG.md](SNAPSHOT_CHANGELOG.md)\n",
|
||||||
|
}
|
|
@ -8,6 +8,9 @@ An advanced portals plugin for bukkit made by sekwah41 designed to have a wide r
|
||||||
|
|
||||||
Also please use the markdown and not html for updates to this file, references can be found [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
|
Also please use the markdown and not html for updates to this file, references can be found [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
|
||||||
|
|
||||||
|
# Module Layout
|
||||||
|
* **api**: All code for adding tags using addons.
|
||||||
|
|
||||||
# Branch Layout
|
# Branch Layout
|
||||||
* [master](https://github.com/sekwah41/Advanced-Portals/) (Release Build) ![Build Status](https://travis-ci.org/sekwah41/Advanced-Portals.svg?branch=master)
|
* [master](https://github.com/sekwah41/Advanced-Portals/) (Release Build) ![Build Status](https://travis-ci.org/sekwah41/Advanced-Portals.svg?branch=master)
|
||||||
* [dev](https://github.com/sekwah41/Advanced-Portals/tree/dev) (Dev Build) ![Build Status](https://travis-ci.org/sekwah41/Advanced-Portals.svg?branch=dev)
|
* [dev](https://github.com/sekwah41/Advanced-Portals/tree/dev) (Dev Build) ![Build Status](https://travis-ci.org/sekwah41/Advanced-Portals.svg?branch=dev)
|
||||||
|
|
332
build.gradle
332
build.gradle
|
@ -1,16 +1,52 @@
|
||||||
apply plugin: 'java'
|
import org.apache.commons.codec.Charsets
|
||||||
apply plugin: 'maven'
|
import org.apache.http.HttpEntity
|
||||||
apply plugin: 'idea'
|
import org.apache.http.HttpResponse
|
||||||
apply plugin: 'eclipse'
|
import org.apache.http.client.HttpClient
|
||||||
|
import org.apache.http.client.config.CookieSpecs
|
||||||
|
import org.apache.http.client.config.RequestConfig
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse
|
||||||
|
import org.apache.http.client.methods.HttpPost
|
||||||
|
import org.apache.http.entity.ContentType
|
||||||
|
import org.apache.http.entity.mime.MultipartEntityBuilder
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder
|
||||||
|
import org.apache.http.impl.client.HttpClients
|
||||||
|
import org.apache.http.client.methods.HttpGet
|
||||||
|
import com.google.gson.Gson
|
||||||
|
|
||||||
archivesBaseName = "advancedportals"
|
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven-publish'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
maven {url "https://plugins.gradle.org/m2/"}
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.apache.httpcomponents:httpmime:4.5.13"
|
||||||
|
classpath "com.google.code.gson:gson:2.8.6"
|
||||||
|
classpath "org.apache.httpcomponents:httpclient:4.5.13"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
archivesBaseName = "Advanced-Portals"
|
||||||
group = 'com.sekwah.advancedportals'
|
group = 'com.sekwah.advancedportals'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
|
|
||||||
description = ""
|
description = ""
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
allprojects {
|
||||||
targetCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
}
|
||||||
|
|
||||||
|
def branch = System.getenv("GITHUB_REF");
|
||||||
|
def sha = System.getenv("GITHUB_SHA");
|
||||||
|
def isDevBranch = branch == null || !(branch.startsWith("refs/tags/") && !branch.contains("-"))
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = 'UTF-8'
|
||||||
|
@ -18,7 +54,7 @@ tasks.withType(JavaCompile) {
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
// configuration that holds jars to copy into lib
|
// configuration that holds jars to copy into lib
|
||||||
includeLibs
|
compile.extendsFrom(includeLibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -29,28 +65,237 @@ repositories {
|
||||||
|
|
||||||
// includeLibs just says to include the library in the final jar
|
// includeLibs just says to include the library in the final jar
|
||||||
dependencies {
|
dependencies {
|
||||||
includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
includeLibs project(':core')
|
||||||
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
//implementation project(':bungee')
|
||||||
includeLibs group: 'com.google.inject', name: 'guice', version:'4.0'
|
//implementation project(':spigot')
|
||||||
compile group: 'com.google.inject', name: 'guice', version:'4.0'
|
//implementation project(':velocity')
|
||||||
compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
|
|
||||||
|
|
||||||
|
|
||||||
// For spigot api
|
|
||||||
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"
|
|
||||||
|
|
||||||
// For bukkit api
|
|
||||||
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from configurations.includeLibs.collect { it.isDirectory() ? it : zipTree(it) }
|
// Filters the files out that are in the build folders. Look to see if there is a better way to do this?
|
||||||
|
from configurations.includeLibs.filter {
|
||||||
|
it.path.contains("\\build\\libs\\")
|
||||||
|
} .collect {
|
||||||
|
println("Including: ${it.name}")
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** For pre-releases and testers to be able to try the latest commits if they want.
|
||||||
|
* If the builds start exceeding 8MB then we may want to upload to s3 instead and periodically clear.
|
||||||
|
* TODO possibly add a task that announces when builds are made?
|
||||||
|
* Though add a note that it may take a while for Curse to approve the files.
|
||||||
|
*/
|
||||||
|
task discordupload {
|
||||||
|
dependsOn(jar)
|
||||||
|
doLast {
|
||||||
|
String discordWebhook = System.getenv("DISCORD_WEBHOOK")
|
||||||
|
|
||||||
|
if(discordWebhook != null) {
|
||||||
|
println("Logging Into Discord")
|
||||||
|
|
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault()
|
||||||
|
HttpPost uploadFile = new HttpPost(discordWebhook)
|
||||||
|
|
||||||
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
|
||||||
|
builder.addTextBody("content", "New automated dev build\n\n" +
|
||||||
|
"Current Features: <${project.github}/blob/${sha}/docs/changelogs/SNAPSHOT_CHANGELOG.md>")
|
||||||
|
|
||||||
|
builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName)
|
||||||
|
|
||||||
|
HttpEntity multipart = builder.build()
|
||||||
|
|
||||||
|
uploadFile.setEntity(multipart)
|
||||||
|
CloseableHttpResponse response = httpClient.execute(uploadFile)
|
||||||
|
response.getEntity()
|
||||||
|
|
||||||
|
println("Posted build")
|
||||||
|
|
||||||
|
} else {
|
||||||
|
println("Discord webhook unspecified")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static String getValueFromCurseAPI(apiKey, endpoint) {
|
||||||
|
String API_BASE_URL = 'https://minecraft.curseforge.com'
|
||||||
|
|
||||||
|
Gson gson = new Gson()
|
||||||
|
|
||||||
|
HttpClient client = HttpClientBuilder.create()
|
||||||
|
.setDefaultRequestConfig(RequestConfig.custom()
|
||||||
|
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()).build()
|
||||||
|
|
||||||
|
HttpGet get = new HttpGet(API_BASE_URL + endpoint)
|
||||||
|
get.setHeader('X-Api-Token', apiKey)
|
||||||
|
|
||||||
|
HttpResponse response = client.execute(get)
|
||||||
|
|
||||||
|
int statusCode = response.statusLine.statusCode
|
||||||
|
|
||||||
|
if (statusCode == 200) {
|
||||||
|
byte[] data = response.entity.content.bytes
|
||||||
|
return new String(data, Charsets.UTF_8)
|
||||||
|
} else {
|
||||||
|
if (response.getFirstHeader('content-type').value.contains('json')) {
|
||||||
|
InputStreamReader reader = new InputStreamReader(response.entity.content)
|
||||||
|
reader.close()
|
||||||
|
throw new RuntimeException("[CurseForge] Error")
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("[CurseForge] HTTP Error Code $response.statusLine.statusCode: $response.statusLine.reasonPhrase")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload a single file (in case you also want to upload the other files like source n stuff)
|
||||||
|
* @param json
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @throws URISyntaxException
|
||||||
|
*/
|
||||||
|
UploadResponse uploadFile(Metadata metadata, File file, String apiKey, Gson gson) throws IOException, URISyntaxException {
|
||||||
|
String API_BASE_URL = 'https://minecraft.curseforge.com'
|
||||||
|
String UPLOAD_URL = "/api/projects/%s/upload-file"
|
||||||
|
// Upload
|
||||||
|
// Important info
|
||||||
|
String uploadUrl = String.format(API_BASE_URL + UPLOAD_URL, project.curse_project_id)
|
||||||
|
|
||||||
|
HttpClient client = HttpClientBuilder.create()
|
||||||
|
.setDefaultRequestConfig(RequestConfig.custom()
|
||||||
|
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()).build()
|
||||||
|
|
||||||
|
HttpPost post = new HttpPost(uploadUrl)
|
||||||
|
post.setHeader('X-Api-Token', apiKey)
|
||||||
|
|
||||||
|
|
||||||
|
// https://support.curseforge.com/en/support/solutions/articles/9000197321-curseforge-api
|
||||||
|
post.setEntity(MultipartEntityBuilder.create()
|
||||||
|
.addTextBody('metadata', gson.toJson(metadata), ContentType.APPLICATION_JSON)
|
||||||
|
.addBinaryBody('file', file)
|
||||||
|
.build())
|
||||||
|
|
||||||
|
HttpResponse response = client.execute(post)
|
||||||
|
InputStreamReader reader = new InputStreamReader(response.entity.content)
|
||||||
|
UploadResponse uploadResponse = gson.fromJson(reader, UploadResponse)
|
||||||
|
reader.close()
|
||||||
|
return uploadResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
class GameVersion {
|
||||||
|
int id
|
||||||
|
int gameVersionTypeID
|
||||||
|
String name
|
||||||
|
String slug
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As described here https://support.curseforge.com/en/support/solutions/articles/9000197321-curseforge-api
|
||||||
|
*/
|
||||||
|
class Metadata {
|
||||||
|
String changelog
|
||||||
|
String changelogType
|
||||||
|
int[] gameVersions
|
||||||
|
String releaseType
|
||||||
|
}
|
||||||
|
|
||||||
|
class UploadResponse {
|
||||||
|
int id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Based on https://github.com/matthewprenger/CurseGradle as it didnt support Bukkit uploads at the time.
|
||||||
|
task curseforge {
|
||||||
|
dependsOn(jar)
|
||||||
|
doLast {
|
||||||
|
String apiKey = null
|
||||||
|
|
||||||
|
if (System.getenv("CURSE_API") != null) {
|
||||||
|
apiKey = System.getenv("CURSE_API")
|
||||||
|
}
|
||||||
|
|
||||||
|
if(apiKey != null) {
|
||||||
|
|
||||||
|
Gson gson = new Gson()
|
||||||
|
|
||||||
|
//String VERSION_TYPES_URL = "/api/game/version-types"
|
||||||
|
int gameVersionTypeID = 1
|
||||||
|
String VERSION_URL = "/api/game/versions"
|
||||||
|
println("Uploading to CurseForge")
|
||||||
|
|
||||||
|
// Get game versions
|
||||||
|
String gameVersionsString = getValueFromCurseAPI(apiKey, VERSION_URL)
|
||||||
|
GameVersion[] gameVersions = gson.fromJson(gameVersionsString, GameVersion[].class)
|
||||||
|
def versions = gameVersions.findAll {it.gameVersionTypeID == gameVersionTypeID}
|
||||||
|
|
||||||
|
String[] supportedVersions = [
|
||||||
|
"1.16",
|
||||||
|
"1.15",
|
||||||
|
"1.14",
|
||||||
|
"1.13"
|
||||||
|
]
|
||||||
|
|
||||||
|
def supportedGameVersions = versions.findAll {supportedVersions.contains(it.name)}
|
||||||
|
int[] supportedGameVersionIds = supportedGameVersions.collect {it.id}.toArray()
|
||||||
|
|
||||||
|
println("Supported Version Id's ${supportedGameVersionIds}")
|
||||||
|
|
||||||
|
Metadata uploadMetadata = new Metadata();
|
||||||
|
|
||||||
|
uploadMetadata.changelog = "${project.github}/blob/${sha}/docs/changelogs/CHANGELOG.md"
|
||||||
|
uploadMetadata.changelogType = "markdown"
|
||||||
|
uploadMetadata.releaseType = isDevBranch ? "beta" : "release"
|
||||||
|
uploadMetadata.gameVersions = supportedGameVersionIds
|
||||||
|
|
||||||
|
def uploadId = uploadFile(uploadMetadata, file(jar.archiveFile), apiKey, gson)
|
||||||
|
|
||||||
|
println("Uploaded with ID: ${uploadId.id}")
|
||||||
|
|
||||||
|
println("Published build")
|
||||||
|
|
||||||
|
} else {
|
||||||
|
println("Discord webhook unspecified")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// id = project.curse_project_id
|
||||||
|
// // TODO add code to reference this but also cut the latest change logs in for the files
|
||||||
|
// changelog = "${project.github}/blob/${sha}/CHANGELOG.md"
|
||||||
|
// changelogType = 'markdown'
|
||||||
|
// releaseType = 'release'
|
||||||
|
}
|
||||||
|
|
||||||
|
task copyPlugin {
|
||||||
|
doLast {
|
||||||
|
copy {
|
||||||
|
if(System.env.MC_SERVER_LOC == null) {
|
||||||
|
throw new Exception('You must set the server location and jar to use')
|
||||||
|
}
|
||||||
|
println "$buildDir/libs/Advanced-Portals-${version}.jar"
|
||||||
|
println "${System.env.MC_SERVER_LOC}/plugins/Advanced-Portals-${version}.jar"
|
||||||
|
try {
|
||||||
|
delete fileTree("${System.env.MC_SERVER_LOC}/plugins/") {
|
||||||
|
include "*.jar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(RuntimeException e) {
|
||||||
|
println e.getLocalizedMessage()
|
||||||
|
}
|
||||||
|
from file("$buildDir/libs/Advanced-Portals-${version}.jar")
|
||||||
|
into file("${System.env.MC_SERVER_LOC}/plugins/")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
||||||
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
||||||
task runJar() {
|
task runJar() {
|
||||||
doLast {
|
doLast {
|
||||||
|
if(System.env.MC_SERVER_LOC == null || System.env.MC_SERVER_JAR == null) {
|
||||||
|
throw new Exception('You must set the server location and jar to use MC_SERVER_LOC and MC_SERVER_JAR')
|
||||||
|
}
|
||||||
javaexec {
|
javaexec {
|
||||||
main "-jar"
|
main "-jar"
|
||||||
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
||||||
|
@ -60,11 +305,42 @@ task runJar() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
* These are needed as standard-version doesnt allow for the ability to skip tag versions for the changelog.
|
||||||
// if it is present.
|
* Well it does but not on purpose and it breaks things.
|
||||||
// If you remove this task, sources will not be generated.
|
*
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
* Tagging is skipped so that the release can be merged and confirmed (A little long winded but just to stop mistakes)
|
||||||
classifier = 'sources'
|
*/
|
||||||
from sourceSets.main.allSource
|
task updateChangelog {
|
||||||
|
doLast{
|
||||||
|
exec {
|
||||||
|
commandLine 'cmd', '/c', 'npx standard-version@9.3.0 -i docs/CHANGELOG.md -t (v)[0-9]+.[0-0]+.[0-0]+(?!-) --skip.tag'
|
||||||
|
ext.output = {
|
||||||
|
return standardOutput.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exec {
|
||||||
|
commandLine 'cmd', '/c', 'npx standard-version@9.3.0 --skip.changelog --skip.bump --skip.tag'
|
||||||
|
ext.output = {
|
||||||
|
return standardOutput.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task updateChangelogPreRelease(type: Exec) {
|
||||||
|
commandLine 'cmd', '/c', 'npx standard-version@9.3.0 --prerelease -i docs/SNAPSHOT_CHANGELOG.md --skip.tag'
|
||||||
|
ext.output = {
|
||||||
|
return standardOutput.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just to stop having to manually tagging. Probably could do this easier but meh stops typos or other issues.
|
||||||
|
*/
|
||||||
|
task tagRelease(type: Exec) {
|
||||||
|
commandLine 'cmd', '/c', 'npx standard-version@9.3.0 --prerelease -i docs/SNAPSHOT_CHANGELOG.md --skip.changelog --skip.bump'
|
||||||
|
ext.output = {
|
||||||
|
return standardOutput.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
// configuration that holds jars to copy into lib
|
||||||
|
includeLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
|
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||||
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// includeLibs just says to include the library in the final jar
|
||||||
|
dependencies {
|
||||||
|
includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||||
|
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||||
|
includeLibs group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||||
|
compile group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||||
|
compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
|
||||||
|
|
||||||
|
|
||||||
|
// For spigot api
|
||||||
|
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
// For bukkit api
|
||||||
|
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from configurations.includeLibs.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
||||||
|
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
||||||
|
task runJar() {
|
||||||
|
doLast {
|
||||||
|
javaexec {
|
||||||
|
main "-jar"
|
||||||
|
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
||||||
|
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
|
||||||
|
workingDir "${System.env.MC_SERVER_LOC}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
|
// if it is present.
|
||||||
|
// If you remove this task, sources will not be generated.
|
||||||
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
|
classifier = 'sources'
|
||||||
|
from sourceSets.main.allSource
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
// configuration that holds jars to copy into lib
|
||||||
|
includeLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
|
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||||
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// includeLibs just says to include the library in the final jar
|
||||||
|
dependencies {
|
||||||
|
includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||||
|
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||||
|
includeLibs group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||||
|
compile group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||||
|
compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from configurations.includeLibs.collect {
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
||||||
|
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
||||||
|
task runJar() {
|
||||||
|
doLast {
|
||||||
|
javaexec {
|
||||||
|
main "-jar"
|
||||||
|
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
||||||
|
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
|
||||||
|
workingDir "${System.env.MC_SERVER_LOC}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,15 +5,16 @@ import com.sekwah.advancedportals.core.config.Config;
|
||||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ConfigRepositoryImpl implements ConfigRepository {
|
public class ConfigRepositoryImpl implements ConfigRepository {
|
||||||
|
|
||||||
private HashMap<String, Config> configs;
|
private Map<String, Config> configs;
|
||||||
private Config config;
|
private Config config;
|
||||||
|
|
||||||
public ConfigRepositoryImpl() {
|
public ConfigRepositoryImpl() {
|
||||||
configs = new HashMap<String,Config>();
|
configs = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getValue(String output) {
|
public <T> T getValue(String output) {
|
||||||
|
@ -26,10 +27,6 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void test() {
|
|
||||||
this.<String>getValue("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getUseOnlySpecialAxe() {
|
public boolean getUseOnlySpecialAxe() {
|
||||||
return this.config.useOnlySpecialAxe;
|
return this.config.useOnlySpecialAxe;
|
||||||
}
|
}
|
|
@ -16,8 +16,6 @@ import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
|
||||||
import com.sekwah.advancedportals.core.config.RepositoryModule;
|
import com.sekwah.advancedportals.core.config.RepositoryModule;
|
||||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||||
import com.sekwah.advancedportals.ConfigRepository;
|
import com.sekwah.advancedportals.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.registry.RegisterBuilder;
|
|
||||||
import com.sekwah.advancedportals.core.registry.Registrar;
|
|
||||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.core.connector.command.CommandRegister;
|
import com.sekwah.advancedportals.core.connector.command.CommandRegister;
|
||||||
|
@ -71,12 +69,6 @@ public class AdvancedPortalsCore {
|
||||||
this.onEnable();
|
this.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
|
||||||
Registrar registrar = RegisterBuilder.newBuilder()
|
|
||||||
.inheritPermissions(true)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int checkMcVer(int[] mcVer) {
|
private int checkMcVer(int[] mcVer) {
|
||||||
int maxSupportedVer = 13;
|
int maxSupportedVer = 13;
|
||||||
int minSupportedVer = 13;
|
int minSupportedVer = 13;
|
||||||
|
@ -150,7 +142,7 @@ public class AdvancedPortalsCore {
|
||||||
|
|
||||||
// TODO remove once annotations are done
|
// TODO remove once annotations are done
|
||||||
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
|
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
|
||||||
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand());
|
this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand());
|
||||||
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
|
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
|
||||||
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
|
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
|
||||||
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
|
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
|
|
@ -8,12 +8,12 @@ import com.sekwah.advancedportals.core.connector.container.CommandSenderContaine
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TransUpdateSubCommand implements SubCommand {
|
public class LangUpdateSubCommand implements SubCommand {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AdvancedPortalsCore portalsCore;
|
private AdvancedPortalsCore portalsCore;
|
||||||
|
|
||||||
public TransUpdateSubCommand() {
|
public LangUpdateSubCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -2,13 +2,11 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||||
|
|
||||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||||
import com.sekwah.advancedportals.core.registry.SubCmd;
|
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.core.connector.container.CommandSenderContainer;
|
import com.sekwah.advancedportals.core.connector.container.CommandSenderContainer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SubCmd(name="version", parent=SubCmd.TYPE.PORTAL, minArgs=5, permissions= {"Test"})
|
|
||||||
public class VersionSubCommand implements SubCommand {
|
public class VersionSubCommand implements SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -12,7 +12,7 @@ public class CommandDemo implements CommandHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommandFailure(String[] command, CommandSenderContainer sender, CommandException exception) {
|
public void onCommandFailure(String[] command, CommandSenderContainer sender, CommandException exception, ImmutableList<String> args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
For the release changelogs see [CHANGELOG.md](CHANGELOG.md)
|
||||||
|
For the snapshot changelogs see [SNAPSHOT_CHANGELOG.md](SNAPSHOT_CHANGELOG.md)
|
||||||
|
|
||||||
|
## 0.6.0 (2021-05-19)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **proxy:** Added a ForceEnableProxySupport config option ([99c810e](https://github.com/sekwah41/Advanced-Portals/commit/99c810e1beeee743734ec451ffe5df312eec8726))
|
||||||
|
* **proxy:** Added Velocity support ([b243b4d](https://github.com/sekwah41/Advanced-Portals/commit/b243b4d889b8039cb800d981d44d85da06ff62d5))
|
||||||
|
* **proxy:** Modern forwarding will be automatically detected. ([f3c8f73](https://github.com/sekwah41/Advanced-Portals/commit/f3c8f73975857a4e5d31a6a21111eee8b7888bdd))
|
||||||
|
* Added configurable proxy teleport delay ([a1121ad](https://github.com/sekwah41/Advanced-Portals/commit/a1121adc10addfcce515d1358d1274232109fdfd))
|
||||||
|
|
||||||
|
### 0.5.12
|
||||||
|
|
||||||
|
* Added support for Velocity.
|
||||||
|
* Also fixed some issues with entity teleporting.
|
||||||
|
|
||||||
|
### 0.5.11
|
||||||
|
|
||||||
|
* Missing changelogs
|
||||||
|
|
||||||
|
### 0.5.10
|
||||||
|
|
||||||
|
* Missing changelogs
|
||||||
|
|
||||||
|
### 0.5.10
|
||||||
|
|
||||||
|
* Added fix for command portals spam triggering if they didn't teleport you out.
|
||||||
|
* Made portals not activate if you were teleported into them by another portal (to allow linking zones like a star trek warp pad)
|
||||||
|
|
||||||
|
### 0.5.9
|
||||||
|
|
||||||
|
* Missing changelogs
|
||||||
|
|
||||||
|
### 0.5.8
|
||||||
|
|
||||||
|
* Missing changelogs
|
||||||
|
|
||||||
|
### 0.5.7
|
||||||
|
|
||||||
|
|
||||||
|
* Extra checks added by @tmantti to fix slow connections to new servers from activating the destination location too quick.
|
||||||
|
|
||||||
|
### 0.5.6
|
||||||
|
* Fixed packet exploit affecting destinations (only effecting versions 0.5.0 to 0.5.5).
|
||||||
|
|
||||||
|
### 0.5.5
|
||||||
|
* Added support for 1.16
|
||||||
|
* Reworked chat menus to better use Spigot API
|
||||||
|
* Changed edit menu to have Activate instead of Teleport to destination
|
||||||
|
* Compat code changed. You must now use Spigot rather than CraftBukkit.
|
||||||
|
|
||||||
|
### 0.5.4
|
||||||
|
* Added bungee backup methods to ensure bungee and desti work correctly together
|
||||||
|
* Fixed protection region issue
|
||||||
|
* Reworked the warp command and fixed the surrounding permissions
|
||||||
|
* Disabling gateway beams is now enabled for placing the blocks as well as by a few other means
|
||||||
|
|
||||||
|
### 0.5.3
|
||||||
|
|
||||||
|
* Fixed destination bug.
|
||||||
|
|
||||||
|
### 0.5.2
|
||||||
|
|
||||||
|
* Fixed issue with bungee destinations.
|
||||||
|
|
||||||
|
### 0.5.1
|
||||||
|
|
||||||
|
* Fixed warp permission info
|
||||||
|
|
||||||
|
### 0.5.0
|
||||||
|
|
||||||
|
* Added command:
|
||||||
|
* Fix for bungee warps
|
||||||
|
|
||||||
|
### 0.4.0
|
||||||
|
|
||||||
|
* Individual portal cooldown added
|
||||||
|
* Bungee improvements
|
||||||
|
|
||||||
|
### Earlier
|
||||||
|
|
||||||
|
* See github releases and spigot pages for more info.
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
For the release changelogs see [CHANGELOG.md](CHANGELOG.md)
|
||||||
|
For the snapshot changelogs see [SNAPSHOT_CHANGELOG.md](SNAPSHOT_CHANGELOG.md)
|
||||||
|
|
||||||
|
### [0.5.13-2](https://github.com/sekwah41/Advanced-Portals/compare/v0.5.13-1...v0.5.13-2) (2021-05-14)
|
||||||
|
|
||||||
|
* No code changes, just updated the changelog generation.
|
||||||
|
|
||||||
|
### 0.5.13-1 (2021-05-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Added configurable proxy teleport delay ([a1121ad](https://github.com/sekwah41/Advanced-Portals/commit/a1121adc10addfcce515d1358d1274232109fdfd))
|
||||||
|
|
||||||
|
### 0.5.13-0 (2021-05-12)
|
||||||
|
|
||||||
|
* Build Tool Change: Updated versioning and changelog tooling and standards.
|
||||||
|
* Added improved support for Velocity (You can now add it directly to Velocity as a plugin)
|
||||||
|
* Added a ForceEnableProxySupport config option in case any are not detected
|
||||||
|
* Modern forwarding will be automatically detected. You will no longer need to manually set ForceEnableProxySupport
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
z# https://docs.gradle.org/current/userguide/build_environment.html
|
z# https://docs.gradle.org/current/userguide/build_environment.html
|
||||||
# Disable with --no-build-cache
|
# Disable with --no-build-cache
|
||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
|
|
||||||
|
github=https://github.com/sekwah41/Advanced-Portals
|
||||||
|
curse_project_id=86001
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
rootProject.name = "advanced-portals"
|
||||||
|
include 'spigot'
|
||||||
|
include 'velocity'
|
||||||
|
include 'bungee'
|
||||||
|
include 'core'
|
|
@ -0,0 +1,47 @@
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
// configuration that holds jars to copy into lib
|
||||||
|
includeLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
|
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||||
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// includeLibs just says to include the library in the final jar
|
||||||
|
dependencies {
|
||||||
|
implementation project(":core")
|
||||||
|
|
||||||
|
// For spigot api
|
||||||
|
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from configurations.includeLibs.collect {
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
||||||
|
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
||||||
|
task runJar() {
|
||||||
|
doLast {
|
||||||
|
javaexec {
|
||||||
|
main "-jar"
|
||||||
|
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
||||||
|
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
|
||||||
|
workingDir "${System.env.MC_SERVER_LOC}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin
|
||||||
|
name: AdvancedPortals
|
||||||
|
version: 1.0.0
|
||||||
|
author: sekwah41
|
||||||
|
description: An advanced portals plugin for bukkit.
|
||||||
|
api-version: 1.13
|
||||||
|
commands:
|
||||||
|
portal:
|
||||||
|
description: The main command for the advanced portals
|
||||||
|
aliases: [portals, aportals, advancedportals]
|
||||||
|
usage: /<command>
|
||||||
|
destination:
|
||||||
|
description: Can be used to access portal destinations.
|
||||||
|
aliases: [desti]
|
||||||
|
usage: /<command>
|
||||||
|
permissions:
|
||||||
|
advancedportals.*:
|
||||||
|
description: Gives access to all commands
|
||||||
|
default: op
|
||||||
|
children:
|
||||||
|
advancedportals.createportal: true
|
||||||
|
advancedportals.portal: true
|
||||||
|
advancedportals.build: true
|
||||||
|
advancedportals.desti: true
|
||||||
|
advancedportals.createportal:
|
||||||
|
description: Allows you to create portals
|
||||||
|
default: op
|
||||||
|
advancedportals.createportal.commandlevel.*:
|
||||||
|
description: Gives access to all level raisers
|
||||||
|
default: false
|
||||||
|
children:
|
||||||
|
advancedportals.createportal.commandlevel.op: true
|
||||||
|
advancedportals.createportal.commandlevel.perms: true
|
||||||
|
advancedportals.createportal.commandlevel.console: true
|
||||||
|
advancedportals.createportal.commandlevel.op:
|
||||||
|
description: Allows you to increase the users level temporaily to op
|
||||||
|
default: false
|
||||||
|
advancedportals.createportal.commandlevel.perms:
|
||||||
|
description: Allows you to increase the users level temporaily to have all perms
|
||||||
|
default: false
|
||||||
|
advancedportals.createportal.commandlevel.console:
|
||||||
|
description: Executes command in the console
|
||||||
|
default: false
|
||||||
|
advancedportals.portal:
|
||||||
|
description: Allows use of portal commands
|
||||||
|
default: op
|
||||||
|
advancedportals.build:
|
||||||
|
description: Allows you to build in the portal regions
|
||||||
|
default: op
|
||||||
|
advancedportals.desti:
|
||||||
|
description: Gives access to all desti commands
|
||||||
|
default: op
|
|
@ -1,16 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface Cmd {
|
|
||||||
String name();
|
|
||||||
//TODO Convert to enum
|
|
||||||
String parentCommand() default "";
|
|
||||||
boolean isEnabled() default true;
|
|
||||||
int minArgs() default 0;
|
|
||||||
String description() default "";
|
|
||||||
String[] permissions() default {};
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.reflect.ClassPath;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class RegisterBuilder<T extends CommandHandler> {
|
|
||||||
public static RegisterBuilder newBuilder() {
|
|
||||||
return new RegisterBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private RegisterBuilder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean allowPermissionInheritance;
|
|
||||||
private String scanDirectory;
|
|
||||||
private final Class<T> genericType = (Class<T>) ((ParameterizedType) getClass()
|
|
||||||
.getGenericSuperclass()).getActualTypeArguments()[0];
|
|
||||||
|
|
||||||
|
|
||||||
public RegisterBuilder<T> inheritPermissions(boolean allowInheritance) {
|
|
||||||
allowPermissionInheritance = allowInheritance;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegisterBuilder<T> scanDirectory(String directoryName) {
|
|
||||||
this.scanDirectory = directoryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO I don't know if we want to use this as it is marked as Unstable.
|
|
||||||
public Registrar<T> build() {
|
|
||||||
// Table<String, String, T> commandMap = HashBasedTable.create();
|
|
||||||
Map<Cmd, T> commandMap = new HashMap<>();
|
|
||||||
ImmutableSet<ClassPath.ClassInfo> classInfo;
|
|
||||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
ClassPath classPath = null;
|
|
||||||
try {
|
|
||||||
classPath = ClassPath.from(loader);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (null == scanDirectory || scanDirectory.isEmpty()) {
|
|
||||||
classInfo = classPath.getTopLevelClasses(scanDirectory);
|
|
||||||
} else {
|
|
||||||
classInfo = classPath.getTopLevelClasses();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO implement blackout of already registered commands.
|
|
||||||
//TODO If there are duplicates ignore them and throw a warning in console.
|
|
||||||
Map<Cmd, Class<?>> commandClasses = classInfo.stream().map(ClassPath.ClassInfo::load)
|
|
||||||
.filter(t -> t.isAnnotationPresent(Cmd.class))
|
|
||||||
.filter(t -> t.isAssignableFrom(genericType))
|
|
||||||
.collect(Collectors.toMap(k -> k.getAnnotation(Cmd.class), k -> k));
|
|
||||||
|
|
||||||
Stream<Map.Entry<Cmd, Class<?>>> result = commandClasses.entrySet().stream();
|
|
||||||
|
|
||||||
result.filter(c -> c.getKey().parentCommand().equals(""))
|
|
||||||
.forEach(c -> {
|
|
||||||
try {
|
|
||||||
commandMap.put(c.getKey(), (T) c.getValue().newInstance());
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
result.filter(c -> c.getKey().parentCommand() != "")
|
|
||||||
.forEach(c -> {
|
|
||||||
try {
|
|
||||||
commandMap.put(c.getKey(), (T) c.getValue().newInstance());
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return new Registrar<>(allowPermissionInheritance, commandMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
import com.sekwah.advancedportals.core.connector.container.CommandSenderContainer;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class Registrar<T extends CommandHandler> implements CommandExecutor, TabCompleter {
|
|
||||||
//Parent Command, Sub Command, Object
|
|
||||||
private boolean allowPermissionInheritance;
|
|
||||||
private Map<Cmd, T> commandMap = new HashMap<>();
|
|
||||||
|
|
||||||
protected Registrar(boolean allowPermissionInheritance, Map<Cmd, T> commandMap) {
|
|
||||||
this.commandMap = commandMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAllowPermissionInheritance() {
|
|
||||||
return allowPermissionInheritance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Cmd, T> getCommandMap() {
|
|
||||||
return commandMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
Stream<Map.Entry<Cmd, T>> topLevelCommands = commandMap.entrySet().stream()
|
|
||||||
.filter(c->c.getKey().name().equals(args[0]) || c.getKey().parentCommand().equals(args[0]));
|
|
||||||
|
|
||||||
Optional<Map.Entry<Cmd, T>> results = topLevelCommands.filter(c->c.getKey().name().equals(args[1])).findFirst();
|
|
||||||
String[] commands = null;
|
|
||||||
Map.Entry<Cmd, T> key = null;
|
|
||||||
|
|
||||||
|
|
||||||
if (results.isPresent()) {
|
|
||||||
args[0] = null;
|
|
||||||
args[1] = null;
|
|
||||||
commands = new String[]{args[0], args[1]};
|
|
||||||
|
|
||||||
key = results.get();
|
|
||||||
} else {
|
|
||||||
commands = new String[]{args[0]};
|
|
||||||
key = topLevelCommands
|
|
||||||
.filter(c->c.getKey().name().equals(args[0]) && c.getKey().parentCommand().equals(""))
|
|
||||||
.findFirst().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].length() >= key.getKey().minArgs()) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
commands = new String[]{args[0], args[1]};
|
|
||||||
//TODO ????
|
|
||||||
key.getValue().onCommandFailure(commands, (CommandSenderContainer) sender, new CommandException(ErrorCode.INSUFFICIENT_ARGUMENTS, ""),
|
|
||||||
ImmutableList.copyOf(Arrays.asList(args)));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
//There is no reason to run a double class file when we can just make the main command default out.
|
|
||||||
@Deprecated()
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface SubCmd {
|
|
||||||
|
|
||||||
TYPE parent();
|
|
||||||
|
|
||||||
String name();
|
|
||||||
|
|
||||||
int minArgs();
|
|
||||||
|
|
||||||
String[] permissions();
|
|
||||||
|
|
||||||
public enum TYPE {
|
|
||||||
PORTAL,
|
|
||||||
DESTI
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue