Skip to content

Instantly share code, notes, and snippets.

@AL1L
Created April 30, 2017 01:16
Show Gist options
  • Save AL1L/7cdb7aba008fc2dc51fe69e8827a251c to your computer and use it in GitHub Desktop.
Save AL1L/7cdb7aba008fc2dc51fe69e8827a251c to your computer and use it in GitHub Desktop.
package me.diamonddev.craftoblo.menus;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import me.diamonddev.craftoblo.Craftoblo;
import me.diamonddev.craftoblo.abilitys.AbilityObject;
import me.diamonddev.craftoblo.camera.CameraManager;
import me.diamonddev.craftoblo.classes.ClassType;
import me.diamonddev.craftoblo.playerdata.DataManager;
import me.diamonddev.craftoblo.playerdata.PlayerData;
import me.diamonddev.craftoblo.scoreboard.SetupScorboard;
public class ClassSelection implements Listener {
// Classes
// - Barbarian // Iron Axe
// - Crusader // Shield
// - Demon Hunter // Bow
// - Monk // Stick
// - Witch Doctor // Skull
// - Wizard // Blaze Rod
// - Necromancer // Ender Pearl
public static void openClassSelector(Player player) {
// Create inventory
Inventory inv = Bukkit.createInventory(player, 45, ChatColor.RED + "" + ChatColor.UNDERLINE + "Class Selctor");
// Barbarian
ItemStack Barbarian = new ItemStack(Material.IRON_AXE);
ItemMeta BarbarianIM = Barbarian.getItemMeta();
BarbarianIM.setDisplayName(ChatColor.DARK_RED + "Barbarian");
BarbarianIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
Barbarian.setItemMeta(BarbarianIM);
inv.setItem(10, Barbarian);
// Crusader
ItemStack Crusader = new ItemStack(Material.SHIELD);
ItemMeta CrusaderIM = Barbarian.getItemMeta();
CrusaderIM.setDisplayName(ChatColor.BLUE + "Crusader");
CrusaderIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
Crusader.setItemMeta(CrusaderIM);
inv.setItem(12, Crusader);
// DemonHunter
ItemStack DemonHunter = new ItemStack(Material.BOW);
ItemMeta DemonHunterIM = Barbarian.getItemMeta();
DemonHunterIM.setDisplayName(ChatColor.GRAY + "Demon Hunter");
DemonHunterIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
DemonHunter.setItemMeta(DemonHunterIM);
inv.setItem(14, DemonHunter);
// Monk
ItemStack Monk = new ItemStack(Material.STICK);
ItemMeta MonkIM = Barbarian.getItemMeta();
MonkIM.setDisplayName(ChatColor.GOLD + "Monk");
MonkIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
Monk.setItemMeta(MonkIM);
inv.setItem(16, Monk);
// WitchDoctor
ItemStack WitchDoctor = new ItemStack(Material.SKULL_ITEM);
ItemMeta WitchDoctorIM = Barbarian.getItemMeta();
WitchDoctorIM.setDisplayName(ChatColor.GREEN + "Witch Doctor");
WitchDoctorIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
WitchDoctor.setItemMeta(WitchDoctorIM);
inv.setItem(29, WitchDoctor);
// Wizard
ItemStack Wizard = new ItemStack(Material.BLAZE_ROD);
ItemMeta WizardIM = Barbarian.getItemMeta();
WizardIM.setDisplayName(ChatColor.DARK_PURPLE + "Wizard");
WizardIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
Wizard.setItemMeta(WizardIM);
inv.setItem(31, Wizard);
// Necromancer
ItemStack Necromancer = new ItemStack(Material.EYE_OF_ENDER);
ItemMeta NecromancerIM = Barbarian.getItemMeta();
NecromancerIM.setDisplayName(ChatColor.YELLOW + "Necromancer");
NecromancerIM.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
Necromancer.setItemMeta(NecromancerIM);
inv.setItem(33, Necromancer);
player.openInventory(inv);
}
@EventHandler
public void onItemClick(InventoryClickEvent e) {
Inventory inv = e.getClickedInventory();
if (inv == null)
return;
if (inv.getName() == null)
return;
if (inv.getName().equalsIgnoreCase(ChatColor.RED + "" + ChatColor.UNDERLINE + "Class Selctor")) {
int clicked = e.getSlot();
final Player p = (Player) inv.getViewers().get(0);
if (clicked == 10) {
p.sendMessage(
ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD + "Barbarian");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Barbarian");
p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_PLACE, 1, 1);
} else if (clicked == 12) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD + "Crusader");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Crusader");
p.playSound(p.getLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 1, 1);
} else if (clicked == 14) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD
+ "Demon Hunter" + ChatColor.AQUA + ".");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Demon_Hunter");
new BukkitRunnable() {
int times = 3;
public void run() {
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_SHOOT, 1, 1);
--times;
if (times == 0)
this.cancel();
}
}.runTaskTimer(Craftoblo.gi(), 0, 3);
} else if (clicked == 16) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD + "Monk"
+ ChatColor.AQUA + ".");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Monk");
p.playSound(p.getLocation(), Sound.ENTITY_ELDER_GUARDIAN_CURSE, 1, 1);
} else if (clicked == 29) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD
+ "Witch Doctor" + ChatColor.AQUA + ".");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Witch_Doctor");
p.playSound(p.getLocation(), Sound.ENTITY_WITCH_AMBIENT, 1, 1);
} else if (clicked == 31) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD + "Wizard"
+ ChatColor.AQUA + ".");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Wizard");
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
} else if (clicked == 33) {
p.sendMessage(ChatColor.AQUA + "Your class was set to " + ChatColor.GOLD + ChatColor.BOLD
+ "Necromancer" + ChatColor.AQUA + ".");
DataManager.getPlayerData(p.getUniqueId()).setPlayerClass("Necromancer");
p.playSound(p.getLocation(), Sound.ENTITY_ENDERDRAGON_GROWL, 1, 1);
} else {
e.setCancelled(true);
return;
}
String playerClass = "None";
PlayerData data = DataManager.getPlayerData(p.getUniqueId());
playerClass = data.getPlayerClass();
if (!DataManager.getPlayerData(p.getUniqueId()).getData()
.contains(ClassType.valueOf(playerClass.toUpperCase()).name() + ".orb"))
DataManager.getPlayerData(p.getUniqueId()).setOrb(100, ClassType.valueOf(playerClass.toUpperCase()));
PlayerInventory pinv = p.getInventory();
pinv.clear();
AbilityObject[] abilitys = data.getActionBar(data.getPlayerClassType());
pinv.setHeldItemSlot(7);
for (int i = 0; i < abilitys.length; i++) {
pinv.setItem(i, abilitys[i].getItem(p));
}
p.closeInventory();
SetupScorboard.set(p);
CameraManager.getManager().detach(p);
CameraManager.getManager().attach(p,5,5,5);
e.setCancelled(true);
} else {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment