idk some "cool" stuff
This commit is contained in:
10
build.gradle
10
build.gradle
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
id 'com.rikonardo.papermake' version '1.0.6'
|
||||
}
|
||||
|
||||
group = 'hdvtdev'
|
||||
@@ -8,6 +9,7 @@ version = '0.0.1-a'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://repo.md-5.net/content/groups/public/' }
|
||||
maven {
|
||||
name = "papermc-repo"
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
@@ -20,6 +22,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||
implementation group: 'me.libraryaddict.disguises', name: 'libsdisguises', version: '11.0.6'
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -31,7 +34,7 @@ tasks {
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 17
|
||||
def targetJavaVersion = 21
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
sourceCompatibility = javaVersion
|
||||
@@ -57,3 +60,8 @@ processResources {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
destinationDirectory.set(file("/home/hadvart/Documents/Minecraft/Pufferfish 1.20.4/plugins"))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,42 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class BlockAndSeek extends JavaPlugin {
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockAndSeek extends JavaPlugin implements CommandExecutor {
|
||||
|
||||
private static File dataFolder;
|
||||
|
||||
public static File getPluginDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
|
||||
dataFolder = getDataFolder();
|
||||
|
||||
LibsDisguises libsDisguises = (LibsDisguises) Bukkit.getPluginManager().getPlugin("LibsDisguises");
|
||||
if (libsDisguises == null) {
|
||||
getLogger().severe("LibsDisguises не найден!");
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
Localization.load(this);
|
||||
ConfigManager.load();
|
||||
|
||||
Objects.requireNonNull(getCommand("blockandseek")).setExecutor(new CommandListener());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
29
src/main/java/hdvtdev/blockAndSeek/BlockAndSeekGame.java
Normal file
29
src/main/java/hdvtdev/blockAndSeek/BlockAndSeekGame.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BlockAndSeekGame {
|
||||
|
||||
private final Set<Player> players = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public BlockAndSeekGame(String name, List<String> players) {
|
||||
for (String player : players) {
|
||||
this.addPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
Player p = Bukkit.getPlayerExact(name);
|
||||
if (p != null) players.add(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
131
src/main/java/hdvtdev/blockAndSeek/CommandListener.java
Normal file
131
src/main/java/hdvtdev/blockAndSeek/CommandListener.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandListener implements CommandExecutor, TabCompleter {
|
||||
|
||||
public static List<String> getAllCommands() {
|
||||
return List.of("tpp", "morph");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
|
||||
|
||||
|
||||
int argsLen = args.length;
|
||||
|
||||
if (argsLen == 0) {
|
||||
sender.sendMessage(Localization.get("bs-usage"));
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "map" -> {
|
||||
if (argsLen > 1) {
|
||||
switch (args[1]) {
|
||||
case "list" -> sender.sendMessage(Localization.get("maps-list", "{maps}", ConfigManager.createdMaps().toString()));
|
||||
case "create" -> {
|
||||
if (argsLen > 2) {
|
||||
String mapName = args[2];
|
||||
World world = Bukkit.getWorld(mapName);
|
||||
if (world == null) {
|
||||
sender.sendMessage(Localization.get("map-missing-world", "{world}", mapName));
|
||||
} else {
|
||||
try {
|
||||
if (ConfigManager.addMap(mapName)) sender.sendMessage(Localization.get("map-created", "{map}", mapName));
|
||||
else sender.sendMessage(Localization.get("map-already-exist", "{map}", mapName));
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage(Localization.get("map-creation-failed", "{error}", e.getMessage()));
|
||||
}
|
||||
}
|
||||
} else sender.sendMessage(Localization.get("not-enough-arguments", "{usage}", "<green>/blockandseek create <gold>[MAP NAME]<white>"));
|
||||
}
|
||||
default -> {
|
||||
if (ConfigManager.createdMaps().contains(args[1])) {
|
||||
if (argsLen > 2) {
|
||||
switch (args[2]) {
|
||||
case "setspawn" -> {}
|
||||
case "setlobby" -> {}
|
||||
case "setduration" -> {}
|
||||
default -> sender.sendMessage(Localization.get("unknown-subcommand", "{subcommand}", args[2]));
|
||||
}
|
||||
} else sender.sendMessage(Localization.get("not-enough-arguments", "{usage}", String.format("<green>/blockandseek create %s <gold>[SUBCOMMAND]", args[1])));
|
||||
} else sender.sendMessage(Localization.get("map-not-exist", "{map}", args[1]));
|
||||
}
|
||||
}
|
||||
} else sender.sendMessage(Localization.get("not-enough-arguments", "{usage}", "<green>/blockandseek map <gold>[MAP NAME | SUBCOMMAND]<white>"));
|
||||
}
|
||||
case "reload" -> {
|
||||
if (argsLen > 1) {
|
||||
switch (args[1]) {
|
||||
case "messages" -> {
|
||||
Localization.reload();
|
||||
sender.sendMessage(Localization.get("messages-reload"));
|
||||
}
|
||||
case "maps" -> {
|
||||
ConfigManager.load();
|
||||
sender.sendMessage(Localization.get("maps-reload"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
sender.sendActionBar(MiniMessage.miniMessage().deserialize("<b><blue>" + args.length));
|
||||
return switch (args.length) {
|
||||
case 1 -> List.of("reload", "help", "map", "join");
|
||||
case 2 -> switch (args[0]) {
|
||||
case "map" -> {
|
||||
List<String> scmds = new ArrayList<>(List.of("create", "list"));
|
||||
scmds.addAll(ConfigManager.createdMaps());
|
||||
yield scmds;
|
||||
}
|
||||
case "join" -> List.of("test");
|
||||
case "reload" -> List.of("messages", "maps");
|
||||
default -> List.of();
|
||||
};
|
||||
case 3 -> switch (args[1]) {
|
||||
case "create", "list" -> List.of();
|
||||
default -> {
|
||||
if (ConfigManager.createdMaps().contains(args[1])) {
|
||||
yield List.of("setspawn", "setlobby", "setduration");
|
||||
} else yield List.of();
|
||||
}
|
||||
};
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
}
|
||||
58
src/main/java/hdvtdev/blockAndSeek/ConfigManager.java
Normal file
58
src/main/java/hdvtdev/blockAndSeek/ConfigManager.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private static final File mapsConfigFile = new File(BlockAndSeek.getPluginDataFolder(), "maps.yml");
|
||||
private static final ConcurrentHashMap<String, MapConfig> mapsConfigs = new ConcurrentHashMap<>();
|
||||
|
||||
public static Set<String> createdMaps() {
|
||||
return mapsConfigs.keySet();
|
||||
}
|
||||
|
||||
public static MapConfig getMapConfig(@NotNull String name) {
|
||||
return mapsConfigs.get(name);
|
||||
}
|
||||
|
||||
public static boolean addMap(String name) throws IOException {
|
||||
if (mapsConfigs.containsKey(name)) return false;
|
||||
mapsConfigs.put(name, MapConfig.defaults());
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(mapsConfigFile);
|
||||
config.set(name + ".spawn", "null");
|
||||
config.set(name + ".duration", "null");
|
||||
config.set(name + ".lobby", "null");
|
||||
|
||||
config.save(mapsConfigFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static void load() {
|
||||
mapsConfigs.clear();
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(mapsConfigFile);
|
||||
for (String mapKey : config.getKeys(false)) {
|
||||
List<Long> spawn = config.getLongList(mapKey + ".spawn");
|
||||
List<Long> lobby = config.getLongList(mapKey + ".lobby");
|
||||
int duration = config.getInt(mapKey + ".duration");
|
||||
MapConfig mapConfig = new MapConfig(spawn, lobby, duration);
|
||||
mapsConfigs.put(mapKey, mapConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public record MapConfig(List<Long> spawn, List<Long> lobby, int duration) {
|
||||
public static MapConfig defaults() {
|
||||
return new MapConfig(null, null, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
25
src/main/java/hdvtdev/blockAndSeek/GamesManager.java
Normal file
25
src/main/java/hdvtdev/blockAndSeek/GamesManager.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GamesManager {
|
||||
|
||||
private static final ConcurrentHashMap<String, BlockAndSeekGame> games = new ConcurrentHashMap<>();
|
||||
|
||||
public static void createGame(String name, ArrayList<String> players) {
|
||||
games.put(name, new BlockAndSeekGame(name, players));
|
||||
}
|
||||
|
||||
public static boolean joinGame(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void endGame(String name) {
|
||||
games.remove(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
68
src/main/java/hdvtdev/blockAndSeek/Localization.java
Normal file
68
src/main/java/hdvtdev/blockAndSeek/Localization.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Localization {
|
||||
|
||||
private static final Map<String, String> localization = new ConcurrentHashMap<>();
|
||||
private static JavaPlugin javaPlugin;
|
||||
|
||||
public static void reload() {
|
||||
File localizationFile = new File(javaPlugin.getDataFolder(), "messages.yml");
|
||||
if (!localizationFile.exists()) javaPlugin.saveResource("messages.yml", false);
|
||||
|
||||
YamlConfiguration locale = YamlConfiguration.loadConfiguration(localizationFile);
|
||||
YamlConfiguration defaultLocale = YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(Objects.requireNonNull(javaPlugin.getResource("messages.yml"))));
|
||||
|
||||
String prefix = locale.getString("prefix");
|
||||
prefix = prefix == null ? defaultLocale.getString("prefix") : prefix;
|
||||
|
||||
for (String defaultElement : defaultLocale.getKeys(false)) {
|
||||
String element = locale.getString(defaultElement);
|
||||
localization.put(defaultElement, String.format("%s%s", prefix, element == null ? defaultLocale.getString(defaultElement) : element));
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(JavaPlugin plugin) {
|
||||
javaPlugin = plugin;
|
||||
File localizationFile = new File(plugin.getDataFolder(), "messages.yml");
|
||||
if (!localizationFile.exists()) plugin.saveResource("messages.yml", false);
|
||||
|
||||
YamlConfiguration locale = YamlConfiguration.loadConfiguration(localizationFile);
|
||||
YamlConfiguration defaultLocale = YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(Objects.requireNonNull(plugin.getResource("messages.yml"))));
|
||||
|
||||
String prefix = locale.getString("prefix");
|
||||
prefix = prefix == null ? defaultLocale.getString("prefix") : prefix;
|
||||
|
||||
for (String defaultElement : defaultLocale.getKeys(false)) {
|
||||
String element = locale.getString(defaultElement);
|
||||
localization.put(defaultElement, String.format("%s%s", prefix, element == null ? defaultLocale.getString(defaultElement) : element));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Component get(String key, String... replacements) {
|
||||
String s = localization.get(key);
|
||||
for (int i = 0; i < replacements.length; i+=2) {
|
||||
s = s.replace(replacements[i], replacements[i + 1]);
|
||||
}
|
||||
|
||||
return MiniMessage.miniMessage().deserialize(s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
src/main/resources/config.yml
Normal file
1
src/main/resources/config.yml
Normal file
@@ -0,0 +1 @@
|
||||
#
|
||||
0
src/main/resources/maps.yml
Normal file
0
src/main/resources/maps.yml
Normal file
15
src/main/resources/messages.yml
Normal file
15
src/main/resources/messages.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
prefix: "[<blue>BlockAndSeek<white>] "
|
||||
bs-usage: "Usage: <italic>/blockandseek [SUBCOMMAND]"
|
||||
|
||||
messages-reload: "<green>Successfully reload messages.yml"
|
||||
not-enough-arguments: "Too few args. Usage: {usage}."
|
||||
unknown-subcommand: "<gold>Unknown subcommand <red>{subcommand}<white>."
|
||||
|
||||
#Map
|
||||
maps-list: "Available maps: <gold>{maps}"
|
||||
maps-reload: "<green>Successfully reload <u>maps.yml"
|
||||
map-created: "<green>Successfully created map <underline><gold>{map}<white>."
|
||||
map-missing-world: "<red>Could not find world <gold>{world}<red> in server folder. An existing world is required to create a map"
|
||||
map-creation-failed: "<red>Failed to create map <bold><green>{map}<reset>.<red> Error: {error}."
|
||||
map-already-exist: "<red>Map <gold>{map}<red> already exist!"
|
||||
map-not-exist: "<red>Map <gold>{map}<red> does not exist!"
|
||||
@@ -2,3 +2,8 @@ name: BlockAndSeek
|
||||
version: '0.0.1-a'
|
||||
main: hdvtdev.blockAndSeek.BlockAndSeek
|
||||
api-version: '1.20'
|
||||
commands:
|
||||
blockandseek:
|
||||
aliases:
|
||||
- bs
|
||||
usage: "Usage: /blockandseek [subcommand]"
|
||||
Reference in New Issue
Block a user