summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/signs/SignTime.java
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/signs/SignTime.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTime.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTime.java b/Essentials/src/com/earth2me/essentials/signs/SignTime.java
new file mode 100644
index 000000000..845cfbcca
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTime.java
@@ -0,0 +1,57 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+
+
+public class SignTime extends EssentialsSign
+{
+ public SignTime()
+ {
+ super("Time");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ validateCharge(sign, 2);
+ final String timeString = sign.getLine(1);
+ if ("Day".equalsIgnoreCase(timeString))
+ {
+ sign.setLine(1, "§2Day");
+ return true;
+ }
+ if ("Night".equalsIgnoreCase(timeString))
+ {
+ sign.setLine(1, "§2Night");
+ return true;
+ }
+ throw new SignException(Util.i18n("onlyDayNight"));
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ final Charge charge = getCharge(sign, 2, ess);
+ charge.isAffordableFor(player);
+ final String timeString = sign.getLine(1);
+ long time = player.getWorld().getTime();
+ time -= time % 24000;
+ if ("§2Day".equalsIgnoreCase(timeString))
+ {
+ player.getWorld().setTime(time + 24000);
+ charge.charge(player);
+ return true;
+ }
+ if ("§2Night".equalsIgnoreCase(timeString))
+ {
+ player.getWorld().setTime(time + 37700);
+ charge.charge(player);
+ return true;
+ }
+ throw new SignException(Util.i18n("onlyDayNight"));
+ }
+}