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;
public final class HolidayManager {
public static ArrayList<String> hasCelebrated;
private static ArrayList<String> hasCelebrated;
private static final Random rand = new Random();
private HolidayManager() {}
@ -93,7 +93,11 @@ public final class HolidayManager {
if (hasCelebrated.contains(sender.getName())) {
return;
}
if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) {
return;
}
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!");
if (sender instanceof Player) {
@ -135,17 +139,17 @@ public final class HolidayManager {
* 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();
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));
@ -157,9 +161,9 @@ public final class HolidayManager {
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());
}
}
private static boolean getDateRange(Date date, Date start, Date end) {
return !(date.before(start) || date.after(end));
@ -195,38 +199,40 @@ public final class HolidayManager {
Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation().add(varX, 0, varZ), EntityType.FIREWORK);
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.setPower(power);
fireworks.setFireworkMeta(fireworkmeta);
}
private static List<Color> colorchoose() {
private static List<Color> colorChoose() {
// 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());
List<Color> choosencolors = allcolors.subList(0, numberofcolors);
int numberOfColors = rand.nextInt(ALL_COLORS.size());
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() {
StringBuilder ret = new StringBuilder(allchatcolors.get(rand.nextInt(allchatcolors.size())).toString());
for (int i = 0; i < chatFormats.length; i++) {
private static String chatColorChoose() {
StringBuilder ret = new StringBuilder(ALL_CHAT_COLORS.get(rand.nextInt(ALL_CHAT_COLORS.size())).toString());
for (ChatColor CHAT_FORMAT : CHAT_FORMATS) {
if (rand.nextInt(4) == 0) {
ret.append(chatFormats[i]);
ret.append(CHAT_FORMAT);
}
}
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 };
private static final List<Color> ALL_COLORS;
private static final List<ChatColor> ALL_CHAT_COLORS;
private static final ChatColor[] CHAT_FORMATS = new ChatColor[]{ChatColor.BOLD, ChatColor.ITALIC, ChatColor.UNDERLINE, ChatColor.STRIKETHROUGH};
static {
allcolors = Arrays.asList(
ALL_COLORS = Arrays.asList(
Color.AQUA,
Color.BLACK,
Color.BLUE,
@ -245,12 +251,12 @@ public final class HolidayManager {
Color.WHITE,
Color.YELLOW
);
allchatcolors = new ArrayList<ChatColor>(16);
ALL_CHAT_COLORS = new ArrayList<ChatColor>(16);
for (ChatColor c : ChatColor.values()) {
if (c.isColor()) {
allchatcolors.add(c);
ALL_CHAT_COLORS.add(c);
}
}
Collections.shuffle(allchatcolors, rand);
Collections.shuffle(ALL_CHAT_COLORS, rand);
}
}