use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class CrazyManager method openCrate.
/**
* Opens a crate for a player.
* @param player The player that is having the crate opened for them.
* @param crate The crate that is being used.
* @param location The location that may be needed for some crate types.
* @param checkHand If it just checks the players hand or if it checks their inventory.
*/
public void openCrate(Player player, Crate crate, KeyType keyType, Location location, boolean virtualCrate, boolean checkHand) {
if (crate.getCrateType() != CrateType.MENU) {
if (!crate.canWinPrizes(player)) {
player.sendMessage(Messages.NO_PRIZES_FOUND.getMessage());
removePlayerFromOpeningList(player);
removePlayerKeyType(player);
return;
}
}
addPlayerToOpeningList(player, crate);
boolean broadcast = crate.getFile() != null && crate.getFile().getBoolean("Crate.OpeningBroadCast");
if (broadcast && crate.getCrateType() != CrateType.QUAD_CRATE) {
if (crate.getFile().contains("Crate.BroadCast")) {
if (!crate.getFile().getString("Crate.BroadCast").isEmpty()) {
getJavaPlugin().getServer().broadcastMessage(color(crate.getFile().getString("Crate.BroadCast").replaceAll("%Prefix%", Methods.getPrefix()).replaceAll("%prefix%", Methods.getPrefix()).replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
}
}
broadcast = false;
}
switch(crate.getCrateType()) {
case MENU:
GUIMenu.openGUI(player);
break;
case COSMIC:
Cosmic.openCosmic(player, crate, keyType, checkHand);
break;
case CSGO:
CSGO.openCSGO(player, crate, keyType, checkHand);
break;
case ROULETTE:
Roulette.openRoulette(player, crate, keyType, checkHand);
break;
case WHEEL:
Wheel.startWheel(player, crate, keyType, checkHand);
break;
case WONDER:
Wonder.startWonder(player, crate, keyType, checkHand);
break;
case WAR:
War.openWarCrate(player, crate, keyType, checkHand);
break;
case QUAD_CRATE:
Location last = player.getLocation();
last.setPitch(0F);
QuadCrateSession session = new QuadCrateSession(player, crate, keyType, location, last, checkHand);
broadcast = session.startCrate();
break;
case FIRE_CRACKER:
if (CrateControl.inUse.containsValue(location)) {
player.sendMessage(Messages.QUICK_CRATE_IN_USE.getMessage());
removePlayerFromOpeningList(player);
return;
} else {
if (virtualCrate) {
player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
removePlayerFromOpeningList(player);
return;
} else {
CrateControl.inUse.put(player, location);
FireCracker.startFireCracker(player, crate, keyType, location);
}
}
break;
case QUICK_CRATE:
if (CrateControl.inUse.containsValue(location)) {
player.sendMessage(Messages.QUICK_CRATE_IN_USE.getMessage());
removePlayerFromOpeningList(player);
return;
} else {
if (virtualCrate && location.equals(player.getLocation())) {
player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
removePlayerFromOpeningList(player);
return;
} else {
CrateControl.inUse.put(player, location);
QuickCrate.openCrate(player, location, crate, keyType);
}
}
break;
case CRATE_ON_THE_GO:
if (virtualCrate) {
player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
removePlayerFromOpeningList(player);
return;
} else {
if (takeKeys(1, player, crate, keyType, true)) {
Prize prize = crate.pickPrize(player);
givePrize(player, prize);
if (prize.useFireworks()) {
Methods.fireWork(player.getLocation().add(0, 1, 0));
}
removePlayerFromOpeningList(player);
} else {
Methods.failedToTakeKey(player, crate);
}
}
break;
}
if (broadcast) {
if (!crate.getFile().getString("Crate.BroadCast").isEmpty()) {
getJavaPlugin().getServer().broadcastMessage(color(crate.getFile().getString("Crate.BroadCast").replaceAll("%Prefix%", Methods.getPrefix()).replaceAll("%prefix%", Methods.getPrefix()).replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class CrateControl method onAdminMenuClick.
@EventHandler
public void onAdminMenuClick(InventoryClickEvent e) {
Inventory inv = e.getInventory();
Player player = (Player) e.getWhoClicked();
if (inv != null && e.getView().getTitle().equals(Methods.sanitizeColor("&4&lAdmin Keys"))) {
e.setCancelled(true);
if (!Methods.permCheck(player, "admin")) {
player.closeInventory();
return;
}
// Added the >= due to an error about a raw slot set at -999.
if (e.getRawSlot() < inv.getSize() && e.getRawSlot() >= 0) {
// Clicked in the admin menu.
ItemStack item = inv.getItem(e.getRawSlot());
if (cc.isKey(item)) {
Crate crate = cc.getCrateFromKey(item);
if (e.getAction() == InventoryAction.PICKUP_ALL) {
player.getInventory().addItem(crate.getKey());
} else if (e.getAction() == InventoryAction.PICKUP_HALF) {
cc.addKeys(1, player, crate, KeyType.VIRTUAL_KEY);
String name = null;
ItemStack key = crate.getKey();
if (key.hasItemMeta() && key.getItemMeta().hasDisplayName()) {
name = key.getItemMeta().getDisplayName();
}
player.sendMessage(Methods.getPrefix() + color("&a&l+1 " + (name != null ? name : crate.getName())));
}
}
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class GUIMenu method onInvClick.
@EventHandler
public void onInvClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
FileConfiguration config = Files.CONFIG.getFile();
if (inv != null) {
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU && crate.isCrateMenu(e.getView())) {
return;
}
}
if (e.getView().getTitle().equals(Methods.sanitizeColor(config.getString("Settings.InventoryName")))) {
e.setCancelled(true);
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
NBTItem nbtItem = new NBTItem(item);
if (nbtItem.hasNBTData() && nbtItem.hasKey("CrazyCrates-Crate")) {
Crate crate = cc.getCrateFromName(nbtItem.getString("CrazyCrates-Crate"));
if (crate != null) {
if (e.getAction() == InventoryAction.PICKUP_HALF) {
// Right-clicked the item
if (crate.isPreviewEnabled()) {
player.closeInventory();
Preview.setPlayerInMenu(player, true);
Preview.openNewPreview(player, crate);
} else {
player.sendMessage(Messages.PREVIEW_DISABLED.getMessage());
}
return;
}
if (cc.isInOpeningList(player)) {
player.sendMessage(Messages.CRATE_ALREADY_OPENED.getMessage());
return;
}
boolean hasKey = false;
KeyType keyType = KeyType.VIRTUAL_KEY;
if (cc.getVirtualKeys(player, crate) >= 1) {
hasKey = true;
} else {
if (Files.CONFIG.getFile().getBoolean("Settings.Virtual-Accepts-Physical-Keys") && cc.hasPhysicalKey(player, crate, false)) {
hasKey = true;
keyType = KeyType.PHYSICAL_KEY;
}
}
if (!hasKey) {
if (config.contains("Settings.Need-Key-Sound")) {
Sound sound = Sound.valueOf(config.getString("Settings.Need-Key-Sound"));
if (sound != null) {
player.playSound(player.getLocation(), sound, 1f, 1f);
}
}
player.sendMessage(Messages.NO_VIRTUAL_KEY.getMessage());
return;
}
for (String world : getDisabledWorlds()) {
if (world.equalsIgnoreCase(player.getWorld().getName())) {
player.sendMessage(Messages.WORLD_DISABLED.getMessage("%World%", player.getWorld().getName()));
return;
}
}
if (Methods.isInventoryFull(player)) {
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
return;
}
cc.openCrate(player, crate, keyType, player.getLocation(), true, false);
}
}
}
}
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class GUIMenu method openGUI.
public static void openGUI(Player player) {
int size = Files.CONFIG.getFile().getInt("Settings.InventorySize");
Inventory inv = CrazyManager.getJavaPlugin().getServer().createInventory(null, size, Methods.sanitizeColor(Files.CONFIG.getFile().getString("Settings.InventoryName")));
if (Files.CONFIG.getFile().contains("Settings.Filler.Toggle")) {
if (Files.CONFIG.getFile().getBoolean("Settings.Filler.Toggle")) {
String id = Files.CONFIG.getFile().getString("Settings.Filler.Item");
String name = Files.CONFIG.getFile().getString("Settings.Filler.Name");
List<String> lore = Files.CONFIG.getFile().getStringList("Settings.Filler.Lore");
ItemStack item = new ItemBuilder().setMaterial(id).setName(name).setLore(lore).build();
for (int i = 0; i < size; i++) {
inv.setItem(i, item.clone());
}
}
}
if (Files.CONFIG.getFile().contains("Settings.GUI-Customizer")) {
for (String custom : Files.CONFIG.getFile().getStringList("Settings.GUI-Customizer")) {
int slot = 0;
ItemBuilder item = new ItemBuilder();
String[] split = custom.split(", ");
for (String option : split) {
if (option.contains("Item:")) {
item.setMaterial(option.replace("Item:", ""));
}
if (option.contains("Name:")) {
option = option.replace("Name:", "");
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU) {
option = option.replaceAll("%" + crate.getName().toLowerCase() + "%", cc.getVirtualKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_physical%", cc.getPhysicalKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_total%", cc.getTotalKeys(player, crate) + "");
}
}
item.setName(option.replaceAll("%player%", player.getName()));
}
if (option.contains("Lore:")) {
option = option.replace("Lore:", "");
String[] d = option.split(",");
for (String l : d) {
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU) {
option = option.replaceAll("%" + crate.getName().toLowerCase() + "%", cc.getVirtualKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_physical%", cc.getPhysicalKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_total%", cc.getTotalKeys(player, crate) + "");
}
}
item.addLore(option.replaceAll("%player%", player.getName()));
}
}
if (option.contains("Glowing:")) {
item.setGlowing(Boolean.parseBoolean(option.replace("Glowing:", "")));
}
if (option.contains("Player:")) {
item.setPlayer(option.replaceAll("%player%", player.getName()));
}
if (option.contains("Slot:")) {
slot = Integer.parseInt(option.replace("Slot:", ""));
}
if (option.contains("Unbreakable-Item")) {
item.setUnbreakable(Boolean.parseBoolean(option.replace("Unbreakable-Item:", "")));
}
if (option.contains("Hide-Item-Flags")) {
item.hideItemFlags(Boolean.parseBoolean(option.replace("Hide-Item-Flags:", "")));
}
}
if (slot > size) {
continue;
}
slot--;
inv.setItem(slot, item.build());
}
}
for (Crate crate : cc.getCrates()) {
FileConfiguration file = crate.getFile();
if (file != null) {
if (file.getBoolean("Crate.InGUI")) {
String path = "Crate.";
int slot = file.getInt(path + "Slot");
if (slot > size) {
continue;
}
slot--;
inv.setItem(slot, new ItemBuilder().setMaterial(file.getString(path + "Item")).setName(file.getString(path + "Name")).setLore(file.getStringList(path + "Lore")).setCrateName(crate.getName()).setPlayer(file.getString(path + "Player")).setGlowing(file.getBoolean(path + "Glowing")).addLorePlaceholder("%Keys%", NumberFormat.getNumberInstance().format(cc.getVirtualKeys(player, crate))).addLorePlaceholder("%Keys_Physical%", NumberFormat.getNumberInstance().format(cc.getPhysicalKeys(player, crate))).addLorePlaceholder("%Keys_Total%", NumberFormat.getNumberInstance().format(cc.getTotalKeys(player, crate))).addLorePlaceholder("%Player%", player.getName()).build());
}
}
}
player.openInventory(inv);
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class Preview method onPlayerClick.
@EventHandler
public void onPlayerClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
if (e.getInventory() != null && playerCrate.get(player.getUniqueId()) != null) {
Crate crate = playerCrate.get(player.getUniqueId());
if (crate.isPreview(e.getView())) {
e.setCancelled(true);
if (e.getCurrentItem() != null) {
if (e.getRawSlot() == crate.getAbsoluteItemPosition(4)) {
// Clicked the menu button.
if (playerInMenu(player)) {
GUIMenu.openGUI(player);
}
} else if (e.getRawSlot() == crate.getAbsoluteItemPosition(5)) {
// Clicked the next button.
if (getPage(player) < crate.getMaxPage()) {
nextPage(player);
openPreview(player, crate);
}
} else if (e.getRawSlot() == crate.getAbsoluteItemPosition(3)) {
// Clicked the back button.
if (getPage(player) > 1 && getPage(player) <= crate.getMaxPage()) {
backPage(player);
openPreview(player, crate);
}
}
}
}
}
}
Aggregations