commit 098c98e00069684bf983f2e79e093c97665dc1c6 Author: zhaoch23 Date: Wed Mar 13 19:04:24 2024 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c37caf --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..d359b6b --- /dev/null +++ b/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'java' +} + +group = 'com.sakurarealm' +version = '1.0' + +repositories { + mavenCentral() + maven { + name = "spigotmc-repo" + url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/groups/public/" + } +} + +dependencies { + compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" + + compileOnly(fileTree("libs")) +} + +def targetJavaVersion = 8 +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + options.release.set(targetJavaVersion) + } +} + +processResources { + def props = [version: version] + inputs.properties props + filteringCharset 'UTF-8' + filesMatching('plugin.yml') { + expand props + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/libs/PlaceholderAPI-2.10.9.jar b/libs/PlaceholderAPI-2.10.9.jar new file mode 100644 index 0000000..ac94604 Binary files /dev/null and b/libs/PlaceholderAPI-2.10.9.jar differ diff --git a/libs/Towny-0.97.SAKU.jar b/libs/Towny-0.97.SAKU.jar new file mode 100644 index 0000000..52f3ea9 Binary files /dev/null and b/libs/Towny-0.97.SAKU.jar differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..74c706a --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'PlayerRisk' diff --git a/src/main/java/com/sakurarealm/playerrisk/CommandHandler.java b/src/main/java/com/sakurarealm/playerrisk/CommandHandler.java new file mode 100644 index 0000000..881df3f --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/CommandHandler.java @@ -0,0 +1,30 @@ +package com.sakurarealm.playerrisk; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class CommandHandler implements CommandExecutor { + + private final PlayerRisk plugin; + + public CommandHandler(PlayerRisk plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (args.length == 0 || !sender.hasPermission("playerrisk.admin")) { + return true; + } + + if (args[0].equalsIgnoreCase("reload")) { + plugin.load(); + sender.sendMessage("&aPlayerRisk plugin reloaded!"); + return true; + } + + return true; + } +} diff --git a/src/main/java/com/sakurarealm/playerrisk/Listener.java b/src/main/java/com/sakurarealm/playerrisk/Listener.java new file mode 100644 index 0000000..9c96934 --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/Listener.java @@ -0,0 +1,37 @@ +package com.sakurarealm.playerrisk; + +import com.palmergames.bukkit.towny.event.PlayerEnterTownEvent; +import com.palmergames.bukkit.towny.event.PlayerLeaveTownEvent; +import org.apache.commons.lang.NotImplementedException; +import org.bukkit.event.entity.PlayerDeathEvent; + +public class Listener implements org.bukkit.event.Listener { + /** + * TODO: 当玩家进入城镇时, 危险度不再增加. + * + * @param event The PlayerEnterTownEvent. + */ + public void onPlayerEnterTown(PlayerEnterTownEvent event) { + throw new NotImplementedException("Not implemented yet."); + } + + /** + * TODO: 当玩家离开城镇时, 危险度开始增加. + * + * @param event The PlayerLeaveTownEvent. + */ + public void onPlayerLeaveTown(PlayerLeaveTownEvent event) { + throw new NotImplementedException("Not implemented yet."); + } + + /** + * TODO: 当玩家死亡时, 危险度重置. + * + * @param event The PlayerDeathEvent. + */ + public void onPlayerDeath(PlayerDeathEvent event) { + throw new NotImplementedException("Not implemented yet."); + } + + // TODO: Add any other event handlers needed to manage player risk. +} diff --git a/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java b/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java new file mode 100644 index 0000000..d381de2 --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java @@ -0,0 +1,39 @@ +package com.sakurarealm.playerrisk; + +import com.sakurarealm.playerrisk.api.PlayerRiskManager; +import com.sakurarealm.playerrisk.api.PlayerRiskSettings; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +public final class PlayerRisk extends JavaPlugin { + + PlayerRiskManager playerRiskManager = null; + + public PlayerRiskManager getPlayerRiskManager() { + if (playerRiskManager == null) { + throw new NullPointerException("PlayerRisk plugin is not initialized."); + } + return playerRiskManager; + } + + public void load() { + saveDefaultConfig(); + FileConfiguration config = getConfig(); + ConfigurationSection settingsSection = config.getConfigurationSection("settings"); + playerRiskManager = new PlayerRiskManager(this, new PlayerRiskSettings(settingsSection)); + } + + @Override + public void onEnable() { + // Plugin startup logic + load(); + getCommand("playerrisk").setExecutor(new CommandHandler(this)); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + } + +} diff --git a/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskManager.java b/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskManager.java new file mode 100644 index 0000000..d36841b --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskManager.java @@ -0,0 +1,74 @@ +package com.sakurarealm.playerrisk.api; + +import com.sakurarealm.playerrisk.Listener; +import com.sakurarealm.playerrisk.PlayerRisk; +import com.sakurarealm.playerrisk.hook.PlaceHolderAPIHook; +import org.apache.commons.lang.NotImplementedException; +import org.bukkit.OfflinePlayer; + +import java.util.UUID; + +/** + * 危机度区间为0~level_max级,每次离开安全区(城镇),重置危险等级:每待n秒会使危机等级(变量)提升1点, + * 但开始计算时玩家在的每一个每种生物群系最多使危机等级提升10 (如上限level_max是50的话, 玩家至少进入5个不同的生物群系才能达到上限), + * 玩家每次死亡重生或回到安全区,会重置当前危机等级。 + * 所有变量见config.yml + * ... + */ +public class PlayerRiskManager { + + private final PlayerRisk plugin; + + // TODO: Add any data structures needed to manage player risk. + + public PlayerRiskManager(PlayerRisk plugin, PlayerRiskSettings settings) { + this.plugin = plugin; + // Register the event listener. + plugin.getServer().getPluginManager().registerEvents(new Listener(), plugin); + new PlaceHolderAPIHook(this).register(); + } + + public int getPlayerRiskLevel(String playerName) { + // Get offline player by name. + OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); + return getPlayerRiskLevel(player); + } + + public int getPlayerRiskLevel(UUID playerId) { + // Get offline player by UUID. + OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerId); + return getPlayerRiskLevel(player); + } + + /** + * TODO: 获取玩家的危险度等级 + * + * @param player 玩家 + * @return 危险度等级 + */ + public int getPlayerRiskLevel(OfflinePlayer player) { + throw new NotImplementedException("Not implemented yet."); + } + + public void setPlayerRiskLevel(String playerName, int level) { + // Get offline player by name. + OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); + setPlayerRiskLevel(player, level); + } + + public void setPlayerRiskLevel(UUID playerId, int level) { + // Get offline player by UUID. + OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerId); + setPlayerRiskLevel(player, level); + } + + /** + * TODO: 设置玩家的危险度等级 + */ + public void setPlayerRiskLevel(OfflinePlayer player, int level) { + throw new NotImplementedException("Not implemented yet."); + } + + // TODO Add any other methods needed to manage player risk. + +} diff --git a/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskSettings.java b/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskSettings.java new file mode 100644 index 0000000..a9d15d3 --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/api/PlayerRiskSettings.java @@ -0,0 +1,22 @@ +package com.sakurarealm.playerrisk.api; + +import org.bukkit.configuration.ConfigurationSection; + +public class PlayerRiskSettings { + + private final int levelMax; + private final int increaseInterval; + + public PlayerRiskSettings(ConfigurationSection config) { + levelMax = config.getInt("level-max"); + increaseInterval = config.getInt("increase-interval"); + } + + public int getIncreaseInterval() { + return increaseInterval; + } + + public int getLevelMax() { + return levelMax; + } +} diff --git a/src/main/java/com/sakurarealm/playerrisk/hook/PlaceHolderAPIHook.java b/src/main/java/com/sakurarealm/playerrisk/hook/PlaceHolderAPIHook.java new file mode 100644 index 0000000..614a813 --- /dev/null +++ b/src/main/java/com/sakurarealm/playerrisk/hook/PlaceHolderAPIHook.java @@ -0,0 +1,38 @@ +package com.sakurarealm.playerrisk.hook; + +import com.sakurarealm.playerrisk.api.PlayerRiskManager; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.OfflinePlayer; + +public class PlaceHolderAPIHook extends PlaceholderExpansion { + + private final PlayerRiskManager playerRiskManager; + + public PlaceHolderAPIHook(PlayerRiskManager playerRiskManager) { + super(); + this.playerRiskManager = playerRiskManager; + } + + @Override + public String getIdentifier() { + return "prisk"; + } + + @Override + public String getAuthor() { + return "sakurarealm"; + } + + @Override + public String getVersion() { + return "1.0"; + } + + @Override + public String onRequest(OfflinePlayer player, String params) { + if (params.equals("level")) { // prisk_level + return String.valueOf(playerRiskManager.getPlayerRiskLevel(player)); + } + return null; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..c82050d --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,5 @@ +settings: + # 危险度最大值 + level-max: 50 + # 每隔n秒危险度会增加一点 + increase-interval: 60 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..3088fd8 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,14 @@ +name: PlayerRisk +version: '${version}' +main: com.sakurarealm.playerrisk.PlayerRisk + +permissions: + playerrisk.admin: + description: PlayerRisk admin permission + default: op + +commands: + playerrisk: + description: PlayerRisk command + usage: /playerrisk + aliases: [ pr, prisk ] \ No newline at end of file