Inventory GUI positioned.

This commit is contained in:
officereso 2020-06-09 22:52:41 -05:00
parent d210d36911
commit bd92f26bfc
6 changed files with 159 additions and 98 deletions

4
.idea/compiler.xml generated
View File

@ -6,9 +6,11 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="canvas" />
<module name="pvp" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="canvas" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

1
.idea/misc.xml generated
View File

@ -8,7 +8,6 @@
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/canvas/pom.xml" />
</list>
</option>
</component>

1
.idea/vcs.xml generated
View File

@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/canvas" vcs="Git" />
</component>
</project>

30
pom.xml
View File

@ -17,6 +17,36 @@
<target>8</target>
</configuration>
</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>
</build>
<repositories>

View File

@ -41,7 +41,8 @@ public class Kit {
HELMET,
CHESTPLATE,
LEGGINGS,
BOOTS
BOOTS,
ADDITIONAL
}
public String getName() {

View File

@ -3,10 +3,13 @@ package io.github.officereso;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
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.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
@ -15,7 +18,6 @@ import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import org.ipvp.canvas.Menu;
import org.ipvp.canvas.MenuFunctionListener;
import org.ipvp.canvas.slot.ClickOptions;
import org.ipvp.canvas.slot.Slot;
import org.ipvp.canvas.type.ChestMenu;
@ -26,26 +28,41 @@ import java.util.Map;
public class pvp extends JavaPlugin implements Listener {
private final FileConfiguration config = this.getConfig();
private HashMap<Integer, Kit> kits = configToKit("kits.");
private HashMap<Integer, Kit> potions = configToKit("potions.");
private HashMap<Integer, Kit> armor = configToKit("armor.");
private HashMap<Integer, Kit> additional = configToKit("additional.");
private HashMap<Integer, Kit> kits = configToKit();
private Menu signMenu = ChestMenu.builder(6).title("PVP Selection Menu").build();
Block signBlock;
@Override
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()) {
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) -> {
});
}
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();
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
@ -53,100 +70,113 @@ public class pvp extends JavaPlugin implements Listener {
getLogger().info("onDisable is called!");
}
private HashMap<Integer, Kit> configToKit(String root) {
HashMap<Integer, Kit> kits = new HashMap<Integer, Kit>();
for (String kit : config.getConfigurationSection(root).getKeys(false)) {
String name = config.getString(root + kit + ".name");
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);
private HashMap<Integer, Kit> configToKit() {
HashMap<Integer, Kit> kits = new HashMap<>();
for (String root : config.getConfigurationSection("").getKeys(false)) {
if (root.equals("maps") || root.equals("sign_pos") || root.equals("giveSteak")) {
continue;
}
if (root.equals("potions.")) {
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
root = root + '.';
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
for (String kit : config.getConfigurationSection(root).getKeys(false)) {
String name = config.getString(root + kit + ".name");
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();
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")));
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.
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");
List<InventoryItem> inventoryItemList = new ArrayList<>();
for (String item : config.getConfigurationSection(root + kit + ".items").getKeys(false)) {
Integer inventoryPos = (Integer) config.get(root + kit + ".items." + item + ".inventoryPos");
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
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);
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));
}
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;