Add holiday celebration for the console

This commit is contained in:
Kane York 2013-05-29 13:58:32 -04:00 committed by TfT_02
parent ca4feca073
commit 288287badf
2 changed files with 122 additions and 45 deletions

View File

@ -9,6 +9,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.party.PartySubcommandType; import com.gmail.nossr50.commands.party.PartySubcommandType;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.HolidayManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class McmmoCommand implements CommandExecutor { public class McmmoCommand implements CommandExecutor {
@ -31,6 +32,7 @@ public class McmmoCommand implements CommandExecutor {
} }
sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion())); sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion()));
HolidayManager.anniversaryCheck(sender);
return true; return true;
case 1: case 1:

View File

@ -7,10 +7,13 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Random;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
@ -26,6 +29,7 @@ import com.gmail.nossr50.mcMMO;
public final class HolidayManager { public final class HolidayManager {
public static ArrayList<String> hasCelebrated; public static ArrayList<String> hasCelebrated;
private static final Random rand = new Random();
private HolidayManager() {} private HolidayManager() {}
@ -78,9 +82,8 @@ public final class HolidayManager {
// This gets called from /mcmmo command // This gets called from /mcmmo command
public static void anniversaryCheck(final CommandSender sender) { public static void anniversaryCheck(final CommandSender sender) {
if (sender instanceof Player) { GregorianCalendar anniversaryStart = new GregorianCalendar(2014, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3); GregorianCalendar anniversaryEnd = new GregorianCalendar(2014, Calendar.FEBRUARY, 6);
GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6);
GregorianCalendar day = new GregorianCalendar(); GregorianCalendar day = new GregorianCalendar();
if (hasCelebrated == null) { if (hasCelebrated == null) {
@ -90,32 +93,83 @@ public final class HolidayManager {
if (hasCelebrated.contains(sender.getName())) { if (hasCelebrated.contains(sender.getName())) {
return; return;
} }
if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) { if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) {
sender.sendMessage(ChatColor.BLUE + "Happy 2 Year Anniversary! In honor of all of"); sender.sendMessage(ChatColor.BLUE + "Happy 3 Year Anniversary! In honor of all of");
sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!"); 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; final int firework_amount = 10;
for (int i = 0; i < firework_amount; i++) { for (int i = 0; i < firework_amount; i++) {
int delay = (int) (Math.random() * 3) + 4; int delay = (int) (rand.nextDouble() * 3 * 20) + 4;
mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() { mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() {
@Override @Override
public void run() { public void run() {
spawnFireworks((Player) sender); spawnFireworks((Player) sender);
} }
}, 20 * delay); }, delay);
}
}
else {
/*
* Credit: http://www.geocities.com/spunk1111/
* (good luck finding that in 3 years heh)
* .''. . *''* :_\/_: .
* :_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
* .''.: /\ : /)\ ':'* /\ * : '..'. -=:o:=-
* :_\/_:'.:::. ' *''* * '.\'/.'_\(/_ '.':'.'
* : /\ : ::::: *_\/_* -= o =- /)\ '
* '..' ':::' * /\ * .'/.\'. ' *
* * *..* : *
* * * *
* * * *
*/
/*
* Color map
* AAAA D GGGG JJJJJJ K
* AAAAAA DDDDD EEEGGGGGG JJJJJJ KKKKKKK
* BBBBAAAAAA DDD EEEGGGGGG I JJJJJ KKKKKKK
* BBBBBBACCCCC D FFFF G IIIIIIIHHHHH KKKKKKK
* BBBBBB CCCCC FFFFFF IIIIIII HHH K
* BBBB CCCCC FFFFFF IIIIIII H k
* b FFFF I k
* b i k
* b i k
*/
String colorA = chatcolorchoose();
String colorB = chatcolorchoose();
String colorC = chatcolorchoose();
String colorD = chatcolorchoose();
String colorE = chatcolorchoose();
String colorF = chatcolorchoose();
String colorG = chatcolorchoose();
String colorH = chatcolorchoose();
String colorI = chatcolorchoose();
String colorJ = chatcolorchoose();
String colorK = chatcolorchoose();
Object[] colorParams = new Object[] { colorA, colorB, colorC, colorD, colorE, colorF, colorG, colorH, colorI, colorJ, colorK };
sender.sendMessage(String.format(" %1$s.''. %4$s. %7$s*''* %10$s:_\\/_: %11$s.", colorParams));
sender.sendMessage(String.format(" %1$s:_\\/_: %4$s_\\(/_ %5$s.:.%7$s*_\\/_* %10$s: /\\ : %11$s.'.:.'.", colorParams));
sender.sendMessage(String.format(" %2$s.''.%1$s: /\\ : %4$s/)\\ %5$s':'%7$s* /\\ * %9$s: %10$s'..'. %11$s-=:o:=-", colorParams));
sender.sendMessage(String.format("%2$s:_\\/_:%1$s'%3$s.:::. %4$s' %6$s*''* %7$s* %9$s'.\\'/.'%8$s_\\(/_ %11$s'.':'.'", colorParams));
sender.sendMessage(String.format("%2$s: /\\ : %3$s::::: %6$s*_\\/_* %9$s-= o =-%8$s /)\\ %11$s'", colorParams));
sender.sendMessage(String.format(" %2$s'..' %3$s':::' %6$s* /\\ * %9$s.'/.\\'. %8$s' %11$s*", colorParams));
sender.sendMessage(String.format(" %2$s* %6$s*..* %9$s: %11$s*", colorParams));
sender.sendMessage(String.format(" %2$s* %9$s* %11$s*", colorParams));
sender.sendMessage(String.format(" %2$s* %9$s* %11$s*", colorParams));
} }
hasCelebrated.add(sender.getName()); hasCelebrated.add(sender.getName());
} }
} }
}
private static boolean getDateRange(Date date, Date start, Date end) { private static boolean getDateRange(Date date, Date start, Date end) {
return !(date.before(start) || date.after(end)); return !(date.before(start) || date.after(end));
} }
private static void spawnFireworks(Player player) { private static void spawnFireworks(Player player) {
int power = (int) (Math.random() * 3) + 1; int power = (int) (rand.nextDouble() * 3) + 1;
int type = (int) (Math.random() * 5) + 1; int type = (int) (rand.nextDouble() * 5) + 1;
double varX = rand.nextGaussian() * 3;
double varZ = rand.nextGaussian() * 3;
Type typen; Type typen;
switch (type) { switch (type) {
@ -139,9 +193,9 @@ public final class HolidayManager {
typen = Type.BALL; typen = Type.BALL;
} }
Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK); Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation().add(varX, 0, varZ), EntityType.FIREWORK);
FireworkMeta fireworkmeta = fireworks.getFireworkMeta(); FireworkMeta fireworkmeta = fireworks.getFireworkMeta();
FireworkEffect effect = FireworkEffect.builder().flicker(Misc.getRandom().nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(Misc.getRandom().nextBoolean()).build(); FireworkEffect effect = FireworkEffect.builder().flicker(rand.nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(rand.nextBoolean()).build();
fireworkmeta.addEffect(effect); fireworkmeta.addEffect(effect);
fireworkmeta.setPower(power); fireworkmeta.setPower(power);
fireworks.setFireworkMeta(fireworkmeta); fireworks.setFireworkMeta(fireworkmeta);
@ -149,33 +203,54 @@ public final class HolidayManager {
private static List<Color> colorchoose() { private static List<Color> colorchoose() {
// Thanks Zomis and Tejpbit for the help with this function! // Thanks Zomis and Tejpbit for the help with this function!
Collections.shuffle(allcolors, rand);
int numberofcolors = Misc.getRandom().nextInt(17) + 1; int numberofcolors = rand.nextInt(allcolors.size());
List<Color> choosencolors = allcolors.subList(0, numberofcolors);
List<Color> allcolors = new ArrayList<Color>(); return new ArrayList<Color>(choosencolors); // don't let caller modify allcolors
allcolors.add(Color.AQUA);
allcolors.add(Color.BLACK);
allcolors.add(Color.BLUE);
allcolors.add(Color.FUCHSIA);
allcolors.add(Color.GRAY);
allcolors.add(Color.GREEN);
allcolors.add(Color.LIME);
allcolors.add(Color.MAROON);
allcolors.add(Color.NAVY);
allcolors.add(Color.OLIVE);
allcolors.add(Color.ORANGE);
allcolors.add(Color.PURPLE);
allcolors.add(Color.RED);
allcolors.add(Color.SILVER);
allcolors.add(Color.TEAL);
allcolors.add(Color.WHITE);
allcolors.add(Color.YELLOW);
List<Color> choosencolors = new ArrayList<Color>();
for (int i = 0; i < numberofcolors; i++) {
choosencolors.add(allcolors.remove(Misc.getRandom().nextInt(allcolors.size())));
} }
return choosencolors;
private static String chatcolorchoose() {
StringBuilder ret = new StringBuilder(allchatcolors.get(rand.nextInt(allchatcolors.size())).toString());
for (int i = 0; i < chatFormats.length; i++) {
if (rand.nextInt(4) == 0) {
ret.append(chatFormats[i]);
}
}
return ret.toString();
}
private static final List<Color> allcolors;
private static final List<ChatColor> allchatcolors;
private static final ChatColor[] chatFormats = new ChatColor[] { ChatColor.BOLD, ChatColor.ITALIC, ChatColor.UNDERLINE, ChatColor.STRIKETHROUGH };
static {
allcolors = Arrays.asList(
Color.AQUA,
Color.BLACK,
Color.BLUE,
Color.FUCHSIA,
Color.GRAY,
Color.GREEN,
Color.LIME,
Color.MAROON,
Color.NAVY,
Color.OLIVE,
Color.ORANGE,
Color.PURPLE,
Color.RED,
Color.SILVER,
Color.TEAL,
Color.WHITE,
Color.YELLOW
);
allchatcolors = new ArrayList<ChatColor>(16);
for (ChatColor c : ChatColor.values()) {
if (c.isColor()) {
allchatcolors.add(c);
}
}
Collections.shuffle(allchatcolors, rand);
} }
} }