Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MineValley/CoreAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier committed Dec 22, 2024
2 parents 1b1fb37 + bb5b1f8 commit 59a604b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 34 deletions.
100 changes: 66 additions & 34 deletions src/main/java/minevalley/core/api/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.util.*;
Expand Down Expand Up @@ -145,6 +147,70 @@ public static void callEvent(Event event) {
server.callEvent(event);
}

/**
* Gets the user of with a specific unique id.
* <br>
* <strong>Note:</strong> If no user is found, this method returns null.
*
* @param uniqueId unique id to get user from
* @return user object of the given unique id
*/
@Nullable
public static User getUser(@Nonnull UUID uniqueId) {
return server.getUser(uniqueId);
}

/**
* Gets the user of this specific player.
* <br>
* <strong>Note:</strong> If no user is found, a new one is created based on the player.
*
* @param player player to get user from
* @return user object of the given player
*/
@NonNull
public static OnlineUser getOnlineUser(@Nonnull Player player) {
return server.getOnlineUser(player);
}

/**
* Gets the name of the player with the specific unique id.
* <br>
* <strong>Note:</strong> If no player is found, this method returns null.
* <p>
* <strong>Runtime Optimization</strong>
* <ul>
* <li>This method uses an internal cache</li>
* <li>If the player is online, no use of the mojang api is taken</li>
* </ul>
* </p>
*
* @param uniqueId unique id of the player
* @return name of the player
*/
@Nullable
public static String getName(@Nonnull UUID uniqueId) {
return server.getName(uniqueId);
}

/**
* Gets the unique id of the player with the specific name.
* <br>
* <strong>Note:</strong> If no player is found, this method returns null.
* <p>
* <strong>Runtime Optimization</strong>
* <ul>
* <li>This method uses an internal cache</li>
* <li>If the player is online, no use of the mojang api is taken</li>
* </p>
* @param name name of the player
* @return unique id as UUID
*/
@Nullable
public static UUID getUniqueId(@Nonnull String name) {
return server.getUniqueId(name);
}

public static void registerCommand(PlayerCommand command) {
server.registerCommand(command);
}
Expand Down Expand Up @@ -344,40 +410,6 @@ public static List<MetadataValue> getMetadata(Metadatable metadatable, String ke
return server.getMetadata(metadatable, key);
}

/**
* Gets a players user object
*
* @param uniqueId uniqueId to get user from
* @return user object of the given uniqueId
*/
public static User getUser(UUID uniqueId) {
return server.getUser(uniqueId);
}

public static OnlineUser getOnlineUser(Player player) {
return server.getOnlineUser(player);
}

/**
* Gets the name of the player with the specific unique id
*
* @param uniqueId unique id of the player
* @return name of the player
*/
public static String getName(UUID uniqueId) {
return server.getName(uniqueId);
}

/**
* Gets the unique id of the player with the specific name
*
* @param name name of the player
* @return unique id of the player
*/
public static UUID getUniqueId(String name) {
return server.getUniqueId(name);
}

/**
* Removes the color-codes from a given string
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/minevalley/core/api/users/OnTimeHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package minevalley.core.api.users;

import lombok.Setter;
import minevalley.core.api.database.Value;

import java.time.LocalDate;
import java.util.Map;
Expand All @@ -22,6 +23,16 @@ public static int getOnTimeSinceRestartInMinutes(User user) {
return manager.getOnTimeSinceRestartInMinutes(user);
}

public static void purgeOnTime() {
// TODO 22.12.2024: purgeOnTime() (OnTimeHandler)
// USER_BY_UUID.values().forEach(user -> {
// final int delta = OnTimeHandler.getOnTimeSinceRestartInMinutes(user);
// if (delta != 0) {
// user.getEntry().changeValue(new Value("ontime", user.totalOnTimeInMinutes + delta));
// }
// });
}

public interface Manager {

int getTodayOnTimeInMinutes(User user);
Expand Down

0 comments on commit 59a604b

Please sign in to comment.