初始化提交
This commit is contained in:
14
hamster-auto-game-rule/build.gradle
Normal file
14
hamster-auto-game-rule/build.gradle
Normal file
@@ -0,0 +1,14 @@
|
||||
version = '1.0.0'
|
||||
setArchivesBaseName("HamsterAuto-GameRule")
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
filesMatching("plugin.yml") {
|
||||
expand "version": project.version
|
||||
}
|
||||
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package cn.hamster3.mc.plugin.auto.game.rule;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class GameRulePlugin extends JavaPlugin {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
FileConfiguration pluginConfig = getConfig();
|
||||
ConfigurationSection allWorldsConfig = pluginConfig.getConfigurationSection("all-worlds");
|
||||
if (allWorldsConfig != null) {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (String key : allWorldsConfig.getKeys(false)) {
|
||||
String value = allWorldsConfig.getString(key, "");
|
||||
//noinspection deprecation
|
||||
world.setGameRuleValue(key, value);
|
||||
getLogger().info("已设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigurationSection specialWorldConfig = pluginConfig.getConfigurationSection("special-worlds");
|
||||
if (specialWorldConfig != null) {
|
||||
for (String worldName : specialWorldConfig.getKeys(false)) {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
getLogger().warning("未找到世界: " + worldName);
|
||||
continue;
|
||||
}
|
||||
ConfigurationSection gameRuleConfig = specialWorldConfig.getConfigurationSection(worldName);
|
||||
if (gameRuleConfig != null) {
|
||||
for (String key : gameRuleConfig.getKeys(false)) {
|
||||
String value = gameRuleConfig.getString(key, "");
|
||||
//noinspection deprecation
|
||||
world.setGameRuleValue(key, value);
|
||||
getLogger().info("已单独设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
hamster-auto-game-rule/src/main/resources/config.yml
Normal file
14
hamster-auto-game-rule/src/main/resources/config.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
# 所有的游戏规则可以在这里查看↓
|
||||
# https://minecraft.fandom.com/wiki/Game_rule
|
||||
|
||||
# 所有世界全部生效的规则
|
||||
all-worlds:
|
||||
# 游戏规则名: 规则值
|
||||
keepInventory: true
|
||||
|
||||
# 指定单一某个世界生效的规则
|
||||
special-worlds:
|
||||
# 世界名
|
||||
world:
|
||||
# 游戏规则名: 规则值
|
||||
playersSleepingPercentage: 49
|
8
hamster-auto-game-rule/src/main/resources/plugin.yml
Normal file
8
hamster-auto-game-rule/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: HamsterAuto-GameRule
|
||||
main: cn.hamster3.mc.plugin.auto.game.rule.GameRulePlugin
|
||||
version: ${version}
|
||||
api-version: 1.13
|
||||
|
||||
author: MiniDay
|
||||
website: https://github.com/MiniDay/hamster-little-plugins
|
||||
description: 服务器启动后自动设置 GameRule
|
Reference in New Issue
Block a user