diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 3da942ee9..a542f5ab2 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.listeners; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -17,14 +16,13 @@ import org.bukkit.event.player.PlayerFishEvent.State; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.PluginDescriptionFile; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.commands.general.XprateCommand; -import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; @@ -32,7 +30,6 @@ import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.runnables.BleedTimer; -import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.fishing.Fishing; @@ -42,6 +39,7 @@ import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.Item; +import com.gmail.nossr50.util.MOTD; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -62,13 +60,12 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); + PlayerProfile profile = Users.getProfile(player); - if (Misc.isNPC(player)) { + if (Misc.isNPC(player, profile)) { return; } - PlayerProfile profile = Users.getProfile(player); - if (profile.getGodMode() && !Permissions.mcgod(player)) { profile.toggleGodMode(); player.sendMessage(LocaleLoader.getString("Commands.GodMode.Forbidden")); @@ -87,11 +84,11 @@ public class PlayerListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerFish(PlayerFishEvent event) { - AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - int shakeUnlockLevel = advancedConfig.getShakeUnlockLevel(); Player player = event.getPlayer(); - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (Misc.isNPC(player)) { + return; + } if (Permissions.fishing(player)) { State state = event.getState(); @@ -102,13 +99,7 @@ public class PlayerListener implements Listener { break; case CAUGHT_ENTITY: - if (!(event.getCaught() instanceof LivingEntity)) { - return; - } - - if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) >= shakeUnlockLevel && Permissions.shakeMob(player)) { - Fishing.shakeMob(event); - } + Fishing.shakeMob(event); break; default: @@ -124,8 +115,14 @@ public class PlayerListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerLogin(PlayerLoginEvent event) { - if (event.getPlayer().hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS(); + Player player = event.getPlayer(); + + /* We can't use the other check here because a profile hasn't been created yet.*/ + if (player == null || player.hasMetadata("NPC")) { + return; + } + + Users.addUser(player).getProfile().actualizeRespawnATS(); } /** @@ -137,12 +134,12 @@ public class PlayerListener implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (Misc.isNPC(player)) { + return; + } /* GARBAGE COLLECTION */ - - //Bleed it out - BleedTimer.bleedOut(player); + BleedTimer.bleedOut(player); //Bleed it out } /** @@ -154,82 +151,43 @@ public class PlayerListener implements Listener { public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - - if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) { - String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); - - player.sendMessage(LocaleLoader.getString("MOTD.Version", new Object[] {plugin.getDescription().getVersion()})); - - if (Config.getInstance().getHardcoreEnabled()) { - if (Config.getInstance().getHardcoreVampirismEnabled()) { - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); - player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Config.getInstance().getHardcoreVampirismStatLeechPercentage()})); - } - else { - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff")); - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); - } - } - - if (Permissions.xpQuadruple(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 4 }) })); - } - else if (Permissions.xpTriple(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 3 }) })); - } - else if (Permissions.xpDoubleAndOneHalf(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 2.5 }) })); - } - else if (Permissions.xpDouble(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 2 }) })); - } - else if (Permissions.xpOneAndOneHalf(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 1.5 }) })); - } - - if (Permissions.cooldownsHalved(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/2" }) })); - } - else if (Permissions.cooldownsThirded(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/3" }) })); - } - else if (Permissions.cooldownsQuartered(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/4" }) })); - } - - if (Permissions.activationTwelve(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 12 }) })); - } - else if (Permissions.activationEight(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 8 }) })); - } - else if (Permissions.activationFour(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 4 }) })); - } - - if (Permissions.luckyAcrobatics(player) || Permissions.luckyArchery(player) || Permissions.luckyAxes(player) || Permissions.luckyFishing(player) || Permissions.luckyHerbalism(player) || Permissions.luckyMining(player) || Permissions.luckyRepair(player) || Permissions.luckySwords(player) || Permissions.luckyTaming(player) || Permissions.luckyUnarmed(player) || Permissions.luckyWoodcutting(player) || Permissions.luckySmelting(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc.login") })); - } - - player.sendMessage(LocaleLoader.getString("MOTD.Website", new Object[] {plugin.getDescription().getWebsite()})); + if (Misc.isNPC(player)) { + return; } - //THIS IS VERY BAD WAY TO DO THINGS, NEED BETTER WAY + if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) { + PluginDescriptionFile pluginDescription = plugin.getDescription(); + MOTD motd = new MOTD(player); + + motd.displayVersion(pluginDescription.getVersion()); + motd.displayHardcoreSettings(); + motd.displayXpPerks(); + motd.displayCooldownPerks(); + motd.displayActivationPerks(); + motd.displayLuckyPerks(); + motd.displayWebsite(pluginDescription.getWebsite()); + } + + //TODO: MAKE THIS SUCK LESS. THIS IS VERY BAD WAY TO DO THINGS, NEED BETTER WAY if (XprateCommand.isXpEventRunning()) { player.sendMessage(LocaleLoader.getString("XPRate.Event", new Object[] {Config.getInstance().xpGainMultiplier})); } } + /** + * Monitor PlayerRespawn events. + * @param event The event to watch + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerRespawn(PlayerRespawnEvent event) { - if (event.getPlayer().hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - PlayerProfile profile = Users.getProfile(event.getPlayer()); + Player player = event.getPlayer(); + PlayerProfile profile = Users.getProfile(player); - if (profile != null) { - profile.actualizeRespawnATS(); + if (Misc.isNPC(player, profile)) { + return; } + + profile.actualizeRespawnATS(); } /** @@ -363,12 +321,9 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); - - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - PlayerProfile profile = Users.getProfile(player); - if (profile == null) { + if (Misc.isNPC(player, profile)) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java index c7c310f43..565649865 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -7,6 +7,7 @@ import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; @@ -139,16 +140,12 @@ public class Fishing { */ public static void processResults(PlayerFishEvent event) { Player player = event.getPlayer(); - if (player == null) - return; - - PlayerProfile profile = Users.getProfile(player); getFishingResults(player, event); Item theCatch = (Item) event.getCaught(); if (theCatch.getItemStack().getType() != Material.RAW_FISH) { - int lootTier = Fishing.getFishingLootTier(profile); + int lootTier = Fishing.getFishingLootTier(Users.getProfile(player)); int specificChance = 1; boolean enchanted = false; ItemStack fishingResults = theCatch.getItemStack(); @@ -224,6 +221,18 @@ public class Fishing { * The event to modify */ public static void shakeMob(PlayerFishEvent event) { + Entity caughtEntity = event.getCaught(); + + if (!(caughtEntity instanceof LivingEntity)) { + return; + } + + Player player = event.getPlayer(); + + if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) < Fishing.shakeUnlockLevel || !Permissions.shakeMob(player)) { + return; + } + int randomChance = 100; //TODO: Invert this so it matches the rest of our lucky checks... @@ -231,7 +240,7 @@ public class Fishing { randomChance = 125; } - final Player player = event.getPlayer(); + final PlayerProfile profile = Users.getProfile(player); int lootTier = getFishingLootTier(profile); diff --git a/src/main/java/com/gmail/nossr50/util/MOTD.java b/src/main/java/com/gmail/nossr50/util/MOTD.java new file mode 100644 index 000000000..2f4145a0c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/util/MOTD.java @@ -0,0 +1,112 @@ +package com.gmail.nossr50.util; + +import org.bukkit.entity.Player; + +import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.SkillType; + +public class MOTD { + private Player player; + private String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); + + public MOTD(Player player) { + this.player = player; + } + + /** + * Display version info. + * @param version The plugin version + */ + public void displayVersion(String version) { + player.sendMessage(LocaleLoader.getString("MOTD.Version", new Object[] {version})); + } + + /** + * Display Hardcore Mode settings. + */ + public void displayHardcoreSettings() { + if (Config.getInstance().getHardcoreEnabled()) { + if (Config.getInstance().getHardcoreVampirismEnabled()) { + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); + player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Config.getInstance().getHardcoreVampirismStatLeechPercentage()})); + } + else { + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff")); + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); + } + } + } + + /** + * Display XP perks. + */ + public void displayXpPerks() { + if (Permissions.xpQuadruple(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 4 }) })); + } + else if (Permissions.xpTriple(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 3 }) })); + } + else if (Permissions.xpDoubleAndOneHalf(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 2.5 }) })); + } + else if (Permissions.xpDouble(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 2 }) })); + } + else if (Permissions.xpOneAndOneHalf(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", new Object[] { 1.5 }) })); + } + } + + /** + * Display cooldown perks. + */ + public void displayCooldownPerks() { + if (Permissions.cooldownsHalved(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/2" }) })); + } + else if (Permissions.cooldownsThirded(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/3" }) })); + } + else if (Permissions.cooldownsQuartered(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", new Object[] { "1/4" }) })); + } + } + + /** + * Display activiation perks. + */ + public void displayActivationPerks() { + if (Permissions.activationTwelve(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 12 }) })); + } + else if (Permissions.activationEight(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 8 }) })); + } + else if (Permissions.activationFour(player)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", new Object[] { 4 }) })); + } + } + + /** + * Display "lucky" perks. + */ + public void displayLuckyPerks() { + for (SkillType skill : SkillType.values()) { + if (Permissions.lucky(player, skill)) { + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc.login") })); + return; + } + } + } + + /** + * Display website info. + * @param website The plugin website + */ + public void displayWebsite(String website) { + player.sendMessage(LocaleLoader.getString("MOTD.Website", new Object[] {website})); + } +} diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index a52c03fbe..f8d968d36 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -17,6 +17,7 @@ import org.bukkit.plugin.PluginManager; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; @@ -89,6 +90,14 @@ public class Misc { return false; } + public static boolean isNPC(Player player, PlayerProfile profile) { + if (player == null || profile == null || player.hasMetadata("NPC")) { + return true; + } + + return false; + } + public static void sendSkillMessage(Player player, String message) { for (Player otherPlayer : player.getWorld().getPlayers()) { if (otherPlayer != player && Misc.isNear(player.getLocation(), otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {