This commit is contained in:
Auxilor
2021-08-12 00:24:35 +01:00
parent b652dbad2d
commit 46415268b7
5 changed files with 49 additions and 9 deletions

View File

@@ -17,6 +17,6 @@ public class MenuUtils {
public Pair<Integer, Integer> convertSlotToRowColumn(final int slot) {
int row = Math.floorDiv(slot, 9);
int column = slot - row * 9;
return new Pair<>(row, column);
return new Pair<>(row + 1, column + 1);
}
}

View File

@@ -16,7 +16,7 @@ import java.util.function.Consumer
class EcoMenuBuilder(private val rows: Int) : MenuBuilder {
private var title = "Menu"
private var maskSlots: List<MutableList<Slot?>>
private val slots: List<MutableList<Slot>> = ListUtils.create2DList(rows, 9)
private val slots: List<MutableList<Slot?>> = ListUtils.create2DList(rows, 9)
private var onClose = Consumer { _: InventoryCloseEvent -> }
override fun setTitle(title: String): MenuBuilder {
@@ -46,15 +46,14 @@ class EcoMenuBuilder(private val rows: Int) : MenuBuilder {
}
override fun build(): Menu {
val finalSlots: MutableList<MutableList<Slot>> = ArrayList()
val tempSlots: MutableList<MutableList<Slot>> = ListUtils.create2DList(rows, 9);
for (maskRow in maskSlots) {
val row = ArrayList<Slot>()
for (slot in maskRow) {
row.add(slot ?: EcoFillerSlot(ItemStack(Material.AIR)))
}
finalSlots.add(ArrayList())
finalSlots.add(row)
tempSlots.add(row)
}
for (i in slots.indices) {
@@ -63,11 +62,14 @@ class EcoMenuBuilder(private val rows: Int) : MenuBuilder {
if (slot is FillerSlot) {
slot = EcoFillerSlot(slot.itemStack)
}
finalSlots[i][j] = slot
if (slot == null && maskSlots[i][j] != null) {
slot = EcoFillerSlot(ItemStack(Material.AIR))
}
tempSlots[i][j] = slot ?: EcoFillerSlot(ItemStack(Material.AIR))
}
}
return EcoMenu(rows, finalSlots, title, onClose)
return EcoMenu(rows, tempSlots, title, onClose)
}
init {

View File

@@ -17,6 +17,7 @@ import com.willfp.eco.spigot.display.*
import com.willfp.eco.spigot.drops.CollatedRunnable
import com.willfp.eco.spigot.eventlisteners.*
import com.willfp.eco.spigot.gui.GUIListener
import com.willfp.eco.spigot.gui.GUITester
import com.willfp.eco.spigot.integrations.anticheat.*
import com.willfp.eco.spigot.integrations.antigrief.*
import com.willfp.eco.spigot.integrations.customitems.CustomItemsOraxen
@@ -141,7 +142,8 @@ abstract class EcoSpigotPlugin : EcoPlugin(
PlayerJumpListeners(),
GUIListener(this),
ArrowDataListener(this),
ArmorChangeEventListeners(this)
ArmorChangeEventListeners(this),
GUITester(this)
)
}
}

View File

@@ -0,0 +1,36 @@
package com.willfp.eco.spigot.gui
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.slot.FillerMask
import com.willfp.eco.core.gui.slot.Slot
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.AsyncPlayerChatEvent
import org.bukkit.inventory.ItemStack
class GUITester(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Listener {
val menu: Menu = Menu.builder(3)
.setMask(FillerMask(
Material.BLACK_STAINED_GLASS_PANE,
"111111111",
"100000001",
"111111111"
)).setSlot(
2, 2,
Slot.builder(ItemStack(Material.RED_STAINED_GLASS_PANE))
.setCaptive()
.build()
).build()
@EventHandler
fun test(event: AsyncPlayerChatEvent) {
if (!event.message.equals("testgui", true)) {
return
}
plugin.scheduler.run{menu.open(event.player)}
}
}

View File

@@ -1,2 +1,2 @@
version = 6.3.3
version = 6.4.0
plugin-name = eco