Skip to content

Commit

Permalink
Merge pull request #28 from SB2DD/fix/multiplayer-fix-and-memory-opti…
Browse files Browse the repository at this point in the history
…misation

fix: Fixed the close event and optimised heap usage
  • Loading branch information
devproje authored Dec 10, 2024
2 parents b85574d + 948721d commit ea4f138
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.bukkit.Bukkit
import org.bukkit.block.Container
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.HandlerList
import org.bukkit.event.Listener
import org.bukkit.event.inventory.*
import org.bukkit.event.player.PlayerSwapHandItemsEvent
Expand Down Expand Up @@ -78,8 +79,8 @@ data class LinkedInventoryBuilder(
@EventHandler
private fun InventoryClickEvent.listener() {
if (title.compareTo(this.view.title())) {
if (inventoryIds.contains(id) && this.currentItem != null && this.view.player == player) {
if (this.inventory == inventory) {
if (inventoryIds.contains(id) && this.currentItem != null && view.player == this@LinkedInventoryBuilder.player) {
if (inventory == this@LinkedInventoryBuilder.inventory) {
for (slot in slots.entries) {
if (slot.key == this.rawSlot){
this.isCancelled = true
Expand All @@ -93,6 +94,7 @@ data class LinkedInventoryBuilder(
}
}

@EventHandler
private fun InventoryMoveItemEvent.listener2() {
if (inventoryIds.contains(id) && this.source.holder?.inventory?.viewers?.contains(player)!!
&& this.source.holder is Container && (this.source.holder as Container).customName() == title
Expand All @@ -102,17 +104,19 @@ data class LinkedInventoryBuilder(

@EventHandler
private fun InventoryCloseEvent.listener3() {
for(closeHandler in closeHandlers) {
closeHandler(this)
}
if (this.view.player == player && inventoryIds.contains(id))
if (view.player == this@LinkedInventoryBuilder.player && inventoryIds.contains(id)) {
for(closeHandler in closeHandlers) {
closeHandler(this)
}
inventoryIds.remove(id)
HandlerList.unregisterAll(this@LinkedInventoryBuilder)
}
}

@EventHandler
private fun PlayerSwapHandItemsEvent.listener4() {
if (this.player.inventory == inventory) {
this.isCancelled = true
if (player.inventory == this@LinkedInventoryBuilder.inventory) {
isCancelled = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.bukkit.Bukkit
import org.bukkit.block.Container
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.HandlerList
import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryCloseEvent
Expand Down Expand Up @@ -65,9 +66,9 @@ class SimpleInventoryBuilder(

@EventHandler
private fun InventoryClickEvent.listener() {
if (title.compareTo(this.view.title())) {
if (inventoryIds.contains(id) && this.currentItem != null && this.view.player == player) {
if (this.inventory == inventory) {
if (title.compareTo(view.title())) {
if (inventoryIds.contains(id) && this.currentItem != null && view.player == this@SimpleInventoryBuilder.player) {
if (inventory == this@SimpleInventoryBuilder.inventory) {
for (slot in slots.entries) {
if (slot.key == this.rawSlot){
this.isCancelled = true
Expand All @@ -88,15 +89,17 @@ class SimpleInventoryBuilder(

@EventHandler
private fun InventoryCloseEvent.listener3() {
for(closeHandler in closeHandlers)
closeHandler(this)
if(this.view.player == player && inventoryIds.contains(id))
if(view.player == this@SimpleInventoryBuilder.player && inventoryIds.contains(id)) {
for(closeHandler in closeHandlers)
closeHandler(this)
inventoryIds.remove(id)
HandlerList.unregisterAll(this@SimpleInventoryBuilder)
}
}

@EventHandler
private fun PlayerSwapHandItemsEvent.listener4() {
if (this.player.inventory == inventory) {
if (player.inventory == this@SimpleInventoryBuilder.inventory) {
this.isCancelled = true
}
}
Expand Down

0 comments on commit ea4f138

Please sign in to comment.