diff --git a/src/main/java/com/gmail/nossr50/Database.java b/src/main/java/com/gmail/nossr50/Database.java index 9e4f92a3b..895696a14 100644 --- a/src/main/java/com/gmail/nossr50/Database.java +++ b/src/main/java/com/gmail/nossr50/Database.java @@ -9,19 +9,19 @@ import java.util.HashMap; import java.util.ArrayList; import java.util.Properties; +import org.bukkit.Bukkit; + import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.DatabaseUpdate; public class Database { - private mcMMO plugin; private String connectionString = "jdbc:mysql://" + LoadProperties.MySQLserverName + ":" + LoadProperties.MySQLport + "/" + LoadProperties.MySQLdbName + "?user=" + LoadProperties.MySQLuserName + "&password=" + LoadProperties.MySQLdbPass; private boolean isConnected; private Connection conn = null; public Database(mcMMO instance) { connect(); //Connect to MySQL - this.plugin = instance; // Load the driver instance try { @@ -29,10 +29,10 @@ public class Database { DriverManager.getConnection(connectionString); } catch (ClassNotFoundException e) { - plugin.getServer().getLogger().warning(e.getLocalizedMessage()); + Bukkit.getLogger().warning(e.getLocalizedMessage()); } catch (SQLException ex) { - plugin.getServer().getLogger().warning(ex.getLocalizedMessage()); + Bukkit.getLogger().warning(ex.getLocalizedMessage()); printErrors(ex); } } diff --git a/src/main/java/com/gmail/nossr50/Leaderboard.java b/src/main/java/com/gmail/nossr50/Leaderboard.java index f181fb782..14e7477e3 100644 --- a/src/main/java/com/gmail/nossr50/Leaderboard.java +++ b/src/main/java/com/gmail/nossr50/Leaderboard.java @@ -6,8 +6,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.bukkit.Bukkit; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerStat; @@ -16,7 +16,6 @@ import com.gmail.nossr50.datatypes.Tree; public class Leaderboard { static String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; - protected static final Logger log = Logger.getLogger("Minecraft"); /** * Create the leaderboards. @@ -122,7 +121,7 @@ public class Leaderboard { in.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString())); } //Write the leader board files @@ -159,7 +158,7 @@ public class Leaderboard { writer = new FileWriter(theLocation); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while creating " + theLocation, e); + Bukkit.getLogger().severe(("Exception while creating " + theLocation + e.toString())); } finally { try { @@ -168,7 +167,7 @@ public class Leaderboard { } } catch (IOException e) { - log.log(Level.SEVERE, "Exception while closing writer for " + theLocation, e); + Bukkit.getLogger().severe("Exception while closing writer for " + theLocation + e.toString()); } } } @@ -197,7 +196,7 @@ public class Leaderboard { out.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); } } } @@ -234,7 +233,7 @@ public class Leaderboard { return info; } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + theLocation + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while reading " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); } return null; //Shouldn't get here @@ -286,7 +285,7 @@ public class Leaderboard { out.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); } } } diff --git a/src/main/java/com/gmail/nossr50/Users.java b/src/main/java/com/gmail/nossr50/Users.java index 6a586253a..f5bd0995c 100644 --- a/src/main/java/com/gmail/nossr50/Users.java +++ b/src/main/java/com/gmail/nossr50/Users.java @@ -1,7 +1,8 @@ package com.gmail.nossr50; -import java.io.*; -import java.util.logging.Logger; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.HashMap; import org.bukkit.entity.Player; @@ -9,7 +10,6 @@ import com.gmail.nossr50.datatypes.PlayerProfile; public class Users { private static volatile Users instance; - protected static final Logger log = Logger.getLogger("Minecraft"); String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; String directory = "plugins/mcMMO/FlatFileStuff/"; diff --git a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java index 6262d18c6..4552d87fb 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java @@ -1,8 +1,5 @@ package com.gmail.nossr50.commands.party; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -17,11 +14,8 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; public class ACommand implements CommandExecutor { - private Logger log; - public ACommand() { - this.log = Logger.getLogger("Minecraft"); - } + public ACommand() {} @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -35,7 +29,7 @@ public class ACommand implements CommandExecutor { String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} "; - log.log(Level.INFO, "[A]<*Console*> " + aMessage); + Bukkit.getLogger().info("[A]<*Console*> " + aMessage); for (Player herp : Bukkit.getServer().getOnlinePlayers()) { if (mcPermissions.getInstance().adminChat(herp) || herp.isOp()) @@ -64,7 +58,7 @@ public class ACommand implements CommandExecutor { String name = (LoadProperties.aDisplayNames) ? player.getDisplayName() : player.getName(); String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + name + ChatColor.AQUA + "} "; - log.log(Level.INFO, "[A]<" + name + "> " + aMessage); + Bukkit.getLogger().info("[A]<" + name + "> " + aMessage); for (Player herp : Bukkit.getServer().getOnlinePlayers()) { if (mcPermissions.getInstance().adminChat(herp) || herp.isOp()) herp.sendMessage(aPrefix + aMessage); @@ -83,10 +77,8 @@ public class ACommand implements CommandExecutor { if (PP.getAdminChatMode()) { player.sendMessage(mcLocale.getString("mcPlayerListener.AdminChatOn")); - // player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.GREEN + "On"); } else { player.sendMessage(mcLocale.getString("mcPlayerListener.AdminChatOff")); - // player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.RED + "Off"); } } return true; diff --git a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java index 8f8d4b3d6..0e69d7002 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java @@ -1,8 +1,5 @@ package com.gmail.nossr50.commands.party; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -18,11 +15,7 @@ import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; public class PCommand implements CommandExecutor { - private Logger log; - - public PCommand() { - this.log = Logger.getLogger("Minecraft"); - } + public PCommand() {} @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -38,7 +31,7 @@ public class PCommand implements CommandExecutor { String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") "; - log.log(Level.INFO, "[P](" + args[0] + ")" + "<*Console*> " + pMessage); + Bukkit.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + pMessage); for (Player herp : Bukkit.getServer().getOnlinePlayers()) { if (Users.getProfile(herp).inParty()) { @@ -73,7 +66,7 @@ public class PCommand implements CommandExecutor { String name = (LoadProperties.pDisplayNames) ? player.getDisplayName() : player.getName(); String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + name + ChatColor.GREEN + ") "; - log.log(Level.INFO, "[P](" + PP.getParty() + ")<" + name + "> " + pMessage); + Bukkit.getLogger().info("[P](" + PP.getParty() + ")<" + name + "> " + pMessage); for (Player herp : Bukkit.getServer().getOnlinePlayers()) { if (Users.getProfile(herp).inParty()) { @@ -91,10 +84,8 @@ public class PCommand implements CommandExecutor { PP.togglePartyChat(); if (PP.getPartyChatMode()) { - // player.sendMessage(ChatColor.GREEN + "Party Chat Toggled On"); player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOn")); } else { - // player.sendMessage(ChatColor.GREEN + "Party Chat Toggled " + ChatColor.RED + "Off"); player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOff")); } diff --git a/src/main/java/com/gmail/nossr50/config/LoadProperties.java b/src/main/java/com/gmail/nossr50/config/LoadProperties.java index cdf56d94f..1ef24c587 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadProperties.java +++ b/src/main/java/com/gmail/nossr50/config/LoadProperties.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.mcMMO; import java.io.File; import java.io.IOException; + import org.bukkit.configuration.file.FileConfiguration; import com.gmail.nossr50.datatypes.HUDType; @@ -123,7 +124,7 @@ public class LoadProperties { } private void loadKeys() { - plugin.getLogger().info("Loading mcMMO config.yml File..."); + plugin.getLogger().info("Loading mcMMO config.yml File..."); // Setup default HUD String temp = readString("Spout.HUD.Default", "STANDARD"); diff --git a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java index 960cf318b..20b5db67f 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java +++ b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -210,7 +211,7 @@ public class LoadTreasures { if(issues.isEmpty()) return true; for(String issue : issues) { - plugin.getLogger().warning(issue); + Bukkit.getLogger().warning(issue); } return false; diff --git a/src/main/java/com/gmail/nossr50/config/Misc.java b/src/main/java/com/gmail/nossr50/config/Misc.java index 4d381127f..c6bd16f54 100644 --- a/src/main/java/com/gmail/nossr50/config/Misc.java +++ b/src/main/java/com/gmail/nossr50/config/Misc.java @@ -1,7 +1,8 @@ package com.gmail.nossr50.config; -import java.util.*; -import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -14,8 +15,6 @@ public class Misc { String location = "mcmmo.properties"; - protected static final Logger log = Logger.getLogger("Minecraft"); - public ArrayList mobSpawnerList = new ArrayList(); public HashSet blockWatchList = new HashSet(); public HashMap arrowTracker = new HashMap(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index f31706608..bfa75bf6c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -6,8 +6,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.util.HashMap; import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -21,8 +19,6 @@ import com.gmail.nossr50.mcMMO; public class PlayerProfile { - protected final Logger log = Logger.getLogger("Minecraft"); - //HUD private HUDType hud; @@ -317,8 +313,7 @@ public class PlayerProfile } in.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " - + location + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } return false; } @@ -440,7 +435,7 @@ public class PlayerProfile 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); + Bukkit.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } } } @@ -518,7 +513,7 @@ public class PlayerProfile out.newLine(); out.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } } public void togglePartyHUD() diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 87401712d..fb81b9dc0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -1,8 +1,5 @@ package com.gmail.nossr50.listeners; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -47,7 +44,6 @@ import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Taming; public class mcPlayerListener implements Listener { - protected static final Logger log = Logger.getLogger("Minecraft"); private mcMMO plugin; public mcPlayerListener(mcMMO instance) { @@ -333,7 +329,7 @@ public class mcPlayerListener implements Listener { } } - log.log(Level.INFO, logHeader + name + ">" + event.getMessage()); + Bukkit.getLogger().info(logHeader + name + ">" + event.getMessage()); } } diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 185090fe9..3c82801e1 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -1,7 +1,5 @@ package com.gmail.nossr50; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -19,7 +17,6 @@ import com.gmail.nossr50.runnables.SQLConversionTask; import com.gmail.nossr50.skills.Repair; public class m { - public static final Logger log = Logger.getLogger("Minecraft"); /** * Gets a capitalized version of the target string. @@ -250,6 +247,15 @@ public class m { return; } - Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new SQLConversionTask(log), 1); + Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new SQLConversionTask(), 1); + } + + public static int skillCheck(int skillLevel, int maxLevel) { + if (skillLevel > maxLevel) { + return maxLevel; + } + else { + return skillLevel; + } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index e2cb223fe..ee2f9b05f 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -30,8 +30,6 @@ import java.io.InputStream; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -50,7 +48,6 @@ public class mcMMO extends JavaPlugin { public static String maindirectory = "plugins" + File.separator + "mcMMO"; public static File file = new File(maindirectory + File.separator + "config.yml"); public static File versionFile = new File(maindirectory + File.separator + "VERSION"); - public static final Logger log = Logger.getLogger("Minecraft"); private final mcPlayerListener playerListener = new mcPlayerListener(this); private final mcBlockListener blockListener = new mcBlockListener(this); @@ -276,7 +273,7 @@ public class mcMMO extends JavaPlugin { in.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } return parties; } @@ -572,7 +569,7 @@ public class mcMMO extends JavaPlugin { treasuresConfig.save(treasuresConfigFile); } catch (IOException ex) { - log.log(Level.SEVERE, "Could not save config to " + treasuresConfigFile, ex); + Bukkit.getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString()); } } } diff --git a/src/main/java/com/gmail/nossr50/party/Party.java b/src/main/java/com/gmail/nossr50/party/Party.java index 083e10e67..29e4ab4c4 100644 --- a/src/main/java/com/gmail/nossr50/party/Party.java +++ b/src/main/java/com/gmail/nossr50/party/Party.java @@ -377,7 +377,7 @@ public class Party ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPlayersFile)); this.partyPlayers = (HashMap>)obj.readObject(); } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (EOFException e) { mcMMO.log.info("partyPlayersFile empty."); + } catch (EOFException e) { Bukkit.getLogger().info("partyPlayersFile empty."); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } @@ -387,7 +387,7 @@ public class Party ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyLocksFile)); this.partyLocks = (HashMap)obj.readObject(); } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (EOFException e) { mcMMO.log.info("partyLocksFile empty."); + } catch (EOFException e) { Bukkit.getLogger().info("partyLocksFile empty."); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } @@ -397,7 +397,7 @@ public class Party ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPasswordsFile)); this.partyPasswords = (HashMap)obj.readObject(); } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (EOFException e) { mcMMO.log.info("partyPasswordsFile empty."); + } catch (EOFException e) { Bukkit.getLogger().info("partyPasswordsFile empty."); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java index 24788d8d4..500acddee 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java @@ -2,19 +2,15 @@ package com.gmail.nossr50.runnables; import java.io.BufferedReader; import java.io.FileReader; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.bukkit.Bukkit; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.LoadProperties; public class SQLConversionTask implements Runnable { - private Logger log; - - public SQLConversionTask(Logger log) { - this.log = log; - } + public SQLConversionTask() {} @Override public void run() { @@ -282,7 +278,7 @@ public class SQLConversionTask implements Runnable { in.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/Acrobatics.java index e8e0ff098..0e1c81cc9 100644 --- a/src/main/java/com/gmail/nossr50/skills/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/Acrobatics.java @@ -5,6 +5,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.Users; +import com.gmail.nossr50.m; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; @@ -96,11 +97,7 @@ public class Acrobatics { if (mcPermissions.getInstance().acrobatics(defender)) { int skillLevel = PPd.getSkillLevel(SkillType.ACROBATICS); - int skillCheck = skillLevel; - - if (skillLevel > MAX_BONUS_LEVEL) { - skillCheck = MAX_BONUS_LEVEL; - } + int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL); if (Math.random() * 4000 <= skillCheck) { defender.sendMessage(mcLocale.getString("Acrobatics.Dodge")); diff --git a/src/main/java/com/gmail/nossr50/skills/Archery.java b/src/main/java/com/gmail/nossr50/skills/Archery.java index 5bf168dd4..0fe21fcc2 100644 --- a/src/main/java/com/gmail/nossr50/skills/Archery.java +++ b/src/main/java/com/gmail/nossr50/skills/Archery.java @@ -56,6 +56,8 @@ public class Archery { if (Math.random() * 100 <= IGNITION_CHANCE) { int ignition = 20; + + /* Add 20 ticks for every 200 skill levels */ ignition += (PPa.getSkillLevel(SkillType.ARCHERY) / 200) * 20; if (ignition > MAX_IGNITION_TICKS) { @@ -89,7 +91,7 @@ public class Archery { int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY); Location loc = defender.getLocation(); - int skillCheck = skillLevel; + int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL); if (Math.random() * 10 > 5) { loc.setPitch(90); @@ -98,10 +100,6 @@ public class Archery { loc.setPitch(-90); } - if (skillLevel > MAX_BONUS_LEVEL) { - skillCheck = MAX_BONUS_LEVEL; - } - if (Math.random() * 2000 <= skillCheck) { defender.teleport(loc); defender.sendMessage(mcLocale.getString("Combat.TouchedFuzzy")); diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index 6d7f6224f..544bee0df 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -1,118 +1,159 @@ package com.gmail.nossr50.skills; -import org.bukkit.Material; +import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Wolf; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; -import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.Users; -import com.gmail.nossr50.mcPermissions; +import com.gmail.nossr50.m; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; public class Axes { - public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) - { + + /** + * Apply bonus to damage done by axes. + * + * @param attacker The attacking player + * @param event The event to modify + */ + public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) { + final int MAX_BONUS = 4; + int bonus = 0; - - //Add 1 DMG for every 50 skill levels - bonus += Users.getProfile(attacker).getSkillLevel(SkillType.AXES)/50; - - if(bonus > 4) - bonus = 4; - + + /* Add 1 DMG for every 50 skill levels */ + bonus += Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / 50; + + if (bonus > MAX_BONUS) { + bonus = MAX_BONUS; + } + event.setDamage(event.getDamage() + bonus); } - public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) - { - Entity x = event.getEntity(); - - if(x instanceof Wolf){ - Wolf wolf = (Wolf)x; - if(wolf.getOwner() instanceof Player) - { - Player owner = (Player) wolf.getOwner(); - if(owner == attacker) - return; - if(Party.getInstance().inSameParty(attacker, owner)) - return; - } - } - PlayerProfile PPa = Users.getProfile(attacker); - if(ItemChecks.isAxe(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker)){ - if(PPa.getSkillLevel(SkillType.AXES) >= 750){ - if(Math.random() * 2000 <= 750 && !x.isDead()){ - if(x instanceof Player){ - int damage = (event.getDamage() * 2) - (event.getDamage() / 2); - event.setDamage(damage); - Player player = (Player)x; - player.sendMessage(mcLocale.getString("Axes.HitCritically")); - } - else { - int damage = event.getDamage() * 2; - event.setDamage(damage); - } - attacker.sendMessage(mcLocale.getString("Axes.CriticalHit")); - } - } else if(Math.random() * 2000 <= PPa.getSkillLevel(SkillType.AXES) && !x.isDead()){ - if(x instanceof Player){ - int damage = (event.getDamage() * 2) - (event.getDamage() / 2); - event.setDamage(damage); - Player player = (Player)x; - player.sendMessage(mcLocale.getString("Axes.HitCritically")); - } - else { - int damage = event.getDamage() * 2; - event.setDamage(damage); - } - attacker.sendMessage(mcLocale.getString("Axes.CriticalHit")); - } - } + + /** + * Check for critical chances on axe damage. + * + * @param attacker The attacking player + * @param event The event to modify + */ + public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + + if (entity instanceof Wolf) { + Wolf wolf = (Wolf) entity; + + if (wolf.isTamed()) { + AnimalTamer tamer = wolf.getOwner(); + + if (tamer instanceof Player) { + Player owner = (Player) tamer; + + if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) { + return; + } + } + } + } + + final int MAX_BONUS_LEVEL = 750; + final double PVP_MODIFIER = 1.5; + final int PVE_MODIFIER = 2; + + PlayerProfile PPa = Users.getProfile(attacker); + int skillLevel = PPa.getSkillLevel(SkillType.AXES); + int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL); + + if (Math.random() * 2000 <= skillCheck && !entity.isDead()){ + int damage = event.getDamage(); + + if (entity instanceof Player){ + event.setDamage((int) (damage * PVP_MODIFIER)); + Player player = (Player) entity; + player.sendMessage(mcLocale.getString("Axes.HitCritically")); + } + else { + event.setDamage(damage * PVE_MODIFIER); + } + attacker.sendMessage(mcLocale.getString("Axes.CriticalHit")); + } } - - public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) - { - //TODO: Finish this skill, the idea is you will greatly damage an opponents armor and when they are armor less you have a proc that will stun them and deal additional damage. - if(target instanceof Player) - { - Player targetPlayer = (Player) target; - int emptySlots = 0; - short durDmg = 5; //Start with 5 durability dmg - - durDmg+=Users.getProfile(attacker).getSkillLevel(SkillType.AXES)/30; //Every 30 Skill Levels you gain 1 durability dmg - - for(ItemStack x : targetPlayer.getInventory().getArmorContents()) - { - if(x.getType() == Material.AIR) - { - emptySlots++; - } else { - x.setDurability((short) (x.getDurability()+durDmg)); //Damage armor piece - } - } - - if(emptySlots == 4) - applyImpact(attacker, target, event); - } - else - //Since mobs are technically unarmored this will always trigger - applyImpact(attacker, target, event); - } - - public static void applyImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) - { - if(Math.random() * 100 > 75) - { - event.setDamage(event.getDamage()+2); - target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(1.5D)); + + /** + * Check for Impact ability. + * + * @param attacker The attacking player + * @param target The defending entity + * @param event The event to modify + */ + public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) { + + /* + * TODO: Finish this skill. The idea is you will greatly damage an opponents armor. + * When they are unarmored, you have a proc that will stun them and deal additional damage. + */ + if (target instanceof Player) { + Player targetPlayer = (Player) target; + short durabilityDamage = 5; //Start with 5 durability damage + + /* Every 30 Skill Levels you gain 1 durability damage */ + durabilityDamage += Users.getProfile(attacker).getSkillLevel(SkillType.AXES)/30; + + if (!hasArmor(targetPlayer)) { + applyImpact(attacker, target, event); + } + else { + for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) { + armor.setDurability((short) (armor.getDurability() + durabilityDamage)); //Damage armor piece + } + targetPlayer.updateInventory(); + } + } + else { + applyImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger + } + } + + /** + * Apply impact ability. + * + * @param attacker The attacking player + * @param target The defending entity + * @param event The event to modify + */ + private static void applyImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) { + final int GREATER_IMPACT_CHANCE = 25; + final double GREATER_IMPACT_MULTIPLIER = 1.5; + + if (Math.random() * 100 <= GREATER_IMPACT_CHANCE) { + event.setDamage(event.getDamage() + 2); + target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER)); attacker.sendMessage(mcLocale.getString("Axes.GreaterImpactOnEnemy")); } - } - + } + + /** + * Check if a player has armor. + * + * @param player Player whose armor to check + * @return true if the player has armor, false otherwise + */ + private static boolean hasArmor(Player player) { + PlayerInventory inventory = player.getInventory(); + + if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) { + return true; + } + else { + return false; + } + } } diff --git a/src/main/java/com/gmail/nossr50/skills/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/BlastMining.java index 7c286185e..324f24593 100644 --- a/src/main/java/com/gmail/nossr50/skills/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/BlastMining.java @@ -23,186 +23,233 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; -public class BlastMining{ - - /** - * Handler for what blocks drop from the explosion. - * - * @param ores List of ore blocks destroyed by the explosion - * @param debris List of non-ore blocks destroyed by the explosion - * @param yield Percentage of blocks to drop - * @param oreBonus Percentage bonus for ore drops - * @param debrisReduction Percentage reduction for non-ore drops - * @param extraDrops Number of times to drop each block - * @param plugin mcMMO plugin instance - * @return A list of blocks dropped from the explosion - */ - private static List explosionYields(List ores, List debris, float yield, float oreBonus, float debrisReduction, int extraDrops, mcMMO plugin) - { - Iterator iterator2 = ores.iterator(); - List blocksDropped = new ArrayList(); - while(iterator2.hasNext()) - { - Block temp = iterator2.next(); - if((float)Math.random() < (yield + oreBonus)) - { - blocksDropped.add(temp); - Mining.miningDrops(temp); - if(temp.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(temp)) - { - if(extraDrops == 2) - { - blocksDropped.add(temp); - Mining.miningDrops(temp); - } - if(extraDrops == 3) - { - blocksDropped.add(temp); - Mining.miningDrops(temp); - } - } - } - } - - if(yield - debrisReduction != 0) - { - Iterator iterator3 = debris.iterator(); - while(iterator3.hasNext()) - { - Block temp = iterator3.next(); - if((float)Math.random() < (yield - debrisReduction)) - Mining.miningDrops(temp); - } - } - return blocksDropped; - } - - /** - * Handler for explosion drops and XP gain. - * @param player Player triggering the explosion - * @param event Event whose explosion is being processed - * @param plugin mcMMO plugin instance - */ - public static void dropProcessing(Player player, EntityExplodeEvent event, mcMMO plugin) - { - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); - float yield = event.getYield(); - List blocks = event.blockList(); - Iterator iterator = blocks.iterator(); - - List ores = new ArrayList(); - List debris = new ArrayList(); - List xp = new ArrayList(); +public class BlastMining { - while(iterator.hasNext()) - { - Block temp = iterator.next(); - if(BlockChecks.isOre(temp.getType())) - ores.add(temp); - else - debris.add(temp); - } - - //Normal explosion - if(skillLevel < 125) - return; - - event.setYield(0); - - //+35% ores, -10% debris - if(skillLevel >= 125 && skillLevel < 250) - xp = explosionYields(ores, debris, yield, .35f, .10f, 1, plugin); - - //+40% ores, -20% debris - if(skillLevel >= 250 && skillLevel < 375) - xp = explosionYields(ores, debris, yield, .40f, .20f, 1, plugin); - - //No debris, +45% ores - if(skillLevel >= 375 && skillLevel < 500) - xp = explosionYields(ores, debris, yield, .45f, .30f, 1, plugin); - - //No debris, +50% ores - if(skillLevel >= 500 && skillLevel < 625) - xp = explosionYields(ores, debris, yield, .50f, .30f, 1, plugin); - - //Double Drops, No Debris, +55% ores - if(skillLevel >= 625 && skillLevel < 750) - xp = explosionYields(ores, debris, yield, .55f, .30f, 2, plugin); - - //Double Drops, No Debris, +60% ores - if(skillLevel >= 750 && skillLevel < 875) - xp = explosionYields(ores, debris, yield, .60f, .30f, 2, plugin); - - //Triple Drops, No debris, +65% ores - if(skillLevel >= 875 && skillLevel < 1000) - xp = explosionYields(ores, debris, yield, .65f, .30f, 3, plugin); + /** + * Handler for what blocks drop from the explosion. + * + * @param ores List of ore blocks destroyed by the explosion + * @param debris List of non-ore blocks destroyed by the explosion + * @param yield Percentage of blocks to drop + * @param oreBonus Percentage bonus for ore drops + * @param debrisReduction Percentage reduction for non-ore drops + * @param extraDrops Number of times to drop each block + * @param plugin mcMMO plugin instance + * @return A list of blocks dropped from the explosion + */ + private static List explosionYields(List ores, List debris, float yield, float oreBonus, float debrisReduction, int extraDrops, mcMMO plugin) { + Iterator iterator2 = ores.iterator(); + List blocksDropped = new ArrayList(); - //Triple Drops, No debris, +70% ores - if(skillLevel >= 1000) - xp = explosionYields(ores, debris, yield, .70f, .30f, 3, plugin); - - for(Block block : xp) - { - if(block.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block)) - Mining.miningXP(player, block); - } - - } - - /** - * Increases the blast radius of the explosion. - * - * @param player Player triggering the explosion - * @param event Event whose explosion radius is being changed - */ - public static void biggerBombs(Player player, ExplosionPrimeEvent event) - { - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); - float radius = event.getRadius(); - if(skillLevel < 250) - return; - if(skillLevel >= 250) - radius++; - if(skillLevel >= 500) - radius++; - if(skillLevel >= 750) - radius++; - if(skillLevel >= 1000) - radius++; - event.setRadius(radius); - } - - /** - * Decreases damage dealt by the explosion. - * - * @param player Player triggering the explosion - * @param event Event whose explosion damage is being reduced - */ - public static void demolitionsExpertise(Player player, EntityDamageEvent event) - { - int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING); - int damage = event.getDamage(); - if(skill < 500) - return; - if(skill >= 500 && skill < 750) - damage = damage/4; - if(skill >= 750 && skill < 1000) - damage = damage/2; - if(skill >= 1000) - damage = 0; - event.setDamage(damage); - } + while (iterator2.hasNext()) { + Block temp = iterator2.next(); + + if ((float) Math.random() < (yield + oreBonus)) { + blocksDropped.add(temp); + Mining.miningDrops(temp); + + if (temp.getData() != (byte) 0x5 && !plugin.misc.blockWatchList.contains(temp)) { + if (extraDrops == 2) { + blocksDropped.add(temp); + Mining.miningDrops(temp); + } + if (extraDrops == 3) { + blocksDropped.add(temp); + Mining.miningDrops(temp); + } + } + } + } + + if (yield - debrisReduction != 0) { + Iterator iterator3 = debris.iterator(); + + while (iterator3.hasNext()) { + Block temp = iterator3.next(); + + if ((float) Math.random() < (yield - debrisReduction)) + Mining.miningDrops(temp); + } + } + + return blocksDropped; + } + + /** + * Handler for explosion drops and XP gain. + * + * @param player Player triggering the explosion + * @param event Event whose explosion is being processed + * @param plugin mcMMO plugin instance + */ + public static void dropProcessing(Player player, EntityExplodeEvent event, mcMMO plugin) { + final int RANK_1_LEVEL = 125; + final int RANK_2_LEVEL = 250; + final int RANK_3_LEVEL = 375; + final int RANK_4_LEVEL = 500; + final int RANK_5_LEVEL = 625; + final int RANK_6_LEVEL = 750; + final int RANK_7_LEVEL = 875; + final int RANK_8_LEVEL = 1000; + + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); + float yield = event.getYield(); + List blocks = event.blockList(); + Iterator iterator = blocks.iterator(); + + List ores = new ArrayList(); + List debris = new ArrayList(); + List xp = new ArrayList(); + + while (iterator.hasNext()) { + Block temp = iterator.next(); + + if (BlockChecks.isOre(temp.getType())) { + ores.add(temp); + } + else { + debris.add(temp); + } + } + + //Normal explosion + if (skillLevel < RANK_1_LEVEL) { + return; + } + + event.setYield(0); + + //Triple Drops, No debris, +70% ores + if (skillLevel >= RANK_8_LEVEL) { + xp = explosionYields(ores, debris, yield, .70f, .30f, 3, plugin); + } + + //Triple Drops, No debris, +65% ores + else if (skillLevel >= RANK_7_LEVEL) { + xp = explosionYields(ores, debris, yield, .65f, .30f, 3, plugin); + } + + //Double Drops, No Debris, +60% ores + else if (skillLevel >= RANK_6_LEVEL) { + xp = explosionYields(ores, debris, yield, .60f, .30f, 2, plugin); + } + + //Double Drops, No Debris, +55% ores + else if (skillLevel >= RANK_5_LEVEL) { + xp = explosionYields(ores, debris, yield, .55f, .30f, 2, plugin); + } + + //No debris, +50% ores + else if (skillLevel >= RANK_4_LEVEL) { + xp = explosionYields(ores, debris, yield, .50f, .30f, 1, plugin); + } + + //No debris, +45% ores + else if (skillLevel >= RANK_3_LEVEL) { + xp = explosionYields(ores, debris, yield, .45f, .30f, 1, plugin); + } + + //+40% ores, -20% debris + else if (skillLevel >= RANK_2_LEVEL) { + xp = explosionYields(ores, debris, yield, .40f, .20f, 1, plugin); + } + + //+35% ores, -10% debris + else if (skillLevel >= RANK_1_LEVEL) { + xp = explosionYields(ores, debris, yield, .35f, .10f, 1, plugin); + } + + for (Block block : xp) { + if (block.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block)) { + Mining.miningXP(player, block); + } + } + } + + /** + * Increases the blast radius of the explosion. + * + * @param player Player triggering the explosion + * @param event Event whose explosion radius is being changed + */ + public static void biggerBombs(Player player, ExplosionPrimeEvent event) { + final int RANK_1_LEVEL = 250; + final int RANK_2_LEVEL = 500; + final int RANK_3_LEVEL = 750; + final int RANK_4_LEVEL = 1000; + + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); + float radius = event.getRadius(); + + if (skillLevel < RANK_1_LEVEL) { + return; + } + + if (skillLevel >= RANK_1_LEVEL) { + radius++; + } + + if (skillLevel >= RANK_2_LEVEL) { + radius++; + } + + if (skillLevel >= RANK_3_LEVEL) { + radius++; + } + + if (skillLevel >= RANK_4_LEVEL) { + radius++; + } + + event.setRadius(radius); + } + + /** + * Decreases damage dealt by the explosion. + * + * @param player Player triggering the explosion + * @param event Event whose explosion damage is being reduced + */ + public static void demolitionsExpertise(Player player, EntityDamageEvent event) { + final int RANK_1_LEVEL = 500; + final int RANK_2_LEVEL = 750; + final int RANK_3_LEVEL = 1000; + + int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING); + int damage = event.getDamage(); + + if (skill < RANK_1_LEVEL) { + return; + } + + if (skill >= RANK_3_LEVEL) { + damage = 0; + } + else if (skill >= RANK_2_LEVEL) { + damage = damage / 2; + } + else if (skill >= RANK_1_LEVEL) { + damage = damage/4; + } + + event.setDamage(damage); + } public static void remoteDetonation(Player player, mcMMO plugin) { + final byte SNOW = 78; + final byte AIR = 0; + final int BLOCKS_AWAY = 100; + PlayerProfile PP = Users.getProfile(player); HashSet transparent = new HashSet(); - transparent.add((byte) 78); //SNOW - transparent.add((byte) 0); //AIR + transparent.add(SNOW); + transparent.add(AIR); - Block b = player.getTargetBlock(transparent, 100); + Block block = player.getTargetBlock(transparent, BLOCKS_AWAY); - if(b.getType().equals(Material.TNT) && m.blockBreakSimulate(b, player, true) && PP.getSkillLevel(SkillType.MINING) >= 125) { + if (block.getType().equals(Material.TNT) && m.blockBreakSimulate(block, player, true) && PP.getSkillLevel(SkillType.MINING) >= 125) { + final int MAX_DISTANCE_AWAY = 10; AbilityType ability = AbilityType.BLAST_MINING; /* Check Cooldown */ @@ -213,7 +260,7 @@ public class BlastMining{ /* Send message to nearby players */ for(Player y : player.getWorld().getPlayers()) { - if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) { + if(y != player && m.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) { y.sendMessage(ability.getAbilityPlayer(player)); } } @@ -221,9 +268,9 @@ public class BlastMining{ player.sendMessage(mcLocale.getString("BlastMining.Boom")); /* Create the TNT entity */ - TNTPrimed tnt = player.getWorld().spawn(b.getLocation(), TNTPrimed.class); + TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class); plugin.misc.tntTracker.put(tnt.getEntityId(), player); - b.setType(Material.AIR); + block.setType(Material.AIR); tnt.setFuseTicks(0); PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index 9b0d5da91..d7bdd5295 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.Block; @@ -27,8 +25,6 @@ import com.gmail.nossr50.locale.mcLocale; public class Skills { - protected static final Logger log = Logger.getLogger("Minecraft"); - public static boolean cooldownOver(Player player, long oldTime, int cooldown){ long currentTime = System.currentTimeMillis(); if(currentTime - oldTime >= (cooldown * 1000))