Skip to content

Commit

Permalink
Fixed spawn saving + gm on join
Browse files Browse the repository at this point in the history
Signed-off-by: XAP3Y <github@xap3x.dev>
  • Loading branch information
xap3y committed Apr 12, 2024
1 parent 0d0aa5b commit 4ff815e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/main/java/me/xap3y/xacore/api/text/Texter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import me.xap3y.xacore.Main
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

@Suppress("DEPRECATION")
class Texter(private val plugin: Main) {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/me/xap3y/xacore/commands/AdminCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,27 @@ class AdminCommands(private val plugin: Main) {
wPrefix = true
)

if (speed < 1 || speed > 10)
if (speed < 0 || speed > 20)
return plugin.textApi.commandReply(
commandSender,
"messages.speedRange",
hashMapOf("speed" to speed.toString()),
true,
"<prefix> &cSpeed must be between 1 and 10!"
"<prefix> &cSpeed must be between 0 and 20!"
)

val realSpeed = if (speed == 0) if (commandSender.isFlying) 2/20f else 4/20f else speed/20f

if (commandSender.isFlying)
commandSender.flySpeed = speed / 20f
commandSender.flySpeed = realSpeed
else
commandSender.walkSpeed = speed / 20f
commandSender.walkSpeed = realSpeed


plugin.textApi.commandReply(
commandSender,
"messages.speedMessage",
hashMapOf("speed" to speed.toString()),
hashMapOf("speed" to realSpeed.toString()),
true,
"<prefix> &fYour speed has been set to &e<speed>&f!"
)
Expand Down Expand Up @@ -165,6 +168,7 @@ class AdminCommands(private val plugin: Main) {
plugin.config.set("spawn.z", commandSender.location.z)
plugin.config.set("spawn.yaw", commandSender.location.yaw)
plugin.config.set("spawn.pitch", commandSender.location.pitch)
plugin.config.save(plugin.configFile)

plugin.textApi.commandReply(
commandSender,
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/me/xap3y/xacore/listeners/PlayerJoinListener.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.xap3y.xacore.listeners

import me.xap3y.xacore.Main
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
Expand Down Expand Up @@ -43,6 +44,23 @@ class PlayerJoinListener(private val plugin: Main): Listener {

// TODO -- Scoreboard and maybe tab-list?

// Gamemode on join
val gamemodeOnJoinToggle = plugin.config.getBoolean("gamemodeOnJoinToggle")
if (gamemodeOnJoinToggle) {

val gamemodeOnJoin = plugin.config.getString("gamemodeOnJoin") ?: "SURVIVAL"
// get gamemode from string
val gamemode = when (gamemodeOnJoin.uppercase()) {
"SURVIVAL" -> org.bukkit.GameMode.SURVIVAL
"CREATIVE" -> org.bukkit.GameMode.CREATIVE
"ADVENTURE" -> org.bukkit.GameMode.ADVENTURE
"SPECTATOR" -> org.bukkit.GameMode.SPECTATOR
else -> org.bukkit.GameMode.SURVIVAL
}
Bukkit.getScheduler().runTask(plugin, Runnable {
e.player.gameMode = gamemode
})
}

}

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ chatFormat: true

spawnOnJoin: true

commandBlackList: true
commandBlackList: true

gamemodeOnJoinToggle: false
gamemodeOnJoin: "creative"

0 comments on commit 4ff815e

Please sign in to comment.