-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cn.variZoo; | ||
|
||
import cn.variZoo.utils.Message; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.util.StringUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
||
public class Command implements CommandExecutor, TabCompleter { | ||
private final List<String> subcommands; | ||
private final Main plugin; | ||
|
||
public Command(Main main) { | ||
this.plugin = main; | ||
subcommands = new ArrayList<>(List.of("reload", "help")); | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { | ||
|
||
if (args.length == 0 || !subcommands.contains(args[0].toLowerCase())) { | ||
Message.showHelp(sender); | ||
return true; | ||
} | ||
|
||
if (!sender.hasPermission("varizoo." + args[0])) { | ||
Message.sendMsg(sender, "你没有权限执行此命令!"); | ||
return true; | ||
} | ||
|
||
switch (args[0].toLowerCase()) { | ||
case "reload": | ||
long startTime = System.currentTimeMillis(); | ||
Message.sendMsg(sender, "插件重启中..."); | ||
plugin.reload(); | ||
long elapsedTime = System.currentTimeMillis() - startTime; | ||
Message.sendMsg(sender, "VariZoo重启完成,耗时 " + elapsedTime + " ms"); | ||
break; | ||
case "help": | ||
Message.showHelp(sender); | ||
break; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String alias, @NotNull String[] args) { | ||
List<String> ret = new ArrayList<>(); | ||
if (args.length == 1) { | ||
for (String subcmd : subcommands) { | ||
if (!sender.hasPermission("varizoo." + subcmd)) continue; | ||
ret.add(subcmd); | ||
} | ||
return StringUtil.copyPartialMatches(args[0].toLowerCase(), ret, new ArrayList<>()); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package cn.variZoo; | ||
|
||
import cn.variZoo.utils.configuration.Comment; | ||
import cn.variZoo.utils.configuration.ConfigurationFile; | ||
import cn.variZoo.utils.configuration.ConfigurationPart; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Configuration extends ConfigurationFile { | ||
|
||
@Comment("版本号") | ||
public static int version = 3; | ||
|
||
@Comment("总开关") | ||
public static boolean enabled = true; | ||
|
||
@Comment("动物生成相关") | ||
public static AnimalSpawn animalSpawn = new AnimalSpawn(); | ||
@Comment("生育相关") | ||
public static Breed breed = new Breed(); | ||
@Comment("其他相关") | ||
public static Other other = new Other(); | ||
|
||
public static class AnimalSpawn extends ConfigurationPart { | ||
|
||
@Comment("基础配置") | ||
public static Basic basic = new Basic(); | ||
@Comment("在基础上二次突变") | ||
public static Mutant mutant = new Mutant(); | ||
@Comment("黑名单") | ||
public static BlackList blackList = new BlackList(); | ||
|
||
public static class Basic extends ConfigurationPart { | ||
|
||
@Comment({"动物生成时附带体型大小的概率", | ||
"设置为0或者负数禁用, 最大为100"}) | ||
public double apply = 50.0; | ||
|
||
@Comment({"体型变化值", | ||
"degree可填写范围或者多个数字"}) | ||
public String degree = "0.86-1.16"; | ||
|
||
} | ||
|
||
public static class Mutant extends ConfigurationPart { | ||
|
||
@Comment({"变异的概率", "设置为0或者负数禁用, 最大为100"}) | ||
public double apply = 3.0; | ||
@Comment({"MULTIPLY: 简单相乘", "MORE: 自适应, 大的更大, 小的更小"}) | ||
public String mode = "MORE"; | ||
@Comment({"变化值", | ||
"degree可填写范围或者多个数字"}) | ||
public String degree = "0.77, 1.3"; | ||
@Comment("触发变异时产生的粒子特效") | ||
public static Particle particle = new Particle(); | ||
|
||
public static class Particle extends ConfigurationPart { | ||
|
||
@Comment("类型, 留空禁用") | ||
public String type = "GLOW"; | ||
|
||
@Comment("数量") | ||
public int count = 20; | ||
} | ||
|
||
} | ||
|
||
public static class BlackList extends ConfigurationPart { | ||
|
||
@Comment({"不受影响的动物", | ||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html"}) | ||
public List<String> animal = new ArrayList<>(); | ||
|
||
@Comment("不受影响的世界") | ||
public List<String> world = new ArrayList<>(); | ||
|
||
@Comment({"不受影响的生成原因", | ||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html"}) | ||
public List<String> spawnReason = List.of( "SPAWNER"); | ||
|
||
} | ||
|
||
} | ||
|
||
public static class Breed extends ConfigurationPart { | ||
|
||
@Comment("动物生育宝宝是否遗传体型") | ||
public static Inheritance inheritance = new Inheritance(); | ||
@Comment("多胞胎功能") | ||
public static Multiple multiple = new Multiple(); | ||
@Comment({"黑名单", "给予玩家varizoo.skip.breed权限可以单独关闭遗传功能, 防止一些生物牧场被破坏"}) | ||
public static BlackList blackList = new BlackList(); | ||
|
||
public static class Inheritance extends ConfigurationPart { | ||
|
||
@Comment({"父母对孩子体型的影响", "可使用复杂的公式, 留空时禁用", "可用变量:{father}、{mother}父母的体型, {degree}对应下方比例"}) | ||
public String finalScale = "({father} * 1.1 + {mother} * 1.2) / {degree}"; | ||
|
||
@Comment("比例, 配合上方的final-scale使用") | ||
public String degree = "2.0-2.6"; | ||
|
||
@Comment("开启该选项会让宝宝不受animal-spawn的二次体型变化影响") | ||
public boolean skipAnimalSpawn = false; | ||
|
||
@Comment({"当饲养出宝宝时的提示","仅支持minimessage颜色格式, 留空时禁用", "可用变量: {scale}体型, {baby}宝宝名称, {player}玩家名称"}) | ||
public String actionbar = "<white>新生命诞生啦! 是体型为<green> {scale} </green>的{baby}宝宝~</white>"; | ||
} | ||
|
||
public static class Multiple extends ConfigurationPart { | ||
|
||
@Comment({"多胞胎的概率", "设置为0或负数时禁止, 最大为100", "注意不可过高, 每次生育都会触发多胞胎判定, 过高会一直生孩子导致卡服"}) | ||
public double apply = 9.0; | ||
|
||
@Comment({"每次生孩子的间隔", "单位为tick, 20ticks = 1s"}) | ||
public int delay = 3; | ||
|
||
@Comment({"启动多胞胎时, 为了限制生育, 每次生育都会扣除以下血量", "可使用复杂的公式, 留空时禁用", "可用变量:{health}当前血量, {max_health}最大血量"}) | ||
public String hurt = "{health} * 0.05"; | ||
} | ||
|
||
public static class BlackList extends ConfigurationPart { | ||
|
||
@Comment("不受影响的动物") | ||
public List<String> animal = List.of("BEE"); | ||
|
||
@Comment("不受影响的世界") | ||
public List<String> world = new ArrayList<>(); | ||
} | ||
} | ||
|
||
public static class Other extends ConfigurationPart { | ||
|
||
@Comment("体型对最大生命的影响, 会等比例变化生命值") | ||
public boolean effectHealth = true; | ||
|
||
@Comment("动物转变时是否保留体型, 比如猪被雷劈变成猪灵, 依旧会继承体型") | ||
public boolean transform = true; | ||
|
||
@Comment("蝾螈、鱼等动物装进桶后放出会失去原有的体型, 该功能可以保留体型, 会修正鱼桶和发射器") | ||
public boolean bucketFishFix = true; | ||
|
||
@Comment({"使动物的掉落物数量乘以以下值", "可使用复杂的公式, 留空时禁用", "可用变量:{scale}生物体型"}) | ||
public String increaseDrops = "sqrt({scale})"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cn.variZoo; | ||
|
||
import cn.variZoo.managers.ConfigManager; | ||
import cn.variZoo.managers.ListenerManager; | ||
import cn.variZoo.utils.*; | ||
import org.bukkit.attribute.Attribute; | ||
import org.bukkit.command.PluginCommand; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public final class Main extends JavaPlugin { | ||
public ConfigManager configManager; | ||
public ListenerManager listenerManager; | ||
private boolean folia; | ||
|
||
@Override | ||
public void onEnable() { | ||
long startTime = System.currentTimeMillis(); | ||
|
||
new XLogger(this); | ||
|
||
boolean enabled = false; | ||
for (Attribute attribute : Attribute.values()) { | ||
if (attribute.name().toLowerCase().contains("scale")) { | ||
new EntityUtil(this,attribute); | ||
enabled = true; | ||
} | ||
} | ||
|
||
if (!enabled) { | ||
XLogger.err("This server is not supported. The plugin will be disabled!"); | ||
this.getServer().getPluginManager().disablePlugin(this); | ||
return; | ||
} | ||
|
||
XLogger.info(this.getServer().getName() + this.getServer().getVersion()); | ||
XLogger.info("██╗ ██╗ █████╗ ██████╗ ██╗███████╗ ██████╗ ██████╗ "); | ||
XLogger.info("██║ ██║██╔══██╗██╔══██╗██║╚══███╔╝██╔═══██╗██╔═══██╗"); | ||
XLogger.info("██║ ██║███████║██████╔╝██║ ███╔╝ ██║ ██║██║ ██║"); | ||
XLogger.info("╚██╗ ██╔╝██╔══██║██╔══██╗██║ ███╔╝ ██║ ██║██║ ██║"); | ||
XLogger.info(" ╚████╔╝ ██║ ██║██║ ██║██║███████╗╚██████╔╝╚██████╔╝"); | ||
XLogger.info(" ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═════╝ "); | ||
XLogger.info("https://github.com/Noogear/VariZoo"); | ||
XLogger.info("Version: " + this.getDescription().getVersion()); | ||
|
||
try { | ||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); | ||
folia = true; | ||
} catch (ClassNotFoundException e) { | ||
folia = false; | ||
} | ||
new Message(); | ||
configManager = new ConfigManager(this); | ||
listenerManager = new ListenerManager(this); | ||
|
||
PluginCommand mainCommand = getCommand("varizoo"); | ||
if (mainCommand != null) { | ||
mainCommand.setExecutor(new Command(this)); | ||
} else { | ||
XLogger.err("Failed to load command."); | ||
} | ||
|
||
new Scheduler(this); | ||
|
||
long elapsedTime = System.currentTimeMillis() - startTime; | ||
XLogger.info("Plugin loaded successfully in " + elapsedTime + " ms"); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
Scheduler.cancelAll(); | ||
} | ||
|
||
public boolean isFolia() { | ||
return folia; | ||
} | ||
|
||
public void reload() { | ||
Scheduler.cancelAll(); | ||
configManager.load(); | ||
listenerManager.reload(); | ||
} | ||
} |
Oops, something went wrong.