Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/main/java/net/quetzi/morpheus/helpers/DateHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.quetzi.morpheus.helpers;

import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.quetzi.morpheus.Morpheus;

Expand All @@ -12,20 +15,22 @@ public class DateHandler
{
public enum Event
{
XMAS(25, 12, TextFormatting.RED + References.XMASTEXT),
NEW_YEAR(1, 1, TextFormatting.GOLD + References.NEWYEARTEXT),
STPATRICKS(17, 3, TextFormatting.DARK_GREEN + References.STPATRICKSTEXT),
HALLOWEEN(31, 10, TextFormatting.DARK_PURPLE + References.HALLOWEENTEXT),
NONE(0, 0, TextFormatting.GOLD + Morpheus.onMorningText);
XMAS(25, 12, new Style().setColor(TextFormatting.RED), References.XMASTEXT),
NEW_YEAR(1, 1, new Style().setColor(TextFormatting.GOLD), References.NEWYEARTEXT),
STPATRICKS(17, 3, new Style().setColor(TextFormatting.DARK_GREEN), References.STPATRICKSTEXT),
HALLOWEEN(31, 10, new Style().setColor(TextFormatting.DARK_PURPLE), References.HALLOWEENTEXT),
NONE(0, 0, new Style().setColor(TextFormatting.GOLD), Morpheus.onMorningText);

private final int month;
private final int day;
private final Style style;
private final String text;

Event(int day, int month, String text)
Event(int day, int month, Style style, String text)
{
this.month = month;
this.day = day;
this.style = style;
this.text = text;
}

Expand All @@ -47,8 +52,9 @@ private static Event getEvent(Calendar calendar)
return Event.NONE;
}

public static String getMorningText()
public static ITextComponent getMorningTextComponent()
{
return getEvent(Calendar.getInstance()).text;
DateHandler.Event event = getEvent(Calendar.getInstance());
return new TextComponentString(event.text).setStyle(event.style);
}
}
15 changes: 11 additions & 4 deletions src/main/java/net/quetzi/morpheus/helpers/SleepChecker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.quetzi.morpheus.helpers;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
Expand Down Expand Up @@ -53,7 +55,7 @@ else if (!player.isPlayerFullyAsleep() && Morpheus.playerSleepStatus.get(player.
}
}

private void alertPlayers(TextComponentString alert, World world)
private void alertPlayers(ITextComponent alert, World world)
{
if ((alert != null) && (Morpheus.isAlertEnabled()))
{
Expand All @@ -64,10 +66,15 @@ private void alertPlayers(TextComponentString alert, World world)
}
}

private TextComponentString createAlert(int dimension, String username, String text)
private ITextComponent createAlert(int dimension, String username, String text)
{
Morpheus.mLog.info(String.format("%s %s %s", username, text, Morpheus.playerSleepStatus.get(dimension).toString()));
return new TextComponentString(String.format("%s%s%s %s %s", TextFormatting.WHITE, username, TextFormatting.GOLD, text, Morpheus.playerSleepStatus.get(dimension).toString()));
ITextComponent toSend = new TextComponentString(username).setStyle(new Style().setColor(TextFormatting.WHITE))
.appendSibling(new TextComponentString(" "))
.appendSibling(new TextComponentString(text).setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentString(" "))
.appendSibling(new TextComponentString(Morpheus.playerSleepStatus.get(dimension).toString()));
return toSend;
}

private void advanceToMorning(World world)
Expand All @@ -83,7 +90,7 @@ private void advanceToMorning(World world)
if (!alertSent.get(world.provider.getDimension()))
{
// Send Good morning message
alertPlayers(new TextComponentString(DateHandler.getMorningText()), world);
alertPlayers(DateHandler.getMorningTextComponent(), world);
Morpheus.playerSleepStatus.get(world.provider.getDimension()).wakeAllPlayers();
alertSent.put(world.provider.getDimension(), true);
}
Expand Down