Add first steps for gui
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
package nl.interestingcorner.coordinates.db;
|
package nl.interestingcorner.coordinates.db;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,6 +115,27 @@ public class Coordinate {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemStack toItem()
|
||||||
|
{
|
||||||
|
ItemStack itemStack = new ItemStack(this.color.toMaterial());
|
||||||
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
meta.setDisplayName(this.color.toColorCode() + this.name);
|
||||||
|
meta.setLore(List.of(
|
||||||
|
MinecraftColor.WHITE.toColorCode() + this.description,
|
||||||
|
this.nether ? MinecraftColor.RED.toColorCode() + "Nether Coordinate" : "Overworld Coordinate",
|
||||||
|
"X: " + this.position.x(),
|
||||||
|
"Y: " + this.position.y(),
|
||||||
|
"Z: " + this.position.z(),
|
||||||
|
"World: " + this.world
|
||||||
|
));
|
||||||
|
itemStack.setItemMeta(meta);
|
||||||
|
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.logging.Level;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
import nl.interestingcorner.core.db.DatabaseManager;
|
||||||
|
|
||||||
public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.DatabaseInitializeListener{
|
public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.DatabaseInitializeListener{
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.D
|
|||||||
|
|
||||||
public void initialize(JavaPlugin app) {
|
public void initialize(JavaPlugin app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
DatabaseManager.INSTANCE.registerDatabaseInitializeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,6 +158,7 @@ public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.D
|
|||||||
if (!initializeTables()) {
|
if (!initializeTables()) {
|
||||||
this.app.getLogger().severe("Could not initialize coordinates database tables");
|
this.app.getLogger().severe("Could not initialize coordinates database tables");
|
||||||
}
|
}
|
||||||
|
this.app.getLogger().info("Coordinates database tables initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public enum DatabaseManager {
|
|||||||
|
|
||||||
public void registerDatabaseInitializeListener(DatabaseInitializeListener listener) {
|
public void registerDatabaseInitializeListener(DatabaseInitializeListener listener) {
|
||||||
this.databaseInitializeListeners.add(listener);
|
this.databaseInitializeListeners.add(listener);
|
||||||
|
this.app.getLogger().log(Level.INFO, "Registered database initialize listener: {0}", listener.getClass().getName());
|
||||||
|
|
||||||
// immediately initialize if the database is already initialized
|
// immediately initialize if the database is already initialized
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
|
public class GUI implements InventoryHolder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getInventory'");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class GUIBuilder {
|
||||||
|
public static final int MAX_INVENTORY_SIZE = 54; // max size of inventory before pages are needed
|
||||||
|
public static final int MAX_PAGE_INVENTORY_SIZE = 45; // max amount of items on a page
|
||||||
|
|
||||||
|
public Inventory buildInventory(List<ItemStack> items) {
|
||||||
|
/**
|
||||||
|
* if more than 45, add pages. Split by 45 items per page.
|
||||||
|
* use bottom row leftmost and rightmost item for navigation.
|
||||||
|
* use paper item for page number display in middle.
|
||||||
|
* use lore of navigation items clicked to handle showing next/previous page.
|
||||||
|
* use player.getOpeninventory() to get current inventory and update or close
|
||||||
|
* it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int itemsAmount = items.size();
|
||||||
|
int pagesAmount = getPagesAmount(itemsAmount);
|
||||||
|
|
||||||
|
Inventory gui = Bukkit.createInventory(null, MAX_INVENTORY_SIZE, "Coordinates Menu");
|
||||||
|
|
||||||
|
for (ItemStack item : items) {
|
||||||
|
gui.addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getPagesAmount(int itemsAmount) {
|
||||||
|
if (itemsAmount > MAX_INVENTORY_SIZE) {
|
||||||
|
return ((itemsAmount / MAX_PAGE_INVENTORY_SIZE) + 1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mvn install -f "/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/pom.xml"
|
mvn install -f "/home/sem/Development/Minecraft/mc-ic-server/pom.xml"
|
||||||
mvn jar:jar -f "/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/pom.xml"
|
scp ic_plugin_core/target/ic_plugin_core-1.0-SNAPSHOT.jar sem@10.10.100.50:/home/sem/minecraft/plugins
|
||||||
|
scp ic_plugin_coordinates/target/ic_plugin_coordinates-1.0-SNAPSHOT.jar sem@10.10.100.50:/home/sem/minecraft/plugins
|
||||||
Reference in New Issue
Block a user