@SubscribeEvent public void onPlayerOpenContainer(PlayerOpenContainerEvent event) { if (event.entityPlayer instanceof EntityPlayerMP) { if (event.entityPlayer.openContainer instanceof net.minecraft.inventory.ContainerWorkbench && event.entityPlayer.openContainer.inventoryItemStacks.get(0) != null) { EntityPlayerMP playerMP = (EntityPlayerMP) event.entityPlayer; PlayerData player = PlayerStore.getInstance().getPlayer(playerMP.getUniqueID().toString()); Item item = (Item) ((ItemStack) event.entityPlayer.openContainer.inventoryItemStacks.get(0)).getItem(); ArrayList<ItemPerk> entitylist = PerkStore.getPerksForItem(item.getUnlocalizedName()); boolean requiresPerk = false; if (entitylist != null) { requiresPerk = true; } for (ItemSkill skill : SkillStore.getInstance().getItemSkill()) { ArrayList<ItemXP> temp = skill.getExp(); for (int i = 0; i < temp.size(); i++) { Item compareItem = ((ItemXP) temp.get(i)).getItem(); if (item.equals(compareItem)) { if (requiresPerk) { if (PlayerHandler.hasPerk(player, entitylist)) { } else { PlayerHandler.taskFail((EntityPlayer) playerMP); event.entityPlayer.closeScreen(); break; } } } } } } } }
@Override public void execute(ICommandSender player, String[] p_71515_2_) { EntityPlayerMP user = (EntityPlayerMP) player; PlayerData playerData = PlayerStore.getInstance().getPlayer(user.getPersistentID().toString()); String toReturn = "You have the current perks: "; for (Slug slug : playerData.getPerkList()) { toReturn += "," + slug; } toReturn += "| Your skill XP: "; for (Entry<String, Integer> skill : playerData.getSkillExp().entrySet()) { toReturn += skill.toString(); } player.addChatMessage(new ChatComponentText(toReturn)); }
@SubscribeEvent // Assumed that crafting wasn't blocked public void onItemCraftedEvent(ItemCraftedEvent event) { if (event.player instanceof EntityPlayerMP) { EntityPlayerMP playerMP = (EntityPlayerMP) event.player; PlayerData player = PlayerStore.getInstance().getPlayer(playerMP.getUniqueID().toString()); Item item = (Item) ((ItemStack) event.player.openContainer.inventoryItemStacks.get(0)).getItem(); ArrayList<ItemPerk> entitylist = PerkStore.getPerksForItem(item.getUnlocalizedName()); boolean requiresPerk = false; if (entitylist != null) { requiresPerk = true; } for (ItemSkill skill : SkillStore.getInstance().getItemSkill()) { ArrayList<ItemXP> temp = skill.getExp(); for (int i = 0; i < temp.size(); i++) { Item compareItem = ((ItemXP) temp.get(i)).getItem(); if (item.equals(compareItem)) { if (requiresPerk) { if (PlayerHandler.hasPerk(player, entitylist)) { // if (event.entity.isDead){ PlayerHandler.awardXP(player, skill.name, temp.get(i).getXp(), playerMP); // } } // else // { // PlayerHandler.taskFail((EntityPlayer) playerMP); // event.player.closeScreen(); // } } else { // if (event.entity.isDead){ PlayerHandler.awardXP(player, skill.name, temp.get(i).getXp(), playerMP); // } } } } } } }