Inventory GUI positioned.
This commit is contained in:
parent
d210d36911
commit
bd92f26bfc
4
.idea/compiler.xml
generated
4
.idea/compiler.xml
generated
@ -6,9 +6,11 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="canvas" />
|
|
||||||
<module name="pvp" />
|
<module name="pvp" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="canvas" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -8,7 +8,6 @@
|
|||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
<option value="$PROJECT_DIR$/canvas/pom.xml" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@ -2,6 +2,5 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/canvas" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
30
pom.xml
30
pom.xml
@ -17,6 +17,36 @@
|
|||||||
<target>8</target>
|
<target>8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<configuration>
|
||||||
|
<minimizeJar>true</minimizeJar>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>log4j:log4j</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>org.ipvp:canvas:1.5.0-SNAPSHOT</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -41,7 +41,8 @@ public class Kit {
|
|||||||
HELMET,
|
HELMET,
|
||||||
CHESTPLATE,
|
CHESTPLATE,
|
||||||
LEGGINGS,
|
LEGGINGS,
|
||||||
BOOTS
|
BOOTS,
|
||||||
|
ADDITIONAL
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -3,10 +3,13 @@ package io.github.officereso;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
@ -15,7 +18,6 @@ import org.bukkit.potion.PotionData;
|
|||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
import org.ipvp.canvas.Menu;
|
import org.ipvp.canvas.Menu;
|
||||||
import org.ipvp.canvas.MenuFunctionListener;
|
import org.ipvp.canvas.MenuFunctionListener;
|
||||||
import org.ipvp.canvas.slot.ClickOptions;
|
|
||||||
import org.ipvp.canvas.slot.Slot;
|
import org.ipvp.canvas.slot.Slot;
|
||||||
import org.ipvp.canvas.type.ChestMenu;
|
import org.ipvp.canvas.type.ChestMenu;
|
||||||
|
|
||||||
@ -26,26 +28,41 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class pvp extends JavaPlugin implements Listener {
|
public class pvp extends JavaPlugin implements Listener {
|
||||||
private final FileConfiguration config = this.getConfig();
|
private final FileConfiguration config = this.getConfig();
|
||||||
private HashMap<Integer, Kit> kits = configToKit("kits.");
|
private HashMap<Integer, Kit> kits = configToKit();
|
||||||
private HashMap<Integer, Kit> potions = configToKit("potions.");
|
private Menu signMenu = ChestMenu.builder(6).title("PVP Selection Menu").build();
|
||||||
private HashMap<Integer, Kit> armor = configToKit("armor.");
|
Block signBlock;
|
||||||
private HashMap<Integer, Kit> additional = configToKit("additional.");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Menu signMenu = ChestMenu.builder(6).title("PVP Selection Menu").build();
|
Bukkit.getPluginManager().registerEvents(new MenuFunctionListener(), this);
|
||||||
|
|
||||||
for (Map.Entry<Integer, Kit> entryKit : kits.entrySet()) {
|
for (Map.Entry<Integer, Kit> entryKit : kits.entrySet()) {
|
||||||
Kit kit = entryKit.getValue();
|
Kit kit = entryKit.getValue();
|
||||||
Slot slot = signMenu.getSlot(kit.getViewPosition());
|
int value = entryKit.getKey();
|
||||||
|
Slot slot = signMenu.getSlot(value);
|
||||||
|
slot.setItem(kit.getInventoryItemList().get(0).getItemStack());
|
||||||
|
|
||||||
slot.setClickHandler((player, info) -> {
|
slot.setClickHandler((player, info) -> {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
World world = Bukkit.getWorld("world");
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new MenuFunctionListener(), this);
|
String[] signPos = config.getString("sign_pos").split(" ");
|
||||||
|
signBlock = world.getBlockAt(Integer.parseInt(signPos[0]), Integer.parseInt(signPos[1]), Integer.parseInt(signPos[2]));
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onClick(PlayerInteractEvent event) {
|
||||||
|
if (event.getClickedBlock() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getClickedBlock().equals(signBlock)) {
|
||||||
|
signMenu.open(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,100 +70,113 @@ public class pvp extends JavaPlugin implements Listener {
|
|||||||
getLogger().info("onDisable is called!");
|
getLogger().info("onDisable is called!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<Integer, Kit> configToKit(String root) {
|
private HashMap<Integer, Kit> configToKit() {
|
||||||
HashMap<Integer, Kit> kits = new HashMap<Integer, Kit>();
|
HashMap<Integer, Kit> kits = new HashMap<>();
|
||||||
|
for (String root : config.getConfigurationSection("").getKeys(false)) {
|
||||||
for (String kit : config.getConfigurationSection(root).getKeys(false)) {
|
if (root.equals("maps") || root.equals("sign_pos") || root.equals("giveSteak")) {
|
||||||
String name = config.getString(root + kit + ".name");
|
continue;
|
||||||
Integer cost = (Integer) config.get(root + kit + ".cost");
|
|
||||||
Integer position = (Integer) config.get(root + kit + ".position");
|
|
||||||
String lore = config.getString(root + kit + ".lore");
|
|
||||||
|
|
||||||
if (name == null) {
|
|
||||||
getLogger().severe(root + ' ' + kit + " has invalid name");
|
|
||||||
return null;
|
|
||||||
} // Checks for bad names.
|
|
||||||
if (cost == null) {
|
|
||||||
getLogger().severe(root + ' ' + kit + " has invalid cost");
|
|
||||||
return null;
|
|
||||||
} // Checks for bad cost.
|
|
||||||
if (position == null) {
|
|
||||||
getLogger().severe(root + ' ' + kit + " has invalid position");
|
|
||||||
return null;
|
|
||||||
} // Checks for bad position.
|
|
||||||
|
|
||||||
List<InventoryItem> inventoryItemList = new ArrayList<InventoryItem>();
|
|
||||||
|
|
||||||
if (root.equals("kits.") || root.equals("additional.")) {
|
|
||||||
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
|
||||||
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(
|
|
||||||
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
|
||||||
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
|
||||||
|
|
||||||
String enchantments = config.getString(root + kit + ".items." + item + ".enchantments");
|
|
||||||
if (enchantments != null) {
|
|
||||||
List<String[]> list = new ArrayList<String[]>();
|
|
||||||
for (String enchantment : enchantments.split(", ")) {
|
|
||||||
list.add(enchantment.split(" "));
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
for (String[] enchantmentData : list) {
|
|
||||||
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantmentData[0].toLowerCase())), Integer.parseInt(enchantmentData[1]), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
|
||||||
}
|
|
||||||
Kit kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.KIT);
|
|
||||||
kits.put(kitClass.getViewPosition(), kitClass);
|
|
||||||
}
|
}
|
||||||
if (root.equals("potions.")) {
|
root = root + '.';
|
||||||
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
|
||||||
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(
|
for (String kit : config.getConfigurationSection(root).getKeys(false)) {
|
||||||
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
String name = config.getString(root + kit + ".name");
|
||||||
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
Integer cost = (Integer) config.get(root + kit + ".cost");
|
||||||
|
Integer position = (Integer) config.get(root + kit + ".position");
|
||||||
|
String lore = config.getString(root + kit + ".lore");
|
||||||
|
|
||||||
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
if (name == null) {
|
||||||
potionMeta.setBasePotionData(new PotionData(
|
getLogger().severe(root + ' ' + kit + " has invalid name");
|
||||||
PotionType.valueOf(config.getString(root + kit + ".items." + item + ".basePotionData")),
|
return null;
|
||||||
config.getBoolean(root + kit + ".items." + item + ".extended"),
|
} // Checks for bad names.
|
||||||
config.getBoolean(root + kit + ".items." + item + ".upgraded")));
|
if (cost == null) {
|
||||||
|
getLogger().severe(root + ' ' + kit + " has invalid cost");
|
||||||
|
return null;
|
||||||
|
} // Checks for bad cost.
|
||||||
|
if (position == null) {
|
||||||
|
getLogger().severe(root + ' ' + kit + " has invalid position");
|
||||||
|
return null;
|
||||||
|
} // Checks for bad position.
|
||||||
|
|
||||||
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
List<InventoryItem> inventoryItemList = new ArrayList<>();
|
||||||
}
|
|
||||||
Kit kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.POTION);
|
|
||||||
kits.put(kitClass.getViewPosition(), kitClass);
|
|
||||||
}
|
|
||||||
if (root.equals("armor.")) {
|
|
||||||
String type = config.getString(root + kit + ".type");
|
|
||||||
|
|
||||||
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
if (root.equals("kits.") || root.equals("additional.")) {
|
||||||
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
||||||
|
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(
|
ItemStack itemStack = new ItemStack(
|
||||||
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
||||||
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
||||||
|
|
||||||
String enchantments = config.getString(root + kit + ".items." + item + ".enchantments");
|
String enchantments = config.getString(root + kit + ".items." + item + ".enchantments");
|
||||||
if (enchantments != null) {
|
if (enchantments != null) {
|
||||||
List<String[]> list = new ArrayList<String[]>();
|
List<String[]> list = new ArrayList<>();
|
||||||
for (String enchantment : enchantments.split(", ")) {
|
for (String enchantment : enchantments.split(", ")) {
|
||||||
list.add(enchantment.split(" "));
|
list.add(enchantment.split(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
for (String[] enchantmentData : list) {
|
for (String[] enchantmentData : list) {
|
||||||
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantmentData[0].toLowerCase())), Integer.parseInt(enchantmentData[1]), true);
|
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantmentData[0].toLowerCase())), Integer.parseInt(enchantmentData[1]), true);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
||||||
}
|
}
|
||||||
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
Kit kitClass;
|
||||||
|
if (root.equals("kits.")) {
|
||||||
|
kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.KIT);
|
||||||
|
}
|
||||||
|
kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.ADDITIONAL);
|
||||||
|
kits.put(kitClass.getViewPosition(), kitClass);
|
||||||
|
}
|
||||||
|
if (root.equals("potions.")) {
|
||||||
|
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
||||||
|
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
||||||
|
|
||||||
|
ItemStack itemStack = new ItemStack(
|
||||||
|
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
||||||
|
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
||||||
|
|
||||||
|
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
||||||
|
potionMeta.setBasePotionData(new PotionData(
|
||||||
|
PotionType.valueOf(config.getString(root + kit + ".items." + item + ".basePotionData")),
|
||||||
|
config.getBoolean(root + kit + ".items." + item + ".extended"),
|
||||||
|
config.getBoolean(root + kit + ".items." + item + ".upgraded")));
|
||||||
|
itemStack.setItemMeta(potionMeta);
|
||||||
|
|
||||||
|
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
||||||
|
}
|
||||||
|
Kit kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.POTION);
|
||||||
|
kits.put(kitClass.getViewPosition(), kitClass);
|
||||||
|
}
|
||||||
|
if (root.equals("armor.")) {
|
||||||
|
String type = config.getString(root + kit + ".type");
|
||||||
|
|
||||||
|
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
|
||||||
|
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
|
||||||
|
|
||||||
|
ItemStack itemStack = new ItemStack(
|
||||||
|
Material.valueOf(config.getString(root + kit + ".items." + item + ".material")), // Material located in config
|
||||||
|
(config.getInt(root + kit + ".items." + item + ".amount"))); // Amount of the item
|
||||||
|
|
||||||
|
String enchantments = config.getString(root + kit + ".items." + item + ".enchantments");
|
||||||
|
if (enchantments != null) {
|
||||||
|
List<String[]> list = new ArrayList<>();
|
||||||
|
for (String enchantment : enchantments.split(", ")) {
|
||||||
|
list.add(enchantment.split(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
for (String[] enchantmentData : list) {
|
||||||
|
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantmentData[0].toLowerCase())), Integer.parseInt(enchantmentData[1]), true);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inventoryItemList.add(new InventoryItem(itemStack, inventoryPos));
|
||||||
|
}
|
||||||
|
Kit kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.valueOf(type));
|
||||||
|
kits.put(kitClass.getViewPosition(), kitClass);
|
||||||
}
|
}
|
||||||
Kit kitClass = new Kit(name, inventoryItemList, cost, position, lore, Kit.Type.valueOf(type));
|
|
||||||
kits.put(kitClass.getViewPosition(), kitClass);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return kits;
|
return kits;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user