From ce5e1e5a3bf1abc85db1e1dcaee88072f1262478 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 16 Feb 2011 14:27:59 -0800 Subject: [PATCH] All changes up to 0.5.17 --- mcMMO/Changelog.txt | 11 + mcMMO/com/gmail/nossr50/mcBlockListener.java | 111 ++ mcMMO/com/gmail/nossr50/mcConfig.java | 96 ++ mcMMO/com/gmail/nossr50/mcEntityListener.java | 376 +++++ mcMMO/com/gmail/nossr50/mcMMO.java | 79 + mcMMO/com/gmail/nossr50/mcPermissions.java | 164 +++ mcMMO/com/gmail/nossr50/mcPlayerListener.java | 377 +++++ mcMMO/com/gmail/nossr50/mcUsers.java | 840 +++++++++++ mcMMO/com/gmail/nossr50/mcm.java | 1285 +++++++++++++++++ mcMMO/plugin.yml | 4 +- 10 files changed, 3341 insertions(+), 2 deletions(-) create mode 100644 mcMMO/com/gmail/nossr50/mcBlockListener.java create mode 100644 mcMMO/com/gmail/nossr50/mcConfig.java create mode 100644 mcMMO/com/gmail/nossr50/mcEntityListener.java create mode 100644 mcMMO/com/gmail/nossr50/mcMMO.java create mode 100644 mcMMO/com/gmail/nossr50/mcPermissions.java create mode 100644 mcMMO/com/gmail/nossr50/mcPlayerListener.java create mode 100644 mcMMO/com/gmail/nossr50/mcUsers.java create mode 100644 mcMMO/com/gmail/nossr50/mcm.java diff --git a/mcMMO/Changelog.txt b/mcMMO/Changelog.txt index 0e66ae0cd..44ddf8377 100644 --- a/mcMMO/Changelog.txt +++ b/mcMMO/Changelog.txt @@ -1,5 +1,16 @@ Changelog: #Versions without changelogs probably had very small misc fixes, like tweaks to the source code# +Version 0.5.17 + + Changed namespaces to fit bukkits new standard + Adjusted excavation proc rates + Modified excavation loot tables + Added Party Invite System + +Version 0.5.16 + + Fixed unarmed not checking for permissions when hitting players + Version 0.5.15 Fixed stone swords not being recognized as swords Fixed /a not working if you were an op but did not have permissions diff --git a/mcMMO/com/gmail/nossr50/mcBlockListener.java b/mcMMO/com/gmail/nossr50/mcBlockListener.java new file mode 100644 index 000000000..5c3df34cf --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcBlockListener.java @@ -0,0 +1,111 @@ +package com.gmail.nossr50; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; + +public class mcBlockListener extends BlockListener { + private final mcMMO plugin; + + public mcBlockListener(final mcMMO plugin) { + this.plugin = plugin; + } + public void onBlockPlace(BlockPlaceEvent event) { + Block block = event.getBlock(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + String xyz = x+","+y+","+z; + mcConfig.getInstance().addBlockWatch(block); + mcConfig.getInstance().addCoordsWatch(xyz); + if(block.getTypeId() == 42) + event.getPlayer().sendMessage(ChatColor.DARK_RED+"You have placed an anvil, anvils can repair tools and armor."); + } + //put all Block related code here + public void onBlockDamage(BlockDamageEvent event) { + //STARTED(0), DIGGING(1), BROKEN(3), STOPPED(2); + Player player = event.getPlayer(); + Block block = event.getBlock(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + String xyz = x+","+y+","+z; + int type = block.getTypeId(); + Location loc = block.getLocation(); + int dmg = event.getDamageLevel().getLevel(); + /* + * MINING + */ + if(dmg == 3 && !mcConfig.getInstance().isBlockWatched(block) && !mcConfig.getInstance().isCoordsWatched(xyz)){ + if(mcPermissions.getInstance().mining(player)) + mcm.getInstance().miningBlockCheck(player, block); + /* + * WOOD CUTTING + */ + if(block.getTypeId() == 17 + && mcPermissions.getInstance().woodcutting(player)){ + mcUsers.getProfile(player).addwgather(1); + mcm.getInstance().woodCuttingProcCheck(player, block, loc); + } + mcm.getInstance().simulateSkillUp(player); + /* + * EXCAVATION + */ + if(mcPermissions.getInstance().excavation(player)) + mcm.getInstance().excavationProcCheck(block, player); + /* + * HERBALISM + */ + if(!(type == 39 || type == 40 || type == 37 || type == 38) + && mcPermissions.getInstance().herbalism(player)); + mcm.getInstance().herbalismProcCheck(block, player); //You place the blocks so we wont check if they are being watched + /* + * EXPLOIT COUNTERMEASURES + */ + mcConfig.getInstance().addCoordsWatch(xyz); + mcConfig.getInstance().addBlockWatch(block); + } + } + + + public void onBlockFlow(BlockFromToEvent event) { + //Code borrowed from WorldGuard by sk89q + World world = event.getBlock().getWorld(); + int radius = 1; + Block blockFrom = event.getBlock(); + Block blockTo = event.getToBlock(); + + boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9; + + int ox = blockTo.getX(); + int oy = blockTo.getY(); + int oz = blockTo.getZ(); + + if(blockTo.getTypeId() == 9 || blockTo.getTypeId() == 8){ + return; + } + + for (int cx = -radius; cx <= radius; cx++) { + for (int cy = -radius; cy <= radius; cy++) { + for (int cz = -radius; cz <= radius; cz++) { + Block dirt = world.getBlockAt(ox + cx, oy + cy, oz + cz); + //If block is dirt + if (isWater == true && + dirt.getTypeId() == 13) { + //Change + dirt.setTypeId(82); + return; + } + } + } + } + } +} \ No newline at end of file diff --git a/mcMMO/com/gmail/nossr50/mcConfig.java b/mcMMO/com/gmail/nossr50/mcConfig.java new file mode 100644 index 000000000..7e54955f3 --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcConfig.java @@ -0,0 +1,96 @@ +package com.gmail.nossr50; + +import java.util.ArrayList; +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class mcConfig { + private static volatile mcConfig instance; + String location = "mcmmo.properties"; + protected static final Logger log = Logger.getLogger("Minecraft"); + static ArrayList adminChatList = new ArrayList(); + static ArrayList coordsWatchList = new ArrayList(); + static ArrayList blockWatchList = new ArrayList(); + static ArrayList partyChatList = new ArrayList(); + public boolean isBlockWatched(Block block) {return blockWatchList.contains(block);} + public boolean isCoordsWatched(String xyz) {return coordsWatchList.contains(xyz);} + public void removeBlockWatch(Block block) {blockWatchList.remove(blockWatchList.indexOf(block));} + public void removeCoordsWatch(String xyz) {coordsWatchList.remove(coordsWatchList.indexOf(xyz));} + public void addBlockWatch(Block block) {blockWatchList.add(block);} + public void addCoordsWatch(String xyz) {coordsWatchList.add(xyz);} + public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);} + public boolean isPartyToggled(String playerName) {return partyChatList.contains(playerName);} + public void removePartyToggled(String playerName) {partyChatList.remove(partyChatList.indexOf(playerName));} + public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));} + public void addPartyToggled(String playerName) {partyChatList.add(playerName);} + public void addAdminToggled(String playerName) {adminChatList.add(playerName);} + public static mcConfig getInstance() { + if (instance == null) { + instance = new mcConfig(); + } + return instance; + } + public void toggleAdminChat(String playerName){ + if(isAdminToggled(playerName)){ + removeAdminToggled(playerName); + } else { + addAdminToggled(playerName); + } + } + public void togglePartyChat(String playerName){ + if(isPartyToggled(playerName)){ + removePartyToggled(playerName); + } else { + addPartyToggled(playerName); + } + } + public void woodProcChecks(Player player, Block block, Location loc){ + if(mcUsers.getProfile(player).getWoodCuttingint() > 1000){ + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 750){ + if((Math.random() * 10) > 2){ + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 300){ + if((Math.random() * 10) > 4){ + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 100){ + if((Math.random() * 10) > 6){ + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 10){ + if((Math.random() * 10) > 8){ + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + } +} \ No newline at end of file diff --git a/mcMMO/com/gmail/nossr50/mcEntityListener.java b/mcMMO/com/gmail/nossr50/mcEntityListener.java new file mode 100644 index 000000000..fd62c1a57 --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcEntityListener.java @@ -0,0 +1,376 @@ +package com.gmail.nossr50; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Creature; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Spider; +import org.bukkit.entity.Squid; +import org.bukkit.entity.Zombie; +import org.bukkit.event.entity.EntityDamageByBlockEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageByProjectileEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityListener; +import org.bukkit.inventory.ItemStack; + +public class mcEntityListener extends EntityListener { + private final mcMMO plugin; + + public mcEntityListener(final mcMMO plugin) { + this.plugin = plugin; + } + public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { + Block block = event.getDamager(); + Entity x = event.getEntity(); + if(x instanceof Player){ + Player player = (Player)x; + if(block != null && block.getTypeId() == 81){ + if(mcUsers.getProfile(player).isDead()) + return; + /* + if(player.getHealth() - event.getDamage() <= 0){ + mcUsers.getProfile(player).setDead(true); + for(Player bidoof : plugin.getServer().getOnlinePlayers()){ + bidoof.sendMessage(ChatColor.GRAY+player.getName()+" has been"+ChatColor.DARK_GREEN+" cactus tickled "+ChatColor.GRAY+"to death."); + } + } + */ + } + } + } + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity x = event.getEntity(); //Defender + Entity y = event.getDamager(); //Attacker + /* + * IF DEFENDER IS PLAYER + */ + if(x instanceof Player){ + Player defender = (Player)x; + /* + * PARRYING CHECK, CHECK TO SEE IF ITS A SUCCESSFUL PARRY OR NOT + */ + mcm.getInstance().parryCheck(defender, event, y); + /* + * PLAYER DEATH BY MONSTER MESSAGE CHECK, CHECKS TO SEE IF TO REPORT THE DEATH OR NOT + */ + mcm.getInstance().playerDeathByMonsterMessageCheck(y, defender, plugin); + /* + * CHECKS IF THE PLAYER DIES, IF SO DROP HIS SHIT BECAUSE OF THE DAMAGE MODIFIERS + * MIGHT BE A BIT BUGGY, IT SEEMS TO WORK RIGHT NOW AT LEAST... + */ + + } + /* + * IF ATTACKER IS PLAYER + */ + if(y instanceof Player){ + int type = ((Player) y).getItemInHand().getTypeId(); + Player attacker = (Player)y; + /* + * Player versus Monster checks, this handles all skill damage modifiers and any procs. + */ + mcm.getInstance().playerVersusMonsterChecks(event, attacker, x, type); + /* + * Player versus Squid checks, this handles all skill damage modifiers and any procs. + */ + mcm.getInstance().playerVersusSquidChecks(event, attacker, x, type); + /* + * Player versus Player checks, these checks make sure players are not in the same party, etc. They also check for any procs from skills and handle damage modifiers. + */ + mcm.getInstance().playerVersusPlayerChecks(x, attacker, event, plugin); + /* + * Player versus Animals checks, these checks handle any skill modifiers or procs + */ + mcm.getInstance().playerVersusAnimalsChecks(x, attacker, event, type); + } + } + public boolean isBow(ItemStack is){ + if (is.getTypeId() == 261){ + return true; + } else { + return false; + } + } + + public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { + Entity y = event.getDamager(); + Entity x = event.getEntity(); + /* + * Defender is player + */ + if(y instanceof Player){ + Player attacker = (Player)y; + if(mcPermissions.getInstance().archery(attacker)){ + /* + * Defender is Monster + */ + if(x instanceof Monster){ + Monster defender = (Monster)x; + if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 1)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 2)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 3)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 4)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 5)); + if(defender.getHealth() <= 0) + mcm.getInstance().simulateNaturalDrops(defender); + //XP + if(Math.random() * 10 > 7){ + mcUsers.getProfile(attacker).skillUpArchery(1); + attacker.sendMessage(ChatColor.YELLOW+"Archery skill increased by 1. Total ("+mcUsers.getProfile(attacker).getArchery()+")"); + } + } + /* + * Defender is Animals + */ + if(x instanceof Animals){ + Animals defender = (Animals)x; + if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 1)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 2)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 3)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 4)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 5)); + if(defender.getHealth() <= 0) + mcm.getInstance().simulateNaturalDrops(defender); + } + /* + * Defender is Squid + */ + if(x instanceof Squid){ + Squid defender = (Squid)x; + if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 1)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 2)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 3)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 4)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 5)); + if(defender.getHealth() <= 0) + mcm.getInstance().simulateNaturalDrops(defender); + } + /* + * Attacker is Player + */ + if(x instanceof Player){ + Player defender = (Player)x; + /* + * Stuff for the daze proc + */ + if(mcUsers.getProfile(attacker).inParty() && mcUsers.getProfile(defender).inParty()){ + if(mcm.getInstance().inSameParty(defender, attacker)){ + event.setCancelled(true); + return; + } + } + Location loc = defender.getLocation(); + if(Math.random() * 10 > 5){ + loc.setPitch(90); + } else { + loc.setPitch(-90); + } + /* + * Check the proc + */ + if(mcUsers.getProfile(attacker).getArcheryInt() >= 300 && mcUsers.getProfile(attacker).getArcheryInt() < 400){ + if(Math.random() * 10 > 7){ + defender.teleportTo(loc); + defender.sendMessage(ChatColor.DARK_RED+"Touched Fuzzy. Felt Dizzy."); + attacker.sendMessage("Target was "+ChatColor.DARK_RED+"Dazed"); + } + } + if(mcUsers.getProfile(attacker).getArcheryInt() >= 600){ + if(Math.random() * 10 > 4){ + defender.teleportTo(loc); + defender.sendMessage(ChatColor.DARK_RED+"Touched Fuzzy. Felt Dizzy."); + attacker.sendMessage("Target was "+ChatColor.DARK_RED+"Dazed"); + } + } + if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 1)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 2)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 3)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 4)); + if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000) + defender.setHealth(mcm.getInstance().calculateDamage(defender, 5)); + if(defender.getHealth() >= 0){ + if(mcUsers.getProfile(defender).isDead()) + return; + if(defender.getHealth() <= 0){ + mcUsers.getProfile(defender).setDead(true); + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName() + " with an arrow."); + } + } + } + + if(mcUsers.getProfile(defender).isDead()) + return; + if(defender.getHealth() - event.getDamage() <= 0){ + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName() + " with the bow and arrow."); + mcUsers.getProfile(defender).setDead(true); + } + } + } + } + } + } + public void onEntityDamage(EntityDamageEvent event) { + Entity x = event.getEntity(); + if(x instanceof Player){ + Player player = (Player)x; + DamageCause type = event.getCause(); + Location loc = player.getLocation(); + int xx = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + if(type == DamageCause.FALL){ + if(mcUsers.getProfile(player).getAcrobaticsInt() >= 50 + && mcUsers.getProfile(player).getAcrobaticsInt() < 250 + && mcPermissions.getInstance().acrobatics(player)){ + if(Math.random() * 10 > 8){ + event.setCancelled(true); + player.sendMessage("**ROLLED**"); + return; + } + } + if(mcUsers.getProfile(player).getAcrobaticsInt() >= 250 + && mcUsers.getProfile(player).getAcrobaticsInt() < 450 + && mcPermissions.getInstance().acrobatics(player)){ + if(Math.random() * 10 > 6){ + event.setCancelled(true); + player.sendMessage("**ROLLED**"); + return; + } + } + if(mcUsers.getProfile(player).getAcrobaticsInt() >= 450 + && mcUsers.getProfile(player).getAcrobaticsInt() < 750 + && mcPermissions.getInstance().acrobatics(player)){ + if(Math.random() * 10 > 4){ + event.setCancelled(true); + player.sendMessage("**ROLLED**"); + return; + } + } + if(mcUsers.getProfile(player).getAcrobaticsInt() >= 750 + && mcUsers.getProfile(player).getAcrobaticsInt() < 950 + && mcPermissions.getInstance().acrobatics(player)){ + if(Math.random() * 10 > 2){ + event.setCancelled(true); + player.sendMessage("**BARREL ROLLED**"); + return; + } + } + if(mcUsers.getProfile(player).getAcrobaticsInt() >= 950 + && mcPermissions.getInstance().acrobatics(player)){ + event.setCancelled(true); + player.sendMessage("**ROLLED... LIKE A BOSS**"); + return; + } + if(player.getHealth() - event.getDamage() <= 0) + return; + if(!mcConfig.getInstance().isBlockWatched(loc.getWorld().getBlockAt(xx, y, z)) + && mcPermissions.getInstance().acrobatics(player)){ + if(event.getDamage() >= 2 && event.getDamage() < 6){ + mcUsers.getProfile(player).skillUpAcrobatics(1); + player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 1. Total ("+mcUsers.getProfile(player).getAcrobatics()+")"); + } + if(event.getDamage() >= 6 && event.getDamage() < 19){ + mcUsers.getProfile(player).skillUpAcrobatics(2); + player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 2. Total ("+mcUsers.getProfile(player).getAcrobatics()+")"); + } + if(event.getDamage() >= 19){ + mcUsers.getProfile(player).skillUpAcrobatics(3); + player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 3. Total ("+mcUsers.getProfile(player).getAcrobatics()+")"); + } + } + mcConfig.getInstance().addBlockWatch(loc.getWorld().getBlockAt(xx, y, z)); + if(player.getHealth() - event.getDamage() <= 0){ + if(mcUsers.getProfile(player).isDead()) + return; + mcUsers.getProfile(player).setDead(true); + for(Player bidoof : plugin.getServer().getOnlinePlayers()){ + bidoof.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.DARK_RED+"fallen "+ChatColor.GRAY+"to death."); + } + } + } + if(type == DamageCause.DROWNING){ + if(mcUsers.getProfile(player).isDead()) + return; + if(player.getHealth() - event.getDamage() <= 0){ + mcUsers.getProfile(player).setDead(true); + for(Player slipslap : plugin.getServer().getOnlinePlayers()){ + slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.AQUA+"drowned."); + } + } + } + /* + if(type == DamageCause.FIRE || type == DamageCause.FIRE_TICK){ + if(mcUsers.getProfile(player).isDead()) + return; + if(player.getHealth() - event.getDamage() <= 0){ + mcUsers.getProfile(player).setDead(true); + for(Player slipslap : plugin.getServer().getOnlinePlayers()){ + slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.RED+"burned "+ChatColor.GRAY+"to death."); + } + } + } + */ + if(type == DamageCause.LAVA){ + if(mcUsers.getProfile(player).isDead()) + return; + if(player.getHealth() - event.getDamage() <= 0){ + mcUsers.getProfile(player).setDead(true); + for(Player slipslap : plugin.getServer().getOnlinePlayers()){ + slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.RED+"melted "+ChatColor.GRAY+"."); + } + } + } + } + } + public void onEntityDeath(EntityDeathEvent event) { + Entity x = event.getEntity(); + if(x instanceof Player){ + Player player = (Player)x; + if(mcUsers.getProfile(player).isDead()){ + mcUsers.getProfile(player).setDead(false); + return; + } + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY+player.getName()+" has died."); + } + } + } + public boolean isPlayer(Entity entity){ + if (entity instanceof Player) { + return true; + } else{ + return false; + } + } +} diff --git a/mcMMO/com/gmail/nossr50/mcMMO.java b/mcMMO/com/gmail/nossr50/mcMMO.java new file mode 100644 index 000000000..1d6a0751c --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcMMO.java @@ -0,0 +1,79 @@ +package com.gmail.nossr50; +import com.nijikokun.bukkit.Permissions.Permissions; +import com.nijiko.Messaging; +import com.nijiko.permissions.PermissionHandler; +import com.nijiko.permissions.Control; +import com.nijikokun.bukkit.Permissions.Permissions; +import org.bukkit.plugin.Plugin; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.event.player.*; +import org.bukkit.Server; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.entity.Player; + + +public class mcMMO extends JavaPlugin { + public static final Logger log = Logger.getLogger("Minecraft"); + private final mcPlayerListener playerListener = new mcPlayerListener(this); + private final mcBlockListener blockListener = new mcBlockListener(this); + private final mcEntityListener entityListener = new mcEntityListener(this); + private final HashMap debugees = new HashMap(); + private final String name = "mcMMO"; + public static PermissionHandler PermissionsHandler = null; + private Permissions permissions; + + public mcMMO(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { + super(pluginLoader, instance, desc, folder, plugin, cLoader); + } + + public void onEnable() { + mcUsers.getInstance().loadUsers(); + PluginManager pm = getServer().getPluginManager(); + pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Monitor, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_BLOCK, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); + //Displays a message when plugin is loaded + PluginDescriptionFile pdfFile = this.getDescription(); + mcPermissions.initialize(getServer()); + System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); + } + public void setupPermissions() { + Plugin test = this.getServer().getPluginManager().getPlugin("Permissions"); + if(this.PermissionsHandler == null) { + if(test != null) { + this.PermissionsHandler = ((Permissions)test).getHandler(); + } else { + log.info(Messaging.bracketize(name) + " Permission system not enabled. Disabling plugin."); + this.getServer().getPluginManager().disablePlugin(this); + } + } + } + public Permissions getPermissions() { + return permissions; + } + public void onDisable() { + System.out.println("mcMMO disabled."); + } +} diff --git a/mcMMO/com/gmail/nossr50/mcPermissions.java b/mcMMO/com/gmail/nossr50/mcPermissions.java new file mode 100644 index 000000000..bc90368cc --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcPermissions.java @@ -0,0 +1,164 @@ +package com.gmail.nossr50; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import com.nijikokun.bukkit.Permissions.Permissions; + +public class mcPermissions { + //Thanks to myWarp source code for helping me figure this shit out! + private static Permissions permissionsPlugin; + private static boolean permissionsEnabled = false; + private static volatile mcPermissions instance; + + public static void initialize(Server server) { + Plugin test = server.getPluginManager().getPlugin("Permissions"); + if (test != null) { + Logger log = Logger.getLogger("Minecraft"); + permissionsPlugin = ((Permissions) test); + permissionsEnabled = true; + log.log(Level.INFO, "[mcMMO] Permissions enabled."); + } else { + Logger log = Logger.getLogger("Minecraft"); + log.log(Level.SEVERE, "[mcMMO] Permissions isn't loaded, there are no restrictions."); + } + } + private boolean permission(Player player, String string) { + return permissionsPlugin.Security.permission(player, string); + } + public boolean mmoedit(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.tools.mmoedit"); + } else { + return true; + } + } + public boolean motd(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.motd"); + } else { + return true; + } + } + public boolean mySpawn(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.commands.myspawn"); + } else { + return true; + } + } + public boolean setMySpawn(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.commands.setmyspawn"); + } else { + return true; + } + } + public boolean partyChat(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.chat.partychat"); + } else { + return true; + } + } + public boolean partyTeleport(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.commands.ptp"); + } else { + return true; + } + } + public boolean whois(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.commands.whois"); + } else { + return true; + } + } + public boolean party(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.commands.party"); + } else { + return true; + } + } + public boolean adminChat(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.chat.adminchat"); + } else { + return true; + } + } + public static mcPermissions getInstance() { + if (instance == null) { + instance = new mcPermissions(); + } + return instance; + } + public boolean mining(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.mining"); + } else { + return true; + } + } + public boolean woodcutting(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.woodcutting"); + } else { + return true; + } + } + public boolean repair(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.repair"); + } else { + return true; + } + } + public boolean unarmed(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.unarmed"); + } else { + return true; + } + } + public boolean archery(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.archery"); + } else { + return true; + } + } + public boolean herbalism(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.herbalism"); + } else { + return true; + } + } + public boolean excavation(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.excavation"); + } else { + return true; + } + } + public boolean swords(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.swords"); + } else { + return true; + } + } + public boolean acrobatics(Player player) { + if (permissionsEnabled) { + return permission(player, "mcmmo.skills.acrobatics"); + } else { + return true; + } + } +} diff --git a/mcMMO/com/gmail/nossr50/mcPlayerListener.java b/mcMMO/com/gmail/nossr50/mcPlayerListener.java new file mode 100644 index 000000000..c554db9f9 --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcPlayerListener.java @@ -0,0 +1,377 @@ +package com.gmail.nossr50; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.event.player.PlayerItemEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerListener; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; + +import com.nijikokun.bukkit.Permissions.Permissions; + +public class mcPlayerListener extends PlayerListener { + protected static final Logger log = Logger.getLogger("Minecraft"); + public Location spawn = null; + private mcMMO plugin; + + public mcPlayerListener(mcMMO instance) { + plugin = instance; + } + public void onPlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + if(mcPermissions.getInstance().mySpawn(player)){ + if(mcUsers.getProfile(player).getMySpawn(player) != null) + event.setRespawnLocation(mcUsers.getProfile(player).getMySpawn(player)); + } + } + public Player[] getPlayersOnline() { + return plugin.getServer().getOnlinePlayers(); + } + public boolean isPlayer(String playerName){ + for(Player herp : getPlayersOnline()){ + if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){ + return true; + } + } + return false; + } + public Player getPlayer(String playerName){ + for(Player herp : getPlayersOnline()){ + if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){ + return herp; + } + } + return null; + } + public int partyCount(Player player){ + int x = 0; + for(Player hurrdurr: getPlayersOnline()){ + if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(hurrdurr).getParty())) + x++; + } + return x; + } + public void informPartyMembers(Player player){ + int x = 0; + for(Player p : getPlayersOnline()){ + if(mcm.getInstance().inSameParty(player, p) && !p.getName().equals(player.getName())){ + p.sendMessage(player.getName() + ChatColor.GREEN + " has joined your party"); + x++; + } + } + } + public void informPartyMembersQuit(Player player){ + int x = 0; + for(Player p : getPlayersOnline()){ + if(mcm.getInstance().inSameParty(player, p) && !p.getName().equals(player.getName())){ + p.sendMessage(player.getName() + ChatColor.GREEN + " has left your party"); + x++; + } + } + } + public void onPlayerJoin(PlayerEvent event) { + Player player = event.getPlayer(); + mcUsers.addUser(player); + if(mcPermissions.getInstance().motd(player)){ + player.sendMessage(ChatColor.BLUE + "This server is running mcMMO "+plugin.getDescription().getVersion()+" type "+ChatColor.YELLOW+"/mcmmo "+ChatColor.BLUE+ "for help."); + } + } + //Check if string is a player + + public void onPlayerItem(PlayerItemEvent event) { + Block block = event.getBlockClicked(); + Player player = event.getPlayer(); + ItemStack is = player.getItemInHand(); + if(mcPermissions.getInstance().herbalism(player)){ + //BREADCHECK, CHECKS HERBALISM SKILL FOR BREAD HP MODIFIERS + mcm.getInstance().breadCheck(player, is); + //STEW, CHECKS HERBALISM SKILL FOR BREAD HP MODIFIERS + mcm.getInstance().stewCheck(player, is); + } + if(mcPermissions.getInstance().repair(player)){ + //REPAIRCHECK, CHECKS TO MAKE SURE PLAYER IS RIGHT CLICKING AN ANVIL, PLAYER HAS ENOUGH RESOURCES, AND THE ITEM IS NOT AT FULL DURABILITY. + mcm.getInstance().repairCheck(player, is, block); + } + } + + public void onPlayerCommand(PlayerChatEvent event) { + Player player = event.getPlayer(); + String[] split = event.getMessage().split(" "); + String playerName = player.getName(); + //Check if the command is an mcMMO related help command + mcm.getInstance().mcmmoHelpCheck(split, player, event); + if(mcPermissions.getInstance().mmoedit(player) && split[0].equalsIgnoreCase("/mmoedit")){ + if(split.length < 3){ + player.sendMessage(ChatColor.RED+"Usage is /mmoedit playername skillname newvalue"); + return; + } + if(split.length == 4){ + if(isPlayer(split[1]) && mcm.getInstance().isInt(split[3]) && mcm.getInstance().isSkill(split[2])){ + int newvalue = Integer.valueOf(split[3]); + mcUsers.getProfile(getPlayer(split[1])).modifyskill(newvalue, split[2]); + player.sendMessage(ChatColor.RED+split[2]+" has been modified."); + } + } + else if(split.length == 3){ + if(mcm.getInstance().isInt(split[2]) && mcm.getInstance().isSkill(split[1])){ + int newvalue = Integer.valueOf(split[2]); + mcUsers.getProfile(player).modifyskill(newvalue, split[1]); + player.sendMessage(ChatColor.RED+split[1]+" has been modified."); + } + } else { + player.sendMessage(ChatColor.RED+"Usage is /mmoedit playername skillname newvalue"); + } + } + if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){ + event.setCancelled(true); + if(!mcPermissions.getInstance().partyTeleport(player)){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + if(split.length < 2){ + player.sendMessage(ChatColor.RED+"Usage is /ptp "); + return; + } + if(isPlayer(split[1])){ + Player target = getPlayer(split[1]); + if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(target).getParty())){ + player.teleportTo(target); + player.sendMessage(ChatColor.GREEN+"You have teleported to "+target.getName()); + target.sendMessage(ChatColor.GREEN+player.getName() + " has teleported to you."); + } + } + } + if((player.isOp() || mcPermissions.getInstance().whois(player)) && split[0].equalsIgnoreCase("/whois")){ + event.setCancelled(true); + if(split.length < 2){ + player.sendMessage(ChatColor.RED + "Proper usage is /whois "); + return; + } + //if split[1] is a player + if(isPlayer(split[1])){ + Player target = getPlayer(split[1]); + double x,y,z; + x = target.getLocation().getX(); + y = target.getLocation().getY(); + z = target.getLocation().getZ(); + player.sendMessage(ChatColor.GREEN + "~~WHOIS RESULTS~~"); + player.sendMessage(target.getName()); + if(mcUsers.getProfile(target).inParty()) + player.sendMessage("Party: "+mcUsers.getProfile(target).getParty()); + player.sendMessage("Health: "+target.getHealth()+ChatColor.GRAY+" (20 is full health)"); + player.sendMessage("OP: " + target.isOp()); + player.sendMessage(ChatColor.GREEN+"~~mcMMO stats~~"); + player.sendMessage("Mining Skill: "+mcUsers.getProfile(target).getMining()); + player.sendMessage("Repair Skill: "+mcUsers.getProfile(target).getRepair()); + player.sendMessage("Woodcutting Skill: "+mcUsers.getProfile(target).getWoodCutting()); + player.sendMessage("Unarmed Skill: "+mcUsers.getProfile(target).getUnarmed()); + player.sendMessage("Herbalism Skill: "+mcUsers.getProfile(target).getHerbalism()); + player.sendMessage("Excavation Skill: "+mcUsers.getProfile(target).getExcavation()); + player.sendMessage("Archery Skill: "+mcUsers.getProfile(target).getArchery()); + player.sendMessage("Swords Skill: "+mcUsers.getProfile(target).getSwords()); + //player.sendMessage("Axes Skill: "+mcUsers.getProfile(target).getAxes()); + player.sendMessage("Acrobatics Skill: "+mcUsers.getProfile(target).getAcrobatics()); + player.sendMessage(ChatColor.GREEN+"~~COORDINATES~~"); + player.sendMessage("X: "+x); + player.sendMessage("Y: "+y); + player.sendMessage("Z: "+z); + } + } + if(split[0].equalsIgnoreCase("/setmyspawn")){ + if(!mcPermissions.getInstance().setMySpawn(player)){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + event.setCancelled(true); + double x = player.getLocation().getX(); + double y = player.getLocation().getY(); + double z = player.getLocation().getZ(); + mcUsers.getProfile(player).setMySpawn(x, y, z); + player.sendMessage(ChatColor.DARK_AQUA + "Myspawn has been set to your current location."); + } + if(split[0].equalsIgnoreCase("/stats")){ + event.setCancelled(true); + player.sendMessage(ChatColor.DARK_RED + "mcMMO stats"); + player.sendMessage(ChatColor.YELLOW + "Mining Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getMining()); + player.sendMessage(ChatColor.YELLOW + "Repair Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getRepair()); + player.sendMessage(ChatColor.YELLOW + "Woodcutting Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getWoodCutting()); + player.sendMessage(ChatColor.YELLOW + "Unarmed Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getUnarmed()); + player.sendMessage(ChatColor.YELLOW + "Herbalism Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getHerbalism()); + player.sendMessage(ChatColor.YELLOW + "Excavation Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getExcavation()); + player.sendMessage(ChatColor.YELLOW + "Archery Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getArchery()); + player.sendMessage(ChatColor.YELLOW + "Swords Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getSwords()); + //player.sendMessage(ChatColor.YELLOW+ "Axes Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getAxes()); + player.sendMessage(ChatColor.YELLOW + "Acrobatics Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getAcrobatics()); + player.sendMessage(ChatColor.DARK_RED+"TOTAL SKILL: "+ChatColor.GREEN+ + (mcUsers.getProfile(player).getAcrobaticsInt()+ + mcUsers.getProfile(player).getArcheryInt()+ + mcUsers.getProfile(player).getAxesInt()+ + mcUsers.getProfile(player).getExcavationInt()+ + mcUsers.getProfile(player).getHerbalismInt()+ + mcUsers.getProfile(player).getMiningInt()+ + mcUsers.getProfile(player).getRepairInt()+ + mcUsers.getProfile(player).getSwordsInt()+ + mcUsers.getProfile(player).getUnarmedInt()+ + mcUsers.getProfile(player).getWoodCuttingint()) + ); + } + //Invite Command + if(mcPermissions.getInstance().party(player) && split[0].equalsIgnoreCase("/invite")){ + if(!mcUsers.getProfile(player).inParty()){ + player.sendMessage(ChatColor.RED+"You are not in a party."); + return; + } + if(split.length < 2){ + player.sendMessage(ChatColor.RED+"Usage is /invite = 2 && isPlayer(split[1])){ + Player target = getPlayer(split[1]); + mcUsers.getProfile(target).modifyInvite(mcUsers.getProfile(player).getParty()); + player.sendMessage(ChatColor.GREEN+"Invite sent successfully"); + target.sendMessage(ChatColor.RED+"ALERT: "+ChatColor.GREEN+"You have received a party invite for "+mcUsers.getProfile(target).getInvite()); + target.sendMessage(ChatColor.YELLOW+"Type "+ChatColor.GREEN+"/accept"+ChatColor.YELLOW+" to accept the invite"); + } + } + //Accept invite + if(mcPermissions.getInstance().party(player) && split[0].equalsIgnoreCase("/accept")){ + if(mcUsers.getProfile(player).hasPartyInvite()){ + if(mcUsers.getProfile(player).inParty()){ + informPartyMembersQuit(player); + } + mcUsers.getProfile(player).acceptInvite(); + informPartyMembers(player); + player.sendMessage(ChatColor.GREEN+"Invite accepted. You have joined party ("+mcUsers.getProfile(player).getParty()+")"); + } else { + player.sendMessage(ChatColor.RED+"You have no invites at this time"); + } + } + //Party command + if(split[0].equalsIgnoreCase("/party")){ + if(!mcPermissions.getInstance().party(player)){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + event.setCancelled(true); + if(split.length == 1 && !mcUsers.getProfile(player).inParty()){ + player.sendMessage("Proper usage is /party or 'q' to quit"); + return; + } + if(split.length == 1 && mcUsers.getProfile(player).inParty()){ + String tempList = ""; + int x = 0; + for(Player p : plugin.getServer().getOnlinePlayers()) + { + if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(p).getParty())){ + if(p != null && x+1 >= partyCount(player)){ + tempList+= p.getName(); + x++; + } + if(p != null && x < partyCount(player)){ + tempList+= p.getName() +", "; + x++; + } + } + } + player.sendMessage(ChatColor.GREEN+"You are in party \""+mcUsers.getProfile(player).getParty()+"\""); + player.sendMessage(ChatColor.GREEN + "Party Members ("+ChatColor.WHITE+tempList+ChatColor.GREEN+")"); + } + if(split.length > 1 && split[1].equals("q") && mcUsers.getProfile(player).inParty()){ + informPartyMembersQuit(player); + mcUsers.getProfile(player).removeParty(); + player.sendMessage(ChatColor.RED + "You have left that party"); + return; + } + if(split.length >= 2){ + mcUsers.getProfile(player).setParty(split[1]); + player.sendMessage("Joined Party: " + split[1]); + informPartyMembers(player); + } + } + if(split[0].equalsIgnoreCase("/p")){ + if(!mcPermissions.getInstance().party(player)){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + event.setCancelled(true); + if(mcConfig.getInstance().isAdminToggled(player.getName())) + mcConfig.getInstance().toggleAdminChat(playerName); + mcConfig.getInstance().togglePartyChat(playerName); + if(mcConfig.getInstance().isPartyToggled(playerName)){ + player.sendMessage(ChatColor.GREEN + "Party Chat Toggled On"); + } else { + player.sendMessage(ChatColor.GREEN + "Party Chat Toggled " + ChatColor.RED + "Off"); + } + } + if(split[0].equalsIgnoreCase("/a") && (player.isOp() || mcPermissions.getInstance().adminChat(player))){ + if(!mcPermissions.getInstance().adminChat(player) && !player.isOp()){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + event.setCancelled(true); + if(mcConfig.getInstance().isPartyToggled(player.getName())) + mcConfig.getInstance().togglePartyChat(playerName); + mcConfig.getInstance().toggleAdminChat(playerName); + if(mcConfig.getInstance().isAdminToggled(playerName)){ + player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.GREEN + "On"); + } else { + player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.RED + "Off"); + } + } + if(split[0].equalsIgnoreCase("/myspawn")){ + if(!mcPermissions.getInstance().mySpawn(player)){ + player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions."); + return; + } + event.setCancelled(true); + if(mcUsers.getProfile(player).getMySpawn(player) != null){ + player.getInventory().clear(); + player.setHealth(20); + player.teleportTo(mcUsers.getProfile(player).getMySpawn(player)); + player.sendMessage("Inventory cleared & health restored"); + }else{ + player.sendMessage(ChatColor.RED+"Configure your myspawn first with /setmyspawn"); + } + } + } + public void onItemHeldChange(PlayerItemHeldEvent event) { + Player player = event.getPlayer(); + } + public void onPlayerChat(PlayerChatEvent event) { + Player player = event.getPlayer(); + String[] split = event.getMessage().split(" "); + String x = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") "; + String y = ChatColor.AQUA + "{" + ChatColor.WHITE + player.getName() + ChatColor.AQUA + "} "; + if(mcConfig.getInstance().isPartyToggled(player.getName())){ + event.setCancelled(true); + log.log(Level.INFO, "[P]("+mcUsers.getProfile(player).getParty()+")"+"<"+player.getName()+"> "+event.getMessage()); + for(Player herp : plugin.getServer().getOnlinePlayers()){ + if(mcUsers.getProfile(herp).inParty()){ + if(mcm.getInstance().inSameParty(herp, player)){ + herp.sendMessage(x+event.getMessage()); + } + } + } + return; + } + if((player.isOp() || mcPermissions.getInstance().adminChat(player)) + && mcConfig.getInstance().isAdminToggled(player.getName())){ + log.log(Level.INFO, "[A]"+"<"+player.getName()+"> "+event.getMessage()); + event.setCancelled(true); + for(Player herp : plugin.getServer().getOnlinePlayers()){ + if(herp.isOp()){ + herp.sendMessage(y+event.getMessage()); + } + } + return; + } + } +} \ No newline at end of file diff --git a/mcMMO/com/gmail/nossr50/mcUsers.java b/mcMMO/com/gmail/nossr50/mcUsers.java new file mode 100644 index 000000000..8b81abbe2 --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcUsers.java @@ -0,0 +1,840 @@ +package com.gmail.nossr50; + +import java.io.*; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.bukkit.Location; +import org.bukkit.entity.*; + +public class mcUsers { + private static volatile mcUsers instance; + protected static final Logger log = Logger.getLogger("Minecraft"); + String location = "mcmmo.users"; + public static PlayerList players = new PlayerList(); + private Properties properties = new Properties(); + + //To load + public void load() throws IOException { + properties.load(new FileInputStream(location)); + } + //To save + public void save() { + try { + properties.store(new FileOutputStream(location), null); + }catch(IOException ex) { + } + } + + + public void loadUsers(){ + File theDir = new File(location); + if(!theDir.exists()){ + //properties = new PropertiesFile(location); + FileWriter writer = null; + try { + writer = new FileWriter(location); + writer.write("#Storage place for user information\r\n"); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while creating " + location, e); + } finally { + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while closing writer for " + location, e); + } + } + + } else { + //properties = new PropertiesFile(location); + try { + load(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading " + location, e); + } + } + } + + //===================================================================== + //Function: addUser + //Input: Player player: The player to create a profile for + //Output: none + //Use: Loads the profile for the specified player + //===================================================================== + public static void addUser(Player player){ + players.addPlayer(player); + } + + //===================================================================== + //Function: removeUser + //Input: Player player: The player to stop following + //Output: none + //Use: Creates the player profile + //===================================================================== + public static void removeUser(Player player){ + players.removePlayer(player); + } + + //===================================================================== + //Function: getProfile + //Input: Player player: The player to find the profile for + //Output: PlayerList.PlayerProfile: The profile + //Use: Gets the player profile + //===================================================================== + public static PlayerList.PlayerProfile getProfile(Player player){ + return players.findProfile(player); + } + + public static mcUsers getInstance() { + if (instance == null) { + instance = new mcUsers(); + } + return instance; + } + public static void getRow(){ + + } +} +class PlayerList +{ + protected static final Logger log = Logger.getLogger("Minecraft"); + ArrayList players; + + //===================================================================== + //Function: PlayerList + //Input: Player player: The player to create a profile object for + //Output: none + //Use: Initializes the ArrayList + //===================================================================== + public PlayerList() { players = new ArrayList(); } + + //===================================================================== + //Function: addPlayer + //Input: Player player: The player to add + //Output: None + //Use: Add a profile of the specified player + //===================================================================== + public void addPlayer(Player player) + { + players.add(new PlayerProfile(player)); + } + + //===================================================================== + //Function: removePlayer + //Input: Player player: The player to remove + //Output: None + //Use: Remove the profile of the specified player + //===================================================================== + public void removePlayer(Player player) + { + players.remove(findProfile(player)); + } + + //===================================================================== + //Function: findProfile + //Input: Player player: The player to find's profile + //Output: PlayerProfile: The profile of the specified player + //Use: Get the profile for the specified player + //===================================================================== + public PlayerProfile findProfile(Player player) + { + for(PlayerProfile ply : players) + { + if(ply.isPlayer(player)) + return ply; + } + return null; + } + + class PlayerProfile + { + protected final Logger log = Logger.getLogger("Minecraft"); + private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn, unarmed, herbalism, excavation, + archery, swords, axes, invite, acrobatics; + private boolean dead; + char defaultColor; + + String location = "mcmmo.users"; + + + //===================================================================== + //Function: PlayerProfile + //Input: Player player: The player to create a profile object for + //Output: none + //Use: Loads settings for the player or creates them if they don't + // exist. + //===================================================================== + public PlayerProfile(Player player) + { + //Declare things + playerName = player.getName(); + party = new String(); + myspawn = new String(); + mining = new String(); + repair = new String(); + unarmed = new String(); + herbalism = new String(); + excavation = new String(); + archery = new String(); + swords = new String(); + axes = new String(); + acrobatics = new String(); + invite = new String(); + //mining = "0"; + wgather = new String(); + //wgather = "0"; + woodcutting = new String(); + //woodcutting = "0"; + gather = new String(); + //gather = "0"; + party = null; + dead = false; + + //Try to load the player and if they aren't found, append them + if(!load()) + addPlayer(); + } + + public boolean load() + { + try { + //Open the user file + FileReader file = new FileReader(location); + BufferedReader in = new BufferedReader(file); + String line = ""; + while((line = in.readLine()) != null) + { + //Find if the line contains the player we want. + String[] character = line.split(":"); + if(!character[0].equals(playerName)){continue;} + + //Get Mining + if(character.length > 1) + mining = character[1]; + //Myspawn + if(character.length > 2) + myspawn = character[2]; + //Party + if(character.length > 3) + party = character[3]; + //Mining Gather + if(character.length > 4) + gather = character[4]; + if(character.length > 5) + woodcutting = character[5]; + if(character.length > 6) + wgather = character[6]; + if(character.length > 7) + repair = character[7]; + if(character.length > 8) + unarmed = character[8]; + if(character.length > 9) + herbalism = character[9]; + if(character.length > 10) + excavation = character[10]; + if(character.length > 11) + archery = character[11]; + if(character.length > 12) + swords = character[12]; + if(character.length > 13) + axes = character[13]; + if(character.length > 14) + acrobatics = character[14]; + in.close(); + return true; + } + in.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + + location + " (Are you sure you formatted it correctly?)", e); + } + return false; + } + + //===================================================================== + // Function: save + // Input: none + // Output: None + // Use: Writes current values of PlayerProfile to disk + // Call this function to save current values + //===================================================================== + public void save() + { + try { + //Open the file + FileReader file = new FileReader(location); + BufferedReader in = new BufferedReader(file); + StringBuilder writer = new StringBuilder(); + String line = ""; + + //While not at the end of the file + while((line = in.readLine()) != null) + { + //Read the line in and copy it to the output it's not the player + //we want to edit + if(!line.split(":")[0].equalsIgnoreCase(playerName)) + { + writer.append(line).append("\r\n"); + + //Otherwise write the new player information + } else { + writer.append(playerName + ":"); + writer.append(mining + ":"); + writer.append(myspawn + ":"); + writer.append(party+":"); + writer.append(gather+":"); + writer.append(woodcutting+":"); + writer.append(wgather+":"); + writer.append(repair+":"); + writer.append(unarmed+":"); + writer.append(herbalism+":"); + writer.append(excavation+":"); + writer.append(archery+":"); + writer.append(swords+":"); + writer.append(axes+":"); + writer.append(acrobatics+":"); + writer.append("\r\n"); + } + } + in.close(); + //Write the new file + FileWriter out = new FileWriter(location); + out.write(writer.toString()); + out.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + } + } + public void addPlayer() + { + try { + //Open the file to write the player + FileWriter file = new FileWriter(location, true); + BufferedWriter out = new BufferedWriter(file); + + //Add the player to the end + out.append(playerName + ":"); + out.append(0 + ":"); //mining + out.append(myspawn+":"); + out.append(party+":"); + out.append(0+":"); //gather + out.append(0+":"); //woodcutting + out.append(0+":"); //wgather + out.append(0+":"); //repair + out.append(0+":"); //unarmed + out.append(0+":"); //herbalism + out.append(0+":"); //excavation + out.append(0+":"); //archery + out.append(0+":"); //swords + out.append(0+":"); //axes + out.append(0+":"); //acrobatics + //Add more in the same format as the line above + + out.newLine(); + out.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + } + } + + //===================================================================== + //Function: isPlayer + //Input: None + //Output: Player: The player this profile belongs to + //Use: Finds if this profile belongs to a specified player + //===================================================================== + public boolean isPlayer(Player player) + { + return player.getName().equals(playerName); + } + public void skillUpAxes(int newskill){ + int x = 0; + if(axes != null){ + if(isInt(axes)){ + x = Integer.parseInt(axes); + }else { + axes = "0"; + x = Integer.parseInt(axes); + } + } + x += newskill; + axes = Integer.toString(x); + save(); + } + public void skillUpAcrobatics(int newskill){ + int x = 0; + if(acrobatics != null){ + if(isInt(acrobatics)){ + x = Integer.parseInt(acrobatics); + }else { + acrobatics = "0"; + x = Integer.parseInt(acrobatics); + } + } + x += newskill; + acrobatics = Integer.toString(x); + save(); + } + public void skillUpSwords(int newskill){ + int x = 0; + if(swords != null){ + if(isInt(swords)){ + x = Integer.parseInt(swords); + }else { + swords = "0"; + x = Integer.parseInt(swords); + } + } + x += newskill; + swords = Integer.toString(x); + save(); + } + public void skillUpArchery(int newskill){ + int x = 0; + if(archery != null){ + if(isInt(archery)){ + x = Integer.parseInt(archery); + }else { + archery = "0"; + x = Integer.parseInt(archery); + } + } + x += newskill; + archery = Integer.toString(x); + save(); + } + public void skillUpRepair(int newskill){ + int x = 0; + if(repair != null){ + if(isInt(repair)){ + x = Integer.parseInt(repair); + }else { + repair = "0"; + x = Integer.parseInt(repair); + } + } + x += newskill; + repair = Integer.toString(x); + save(); + } + public void skillUpMining(int newmining){ + int x = 0; + if(mining != null){ + if(isInt(mining)){ + x = Integer.parseInt(mining); + }else { + mining = "0"; + x = Integer.parseInt(mining); + } + } + x += newmining; + mining = Integer.toString(x); + save(); + } + public void skillUpUnarmed(int newskill){ + int x = 0; + if(unarmed != null){ + if(isInt(unarmed)){ + x = Integer.parseInt(unarmed); + }else { + unarmed = "0"; + x = Integer.parseInt(unarmed); + } + } + x += newskill; + unarmed = Integer.toString(x); + save(); + } + public void skillUpHerbalism(int newskill){ + int x = 0; + if(herbalism != null){ + if(isInt(herbalism)){ + x = Integer.parseInt(herbalism); + }else { + herbalism = "0"; + x = Integer.parseInt(herbalism); + } + } + x += newskill; + herbalism = Integer.toString(x); + save(); + } + public void skillUpExcavation(int newskill){ + int x = 0; + if(excavation != null){ + if(isInt(excavation)){ + x = Integer.parseInt(excavation); + }else { + excavation = "0"; + x = Integer.parseInt(excavation); + } + } + x += newskill; + excavation = Integer.toString(x); + save(); + } + public void skillUpWoodcutting(int newskill){ + int x = 0; + if(woodcutting != null){ + if(isInt(woodcutting)){ + x = Integer.parseInt(woodcutting); + }else { + woodcutting = "0"; + x = Integer.parseInt(woodcutting); + } + } + x += newskill; + woodcutting = Integer.toString(x); + save(); + } + public String getRepair(){ + if(repair != null && !repair.equals("") && !repair.equals("null")){ + return repair; + } else { + return "0"; + } + } + public String getMining(){ + if(mining != null && !mining.equals("") && !mining.equals("null")){ + return mining; + } else { + return "0"; + } + } + public String getUnarmed(){ + if(unarmed != null && !unarmed.equals("") && !unarmed.equals("null")){ + return unarmed; + } else { + return "0"; + } + } + public String getHerbalism(){ + if(herbalism != null && !herbalism.equals("") && !herbalism.equals("null")){ + return herbalism; + } else { + return "0"; + } + } + public String getExcavation(){ + if(excavation != null && !excavation.equals("") && !excavation.equals("null")){ + return excavation; + } else { + return "0"; + } + } + public String getArchery(){ + if(archery != null && !archery.equals("") && !archery.equals("null")){ + return archery; + } else { + return "0"; + } + } + public String getSwords(){ + if(swords != null && !swords.equals("") && !swords.equals("null")){ + return swords; + } else { + return "0"; + } + } + public String getAxes(){ + if(axes != null && !axes.equals("") && !axes.equals("null")){ + return axes; + } else { + return "0"; + } + } + public String getAcrobatics(){ + if(acrobatics != null && !acrobatics.equals("") && !acrobatics.equals("null")){ + return acrobatics; + } else { + return "0"; + } + } + public int getMiningInt(){ + if(isInt(mining)){ + int x = Integer.parseInt(mining); + return x; + } else{ + return 0; + } + } + public int getUnarmedInt(){ + if(isInt(unarmed)){ + int x = Integer.parseInt(unarmed); + return x; + } else{ + return 0; + } + } + public int getArcheryInt(){ + if(isInt(archery)){ + int x = Integer.parseInt(archery); + return x; + } else{ + return 0; + } + } + public int getSwordsInt(){ + if(isInt(swords)){ + int x = Integer.parseInt(swords); + return x; + } else{ + return 0; + } + } + public int getAxesInt(){ + if(isInt(axes)){ + int x = Integer.parseInt(axes); + return x; + } else{ + return 0; + } + } + public int getAcrobaticsInt(){ + if(isInt(acrobatics)){ + int x = Integer.parseInt(acrobatics); + return x; + } else{ + return 0; + } + } + public int getHerbalismInt(){ + if(isInt(herbalism)){ + int x = Integer.parseInt(herbalism); + return x; + } else{ + return 0; + } + } + public int getExcavationInt(){ + if(isInt(excavation)){ + int x = Integer.parseInt(excavation); + return x; + } else{ + return 0; + } + } + public int getRepairInt(){ + if(isInt(repair)){ + int x = Integer.parseInt(repair); + return x; + } else{ + return 0; + } + } + public int getWoodCuttingint(){ + if(isInt(woodcutting)){ + int x = Integer.parseInt(woodcutting); + return x; + } else{ + return 0; + } + } + public String getWoodCutting(){ + if(woodcutting != null && !woodcutting.equals("") && !woodcutting.equals("null")){ + return woodcutting; + } else { + return "0"; + } + } + + public void addwgather(int newgather) + { + int x = 0; + if(isInt(wgather)){ + x = Integer.parseInt(wgather); + } + x += newgather; + wgather = String.valueOf(x); + save(); + } + public void removewgather(int newgather){ + int x = 0; + if(isInt(wgather)){ + x = Integer.parseInt(wgather); + } + x -= newgather; + wgather = String.valueOf(x); + save(); + } + public void addgather(int newgather) + { + int x = 0; + if(isInt(gather)){ + x = Integer.parseInt(gather); + } else { + x = 0; + } + x += newgather; + gather = String.valueOf(x); + save(); + } + public void removegather(int newgather){ + int x = 0; + if(isInt(gather)){ + x = Integer.parseInt(gather); + } + x -= newgather; + gather = String.valueOf(x); + save(); + } + + public boolean isInt(String string){ + try { + int x = Integer.parseInt(string); + } + catch(NumberFormatException nFE) { + return false; + } + return true; + } + public boolean isDouble(String string){ + try { + Double x = Double.valueOf(string); + } + catch(NumberFormatException nFE) { + return false; + } + return true; + } + public void acceptInvite(){ + party = invite; + invite = ""; + save(); + } + public void modifyInvite(String invitename){ + invite = invitename; + } + //Returns player gather + public String getgather() { return gather; } + public String getInvite() { return invite; } + public String getwgather() { return wgather; } + + public int getwgatheramt() { + if(isInt(wgather)){ + return Integer.parseInt(getwgather()); + } else { + wgather = "0"; + save(); + return 0; + } + } + public void modifyskill(int newvalue, String skillname){ + if(skillname.equals("mining")){ + mining = String.valueOf(newvalue); + } + if(skillname.equals("woodcutting")){ + woodcutting = String.valueOf(newvalue); + } + if(skillname.equals("repair")){ + repair = String.valueOf(newvalue); + } + if(skillname.equals("herbalism")){ + herbalism = String.valueOf(newvalue); + } + if(skillname.equals("acrobatics")){ + acrobatics = String.valueOf(newvalue); + } + if(skillname.equals("swords")){ + swords = String.valueOf(newvalue); + } + if(skillname.equals("archery")){ + archery = String.valueOf(newvalue); + } + if(skillname.equals("unarmed")){ + unarmed = String.valueOf(newvalue); + } + if(skillname.equals("excavation")){ + excavation = String.valueOf(newvalue); + } + save(); + } + public int getgatheramt() { + if(isInt(gather)){ + return Integer.parseInt(getgather()); + } else { + gather = "0"; + save(); + return 0; + } + } + + //Store the player's party + public void setParty(String newParty) + { + party = newParty; + save(); + } + //Retrieve the player's party + public String getParty() {return party;} + //Remove party + public void removeParty() { + party = null; + save(); + } + //Retrieve whether or not the player is in a party + public boolean inParty() { + if(party != null && !party.equals("") && !party.equals("null")){ + return true; + } else { + return false; + } + } + //Retrieve whether or not the player has an invite + public boolean hasPartyInvite() { + if(invite != null && !invite.equals("") && !invite.equals("null")){ + return true; + } else { + return false; + } + } + //Save a users spawn location + public void setMySpawn(double x, double y, double z){ + myspawn = x+","+y+","+z; + save(); + } + public String getX(){ + String[] split = myspawn.split(","); + String x = split[0]; + return x; + } + public String getY(){ + String[] split = myspawn.split(","); + String y = split[1]; + return y; + } + public String getZ(){ + String[] split = myspawn.split(","); + String z = split[2]; + return z; + } + public void setDead(boolean x){ + dead = x; + save(); + } + public boolean isDead(){ + return dead; + } + public Location getMySpawn(Player player){ + Location loc = player.getLocation(); + if(isDouble(getX()) && isDouble(getY()) && isDouble(getX())){ + loc.setX(Double.parseDouble(mcUsers.getProfile(player).getX())); + loc.setY(Double.parseDouble(mcUsers.getProfile(player).getY())); + loc.setZ(Double.parseDouble(mcUsers.getProfile(player).getZ())); + } else { + return null; + } + loc.setYaw(0); + loc.setPitch(0); + return loc; + } + } + +} + + + diff --git a/mcMMO/com/gmail/nossr50/mcm.java b/mcMMO/com/gmail/nossr50/mcm.java new file mode 100644 index 000000000..4fa3d7e55 --- /dev/null +++ b/mcMMO/com/gmail/nossr50/mcm.java @@ -0,0 +1,1285 @@ +package com.gmail.nossr50; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Cow; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Pig; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Spider; +import org.bukkit.entity.Squid; +import org.bukkit.entity.Zombie; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class mcm { + /* + * I'm storing my functions/methods in here in an unorganized manner. Spheal with it. + */ + private static volatile mcm instance; + public static mcm getInstance() { + if (instance == null) { + instance = new mcm(); + } + return instance; + } + public boolean inSameParty(Player playera, Player playerb){ + if(mcUsers.getProfile(playera).getParty().equals(mcUsers.getProfile(playerb).getParty())){ + return true; + } else { + return false; + } + } + public boolean hasArrows(Player player){ + for(ItemStack x : player.getInventory().getContents()){ + if (x.getTypeId() == 262){ + return true; + } + } + return false; + } + public void addArrows(Player player){ + for(ItemStack x : player.getInventory().getContents()){ + if (x.getTypeId() == 262){ + x.setAmount(x.getAmount() + 1); + return; + } + } + } + public boolean isSkill(String skillname){ + if(skillname.equals("mining")){ + return true; + } + else if(skillname.equals("woodcutting")){ + return true; + } + else if(skillname.equals("repair")){ + return true; + } + else if(skillname.equals("herbalism")){ + return true; + } + else if(skillname.equals("acrobatics")){ + return true; + } + else if(skillname.equals("swords")){ + return true; + } + else if(skillname.equals("archery")){ + return true; + } + else if(skillname.equals("unarmed")){ + return true; + } else { + return false; + } + } + public boolean isInt(String string){ + try { + int x = Integer.parseInt(string); + } + catch(NumberFormatException nFE) { + return false; + } + return true; + } + public void simulateNaturalDrops(Entity entity){ + Location loc = entity.getLocation(); + if(entity instanceof Pig){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 319); //BACON + } + dropItem(loc, 319); + } + } + if(entity instanceof Spider){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 287); //SILK + } + dropItem(loc, 287); + } + } + if(entity instanceof Skeleton){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 262); //ARROWS + } + dropItem(loc, 262); + } + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 352); //BONES + } + dropItem(loc, 352); + } + } + if(entity instanceof Zombie){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 288); //FEATHERS + } + dropItem(loc, 288); + } + } + if(entity instanceof Cow){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 334); //LEATHER + } + if(Math.random() * 2 > 1){ + dropItem(loc, 334); + } + dropItem(loc, 334); + } + } + if(entity instanceof Squid){ + if(Math.random() * 3 > 2){ + if(Math.random() * 2 > 1){ + dropItem(loc, 351); //INK SACS + } + if(Math.random() * 2 > 1){ + dropItem(loc, 351); + } + dropItem(loc, 351); + } + } + + + } + public void dropItem(Location loc, int id){ + if(loc != null){ + Material mat = Material.getMaterial(id); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + loc.getWorld().dropItemNaturally(loc, item); + } + } + public boolean checkPlayerProcRepair(Player player){ + if(mcUsers.getProfile(player).getRepairInt() >= 750){ + if(Math.random() * 10 > 2){ + player.sendMessage(ChatColor.GRAY + "That took no effort."); + return true; + } + } else if (mcUsers.getProfile(player).getRepairInt() >= 450 && mcUsers.getProfile(player).getRepairInt() < 750){ + if(Math.random() * 10 > 4){ + player.sendMessage(ChatColor.GRAY + "That felt really easy."); + return true; + } + } else if (mcUsers.getProfile(player).getRepairInt() >= 150 && mcUsers.getProfile(player).getRepairInt() < 450){ + if(Math.random() * 10 > 6){ + player.sendMessage(ChatColor.GRAY + "That felt pretty easy."); + return true; + } + } else if (mcUsers.getProfile(player).getRepairInt() >= 50 && mcUsers.getProfile(player).getRepairInt() < 150){ + if(Math.random() * 10 > 8){ + player.sendMessage(ChatColor.GRAY + "That felt easy."); + return true; + } + } + return false; + } + + //This determines how much we repair + public short getArmorRepairAmount(ItemStack is, Player player){ + short durability = is.getDurability(); + switch(is.getTypeId()) + { + case 306: + durability -= 27; + break; + case 310: + durability -= 55; + break; + case 307: + durability -= 24; + break; + case 311: + durability -= 48; + break; + case 308: + durability -= 27; + break; + case 312: + durability -= 53; + break; + case 309: + durability -= 40; + break; + case 313: + durability -= 80; + break; + } + if(durability < 0) + durability = 0; + if(checkPlayerProcRepair(player)) + durability = 0; + return durability; + } + public short getToolRepairAmount(ItemStack is, short durability, Player player){ + //IRON SHOVEL + if(is.getTypeId() == 256){ + return 0; //full repair + } + //DIAMOND SHOVEL + if(is.getTypeId() == 277){ + return 0; //full repair + } + //IRON TOOLS + if(is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292){ + if(durability < 84){ + return 0; + }else { + if(checkPlayerProcRepair(player)) + return 0; + return (short) (durability-84); + } + //DIAMOND TOOLS + } else if(is.getTypeId() == 276 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293){ + if(durability < 509){ + return 0; + } else { + if(checkPlayerProcRepair(player)) + return 0; + return (short) (durability-509); + } + } else { + return durability; + } + } + public void blockProcSimulate(Block block){ + Location loc = block.getLocation(); + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + ItemStack item = new ItemStack(mat, 1, (byte)0, damage); + if(block.getTypeId() != 73 && block.getTypeId() != 74 && block.getTypeId() != 56 && block.getTypeId() != 21 && block.getTypeId() != 1 && block.getTypeId() != 16) + block.getWorld().dropItemNaturally(loc, item); + if(block.getTypeId() == 73 || block.getTypeId() == 74){ + mat = Material.getMaterial(331); + item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + if(Math.random() * 10 > 5){ + block.getWorld().dropItemNaturally(loc, item); + } + } + if(block.getTypeId() == 21){ + mat = Material.getMaterial(351); + item = new ItemStack(mat, 1, (byte)0,(byte)0x4); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + block.getWorld().dropItemNaturally(loc, item); + } + if(block.getTypeId() == 56){ + mat = Material.getMaterial(264); + item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + } + if(block.getTypeId() == 1){ + mat = Material.getMaterial(4); + item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + } + if(block.getTypeId() == 16){ + mat = Material.getMaterial(263); + item = new ItemStack(mat, 1, (byte)0, damage); + block.getWorld().dropItemNaturally(loc, item); + } + } + public void blockProcCheck(Block block, Player player){ + if(mcUsers.getProfile(player).getMiningInt() > 3000){ + blockProcSimulate(block); + return; + } + if(mcUsers.getProfile(player).getMiningInt() > 2000){ + if((Math.random() * 10) > 2){ + blockProcSimulate(block); + return; + } + } + if(mcUsers.getProfile(player).getMiningInt() > 750){ + if((Math.random() * 10) > 4){ + blockProcSimulate(block); + return; + } + } + if(mcUsers.getProfile(player).getMiningInt() > 150){ + if((Math.random() * 10) > 6){ + blockProcSimulate(block); + return; + } + } + if(mcUsers.getProfile(player).getMiningInt() > 25){ + if((Math.random() * 10) > 8){ + blockProcSimulate(block); + return; + } + } + + } + public void miningBlockCheck(Player player, Block block){ + if(block.getTypeId() == 1){ + mcUsers.getProfile(player).addgather(1); + mcm.getInstance().blockProcCheck(block, player); + } + //COAL + if(block.getTypeId() == 16){ + mcUsers.getProfile(player).addgather(3); + mcm.getInstance().blockProcCheck(block, player); + } + //GOLD + if(block.getTypeId() == 14){ + mcUsers.getProfile(player).addgather(20); + mcm.getInstance().blockProcCheck(block, player); + } + //DIAMOND + if(block.getTypeId() == 56){ + mcUsers.getProfile(player).addgather(50); + mcm.getInstance().blockProcCheck(block, player); + } + //IRON + if(block.getTypeId() == 15){ + mcUsers.getProfile(player).addgather(10); + mcm.getInstance().blockProcCheck(block, player); + } + //REDSTONE + if(block.getTypeId() == 73 || block.getTypeId() == 74){ + mcUsers.getProfile(player).addgather(15); + mcm.getInstance().blockProcCheck(block, player); + } + //LAPUS + if(block.getTypeId() == 21){ + mcUsers.getProfile(player).addgather(50); + mcm.getInstance().blockProcCheck(block, player); + } + } + public void breadCheck(Player player, ItemStack is){ + if(is.getTypeId() == 297){ + if(mcUsers.getProfile(player).getHerbalismInt() >= 50 && mcUsers.getProfile(player).getHerbalismInt() < 150){ + player.setHealth(player.getHealth() + 1); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 150 && mcUsers.getProfile(player).getHerbalismInt() < 250){ + player.setHealth(player.getHealth() + 2); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 250 && mcUsers.getProfile(player).getHerbalismInt() < 350){ + player.setHealth(player.getHealth() + 3); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 350 && mcUsers.getProfile(player).getHerbalismInt() < 450){ + player.setHealth(player.getHealth() + 4); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 450 && mcUsers.getProfile(player).getHerbalismInt() < 550){ + player.setHealth(player.getHealth() + 5); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 550 && mcUsers.getProfile(player).getHerbalismInt() < 650){ + player.setHealth(player.getHealth() + 6); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 650 && mcUsers.getProfile(player).getHerbalismInt() < 750){ + player.setHealth(player.getHealth() + 7); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 750){ + player.setHealth(player.getHealth() + 8); + } + } + } + public void stewCheck(Player player, ItemStack is){ + if(is.getTypeId() == 282){ + if(mcUsers.getProfile(player).getHerbalismInt() >= 50 && mcUsers.getProfile(player).getHerbalismInt() < 150){ + player.setHealth(player.getHealth() + 1); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 150 && mcUsers.getProfile(player).getHerbalismInt() < 250){ + player.setHealth(player.getHealth() + 2); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 250 && mcUsers.getProfile(player).getHerbalismInt() < 350){ + player.setHealth(player.getHealth() + 3); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 350 && mcUsers.getProfile(player).getHerbalismInt() < 450){ + player.setHealth(player.getHealth() + 4); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 450 && mcUsers.getProfile(player).getHerbalismInt() < 550){ + player.setHealth(player.getHealth() + 5); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 550 && mcUsers.getProfile(player).getHerbalismInt() < 650){ + player.setHealth(player.getHealth() + 6); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 650 && mcUsers.getProfile(player).getHerbalismInt() < 750){ + player.setHealth(player.getHealth() + 7); + } else if (mcUsers.getProfile(player).getHerbalismInt() >= 750){ + player.setHealth(player.getHealth() + 8); + } + } + } + public void needMoreVespeneGas(ItemStack is, Player player){ + if ((mcm.getInstance().isDiamondTools(is) || mcm.getInstance().isDiamondArmor(is) ) && mcUsers.getProfile(player).getRepairInt() < 50){ + player.sendMessage(ChatColor.DARK_RED +"You're not adept enough to repair Diamond"); + } else if (mcm.getInstance().isDiamondTools(is) && !mcm.getInstance().hasDiamond(player) || mcm.getInstance().isIronTools(is) && !mcm.getInstance().hasIron(player)){ + if(mcm.getInstance().isDiamondTools(is) && !mcm.getInstance().hasDiamond(player)) + player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.BLUE+ "Diamonds"); + if(mcm.getInstance().isIronTools(is) && !mcm.getInstance().hasIron(player)) + player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GRAY+ "Iron"); + } else if (mcm.getInstance().isDiamondArmor(is) && !mcm.getInstance().hasDiamond(player)){ + player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.BLUE+ "Diamonds"); + } else if (mcm.getInstance().isIronArmor(is) && !mcm.getInstance().hasIron(player)) + player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GRAY+ "Iron"); + } + public boolean isSwords(ItemStack is){ + if(is.getTypeId() == 268 || is.getTypeId() == 267 || is.getTypeId() == 272 || is.getTypeId() == 283 || is.getTypeId() == 276){ + return true; + } else { + return false; + } + } + public boolean simulateUnarmedProc(Player player){ + if(mcUsers.getProfile(player).getUnarmedInt() >= 750){ + if(Math.random() * 10 > 4){ + return true; + } + }if(mcUsers.getProfile(player).getUnarmedInt() >= 350 && mcUsers.getProfile(player).getUnarmedInt() < 750){ + if(Math.random() * 10 > 4){ + return true; + } + } + return false; + } + public void playerVersusPlayerChecks(Entity x, Player attacker, EntityDamageByEntityEvent event, Plugin plugin){ + if(x instanceof Player){ + Player defender = (Player)x; + if(mcUsers.getProfile(attacker).inParty() && mcUsers.getProfile(defender).inParty()){ + if(inSameParty(defender, attacker)){ + event.setCancelled(true); + return; + } + } + if(mcPermissions.getInstance().unarmed(attacker) && attacker.getItemInHand().getTypeId() == 0){ + //DMG MODIFIER + if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){ + defender.setHealth(calculateDamage(defender, 1)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){ + defender.setHealth(calculateDamage(defender, 2)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){ + defender.setHealth(calculateDamage(defender, 3)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){ + defender.setHealth(calculateDamage(defender, 4)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){ + defender.setHealth(calculateDamage(defender, 5)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){ + defender.setHealth(calculateDamage(defender, 6)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){ + defender.setHealth(calculateDamage(defender, 7)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){ + defender.setHealth(calculateDamage(defender, 8)); + } + if(mcUsers.getProfile(defender).isDead()) + return; + //XP + if(attacker.getItemInHand().getTypeId() == 0 && Math.random() * 10 > 9){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(1); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + //PROC + if(simulateUnarmedProc(attacker)){ + Location loc = defender.getLocation(); + if(defender.getItemInHand() != null && defender.getItemInHand().getTypeId() != 0){ + attacker.sendMessage(ChatColor.DARK_RED+"You have hit with great force."); + defender.sendMessage(ChatColor.DARK_RED+"You have been disarmed!"); + ItemStack item = defender.getItemInHand(); + if(item != null){ + loc.getWorld().dropItemNaturally(loc, item); + Material mat; + mat = Material.getMaterial(0); + ItemStack itemx = null; + defender.setItemInHand(itemx); + } + } + } + /* + * Make the defender drop items on death + */ + if(defender.getHealth()<= 0 && !mcUsers.getProfile(defender).isDead()){ + mcUsers.getProfile(defender).setDead(true); + event.setCancelled(true); //SEE IF THIS HELPS + for(ItemStack herp : defender.getInventory().getContents()){ + if(herp != null && herp.getTypeId() != 0) + defender.getLocation().getWorld().dropItemNaturally(defender.getLocation(), herp); + } + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName()); + mcUsers.getProfile(defender).setDead(true); + } + } + return; + } + if(mcUsers.getProfile(defender).isDead()) + return; + if((defender.getHealth() - event.getDamage()) <= 0 && defender.getHealth() != 0){ + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName()); + mcUsers.getProfile(defender).setDead(true); + } + } + //Moving this below the death message for now, seems to have issues when the defender is not in a party + if((mcUsers.getProfile(defender).inParty() && mcUsers.getProfile(attacker).inParty())&& mcUsers.getProfile(defender).getParty().equals(mcUsers.getProfile(attacker).getParty())) + event.setCancelled(true); + } + } + public void playerVersusSquidChecks(EntityDamageByEntityEvent event, Player attacker, Entity x, int type){ + if(x instanceof Squid){ + Squid defender = (Squid)event.getEntity(); + if(isSwords(attacker.getItemInHand()) && defender.getHealth() > 0 && mcPermissions.getInstance().swords(attacker)){ + if(Math.random() * 10 > 9){ + mcUsers.getProfile(attacker).skillUpSwords(1); + attacker.sendMessage(ChatColor.YELLOW+"Swords skill increased by 1. Total ("+mcUsers.getProfile(attacker).getSwords()+")"); + } + } + /* + * UNARMED VS SQUID + */ + if(type == 0 && mcPermissions.getInstance().unarmed(attacker)){ + if(defender.getHealth() <= 0) + return; + if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){ + defender.setHealth(calculateDamage(defender, 1)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){ + defender.setHealth(calculateDamage(defender, 2)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){ + defender.setHealth(calculateDamage(defender, 3)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){ + defender.setHealth(calculateDamage(defender, 4)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){ + defender.setHealth(calculateDamage(defender, 5)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){ + defender.setHealth(calculateDamage(defender, 6)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){ + defender.setHealth(calculateDamage(defender, 7)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){ + defender.setHealth(calculateDamage(defender, 8)); + } + //XP + if(attacker.getItemInHand().getTypeId() == 0 && Math.random() * 10 > 8){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(1); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + if(defender.getHealth() <= 0) + mcm.getInstance().simulateNaturalDrops(defender); + } + } + } + public void playerVersusAnimalsChecks(Entity x, Player attacker, EntityDamageByEntityEvent event, int type){ + if(x instanceof Animals){ + if(type == 0 && mcPermissions.getInstance().unarmed(attacker)){ + Animals defender = (Animals)event.getEntity(); + if(defender.getHealth() <= 0) + return; + if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){ + defender.setHealth(calculateDamage(defender, 1)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){ + defender.setHealth(calculateDamage(defender, 2)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){ + defender.setHealth(calculateDamage(defender, 3)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){ + defender.setHealth(calculateDamage(defender, 4)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){ + defender.setHealth(calculateDamage(defender, 5)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){ + defender.setHealth(calculateDamage(defender, 6)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){ + defender.setHealth(calculateDamage(defender, 7)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){ + defender.setHealth(calculateDamage(defender, 8)); + } + if(defender.getHealth() <= 0){ + mcm.getInstance().simulateNaturalDrops(defender); + } + } + } + } + public void playerDeathByMonsterMessageCheck(Entity y, Player defender, Plugin plugin){ + if(y instanceof Monster){ + if(mcUsers.getProfile(defender).isDead()) + return; + if(defender.getHealth() <= 0){ + mcm.getInstance().simulateNaturalDrops(defender); + if(y instanceof Creeper){ + mcUsers.getProfile(defender).setDead(true); + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY + "A "+ChatColor.DARK_GREEN+"Creeper"+ChatColor.GRAY+" has killed "+ChatColor.DARK_RED+defender.getName()); + } + } + if(y instanceof Skeleton){ + mcUsers.getProfile(defender).setDead(true); + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY + "A "+ChatColor.WHITE+"Skeleton"+ChatColor.GRAY+" has killed "+ChatColor.DARK_RED+defender.getName()); + } + } + if(y instanceof Spider){ + mcUsers.getProfile(defender).setDead(true); + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY + "A "+ChatColor.DARK_PURPLE+"Spider"+ChatColor.GRAY+" has killed "+ChatColor.DARK_RED+defender.getName()); + } + } + if(y instanceof Zombie){ + mcUsers.getProfile(defender).setDead(true); + for(Player derp : plugin.getServer().getOnlinePlayers()){ + derp.sendMessage(ChatColor.GRAY + "A "+ChatColor.DARK_AQUA+"Zombie"+ChatColor.GRAY+" has killed "+ChatColor.DARK_RED+defender.getName()); + } + } + } + } + } + public void playerVersusMonsterChecks(EntityDamageByEntityEvent event, Player attacker, Entity x, int type){ + if(x instanceof Monster){ + Monster defender = (Monster)event.getEntity(); + if(isSwords(attacker.getItemInHand()) + && defender.getHealth() > 0 + && mcPermissions.getInstance().swords(attacker)){ + if(Math.random() * 10 > 9){ + mcUsers.getProfile(attacker).skillUpSwords(1); + attacker.sendMessage(ChatColor.YELLOW+"Swords skill increased by 1. Total ("+mcUsers.getProfile(attacker).getSwords()+")"); + } + } + if(type == 0 && mcPermissions.getInstance().unarmed(attacker)){ + if(defender.getHealth() <= 0) + return; + if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){ + defender.setHealth(calculateDamage(defender, 1)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){ + defender.setHealth(calculateDamage(defender, 2)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){ + defender.setHealth(calculateDamage(defender, 3)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){ + defender.setHealth(calculateDamage(defender, 4)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){ + defender.setHealth(calculateDamage(defender, 5)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){ + defender.setHealth(calculateDamage(defender, 6)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){ + defender.setHealth(calculateDamage(defender, 7)); + } else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){ + defender.setHealth(calculateDamage(defender, 8)); + } + //XP + if(x instanceof Skeleton && Math.random() * 100 > 95){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(1); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + if(x instanceof Spider&& Math.random() * 10 > 9){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(1); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + if(x instanceof Zombie && Math.random() * 100 > 95){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(1); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + if(x instanceof Creeper && Math.random() * 100 > 90){ + if(defender.getHealth() != 0){ + mcUsers.getProfile(attacker).skillUpUnarmed(2); + attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 2. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")"); + } + } + if(defender.getHealth() <= 0) + mcm.getInstance().simulateNaturalDrops(defender); + } + } + } + public int calculateDamage(Player player, int dmg){ + int health = player.getHealth(); + if(health - dmg <0){ + return 0; + } else { + health-= dmg; + return health; + } + } + public int calculateDamage(Squid squid, int dmg){ + int health = squid.getHealth(); + if(health - dmg <0){ + return 0; + } else { + health-= dmg; + return health; + } + } + public int calculateDamage(Monster monster, int dmg){ + int health = monster.getHealth(); + if(health - dmg <0){ + return 0; + } else { + health-= dmg; + return health; + } + } + public int calculateDamage(Animals animal, int dmg){ + int health = animal.getHealth(); + if(health - dmg <0){ + return 0; + } else { + health-= dmg; + return health; + } + } + public void parryCheck(Player defender, EntityDamageByEntityEvent event, Entity y){ + if(isSwords(defender.getItemInHand()) + && event.getDamage() > 0 + && mcPermissions.getInstance().swords(defender)){ + if(mcUsers.getProfile(defender).getSwordsInt() >= 50 && mcUsers.getProfile(defender).getSwordsInt() < 250){ + if(Math.random() * 100 > 95){ + event.setCancelled(true); + defender.sendMessage(ChatColor.YELLOW+"*CLANG* SUCCESSFUL PARRY *CLANG*"); + defender.getItemInHand().setDurability((short) (defender.getItemInHand().getDurability() + 1)); + if(y instanceof Player){ + Player attacker = (Player)y; + attacker.sendMessage(ChatColor.DARK_RED+"**TARGET HAS PARRIED THAT ATTACK**"); + } + return; + } + } + if(mcUsers.getProfile(defender).getSwordsInt() >= 250 && mcUsers.getProfile(defender).getSwordsInt() < 450){ + if(Math.random() * 100 > 90){ + event.setCancelled(true); + defender.sendMessage(ChatColor.YELLOW+"*CLANG* SUCCESSFUL PARRY *CLANG*"); + defender.getItemInHand().setDurability((short) (defender.getItemInHand().getDurability() + 1)); + if(y instanceof Player){ + Player attacker = (Player)y; + attacker.sendMessage(ChatColor.DARK_RED+"**TARGET HAS PARRIED THAT ATTACK**"); + } + return; + } + } + if(mcUsers.getProfile(defender).getSwordsInt() >= 450 && mcUsers.getProfile(defender).getSwordsInt() < 775){ + if(Math.random() * 100 > 85){ + event.setCancelled(true); + defender.sendMessage(ChatColor.YELLOW+"*CLANG* SUCCESSFUL PARRY *CLANG*"); + defender.getItemInHand().setDurability((short) (defender.getItemInHand().getDurability() + 1)); + if(y instanceof Player){ + Player attacker = (Player)y; + attacker.sendMessage(ChatColor.DARK_RED+"**TARGET HAS PARRIED THAT ATTACK**"); + } + return; + } + } + if(mcUsers.getProfile(defender).getSwordsInt() >= 775){ + if(Math.random() * 100 > 80){ + event.setCancelled(true); + defender.sendMessage(ChatColor.YELLOW+"*CLANG* SUCCESSFUL PARRY *CLANG*"); + defender.getItemInHand().setDurability((short) (defender.getItemInHand().getDurability() + 1)); + if(y instanceof Player){ + Player attacker = (Player)y; + attacker.sendMessage(ChatColor.DARK_RED+"**TARGET HAS PARRIED THAT ATTACK**"); + } + return; + } + } + } + } + public void mcmmoHelpCheck(String[] split, Player player, PlayerChatEvent event){ + if(split[0].equalsIgnoreCase("/woodcutting")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~WOODCUTTING INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Chop down trees."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Double Drops start to happen at 10 woodcutting skill"); + player.sendMessage(ChatColor.GRAY+"and it gets more frequent from there."); + } + if(split[0].equalsIgnoreCase("/archery")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~ARCHERY INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Shooting monsters."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Damage scales with Archery skill"); + player.sendMessage(ChatColor.GRAY+"Chance to daze player opponents with high skill lvl"); + } + if(split[0].equalsIgnoreCase("/swords")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~SWORDS INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Slicing up monsters"); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Parrying. It negates damage."); + player.sendMessage(ChatColor.GRAY+"Chance to parry scales with skill."); + } + if(split[0].equalsIgnoreCase("/acrobatics")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~ACROBATICS INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Spraining ankles."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Rolling. Negates fall damage."); + player.sendMessage(ChatColor.GRAY+"Chance to roll scales with skill."); + } + if(split[0].equalsIgnoreCase("/mining")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~MINING INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Mining ore and stone,"); + player.sendMessage(ChatColor.DARK_GRAY+"the xp rate depends entirely upon the rarity of what you're harvesting."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Double Drops start to happen at 25 Mining skill,"); + player.sendMessage(ChatColor.GRAY+"and the chance for it increases with skill."); + } + if(split[0].equalsIgnoreCase("/repair")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~REPAIR INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Repairing tools and armor."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"High skill levels make a proc to fully repair items happen more often."); + player.sendMessage(ChatColor.GREEN+"~~USE~~"); + player.sendMessage(ChatColor.GRAY+"Approach an Anvil (Iron Block) with the item you wish "); + player.sendMessage(ChatColor.GRAY+"to repair in hand, right click to consume resources of the"); + player.sendMessage(ChatColor.GRAY+"same type to repair it. This does not work for stone/wood/gold"); + } + if(split[0].equalsIgnoreCase("/unarmed")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~UNARMED INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Punching monsters and players."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Damage scales with unarmed skill. The first damage increase"); + player.sendMessage(ChatColor.DARK_GRAY+"happens at 50 skill. At very high skill levels, you will"); + player.sendMessage(ChatColor.DARK_GRAY+"gain a proc to disarm player opponents on hit"); + } + if(split[0].equalsIgnoreCase("/herbalism")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~HERBALISM INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Farming and picking herbs."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"Increases healing effects of bread and stew."); + player.sendMessage(ChatColor.GRAY+"Allows for chance to receive double drops based on skill"); + } + if(split[0].equalsIgnoreCase("/excavation")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GREEN+"~~EXCAVATION INFO~~"); + player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Digging."); + player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~"); + player.sendMessage(ChatColor.GRAY+"You will find treasures while digging based on your excavation,"); + player.sendMessage(ChatColor.GRAY+"and at high levels the rewards are quite nice. The items you get"); + player.sendMessage(ChatColor.GRAY+"depend on the block you're digging."); + player.sendMessage(ChatColor.GRAY+"Different blocks give diffrent stuff."); + } + if(split[0].equalsIgnoreCase("/mcmmo")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GRAY+"mcMMO is an RPG inspired plugin"); + player.sendMessage(ChatColor.GRAY+"You can gain skills in several professions by"); + player.sendMessage(ChatColor.GRAY+"doing things related to that profession."); + player.sendMessage(ChatColor.GRAY+"Mining for example will increase your mining XP."); + player.sendMessage(ChatColor.GRAY+"Wood Cutting will increase Wood Cutting, etc..."); + player.sendMessage(ChatColor.GRAY+"Repairing is simple in mcMMO"); + player.sendMessage(ChatColor.GRAY+"Say you want to repair an iron shovel"); + player.sendMessage(ChatColor.GRAY+"start by making an anvil by combining 9 iron ingots"); + player.sendMessage(ChatColor.GRAY+"on a workbench. Place the anvil and while holding the shovel"); + player.sendMessage(ChatColor.GRAY+"right click the anvil to interact with it, If you have spare"); + player.sendMessage(ChatColor.GRAY+"iron ingots in your inventory the item will be repaired."); + player.sendMessage(ChatColor.GRAY+"You cannot hurt other party members"); + player.sendMessage(ChatColor.BLUE+"Set your own spawn with "+ChatColor.RED+"/myspawn"); + player.sendMessage(ChatColor.GREEN+"Based on your skills you will get "+ChatColor.DARK_RED+"random procs "+ChatColor.GREEN+ "when"); + player.sendMessage(ChatColor.GREEN+"using your profession, like "+ChatColor.DARK_RED+"double drops "+ChatColor.GREEN+"or "+ChatColor.DARK_RED+"better repairs"); + player.sendMessage(ChatColor.GREEN+"Find out mcMMO commands with /mcc"); + } + if(split[0].equalsIgnoreCase("/mcc")){ + event.setCancelled(true); + player.sendMessage(ChatColor.GRAY+"mcMMO has a party system included"); + player.sendMessage(ChatColor.GREEN+"~~Commands~~"); + if(mcPermissions.getInstance().party(player)){ + player.sendMessage(ChatColor.GRAY+"/party - to join a party"); + player.sendMessage(ChatColor.GRAY+"/party q - to quit a party"); + } + if(mcPermissions.getInstance().partyTeleport(player)) + player.sendMessage(ChatColor.GRAY+"/ptp - party teleport"); + if(mcPermissions.getInstance().partyChat(player)) + player.sendMessage(ChatColor.GRAY+"/p - toggles party chat"); + player.sendMessage(ChatColor.GREEN+"/stats"+ChatColor.GRAY+" - Check current skill levels"); + if(mcPermissions.getInstance().setMySpawn(player)) + player.sendMessage(ChatColor.GRAY+"/setmyspawn - Skill info"); + if(mcPermissions.getInstance().mySpawn(player)) + player.sendMessage(ChatColor.GRAY+"/myspawn - travel to myspawn, clears inventory"); + if(mcPermissions.getInstance().whois(player) || player.isOp()) + player.sendMessage(ChatColor.GRAY+"/whois - view detailed info about a player (req op)"); + player.sendMessage(ChatColor.GRAY+"/woodcutting - Skill info"); + player.sendMessage(ChatColor.GRAY+"/mining - Skill info"); + player.sendMessage(ChatColor.GRAY+"/repair - Skill info"); + player.sendMessage(ChatColor.GRAY+"/unarmed - Skill info"); + player.sendMessage(ChatColor.GRAY+"/herbalism - Skill info"); + player.sendMessage(ChatColor.GRAY+"/excavation - Skill info"); + player.sendMessage(ChatColor.GRAY+"/archery - Skill info"); + player.sendMessage(ChatColor.GRAY+"/swords - Skill info"); + player.sendMessage(ChatColor.GRAY+"/acrobatics - Skill info"); + player.sendMessage(ChatColor.GRAY+"/invite - Invite players to your party"); + player.sendMessage(ChatColor.GRAY+"/accept - Accept an invite"); + if(mcPermissions.getInstance().mmoedit(player)) + player.sendMessage(ChatColor.GRAY+"/mmoedit - Modify mcMMO skills of players/yourself"); + } + } + public void repairCheck(Player player, ItemStack is, Block block){ + if(block != null + && block.getTypeId() == 42 + && mcPermissions.getInstance().repair(player)){ + short durability = is.getDurability(); + if(player.getItemInHand().getDurability() > 0){ + /* + * ARMOR + */ + if(mcm.getInstance().isArmor(is) && block.getTypeId() == 42){ + if(mcm.getInstance().isDiamondArmor(is) && mcm.getInstance().hasDiamond(player)){ + mcm.getInstance().removeDiamond(player); + player.getItemInHand().setDurability(mcm.getInstance().getArmorRepairAmount(is, player)); + mcUsers.getProfile(player).skillUpRepair(1); + player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")"); + } else if (mcm.getInstance().isIronArmor(is) && mcm.getInstance().hasIron(player)){ + mcm.getInstance().removeIron(player); + player.getItemInHand().setDurability(mcm.getInstance().getArmorRepairAmount(is, player)); + mcUsers.getProfile(player).skillUpRepair(1); + player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")"); + } else { + needMoreVespeneGas(is, player); + } + } + /* + * TOOLS + */ + if(mcm.getInstance().isTools(is) && block.getTypeId() == 42){ + if(mcm.getInstance().isIronTools(is) && mcm.getInstance().hasIron(player)){ + is.setDurability(mcm.getInstance().getToolRepairAmount(is, durability, player)); + mcm.getInstance().removeIron(player); + mcUsers.getProfile(player).skillUpRepair(1); + player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")"); + } else if (mcm.getInstance().isDiamondTools(is) && mcm.getInstance().hasDiamond(player) && mcUsers.getProfile(player).getRepairInt() >= 50){ //Check if its diamond and the player has diamonds + is.setDurability(mcm.getInstance().getToolRepairAmount(is, durability, player)); + mcm.getInstance().removeDiamond(player); + mcUsers.getProfile(player).skillUpRepair(1); + player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")"); + } else { + needMoreVespeneGas(is, player); + } + } + + } else { + player.sendMessage("That is at full durability."); + } + player.updateInventory(); + } //end if block is iron block bracket + } + public void herbalismProcCheck(Block block, Player player){ + int type = block.getTypeId(); + Location loc = block.getLocation(); + ItemStack is = null; + Material mat = null; + if(!mcConfig.getInstance().isBlockWatched(block)){ + if(type == 39 || type == 40){ + mcUsers.getProfile(player).skillUpHerbalism(3); + player.sendMessage(ChatColor.YELLOW+"Herbalism skill increased by 3. Total ("+mcUsers.getProfile(player).getHerbalismInt()+")"); + } + if(type == 37 || type == 38){ + if(Math.random() * 10 > 8){ + mcUsers.getProfile(player).skillUpHerbalism(1); + player.sendMessage(ChatColor.YELLOW+"Herbalism skill increased by 1. Total ("+mcUsers.getProfile(player).getHerbalismInt()+")"); + } + } + if(type == 59 && block.getData() == (byte) 0x7){ + mat = Material.getMaterial(296); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + if(Math.random() * 100 > 80){ + mcUsers.getProfile(player).skillUpHerbalism(1); + player.sendMessage(ChatColor.YELLOW+"Herbalism skill increased by 1. Total ("+mcUsers.getProfile(player).getHerbalismInt()+")"); + } + if(mcUsers.getProfile(player).getHerbalismInt() >= 50 && mcUsers.getProfile(player).getHerbalismInt() < 150){ + if(Math.random() * 10 > 8) + loc.getWorld().dropItemNaturally(loc, is); + } + if(mcUsers.getProfile(player).getHerbalismInt() >= 150 && mcUsers.getProfile(player).getHerbalismInt() < 350 ){ + if(Math.random() * 10 > 6) + loc.getWorld().dropItemNaturally(loc, is); + } + if(mcUsers.getProfile(player).getHerbalismInt() >= 350 && mcUsers.getProfile(player).getHerbalismInt() < 500 ){ + if(Math.random() * 10 > 4) + loc.getWorld().dropItemNaturally(loc, is); + } + if(mcUsers.getProfile(player).getHerbalismInt() >= 500 && mcUsers.getProfile(player).getHerbalismInt() < 750 ){ + if(Math.random() * 10 > 2) + loc.getWorld().dropItemNaturally(loc, is); + } + } + } + } + public void excavationProcCheck(Block block, Player player){ + int type = block.getTypeId(); + Location loc = block.getLocation(); + ItemStack is = null; + Material mat = null; + if(type == 2 && mcUsers.getProfile(player).getExcavationInt() > 250){ + //CHANCE TO GET EGGS + if(mcUsers.getProfile(player).getExcavationInt() > 50 && Math.random() * 100 > 99){ + mat = Material.getMaterial(344); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + //CHANCE TO GET APPLES + if(Math.random() * 100 > 99){ + mat = Material.getMaterial(260); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + //DIRT SAND OR GRAVEL + if(type == 3 || type == 13 || type == 2 || type == 12){ + if(Math.random() * 100 > 95){ + mcUsers.getProfile(player).skillUpExcavation(1); + player.sendMessage(ChatColor.YELLOW+"Excavation skill increased by 1. Total ("+mcUsers.getProfile(player).getExcavationInt()+")"); + + } + if(mcUsers.getProfile(player).getExcavationInt() > 750){ + //CHANCE TO GET CAKE + if(Math.random() * 2000 > 1999){ + mat = Material.getMaterial(354); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + if(mcUsers.getProfile(player).getExcavationInt() > 150){ + //CHANCE TO GET MUSIC + if(Math.random() * 2000 > 1999){ + mat = Material.getMaterial(2256); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + + } + if(mcUsers.getProfile(player).getExcavationInt() > 350){ + //CHANCE TO GET DIAMOND + if(Math.random() * 500 > 499){ + mat = Material.getMaterial(264); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + if(mcUsers.getProfile(player).getExcavationInt() > 250){ + //CHANCE TO GET MUSIC + if(Math.random() * 2000 > 1999){ + mat = Material.getMaterial(2257); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + } + //SAND + if(type == 12){ + //CHANCE TO GET GLOWSTONE + if(mcUsers.getProfile(player).getExcavationInt() > 50 && Math.random() * 100 > 95){ + mat = Material.getMaterial(348); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + //CHANCE TO GET SLOWSAND + if(mcUsers.getProfile(player).getExcavationInt() > 650 && Math.random() * 200 > 199){ + mat = Material.getMaterial(88); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + //CHANCE TO GET DIAMOND + if(mcUsers.getProfile(player).getExcavationInt() > 500 && Math.random() * 500 > 499){ + mat = Material.getMaterial(264); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + //GRASS OR DIRT + if((type == 2 || type == 3) && mcUsers.getProfile(player).getExcavationInt() > 25){ + //CHANCE TO GET GLOWSTONE + if(Math.random() * 100 > 95){ + mat = Material.getMaterial(348); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + //GRAVEL + if(type == 13){ + //CHANCE TO GET NETHERRACK + if(mcUsers.getProfile(player).getExcavationInt() > 850 && Math.random() * 200 > 199){ + mat = Material.getMaterial(87); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + //CHANCE TO GET SULPHUR + if(mcUsers.getProfile(player).getExcavationInt() > 75){ + if(Math.random() * 10 > 9){ + mat = Material.getMaterial(289); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + if(mcUsers.getProfile(player).getExcavationInt() > 175){ + if(Math.random() * 10 > 6){ + mat = Material.getMaterial(352); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + //CHANCE TO GET COAL + if(mcUsers.getProfile(player).getExcavationInt() > 125){ + if(Math.random() * 100 > 99){ + mat = Material.getMaterial(263); + is = new ItemStack(mat, 1, (byte)0, (byte)0); + loc.getWorld().dropItemNaturally(loc, is); + } + } + } + } + public void woodCuttingProcCheck(Player player, Block block, Location loc){ + byte type = block.getData(); + Material mat = Material.getMaterial(block.getTypeId()); + byte damage = 0; + if(mcUsers.getProfile(player).getWoodCuttingint() > 1000){ + ItemStack item = new ItemStack(mat, 1, type, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 750){ + if((Math.random() * 10) > 2){ + ItemStack item = new ItemStack(mat, 1, type, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 300){ + if((Math.random() * 10) > 4){ + ItemStack item = new ItemStack(mat, 1, type, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 100){ + if((Math.random() * 10) > 6){ + ItemStack item = new ItemStack(mat, 1, type, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + if(mcUsers.getProfile(player).getWoodCuttingint() > 10){ + if((Math.random() * 10) > 8){ + ItemStack item = new ItemStack(mat, 1, type, damage); + block.getWorld().dropItemNaturally(loc, item); + return; + } + } + } + public void simulateSkillUp(Player player){ + if(mcUsers.getProfile(player).getwgatheramt() > 10){ + while(mcUsers.getProfile(player).getwgatheramt() > 10){ + mcUsers.getProfile(player).removewgather(10); + mcUsers.getProfile(player).skillUpWoodcutting(1); + player.sendMessage(ChatColor.YELLOW+"Wood Cutting skill increased by 1. Total ("+mcUsers.getProfile(player).getWoodCutting()+")"); + } + } + if(mcUsers.getProfile(player).getgatheramt() > 50){ + while(mcUsers.getProfile(player).getgatheramt() > 50){ + mcUsers.getProfile(player).removegather(50); + mcUsers.getProfile(player).skillUpMining(1); + player.sendMessage(ChatColor.YELLOW+"Mining skill increased by 1. Total ("+mcUsers.getProfile(player).getMining()+")"); + } + } + } + // IS TOOLS FUNCTION + public boolean isArmor(ItemStack is){ + if(is.getTypeId() == 306 || is.getTypeId() == 307 ||is.getTypeId() == 308 ||is.getTypeId() == 309 || + is.getTypeId() == 310 ||is.getTypeId() == 311 ||is.getTypeId() == 312 ||is.getTypeId() == 313){ + return true; + } else { + return false; + } + } + public boolean isIronArmor(ItemStack is){ + if(is.getTypeId() == 306 || is.getTypeId() == 307 || is.getTypeId() == 308 || is.getTypeId() == 309) + { + return true; + } else { + return false; + } + } + public boolean isDiamondArmor(ItemStack is){ + if(is.getTypeId() == 310 || is.getTypeId() == 311 || is.getTypeId() == 312 || is.getTypeId() == 313) + { + return true; + } else { + return false; + } + } + public boolean isTools(ItemStack is){ + if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292 ||//IRON + is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293) //DIAMOND + { + return true; + } else { + return false; + } + } + + public boolean isIronTools(ItemStack is){ + if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292) + { + return true; + } else { + return false; + } + } + + public boolean isDiamondTools(ItemStack is){ + if(is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293) + { + return true; + } else { + return false; + } + } + public void removeIron(Player player){ + ItemStack[] inventory = player.getInventory().getContents(); + for(ItemStack x : inventory){ + if(x.getTypeId() == 265){ + if(x.getAmount() == 1){ + x.setTypeId(0); + x.setAmount(0); + player.getInventory().setContents(inventory); + } else{ + x.setAmount(x.getAmount() - 1); + player.getInventory().setContents(inventory); + } + return; + } + } + } + public void removeDiamond(Player player){ + ItemStack[] inventory = player.getInventory().getContents(); + for(ItemStack x : inventory){ + if(x.getTypeId() == 264){ + if(x.getAmount() == 1){ + x.setTypeId(0); + x.setAmount(0); + player.getInventory().setContents(inventory); + } else{ + x.setAmount(x.getAmount() - 1); + player.getInventory().setContents(inventory); + } + return; + } + } + } + public boolean hasDiamond(Player player){ + ItemStack[] inventory = player.getInventory().getContents(); + for(ItemStack x : inventory){ + if(x.getTypeId() == 264){ + return true; + } + } + return false; + } + public boolean hasIron(Player player){ + ItemStack[] inventory = player.getInventory().getContents(); + for(ItemStack x : inventory){ + if(x.getTypeId() == 265){ + return true; + } + } + return false; + } +} diff --git a/mcMMO/plugin.yml b/mcMMO/plugin.yml index e01966378..095a48459 100644 --- a/mcMMO/plugin.yml +++ b/mcMMO/plugin.yml @@ -1,3 +1,3 @@ name: mcMMO -main: com.bukkit.nossr50.mcMMO.mcMMO -version: 0.5.15 \ No newline at end of file +main: com.gmail.nossr50.mcMMO +version: 0.5.17 \ No newline at end of file