A one size fits all plugin for vanilla servers running Minecraft Beta 1.7.3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: finish initial implementation of seen and configs

+294 -103
-9
.idea/artifacts/GoldenAge_jar.xml
··· 1 - <component name="ArtifactManager"> 2 - <artifact type="jar" name="GoldenAge:jar"> 3 - <output-path>$PROJECT_DIR$/out/artifacts/GoldenAge_jar</output-path> 4 - <root id="archive" name="GoldenAge.jar"> 5 - <element id="module-output" name="GoldenAge" /> 6 - <element id="extracted-dir" path="$USER_HOME$/Downloads/uberbukkit-2.0.2.jar" path-in-jar="/" /> 7 - </root> 8 - </artifact> 9 - </component>
-10
.idea/artifacts/GoldenAge_jar2.xml
··· 1 - <component name="ArtifactManager"> 2 - <artifact type="jar" name="GoldenAge:jar2"> 3 - <output-path>$USER_HOME$/Coding/b173server/plugins</output-path> 4 - <root id="archive" name="GoldenAge.jar"> 5 - <element id="module-output" name="GoldenAge" /> 6 - <element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/xerial/sqlite-jdbc/3.49.1.0/sqlite-jdbc-3.49.1.0.jar" path-in-jar="/" /> 7 - <element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/Moresteck/uberbukkit/2.0.2-241217-1442-3a5552b/uberbukkit-2.0.2-241217-1442-3a5552b.jar" path-in-jar="/" /> 8 - </root> 9 - </artifact> 10 - </component>
-10
.idea/artifacts/GoldenAge_jar3.xml
··· 1 - <component name="ArtifactManager"> 2 - <artifact type="jar" name="GoldenAge:jar3"> 3 - <output-path>$PROJECT_DIR$/../b173server/plugins</output-path> 4 - <root id="archive" name="GoldenAge.jar"> 5 - <element id="module-output" name="GoldenAge" /> 6 - <element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/Moresteck/uberbukkit/2.0.2-241217-1442-3a5552b/uberbukkit-2.0.2-241217-1442-3a5552b.jar" path-in-jar="/" /> 7 - <element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/xerial/sqlite-jdbc/3.49.1.0/sqlite-jdbc-3.49.1.0.jar" path-in-jar="/" /> 8 - </root> 9 - </artifact> 10 - </component>
+1 -1
.idea/artifacts/GoldenAge_jar5.xml
··· 1 1 <component name="ArtifactManager"> 2 2 <artifact type="jar" name="GoldenAge:jar5"> 3 - <output-path>$PROJECT_DIR$/out/artifacts/GoldenAge_jar5</output-path> 3 + <output-path>$PROJECT_DIR$/../b173server/plugins</output-path> 4 4 <root id="archive" name="GoldenAge.jar"> 5 5 <element id="module-output" name="GoldenAge" /> 6 6 <element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.18.3/jackson-annotations-2.18.3.jar" path-in-jar="/" />
-15
pom.xml
··· 62 62 <artifactId>sqlite-jdbc</artifactId> 63 63 <version>3.49.1.0</version> 64 64 </dependency> 65 - <dependency> 66 - <groupId>com.fasterxml.jackson.core</groupId> 67 - <artifactId>jackson-core</artifactId> 68 - <version>2.18.3</version> 69 - </dependency> 70 - <dependency> 71 - <groupId>com.fasterxml.jackson.core</groupId> 72 - <artifactId>jackson-databind</artifactId> 73 - <version>2.18.3</version> 74 - </dependency> 75 - <dependency> 76 - <groupId>com.fasterxml.jackson.dataformat</groupId> 77 - <artifactId>jackson-dataformat-yaml</artifactId> 78 - <version>2.18.3</version> 79 - </dependency> 80 65 </dependencies> 81 66 </project>
+47 -20
src/main/java/dev/keii/goldenage/GoldenAge.java
··· 5 5 import dev.keii.goldenage.commands.SeenCommand; 6 6 import dev.keii.goldenage.config.Config; 7 7 import dev.keii.goldenage.config.ConfigLoader; 8 + import dev.keii.goldenage.config.Env; 8 9 import dev.keii.goldenage.listeners.PlayerJoinListener; 9 10 import dev.keii.goldenage.migration.Migrator; 10 11 import dev.keii.goldenage.utils.DatabaseUtility; 11 12 import dev.keii.goldenage.utils.Logger; 12 13 import lombok.Getter; 14 + import lombok.SneakyThrows; 13 15 import org.bukkit.Bukkit; 16 + import org.bukkit.plugin.PluginManager; 14 17 import org.bukkit.plugin.java.JavaPlugin; 15 18 16 19 import java.io.*; ··· 30 33 @Getter 31 34 private Config config; 32 35 33 - public void setupConfig() { 34 - File configFile = new File(getDataFolder(), "plugins/GoldenAge/config.yml"); 36 + @SneakyThrows 37 + public boolean setupConfig() { 38 + File configFile = new File("plugins/GoldenAge/config.yml"); 35 39 36 40 try { 41 + if (configFile.exists()) { 42 + return true; 43 + } 44 + 45 + GoldenAge.getLogger().info("Creating config..."); 46 + 37 47 InputStream configInputStream = getClassLoader().getResourceAsStream("config.yml"); 38 48 FileWriter configFileWriter = new FileWriter("plugins/GoldenAge/config.yml"); 39 49 40 - if (configInputStream != null && configFile.createNewFile()) { 50 + if (configInputStream != null) { 41 51 try (BufferedReader reader = new BufferedReader(new InputStreamReader(configInputStream, StandardCharsets.UTF_8))) { 42 52 StringBuilder content = new StringBuilder(); 43 53 String line; 54 + GoldenAge.getLogger().info("Writing defaults to config..."); 44 55 while ((line = reader.readLine()) != null) { 45 56 content.append(line).append(System.lineSeparator()); 46 57 } ··· 49 60 } 50 61 51 62 configInputStream.close(); 63 + GoldenAge.getLogger().info("Config created!"); 52 64 } 65 + return true; 53 66 } catch (IOException e) { 54 67 GoldenAge.getLogger().severe("Failed to create config!"); 55 68 GoldenAge.getLogger().severe(e.getMessage()); 69 + GoldenAge.getLogger().severe(e.toString()); 56 70 Bukkit.getPluginManager().disablePlugin(this); 71 + throw e; 72 + //return false; 57 73 } 58 74 } 59 75 60 76 @Override 61 77 public void onEnable() { 62 78 GoldenAge.logger = new Logger("[GoldenAge]"); 79 + GoldenAge.getLogger().info("Enabling GoldenAge..."); 63 80 64 81 if (!getDataFolder().exists()) { 65 82 getDataFolder().mkdirs(); 66 83 } 67 84 68 - setupConfig(); 85 + // Return out of onEnable if setting up config failed 86 + if (!setupConfig()) { 87 + return; 88 + } 69 89 70 90 try { 91 + GoldenAge.getLogger().info("Loading config."); 71 92 this.config = ConfigLoader.loadConfig("plugins/GoldenAge/config.yml"); 72 93 } catch (IOException e) { 73 94 GoldenAge.getLogger().severe("Failed to read config!"); ··· 76 97 return; 77 98 } 78 99 79 - if (config.getDatabase().isAutoMigrate()) { 80 - Migrator migrator = new Migrator(this); 81 - try { 82 - migrator.migrate(); 83 - } catch (SQLException e) { 84 - GoldenAge.getLogger().severe("Failed to migrate db!"); 85 - GoldenAge.getLogger().severe(e.getMessage()); 86 - Bukkit.getPluginManager().disablePlugin(this); 87 - return; 88 - } 89 - } 90 - 91 100 File databaseFile = new File("plugins/GoldenAge/database.db"); 92 101 93 102 this.databaseUtility = new DatabaseUtility(this, "jdbc:sqlite:" + databaseFile.getAbsolutePath()); ··· 103 112 return; 104 113 } 105 114 106 - this.getCommand("list").setExecutor(new ListCommand()); 107 - this.getCommand("seen").setExecutor(new SeenCommand(this)); 108 - this.getCommand("db").setExecutor(new DatabaseCommand(this)); 115 + if (config.getDatabase().isAutoMigrate()) { 116 + Migrator migrator = new Migrator(this); 117 + try { 118 + GoldenAge.getLogger().info("Migrating database..."); 119 + migrator.migrate(); 120 + GoldenAge.getLogger().info("Finished migrating database."); 121 + } catch (SQLException e) { 122 + GoldenAge.getLogger().severe("Failed to migrate db!"); 123 + GoldenAge.getLogger().severe(e.getMessage()); 124 + Bukkit.getPluginManager().disablePlugin(this); 125 + return; 126 + } 127 + } 109 128 110 - this.getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this); 129 + if (config.getCommands().getList().isEnabled()) 130 + this.getCommand("list").setExecutor(new ListCommand(this)); 131 + if (config.getCommands().getSeen().isEnabled()) 132 + this.getCommand("seen").setExecutor(new SeenCommand(this)); 133 + if (config.getEnv().equals(Env.Development)) 134 + this.getCommand("db").setExecutor(new DatabaseCommand(this)); 135 + 136 + PluginManager pm = this.getServer().getPluginManager(); 137 + pm.registerEvents(new PlayerJoinListener(this), this); 111 138 112 139 GoldenAge.getLogger().info("GoldenAge has been enabled!"); 113 140 }
+4 -6
src/main/java/dev/keii/goldenage/commands/DatabaseCommand.java
··· 1 1 package dev.keii.goldenage.commands; 2 2 3 3 import dev.keii.goldenage.GoldenAge; 4 + import dev.keii.goldenage.config.Env; 4 5 import dev.keii.goldenage.migration.Migrator; 5 6 import dev.keii.goldenage.utils.DatabaseUtility; 6 7 import org.bukkit.command.Command; ··· 26 27 27 28 @Override 28 29 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 29 - if (sender instanceof Player) { 30 - if (!((Player) sender).getAddress().toString().contains("127.0.0.1")) { 31 - sender.sendMessage(((Player) sender).getAddress().toString()); 32 - sender.sendMessage("Unknown command. Type \"help\" for help."); 33 - return true; 34 - } 30 + // Don't allow execution of this command if the environment isn't development 31 + if(!plugin.getConfig().getEnv().equals(Env.Development)) { 32 + return false; 35 33 } 36 34 37 35 if (args.length == 0) {
+18 -5
src/main/java/dev/keii/goldenage/commands/ListCommand.java
··· 1 1 package dev.keii.goldenage.commands; 2 2 3 + import dev.keii.goldenage.GoldenAge; 3 4 import dev.keii.goldenage.utils.PlayerUtility; 4 - import org.bukkit.ChatColor; 5 + import dev.keii.goldenage.utils.StringSubstitutor; 5 6 import org.bukkit.command.Command; 6 7 import org.bukkit.command.CommandExecutor; 7 8 import org.bukkit.command.CommandSender; 8 - import org.bukkit.entity.Player; 9 - import org.bukkit.plugin.PluginDescriptionFile; 10 - import org.bukkit.plugin.java.JavaPlugin; 9 + 10 + import java.util.HashMap; 11 + import java.util.Map; 11 12 12 13 @SuppressWarnings("unused") 13 14 public class ListCommand implements CommandExecutor { 15 + private GoldenAge plugin; 16 + 17 + public ListCommand(GoldenAge plugin) { 18 + this.plugin = plugin; 19 + } 20 + 14 21 @Override 15 22 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 16 23 if (command.getName().equalsIgnoreCase("list")) { 17 24 PlayerUtility playerUtility = new PlayerUtility(); 18 - sender.sendMessage(ChatColor.GREEN + playerUtility.getPlayersListString()); 25 + Map<String, Object> params = new HashMap<>(); 26 + params.put("online", playerUtility.getOnlinePlayers()); 27 + params.put("max", playerUtility.getMaxPlayers()); 28 + params.put("playerList", playerUtility.getPlayersListString()); 29 + 30 + StringSubstitutor substitutor = new StringSubstitutor(params); 31 + sender.sendMessage(substitutor.replace(plugin.getConfig().getCommands().getList().getFormat())); 19 32 20 33 return true; 21 34 }
+28 -7
src/main/java/dev/keii/goldenage/commands/SeenCommand.java
··· 6 6 import dev.keii.goldenage.models.Login; 7 7 import dev.keii.goldenage.models.User; 8 8 import dev.keii.goldenage.utils.DateUtility; 9 + import dev.keii.goldenage.utils.StringSubstitutor; 10 + import org.bukkit.Bukkit; 9 11 import org.bukkit.command.Command; 10 12 import org.bukkit.command.CommandExecutor; 11 13 import org.bukkit.command.CommandSender; 14 + import org.bukkit.entity.Player; 12 15 13 16 import java.time.ZoneOffset; 17 + import java.util.Arrays; 18 + import java.util.HashMap; 19 + import java.util.Map; 14 20 15 21 @SuppressWarnings("unused") 16 22 public class SeenCommand implements CommandExecutor { ··· 23 29 @Override 24 30 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 25 31 if (args.length == 0) { 26 - sender.sendMessage("No argument is specified."); 32 + sender.sendMessage(plugin.getConfig().getErrors().getInsufficientArguments()); 27 33 return false; 28 34 } 29 35 ··· 31 37 User user = userDao.getUserByUserName(args[0]); 32 38 33 39 if (user == null) { 34 - sender.sendMessage("§eThis user has never been seen."); 40 + sender.sendMessage(plugin.getConfig().getCommands().getSeen().getNoUser()); 35 41 return true; 36 42 } 37 43 ··· 39 45 Login login = loginDao.getLatestLoginByUser(user); 40 46 41 47 if (login == null) { 42 - sender.sendMessage("§eThis user has never been seen."); 48 + sender.sendMessage(plugin.getConfig().getCommands().getSeen().getNoUser()); 43 49 return true; 44 50 } 45 51 52 + Map<String, Object> params = new HashMap<>(); 53 + params.put("player", args[0]); 54 + 55 + if (Arrays.stream(Bukkit.getOnlinePlayers()).anyMatch((Player player) -> player.getDisplayName().equalsIgnoreCase(args[0]) )) 56 + { 57 + StringSubstitutor substitutor = new StringSubstitutor(params); 58 + sender.sendMessage(substitutor.replace(plugin.getConfig().getCommands().getSeen().getSuccessOnline())); 59 + return true; 60 + } 46 61 47 62 String ago = DateUtility.getHumanReadableTimeSpan(login.getCreatedAt().toEpochSecond(ZoneOffset.UTC)); 48 - String sb = "§eThis user was seen " + 49 - ago + 50 - (ago.equals("now") ? "." : " ago."); 51 - sender.sendMessage(sb); 63 + 64 + if (ago.equals("now")) { 65 + StringSubstitutor substitutor = new StringSubstitutor(params); 66 + sender.sendMessage(substitutor.replace(plugin.getConfig().getCommands().getSeen().getSuccessNow())); 67 + } else { 68 + params.put("duration", ago); 69 + 70 + StringSubstitutor substitutor = new StringSubstitutor(params); 71 + sender.sendMessage(substitutor.replace(plugin.getConfig().getCommands().getSeen().getSuccessDuration())); 72 + } 52 73 53 74 return true; 54 75 }
+24
src/main/java/dev/keii/goldenage/config/CommandsConfig.java
··· 1 + package dev.keii.goldenage.config; 2 + 3 + import dev.keii.goldenage.config.commands.ListConfig; 4 + import dev.keii.goldenage.config.commands.SeenConfig; 5 + import lombok.Getter; 6 + import org.bukkit.util.config.Configuration; 7 + 8 + public class CommandsConfig { 9 + private final Configuration configuration; 10 + @Getter 11 + private ListConfig list; 12 + @Getter 13 + private SeenConfig seen; 14 + 15 + public CommandsConfig(Configuration configuration) { 16 + this.configuration = configuration; 17 + this.list = new ListConfig(configuration); 18 + this.seen = new SeenConfig(configuration); 19 + } 20 + 21 + public boolean isAutoMigrate() { 22 + return this.configuration.getBoolean("database.auto-migrate", true); 23 + } 24 + }
+34 -1
src/main/java/dev/keii/goldenage/config/Config.java
··· 1 1 package dev.keii.goldenage.config; 2 2 3 + import dev.keii.goldenage.GoldenAge; 3 4 import lombok.Getter; 4 5 import lombok.Setter; 6 + import org.bukkit.util.config.Configuration; 5 7 6 8 public class Config { 7 9 @Getter 8 - @Setter 9 10 private DatabaseConfig database; 11 + 12 + @Getter 13 + private CommandsConfig commands; 14 + 15 + @Getter 16 + private ErrorsConfig errors; 17 + 18 + private final Configuration configuration; 19 + 20 + public Config(Configuration configuration) 21 + { 22 + this.configuration = configuration; 23 + this.database = new DatabaseConfig(configuration); 24 + this.commands = new CommandsConfig(configuration); 25 + this.errors = new ErrorsConfig(configuration); 26 + } 27 + 28 + public Env getEnv() 29 + { 30 + String envString = configuration.getString("env", "development"); 31 + 32 + switch(envString.toLowerCase()) 33 + { 34 + case "development": return Env.Development; 35 + case "production": 36 + return Env.Production; 37 + // Env is defaulted to production instead of throwing so the plugin still runs 38 + default: 39 + GoldenAge.getLogger().warning("Invalid env in config. Accepted values are 'development' and 'production'."); 40 + return Env.Production; 41 + } 42 + } 10 43 }
+3 -4
src/main/java/dev/keii/goldenage/config/ConfigLoader.java
··· 1 1 package dev.keii.goldenage.config; 2 2 3 - import com.fasterxml.jackson.databind.ObjectMapper; 4 - import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 3 + import org.bukkit.util.config.Configuration; 5 4 6 5 import java.io.File; 7 6 import java.io.IOException; 8 7 9 8 public class ConfigLoader { 10 9 public static Config loadConfig(String filePath) throws IOException { 11 - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); 12 - return mapper.readValue(new File(filePath), Config.class); 10 + Configuration config = new Configuration(new File(filePath)); 11 + return new Config(config); 13 12 } 14 13 }
+12 -3
src/main/java/dev/keii/goldenage/config/DatabaseConfig.java
··· 2 2 3 3 import lombok.Getter; 4 4 import lombok.Setter; 5 + import org.bukkit.util.config.Configuration; 5 6 6 7 public class DatabaseConfig { 7 - @Getter 8 - @Setter 9 - private boolean autoMigrate; 8 + private final Configuration configuration; 9 + 10 + public DatabaseConfig(Configuration configuration) 11 + { 12 + this.configuration = configuration; 13 + } 14 + 15 + public boolean isAutoMigrate() 16 + { 17 + return this.configuration.getBoolean("database.auto-migrate", true); 18 + } 10 19 }
+6
src/main/java/dev/keii/goldenage/config/Env.java
··· 1 + package dev.keii.goldenage.config; 2 + 3 + public enum Env { 4 + Production, 5 + Development 6 + }
+15
src/main/java/dev/keii/goldenage/config/ErrorsConfig.java
··· 1 + package dev.keii.goldenage.config; 2 + 3 + import org.bukkit.util.config.Configuration; 4 + 5 + public class ErrorsConfig { 6 + private final Configuration configuration; 7 + 8 + public ErrorsConfig(Configuration configuration) { 9 + this.configuration = configuration; 10 + } 11 + 12 + public String getInsufficientArguments() { 13 + return this.configuration.getString("errors.insufficient-arguments", "§cNot enough arguments"); 14 + } 15 + }
+21
src/main/java/dev/keii/goldenage/config/commands/ListConfig.java
··· 1 + package dev.keii.goldenage.config.commands; 2 + 3 + import org.bukkit.util.config.Configuration; 4 + 5 + public class ListConfig { 6 + private final Configuration configuration; 7 + 8 + public ListConfig(Configuration configuration) 9 + { 10 + this.configuration = configuration; 11 + } 12 + 13 + public boolean isEnabled() 14 + { 15 + return this.configuration.getBoolean("commands.list.enabled", true); 16 + } 17 + 18 + public String getFormat() { 19 + return this.configuration.getString("commands.list.format", "§eOnline players (${online}/${max}): ${playerList}"); 20 + } 21 + }
+31
src/main/java/dev/keii/goldenage/config/commands/SeenConfig.java
··· 1 + package dev.keii.goldenage.config.commands; 2 + 3 + import org.bukkit.util.config.Configuration; 4 + 5 + public class SeenConfig { 6 + private final Configuration configuration; 7 + 8 + public SeenConfig(Configuration configuration) { 9 + this.configuration = configuration; 10 + } 11 + 12 + public boolean isEnabled() { 13 + return this.configuration.getBoolean("commands.seen.enabled", true); 14 + } 15 + 16 + public String getNoUser() { 17 + return this.configuration.getString("commands.seen.no-user", "§cThis user has never been seen."); 18 + } 19 + 20 + public String getSuccessDuration() { 21 + return this.configuration.getString("commands.seen.success-duration", "§e${player} was seen ${duration} ago."); 22 + } 23 + 24 + public String getSuccessNow() { 25 + return this.configuration.getString("commands.seen.success-now", "§e${player} was seen now."); 26 + } 27 + 28 + public String getSuccessOnline() { 29 + return this.configuration.getString("commands.seen.success-online", "§e${player} is online."); 30 + } 31 + }
+4 -3
src/main/java/dev/keii/goldenage/listeners/PlayerJoinListener.java
··· 13 13 import org.bukkit.event.player.PlayerJoinEvent; 14 14 15 15 import java.time.LocalDateTime; 16 + import java.time.ZoneOffset; 16 17 17 18 public class PlayerJoinListener implements Listener { 18 19 ··· 27 28 UserDao userDao = new UserDao(plugin.getDatabaseUtility()); 28 29 User user = userDao.getUserByUuid(event.getPlayer().getUniqueId()); 29 30 if (user == null) { 30 - user = new User(event.getPlayer().getUniqueId(), LocalDateTime.now(), null); 31 + user = new User(event.getPlayer().getUniqueId(), LocalDateTime.now(ZoneOffset.UTC), null); 31 32 user = userDao.insertUser(user); 32 33 Bukkit.getLogger().info("Created user in db for " + event.getPlayer().getDisplayName()); 33 34 } 34 35 UserNameDao userNameDao = new UserNameDao(plugin.getDatabaseUtility()); 35 36 UserName userName = userNameDao.getUserNameByName(event.getPlayer().getDisplayName()); 36 37 if (userName == null) { 37 - userName = new UserName(user, event.getPlayer().getDisplayName(), LocalDateTime.now()); 38 + userName = new UserName(user, event.getPlayer().getDisplayName(), LocalDateTime.now(ZoneOffset.UTC)); 38 39 userNameDao.insertUserName(userName); 39 40 } 40 41 41 - Login login = new Login(user, LocalDateTime.now()); 42 + Login login = new Login(user, LocalDateTime.now(ZoneOffset.UTC)); 42 43 LoginDao loginDao = new LoginDao(plugin.getDatabaseUtility()); 43 44 loginDao.insertLogin(login); 44 45 }
-3
src/main/java/dev/keii/goldenage/migration/Migrator.java
··· 55 55 public void migrate() throws SQLException { 56 56 int newBatch = getLatestBatch() + 1; 57 57 58 - GoldenAge.getLogger().info("Migrate"); 59 58 for (Migration migration : migrations) 60 59 { 61 60 migration.migrate(newBatch); ··· 64 63 65 64 public void rollback() throws SQLException { 66 65 int latestBatch = getLatestBatch(); 67 - 68 - GoldenAge.getLogger().info("Rollback"); 69 66 70 67 Collections.reverse(migrations); 71 68 for (Migration migration : migrations)
-2
src/main/java/dev/keii/goldenage/utils/DateUtility.java
··· 13 13 return null; 14 14 } 15 15 16 - GoldenAge.getLogger().info(epochTimeSeconds.toString()); 17 - GoldenAge.getLogger().info(String.valueOf((long) epochTimeSeconds * 1000L)); 18 16 Instant instant = Instant.ofEpochMilli((long) epochTimeSeconds * 1000L); 19 17 20 18 return instant.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toLocalDateTime();
+12 -3
src/main/java/dev/keii/goldenage/utils/PlayerUtility.java
··· 12 12 public String getPlayersListString() 13 13 { 14 14 Player[] players = Bukkit.getOnlinePlayers(); 15 - int onlinePlayers = players.length; 16 - int maxPlayers = Bukkit.getMaxPlayers(); 17 15 18 16 StringBuilder playerList = new StringBuilder(); 19 17 for (Player player : players) { ··· 22 20 } 23 21 playerList.setLength(playerList.length() - 2); 24 22 25 - return "Online players (" + onlinePlayers + "/" + maxPlayers + "): " + playerList.toString(); 23 + return playerList.toString(); 24 + } 25 + 26 + public int getOnlinePlayers() 27 + { 28 + Player[] players = Bukkit.getOnlinePlayers(); 29 + return players.length; 30 + } 31 + 32 + public int getMaxPlayers() 33 + { 34 + return Bukkit.getMaxPlayers(); 26 35 } 27 36 }
+20
src/main/java/dev/keii/goldenage/utils/StringSubstitutor.java
··· 1 + package dev.keii.goldenage.utils; 2 + 3 + import java.util.Map; 4 + import java.util.regex.Pattern; 5 + 6 + public class StringSubstitutor { 7 + private final Map<String, Object> map; 8 + 9 + public StringSubstitutor(Map<String, Object> map) { 10 + this.map = map; 11 + } 12 + 13 + public String replace(String str) { 14 + String finalString = str; 15 + for (Map.Entry<String, Object> entry : map.entrySet()) { 16 + finalString = finalString.replace("${" + entry.getKey() + "}", String.valueOf(entry.getValue())); 17 + } 18 + return finalString; 19 + } 20 + }
+14 -1
src/main/resources/config.yml
··· 1 + env: production 1 2 database: 2 - auto-migrate: true 3 + auto-migrate: true 4 + errors: 5 + insufficient-arguments: "§cNot enough arguments" 6 + commands: 7 + list: 8 + format: "§eOnline players (${online}/${max}): ${playerList}" 9 + enabled: true 10 + seen: 11 + no-user: "§cThis user has never been seen." 12 + success-duration: "§e${player} was seen ${duration} ago." 13 + success-now: "§e${player} was seen now." 14 + success-online: "§e${player} is online." 15 + enabled: true