Skip to content

Commit

Permalink
Use Canary's ToolBox to get the time.
Browse files Browse the repository at this point in the history
Also using updated UnoModding formatter.
  • Loading branch information
jamierocks committed Nov 22, 2014
1 parent dc8df44 commit ccf97ac
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PlayTimeLimiter

### What is it?

PlayTimeLimiter is a CanaryMod plugin for Minecraft servers to only allow players to limit the amount of time players spent on your server.
PlayTimeLimiter is a CanaryLib plugin for Minecraft servers to only allow players to limit the amount of time players spend on your server.

### Links

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<name>PlayTimeLimiter</name>
<url>https://github.com/UnoModding/Canary-PlayTimeLimiter</url>
<description>PlayTimeLimiter is a CanaryMod plugin for Minecraft servers to only allow players to limit the amount of time players spent on your server.</description>
<version>0.25</version>
<description>PlayTimeLimiter is a CanaryLib plugin for Minecraft servers to only allow players to limit the amount of time players spend on your server.</description>
<version>0.3</version>
<inceptionYear>2014</inceptionYear>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014 by RyanTheAlmighty, UnoModding and Contributors
* Copyright 2014 by UnoModding, RyanTheAlmighty and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
Expand All @@ -10,6 +10,7 @@

import net.canarymod.Canary;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.chat.Colors;
import net.canarymod.chat.MessageReceiver;
import net.canarymod.chat.TextFormat;
import net.canarymod.commandsys.Command;
Expand Down Expand Up @@ -42,9 +43,9 @@ public void baseCommand(MessageReceiver caller, String[] args) {
version = 2)
public void startCommand(MessageReceiver caller, String[] args) {
if (!plugin.start()) {
caller.message(TextFormat.RED + "Playtime already started!");
caller.message(Colors.RED + "Playtime already started!");
} else {
caller.message(TextFormat.RED + "Playtime started!");
caller.message(Colors.RED + "Playtime started!");
}
}

Expand All @@ -56,9 +57,9 @@ public void startCommand(MessageReceiver caller, String[] args) {
version = 2)
public void stopCommand(MessageReceiver caller, String[] args) {
if (!plugin.stop()) {
caller.message(TextFormat.RED + "Playtime already stopped!");
caller.message(Colors.RED + "Playtime already stopped!");
} else {
caller.message(TextFormat.RED + "Playtime stopped!");
caller.message(Colors.RED + "Playtime stopped!");
}
}

