Cleanup and formatting

This commit is contained in:
TfT_02 2013-10-01 22:14:29 +02:00
parent 288287badf
commit 6baf820afa

View File

@ -28,7 +28,7 @@ import org.bukkit.inventory.meta.FireworkMeta;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
public final class HolidayManager { public final class HolidayManager {
public static ArrayList<String> hasCelebrated; private static ArrayList<String> hasCelebrated;
private static final Random rand = new Random(); private static final Random rand = new Random();
private HolidayManager() {} private HolidayManager() {}
@ -93,22 +93,26 @@ 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 3 Year Anniversary! In honor of all of"); return;
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; sender.sendMessage(ChatColor.BLUE + "Happy 3 Year Anniversary! In honor of all of");
for (int i = 0; i < firework_amount; i++) { sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
int delay = (int) (rand.nextDouble() * 3 * 20) + 4; if (sender instanceof Player) {
mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() { final int firework_amount = 10;
@Override for (int i = 0; i < firework_amount; i++) {
public void run() { int delay = (int) (rand.nextDouble() * 3 * 20) + 4;
spawnFireworks((Player) sender); mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() {
} @Override
}, delay); public void run() {
} spawnFireworks((Player) sender);
}
}, delay);
} }
else { }
else {
/* /*
* Credit: http://www.geocities.com/spunk1111/ * Credit: http://www.geocities.com/spunk1111/
* (good luck finding that in 3 years heh) * (good luck finding that in 3 years heh)
@ -135,30 +139,30 @@ public final class HolidayManager {
* b i k * b i k
* b i k * b i k
*/ */
String colorA = chatcolorchoose(); String colorA = chatColorChoose();
String colorB = chatcolorchoose(); String colorB = chatColorChoose();
String colorC = chatcolorchoose(); String colorC = chatColorChoose();
String colorD = chatcolorchoose(); String colorD = chatColorChoose();
String colorE = chatcolorchoose(); String colorE = chatColorChoose();
String colorF = chatcolorchoose(); String colorF = chatColorChoose();
String colorG = chatcolorchoose(); String colorG = chatColorChoose();
String colorH = chatcolorchoose(); String colorH = chatColorChoose();
String colorI = chatcolorchoose(); String colorI = chatColorChoose();
String colorJ = chatcolorchoose(); String colorJ = chatColorChoose();
String colorK = chatcolorchoose(); String colorK = chatColorChoose();
Object[] colorParams = new Object[] { colorA, colorB, colorC, colorD, colorE, colorF, colorG, colorH, colorI, colorJ, colorK }; 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. %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(" %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: /\\ : %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:_\\/_:%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-= 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'..' %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* %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));
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) {
@ -195,62 +199,64 @@ public final class HolidayManager {
Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation().add(varX, 0, varZ), 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(rand.nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(rand.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);
} }
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); Collections.shuffle(ALL_COLORS, rand);
int numberofcolors = rand.nextInt(allcolors.size()); int numberOfColors = rand.nextInt(ALL_COLORS.size());
List<Color> choosencolors = allcolors.subList(0, numberofcolors); List<Color> choosenColors = ALL_COLORS.subList(0, numberOfColors);
return new ArrayList<Color>(choosencolors); // don't let caller modify allcolors return new ArrayList<Color>(choosenColors); // don't let caller modify ALL_COLORS
} }
private static String chatcolorchoose() { private static String chatColorChoose() {
StringBuilder ret = new StringBuilder(allchatcolors.get(rand.nextInt(allchatcolors.size())).toString()); StringBuilder ret = new StringBuilder(ALL_CHAT_COLORS.get(rand.nextInt(ALL_CHAT_COLORS.size())).toString());
for (int i = 0; i < chatFormats.length; i++) {
for (ChatColor CHAT_FORMAT : CHAT_FORMATS) {
if (rand.nextInt(4) == 0) { if (rand.nextInt(4) == 0) {
ret.append(chatFormats[i]); ret.append(CHAT_FORMAT);
} }
} }
return ret.toString(); return ret.toString();
} }
private static final List<Color> allcolors; private static final List<Color> ALL_COLORS;
private static final List<ChatColor> allchatcolors; private static final List<ChatColor> ALL_CHAT_COLORS;
private static final ChatColor[] chatFormats = new ChatColor[] { ChatColor.BOLD, ChatColor.ITALIC, ChatColor.UNDERLINE, ChatColor.STRIKETHROUGH }; private static final ChatColor[] CHAT_FORMATS = new ChatColor[]{ChatColor.BOLD, ChatColor.ITALIC, ChatColor.UNDERLINE, ChatColor.STRIKETHROUGH};
static { static {
allcolors = Arrays.asList( ALL_COLORS = Arrays.asList(
Color.AQUA, Color.AQUA,
Color.BLACK, Color.BLACK,
Color.BLUE, Color.BLUE,
Color.FUCHSIA, Color.FUCHSIA,
Color.GRAY, Color.GRAY,
Color.GREEN, Color.GREEN,
Color.LIME, Color.LIME,
Color.MAROON, Color.MAROON,
Color.NAVY, Color.NAVY,
Color.OLIVE, Color.OLIVE,
Color.ORANGE, Color.ORANGE,
Color.PURPLE, Color.PURPLE,
Color.RED, Color.RED,
Color.SILVER, Color.SILVER,
Color.TEAL, Color.TEAL,
Color.WHITE, Color.WHITE,
Color.YELLOW Color.YELLOW
); );
allchatcolors = new ArrayList<ChatColor>(16); ALL_CHAT_COLORS = new ArrayList<ChatColor>(16);
for (ChatColor c : ChatColor.values()) { for (ChatColor c : ChatColor.values()) {
if (c.isColor()) { if (c.isColor()) {
allchatcolors.add(c); ALL_CHAT_COLORS.add(c);
} }
} }
Collections.shuffle(allchatcolors, rand); Collections.shuffle(ALL_CHAT_COLORS, rand);
} }
} }