Skip to content

Commit

Permalink
Add "sides mode"
Browse files Browse the repository at this point in the history
  • Loading branch information
MP3Martin committed Nov 21, 2022
1 parent eec0708 commit 1665625
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.mp3martin.biggerhotbar</groupId>
<artifactId>BiggerHotbar</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<packaging>jar</packaging>

<name>BiggerHotbar</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BiggerHotbar : JavaPlugin() {

config.addDefault("bh_enabled", false)
config.addDefault("maxMovesAtOnce", 4)
config.addDefault("mode", "center")
config.options().copyDefaults(true)
saveConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,58 @@ class EventListener(plugin: BiggerHotbar) : Listener {
val oldSlot = event.player.inventory.heldItemSlot
val bhIsEnabled = plugin.config.getBoolean("bh_enabled")
val maxMovesAtOnce = plugin.config.getInt("maxMovesAtOnce")
val mode = plugin.config.getString("mode")
if (bhIsEnabled && event.player.hasPermission("biggerhotbar.hotbar")) {
// - BiggerHotbar is enabled -
// - Player has permission -

scheduleSyncDelayedTask(plugin, {
val oldSlot = event.player.inventory.heldItemSlot
if (mode == "sides") {
// - Mode is sides -
scheduleSyncDelayedTask(plugin, {
val newSlot = event.player.inventory.heldItemSlot
// event.player.sendMessage("$oldSlot + $newSlot")
val moveLeftOldSlot = (oldSlot == 6 || oldSlot == 7 || oldSlot == 8)
val moveRightOldSlot = (oldSlot == 0 || oldSlot == 1 || oldSlot == 2)
if ((moveLeftOldSlot && (newSlot == 0 || newSlot == 1 || newSlot == 2)) || (oldSlot == 7 && newSlot == 8) || (oldSlot == 6 && newSlot == 7) || (oldSlot == 6 && newSlot == 8)) {
event.player.inventory.heldItemSlot = 6
moveItemsHotbarInvSmall(plugin, event.player, 0)
} else if ((moveRightOldSlot && (newSlot == 8 || newSlot == 7 || newSlot == 6)) || (oldSlot == 1 && newSlot == 0) || (oldSlot == 2 && newSlot == 1) || (oldSlot == 2 && newSlot == 0)) {
event.player.inventory.heldItemSlot = 2
moveItemsHotbarInvSmall(plugin, event.player, 1)
}
}, 1)
} else {
// - Mode is center -
scheduleSyncDelayedTask(plugin, {
val oldSlot = event.player.inventory.heldItemSlot

event.player.inventory.heldItemSlot = 4
event.player.inventory.heldItemSlot = 4

var scrLeft = oldSlot - 4
var scrRight = 4 - oldSlot
val scrLeft = oldSlot - 4
val scrRight = 4 - oldSlot

if (oldSlot != 4) {
if (oldSlot > 4) {
for (i in 0..min(scrLeft, maxMovesAtOnce) -1) {
moveItemsHotbarInvSmall(plugin, event.player, 0)
}
} else {
for (i in 0..min(scrRight, maxMovesAtOnce) -1) {
moveItemsHotbarInvSmall(plugin, event.player, 1)
if (oldSlot != 4) {
if (oldSlot > 4) {
for (i in 0..min(scrLeft, maxMovesAtOnce) - 1) {
moveItemsHotbarInvSmall(plugin, event.player, 0)
}
} else {
for (i in 0..min(scrRight, maxMovesAtOnce) - 1) {
moveItemsHotbarInvSmall(plugin, event.player, 1)
}
}
}
}
}, 1)
}, 1)
}
}
return
}

@EventHandler
fun onPlayerJoinEvent(event: PlayerJoinEvent) {
centerHotbar(plugin)
val mode = plugin.config.getString("mode")
if (mode == "center") {
centerHotbar(plugin)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.bukkit.entity.Player
import xyz.mp3martin.biggerhotbar.biggerhotbar.BiggerHotbar
import xyz.mp3martin.biggerhotbar.biggerhotbar.utils.Settings.formatMessage
import xyz.mp3martin.biggerhotbar.biggerhotbar.utils.centerHotbar
import xyz.mp3martin.biggerhotbar.biggerhotbar.utils.moveItemsHotbarInvSmall


class BiggerhotbarCommand(plugin: BiggerHotbar) : TabExecutor {
Expand Down Expand Up @@ -83,6 +82,32 @@ class BiggerhotbarCommand(plugin: BiggerHotbar) : TabExecutor {
p.sendMessage(formatMessage("BiggerHotbar is $status"))
}

"mode" -> {
val mode = plugin.config.getString("mode")
try {
args[1]
} catch (e: Throwable) {
args = arrayOf("NOO", "NOO")
}
if (args[1] == "NOO") {
p.sendMessage(formatMessage("Current mode is §3$mode"))
p.sendMessage(formatMessage("All available modes are: §3center§r, §3sides"))
} else if (args[1].lowercase() == "center") {
plugin.config.set("mode", "center")
centerHotbar(plugin)
p.sendMessage(formatMessage("Successfully changed mode to §3center"))
plugin.saveConfig()
plugin.reloadConfig()
} else if (args[1].lowercase() == "sides") {
plugin.config.set("mode", "sides")
p.sendMessage(formatMessage("Successfully changed mode to §3sides"))
plugin.saveConfig()
plugin.reloadConfig()
} else {
return false
}
}

"reload" -> {
val success = try {
plugin.reloadConfig()
Expand Down Expand Up @@ -128,11 +153,17 @@ class BiggerhotbarCommand(plugin: BiggerHotbar) : TabExecutor {
if (sender.hasPermission("biggerhotbar.commands")) {
return when (args.size) {
1 -> {
mutableListOf("enable", "disable", "toggle", "status", "reload", "version")
mutableListOf("enable", "disable", "toggle", "status", "mode", "reload", "version")
}

2 -> {
null
if (args[0] == "mode") {
mutableListOf("center", "sides")
} else {
null
}
}

else -> {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import xyz.mp3martin.biggerhotbar.biggerhotbar.BiggerHotbar

fun centerHotbar(plugin: BiggerHotbar) {
val bhIsEnabled = plugin.config.getBoolean("bh_enabled")
if (bhIsEnabled) {
val mode = plugin.config.getString("mode")
if (bhIsEnabled && mode == "center") {
for (player in getOnlinePlayers()) {
if(player.hasPermission("biggerhotbar.hotbar")) {
if (player.inventory.heldItemSlot != 4) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ commands:
biggerhotbar:
aliases: [bh, bhotbar, biggerh]
description: Control bigger hotbar plugin
usage: /<command> { enable | disable | toggle | status | reload }
usage: /<command> <enable | disable | toggle | status | mode [center | sides] | reload | version>

0 comments on commit 1665625

Please sign in to comment.