mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Fixed some issues with the HolidayManager
Was severely lacking more lols
This commit is contained in:
parent
8256f5461c
commit
beab794c0e
@ -0,0 +1,205 @@
|
||||
package com.gmail.nossr50.commands.skills;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.HolidayManager.FakeSkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class AprilCommand implements TabExecutor {
|
||||
private String skillName;
|
||||
|
||||
protected DecimalFormat percent = new DecimalFormat("##0.00%");
|
||||
protected DecimalFormat decimal = new DecimalFormat("##0.00");
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (CommandUtils.noConsoleUsage(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
skillName = StringUtils.getCapitalized(label);
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
Player player = (Player) sender;
|
||||
FakeSkillType fakeSkillType = FakeSkillType.getByName(skillName);
|
||||
|
||||
float skillValue = Misc.getRandom().nextInt(99);
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.XPGain", getXPGainString(fakeSkillType)));
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, Misc.getRandom().nextInt(1000), 1000 + Misc.getRandom().nextInt(1000)));
|
||||
|
||||
|
||||
List<String> effectMessages = effectsDisplay(fakeSkillType);
|
||||
|
||||
if (!effectMessages.isEmpty()) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
|
||||
|
||||
for (String message : effectMessages) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> statsMessages = statsDisplay(fakeSkillType);
|
||||
|
||||
if (!statsMessages.isEmpty()) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
|
||||
|
||||
for (String message : statsMessages) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.formatString("[[DARK_AQUA]]Guide for {0} available - type /APRIL FOOLS ! :D", skillName));
|
||||
return true;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private String getXPGainString(FakeSkillType fakeSkillType) {
|
||||
switch (fakeSkillType) {
|
||||
case MACHO:
|
||||
return "Get beaten up";
|
||||
case JUMPING:
|
||||
return "Kris Kross will make ya Jump Jump";
|
||||
case THROWING:
|
||||
return "Chuck your items on the floor";
|
||||
case WRECKING:
|
||||
return "I'M GONNA WRECK IT!";
|
||||
case CRAFTING:
|
||||
return "Craft apple pies";
|
||||
case WALKING:
|
||||
return "Walk around the park";
|
||||
case SWIMMING:
|
||||
return "Like a fish on a bicycle";
|
||||
case FALLING:
|
||||
return "Faceplant the floor, headbutt the ground";
|
||||
case CLIMBING:
|
||||
return "Climb the highest mountain";
|
||||
case FLYING:
|
||||
return "I believe I can fly";
|
||||
case DIVING:
|
||||
return "Scuba club 4000";
|
||||
case PIGGY:
|
||||
return "OINK! OINK!";
|
||||
default:
|
||||
return "Sit and wait?";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
return ImmutableList.of("?");
|
||||
default:
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> effectsDisplay(FakeSkillType fakeSkillType) {
|
||||
List<String> messages = new ArrayList<String>();
|
||||
|
||||
switch (fakeSkillType) {
|
||||
case MACHO:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Punching bag", "Absorb damage, like a bag of sand"));
|
||||
break;
|
||||
case JUMPING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Jump", "PRESS SPACE TO JUMP"));
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Jump Twice", "PRESS SPACE TWICE TO JUMP TWICE"));
|
||||
break;
|
||||
case THROWING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Drop Item", "Randomly drop items, at random"));
|
||||
break;
|
||||
case WRECKING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Ralphinator", "Smash windows with your fists"));
|
||||
break;
|
||||
case CRAFTING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Crafting", "Chance of successful craft"));
|
||||
break;
|
||||
case WALKING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Walk", "Traveling gracefully by foot"));
|
||||
break;
|
||||
case SWIMMING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Swim", "Just keep swimming, swimming, swimming"));
|
||||
break;
|
||||
case FALLING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Skydiving", "Go jump of a cliff. No, seriously."));
|
||||
break;
|
||||
case CLIMBING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Rock Climber", "Use string to climb mountains faster"));
|
||||
break;
|
||||
case FLYING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Fly", "Throw yourself at the ground and miss"));
|
||||
break;
|
||||
case DIVING:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Hold Breath", "Press shift to hold your breath longer"));
|
||||
break;
|
||||
case PIGGY:
|
||||
messages.add(LocaleLoader.getString("Effects.Template", "Carrot Turbo", "Supercharge your pigs with carrots"));
|
||||
break;
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
private List<String> statsDisplay(FakeSkillType fakeSkillType) {
|
||||
List<String> messages = new ArrayList<String>();
|
||||
|
||||
switch (fakeSkillType) {
|
||||
case MACHO:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Damage Taken: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(77))));
|
||||
break;
|
||||
case JUMPING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Double Jump Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case THROWING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Drop Item Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(87))));
|
||||
break;
|
||||
case WRECKING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Wrecking Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(14))));
|
||||
break;
|
||||
case CRAFTING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Crafting Success: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case WALKING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Walk Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case SWIMMING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Swim Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case FALLING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Skydiving Success: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(37))));
|
||||
break;
|
||||
case CLIMBING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Rock Climber Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case FLYING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Fly Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case DIVING:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Hold Breath Chance: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(27))));
|
||||
break;
|
||||
case PIGGY:
|
||||
messages.add(LocaleLoader.formatString("[[RED]]Carrot Turbo Boost: [[YELLOW]]{0}%", decimal.format(Misc.getRandom().nextInt(80)) + 10));
|
||||
break;
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ import com.gmail.nossr50.listeners.WorldListener;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.metrics.MetricsManager;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.runnables.CheckDateTask;
|
||||
import com.gmail.nossr50.runnables.SaveTimerTask;
|
||||
import com.gmail.nossr50.runnables.backups.CleanBackupsTask;
|
||||
import com.gmail.nossr50.runnables.database.UserPurgeTask;
|
||||
@ -477,6 +478,10 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
// Update power level tag scoreboards
|
||||
new PowerLevelUpdatingTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
|
||||
|
||||
if (getHolidayManager().nearingAprilFirst()) {
|
||||
new CheckDateTask().runTaskTimer(this, 10L * Misc.TICK_CONVERSION_FACTOR, 1L * 60L * 60L * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkModConfigs() {
|
||||
|
24
src/main/java/com/gmail/nossr50/runnables/CheckDateTask.java
Normal file
24
src/main/java/com/gmail/nossr50/runnables/CheckDateTask.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.runnables.skills.AprilTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class CheckDateTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mcMMO.getHolidayManager().isAprilFirst()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up jokes
|
||||
new AprilTask().runTaskTimer(mcMMO.p, 1L * 60L * Misc.TICK_CONVERSION_FACTOR, 10L * 60L * Misc.TICK_CONVERSION_FACTOR);
|
||||
mcMMO.getHolidayManager().registerAprilCommand();
|
||||
|
||||
// Jokes deployed.
|
||||
this.cancel();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.gmail.nossr50.runnables.skills;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.HolidayManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class AprilTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mcMMO.getHolidayManager().isAprilFirst()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||
int betterRandom = Misc.getRandom().nextInt(2000);
|
||||
if (betterRandom == 0) {
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);
|
||||
player.sendMessage(unknown("superskill") + " skill increased by 1. Total (" + unknown("12") + ")");
|
||||
fireworksShow(player);
|
||||
}
|
||||
|
||||
for (HolidayManager.FakeSkillType fakeSkillType : HolidayManager.FakeSkillType.values()) {
|
||||
int random = Misc.getRandom().nextInt(250);
|
||||
if (random == 0) {
|
||||
mcMMO.getHolidayManager().levelUpApril(player, fakeSkillType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fireworksShow(final Player player) {
|
||||
final int firework_amount = 10;
|
||||
for (int i = 0; i < firework_amount; i++) {
|
||||
int delay = (int) (Misc.getRandom().nextDouble() * 3 * Misc.TICK_CONVERSION_FACTOR) + 4;
|
||||
mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mcMMO.getHolidayManager().spawnFireworks(player);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
|
||||
private String unknown(String string) {
|
||||
return ChatColor.MAGIC + string + ChatColor.RESET + ChatColor.YELLOW;
|
||||
}
|
||||
}
|
@ -19,25 +19,56 @@ import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
import org.bukkit.Sound;
|
||||
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.inventory.meta.FireworkMeta;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.skills.AprilCommand;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public final class HolidayManager {
|
||||
private ArrayList<String> hasCelebrated;
|
||||
private int currentYear;
|
||||
private final int startYear = 2011;
|
||||
private static final int START_YEAR = 2011;
|
||||
|
||||
private static final List<Color> ALL_COLORS;
|
||||
private static final List<ChatColor> ALL_CHAT_COLORS;
|
||||
private static final List<ChatColor> CHAT_FORMATS;
|
||||
|
||||
public enum FakeSkillType {
|
||||
MACHO,
|
||||
JUMPING,
|
||||
THROWING,
|
||||
WRECKING,
|
||||
CRAFTING,
|
||||
WALKING,
|
||||
SWIMMING,
|
||||
FALLING,
|
||||
CLIMBING,
|
||||
FLYING,
|
||||
DIVING,
|
||||
PIGGY,
|
||||
UNKNOWN;
|
||||
|
||||
public static FakeSkillType getByName(String skillName) {
|
||||
for (FakeSkillType type : values()) {
|
||||
if (type.name().equalsIgnoreCase(skillName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
List<Color> colors = new ArrayList<Color>();
|
||||
List<ChatColor> chatColors = new ArrayList<ChatColor>();
|
||||
@ -165,7 +196,7 @@ public final class HolidayManager {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.BLUE + "Happy " + (currentYear - startYear) + " Year Anniversary! In honor of all of");
|
||||
sender.sendMessage(ChatColor.BLUE + "Happy " + (currentYear - START_YEAR) + " Year Anniversary! In honor of all of");
|
||||
sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
|
||||
if (sender instanceof Player) {
|
||||
final int firework_amount = 10;
|
||||
@ -221,11 +252,11 @@ public final class HolidayManager {
|
||||
hasCelebrated.add(sender.getName());
|
||||
}
|
||||
|
||||
private boolean getDateRange(Date date, Date start, Date end) {
|
||||
public boolean getDateRange(Date date, Date start, Date end) {
|
||||
return !(date.before(start) || date.after(end));
|
||||
}
|
||||
|
||||
private void spawnFireworks(Player player) {
|
||||
public void spawnFireworks(Player player) {
|
||||
int power = Misc.getRandom().nextInt(3) + 1;
|
||||
Type fireworkType = Type.values()[Misc.getRandom().nextInt(Type.values().length)];
|
||||
double varX = Misc.getRandom().nextGaussian() * 3;
|
||||
@ -254,4 +285,31 @@ public final class HolidayManager {
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public boolean isAprilFirst() {
|
||||
GregorianCalendar aprilFirst = new GregorianCalendar(currentYear, Calendar.APRIL, 1);
|
||||
GregorianCalendar aprilSecond = new GregorianCalendar(currentYear, Calendar.APRIL, 2);
|
||||
GregorianCalendar day = new GregorianCalendar();
|
||||
return getDateRange(day.getTime(), aprilFirst.getTime(), aprilSecond.getTime());
|
||||
}
|
||||
|
||||
public boolean nearingAprilFirst() {
|
||||
GregorianCalendar start = new GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), Calendar.MARCH, 28);
|
||||
GregorianCalendar end = new GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), Calendar.APRIL, 2);
|
||||
GregorianCalendar day = new GregorianCalendar();
|
||||
|
||||
return mcMMO.getHolidayManager().getDateRange(day.getTime(), start.getTime(), end.getTime());
|
||||
}
|
||||
|
||||
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);
|
||||
player.sendMessage(ChatColor.YELLOW + StringUtils.getCapitalized(fakeSkillType.toString()) + " skill increased by 1. Total (" + levelTotal + ")");
|
||||
ParticleEffectUtils.fireworkParticleShower(player, ALL_COLORS.get(Misc.getRandom().nextInt(ALL_COLORS.size())));
|
||||
}
|
||||
|
||||
public void registerAprilCommand() {
|
||||
PluginCommand command = mcMMO.p.getCommand("mcfools");
|
||||
command.setExecutor(new AprilCommand());
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,9 @@ commands:
|
||||
kraken:
|
||||
aliases: [mckraken]
|
||||
description: Unleash the kraken!
|
||||
mcfools:
|
||||
aliases: [macho, jumping, throwing, wrecking, crafting, walking, swimming, falling, climbing, flying, diving, piggy]
|
||||
description: Deploy jokes
|
||||
permissions:
|
||||
mcmmo.*:
|
||||
default: false
|
||||
|
Loading…
Reference in New Issue
Block a user