From e1b8088c17360ee7a15ff88955be96aa33300332 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Tue, 1 Apr 2014 15:36:40 +0200 Subject: [PATCH] Improve holiday manager with 1.7 changes --- .../nossr50/listeners/PlayerListener.java | 10 +++ .../nossr50/runnables/skills/AprilTask.java | 9 +-- .../gmail/nossr50/util/HolidayManager.java | 72 +++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 1c39d141e..fa03c0ecb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -24,6 +24,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerStatisticIncrementEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; @@ -694,4 +695,13 @@ public class PlayerListener implements Listener { } } } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerStatisticIncrementEvent(PlayerStatisticIncrementEvent event) { + if (!mcMMO.getHolidayManager().isAprilFirst()) { + return; + } + + mcMMO.getHolidayManager().handleStatisticEvent(event); + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AprilTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AprilTask.java index 748cf3c1b..7472c026a 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AprilTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AprilTask.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.runnables.skills; import org.bukkit.ChatColor; import org.bukkit.Sound; +import org.bukkit.Statistic; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -19,6 +20,7 @@ public class AprilTask extends BukkitRunnable { } for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { + int random = Misc.getRandom().nextInt(40) + 11; int betterRandom = Misc.getRandom().nextInt(2000); if (betterRandom == 0) { player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH); @@ -26,10 +28,9 @@ public class AprilTask extends BukkitRunnable { fireworksShow(player); } - for (HolidayManager.FakeSkillType fakeSkillType : HolidayManager.FakeSkillType.values()) { - int random = Misc.getRandom().nextInt(250); - if (random == 0) { - mcMMO.getHolidayManager().levelUpApril(player, fakeSkillType); + for (Statistic statistic : mcMMO.getHolidayManager().movementStatistics) { + if (player.getStatistic(statistic) > 0 && player.getStatistic(statistic) % random == 0) { + mcMMO.getHolidayManager().levelUpApril(player, HolidayManager.FakeSkillType.getByStatistic(statistic)); break; } } diff --git a/src/main/java/com/gmail/nossr50/util/HolidayManager.java b/src/main/java/com/gmail/nossr50/util/HolidayManager.java index 982bf23f1..c17e14f29 100644 --- a/src/main/java/com/gmail/nossr50/util/HolidayManager.java +++ b/src/main/java/com/gmail/nossr50/util/HolidayManager.java @@ -10,8 +10,10 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.GregorianCalendar; import java.util.List; +import java.util.Set; import java.util.regex.Pattern; import org.bukkit.ChatColor; @@ -20,11 +22,13 @@ import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.Sound; +import org.bukkit.Statistic; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerStatisticIncrementEvent; import org.bukkit.inventory.meta.FireworkMeta; import com.gmail.nossr50.mcMMO; @@ -67,8 +71,45 @@ public final class HolidayManager { } return null; } + + public static FakeSkillType getByStatistic(Statistic statistic) { + switch (statistic) { + case DAMAGE_TAKEN: + return FakeSkillType.MACHO; + case JUMP: + return FakeSkillType.JUMPING; + case DROP: + return FakeSkillType.THROWING; + case MINE_BLOCK: + case BREAK_ITEM: + return FakeSkillType.WRECKING; + case CRAFT_ITEM: + return FakeSkillType.CRAFTING; + case WALK_ONE_CM: + return FakeSkillType.WALKING; + case SWIM_ONE_CM: + return FakeSkillType.SWIMMING; + case FALL_ONE_CM: + return FakeSkillType.FALLING; + case CLIMB_ONE_CM: + return FakeSkillType.CLIMBING; + case FLY_ONE_CM: + return FakeSkillType.FLYING; + case DIVE_ONE_CM: + return FakeSkillType.DIVING; + case PIG_ONE_CM: + return FakeSkillType.PIGGY; + default: + return FakeSkillType.UNKNOWN; + } + } } + public final Set movementStatistics = EnumSet.of( + Statistic.WALK_ONE_CM, Statistic.SWIM_ONE_CM, Statistic.FALL_ONE_CM, + Statistic.CLIMB_ONE_CM, Statistic.FLY_ONE_CM, Statistic.DIVE_ONE_CM, + Statistic.PIG_ONE_CM); + static { List colors = new ArrayList(); List chatColors = new ArrayList(); @@ -301,6 +342,37 @@ public final class HolidayManager { return mcMMO.getHolidayManager().getDateRange(day.getTime(), start.getTime(), end.getTime()); } + public void handleStatisticEvent(PlayerStatisticIncrementEvent event) {Player player = event.getPlayer(); + Statistic statistic = event.getStatistic(); + int newValue = event.getNewValue(); + + int modifier; + switch (statistic) { + case DAMAGE_TAKEN: + modifier = 500; + break; + case JUMP: + modifier = 500; + break; + case DROP: + modifier = 200; + break; + case MINE_BLOCK: + case BREAK_ITEM: + modifier = 500; + break; + case CRAFT_ITEM: + modifier = 100; + break; + default: + return; + } + + if (newValue % modifier == 0) { + mcMMO.p.getHolidayManager().levelUpApril(player, FakeSkillType.getByStatistic(statistic)); + } + } + public void levelUpApril(Player player, FakeSkillType fakeSkillType) { int levelTotal = Misc.getRandom().nextInt(UserManager.getPlayer(player).getSkillLevel(SkillType.MINING)) + 1; player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);