Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.softwarerat.API.builder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
public class ItemBuilder {
|
||||
// Basic ItemBuilder
|
||||
private final ItemMeta itemMeta;
|
||||
private final ItemStack itemStack;
|
||||
public ItemBuilder(Material mat){
|
||||
itemStack = new ItemStack(mat);
|
||||
itemMeta = itemStack.getItemMeta();
|
||||
}
|
||||
public ItemBuilder setDisplayname(String s){
|
||||
itemMeta.setDisplayName(s);
|
||||
return this;
|
||||
}
|
||||
public ItemBuilder setLocalizedName(String s){
|
||||
itemMeta.setLocalizedName(s);
|
||||
return this;
|
||||
}
|
||||
public ItemBuilder setLore(String... s){
|
||||
itemMeta.setLore(Arrays.asList(s));
|
||||
return this;
|
||||
}
|
||||
public ItemBuilder setUnbreakable(boolean s){
|
||||
itemMeta.setUnbreakable(s);
|
||||
return this;
|
||||
}
|
||||
public ItemBuilder addItemFlags(ItemFlag... s){
|
||||
itemMeta.addItemFlags(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemBuilder{" +
|
||||
"itemMeta=" + itemMeta +
|
||||
", itemStack=" + itemStack +
|
||||
'}';
|
||||
}
|
||||
public ItemStack build(){
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.softwarerat.API.builder;
|
||||
|
||||
import com.softwarerat.GameAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// Inventory Builder
|
||||
|
||||
public final class SpigotInventory implements Listener{
|
||||
|
||||
private final PlayerInventory playerInventory;
|
||||
private final Map<ItemStack, Consumer<PlayerInteractEvent>> clickActions;
|
||||
private GameAPI gameAPI;
|
||||
|
||||
public SpigotInventory(Player player, JavaPlugin javaPlugin) {
|
||||
this.clickActions = new HashMap<>();
|
||||
this.playerInventory = player.getInventory();
|
||||
Bukkit.getPluginManager().registerEvents(this,javaPlugin );
|
||||
}
|
||||
|
||||
public SpigotInventory addItem(ItemStack... items) {
|
||||
this.playerInventory.addItem(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setHelmet(ItemStack item) {
|
||||
this.playerInventory.setHelmet(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setChestplate(ItemStack item) {
|
||||
this.playerInventory.setChestplate(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setLeggings(ItemStack item) {
|
||||
this.playerInventory.setLeggings(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setBoots(ItemStack item) {
|
||||
this.playerInventory.setBoots(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated public SpigotInventory setItemInHand(ItemStack item) {
|
||||
this.playerInventory.setItemInHand(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setItemInHand(ItemStack item, Hand hand) {
|
||||
hand.setItem(this.playerInventory, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setItemInMainHand(ItemStack item) {
|
||||
this.playerInventory.setItemInMainHand(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setItemInOffHand(ItemStack item) {
|
||||
this.playerInventory.setItemInOffHand(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SpigotInventory setArmorContents(ItemStack[] item) {
|
||||
this.playerInventory.setArmorContents(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setSlot(@Nonnull ItemStack item, int slot, @Nonnull Consumer<PlayerInteractEvent> clickAction) {
|
||||
this.setSlot(item, slot);
|
||||
this.clickActions.put(item, clickAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setSlot(ItemStack item, int slot) {
|
||||
this.playerInventory.setItem(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setSlot(ItemStack item, int... slots) {
|
||||
for (byte b = 0; b <= (byte) slots.length; b++) { this.playerInventory.setItem(slots[b], item); }
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory setSlot(ItemStack item, List<Integer> slots) {
|
||||
slots.forEach(slot -> this.playerInventory.setItem(slot, item));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory forEach(Consumer<? super ItemStack> action) {
|
||||
this.playerInventory.forEach(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory clear() {
|
||||
this.playerInventory.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory clear(int slot) {
|
||||
this.playerInventory.clear(slot);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory clear(int... slots) {
|
||||
for (int slot : slots) { this.playerInventory.clear(slot); }
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotInventory clear(@Nonnull List<Integer> slots) {
|
||||
slots.stream().forEach(slot -> this.playerInventory.clear(slot));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getSlot(@Nonnull Material material) {
|
||||
for (int slot = 0; slot < this.playerInventory.getSize(); slot++) {
|
||||
if(this.getItem(slot) == null) continue;
|
||||
if (this.getItem(slot).getType() != material) continue;
|
||||
return slot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ItemStack getItem(@Nonnull Material material) {
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != material) continue;
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getItem(@Nonnull ItemStack item) {
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != item.getType()) continue;
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getItem(@Nonnull Material material, int amaunt) {
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != material) continue;
|
||||
if(itemStack.getAmount() < amaunt) continue;
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getItem(@Nonnull ItemStack item, int amaunt) {
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != item.getType()) continue;
|
||||
if(itemStack.getAmount() < amaunt) continue;
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getAmount(@Nonnull ItemStack item) {
|
||||
var amount = 0;
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != item.getType()) continue;
|
||||
amount += itemStack.getAmount();
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int getAmount(@Nonnull Material material) {
|
||||
var amount = 0;
|
||||
for (ItemStack itemStack : this.playerInventory.getContents()) {
|
||||
if(itemStack == null) continue;
|
||||
if(itemStack.getType() != material) continue;
|
||||
amount += itemStack.getAmount();
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public SpigotInventory removeItems(ItemStack item, int amount) {
|
||||
if (amount <= 0) return this;
|
||||
int size = this.playerInventory.getSize();
|
||||
for (int slot = 0; slot < size; slot++) {
|
||||
ItemStack invItem = this.getItem(slot);
|
||||
if (invItem == null) continue;
|
||||
if (!invItem.isSimilar(item)) continue;
|
||||
int newAmount = invItem.getAmount() - amount;
|
||||
if (newAmount > 0) {
|
||||
invItem.setAmount(newAmount);
|
||||
break;
|
||||
}
|
||||
|
||||
this.playerInventory.clear(slot);
|
||||
amount = -newAmount;
|
||||
if (amount == 0) break;
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmorContents() { return this.playerInventory.getArmorContents(); }
|
||||
public ItemStack getChestplate() { return this.playerInventory.getChestplate(); }
|
||||
public ItemStack getLeggings() { return this.playerInventory.getLeggings(); }
|
||||
public ItemStack getBoots() { return this.playerInventory.getBoots(); }
|
||||
public ItemStack getHelmet() { return this.playerInventory.getHelmet(); }
|
||||
public HumanEntity getHolder() { return this.playerInventory.getHolder(); }
|
||||
public ItemStack[] getContents() { return this.playerInventory.getContents(); }
|
||||
public int getHeldItemSlot() { return this.playerInventory.getHeldItemSlot(); }
|
||||
public ItemStack getItem(int slot) { return this.playerInventory.getItem(slot); }
|
||||
public ItemStack getItemInMainHand() { return this.playerInventory.getItemInMainHand(); }
|
||||
public ItemStack getItemInOffHand() { return this.playerInventory.getItemInOffHand(); }
|
||||
public int getMaxStackSize() { return this.playerInventory.getMaxStackSize(); }
|
||||
public ItemStack[] getExtraContents() { return this.playerInventory.getExtraContents(); }
|
||||
public int getSize() { return this.playerInventory.getSize(); }
|
||||
public Location getLocation() { return this.playerInventory.getLocation(); }
|
||||
public ItemStack[] getStorageContents() { return this.playerInventory.getStorageContents(); }
|
||||
public InventoryType getType() { return this.playerInventory.getType(); }
|
||||
public List<HumanEntity> getViewers() { return this.playerInventory.getViewers(); }
|
||||
public boolean isEmpty() { return this.playerInventory.isEmpty(); }
|
||||
public ItemStack getItem(EquipmentSlot slot) { return this.playerInventory.getItem(slot); }
|
||||
@Deprecated public ItemStack getItemInHand() { return this.playerInventory.getItemInHand(); }
|
||||
public ItemStack getItemInHand(Hand hand) { return hand.getItem(this.playerInventory); }
|
||||
|
||||
public enum Hand {
|
||||
MAIN {
|
||||
@Override public ItemStack getItem(PlayerInventory inventory) { return inventory.getItemInMainHand(); }
|
||||
@Override public void setItem(PlayerInventory inventory, ItemStack item) { inventory.setItemInMainHand(item); }
|
||||
},
|
||||
OFF {
|
||||
@Override public ItemStack getItem(PlayerInventory inventory) { return inventory.getItemInOffHand(); }
|
||||
@Override public void setItem(PlayerInventory inventory, ItemStack item) { inventory.setItemInOffHand(item); }
|
||||
};
|
||||
|
||||
public abstract ItemStack getItem(PlayerInventory inventory);
|
||||
public abstract void setItem(PlayerInventory inventory, ItemStack item);
|
||||
}
|
||||
|
||||
@EventHandler public void onInteract(PlayerInteractEvent interactEvent) {
|
||||
var item = interactEvent.getItem();
|
||||
if(item == null) return;
|
||||
if(!this.clickActions.containsKey(item)) return;
|
||||
this.clickActions.get(item).accept(interactEvent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.softwarerat.API.builder;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
// Another Item Builder
|
||||
public class SpigotItem {
|
||||
private ItemStack itemStack;
|
||||
private String textures;
|
||||
|
||||
private String colorCode(@Nonnull String message) { return ChatColor.translateAlternateColorCodes('&', message); }
|
||||
|
||||
public SpigotItem(@Nonnull Material material, @Nonnull int amount) {
|
||||
this.itemStack = new ItemStack(material, amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public SpigotItem(@Nonnull Material material) { this(material, 1); }
|
||||
public SpigotItem(@Nonnull ItemStack itemStack) { this(itemStack.getType()); }
|
||||
|
||||
public SpigotItem setAmount(int amount) {
|
||||
this.itemStack.setAmount(amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setName(@Nonnull String name) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
itemMeta.setDisplayName(colorCode(name));
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setLore(@Nonnull String lore) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
itemMeta.setLore(Arrays.asList(colorCode(lore)));
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setLore(@Nonnull String... lores) {
|
||||
List<String> colored = new ArrayList<>();
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
for (String lore : lores) { colored.add(this.colorCode(lore)); }
|
||||
itemMeta.setLore(colored);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setLore(@Nonnull List<String> lore) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
List<String> colored = lore.stream().filter(Objects::nonNull).map(this::colorCode).collect(Collectors.toList());
|
||||
itemMeta.setLore(colored);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem removeLoreLine(@Nonnull String line) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
if (!lore.contains(line)) return this;
|
||||
lore.remove(colorCode(line));
|
||||
itemMeta.setLore(lore);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem removeLoreLine(int index) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
if (index < 0 || index > lore.size()) return this;
|
||||
lore.remove(index);
|
||||
itemMeta.setLore(lore);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem addLoreLine(@Nonnull String line) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (itemMeta.hasLore()) lore = new ArrayList<>(itemMeta.getLore());
|
||||
lore.add(colorCode(line));
|
||||
itemMeta.setLore(lore);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem addLoreLine(@Nonnull String line, int pos) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
List<String> lore = new ArrayList<>(itemMeta.getLore());
|
||||
lore.set(pos, colorCode(line));
|
||||
itemMeta.setLore(lore);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem addEnchant(@Nonnull Enchantment ench, int level) {
|
||||
this.itemStack.addEnchantment(ench, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem addUnsafeEnchantment(@Nonnull Enchantment ench, int level) {
|
||||
this.itemStack.addUnsafeEnchantment(ench, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem addEnchantments(@Nonnull Map<Enchantment, Integer> ench) {
|
||||
this.itemStack.addEnchantments(ench);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem removeEnchant(@Nonnull Enchantment ench) {
|
||||
this.itemStack.removeEnchantment(ench);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SpigotItem setOwner(@Nonnull String owner) {
|
||||
if (Material.LEGACY_SKULL_ITEM.equals(this.itemStack.getType())) {
|
||||
if (this.itemStack.getDurability() != 3) this.itemStack.setDurability((short)3);
|
||||
SkullMeta skullMeta = (SkullMeta) this.itemStack.getItemMeta();
|
||||
skullMeta.setOwner(owner);
|
||||
this.itemStack.setItemMeta(skullMeta);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SpigotItem setColor(@Nonnull DyeColor color) {
|
||||
this.itemStack.setDurability(color.getDyeData());
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setFireworkColor(@Nonnull Color... color) {
|
||||
if (this.itemStack.getType() == Material.FIREWORK_STAR) {
|
||||
FireworkEffectMeta meta = (FireworkEffectMeta) this.itemStack.getItemMeta();
|
||||
meta.setEffect(FireworkEffect.builder().withColor(color).build());
|
||||
this.itemStack.setItemMeta(meta);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setItemFlag(@Nonnull ItemFlag... flags) {
|
||||
ItemMeta meta = this.itemStack.getItemMeta();
|
||||
meta.addItemFlags(flags);
|
||||
this.itemStack.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setAllItemFlag() {
|
||||
ItemMeta meta = this.itemStack.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
this.itemStack.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setUnbreakable(boolean unbreakable) {
|
||||
this.itemStack.getItemMeta().setUnbreakable(unbreakable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setGlowing() {
|
||||
this.itemStack.addUnsafeEnchantment(Enchantment.LUCK, 1);
|
||||
ItemMeta meta = this.itemStack.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
this.itemStack.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem unGlowing() {
|
||||
this.itemStack.removeEnchantment(Enchantment.LUCK);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setArmorColor(@Nonnull Color color) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemStack.getItemMeta();
|
||||
leatherArmorMeta.setColor(color);
|
||||
this.itemStack.setItemMeta(leatherArmorMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotItem setMeta(@Nonnull ItemMeta meta) {
|
||||
this.itemStack.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getLore() { return this.itemStack.getItemMeta().getLore(); }
|
||||
public Set<ItemFlag> getItemFlags() { return this.itemStack.getItemMeta().getItemFlags(); }
|
||||
public String getName() { return this.itemStack.getItemMeta().getDisplayName(); }
|
||||
public boolean hasItemFlag(@Nonnull ItemFlag flag) { return this.itemStack.getItemMeta().hasItemFlag(flag); }
|
||||
public boolean hasDisplay() { return this.itemStack.getItemMeta().hasDisplayName(); }
|
||||
public boolean hasLore() { return this.itemStack.getItemMeta().hasLore(); }
|
||||
public boolean isUnbreakable() { return this.itemStack.getItemMeta().isUnbreakable(); }
|
||||
// public boolean isSimilar() { return this.itemStack.isSimilar(this.itemStack); }
|
||||
public boolean isSimilar(@Nonnull ItemStack item) { return this.itemStack.isSimilar(item); }
|
||||
@Deprecated public short getDurability() { return this.itemStack.getDurability(); }
|
||||
public int getStackSize() { return this.itemStack.getMaxStackSize(); }
|
||||
public int getAmount() { return this.itemStack.getAmount(); }
|
||||
public String getTextures() { return this.textures; }
|
||||
public Map<Enchantment, Integer> getEnchants() { return this.itemStack.getEnchantments(); }
|
||||
public boolean hasEnchant(@Nonnull Enchantment ench) { return this.itemStack.getItemMeta().hasEnchant(ench); }
|
||||
public boolean hasEnchants() { return this.itemStack.getItemMeta().hasEnchants(); }
|
||||
public int getEnchantmentLevel(@Nonnull Enchantment ench) { return this.itemStack.getEnchantmentLevel(ench); }
|
||||
public ItemMeta getMeta() { return this.itemStack.getItemMeta(); }
|
||||
public Material getType() { return this.itemStack.getType(); }
|
||||
|
||||
public ItemStack build() { return this.itemStack; }
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package com.softwarerat.API.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
import com.softwarerat.GameAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
// UI Builder
|
||||
public final class SpigotUI implements Listener {
|
||||
private static Map<Player, Boolean> openList = new HashMap<>();
|
||||
|
||||
private final Inventory inventory;
|
||||
private final Map<Integer, Consumer<InventoryClickEvent>> clickActions;
|
||||
private Runnable callback;
|
||||
private final List<Integer> freeSlots;
|
||||
private Player player;
|
||||
private int rows;
|
||||
|
||||
|
||||
|
||||
private String title;
|
||||
|
||||
public SpigotUI(InventoryHolder holder, int rows, JavaPlugin javaPlugin) {
|
||||
if (rows >= 7) rows = 6;
|
||||
this.inventory = Bukkit.createInventory(holder, rows * 9);
|
||||
this.rows = rows;
|
||||
if (holder != null) this.player = (Player)holder;
|
||||
this.freeSlots = new ArrayList<>();
|
||||
this.clickActions = new HashMap<>();
|
||||
openList.put(player, false);
|
||||
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
|
||||
}
|
||||
|
||||
public SpigotUI(InventoryHolder holder, @Nonnull InventoryType type,JavaPlugin javaPlugin) {
|
||||
this.inventory = Bukkit.createInventory(holder, type);
|
||||
this.rows = -1;
|
||||
if (holder != null) this.player = (Player)holder;
|
||||
if (type == InventoryType.CHEST) this.rows = 3;
|
||||
this.freeSlots = new ArrayList<>();
|
||||
this.clickActions = new HashMap<>();
|
||||
openList.put(player, false);
|
||||
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
|
||||
}
|
||||
|
||||
public SpigotUI(InventoryHolder holder, int rows, @Nonnull String title,JavaPlugin javaPlugin) {
|
||||
if (rows >= 7) rows = 6;
|
||||
this.inventory = Bukkit.createInventory(holder, rows * 9, title);
|
||||
this.title = title;
|
||||
this.rows = rows;
|
||||
if (holder != null) this.player = (Player)holder;
|
||||
this.freeSlots = new ArrayList<>();
|
||||
this.clickActions = new HashMap<>();
|
||||
openList.put(player, false);
|
||||
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
|
||||
}
|
||||
|
||||
public SpigotUI(InventoryHolder holder, @Nonnull InventoryType type, @Nonnull String title,JavaPlugin javaPlugin) {
|
||||
this.inventory = Bukkit.createInventory(holder, type, title);
|
||||
this.rows = -1;
|
||||
if (holder != null) this.player = (Player)holder;
|
||||
if (type == InventoryType.CHEST) this.rows = 3;
|
||||
this.freeSlots = new ArrayList<>();
|
||||
this.clickActions = new HashMap<>();
|
||||
openList.put(player, false);
|
||||
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
|
||||
}
|
||||
|
||||
public SpigotUI setFreeClickedSlots(int... slots) {
|
||||
for (int slot = 0; slot < slots.length; slot++) { this.freeSlots.add(slot); }
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI setSlot(@Nonnull ItemStack item, int slot) {
|
||||
this.inventory.setItem(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI setSlot(@Nonnull ItemStack item, int row, int slot) {
|
||||
this.inventory.setItem(getSlots(row).get(slot), item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI setSlot(@Nonnull ItemStack item, int slot, @Nonnull Consumer<InventoryClickEvent> clickAction) {
|
||||
this.inventory.setItem(slot, item);
|
||||
this.clickActions.put(slot, clickAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI setSlot(@Nonnull ItemStack item, int row, int slot, @Nonnull Consumer<InventoryClickEvent> clickAction) {
|
||||
int slots = getSlots(row).get(slot);
|
||||
this.inventory.setItem(slots, item);
|
||||
this.clickActions.put(slots, clickAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI setSlot(@Nonnull ItemStack item, int... slots) {
|
||||
for (int slot = 0; slot < slots.length; slot++) { this.inventory.setItem(slot, item); }
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI all(@Nonnull ItemStack item) {
|
||||
this.inventory.all(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI all(@Nonnull Material material) {
|
||||
this.inventory.all(material);
|
||||
return this;
|
||||
}
|
||||
public SpigotUI addItem(@Nonnull ItemStack... items) {
|
||||
this.inventory.addItem(items);
|
||||
return this;
|
||||
}
|
||||
public SpigotUI clear() {
|
||||
this.inventory.clear();
|
||||
return this;
|
||||
}
|
||||
public SpigotUI clear(int slot) {
|
||||
this.inventory.clear(slot);
|
||||
return this;
|
||||
}
|
||||
public SpigotUI clear(int... slots) {
|
||||
for (int slot : slots) { this.inventory.clear(slot); }
|
||||
return this;
|
||||
}
|
||||
public SpigotUI clear(@Nonnull List<Integer> slots) {
|
||||
slots.stream().forEach(slot -> this.inventory.clear(slot));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpigotUI placeHolder(@Nonnull ItemStack item, boolean replaceItem) {
|
||||
for (int i = 0; i < this.inventory.getSize(); i++) {
|
||||
if (this.inventory.getItem(i) == null && !replaceItem) setSlot(item, i);
|
||||
if (replaceItem) setSlot(item, i);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void openInventory() {
|
||||
this.player.openInventory(this.inventory);
|
||||
openList.put(player, true);
|
||||
}
|
||||
|
||||
public void updateInventory() {
|
||||
this.player.updateInventory();
|
||||
}
|
||||
|
||||
public void closeInventory() {
|
||||
openList.put(player, false);
|
||||
this.player.closeInventory();
|
||||
}
|
||||
|
||||
public void openInventory(@Nonnull Player player) {
|
||||
player.openInventory(this.inventory);
|
||||
openList.put(player, true);
|
||||
}
|
||||
|
||||
public void updateInventory(@Nonnull Player player) { player.updateInventory(); }
|
||||
public void closeInventory(@Nonnull Player player) {
|
||||
player.closeInventory();
|
||||
openList.put(player, false);
|
||||
}
|
||||
|
||||
public boolean containsAsFor(@Nonnull ItemStack item) {
|
||||
for (int slot = 0; slot < this.inventory.getSize(); slot++) { if (this.inventory.getItem(slot) == item) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getSlot(@Nonnull ItemStack item) {
|
||||
for (int slot = 0; slot < this.inventory.getSize(); slot++) { if (this.inventory.getItem(slot) == item) return slot; }
|
||||
return -1;
|
||||
}
|
||||
|
||||
public List<Integer> getSlots(int row) {
|
||||
if (row > getRows()) row = getRows();
|
||||
List<Integer> slots = new ArrayList<>();
|
||||
for (int slot = 9 * (row - 1); slot < row * 9; slot++) slots.add(slot);
|
||||
return slots;
|
||||
}
|
||||
|
||||
public SpigotUI setRunOnClose(Runnable callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean contains(@Nonnull ItemStack item, int slot) { return this.inventory.contains(item, slot); }
|
||||
public boolean contains(@Nonnull ItemStack item) { return this.inventory.contains(item); }
|
||||
public boolean contains(@Nonnull Material material, int slot) { return this.inventory.contains(material, slot); }
|
||||
public boolean contains(@Nonnull Material material) { return this.inventory.contains(material); }
|
||||
public boolean containsAtLeast(@Nonnull ItemStack item, int slot) { return this.inventory.containsAtLeast(item, slot); }
|
||||
public ItemStack getItem(int slot) { return this.inventory.getItem(slot); }
|
||||
public int getSize() { return this.inventory.getSize(); }
|
||||
public int getSlot() { return this.inventory.getSize() - 1; }
|
||||
public int getRows() { return this.rows; }
|
||||
public InventoryType getType() { return this.inventory.getType(); }
|
||||
public InventoryHolder getHolder() { return this.inventory.getHolder(); }
|
||||
public ItemStack[] getContents() { return this.inventory.getContents(); }
|
||||
public int getMaxStackSize() { return this.inventory.getMaxStackSize(); }
|
||||
public List<HumanEntity> getViewers() { return this.inventory.getViewers(); }
|
||||
public ItemStack[] getStorageContents() { return this.inventory.getStorageContents(); }
|
||||
public int firstEmpty() { return this.inventory.firstEmpty(); }
|
||||
public boolean isOpen() { return openList.get(this.player) != null && openList.get(this.player); }
|
||||
public boolean isOpen(@Nonnull Player player) { return openList.get(player) != null && openList.get(player); }
|
||||
|
||||
@EventHandler
|
||||
public void openInventory(InventoryOpenEvent openEvent) {
|
||||
Inventory openInventory = openEvent.getInventory();
|
||||
if (Boolean.TRUE.equals(openList.get(openEvent.getPlayer()))) return;
|
||||
if (openInventory.getType() != InventoryType.CHEST) return;
|
||||
if (!openInventory.getType().equals(this.inventory.getType())) return;
|
||||
openList.put(player, true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void closeInventory(InventoryCloseEvent closeEvent) {
|
||||
Inventory closeInventory = closeEvent.getInventory();
|
||||
if (Boolean.FALSE.equals(openList.get(closeEvent.getPlayer()))) return;
|
||||
if (closeInventory.getType() != InventoryType.CHEST) return;
|
||||
if (!closeInventory.getType().equals(this.inventory.getType())) return;
|
||||
openList.put(player, false);
|
||||
if (this.callback != null) this.callback.run();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void executeActions(InventoryClickEvent clickEvent) {
|
||||
Inventory clickedInventory = clickEvent.getClickedInventory();
|
||||
if (clickedInventory == null) return;
|
||||
if (clickedInventory.getType() != InventoryType.CHEST) return;
|
||||
if (Boolean.FALSE.equals(openList.get(clickEvent.getWhoClicked()))) return;
|
||||
if (!clickedInventory.getType().equals(this.inventory.getType())) return;
|
||||
if (clickedInventory.getHolder() != this.player) return;
|
||||
if (!clickEvent.getView().getTitle().equals(this.title)) return;
|
||||
if (!this.freeSlots.contains(clickEvent.getSlot())) clickEvent.setCancelled(true);
|
||||
if (this.clickActions.containsKey(clickEvent.getSlot())) this.clickActions.get(clickEvent.getSlot()).accept(clickEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.softwarerat.API.commands;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.softwarerat.API.builder.SpigotInventory;
|
||||
import com.softwarerat.API.builder.SpigotItem;
|
||||
import com.softwarerat.API.builder.SpigotUI;
|
||||
import com.softwarerat.GameAPI;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
//Default Navigator
|
||||
public class Navigator implements CommandExecutor {
|
||||
JavaPlugin javaPlugin;
|
||||
|
||||
public Navigator(JavaPlugin javaPlugin) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
Player player = Bukkit.getPlayer(commandSender.getName());
|
||||
SpigotInventory playerInventory = new SpigotInventory(player,javaPlugin);
|
||||
|
||||
|
||||
playerInventory.setSlot(new SpigotItem(Material.COMPASS).setName("Navigator").build(), 4, (click) -> openServerCreatorMenu(click.getPlayer()));
|
||||
player.sendMessage("give ITem");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void sendPlayer(Player player){
|
||||
if (player.hasPermission("group.Content")) {
|
||||
// player.sendMessage("hasperm");
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF("build-1");
|
||||
|
||||
|
||||
player.sendPluginMessage(javaPlugin, "BungeeCord", out.toByteArray());
|
||||
// player.sendMessage("sucess");
|
||||
}
|
||||
|
||||
}
|
||||
public void openServerCreatorMenu(Player player) {
|
||||
int rows = 6;
|
||||
SpigotUI gui = new SpigotUI(player, rows, "Server Auswählen",javaPlugin);
|
||||
gui.openInventory(player);
|
||||
gui.setSlot(new SpigotItem( Material.GRASS_BLOCK).setName("Bauserver").build(),10, (click) -> sendPlayer(player));
|
||||
// gui.setRunOnClose(() -> {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.softwarerat.API.data;
|
||||
|
||||
import com.softwarerat.API.gameState.GameState;
|
||||
import com.softwarerat.API.gameType.GameType;
|
||||
import com.softwarerat.API.location.PlayerSpawnLocation;
|
||||
import com.softwarerat.GameAPI;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.List;
|
||||
// Server related Data
|
||||
// made possible with Lombok
|
||||
@Getter
|
||||
@Setter
|
||||
public class GameData {
|
||||
List<PlayerSpawnLocation> spawnLocations;
|
||||
PlayerSpawnLocation defaultSpawnLocation;
|
||||
GameAPI gameapi;
|
||||
GameState currentGameState;
|
||||
Location mapLocation;
|
||||
String primaryKit;
|
||||
String secondaryKit;
|
||||
String helper;
|
||||
GameType gameType;
|
||||
List<Player> alivePlayers;
|
||||
List<Player> spectators;
|
||||
Scoreboard scoreboard;
|
||||
public GameData(GameAPI gameapi) {
|
||||
this.gameapi = gameapi;
|
||||
}
|
||||
|
||||
public String getGameHost(JavaPlugin javaPlugin){
|
||||
String sn = javaPlugin.getName();
|
||||
int indexOfUnderscore = sn.indexOf("_");
|
||||
int indexOfHyphen = sn.indexOf("-");
|
||||
if (indexOfUnderscore != -1 && indexOfHyphen != -1) {
|
||||
return sn.substring(indexOfUnderscore + 1, indexOfHyphen);
|
||||
}else return "zLavra";
|
||||
}
|
||||
|
||||
public void setPrimaryKit(String kitData){
|
||||
primaryKit = kitData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.softwarerat.API.gameState;
|
||||
|
||||
|
||||
public enum GameState {
|
||||
GAME_STATE_LOBBY,
|
||||
GAME_STATE_INGAME;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.softwarerat.API.gameState;
|
||||
|
||||
public interface IGameState {
|
||||
|
||||
public void Start();
|
||||
public void Stop();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.softwarerat.API.gameType;
|
||||
|
||||
public enum GameType {
|
||||
GAME_TYPE_MINIGAME,
|
||||
GAME_TYPE_ONE_VERSUS_ONE,
|
||||
GAME_TYPE_TYPELESS;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.softwarerat.API.listener;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
// Listener for checking if a Player is Building / Breaking any Blocks
|
||||
|
||||
public class BuildBreakListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEvent(BlockBreakEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.softwarerat.API.listener;
|
||||
|
||||
// Chat Listener
|
||||
public class ChatListener {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.softwarerat.API.listener;
|
||||
// Join Listener
|
||||
public class JoinListener {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.softwarerat.API.listener;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
// Inventory Click listener for Lobbies
|
||||
public class LobbyInventoryClickListener implements Listener {
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.softwarerat.API.listener;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.softwarerat.API.builder.SpigotInventory;
|
||||
import com.softwarerat.API.builder.SpigotItem;
|
||||
import com.softwarerat.API.builder.SpigotUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
// Lobby join magic including the navigator
|
||||
public class LobbyJoinListener implements Listener{
|
||||
JavaPlugin javaPlugin;
|
||||
|
||||
public LobbyJoinListener(JavaPlugin javaPlugin) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
event.getPlayer().getInventory().clear();
|
||||
SpigotInventory playerInventory = new SpigotInventory(player,javaPlugin);
|
||||
|
||||
|
||||
playerInventory.setSlot(new SpigotItem(Material.COMPASS).setName(ChatColor.BLUE.toString() + ChatColor.BOLD +"Navigator "+ ChatColor.RESET + ChatColor.GRAY+"(Click)" ).build(), 4, (click) -> openServerCreatorMenu(event.getPlayer()));
|
||||
player.sendMessage("give ITem");
|
||||
|
||||
}
|
||||
public void sendPlayer(Player player){
|
||||
if (player.hasPermission("group.Content")) {
|
||||
// player.sendMessage("hasperm");
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF("build-1");
|
||||
|
||||
|
||||
player.sendPluginMessage(javaPlugin, "BungeeCord", out.toByteArray());
|
||||
// player.sendMessage("sucess");
|
||||
}
|
||||
|
||||
}
|
||||
public void openServerCreatorMenu(Player player) {
|
||||
int rows = 6;
|
||||
SpigotUI gui = new SpigotUI(player, rows, "Server Auswählen",javaPlugin);
|
||||
gui.openInventory(player);
|
||||
gui.setSlot(new SpigotItem( Material.GRASS_BLOCK).setName("Bauserver").build(),10, inventoryClickEvent -> sendPlayer(player));
|
||||
// gui.setRunOnClose(() -> {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.softwarerat.API.listener;
|
||||
|
||||
public class QuitListener {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.softwarerat.API.location;
|
||||
|
||||
import com.softwarerat.API.data.GameData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
// Game related Location building
|
||||
@AllArgsConstructor
|
||||
public class LocationAPI {
|
||||
GameData gameData;
|
||||
|
||||
|
||||
public void setDefaultSpawnLocation(String world,int x,int y,int z){
|
||||
Location l = new Location(Bukkit.getWorld(world),x,y,z);
|
||||
PlayerSpawnLocation location = new PlayerSpawnLocation();
|
||||
location.setLocation(l);
|
||||
gameData.setDefaultSpawnLocation(location);
|
||||
}
|
||||
public void addSpawnLocationForPlayer(@NotNull Player p, String world, int x, int y, int z){
|
||||
|
||||
Location l = new Location(Bukkit.getWorld(world),x,y,z);
|
||||
PlayerSpawnLocation location = new PlayerSpawnLocation();
|
||||
location.setLocation(l);
|
||||
location.setAssociatedPlayer(p.getUniqueId());
|
||||
gameData.getSpawnLocations().add(location);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.softwarerat.API.location;
|
||||
|
||||
import com.softwarerat.API.gameType.GameType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
// Game related Player spawn Location
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlayerSpawnLocation {
|
||||
GameType gameType;
|
||||
Location location;
|
||||
UUID associatedPlayer;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.softwarerat.API.player;
|
||||
|
||||
import com.softwarerat.API.data.GameData;
|
||||
import com.softwarerat.GameAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
// Game related PlayerAPI for checking if a player is the GameHost
|
||||
|
||||
public class PlayerAPI {
|
||||
GameAPI gameAPI;
|
||||
GameData gameData;
|
||||
JavaPlugin javaPlugin = gameAPI.getJavaPlugin();
|
||||
public boolean isHosting(Player p){
|
||||
String s = gameData.getGameHost(javaPlugin);
|
||||
return p.getName().equals(s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.softwarerat.API.prefix;
|
||||
|
||||
import com.softwarerat.API.data.GameData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PrefixAPI {
|
||||
/* PrefixSystem of the whole Network
|
||||
* this will be the future way to add Tablist Prefixes, and will depend on GameData Settings like wich GameType and
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
Scoreboard scoreboard;
|
||||
|
||||
public PrefixAPI(Scoreboard scoreboard) {
|
||||
this.scoreboard = scoreboard;
|
||||
}
|
||||
|
||||
public void createPrefix(String prefixName, int priority, String prefix) {
|
||||
Team t = scoreboard.registerNewTeam(priority+prefixName);
|
||||
t.setPrefix(prefix);
|
||||
}
|
||||
public void addPlayerToTeam(String prefixName, int priority,Player player) {
|
||||
if (scoreboard.getTeam(priority+prefixName) != null){
|
||||
scoreboard.getTeam(priority+prefixName).addPlayer(player);
|
||||
}
|
||||
|
||||
}
|
||||
public boolean playerIsPermissible(Player player, String prefixName){
|
||||
return player.hasPermission("prefixAPI."+prefixName);
|
||||
}
|
||||
|
||||
public void addPermissiblePlayerToTeam(Player player, String prefixName,int priority){
|
||||
Team t = getTeam(prefixName,priority);
|
||||
if (this.playerIsPermissible(player,prefixName)) t.addPlayer(player);
|
||||
|
||||
}
|
||||
public void removePlayerFromTeam(String prefixName, int priority,Player player){
|
||||
if (scoreboard.getTeam(priority+prefixName) != null){
|
||||
scoreboard.getTeam(priority+prefixName).removePlayer(player);
|
||||
}
|
||||
}
|
||||
public Team getTeam(String prefixName, int priority){
|
||||
if (scoreboard.getTeam(priority+prefixName) != null){
|
||||
return scoreboard.getTeam(priority+prefixName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.softwarerat.API.scoreboard;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.*;
|
||||
|
||||
public class ScoreAPI {
|
||||
|
||||
public ScoreAPI(String minigameName, String mapName,Player player,String localName){
|
||||
ScoreboardManager manager = Bukkit.getScoreboardManager();
|
||||
Scoreboard board = manager.getNewScoreboard();
|
||||
Objective objective = board.registerNewObjective(localName, "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName(minigameName);
|
||||
player.setScoreboard(board);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.softwarerat.API.world;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
public class WorldAPI {
|
||||
public void unloadWorld(String WorldName){
|
||||
Bukkit.unloadWorld(WorldName,true);
|
||||
}
|
||||
public void loadWorld(String WorldName){
|
||||
new WorldCreator(WorldName).environment(World.Environment.NORMAL).createWorld();
|
||||
}
|
||||
|
||||
public void teleportOnlinePlayersToWorld(String worldName){
|
||||
Location L = new Location(Bukkit.getWorld(worldName),0,10,0);
|
||||
Bukkit.getOnlinePlayers().forEach(p ->{p.teleportAsync(L);});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.softwarerat;
|
||||
|
||||
|
||||
import com.softwarerat.API.commands.Navigator;
|
||||
import com.softwarerat.API.data.GameData;
|
||||
import com.softwarerat.API.location.LocationAPI;
|
||||
import com.softwarerat.API.prefix.PrefixAPI;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.softwarerat.API.world.WorldAPI;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GameAPI {
|
||||
|
||||
|
||||
JavaPlugin javaPlugin;
|
||||
GameData gameData;
|
||||
WorldAPI worldAPI;
|
||||
LocationAPI locationAPI;
|
||||
PrefixAPI prefixAPI;
|
||||
|
||||
public void enableAPI(JavaPlugin jPlugin){
|
||||
javaPlugin = jPlugin;
|
||||
worldAPI = new WorldAPI();
|
||||
System.out.println("Enabled GameAPI");
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
locationAPI = new LocationAPI(gameData);
|
||||
|
||||
//javaPlugin.getCommand("getNavigator").setExecutor(new Navigator(this));
|
||||
//if (gameData.getGameType().equals(GameType.GAME_TYPE_TYPELESS) || gameData.getCurrentGameState().equals(GameState.GAME_STATE_LOBBY)){
|
||||
// pluginManager.registerEvents(new BuildBreakListener(),jPlugin);
|
||||
// pluginManager.registerEvents(new LobbyJoinListener(),jPlugin);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user