Skip to content

Commit bf9754c

Browse files
committed
Code so far
1 parent 9cff1ea commit bf9754c

File tree

13 files changed

+511
-0
lines changed

13 files changed

+511
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ gradle-app.setting
1919
.project
2020
# JDT-specific (Eclipse Java Development Tools)
2121
.classpath
22+
23+
/target/
24+
dependency-reduced-pom.xml
25+
26+
*.iml
27+
28+
/.idea

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# Live-Resources
22
A Simple plugin to add quick refreshing of server resoucepacks supporting both links and hash
3+
4+
## Commands
5+
| Command | Permission | Description | Aliases |
6+
|------------------------------------------|------------------------|-----------------------------------------------------------------------------------------|---------------------|
7+
| `/live_rp reloadconfig` | `live_rp.reload` | Reload the plugins configuration | liveresources |
8+
| `/live_rp update <link> [hash] [reload]` | `live_rp.update` | Allows you to update the server rp, the hash is optional and reload will force a reload | |
9+
| `/reloadpack` | `live_rp.apply` | Allows you to reload your pack | reloadrp, rp_reload |
10+
| `/reloadpack <player>` | `live_rp.apply.others` | Allows you to reload other peoples resource packs | |

pom.xml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.kruthers</groupId>
7+
<artifactId>LiveResources</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>LiveResources</name>
12+
<description>Live Resources is a way to update your resourcepack link and hash without restarting your server or kicking anyone!</description>
13+
14+
<repositories>
15+
<repository>
16+
<id>spigot-repo</id>
17+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
18+
</repository>
19+
</repositories>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.jetbrains.kotlin</groupId>
28+
<artifactId>kotlin-test-junit</artifactId>
29+
<version>1.5.30</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.spigotmc</groupId>
33+
<artifactId>spigot-api</artifactId>
34+
<version>1.19.4-R0.1-SNAPSHOT</version>
35+
<scope>provided</scope>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<sourceDirectory>src/main/kotlin</sourceDirectory>
41+
<resources>
42+
<resource>
43+
<directory>src/main/resources</directory>
44+
<filtering>true</filtering>
45+
</resource>
46+
</resources>
47+
<plugins>
48+
<plugin>
49+
<artifactId>kotlin-maven-plugin</artifactId>
50+
<groupId>org.jetbrains.kotlin</groupId>
51+
<version>1.5.30-RC</version>
52+
<executions>
53+
<execution>
54+
<id>compile</id>
55+
<goals> <goal>compile</goal> </goals>
56+
<configuration>
57+
<sourceDirs>
58+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
59+
</sourceDirs>
60+
</configuration>
61+
</execution>
62+
<execution>
63+
<id>test-compile</id>
64+
<goals> <goal>test-compile</goal> </goals>
65+
<configuration>
66+
<sourceDirs>
67+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
68+
</sourceDirs>
69+
</configuration>
70+
</execution>
71+
</executions>
72+
</plugin>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-compiler-plugin</artifactId>
76+
<version>3.8.1</version>
77+
<executions>
78+
<execution>
79+
<id>default-compile</id>
80+
<phase>none</phase>
81+
</execution>
82+
<execution>
83+
<id>default-testCompile</id>
84+
<phase>none</phase>
85+
</execution>
86+
<execution>
87+
<id>java-compile</id>
88+
<phase>compile</phase>
89+
<goals> <goal>compile</goal> </goals>
90+
</execution>
91+
<execution>
92+
<id>java-test-compile</id>
93+
<phase>test-compile</phase>
94+
<goals> <goal>testCompile</goal> </goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-shade-plugin</artifactId>
101+
<version>3.2.4</version>
102+
<executions>
103+
<execution>
104+
<phase>package</phase>
105+
<goals>
106+
<goal>shade</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
114+
</project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.kruthers.liveresources
2+
3+
import com.kruthers.liveresources.commands.LiveRpCommand
4+
import com.kruthers.liveresources.commands.ReloadPackCommand
5+
import com.kruthers.liveresources.commands.tabcompleters.LiveRpTabCompleter
6+
import com.kruthers.liveresources.commands.tabcompleters.ReloadPackTabCompleter
7+
import com.kruthers.liveresources.listeners.PlayerListeners
8+
import com.kruthers.liveresources.utils.URLUtils
9+
import org.bukkit.ChatColor
10+
import org.bukkit.entity.Player
11+
import org.bukkit.plugin.java.JavaPlugin
12+
import java.util.*
13+
14+
15+
class LiveResources : JavaPlugin() {
16+
17+
companion object {
18+
val properties: Properties = Properties();
19+
}
20+
private var link: String = ""
21+
private var hash: String = ""
22+
23+
override fun onEnable() {
24+
logger.info("${ChatColor.BLUE}Loading Live Resources by kruthers")
25+
//load properties
26+
properties.load(this.classLoader.getResourceAsStream(".properties"))
27+
logger.info("Loading config")
28+
//make sure the config has been initiated & save it
29+
config.options().copyDefaults(true)
30+
this.saveConfig()
31+
this.loadSavedRP()
32+
33+
logger.info("Loaded config, registering commands/ events")
34+
this.server.pluginManager.registerEvents(PlayerListeners(this),this)
35+
this.server.getPluginCommand("live_rp")?.setExecutor(LiveRpCommand(this))
36+
this.server.getPluginCommand("live_rp")?.tabCompleter = LiveRpTabCompleter()
37+
this.server.getPluginCommand("reloadpack")?.setExecutor(ReloadPackCommand(this))
38+
this.server.getPluginCommand("reloadpack")?.tabCompleter = ReloadPackTabCompleter()
39+
40+
41+
}
42+
43+
fun getRPLink(): String {
44+
return this.link
45+
}
46+
47+
fun getRPHash(): String {
48+
return this.hash
49+
}
50+
51+
fun loadSavedRP(): Boolean {
52+
this.reloadConfig()
53+
this.hash = this.config.getString("resourepack.hash")?: ""
54+
55+
this.config.getString("resourepack.link").let {
56+
if (it == null || it == "") {
57+
this.logger.warning("No resourcepack defined in config, please specify one.")
58+
this.link = ""
59+
return false
60+
} else {
61+
if (URLUtils.isValid(it)) {
62+
this.link = it
63+
} else {
64+
this.logger.warning("Invalid resourcepack defined in config, please specify one.")
65+
this.link = ""
66+
return false
67+
}
68+
}
69+
}
70+
return true;
71+
}
72+
73+
fun updateSavedRP(link: String, hash: String): Boolean{
74+
return if (URLUtils.isValid(link)) {
75+
this.link = link
76+
this.hash = hash
77+
this.config.set("resourepack.link", link)
78+
this.config.set("resourepack.hash", hash)
79+
this.saveConfig()
80+
true
81+
} else {
82+
false
83+
}
84+
}
85+
86+
fun reloadPlayerRP(player: Player, plugin: LiveResources) {
87+
if (this.link != "") {
88+
if (this.hash == "") {
89+
player.setResourcePack(this.link)
90+
} else {
91+
player.setResourcePack(this.link, this.hash.toByteArray())
92+
}
93+
} else {
94+
player.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.failed_no_rp") ?: "&4No resourepack provided to load in, please contact your system administrator"))
95+
}
96+
}
97+
98+
99+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.kruthers.liveresources.commands
2+
3+
import com.kruthers.liveresources.LiveResources
4+
import org.bukkit.Bukkit
5+
import org.bukkit.ChatColor
6+
import org.bukkit.command.Command
7+
import org.bukkit.command.CommandExecutor
8+
import org.bukkit.command.CommandSender
9+
10+
class LiveRpCommand(val plugin: LiveResources): CommandExecutor {
11+
12+
private fun reloadEveryone(plugin: LiveResources) {
13+
Bukkit.getOnlinePlayers().forEach { player ->
14+
player.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.reloaded_auto") ?: "&2Your resourcepack has been automatically reloaded"))
15+
plugin.reloadPlayerRP(player,plugin)
16+
}
17+
}
18+
19+
override fun onCommand(sender: CommandSender, cmd: Command, label: String, args: Array<out String>): Boolean {
20+
if (args == null) {
21+
sender.sendMessage("You are running Live Resourcepacks version ${LiveResources.properties.getProperty("version")}")
22+
} else {
23+
if (args.isEmpty()) {
24+
sender.sendMessage("You are running Live Resourcepacks version ${LiveResources.properties.getProperty("version")}")
25+
} else {
26+
when (args[0].lowercase()) {
27+
"reloadconfig" -> {
28+
if (sender.hasPermission("live_rp.reload")) {
29+
if (args.size > 1) {
30+
sender.sendMessage("${ChatColor.RED}Invalid agument given at: /${label} reloadconfig <---- Expected usage: /live_rp reloadconfig")
31+
} else {
32+
sender.sendMessage("${ChatColor.GRAY}Reloading config")
33+
if (!plugin.loadSavedRP()) {
34+
sender.sendMessage("${ChatColor.RED}Invalid resourcepack link defined in config, please update.")
35+
}
36+
sender.sendMessage("${ChatColor.GRAY}Reloaded config.")
37+
}
38+
} else {
39+
sender.sendMessage(cmd.permissionMessage)
40+
}
41+
}
42+
"update" -> {
43+
if (sender.hasPermission("live_rp.update")) {
44+
when (args.size-1) {
45+
0 -> sender.sendMessage("${ChatColor.RED}Expected argument at: /${label} update <--- Correct usage: /live_rp update <link> [hash] [reload]")
46+
1,2,3 -> {
47+
val link: String = args[1]
48+
val hash: String = if (args.size == 3) args[2] else ""
49+
val reloadEveryone = if (args.size == 4) {
50+
when(args[3]) {
51+
"true" -> true
52+
"false" -> false
53+
else -> {
54+
sender.sendMessage("${ChatColor.RED}Invalid argument at: /${label} update ${args[1]} ${args[2]} <--- Expected \"true\" or \"false\". Proceeding as if it was true")
55+
true
56+
}
57+
}
58+
} else {
59+
true
60+
}
61+
62+
if (plugin.updateSavedRP(link,hash)) {
63+
sender.sendMessage("${ChatColor.GREEN}Resourcepack link updated, reloading all user resourcepacks")
64+
if (reloadEveryone) {
65+
this.reloadEveryone(plugin)
66+
}
67+
} else {
68+
sender.sendMessage("${ChatColor.RED}Resourcepack link invalid, failed to update")
69+
}
70+
}
71+
else -> {
72+
sender.sendMessage("${ChatColor.RED}Unexpected argument at: /${label} update ${args[1]} ${args[2]} ${args[3]} <--- Correct usage: /live_rp update <link> [hash] [reload]")
73+
}
74+
}
75+
} else {
76+
sender.sendMessage(cmd.permissionMessage)
77+
}
78+
}
79+
else -> {
80+
sender.sendMessage("${ChatColor.RED}Invalid usage at: /${label} <--- expected argument, correct usage: ${cmd.usage}")
81+
}
82+
}
83+
}
84+
}
85+
86+
return true
87+
}
88+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.kruthers.liveresources.commands
2+
3+
import com.kruthers.liveresources.LiveResources
4+
import org.bukkit.Bukkit
5+
import org.bukkit.ChatColor
6+
import org.bukkit.command.Command
7+
import org.bukkit.command.CommandExecutor
8+
import org.bukkit.command.CommandSender
9+
import org.bukkit.entity.Player
10+
11+
class ReloadPackCommand(val plugin: LiveResources): CommandExecutor {
12+
override fun onCommand(sender: CommandSender, p1: Command, p2: String, args: Array<out String>): Boolean {
13+
//sender.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.MESSAGE") ?: "DEFAULT"))
14+
when (args.size) {
15+
0 -> {
16+
if (sender is Player) {
17+
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.reload_sef") ?: "&2Your resourcepack is being reloaded from the server"))
18+
plugin.reloadPlayerRP(sender,plugin)
19+
} else {
20+
sender.sendMessage("${ChatColor.RED}You must be a player to run this command, use /reloadpack <player>")
21+
}
22+
}
23+
1 -> {
24+
if (sender.hasPermission("live_rp.apply.others")) {
25+
val username: String = args[0]
26+
val player: Player? = Bukkit.getPlayer(username)
27+
if (player == null) {
28+
sender.sendMessage("${ChatColor.RED}Failed to find player $username")
29+
} else {
30+
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.reload_other") ?: "&2Force reloading {name}'s resourcepack").replace("{name}",player.name))
31+
player.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.config.getString("message.reloaded_other") ?: "&2Your Resourcepack is being reloaded by {name}").replace("{name}",sender.name))
32+
plugin.reloadPlayerRP(player,plugin)
33+
}
34+
} else {
35+
sender.sendMessage("${ChatColor.RED}You do not have permission to reload other people's resourepack")
36+
}
37+
}
38+
else -> sender.sendMessage("${ChatColor.RED}Too many arguments provided, correct usage: /reloadpack [player]")
39+
}
40+
41+
return true
42+
}
43+
}

0 commit comments

Comments
 (0)