Expand All @@ -70,14 +71,14 @@ public void stopCommand(MessageReceiver caller, String[] args) {
version = 2)
public void checkCommand(MessageReceiver caller, String[] args) {
if (!plugin.hasStarted()) {
caller.message(TextFormat.RED + "Playtime hasn't started yet!");
caller.message(Colors.RED + "Playtime hasn't started yet!");
} else {
if (args.length == 0) {
if (!caller.hasPermission("playtimelimiter.playtime.check.self")) {
caller.message(TextFormat.RED + "You don't have permission to check your playtime!");
caller.message(Colors.RED + "You don't have permission to check your playtime!");
} else {
Player player = Canary.getServer().getPlayer(caller.getName());
caller.message(TextFormat.GREEN
caller.message(Colors.GREEN
+ "You have played for "
+ plugin.secondsToDaysHoursSecondsString(plugin.getPlayerPlayTime(player
.getUUIDString()))
Expand All @@ -87,11 +88,10 @@ public void checkCommand(MessageReceiver caller, String[] args) {
}
} else if (args.length == 1) {
if (!caller.hasPermission("playtimelimiter.playtime.check.others")) {
caller.message(TextFormat.RED
+ "You don't have permission to check other players playtime!");
caller.message(Colors.RED + "You don't have permission to check other players playtime!");
} else {
Player player = Canary.getServer().getPlayer(args[0]);
caller.message(TextFormat.GREEN
caller.message(Colors.GREEN
+ player.getName()
+ " has played for "
+ plugin.secondsToDaysHoursSecondsString(plugin.getPlayerPlayTime(player
Expand All @@ -112,19 +112,19 @@ public void checkCommand(MessageReceiver caller, String[] args) {
version = 2)
public void addCommand(MessageReceiver caller, String[] args) {
if (!plugin.hasStarted()) {
caller.message(TextFormat.RED + "Playtime hasn't started yet!");
caller.message(Colors.RED + "Playtime hasn't started yet!");
} else {
try {
plugin.addPlayTime(Canary.getServer().getPlayer(args[0]).getUUIDString(),
Integer.parseInt(args[1]));
caller.message(TextFormat.GREEN + "Added " + Integer.parseInt(args[1])
caller.message(Colors.GREEN + "Added " + Integer.parseInt(args[1])
+ " seconds of playtime from " + args[0]);
} catch (NumberFormatException e) {
e.printStackTrace();
caller.message(TextFormat.RED + "Invalid number of seconds given!");
caller.message(Colors.RED + "Invalid number of seconds given!");
} catch (UnknownPlayerException e) {
e.printStackTrace();
caller.message(TextFormat.RED + e.getMessage());
caller.message(Colors.RED + e.getMessage());
}
}
}
Expand All @@ -137,16 +137,16 @@ public void addCommand(MessageReceiver caller, String[] args) {
version = 2)
public void removeCommand(MessageReceiver caller, String[] args) {
if (!plugin.hasStarted()) {
caller.message(TextFormat.RED + "Playtime hasn't started yet!");
caller.message(Colors.RED + "Playtime hasn't started yet!");
} else {
try {
plugin.removePlayTime(Canary.getServer().getPlayer(args[0]).getUUIDString(),
Integer.parseInt(args[1]));
caller.message(TextFormat.GREEN + "Removed " + Integer.parseInt(args[1])
caller.message(Colors.GREEN + "Removed " + Integer.parseInt(args[1])
+ " seconds of playtime from " + args[0]);
} catch (NumberFormatException e) {
e.printStackTrace();
caller.message(TextFormat.RED + "Invalid number of seconds given!");
caller.message(Colors.RED + "Invalid number of seconds given!");
}
}
}
Expand All @@ -166,28 +166,28 @@ public List<String> playtimeTabComplete(MessageReceiver caller, String[] paramet
}

public void printUsage(MessageReceiver caller) {
caller.message(TextFormat.YELLOW + "/playtime usage:");
caller.message(Colors.YELLOW + "/playtime usage:");
if (caller.hasPermission("playtimelimiter.playtime.start")) {
caller.message(TextFormat.CYAN + "/playtime start" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime start" + TextFormat.RESET
+ " - Start the playtime counter.");
}
if (caller.hasPermission("playtimelimiter.playtime.stop")) {
caller.message(TextFormat.CYAN + "/playtime stop" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime stop" + TextFormat.RESET
+ " - Stop the playtime counter.");
}
if (caller.hasPermission("playtimelimiter.playtime.add")) {
caller.message(TextFormat.CYAN + "/playtime add <user> <time>" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime add <user> <time>" + TextFormat.RESET
+ " - Add time in seconds to the user's playtime.");
}
if (caller.hasPermission("playtimelimiter.playtime.check.others")) {
caller.message(TextFormat.CYAN + "/playtime check [user]" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime check [user]" + TextFormat.RESET
+ " - Check the time played and time left for a given user, or if blank, for yourself.");
} else if (caller.hasPermission("playtimelimiter.playtime.check.self")) {
caller.message(TextFormat.CYAN + "/playtime check" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime check" + TextFormat.RESET
+ " - Check the time played and time left for yourself.");
}
if (caller.hasPermission("playtimelimiter.playtime.remove")) {
caller.message(TextFormat.CYAN + "/playtime remove <user> <time>" + TextFormat.RESET
caller.message(Colors.CYAN + "/playtime remove <user> <time>" + TextFormat.RESET
+ " - Remove time in seconds from the user's playtime.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014 by RyanTheAlmighty, UnoModding and Contributors
* Copyright 2014 by UnoModding, RyanTheAlmighty and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
Expand All @@ -17,7 +17,7 @@
import java.util.Timer;

import net.canarymod.Canary;
import net.canarymod.chat.TextFormat;
import net.canarymod.chat.Colors;
import net.canarymod.commandsys.CommandDependencyException;
import net.canarymod.plugin.Plugin;
import unomodding.canary.playtimelimiter.exceptions.UnknownPlayerException;
Expand All @@ -37,10 +37,12 @@ public final class PlayTimeLimiter extends Plugin {
private boolean started = false;
private final Gson GSON = new Gson();

@Override
public void disable() {
this.savePlayTime(); // Save the playtime to file on plugin disable
}

@Override
public boolean enable() {
if (!getConfig().containsKey("timeStarted")) {
getConfig().setInt("timeStarted", (int) (System.currentTimeMillis() / 1000));
Expand Down Expand Up @@ -230,7 +232,7 @@ public boolean start() {
String initial = (getConfig().getInt("initialTime") / 60 / 60) + "";
String perday = (getConfig().getInt("timePerDay") / 60 / 60) + "";
Canary.getServer().broadcastMessage(
TextFormat.GREEN + "Playtime has now started! You have " + initial
Colors.GREEN + "Playtime has now started! You have " + initial
+ " hour/s of playtime to start with and " + perday
+ " hour/s of playtime added per day!");
getConfig().setInt("timeStarted", (int) (System.currentTimeMillis() / 1000));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014 by RyanTheAlmighty, UnoModding and Contributors
* Copyright 2014 by UnoModding, RyanTheAlmighty and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
Expand All @@ -8,6 +8,7 @@

import java.io.File;

import net.canarymod.chat.Colors;
import net.canarymod.chat.TextFormat;
import net.canarymod.hook.HookHandler;
import net.canarymod.hook.player.ConnectionHook;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void onPlayerJoin(ConnectionHook hook) {
}
hook.getPlayer().message(
"You have "
+ TextFormat.GREEN
+ Colors.GREEN
+ plugin.secondsToDaysHoursSecondsString(plugin.getTimeAllowedInSeconds(hook
.getPlayer().getUUIDString())) + TextFormat.RESET + " of playtime left!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014 by RyanTheAlmighty, UnoModding and Contributors
* Copyright 2014 by UnoModding, RyanTheAlmighty and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014 by RyanTheAlmighty, UnoModding and Contributors
* Copyright 2014 by UnoModding, RyanTheAlmighty and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
Expand All @@ -11,6 +11,7 @@

import net.canarymod.Canary;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.chat.Colors;
import net.canarymod.chat.TextFormat;
import unomodding.canary.playtimelimiter.PlayTimeLimiter;
import unomodding.canary.playtimelimiter.utils.FileUtils;
Expand All @@ -36,21 +37,21 @@ public void run() {
+ this.plugin.secondsToDaysHoursSecondsString(this.plugin.secondsUntilNextDay())
+ "!");
} else if (timeLeft <= 10 && !this.plugin.hasPlayerSeenMessage(player.getUUIDString(), 10)) {
player.message(TextFormat.RED
player.message(Colors.RED
+ "WARNING!"
+ TextFormat.RESET
+ " You have less than 10 seconds of playtime left! Stop what your doing and prepare to be disconnected!");
this.plugin.sentPlayerWarningMessage(player.getUUIDString(), 10);
} else if (timeLeft <= 60 && timeLeft > 10
&& !this.plugin.hasPlayerSeenMessage(player.getUUIDString(), 60)) {
player.message(TextFormat.RED
player.message(Colors.RED
+ "WARNING!"
+ TextFormat.RESET
+ " You have less than 60 seconds of playtime left! Stop what your doing and prepare to be disconnected!");
this.plugin.sentPlayerWarningMessage(player.getUUIDString(), 60);
} else if (timeLeft <= 300 && timeLeft > 60
&& !this.plugin.hasPlayerSeenMessage(player.getUUIDString(), 300)) {
player.message(TextFormat.RED
player.message(Colors.RED
+ "WARNING!"
+ TextFormat.RESET
+ " You have less than 5 minutes of playtime left! Stop what your doing and prepare to be disconnected!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
/**
* Copyright 2013-2014 by ATLauncher and Contributors
* Copyright 2013-2014 by UnoModding, ATLauncher and Contributors
*
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
*/
package unomodding.canary.playtimelimiter.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import net.canarymod.ToolBox;

public final class Timestamper {
private static final SimpleDateFormat format = new SimpleDateFormat("dd/M/yyy HH:mm:ss a");

public static String now() {
return format.format(new Date());
}

public static String was(Date date) {
return format.format(date);
return ToolBox.formatTimestamp(ToolBox.getUnixTimestamp());
}
}

0 comments on commit ccf97ac

Please sign in to comment.