Mekanism-tilera-Edition/common/mekanism/client/HolidayManager.java

239 lines
5.8 KiB
Java
Raw Normal View History

2013-12-24 19:25:31 +01:00
package mekanism.client;
2013-12-24 02:23:23 +01:00
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import mekanism.api.EnumColor;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatMessageComponent;
public final class HolidayManager
{
private static Calendar calendar = Calendar.getInstance();
private static Minecraft mc = Minecraft.getMinecraft();
2013-12-24 02:23:23 +01:00
public static List<Holiday> holidays = new ArrayList<Holiday>();
private static List<Holiday> holidaysNotified = new ArrayList<Holiday>();
2013-12-24 02:23:23 +01:00
public static void init()
{
2013-12-24 19:25:31 +01:00
if(MekanismClient.holidays)
{
holidays.add(new Christmas());
holidays.add(new NewYear());
}
2013-12-24 02:23:23 +01:00
System.out.println("[Mekanism] Initialized HolidayManager.");
}
2013-12-24 02:23:23 +01:00
public static void check()
{
try {
YearlyDate date = getDate();
2013-12-24 02:23:23 +01:00
for(Holiday holiday : holidays)
{
if(!holidaysNotified.contains(holiday))
{
if(holiday.getDate().equals(date))
{
holiday.onEvent(mc.thePlayer);
holidaysNotified.add(holiday);
}
}
}
} catch(Exception e) {}
}
2013-12-24 19:25:31 +01:00
public static String filterSound(String sound)
{
if(!MekanismClient.holidays)
{
return sound;
}
2013-12-24 19:25:31 +01:00
try {
YearlyDate date = getDate();
2013-12-24 19:25:31 +01:00
for(Holiday holiday : holidays)
{
if(holiday.getDate().equals(date))
{
return holiday.filterSound(sound);
}
}
} catch(Exception e) {}
2013-12-24 19:25:31 +01:00
return sound;
}
2013-12-24 02:23:23 +01:00
private static YearlyDate getDate()
{
return new YearlyDate(calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH));
}
2013-12-24 02:23:23 +01:00
public static abstract class Holiday
{
public abstract YearlyDate getDate();
2013-12-24 02:23:23 +01:00
public abstract void onEvent(EntityPlayer player);
2013-12-24 19:25:31 +01:00
public String filterSound(String sound)
{
return sound;
}
2013-12-24 02:23:23 +01:00
}
2013-12-24 02:23:23 +01:00
private static class Christmas extends Holiday
{
2013-12-24 19:25:31 +01:00
private String[] nutcracker = new String[] {"holiday/Nutcracker1.ogg", "holiday/Nutcracker2.ogg", "holiday/Nutcracker3.ogg", "holiday/Nutcracker4.ogg", "holiday/Nutcracker5.ogg"};
2013-12-24 02:23:23 +01:00
@Override
public YearlyDate getDate()
{
return new YearlyDate(12, 25);
}
2013-12-24 02:23:23 +01:00
@Override
public void onEvent(EntityPlayer player)
{
String themedLines = getThemedLines(new EnumColor[] {EnumColor.DARK_GREEN, EnumColor.DARK_RED}, 13);
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[Mekanism]" + themedLines));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "Merry Christmas, " + EnumColor.DARK_BLUE + player.username + EnumColor.RED + "!"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "May you have plenty of Christmas cheer"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "and have a relaxing holiday with your"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "family :)"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_GREY + "-aidancbrady"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[=======]" + themedLines));
}
2013-12-24 19:25:31 +01:00
@Override
public String filterSound(String sound)
{
if(sound.equals("Chamber.ogg"))
{
return nutcracker[0];
}
else if(sound.equals("MetallurgicInfuser.ogg"))
{
return nutcracker[1];
}
else if(sound.equals("PurificationChamber.ogg"))
{
return nutcracker[2];
}
else if(sound.equals("Smelter.ogg"))
{
return nutcracker[3];
}
else if(sound.equals("HeatGenerator.ogg"))
{
return nutcracker[4];
}
2013-12-24 19:25:31 +01:00
return sound;
}
2013-12-24 02:23:23 +01:00
}
2013-12-24 02:23:23 +01:00
private static class NewYear extends Holiday
{
@Override
public YearlyDate getDate()
{
return new YearlyDate(1, 1);
}
2013-12-24 02:23:23 +01:00
@Override
public void onEvent(EntityPlayer player)
{
String themedLines = getThemedLines(new EnumColor[] {EnumColor.WHITE, EnumColor.YELLOW}, 13);
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[Mekanism]" + themedLines));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "Happy New Year, " + EnumColor.DARK_BLUE + player.username + EnumColor.RED + "!"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "Best wishes to you as we enter this"));
2013-12-24 22:06:57 +01:00
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "new and exciting year of " + calendar.get(Calendar.YEAR) + "! :)"));
2013-12-24 02:23:23 +01:00
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_GREY + "-aidancbrady"));
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[=======]" + themedLines));
}
}
2013-12-24 02:23:23 +01:00
public static enum Month
{
JANUARY("January"),
FEBRUARY("February"),
MARCH("March"),
APRIL("April"),
MAY("May"),
JUNE("June"),
JULY("July"),
AUGUST("August"),
SEPTEMBER("September"),
OCTOBER("October"),
NOVEMBER("November"),
2013-12-24 02:23:23 +01:00
DECEMBER("December");
2013-12-24 02:23:23 +01:00
private final String name;
2013-12-24 02:23:23 +01:00
private Month(String n)
{
name = n;
}
2013-12-24 02:23:23 +01:00
public String getName()
{
return name;
}
2013-12-24 02:23:23 +01:00
public int month()
{
return ordinal()+1;
}
}
2013-12-24 02:23:23 +01:00
public static class YearlyDate
{
public Month month;
2013-12-24 02:23:23 +01:00
public int day;
2013-12-24 02:23:23 +01:00
public YearlyDate(Month m, int d)
{
month = m;
day = d;
}
2013-12-24 02:23:23 +01:00
public YearlyDate(int m, int d)
{
this(Month.values()[m-1], d);
}
2013-12-24 02:23:23 +01:00
@Override
public boolean equals(Object obj)
{
return obj instanceof YearlyDate && ((YearlyDate)obj).month == month && ((YearlyDate)obj).day == day;
}
2013-12-24 02:23:23 +01:00
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + month.ordinal();
code = 31 * code + day;
return code;
}
}
2013-12-24 02:23:23 +01:00
private static String getThemedLines(EnumColor[] colors, int amount)
{
StringBuilder builder = new StringBuilder();
2013-12-24 02:23:23 +01:00
for(int i = 0; i < amount; i++)
{
builder.append(colors[i%colors.length] + "-");
}
2013-12-24 02:23:23 +01:00
return builder.toString();
}
}