public void input(int slot, ClickType action) { ItemStack is = null; if (slot >= 0 && slot <= 8) { if (slot == 8) { this.sfx(Sound.CLICK); this.close(true); return; } is = this.inventory.getItem(slot); if (is != null) { String s = Main.getItemData(is, 0); if (!s.isEmpty()) { if (s.startsWith("#")) { try { int id = Integer.parseInt(s.substring(1)); this.sfx(Sound.CLICK); this.recipe.remove((Object) id); Main.giveReward(this.editing, id); } catch (NumberFormatException e) { } } } } } else if (slot >= 9 && slot <= 45) { if (slot >= 9 && slot <= 35) { is = this.editing.getInventory().getItem(slot); } else if (slot >= 36 && slot <= 45) { is = this.editing.getInventory().getItem(slot - 36); } if (is != null) { String s = Main.getItemData(is, 0); if (!s.isEmpty()) { if (s.startsWith("#")) { try { int id = Integer.parseInt(s.substring(1)); if (this.recipe.size() >= 4) { this.editing.sendMessage("Cannot fuse more than 4 cards."); this.sfx(Sound.FIRE_IGNITE); return; } this.recipe.add(id); this.sfx(Sound.CLICK); is = is.clone(); is.setAmount(1); this.editing.getInventory().removeItem(is); } catch (NumberFormatException e) { } } } } } this.updateInterface(); }
public void close(boolean fuse) { PluginVars.commu_mode.remove(this.editing); this.editing.closeInventory(); if (fuse) { if (!this.editing.isOnline()) { this.returnCards(); return; } else if (!this.receiver.isOnline()) { this.editing.sendMessage( "Player " + this.receiver.getDisplayName() + ChatColor.WHITE + " has gone offline"); this.returnCards(); return; } if (this.recipe.size() > 4 || this.recipe.size() < 3) { this.editing.sendMessage("You must use 3 or 4 cards in a commu fusion!"); this.returnCards(); return; } else { if (this.editing.getLocation().distance(this.receiver.getLocation()) > 6.0d) { this.editing.sendMessage("MISS!"); this.editing.sendMessage( "Player " + this.receiver.getDisplayName() + " has gone out of reach."); this.returnCards(); return; } this.editing .getWorld() .playSound(this.editing.getLocation(), Sound.FIREWORK_BLAST, 1.0f, 1.0f); this.receiver .getWorld() .playSound(this.receiver.getLocation(), Sound.FIREWORK_BLAST, 1.0f, 1.0f); try { int result = this.fuse(); Main.giveReward(this.receiver, result); this.receiver.sendMessage("Commu Fusion: " + Card.fromId(result).name); this.editing.sendMessage(ChatColor.GREEN + "SUCCESS!!!"); } catch (NoCardCreatedException e) { this.editing.sendMessage( ChatColor.RED + "FAILED!!!\n" + ChatColor.YELLOW + "\nNo card created."); } } } else { this.editing.sendMessage("Cancelled fusion"); this.returnCards(); } }
public void returnCards() { for (Integer card : this.recipe) { Main.giveReward(this.editing, card); } }