-
Notifications
You must be signed in to change notification settings - Fork 1
Get with the times
Hempfest edited this page May 19, 2021
·
2 revisions
public final class ExamplePlugin extends BukkitCommand {
protected ExamplePlugin() {
super("test");
}
private final ConcurrentMap<UUID, Date> playerTime = new MapMaker().weakKeys().weakValues().makeMap();
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!(sender instanceof Player)) {
return true;
}
Player p = (Player) sender;
Message msg = new Message(p);
if (args.length == 0) {
if (!playerTime.containsKey(p.getUniqueId())) {
playerTime.put(p.getUniqueId(), new Date());
}
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("check")) {
if (playerTime.containsKey(p.getUniqueId())) {
if (TimeUtils.isHoursSince(playerTime.get(p.getUniqueId()), 2)) {
msg.send("2 or MORE hours has passed");
} else {
msg.send("2 hours has NOT passed");
}
if (TimeUtils.isMinutesSince(playerTime.get(p.getUniqueId()), 5)) {
msg.send("5 or MORE minutes has passed");
} else {
msg.send("5 minutes has NOT passed");
}
if (TimeUtils.isSecondsSince(playerTime.get(p.getUniqueId()), 25)) {
msg.send("25 or MORE seconds has passed");
} else {
msg.send("25 seconds has NOT passed");
}
}
return true;
}
}
return false;
}
}
public class TestClass {
private final Date date;
public TestClass() {
this.date = new Date(System.nanoTime());
}
public boolean isBetween(TimeUnit unit, long time) {
return TimeWatch.start(date.getTime()).hasElapsed(unit, time);
}
}
public void t() {
TestClass c = new TestClass();
if (c.isBetween(TimeUnit.SECONDS, 5)) {
JavaPlugin pl = JavaPlugin.getProvidingPlugin(getClass());
pl.getLogger().info("- Yo! The time is correct, were spot on.");
}
}
Utility "TimeUtils.java"
-
- AFK Player Utility
- Command Builder
- Command Utility
- Complete GUI Builder
- Complete Head Database/Locator
- Cooldown Abstraction
- Custom Gradient Color Interface
- Custom ID Generation
- Directional Enumeration
- Economy Interface Wrapper
- Entity Creation Tools
- File Management
- Item Recipe Builder
- Item Modification Builder
- Legacy Safe NamespacedKey
- Listing Collections
- Material Matcher
- Message Formatter
- String Utility
- Tab Completion Builder
- Task Scheduling
- Template Creation
- TextComponent Builder
- Vault Permission Interface Wrapper