Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Commit

Permalink
refactor to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
NotJansel committed May 8, 2022
1 parent ecfca5d commit 5dc6d78
Show file tree
Hide file tree
Showing 20 changed files with 405 additions and 434 deletions.
75 changes: 66 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.7.0-Beta</kotlin.version>
</properties>
<url>https://www.notjansel.de</url>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -45,6 +37,55 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -82,5 +123,21 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</project>
84 changes: 0 additions & 84 deletions src/main/java/de/notjansel/datapacksync/Datapacksync.java

This file was deleted.

74 changes: 74 additions & 0 deletions src/main/java/de/notjansel/datapacksync/Datapacksync.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package de.notjansel.datapacksync

import de.notjansel.datapacksync.commands.Copy
import de.notjansel.datapacksync.commands.Download
import de.notjansel.datapacksync.commands.Update
import de.notjansel.datapacksync.listeners.JoinListener
import de.notjansel.datapacksync.threading.UpdateCheckerThread
import io.papermc.paper.datapack.DatapackManager
import org.apache.commons.io.FileUtils
import org.bukkit.Bukkit
import org.bukkit.Server
import org.bukkit.World
import org.bukkit.plugin.java.JavaPlugin
import java.io.File
import java.io.IOException
import java.net.URL

class Datapacksync : JavaPlugin() {
override fun onEnable() {
// Plugin startup logic
server.pluginManager.registerEvents(JoinListener(), this)
getCommand("copy")!!.setExecutor(Copy())
getCommand("Download")!!.setExecutor(Download())
getCommand("update")!!.setExecutor(Update())
serverpath = server.worldContainer.absolutePath.replace(".", "")
worlds = server.worlds
datapackManager = server.datapackManager
Companion.server = server
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, UpdateCheckerThread(), 1200, 18000)
try {
prepare_requisites()
} catch (e: IOException) {
throw RuntimeException(e)
}
remorselessness_against_files()
}

private fun remorselessness_against_files() {
for (file in File(serverpath + "/plugins").listFiles()) {
if (file.name.contains("datapacksync")) {
if (!file.name.contains(version)) {
file.delete()
}
}
}
}

@Throws(IOException::class)
private fun prepare_requisites() {
if (!File(serverpath + "/downloads/version.json").exists()) {
val file = File(serverpath + "downloads/version.json")
val fetchsite = URL("https://raw.githubusercontent.com/TornRPG/datasync/master/version.json")
FileUtils.copyURLToFile(fetchsite, file)
}
}

override fun onDisable() {
// Plugin shutdown logic
}

companion object {
var serverpath: String? = null
var worlds: List<World>? = null
var datapackManager: DatapackManager? = null
var server: Server? = null
const val version = "0.30.2"
@Throws(IOException::class)
fun downloadFile(url: String?, path: String?) {
val file = File(path)
val fetchsite = URL(url)
FileUtils.copyURLToFile(fetchsite, file)
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/de/notjansel/datapacksync/commands/Copy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.notjansel.datapacksync.commands

import de.notjansel.datapacksync.Datapacksync
import de.notjansel.datapacksync.threading.CopyThread
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import java.io.File

class Copy : CommandExecutor, TabCompleter {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
val thread = CopyThread(sender, args)
thread.start()
return true
}

override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array<String>): List<String>? {
val tabComplete: MutableList<String> = ArrayList()
if (args.size == 1) {
val directoryPath = File(Datapacksync.serverpath + "/downloads/")
for (filename in directoryPath.list()) {
tabComplete.add(filename)
}
}
return tabComplete
}
}
14 changes: 14 additions & 0 deletions src/main/java/de/notjansel/datapacksync/commands/Download.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.notjansel.datapacksync.commands

import de.notjansel.datapacksync.threading.DatapackThread
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender

class Download : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
val thread = DatapackThread(sender, args)
thread.start()
return true
}
}
18 changes: 18 additions & 0 deletions src/main/java/de/notjansel/datapacksync/commands/Update.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.notjansel.datapacksync.commands

import de.notjansel.datapacksync.threading.DownloadThread
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender

class Update : CommandExecutor {
override fun onCommand(commandSender: CommandSender, command: Command, s: String, strings: Array<String>): Boolean {
if (!commandSender.hasPermission("datapacksync.use")) {
commandSender.sendMessage("You do not have the Permission to use this.")
return true
}
val thread = DownloadThread(commandSender)
thread.start()
return true
}
}
43 changes: 0 additions & 43 deletions src/main/java/de/notjansel/datapacksync/commands/copy.java

This file was deleted.

Loading

0 comments on commit 5dc6d78

Please sign in to comment.