Skip to content

Commit

Permalink
Merge pull request #98 from Foxikle/fix/javadocs
Browse files Browse the repository at this point in the history
Add javadocs to everywhere that didn't have them
  • Loading branch information
webhead1104 authored Jun 16, 2024
2 parents 7ec66eb + edc3982 commit e69d474
Show file tree
Hide file tree
Showing 63 changed files with 1,640 additions and 59 deletions.
22 changes: 22 additions & 0 deletions src/main/java/net/cytonic/cytosis/CytonicNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import net.cytonic.cytosis.data.RedisDatabase;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
Expand All @@ -14,18 +15,39 @@ public class CytonicNetwork {
private final Set<String> networkPlayers = new HashSet<>();
private final Set<UUID> networkPlayerUUIDs = new HashSet<>();

/**
* The default constructor
*/
public CytonicNetwork() {
}

/**
* Imports online player data from redis
*
* @param redisDatabase The redis instance
*/
public void importDataFromRedis(RedisDatabase redisDatabase) {
networkPlayers.clear();
networkPlayerUUIDs.clear();
networkPlayers.addAll(redisDatabase.getOnlinePlayers());
networkPlayerUUIDs.addAll(redisDatabase.getOnlineUUIDs());
}

/**
* Adds a player to the cache
* @param name The player's name
* @param uuid The player's UUID
*/
public void addPlayer(String name, UUID uuid) {
networkPlayers.add(name);
networkPlayerUUIDs.add(uuid);
}

/**
* Removes the player from the cache
* @param name The player's name
* @param uuid The player's UUID
*/
public void removePlayer(String name, UUID uuid) {
networkPlayers.remove(name);
networkPlayerUUIDs.remove(uuid);
Expand Down
70 changes: 67 additions & 3 deletions src/main/java/net/cytonic/cytosis/Cytosis.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@
import net.minestom.server.network.ConnectionManager;
import net.minestom.server.permission.Permission;
import org.jetbrains.annotations.Nullable;

import java.util.*;

import static net.cytonic.cytosis.utils.MiniMessageTemplate.MM;

/**
* The main class for Cytosis
*/
@Getter
public class Cytosis {
public final class Cytosis {

/**
* the instance ID is used to identify the server
*/
public static final String SERVER_ID = generateID();
/**
* The version of Cytosis
*/
public static final String VERSION = "0.1";
// manager stuff
@Getter
private static MinecraftServer minecraftServer;
Expand Down Expand Up @@ -78,10 +90,16 @@ public class Cytosis {
private static SideboardManager sideboardManager;
@Getter
private static NPCManager npcManager;
public static final String VERSION = "0.1";

private static List<String> FLAGS;

private Cytosis() {
}

/**
* The entry point for the Minecraft Server
*
* @param args Runtime flags
*/
public static void main(String[] args) {
FLAGS = List.of(args);
long start = System.currentTimeMillis();
Expand Down Expand Up @@ -135,12 +153,23 @@ public static void main(String[] args) {
});
}

/**
* Gets the players currently on THIS instance
*
* @return a set of players
*/
public static Set<Player> getOnlinePlayers() {
Set<Player> players = new HashSet<>();
instanceManager.getInstances().forEach(instance -> players.addAll(instance.getPlayers()));
return players;
}

/**
* Gets the player if they are on THIS instance, by USERNAME
*
* @param username The name to fetch the player by
* @return The optional holding the player if they exist
*/
public static Optional<Player> getPlayer(String username) {
Player target = null;
for (Player onlinePlayer : getOnlinePlayers())
Expand All @@ -162,19 +191,35 @@ public static Optional<Player> getPlayer(UUID uuid) {
return Optional.ofNullable(target);
}

/**
* Gives a player all permissions
*
* @param player to grant all permissions to
*/
public static void opPlayer(Player player) {
player.addPermission(new Permission("*")); // give them every permission
}

/**
* Removes the '*' permission from a player
*
* @param player The player to remove the '*' permission from
*/
public static void deopPlayer(Player player) {
player.removePermission("*"); // remove every permission
}

/**
* Sets up Mojang Authentication
*/
public static void mojangAuth() {
Logger.info("Initializing Mojang Authentication");
MojangAuth.init(); //VERY IMPORTANT! (This is online mode!)
}

/**
* Loads the world based on the settings
*/
public static void loadWorld() {
if (CytosisSettings.SERVER_WORLD_NAME.isEmpty()) {
Logger.info("Generating basic world");
Expand All @@ -195,6 +240,11 @@ public static void loadWorld() {
});
}

/**
* Completes nonessential startup tasks for the server
*
* @param start The time the server started
*/
public static void completeNonEssentialTasks(long start) {
Logger.info("Initializing database");
databaseManager = new DatabaseManager();
Expand Down Expand Up @@ -299,6 +349,13 @@ public static void completeNonEssentialTasks(long start) {

}

/**
* Generates a random Server ID:
* <p>
* TODO: make a check for existing server ids
*
* @return a random Server ID
*/
private static String generateID() {
//todo: make a check for existing server ids
StringBuilder id = new StringBuilder("Cytosis-");
Expand All @@ -311,6 +368,13 @@ private static String generateID() {
return id.toString();
}

/**
* Gets the Raw ID of the server
* <p>
* For example, Cytosis-a1234b would return a1234b
*
* @return The raw ID
*/
public static String getRawID() {
return Cytosis.SERVER_ID.replace("Cytosis-", "");
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/cytonic/cytosis/auditlog/Category.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package net.cytonic.cytosis.auditlog;

/**
* An enum for the different audit log categories
*/
public enum Category {
/**
* A player ban
*/
BAN,
/**
* A player unban
*/
UNBAN,
/**
* A player mute
*/
MUTE,
/**
* A player unmute
*/
UNMUTE,
/**
* A player IP ban
*/
IPBAN,
/**
* A player IP unban
*/
IPUNBAN
}
8 changes: 8 additions & 0 deletions src/main/java/net/cytonic/cytosis/auditlog/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

import java.util.UUID;

/**
* A class representing an entry in the audit log
*
* @param uuid The UUID of the player
* @param actor The UUID of the actor who caused the entry
* @param category The cateory of the entry
* @param reason The reason for the entry
*/
public record Entry(UUID uuid, UUID actor, Category category, String reason) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
import net.minestom.server.entity.Player;

/**
* A class that handles the chat channel command
*/
public class ChatChannelCommand extends Command {

/**
* Creates the command
*/
public ChatChannelCommand() {
super("chat");
setDefaultExecutor((sender, _) -> sender.sendMessage(Component.text("You must specify a channel!", NamedTextColor.RED)));
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/cytonic/cytosis/commands/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@
import net.cytonic.cytosis.commands.moderation.BanCommand;
import net.minestom.server.command.CommandManager;
import net.minestom.server.entity.Player;

import java.util.Scanner;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
* A class that handles the commands, their execution, and allegedly a console.
*/
public class CommandHandler {

private final ScheduledExecutorService worker;
private final Scanner CONSOLE_IN = new Scanner(System.in);
private final Object consoleLock = new Object();

/**
* Creates a command handler and sets up the worker
*/
public CommandHandler() {
this.worker = Executors.newSingleThreadScheduledExecutor(Thread.ofVirtual().name("CytosisConsoleWorker").factory());
}

/**
* Registers the default Cytosis commands
*/
public void registerCytosisCommands() {
CommandManager cm = Cytosis.getCommandManager();
cm.register(new GamemodeCommand());
Expand All @@ -28,11 +38,19 @@ public void registerCytosisCommands() {
cm.register(new StopCommand());
}

/**
* Sends a packet to the player to recalculate command permissions
*
* @param player The player to send the packet to
*/
@SuppressWarnings("UnstableApiUsage")
public void recalculateCommands(Player player) {
player.sendPacket(Cytosis.getCommandManager().createDeclareCommandsPacket(player));
}

/**
* Sets up the console so commands can be executed from there
*/
public void setupConsole() {
worker.scheduleAtFixedRate(() -> {
if (CONSOLE_IN.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;

/**
* The class representing the gamemode command
*/
public class GamemodeCommand extends Command {

/**
* Creates a new command and sets up the consumers and execution logic
*/
public GamemodeCommand() {
super("gamemode", "gm");
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.gamemode"));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/cytonic/cytosis/commands/RankCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

import static net.cytonic.cytosis.utils.MiniMessageTemplate.MM;

/**
* A command that allows players to change another player's rank
*/
public class RankCommand extends Command {

/**
* A command that allows authorized users to change player ranks
*/
public RankCommand() {
super("rank");
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.rank"));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/cytonic/cytosis/commands/StopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.Command;

/**
* A class representing the stop command
*/
public class StopCommand extends Command {

/**
* A simple command to stop the server
*/
public StopCommand() {
super("stop");
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.stop"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

import static net.cytonic.cytosis.utils.MiniMessageTemplate.MM;

/**
* A command that allows authorized players to ban players.
*/
public class BanCommand extends Command {
/**
* Creates the command and sets the consumers
*/
public BanCommand() {
super("ban");
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.moderation.ban"));
Expand Down
Loading

0 comments on commit e69d474

Please sign in to comment.