From 2788eb1be2666d752670487f7d74da540ddc5190 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 26 Feb 2011 13:36:35 -0800 Subject: [PATCH] All changes up to 0.8.3 --- mcMMO/Changelog.txt | 13 + mcMMO/com/gmail/nossr50/mcConfig.java | 22 +- mcMMO/com/gmail/nossr50/mcEntityListener.java | 11 + mcMMO/com/gmail/nossr50/mcLoadProperties.java | 60 ++-- mcMMO/com/gmail/nossr50/mcMMO.java | 1 + mcMMO/com/gmail/nossr50/mcPermissions.java | 2 +- mcMMO/com/gmail/nossr50/mcPlayerListener.java | 1 + mcMMO/com/gmail/nossr50/mcTimer.java | 124 ++------ mcMMO/com/gmail/nossr50/mcUsers.java | 20 +- mcMMO/com/gmail/nossr50/mcm.java | 284 ++++++++++++++---- mcMMO/plugin.yml | 2 +- 11 files changed, 335 insertions(+), 205 deletions(-) diff --git a/mcMMO/Changelog.txt b/mcMMO/Changelog.txt index 201ea91c0..49574ba49 100644 --- a/mcMMO/Changelog.txt +++ b/mcMMO/Changelog.txt @@ -1,5 +1,18 @@ Changelog: #Versions without changelogs probably had very small misc fixes, like tweaks to the source code# +Version 0.8.3 + Modified the timer intervals (from 1 second to 2) + All skills now have an individual modifier (Set by default to 2) + There is now a global XP modifier (Set by default to 1) + Herbalism now correctly follows its skill curve + Unarmed no longer gives experience for harming other players + Players can no longer exploit mob spawners for experience +Version 0.8.2 + Fixed Concurrent Modification Exception + Fixed some incorrect skill descriptions + First tier of HP Regeneration is now available from the start + Fixed bleed proc rate for very high skill levels + Changed regeneration permissions to 'mcmmo.regeneration' Version 0.8 Archery skill now lets players recover arrows from downed foes Health regenerates based on power level diff --git a/mcMMO/com/gmail/nossr50/mcConfig.java b/mcMMO/com/gmail/nossr50/mcConfig.java index b1ee3542f..8c170ab92 100644 --- a/mcMMO/com/gmail/nossr50/mcConfig.java +++ b/mcMMO/com/gmail/nossr50/mcConfig.java @@ -21,25 +21,24 @@ public class mcConfig { static ArrayList blockWatchList = new ArrayList(); static ArrayList partyChatList = new ArrayList(); HashMap arrowTracker = new HashMap(); - HashMap bleedTracker = new HashMap(); + static ArrayList bleedTracker = new ArrayList(); + static ArrayList mobSpawnTracker = 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 void addBleedTrack(Entity entity) {bleedTracker.add(entity);} + public void addMobSpawnTrack(Entity entity) {mobSpawnTracker.add(entity);} + public ArrayList getBleedTracked() {return bleedTracker;} public void addArrowTrack(Entity entity, Integer arrowcount) {arrowTracker.put(entity, arrowcount);} - public void addBleedTrack(Entity entity, Integer duration) {bleedTracker.put(entity, duration);} public Integer getArrowCount(Entity entity) {return arrowTracker.get(entity);} - public Integer getBleedCount(Entity entity) {return bleedTracker.get(entity);} public void removeBleedTrack(Entity entity){ bleedTracker.remove(entity); } public void setBleedCount(Entity entity, Integer newvalue){ - bleedTracker.put(entity, newvalue); - } - public void removeBleedCount(Entity entity, Integer newvalue) { - bleedTracker.put(entity, bleedTracker.get(entity) - newvalue); + bleedTracker.add(entity); } public void addArrowCount(Entity entity, Integer newvalue) { arrowTracker.put(entity, arrowTracker.get(entity) + newvalue); @@ -51,8 +50,15 @@ public class mcConfig { return false; } } + public boolean isMobSpawnTracked(Entity entity) { + if(mobSpawnTracker.contains(entity)){ + return true; + } else { + return false; + } + } public boolean isBleedTracked(Entity entity) { - if(bleedTracker.containsKey(entity)){ + if(bleedTracker.contains(entity)){ return true; } else { return false; diff --git a/mcMMO/com/gmail/nossr50/mcEntityListener.java b/mcMMO/com/gmail/nossr50/mcEntityListener.java index 41d108d90..aefb9b7c3 100644 --- a/mcMMO/com/gmail/nossr50/mcEntityListener.java +++ b/mcMMO/com/gmail/nossr50/mcEntityListener.java @@ -8,12 +8,15 @@ import org.bukkit.entity.Animals; import org.bukkit.entity.Creature; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; +import org.bukkit.entity.MobType; 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.Event; +import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByProjectileEvent; @@ -36,6 +39,13 @@ public class mcEntityListener extends EntityListener { return false; } } + public void onCreatureSpawn(CreatureSpawnEvent event) { + Location loc = event.getLocation(); + Entity spawnee = event.getEntity(); + if(mcm.getInstance().isBlockAround(loc, 5, 52)){ + mcConfig.getInstance().addMobSpawnTrack(spawnee); + } + } public void onEntityDamage(EntityDamageEvent event) { Entity x = event.getEntity(); DamageCause type = event.getCause(); @@ -106,6 +116,7 @@ public class mcEntityListener extends EntityListener { /* * 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. */ + if(mcm.getInstance().isPvpEnabled()) mcm.getInstance().playerVersusPlayerChecks(e, attacker, eventb, plugin); /* * Player versus Animals checks, these checks handle any skill modifiers or procs diff --git a/mcMMO/com/gmail/nossr50/mcLoadProperties.java b/mcMMO/com/gmail/nossr50/mcLoadProperties.java index 7ecc063e8..d44825217 100644 --- a/mcMMO/com/gmail/nossr50/mcLoadProperties.java +++ b/mcMMO/com/gmail/nossr50/mcLoadProperties.java @@ -3,7 +3,7 @@ package com.gmail.nossr50; public class mcLoadProperties { public static Boolean pvp, eggs, apples, myspawnclearsinventory, cake, music, diamond, glowstone, slowsand, sulphur, netherrack, bones, coal, clay, anvilmessages; public static String mcmmo, mcc, stats, mmoedit, ptp, party, myspawn, setmyspawn, whois, invite, accept, clearmyspawn; - public static int xpmodifier; + public static int globalxpmodifier, miningxpmodifier, repairxpmodifier, woodcuttingxpmodifier, unarmedxpmodifier, herbalismxpmodifier, excavationxpmodifier, archeryxpmodifier, swordsxpmodifier, axesxpmodifier, acrobaticsxpmodifier; public static void loadMain(){ String propertiesFile = mcMMO.maindirectory + "mcmmo.properties"; @@ -13,11 +13,21 @@ public class mcLoadProperties { /* * EXPERIENCE RATE MODIFIER */ - xpmodifier = properties.getInteger("xpmodifier", 2); + globalxpmodifier = properties.getInteger("globalxpmodifier", 1); + miningxpmodifier = properties.getInteger("miningxpmodifier", 2); + repairxpmodifier = properties.getInteger("repairxpmodifier", 2); + woodcuttingxpmodifier = properties.getInteger("woodcuttingxpmodifier", 2); + unarmedxpmodifier = properties.getInteger("unarmedxpmodifier", 2); + herbalismxpmodifier = properties.getInteger("herbalismxpmodifier", 2); + excavationxpmodifier = properties.getInteger("excavationxpmodifier", 2); + archeryxpmodifier = properties.getInteger("archeryxpmodifier", 2); + swordsxpmodifier = properties.getInteger("swordsxpmodifier", 2); + axesxpmodifier = properties.getInteger("axesxpmodifier", 2); + acrobaticsxpmodifier = properties.getInteger("acrobaticsxpmodifier", 2); /* * TOGGLE CLAY */ - clay = properties.getBoolean("clay", true); + clay = properties.getBoolean("graveltoclay", true); /* * ANVIL MESSAGES */ @@ -26,32 +36,32 @@ public class mcLoadProperties { * EXCAVATION LOOT TOGGLES */ myspawnclearsinventory = properties.getBoolean("myspawnclearsinventory", true); - glowstone = properties.getBoolean("glowstone", true); + glowstone = properties.getBoolean("canexcavateglowstone", true); pvp = properties.getBoolean("pvp", true); - eggs = properties.getBoolean("eggs", true); - apples = properties.getBoolean("apples", true); - cake = properties.getBoolean("cake", true); - music = properties.getBoolean("music", true); - diamond = properties.getBoolean("diamond", true); - slowsand = properties.getBoolean("slowsand", true); - sulphur = properties.getBoolean("sulphur", true); - netherrack = properties.getBoolean("netherrack", true); - bones = properties.getBoolean("bones", true); + eggs = properties.getBoolean("canexcavateeggs", true); + apples = properties.getBoolean("canexcavateapples", true); + cake = properties.getBoolean("canexcavatecake", true); + music = properties.getBoolean("canexcavatemusic", true); + diamond = properties.getBoolean("canexcavatediamond", true); + slowsand = properties.getBoolean("canexcavateslowsand", true); + sulphur = properties.getBoolean("canexcavatesulphur", true); + netherrack = properties.getBoolean("canexcavatenetherrack", true); + bones = properties.getBoolean("canexcavatebones", true); /* * CUSTOM COMMANDS */ - mcmmo = properties.getString("mcmmo", "mcmmo"); - mcc = properties.getString("mcc", "mcc"); - stats = properties.getString("stats", "stats"); - mmoedit = properties.getString("mmoedit", "mmoedit"); - ptp = properties.getString("ptp", "ptp"); - party = properties.getString("party", "party"); - myspawn = properties.getString("myspawn", "myspawn"); - setmyspawn = properties.getString("setmyspawn", "setmyspawn"); - whois = properties.getString("whois", "whois"); - invite = properties.getString("invite", "invite"); - accept = properties.getString("accept", "accept"); - clearmyspawn = properties.getString("clearmyspawn", "clearmyspawn"); + mcmmo = properties.getString("/mcmmo", "mcmmo"); + mcc = properties.getString("/mcc", "mcc"); + stats = properties.getString("/stats", "stats"); + mmoedit = properties.getString("/mmoedit", "mmoedit"); + ptp = properties.getString("/ptp", "ptp"); + party = properties.getString("/party", "party"); + myspawn = properties.getString("/myspawn", "myspawn"); + setmyspawn = properties.getString("/setmyspawn", "setmyspawn"); + whois = properties.getString("/whois", "whois"); + invite = properties.getString("/invite", "invite"); + accept = properties.getString("/accept", "accept"); + clearmyspawn = properties.getString("/clearmyspawn", "clearmyspawn"); properties.save("==McMMO Configuration==\r\nYou can turn off excavation loot tables by turning the option to false\r\nYou can customize mcMMOs command names by modifying them here as well\r\nThis is an early version of the configuration file, eventually you'll be able to customize messages from mcMMO and XP gains"); //herp derp } diff --git a/mcMMO/com/gmail/nossr50/mcMMO.java b/mcMMO/com/gmail/nossr50/mcMMO.java index 794c2c91f..c448b1707 100644 --- a/mcMMO/com/gmail/nossr50/mcMMO.java +++ b/mcMMO/com/gmail/nossr50/mcMMO.java @@ -107,6 +107,7 @@ public class mcMMO extends JavaPlugin { 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_DAMAGED, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this); //Displays a message when plugin is loaded PluginDescriptionFile pdfFile = this.getDescription(); mcPermissions.initialize(getServer()); diff --git a/mcMMO/com/gmail/nossr50/mcPermissions.java b/mcMMO/com/gmail/nossr50/mcPermissions.java index 1273123a8..9f495a24d 100644 --- a/mcMMO/com/gmail/nossr50/mcPermissions.java +++ b/mcMMO/com/gmail/nossr50/mcPermissions.java @@ -39,7 +39,7 @@ public class mcPermissions { } public boolean regeneration(Player player){ if (permissionsEnabled) { - return permission(player, "mcmmo.skills.regeneration"); + return permission(player, "mcmmo.regeneration"); } else { return true; } diff --git a/mcMMO/com/gmail/nossr50/mcPlayerListener.java b/mcMMO/com/gmail/nossr50/mcPlayerListener.java index 3325cf472..021f646c9 100644 --- a/mcMMO/com/gmail/nossr50/mcPlayerListener.java +++ b/mcMMO/com/gmail/nossr50/mcPlayerListener.java @@ -32,6 +32,7 @@ public class mcPlayerListener extends PlayerListener { Player player = event.getPlayer(); Location mySpawn = mcUsers.getProfile(player).getMySpawn(player); if(mcUsers.getProfile(player).getMySpawnWorld() != null && !mcUsers.getProfile(player).getMySpawnWorld().equals("")){ + if(plugin.getServer().getWorld(mcUsers.getProfile(player).getMySpawnWorld()) != null) mySpawn.setWorld(plugin.getServer().getWorld(mcUsers.getProfile(player).getMySpawnWorld())); } if(mcPermissions.getInstance().mySpawn(player)){ diff --git a/mcMMO/com/gmail/nossr50/mcTimer.java b/mcMMO/com/gmail/nossr50/mcTimer.java index 7dff23964..d7ad120bc 100644 --- a/mcMMO/com/gmail/nossr50/mcTimer.java +++ b/mcMMO/com/gmail/nossr50/mcTimer.java @@ -1,4 +1,5 @@ package com.gmail.nossr50; +import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -13,102 +14,20 @@ public class mcTimer extends TimerTask{ public mcTimer(final mcMMO plugin) { this.plugin = plugin; - } - public Integer calculateHealth(Integer health, Integer newvalue){ - if((health + newvalue) > 20){ - return 20; - } else { - return health+newvalue; - } - } - public Integer calculateMinusHealth(Integer health, Integer newvalue){ - if((health - newvalue) < 1){ - return 0; - } else { - return health-newvalue; - } - } - public Integer getHealth(Entity entity){ - if(entity instanceof Monster){ - Monster monster = (Monster)entity; - return monster.getHealth(); - } else if (entity instanceof Animals){ - Animals animals = (Animals)entity; - return animals.getHealth(); - } else if (entity instanceof Player){ - Player player = (Player)entity; - return player.getHealth(); - } else { - return 0; - } } public void run() { - for(World world : plugin.getServer().getWorlds()){ - for(Entity entity : world.getEntities()){ - if(entity == null) - return; - /* - if(!mcConfig.getInstance().isBleedTracked(entity)) - return; - */ - if(getHealth(entity) <= 0) - return; - /* - if(entity instanceof Animals){ - Animals animals = (Animals)entity; - if(animals.getHealth() >= 1){ - animals.setHealth(calculateMinusHealth(animals.getHealth(), 1)); - if(animals.getHealth() <= 0){ - mcm.getInstance().simulateNaturalDrops(entity); - } - } - } - if(entity instanceof Monster){ - Monster monster = (Monster)entity; - if(monster.getHealth() >= 1){ - monster.setHealth(calculateMinusHealth(monster.getHealth(), 1)); - if(monster.getHealth() <= 0){ - mcm.getInstance().simulateNaturalDrops(entity); - } - } - } - */ - if(entity instanceof Player){ - Player player = (Player)entity; - if(player.getHealth() >= 1 && mcUsers.getProfile(player).getBleedTicks() >= 1){ - player.setHealth(calculateMinusHealth(player.getHealth(), 1)); - player.sendMessage(ChatColor.RED+"**BLEED**"); - if(player.getHealth() <= 0){ - mcUsers.getProfile(player).setBleedTicks(0); - for(ItemStack items : player.getInventory().getContents()){ - if(items.getTypeId() != 0) - player.getLocation().getWorld().dropItemNaturally(player.getLocation(), items); - } - } - if(mcUsers.getProfile(player).getBleedTicks() >= 1){ - mcUsers.getProfile(player).setBleedTicks(mcUsers.getProfile(player).getBleedTicks() - 1); - } - } - } - } + if(thecount == 5 || thecount == 10 || thecount == 15 || thecount == 20){ + for(Player player : plugin.getServer().getOnlinePlayers()){ + if(player != null && + player.getHealth() > 0 && player.getHealth() < 20 + && mcUsers.getProfile(player).getPowerLevel() >= 1000 + && mcUsers.getProfile(player).getRecentlyHurt() == 0 + && mcPermissions.getInstance().regeneration(player)){ + player.setHealth(mcm.getInstance().calculateHealth(player.getHealth(), 1)); + } + } } - if(thecount == 10 || thecount == 20 || thecount == 30 || thecount == 40){ - for(Player player : plugin.getServer().getOnlinePlayers()){ - if(player != null && mcUsers.getProfile(player).getRecentlyHurt() >= 1) - mcUsers.getProfile(player).decreaseLastHurt(); - } - } - - for(Player player : plugin.getServer().getOnlinePlayers()){ - if(player != null && - player.getHealth() > 0 && player.getHealth() < 20 - && mcUsers.getProfile(player).getPowerLevel() >= 1000 - && mcUsers.getProfile(player).getRecentlyHurt() == 0 - && mcPermissions.getInstance().regeneration(player)){ - player.setHealth(calculateHealth(player.getHealth(), 1)); - } - } - if(thecount == 20 || thecount == 40){ + if(thecount == 10 || thecount == 20){ for(Player player : plugin.getServer().getOnlinePlayers()){ if(player != null && player.getHealth() > 0 && player.getHealth() < 20 @@ -116,29 +35,36 @@ public class mcTimer extends TimerTask{ && mcUsers.getProfile(player).getPowerLevel() < 1000 && mcUsers.getProfile(player).getRecentlyHurt() == 0 && mcPermissions.getInstance().regeneration(player)){ - player.setHealth(calculateHealth(player.getHealth(), 1)); + player.setHealth(mcm.getInstance().calculateHealth(player.getHealth(), 1)); } } } - if(thecount == 40){ + if(thecount == 20){ for(Player player : plugin.getServer().getOnlinePlayers()){ if(player != null && - player.getHealth() > 0 && player.getHealth() < 20 - && mcUsers.getProfile(player).getPowerLevel() >= 100 + player.getHealth() > 0 && player.getHealth() < 20 && mcUsers.getProfile(player).getPowerLevel() < 500 && mcUsers.getProfile(player).getRecentlyHurt() == 0 && mcPermissions.getInstance().regeneration(player)){ - player.setHealth(calculateHealth(player.getHealth(), 1)); + player.setHealth(mcm.getInstance().calculateHealth(player.getHealth(), 1)); } } } /* * RESET THE COUNT */ - if(thecount < 40){ + if(thecount < 20){ thecount++; } else { thecount = 1; } + for(Player player : plugin.getServer().getOnlinePlayers()){ + if(player == null) + continue; + if(player != null + && mcUsers.getProfile(player).getRecentlyHurt() >= 1) + mcUsers.getProfile(player).decreaseLastHurt(); + } + mcm.getInstance().bleedSimulate(plugin); } } diff --git a/mcMMO/com/gmail/nossr50/mcUsers.java b/mcMMO/com/gmail/nossr50/mcUsers.java index dcb249422..324f3b441 100644 --- a/mcMMO/com/gmail/nossr50/mcUsers.java +++ b/mcMMO/com/gmail/nossr50/mcUsers.java @@ -1163,34 +1163,34 @@ class PlayerList } public Integer getXpToLevel(String skillname){ if(skillname.equals("mining")){ - return (getMiningInt() + 50) * mcLoadProperties.xpmodifier; + return ((getMiningInt() + 50) * mcLoadProperties.miningxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("woodcutting")){ - return (getWoodCuttingInt() + 50) * mcLoadProperties.xpmodifier; + return ((getWoodCuttingInt() + 50) * mcLoadProperties.woodcuttingxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("repair")){ - return (getRepairInt() + 50) * mcLoadProperties.xpmodifier; + return ((getRepairInt() + 50) * mcLoadProperties.repairxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("herbalism")){ - return (getHerbalismInt() + 50) * mcLoadProperties.xpmodifier; + return ((getHerbalismInt() + 50) * mcLoadProperties.herbalismxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("acrobatics")){ - return (getAcrobaticsInt() + 50) * mcLoadProperties.xpmodifier; + return ((getAcrobaticsInt() + 50) * mcLoadProperties.acrobaticsxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("swords")){ - return (getSwordsInt() + 50) * mcLoadProperties.xpmodifier; + return ((getSwordsInt() + 50) * mcLoadProperties.swordsxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("archery")){ - return (getArcheryInt() + 50) * mcLoadProperties.xpmodifier; + return ((getArcheryInt() + 50) * mcLoadProperties.archeryxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("unarmed")){ - return (getUnarmedInt() + 50) * mcLoadProperties.xpmodifier; + return ((getUnarmedInt() + 50) * mcLoadProperties.unarmedxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("excavation")){ - return (getExcavationInt() + 50) * mcLoadProperties.xpmodifier; + return ((getExcavationInt() + 50) * mcLoadProperties.excavationxpmodifier) * mcLoadProperties.globalxpmodifier; } if(skillname.equals("axes")){ - return (getAxesInt() + 50) * mcLoadProperties.xpmodifier; + return ((getAxesInt() + 50) * mcLoadProperties.axesxpmodifier) * mcLoadProperties.globalxpmodifier; } else { return 0; } diff --git a/mcMMO/com/gmail/nossr50/mcm.java b/mcMMO/com/gmail/nossr50/mcm.java index 0ff4654d1..ea8facbd3 100644 --- a/mcMMO/com/gmail/nossr50/mcm.java +++ b/mcMMO/com/gmail/nossr50/mcm.java @@ -1,8 +1,19 @@ package com.gmail.nossr50; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.server.Packet38EntityStatus; + 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.Animals; import org.bukkit.entity.Item; @@ -23,18 +34,94 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; +import org.bukkit.craftbukkit.entity.CraftPlayer; public class mcm { /* * I'm storing my functions/methods in here in an unorganized manner. Spheal with it. */ + private static mcMMO plugin; + public mcm(mcMMO instance) { + plugin = instance; + } private static volatile mcm instance; public static mcm getInstance() { if (instance == null) { - instance = new mcm(); + instance = new mcm(plugin); } return instance; } + public static double getDistance(Location loca, Location locb) + { + return Math.sqrt(Math.pow(loca.getX() - locb.getX(), 2) + Math.pow(loca.getY() - locb.getY(), 2) + + Math.pow(loca.getZ() - locb.getZ(), 2)); + } + public boolean isBlockAround(Location loc, Integer radius, Integer typeid){ + Block blockx = loc.getBlock(); + int ox = blockx.getX(); + int oy = blockx.getY(); + int oz = blockx.getZ(); + for (int cx = -radius; cx <= radius; cx++) { + for (int cy = -radius; cy <= radius; cy++) { + for (int cz = -radius; cz <= radius; cz++) { + Block block = loc.getWorld().getBlockAt(ox + cx, oy + cy, oz + cz); + //If block is block + if (block.getTypeId() == typeid) { + return true; + } + } + } + } + return false; + } + public boolean isPvpEnabled(){ + String propertyName = "pvp"; + FileReader fr = null; + try { + fr = new FileReader("server.properties"); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + BufferedReader br = new BufferedReader(fr); + String property; + String s = null; + try { + while((s=br.readLine()) .indexOf(propertyName)==-1); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + property = s.split("=")[1]; + try { + fr.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(property.toLowerCase().equals("true")){ + return true; + } else { + return false; + } + } + + public void sendDamagedLookPackets(Entity damaged){ + for(Player x : plugin.getServer().getOnlinePlayers()){ + if(x != null && damaged != null){ + CraftPlayer cp = (CraftPlayer)x; + if(x.getEntityId() != damaged.getEntityId()) + cp.getHandle().a.b(new Packet38EntityStatus(damaged.getEntityId(), (byte)2)); + } + } + } + public void sendDeathLookPackets(Entity damaged){ + for(Player x : plugin.getServer().getOnlinePlayers()){ + CraftPlayer cp = (CraftPlayer)x; + if(x.getEntityId() != damaged.getEntityId()) + cp.getHandle().a.b(new Packet38EntityStatus(damaged.getEntityId(), (byte)3)); + } + } public boolean inSameParty(Player playera, Player playerb){ if(mcUsers.getProfile(playera).getParty().equals(mcUsers.getProfile(playerb).getParty())){ return true; @@ -58,6 +145,84 @@ public class mcm { } } } + public Integer calculateHealth(Integer health, Integer newvalue){ + if((health + newvalue) > 20){ + return 20; + } else { + return health+newvalue; + } + } + public Integer calculateMinusHealth(Integer health, Integer newvalue){ + if((health - newvalue) < 1){ + return 0; + } else { + return health-newvalue; + } + } + public Integer getHealth(Entity entity){ + if(entity instanceof Monster){ + Monster monster = (Monster)entity; + return monster.getHealth(); + } else if (entity instanceof Animals){ + Animals animals = (Animals)entity; + return animals.getHealth(); + } else if (entity instanceof Player){ + Player player = (Player)entity; + return player.getHealth(); + } else { + return 0; + } + } + public void bleedSimulate(Plugin plugin){ + for(Entity x : mcConfig.getInstance().getBleedTracked()){ + if(x == null) + continue; + if(!mcConfig.getInstance().isBleedTracked(x)) + continue; + if(getHealth(x) <= 0) + continue; + if(x instanceof Animals){ + Animals animals = (Animals)x; + if(animals.getHealth() >= 1){ + animals.setHealth(calculateMinusHealth(animals.getHealth(), 2)); + mcm.getInstance().sendDamagedLookPackets(x); + } + if(animals.getHealth() <= 0){ + mcm.getInstance().simulateNaturalDrops(x); + } + } + + if(x instanceof Monster){ + Monster monster = (Monster)x; + if(monster.getHealth() >= 1){ + mcm.getInstance().sendDamagedLookPackets(x); + monster.setHealth(calculateMinusHealth(monster.getHealth(), 2)); + } + if(monster.getHealth() <= 0){ + mcm.getInstance().simulateNaturalDrops(x); + } + } + + if(x instanceof Player){ + Player player = (Player)x; + if(player.getHealth() >= 1 && mcUsers.getProfile(player).getBleedTicks() >= 1){ + player.setHealth(calculateMinusHealth(player.getHealth(), 1)); + mcm.getInstance().sendDamagedLookPackets(x); + player.sendMessage(ChatColor.RED+"**BLEED**"); + if(player.getHealth() <= 0){ + mcUsers.getProfile(player).setBleedTicks(0); + for(ItemStack items : player.getInventory().getContents()){ + if(items.getTypeId() != 0) + player.getLocation().getWorld().dropItemNaturally(player.getLocation(), items); + } + } + if(mcUsers.getProfile(player).getBleedTicks() >= 1){ + mcUsers.getProfile(player).setBleedTicks(mcUsers.getProfile(player).getBleedTicks() - 1); + } + } + } + } + } public boolean isSkill(String skillname){ if(skillname.equals("mining")){ return true; @@ -172,6 +337,7 @@ public class mcm { /* * TRACK ARROWS USED AGAINST THE ENTITY */ + int healthbefore = defender.getHealth(); 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) @@ -182,10 +348,13 @@ public class mcm { 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 it only would've died from mcMMO damage modifiers + if(defender.getHealth() <= 0 && healthbefore - event.getDamage() >= 1){ + mcm.getInstance().sendDeathLookPackets(defender); simulateNaturalDrops(defender); } //XP + if(!mcConfig.getInstance().isMobSpawnTracked(x)){ if(x instanceof Creeper) mcUsers.getProfile(attacker).addArcheryGather(10); if(x instanceof Spider) @@ -196,6 +365,7 @@ public class mcm { mcUsers.getProfile(attacker).addArcheryGather(3); if(x instanceof PigZombie) mcUsers.getProfile(attacker).addArcheryGather(7); + } if(mcUsers.getProfile(attacker).getArcheryGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("archery")){ int skillups = 0; while(mcUsers.getProfile(attacker).getArcheryGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("archery")){ @@ -211,6 +381,7 @@ public class mcm { */ if(x instanceof Animals){ Animals defender = (Animals)x; + int healthbefore = defender.getHealth(); 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) @@ -221,14 +392,18 @@ public class mcm { 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); + //If it only would've died from mcMMO damage modifiers + if(defender.getHealth() <= 0 && healthbefore - event.getDamage() >= 1){ + mcm.getInstance().sendDeathLookPackets(defender); + simulateNaturalDrops(defender); } + } /* * Defender is Squid */ if(x instanceof Squid){ Squid defender = (Squid)x; + int healthbefore = defender.getHealth(); 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) @@ -239,9 +414,12 @@ public class mcm { 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); + //If it only would've died from mcMMO damage modifiers + if(defender.getHealth() <= 0 && healthbefore - event.getDamage() >= 1){ + mcm.getInstance().sendDeathLookPackets(defender); + simulateNaturalDrops(defender); } + } /* * Attacker is Player */ @@ -283,6 +461,7 @@ public class mcm { attacker.sendMessage("Target was "+ChatColor.DARK_RED+"Dazed"); } } + int healthbefore = defender.getHealth(); 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) @@ -293,18 +472,11 @@ public class mcm { 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 it only would've died from mcMMO damage modifiers + if(defender.getHealth() <= 0 && healthbefore - event.getDamage() >= 1){ + mcm.getInstance().sendDeathLookPackets(defender); + simulateNaturalDrops(defender); + } if(mcUsers.getProfile(defender).isDead()) return; @@ -752,7 +924,7 @@ public class mcm { if(mcm.getInstance().isSwords(attacker.getItemInHand()) && !mcConfig.getInstance().isBleedTracked(x)){ if(mcUsers.getProfile(attacker).getSwordsInt() >= 50 && mcUsers.getProfile(attacker).getSwordsInt() < 200){ if(Math.random() * 10 > 8){ - mcConfig.getInstance().addBleedTrack(x, 4); + mcConfig.getInstance().addBleedTrack(x); if(x instanceof Player){ Player target = (Player)x; mcUsers.getProfile(target).setBleedTicks(4); @@ -761,7 +933,7 @@ public class mcm { } } else if(mcUsers.getProfile(attacker).getSwordsInt() >= 200 && mcUsers.getProfile(attacker).getSwordsInt() < 600){ if(Math.random() * 10 > 6){ - mcConfig.getInstance().addBleedTrack(x, 4); + mcConfig.getInstance().addBleedTrack(x); if(x instanceof Player){ Player target = (Player)x; mcUsers.getProfile(target).setBleedTicks(4); @@ -770,7 +942,7 @@ public class mcm { } } else if(mcUsers.getProfile(attacker).getSwordsInt() >= 600 && mcUsers.getProfile(attacker).getSwordsInt() < 900){ if(Math.random() * 10 > 4){ - mcConfig.getInstance().addBleedTrack(x, 6); + mcConfig.getInstance().addBleedTrack(x); if(x instanceof Player){ Player target = (Player)x; mcUsers.getProfile(target).setBleedTicks(6); @@ -778,8 +950,8 @@ public class mcm { attacker.sendMessage(ChatColor.RED+"**Your target is bleeding**"); } } else if(mcUsers.getProfile(attacker).getSwordsInt() >= 900){ - if(Math.random() * 100 > 75){ - mcConfig.getInstance().addBleedTrack(x, 6); + if(Math.random() * 100 > 25){ + mcConfig.getInstance().addBleedTrack(x); if(x instanceof Player){ Player target = (Player)x; mcUsers.getProfile(target).setBleedTicks(6); @@ -810,6 +982,7 @@ public class mcm { if(!mcConfig.getInstance().isBleedTracked(x)){ bleedCheck(attacker, x); } + int healthbefore = defender.getHealth(); if(mcPermissions.getInstance().unarmed(attacker) && attacker.getItemInHand().getTypeId() == 0){ //DMG MODIFIER if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){ @@ -831,13 +1004,6 @@ public class mcm { } 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(); @@ -854,36 +1020,25 @@ public class mcm { } } } - /* - * 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); - } - */ + } + /* + * 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 + //If it only would've died from mcMMO damage modifiers + if(defender.getHealth() <= 0 && healthbefore - event.getDamage() >= 1){ + mcm.getInstance().sendDeathLookPackets(defender); + simulateNaturalDrops(defender); } - return; + for(ItemStack herp : defender.getInventory().getContents()){ + if(herp != null && herp.getTypeId() != 0) + defender.getLocation().getWorld().dropItemNaturally(defender.getLocation(), herp); + } } 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); } @@ -1024,6 +1179,7 @@ public class mcm { if(isSwords(attacker.getItemInHand()) && defender.getHealth() > 0 && mcPermissions.getInstance().swords(attacker)){ + if(!mcConfig.getInstance().isMobSpawnTracked(x)){ if(x instanceof Creeper) mcUsers.getProfile(attacker).addSwordsGather(10); if(x instanceof Spider) @@ -1034,6 +1190,7 @@ public class mcm { mcUsers.getProfile(attacker).addSwordsGather(3); if(x instanceof PigZombie) mcUsers.getProfile(attacker).addSwordsGather(7); + } if(mcUsers.getProfile(attacker).getSwordsGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("swords")){ int skillups = 0; while(mcUsers.getProfile(attacker).getSwordsGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("swords")){ @@ -1047,6 +1204,7 @@ public class mcm { if(isAxes(attacker.getItemInHand()) && defender.getHealth() > 0 && mcPermissions.getInstance().axes(attacker)){ + if(!mcConfig.getInstance().isMobSpawnTracked(x)){ mcUsers.getProfile(attacker).addAxesGather(1); if(x instanceof Creeper) mcUsers.getProfile(attacker).addAxesGather(10); @@ -1058,6 +1216,7 @@ public class mcm { mcUsers.getProfile(attacker).addAxesGather(3); if(x instanceof PigZombie) mcUsers.getProfile(attacker).addAxesGather(7); + } if(mcUsers.getProfile(attacker).getAxesGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("axes")){ int skillups = 0; while(mcUsers.getProfile(attacker).getAxesGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("axes")){ @@ -1102,6 +1261,7 @@ public class mcm { defender.setHealth(calculateDamage(defender, 8)); } //XP + if(!mcConfig.getInstance().isMobSpawnTracked(x)){ if(x instanceof Creeper) mcUsers.getProfile(attacker).addUnarmedGather(20); if(x instanceof Spider) @@ -1112,6 +1272,7 @@ public class mcm { mcUsers.getProfile(attacker).addUnarmedGather(5); if(x instanceof PigZombie) mcUsers.getProfile(attacker).addUnarmedGather(15); + } if(mcUsers.getProfile(attacker).getUnarmedGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("unarmed")){ int skillups = 0; while(mcUsers.getProfile(attacker).getUnarmedGatherInt() >= mcUsers.getProfile(attacker).getXpToLevel("unarmed")){ @@ -1419,7 +1580,7 @@ public class mcm { player.sendMessage(ChatColor.RED+"-----[]"+ChatColor.GREEN+"ARCHERY"+ChatColor.RED+"[]-----"); player.sendMessage(ChatColor.DARK_GRAY+"XP GAIN: "+ChatColor.WHITE+"Attacking Monsters"); player.sendMessage(ChatColor.RED+"---[]"+ChatColor.GREEN+"EFFECTS"+ChatColor.RED+"[]---"); - player.sendMessage(ChatColor.DARK_AQUA+"Daze (Monsters): "+ChatColor.GREEN+"Enemies lose interest for 1 second"); + //player.sendMessage(ChatColor.DARK_AQUA+"Daze (Monsters): "+ChatColor.GREEN+"Enemies lose interest for 1 second"); player.sendMessage(ChatColor.DARK_AQUA+"Daze (Players): "+ChatColor.GREEN+"Disorients foes"); player.sendMessage(ChatColor.DARK_AQUA+"Damage+: "+ChatColor.GREEN+"Modifies Damage"); } @@ -1479,8 +1640,9 @@ public class mcm { player.sendMessage(ChatColor.DARK_AQUA+"Double Drops (Wheat): "+ChatColor.GREEN+"Double the normal loot"); } if(split[0].equalsIgnoreCase("/excavation")){ + event.setCancelled(true); - player.sendMessage(ChatColor.RED+"-----[]"+ChatColor.GREEN+"ARCHERY"+ChatColor.RED+"[]-----"); + player.sendMessage(ChatColor.RED+"-----[]"+ChatColor.GREEN+"EXCAVATION"+ChatColor.RED+"[]-----"); player.sendMessage(ChatColor.DARK_GRAY+"XP GAIN: "+ChatColor.WHITE+"Digging and finding treasures"); player.sendMessage(ChatColor.RED+"---[]"+ChatColor.GREEN+"EFFECTS"+ChatColor.RED+"[]---"); player.sendMessage(ChatColor.DARK_AQUA+"Treasure Hunter: "+ChatColor.GREEN+"Ability to dig for treasure"); @@ -1654,11 +1816,11 @@ public class mcm { mcUsers.getProfile(player).addHerbalismGather(3); } } - if(mcUsers.getProfile(player).getHerbalismGatherInt() >= (mcUsers.getProfile(player).getHerbalismInt() + 5) * mcLoadProperties.xpmodifier){ + if(mcUsers.getProfile(player).getHerbalismGatherInt() >= mcUsers.getProfile(player).getXpToLevel("herbalism")){ int skillups = 0; - while(mcUsers.getProfile(player).getHerbalismGatherInt() >= (mcUsers.getProfile(player).getHerbalismInt() +5) * mcLoadProperties.xpmodifier){ + while(mcUsers.getProfile(player).getHerbalismGatherInt() >= mcUsers.getProfile(player).getXpToLevel("herbalism")){ skillups++; - mcUsers.getProfile(player).removeHerbalismGather((mcUsers.getProfile(player).getHerbalismInt() + 5) * mcLoadProperties.xpmodifier); + mcUsers.getProfile(player).removeHerbalismGather(mcUsers.getProfile(player).getXpToLevel("herbalism")); mcUsers.getProfile(player).skillUpHerbalism(1); } player.sendMessage(ChatColor.YELLOW+"Herbalism skill increased by "+skillups+"."+" Total ("+mcUsers.getProfile(player).getHerbalism()+")"); diff --git a/mcMMO/plugin.yml b/mcMMO/plugin.yml index 99683dd12..2a6a9c8f9 100644 --- a/mcMMO/plugin.yml +++ b/mcMMO/plugin.yml @@ -1,3 +1,3 @@ name: mcMMO main: com.gmail.nossr50.mcMMO -version: 0.8.1 \ No newline at end of file +version: 0.8.3 \ No newline at end of file