Skip to content

Commit 90900f9

Browse files
committed
SimpleWarp v4.0
1 parent a0e7343 commit 90900f9

7 files changed

Lines changed: 161 additions & 5 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ The plugin also features an auto update System. This System downloads the newest
1414

1515

1616
The plugin now also features a "per-warp-permission System".
17-
That means if you enable "RequirePermissionForEachWarp" in your Warps.yml Config, every Warp Point gets an individual Permission that follows this scheme: "simplewarp.warp.WARPNAME".
17+
That means if you enable `RequirePermissionForEachWarp` in your `Warps.yml` Config, every Warp Point gets an individual Permission that follows this scheme: `simplewarp.warp.WARPNAME`.
1818
(You have to replace WARPNAME with the exact name of your warp point). Only players with the correct permissions can see and use the warp points.
1919
You can now set Default Warp Point permissions in the Permission.yml file. Note: Only simplewarp permissions can be set by default. Other Permissions in the Permission.yml file will be ignored.
2020

21+
The new Integrated Permission Manager allows you to manage SimpleWarp permissions without the need of an external Permission System. To use this, set `IntegratedPermissionSystem` in your `Warps.yml` to `true`
22+
Please note that only SimpleWarp permissions can be set via the integrated permission manager.
23+
2124
[![CircleCI](https://circleci.com/gh/marylieh/SimpleWarpV3/tree/main.svg?style=shield)](https://circleci.com/gh/marylieh/SimpleWarpV3/tree/main)
2225
## Commands
2326

@@ -30,6 +33,10 @@ You can now set Default Warp Point permissions in the Permission.yml file. Note:
3033
* `positionName` - *Shows the coordinates of the position. If the position doesn't exist, the position will be set to your current location*
3134
* `del` - *Remove a position*
3235
* `list` - *Lists all available positions*
36+
* `/pm <add |remove | list>`
37+
* `add` - *Adds a simplewarp permission to a given player*
38+
* `remove` - *Removes a simplewarp permission from a given player*
39+
* `list` - *List all simplewarp permissions from a given player*
3340

3441
## Permissions
3542

@@ -42,6 +49,7 @@ You can now set Default Warp Point permissions in the Permission.yml file. Note:
4249
* `simplewarp.position.create` - Allows you to use the **/position \<name>**
4350
* `simplewarp.position.del` - Allows you to use the **/position del \<name>**
4451
* `simplewarp.position.list` - Allows you to use the **/position list**
52+
* `simplewarp.permissionmanager` - Allows you to use the **/pm** command
4553

4654
*To give the permissions to players you need a Permission System like [LuckPerms](https://luckperms.net/).*
4755

src/main/kotlin/me/marylieh/simplewarp/SimpleWarp.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.util.logging.Level
1414
class SimpleWarp : JavaPlugin() {
1515

1616
val prefix = "§6[SimpleWarp]"
17-
val version = "R-3.9"
17+
val version = "R-4.0"
1818
private val pluginId: Int = 20196
1919

2020
companion object {
@@ -57,12 +57,14 @@ class SimpleWarp : JavaPlugin() {
5757
val warpsCommand = getCommand("warps") ?: error("Couldn't get warps command! This should not happen!")
5858
val warpVersionCommand = getCommand("warpversion") ?: error("Couldn't get warpversion command! This should not happen!")
5959
val positionCommand = getCommand("position") ?: error("Couldn't get position command! This should not happen!")
60+
val permissionManagerCommand = getCommand("pm") ?: error("Couldn't get permissions manager command! This should not happen!")
6061
setWarpCommand.setExecutor(SetWarpCommandExecutor())
6162
delWarpCommand.setExecutor(DelWarpCommandExecutor())
6263
warpCommand.setExecutor(WarpCommandExecutor())
6364
warpsCommand.setExecutor(WarpsCommandExecutor())
6465
warpVersionCommand.setExecutor(WarpVersionCommandExecutor())
6566
positionCommand.setExecutor(PositionCommandExecutor())
67+
permissionManagerCommand.setExecutor(PermissionManagerCommandExecutor())
6668
warpCommand.setTabCompleter(WarpTabCompleter())
6769
delWarpCommand.setTabCompleter(WarpTabCompleter())
6870
}
@@ -74,6 +76,11 @@ class SimpleWarp : JavaPlugin() {
7476
pluginManager.registerEvents(PlayerJoinListener(), this)
7577
Bukkit.getLogger().log(Level.INFO, "The Following default permissions will be set for each player: ${PermissionFile.getFile().getList("DefaultPermissions")}")
7678
}
79+
80+
if (Config.getConfig().getBoolean("IntegratedPermissionSystem")) {
81+
pluginManager.registerEvents(PlayerJoinListener(), this)
82+
Bukkit.getLogger().log(Level.INFO, "The integrated permission system has been enabled. That means you can use the /pm command as OP to give permissions to your players. This only works if the permission you are trying to add is a simplewarp permission.")
83+
}
7784
}
7885

7986
private fun initConfig() {
@@ -89,6 +96,9 @@ class SimpleWarp : JavaPlugin() {
8996
if (Config.getConfig().get("DefaultPermissions") == null) {
9097
Config.getConfig().set("DefaultPermissions", false)
9198
}
99+
if (Config.getConfig().get("IntegratedPermissionSystem") == null) {
100+
Config.getConfig().set("IntegratedPermissionSystem", false)
101+
}
92102
Config.save()
93103
}
94104

src/main/kotlin/me/marylieh/simplewarp/commands/DelWarpCommandExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DelWarpCommandExecutor : CommandExecutor {
2727
player.sendMessage("${SimpleWarp.instance.prefix} §aThe Warp §6 $id §a was successfully deleted!")
2828

2929
} else {
30-
player.sendMessage("${SimpleWarp.instance.prefix} §cPleas use: §7/warp <warpname>")
30+
player.sendMessage("${SimpleWarp.instance.prefix} §cPlease use: §7/warp <warpname>")
3131
}
3232
} else {
3333
player.sendMessage("${SimpleWarp.instance.prefix} §cYou don't have the permission to do that!")
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package me.marylieh.simplewarp.commands
2+
3+
import me.marylieh.simplewarp.SimpleWarp
4+
import me.marylieh.simplewarp.permissions.PermissionManager
5+
import me.marylieh.simplewarp.utils.Config
6+
import org.bukkit.Bukkit
7+
import org.bukkit.command.Command
8+
import org.bukkit.command.CommandExecutor
9+
import org.bukkit.command.CommandSender
10+
import org.bukkit.entity.Player
11+
12+
class PermissionManagerCommandExecutor : CommandExecutor {
13+
14+
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
15+
if (sender !is Player) {
16+
sender.sendMessage("${SimpleWarp.instance.prefix} §4Just a Player can execute this command!")
17+
return true
18+
}
19+
val player: Player = sender
20+
21+
if (player.isOp || player.hasPermission("simplewarp.permissionmanager")) {
22+
23+
if (!Config.getConfig().getBoolean("IntegratedPermissionSystem")) {
24+
player.sendMessage("${SimpleWarp.instance.prefix} §cThe integrated permission system is globally disabled.")
25+
return true
26+
}
27+
28+
if (args.size > 3 || args.size < 2) {
29+
player.sendMessage("${SimpleWarp.instance.prefix} §cPlease use: §7/pm <add | remove | list> <player> [permission]")
30+
return true
31+
}
32+
33+
if (args.size != 2 && !args[2].startsWith("simplewarp")) {
34+
player.sendMessage("${SimpleWarp.instance.prefix} §cThe permission system can only be used on internal permissions starting with 'simplewarp'.")
35+
return true
36+
}
37+
38+
if (Bukkit.getPlayerExact(args[1]) == null) {
39+
player.sendMessage("${SimpleWarp.instance.prefix} §cThe player ${args[1]} is not online.")
40+
return true
41+
}
42+
val target: Player = Bukkit.getPlayer(args[1])!!
43+
44+
when (args[0].lowercase()) {
45+
"add" -> {
46+
PermissionManager.setPermission(target, args[2], true)
47+
PermissionManager.savePermission(target, args[2])
48+
49+
player.sendMessage("${SimpleWarp.instance.prefix} The permission §a${args[2]} §6has been §2added §6to §b${target.name}§6. §7Remember that permissions set by this plugin only works with SimpleWarp.")
50+
}
51+
"remove" -> {
52+
PermissionManager.setPermission(target, args[2], false)
53+
PermissionManager.removeSavedPermission(target, args[2])
54+
55+
player.sendMessage("${SimpleWarp.instance.prefix} The permission §a${args[2]} §6has been §4removed §6from §b${target.name}§6.")
56+
}
57+
"list" -> {
58+
val permissions: List<String> = PermissionManager.getPermissions(target)
59+
60+
player.sendMessage("${SimpleWarp.instance.prefix} The player §b${target.name} §6has the following permission: §a$permissions")
61+
}
62+
else -> {
63+
player.sendMessage("${SimpleWarp.instance.prefix} §cPlease use: §7/pm <add | remove> <player> <permission>")
64+
}
65+
}
66+
67+
} else {
68+
player.sendMessage("${SimpleWarp.instance.prefix} §cYou don't have the permission to do that!")
69+
}
70+
return true
71+
}
72+
}

src/main/kotlin/me/marylieh/simplewarp/listener/PlayerJoinListener.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.marylieh.simplewarp.listener
22

33
import me.marylieh.simplewarp.SimpleWarp
4+
import me.marylieh.simplewarp.permissions.PermissionManager
5+
import me.marylieh.simplewarp.utils.Config
46
import me.marylieh.simplewarp.utils.PermissionFile
57
import org.bukkit.event.EventHandler
68
import org.bukkit.event.Listener
@@ -11,6 +13,18 @@ class PlayerJoinListener : Listener {
1113
@EventHandler fun handleJoin(event: PlayerJoinEvent) {
1214
val permissions = PermissionFile.getFile().getList("DefaultPermissions") as List<String>
1315

16+
if (Config.getConfig().getBoolean("IntegratedPermissionSystem")) {
17+
val integratedPermissions = PermissionManager.getPermissions(event.player)
18+
19+
integratedPermissions.forEach {
20+
if (!it.startsWith("simplewarp")) {
21+
return
22+
}
23+
24+
PermissionManager.setPermission(event.player, it, true)
25+
}
26+
}
27+
1428
permissions.forEach {
1529

1630
if (!it.startsWith("simplewarp")) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.marylieh.simplewarp.permissions
2+
3+
import me.marylieh.simplewarp.SimpleWarp
4+
import me.marylieh.simplewarp.utils.Config
5+
import org.bukkit.entity.Player
6+
7+
object PermissionManager {
8+
9+
fun setPermission(player: Player, permission: String, state: Boolean) {
10+
val attachment = player.addAttachment(SimpleWarp.instance)
11+
attachment.setPermission(permission, state)
12+
}
13+
14+
fun savePermission(player: Player, permission: String) {
15+
if (Config.getConfig().get("IntegratedPermissions.${player.uniqueId}.permissions") == null) {
16+
val tempPerms = mutableListOf<String>()
17+
tempPerms.add("simplewarp.default")
18+
Config.getConfig().set("IntegratedPermissions.${player.uniqueId}.permissions", tempPerms)
19+
Config.save()
20+
}
21+
22+
val validPerms = Config.getConfig().getList("IntegratedPermissions.${player.uniqueId}.permissions") as MutableList<String>
23+
validPerms.add(permission)
24+
Config.getConfig().set("IntegratedPermissions.${player.uniqueId}.permissions", validPerms)
25+
Config.save()
26+
}
27+
28+
fun removeSavedPermission(player: Player, permission: String) {
29+
if (Config.getConfig().get("IntegratedPermissions.${player.uniqueId}.permissions") == null) {
30+
return
31+
}
32+
val perms = Config.getConfig().getList("IntegratedPermissions.${player.uniqueId}.permissions") as MutableList<String>
33+
perms.remove(permission)
34+
Config.getConfig().set("IntegratedPermissions.${player.uniqueId}.permissions", perms)
35+
Config.save()
36+
}
37+
38+
fun getPermissions(player: Player): List<String> {
39+
if (Config.getConfig().get("IntegratedPermissions.${player.uniqueId}.permissions") == null) {
40+
return listOf("player has no permissions")
41+
}
42+
43+
if (player.isOp) {
44+
return listOf("every permission because player is OP")
45+
}
46+
47+
val permissions = Config.getConfig().getList("IntegratedPermissions.${player.uniqueId}.permissions") as List<String>
48+
49+
return permissions
50+
}
51+
}

src/main/resources/plugin.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ api-version: 1.16
33
authors:
44
- Marylieh
55
main: me.marylieh.simplewarp.SimpleWarp
6-
version: 3.9
6+
version: 4.0
77

88
commands:
99
setwarp:
1010
delwarp:
1111
warp:
1212
warps:
1313
warpversion:
14-
position:
14+
position:
15+
pm:

0 commit comments

Comments
 (0)