1.0
This commit is contained in:
commit
9e1a8f0298
115
.gitignore
vendored
Normal file
115
.gitignore
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# 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
|
||||
|
||||
target/
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
/src1.7z
|
||||
/src.7z
|
74
pom.xml
Normal file
74
pom.xml
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>TheWarDungeonPlus</groupId>
|
||||
<artifactId>TheWarDungeonPlus</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>TheWarDungeonPlus</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
89
src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java
Normal file
89
src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package com.io.yutian.thewardungeon;
|
||||
|
||||
import com.io.yutian.thewardungeon.command.DungeonCommand;
|
||||
import com.io.yutian.thewardungeon.config.CommonConfig;
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.hook.PluginHook;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.listener.DungeonListener;
|
||||
import com.io.yutian.thewardungeon.listener.ObjectiveListener;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewardungeon.manager.MapManager;
|
||||
import com.io.yutian.thewardungeon.manager.RegistryManager;
|
||||
import com.io.yutian.thewardungeon.papi.DungeonPAPI;
|
||||
import com.io.yutian.thewarskyblocklib.gui.GuiListener;
|
||||
import com.io.yutian.thewarskyblocklib.manager.CommandManager;
|
||||
import com.io.yutian.thewarskyblocklib.util.FileUtil;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class TheWarDungeon extends JavaPlugin {
|
||||
|
||||
private static final String PERSION = "1.0beta";
|
||||
|
||||
private static TheWarDungeon instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
PluginHook.hook();
|
||||
RegistryManager.init();
|
||||
CommonConfig.init();
|
||||
DungeonCommand.init();
|
||||
Lang.reload();
|
||||
MapManager.load();
|
||||
DungeonManager.load();
|
||||
|
||||
registerListener();
|
||||
|
||||
checkWorldFile();
|
||||
|
||||
new DungeonPAPI().register();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
CommandManager.unregisterAll();
|
||||
|
||||
/*
|
||||
for (Dungeon dungeon : DungeonManager.getDungeons()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
dungeonInstance.getWorldInstance().remove();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
checkWorldFile();
|
||||
|
||||
}
|
||||
|
||||
private void checkWorldFile() {
|
||||
File path = new File(System.getProperty("user.dir"));
|
||||
for (File file : path.listFiles()) {
|
||||
if (file.isDirectory() && file.getName().startsWith("dw_")) {
|
||||
File file1 = new File(file+File.separator+"dungeonworld.token");
|
||||
if (file1.exists()) {
|
||||
FileUtil.removeDir(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
Bukkit.getPluginManager().registerEvents(new DungeonListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ObjectiveListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
|
||||
}
|
||||
|
||||
public static TheWarDungeon inst() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.io.yutian.thewardungeon.command;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.command.list.*;
|
||||
import com.io.yutian.thewarskyblocklib.command.Command;
|
||||
import com.io.yutian.thewarskyblocklib.command.list.CommandHelp;
|
||||
import com.io.yutian.thewarskyblocklib.manager.CommandManager;
|
||||
|
||||
public class DungeonCommand {
|
||||
|
||||
private static Command command;
|
||||
|
||||
public static void init() {
|
||||
command = Command.of(TheWarDungeon.inst(), "thewardungeon");
|
||||
command.addAlias("dungeon");
|
||||
command.register(new CommandHelp(command, "TheWarDungeon"),
|
||||
new CommandCreate(),
|
||||
new CommandStart(),
|
||||
new CommandLeave(),
|
||||
new CommandGui(),
|
||||
new CommandState(),
|
||||
new CommandDungeonEvent(),
|
||||
new CommandReload());
|
||||
CommandManager.register(command);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.config.DungeonConfig;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import com.io.yutian.thewarskyblocklib.util.FileUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CommandCreate extends ICommand {
|
||||
|
||||
public CommandCreate() {
|
||||
super("create");
|
||||
addArgument(Argument.argument("id", ArgumentTypes.STRING));
|
||||
addArgument(Argument.argument("world", ArgumentTypes.STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
CommandSender sender = commandContext.getSender();
|
||||
String id = commandContext.getArgumentsValue("id").getString();
|
||||
String worldName = commandContext.getArgumentsValue("world").getString();
|
||||
if (DungeonManager.getDungeon(id) != null) {
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c副本 "+id+" 已存在"));
|
||||
return;
|
||||
}
|
||||
File folder = new File(DungeonManager.MAIN_FOLDER, id);
|
||||
File worldFolder = new File(TheWarDungeon.inst().getDataFolder()+File.separator+"maps"+File.separator+worldName);
|
||||
boolean copy = !worldFolder.exists();
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
if (world.getPlayerCount() > 0) {
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c世界"+worldName+"已加载且世界内有玩家,请先卸载世界"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c世界"+worldName+"已加载,请先卸载世界"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§e正在创建副本..."));
|
||||
if (copy) {
|
||||
worldFolder.mkdirs();
|
||||
File importMapFolder = new File(worldName);
|
||||
FileUtil.copyDir(importMapFolder, worldFolder, "advancements", "DIM1", "DIM-1", "data", "datapacks", "playerdata", "stats", "paper-world.yml", "uid.dat", "icon.png", "serverconfig");
|
||||
}
|
||||
if (folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
DungeonConfig dungeonConfig = new DungeonConfig(worldName, folder);
|
||||
dungeonConfig.initConfig();
|
||||
Dungeon dungeon = new Dungeon(id, dungeonConfig);
|
||||
DungeonManager.registerDungeon(id, dungeon);
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§a成功创建副本 §b"+id));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.PlayerState;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandDungeonEvent extends ICommand {
|
||||
|
||||
public CommandDungeonEvent() {
|
||||
super("dungeonevent");
|
||||
addArgument(Argument.argument("uuid", ArgumentTypes.UUID));
|
||||
addArgument(Argument.argument("event", ArgumentTypes.STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
Player player = (Player) commandContext.getSender();
|
||||
UUID uuid = commandContext.getArgumentsValue("uuid").getUUID();
|
||||
String event = commandContext.getArgumentsValue("event").getString();
|
||||
if (!uuid.equals(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
if (event.equalsIgnoreCase("respawn")) {
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
DungeonPlayer dungeonPlayer = dungeonInstance.getPlayer(player);
|
||||
if (dungeonPlayer == null || !dungeonPlayer.getState().equals(PlayerState.DEAD)) {
|
||||
return;
|
||||
}
|
||||
dungeonInstance.respawn(dungeonPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hide() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.gui.DungeonRoomGui;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Suggests;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandGui extends ICommand {
|
||||
|
||||
public CommandGui() {
|
||||
super("gui");
|
||||
addArgument(Argument.argument("id", ArgumentTypes.STRING).suggest(Suggests.DUNGEON_LIST));
|
||||
addArgument(Argument.argument("player", ArgumentTypes.STRING).suggest(Suggests.PLAYER_LIST).optional(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
CommandSender sender = commandContext.getSender();
|
||||
String id = commandContext.getArgumentsValue("id").getString();
|
||||
String playerName = commandContext.getArgumentsValue("player").getString();
|
||||
Dungeon dungeon = DungeonManager.getDungeon(id);
|
||||
if (dungeon == null) {
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c副本 "+id+" 不存在"));
|
||||
return;
|
||||
}
|
||||
if (playerName == null && sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Lang.prefix+"§c请输入玩家ID");
|
||||
return;
|
||||
}
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else if (sender instanceof ConsoleCommandSender) {
|
||||
Player player1 = Bukkit.getPlayer(playerName);
|
||||
player = player1;
|
||||
}
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage(Lang.prefix+Lang.get("command-player-noonline"));
|
||||
return;
|
||||
}
|
||||
if (DungeonManager.getDungeonInstance(player) != null) {
|
||||
if (player.equals(sender)) {
|
||||
sender.sendMessage(Lang.prefix+"§f你已在副本中");
|
||||
} else {
|
||||
sender.sendMessage(Lang.prefix+"§f该玩家已在副本中");
|
||||
}
|
||||
return;
|
||||
}
|
||||
new DungeonRoomGui(player, dungeon).open();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandLeave extends ICommand {
|
||||
|
||||
public CommandLeave() {
|
||||
super("leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
Player player = (Player) commandContext.getSender();
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
if (dungeonInstance == null) {
|
||||
player.sendMessage(Component.text(Lang.get("dungeon.level.no-in-dungeon")));
|
||||
return;
|
||||
}
|
||||
dungeonInstance.leave(player);
|
||||
player.sendMessage(Component.text(Lang.prefix+Lang.get("dungeon.level.message")));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewardungeon.manager.MapManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandReload extends ICommand {
|
||||
|
||||
public CommandReload() {
|
||||
super("reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
CommandSender commandSender = commandContext.getSender();
|
||||
for (Dungeon dungeon : DungeonManager.getDungeons()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
dungeonInstance.stop();
|
||||
}
|
||||
}
|
||||
Lang.reload();
|
||||
MapManager.load();
|
||||
DungeonManager.load();
|
||||
commandSender.sendMessage(Lang.prefix+"§a重载成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emptyExecutes(CommandSender commandSender) {
|
||||
for (Dungeon dungeon : DungeonManager.getDungeons()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
dungeonInstance.stop();
|
||||
}
|
||||
}
|
||||
Lang.reload();
|
||||
DungeonManager.load();
|
||||
commandSender.sendMessage(Lang.prefix+"§a重载成功");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Suggests;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CommandStart extends ICommand {
|
||||
|
||||
public CommandStart() {
|
||||
super("start");
|
||||
addArgument(Argument.argument("id", ArgumentTypes.STRING).suggest(Suggests.DUNGEON_LIST));
|
||||
addArgument(Argument.argument("mode", ArgumentTypes.STRING).suggest(()-> Arrays.asList("start", "match", "room")));
|
||||
addArgument(Argument.argument("player", ArgumentTypes.STRING).suggest(Suggests.PLAYER_LIST).optional(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
CommandSender sender = commandContext.getSender();
|
||||
String id = commandContext.getArgumentsValue("id").getString();
|
||||
String mode = commandContext.getArgumentsValue("mode").getString();
|
||||
String playerName = commandContext.getArgumentsValue("player").getString();
|
||||
Dungeon dungeon = DungeonManager.getDungeon(id);
|
||||
if (dungeon == null) {
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c副本 "+id+" 不存在"));
|
||||
return;
|
||||
}
|
||||
if (playerName == null && sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Lang.prefix+"§c请输入玩家ID");
|
||||
return;
|
||||
}
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else if (sender instanceof ConsoleCommandSender) {
|
||||
Player player1 = Bukkit.getPlayer(playerName);
|
||||
player = player1;
|
||||
}
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage(Lang.prefix+Lang.get("command-player-noonline"));
|
||||
return;
|
||||
}
|
||||
if (DungeonManager.getDungeonInstance(player) != null) {
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(Lang.prefix+"§f你已在副本中");
|
||||
} else {
|
||||
sender.sendMessage(Lang.prefix+"§f该玩家已在副本中");
|
||||
}
|
||||
return;
|
||||
}
|
||||
mode = mode.toLowerCase();
|
||||
if (mode.equalsIgnoreCase("start")) {
|
||||
if (!dungeon.getConfig().getConditionGroup().isValid(player) && !player.isOp()) {
|
||||
return;
|
||||
}
|
||||
if (dungeon.getConfig().getOption().getMin() != 1) {
|
||||
player.sendMessage(Lang.prefix+"§c该副本无法单独开始");
|
||||
return;
|
||||
}
|
||||
if (!dungeon.hasFreeInstance()) {
|
||||
player.sendMessage(Lang.prefix+"§c当前队列已满,请稍等");
|
||||
return;
|
||||
}
|
||||
DungeonInstance instance = dungeon.newInstance();
|
||||
instance.join(player, true);
|
||||
} else if (mode.equalsIgnoreCase("match")) {
|
||||
if (!dungeon.getConfig().getConditionGroup().isValid(player)) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = dungeon.getQueue().findFreeDungeonInstance();
|
||||
if (dungeonInstance == null) {
|
||||
player.sendMessage(Lang.prefix+"§c未找到空闲房间");
|
||||
return;
|
||||
}
|
||||
dungeonInstance.join(player, false);
|
||||
} else if (mode.equalsIgnoreCase("room")) {
|
||||
if (!dungeon.getConfig().getConditionGroup().isValid(player)) {
|
||||
return;
|
||||
}
|
||||
if (!dungeon.hasFreeInstance()) {
|
||||
player.sendMessage(Lang.prefix+"§c当前队列已满,请稍等");
|
||||
return;
|
||||
}
|
||||
DungeonInstance instance = dungeon.newInstance();
|
||||
instance.join(player, false);
|
||||
} else {
|
||||
sender.sendMessage(Lang.prefix+"§c未知的模式");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Suggests;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CommandState extends ICommand {
|
||||
|
||||
public CommandState() {
|
||||
super("state");
|
||||
addArgument(Argument.argument("id", ArgumentTypes.STRING).suggest(Suggests.DUNGEON_LIST));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
CommandSender sender = commandContext.getSender();
|
||||
String id = commandContext.getArgumentsValue("id").getString();
|
||||
Dungeon dungeon = DungeonManager.getDungeon(id);
|
||||
if (dungeon == null) {
|
||||
sender.sendMessage(Component.text(Lang.prefix+"§c副本 "+id+" 不存在"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Component.text("§7---------- §8[§9"+id+"§8]§7----------"));
|
||||
sender.sendMessage(Component.text("§aId: §f"+id));
|
||||
sender.sendMessage(Component.text("§a文件目录: §f"+"plugins"+File.separator+"TheWarDungeon"+File.separator+"dungeons"+File.separator+id));
|
||||
sender.sendMessage(Component.text("§a实例数量: §f"+dungeon.getQueue().size()));
|
||||
sender.sendMessage(Component.text("§a空闲房间数量: §f"+dungeon.getQueue().getAllFreeDungeonInstance().size()));
|
||||
sender.sendMessage(Component.text("§7---------- §8[§9"+id+"§8]§7----------"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.io.yutian.thewardungeon.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.command.CommandContext;
|
||||
import com.io.yutian.thewarskyblocklib.command.ICommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CommandTest extends ICommand {
|
||||
|
||||
public CommandTest() {
|
||||
super("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
Player player = (Player) commandContext.getSender();
|
||||
new BukkitRunnable() {
|
||||
|
||||
private int i = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
i++;
|
||||
if (i >= 5) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
Dungeon dungeon = DungeonManager.getDungeon("fb2");
|
||||
DungeonInstance dungeonInstance = dungeon.newInstance();
|
||||
dungeonInstance.join(player, true);
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()->{
|
||||
dungeonInstance.stop();
|
||||
}, 40L);
|
||||
}
|
||||
}.runTaskTimer(TheWarDungeon.inst(), 0L, 60L);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.io.yutian.thewardungeon.config;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewarskyblocklib.config.Config;
|
||||
import com.io.yutian.thewarskyblocklib.util.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CommonConfig {
|
||||
|
||||
private static Config config;
|
||||
|
||||
public static Config.StringListValue allowCommands;
|
||||
public static Config.LocationValue safeLocation;
|
||||
|
||||
public static void init() {
|
||||
FileUtil.saveResource(TheWarDungeon.inst(), "config.yml", false);
|
||||
File file = FileUtil.getFile(TheWarDungeon.inst(), "config.yml");
|
||||
config = new Config(file, CommonConfig.class);
|
||||
config.define("allowCommands", "allowCommands", new Config.StringListValue());
|
||||
config.define("safeLocation", "safeLocation", new Config.LocationValue());
|
||||
config.load();
|
||||
}
|
||||
|
||||
}
|
212
src/main/java/com/io/yutian/thewardungeon/data/LineMetadata.java
Normal file
212
src/main/java/com/io/yutian/thewardungeon/data/LineMetadata.java
Normal file
|
@ -0,0 +1,212 @@
|
|||
package com.io.yutian.thewardungeon.data;
|
||||
|
||||
import com.io.yutian.thewardungeon.util.ClassUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LineMetadata {
|
||||
|
||||
private String source;
|
||||
private Map<String, String> metadata = new HashMap<>();
|
||||
|
||||
public LineMetadata(String source, Map<String, String> metadata) {
|
||||
this.source = source;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public boolean contains(String key) {
|
||||
return metadata.containsKey(key);
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return getString(key, "");
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
String s = key.toLowerCase();
|
||||
return metadata.getOrDefault(s, defaultValue);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String key) {
|
||||
return getInt(key, 0);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String key, @NotNull int defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String key) {
|
||||
return getBoolean(key, false);
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String key, @NotNull boolean defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Boolean.parseBoolean(s);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String key) {
|
||||
return getDouble(key, 0.0D);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String key, @NotNull double defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(s);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public float getFloat(@NotNull String key) {
|
||||
return getFloat(key, 0.0F);
|
||||
}
|
||||
|
||||
public float getFloat(@NotNull String key, @NotNull float defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(s);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLong(@NotNull String key) {
|
||||
return getLong(key, 0L);
|
||||
}
|
||||
|
||||
public long getLong(@NotNull String key, @NotNull long defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(s);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> List<T> getList(@NotNull String key, @NotNull Class<T> clazz) {
|
||||
return getList(key, clazz, new ArrayList<>());
|
||||
}
|
||||
|
||||
public <T> List<T> getList(@NotNull String key, @NotNull Class<T> clazz, @NotNull List<T> defaultValue) {
|
||||
String s = this.metadata.get(key.toLowerCase());
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (!s.startsWith("[") || !s.endsWith("]")) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
String s1 = s.substring(1, s.length()-1);
|
||||
List<T> list = new ArrayList<>();
|
||||
if (s1.contains(",")) {
|
||||
if (s1.startsWith(",") || s1.endsWith(",")) {
|
||||
return defaultValue;
|
||||
}
|
||||
String[] array = s1.split(",");
|
||||
for (String arg : array) {
|
||||
T obj = loadValue(arg, clazz);
|
||||
if (obj != null) {
|
||||
list.add(obj);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
T obj = loadValue(s1, clazz);
|
||||
if (obj != null) {
|
||||
list.add(obj);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> @Nullable T loadValue(String arg, Class<T> clazz) {
|
||||
Class<?> clazz1 = ClassUtil.PRIMITIVE_TO_WRAPPER.getOrDefault(clazz, clazz);
|
||||
if (clazz1.equals(String.class)) {
|
||||
if (arg.startsWith("\"") && arg.endsWith("\"")) {
|
||||
String arg1 = arg.substring(1, arg.length()-1);
|
||||
return (T) arg1;
|
||||
}
|
||||
return (T) arg;
|
||||
} else if (clazz1.equals(Integer.class)) {
|
||||
if (!StringUtil.isInt(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Integer)Integer.parseInt(arg);
|
||||
}
|
||||
} else if (clazz1.equals(Double.class)) {
|
||||
if (!StringUtil.isDouble(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Double)Double.parseDouble(arg);
|
||||
}
|
||||
} else if (clazz1.equals(Float.class)) {
|
||||
if (!StringUtil.isFloat(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Float)Float.parseFloat(arg);
|
||||
}
|
||||
} else if (clazz1.equals(Long.class)) {
|
||||
if (!StringUtil.isLong(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Long)Long.parseLong(arg);
|
||||
}
|
||||
} else if (clazz1.equals(Byte.class)) {
|
||||
if (!StringUtil.isByte(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Byte)Byte.parseByte(arg);
|
||||
}
|
||||
} else if (clazz1.equals(Boolean.class)) {
|
||||
if (!StringUtil.isBoolean(arg)) {
|
||||
return null;
|
||||
} else {
|
||||
return (T)(Boolean)Boolean.parseBoolean(arg);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LineMetadata{" + source + "}";
|
||||
}
|
||||
|
||||
}
|
122
src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java
Normal file
122
src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
package com.io.yutian.thewardungeon.dungeon;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.config.DungeonConfig;
|
||||
import com.io.yutian.thewardungeon.dungeon.queue.DungeonQueue;
|
||||
import com.io.yutian.thewardungeon.dungeon.world.WorldInstance;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import com.io.yutian.thewarskyblocklib.util.FileUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Dungeon {
|
||||
|
||||
private final String id;
|
||||
private final DungeonConfig config;
|
||||
|
||||
private File mapFolder;
|
||||
|
||||
private final DungeonQueue queue;
|
||||
private List<WorldInstance> worldInstances;
|
||||
|
||||
public Dungeon(String id, DungeonConfig config) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
this.config.read();
|
||||
this.queue = new DungeonQueue(this, config.getOption().getMaxInstance());
|
||||
this.worldInstances = new LinkedList<>();
|
||||
this.mapFolder = new File(TheWarDungeon.inst().getDataFolder()+File.separator+"maps"+File.separator+config.getMap());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public DungeonConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public File getMapFolder() {
|
||||
return mapFolder;
|
||||
}
|
||||
|
||||
public boolean hasFreeInstance() {
|
||||
if (worldInstances.size() < config.getOption().getMaxInstance()) {
|
||||
return true;
|
||||
}
|
||||
for (WorldInstance worldInstance : worldInstances) {
|
||||
if (!worldInstance.isOccupied()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public WorldInstance getFreeInstance() {
|
||||
for (WorldInstance worldInstance : worldInstances) {
|
||||
if (!worldInstance.isOccupied()) {
|
||||
return worldInstance;
|
||||
}
|
||||
}
|
||||
if (worldInstances.size() >= config.getOption().getMaxInstance()) {
|
||||
return null;
|
||||
}
|
||||
if (!mapFolder.exists()) {
|
||||
Log.error("副本Map文件不存在"+ mapFolder);
|
||||
return null;
|
||||
}
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String worldName = "dw_"+id + "_"+ uuid.toString().replace("_", "");
|
||||
File folder = new File(worldName);
|
||||
folder.mkdirs();
|
||||
FileUtil.copyDir(mapFolder, folder);
|
||||
File tFile = new File(folder+File.separator+"dungeonworld.token");
|
||||
if (!tFile.exists()) {
|
||||
try {
|
||||
tFile.createNewFile();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
World world;
|
||||
WorldCreator dungeonWorldCreator = new WorldCreator(worldName);
|
||||
try {
|
||||
world = dungeonWorldCreator.createWorld();
|
||||
world.setKeepSpawnInMemory(false);
|
||||
world.setAutoSave(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
WorldInstance worldInstance = new WorldInstance(folder, world, uuid);
|
||||
worldInstances.add(worldInstance);
|
||||
return worldInstance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DungeonInstance newInstance() {
|
||||
if (!hasFreeInstance()) {
|
||||
return null;
|
||||
}
|
||||
WorldInstance worldInstance = getFreeInstance();
|
||||
DungeonInstance dungeonInstance = new DungeonInstance(worldInstance.getUUID(), this, worldInstance);
|
||||
worldInstance.setOccupied(true);
|
||||
queue.add(dungeonInstance);
|
||||
return dungeonInstance;
|
||||
}
|
||||
|
||||
public DungeonQueue getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dungeon["+id+"]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,401 @@
|
|||
package com.io.yutian.thewardungeon.dungeon;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.ObjectiveGourp;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.LocationObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.RegionObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.TimeObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.PlayerState;
|
||||
import com.io.yutian.thewardungeon.dungeon.world.WorldInstance;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewardungeon.script.ScriptGourp;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import io.lumine.mythic.core.mobs.MobRegistry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DungeonInstance {
|
||||
|
||||
protected final UUID uuid;
|
||||
private final Dungeon dungeon;
|
||||
private final WorldInstance worldInstance;
|
||||
|
||||
private int id;
|
||||
|
||||
private DungeonState state = DungeonState.WAITING;
|
||||
|
||||
private DungeonLobby dungeonLobby;
|
||||
|
||||
private Point spawnPoint;
|
||||
|
||||
private Map<UUID, DungeonPlayer> players = new HashMap<>();
|
||||
private List<ObjectiveGourp> objectiveGourps = new ArrayList<>();
|
||||
|
||||
private int time;
|
||||
|
||||
protected int countdown = -1;
|
||||
|
||||
private List<ActiveMob> activeMobs = new ArrayList<>();
|
||||
|
||||
private List<BukkitTask> tasks = new ArrayList<>();
|
||||
|
||||
private boolean loaded = false;
|
||||
private boolean overdue = false;
|
||||
|
||||
public DungeonInstance(UUID uuid, Dungeon dungeon, WorldInstance worldInstance) {
|
||||
this.uuid = uuid;
|
||||
this.dungeon = dungeon;
|
||||
this.worldInstance = worldInstance;
|
||||
}
|
||||
|
||||
public void join(Player player, boolean start) {
|
||||
if (!canJoin(player)) {
|
||||
return;
|
||||
}
|
||||
addPlayer(player);
|
||||
if (start && players.size() == 1) {
|
||||
player.teleport(dungeon.getConfig().getLobbyPoint().toLocation(worldInstance.getWorld()));
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), this::start, 10L);
|
||||
} else {
|
||||
player.teleport(dungeon.getConfig().getLobbyPoint().toLocation(worldInstance.getWorld()));
|
||||
if (dungeonLobby == null) {
|
||||
this.dungeonLobby = new DungeonLobby(this);
|
||||
this.dungeonLobby.runTaskTimer(TheWarDungeon.inst(), 0, 20L);
|
||||
}
|
||||
dungeonLobby.showBossBar(player);
|
||||
}
|
||||
if (players.size() == dungeon.getConfig().getOption().getMax()) {
|
||||
if (dungeonLobby != null) {
|
||||
dungeonLobby.setCounter(10);
|
||||
for (DungeonPlayer dungeonPlayer : getPlayers()) {
|
||||
dungeonPlayer.getPlayer().sendMessage(Lang.prefix+Lang.get("dungeon.lobby.max"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DungeonPlayer dungeonPlayer : getPlayers()) {
|
||||
Player player1 = dungeonPlayer.getPlayer();
|
||||
player1.sendMessage(Lang.prefix+Lang.get("dungeon.lobby.join", player.getName(), players.size(), dungeon.getConfig().getOption().getMax()));
|
||||
}
|
||||
}
|
||||
|
||||
public void leave(Player player) {
|
||||
if (dungeonLobby != null && state.equals(DungeonState.WAITING)) {
|
||||
dungeonLobby.removeBossBar(player);
|
||||
}
|
||||
DungeonPlayer dungeonPlayer = getPlayer(player);
|
||||
if (dungeonPlayer != null) {
|
||||
player.setGameMode(dungeonPlayer.getGameMode());
|
||||
}
|
||||
if (players.size() - 1 == 0) {
|
||||
if (dungeonLobby != null && dungeonLobby.isCancelled()) {
|
||||
dungeonLobby.cancel();
|
||||
}
|
||||
stop();
|
||||
} else {
|
||||
players.remove(player.getUniqueId());
|
||||
player.teleport(dungeon.getConfig().getEndPoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void respawn(DungeonPlayer player) {
|
||||
if (player.getDeath() > dungeon.getConfig().getOption().getReviveAmount()) {
|
||||
return;
|
||||
}
|
||||
if (player.getState().equals(PlayerState.DEAD)) {
|
||||
player.setState(PlayerState.LIVING);
|
||||
}
|
||||
player.getPlayer().setGameMode(dungeon.getConfig().getOption().getGameMode());
|
||||
World world = worldInstance.getWorld();
|
||||
Location respawnLocation = dungeon.getConfig().getStartPoint().toLocation(world);
|
||||
if (spawnPoint != null) {
|
||||
respawnLocation = spawnPoint.toLocation(world);
|
||||
}
|
||||
player.getPlayer().teleport(respawnLocation);
|
||||
}
|
||||
|
||||
public boolean canJoin(Player player) {
|
||||
return state.equals(DungeonState.WAITING) && players.size() < dungeon.getConfig().getOption().getMax();
|
||||
}
|
||||
|
||||
private void addPlayer(Player player) {
|
||||
if (!state.equals(DungeonState.WAITING)) {
|
||||
return;
|
||||
}
|
||||
players.put(player.getUniqueId(), new DungeonPlayer(player));
|
||||
}
|
||||
|
||||
public void setState(DungeonState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void addTask(BukkitTask task) {
|
||||
if (overdue) {
|
||||
return;
|
||||
}
|
||||
tasks.add(task);
|
||||
}
|
||||
|
||||
public void addActiveMob(ActiveMob activeMob) {
|
||||
activeMobs.add(activeMob);
|
||||
}
|
||||
|
||||
public List<ActiveMob> getActiveMobs() {
|
||||
return activeMobs;
|
||||
}
|
||||
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
public List<ObjectiveGourp> getObjectiveGourps() {
|
||||
return objectiveGourps;
|
||||
}
|
||||
|
||||
public void checkObjectiveGroup() {
|
||||
List<ScriptGourp> scriptGourps = new ArrayList<>();
|
||||
Iterator<ObjectiveGourp> gourpIterator = objectiveGourps.iterator();
|
||||
while (gourpIterator.hasNext()) {
|
||||
ObjectiveGourp gourp = gourpIterator.next();
|
||||
boolean flag = true;
|
||||
for (Objective objective : gourp.getObjectives()) {
|
||||
if (!objective.isComplete()) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
ScriptGourp scriptGourp = new ScriptGourp(gourp.getScripts());
|
||||
scriptGourps.add(scriptGourp);
|
||||
gourpIterator.remove();
|
||||
}
|
||||
}
|
||||
scriptGourps.forEach(scriptGourp -> scriptGourp.execute(this));
|
||||
}
|
||||
|
||||
public void addObjectiveGourp(ObjectiveGourp gourp) {
|
||||
this.objectiveGourps.add(gourp);
|
||||
for (TimeObjective objective : gourp.getObjectives(TimeObjective.class)) {
|
||||
addTask(objective.createTask(this));
|
||||
}
|
||||
}
|
||||
|
||||
public WorldInstance getWorldInstance() {
|
||||
return worldInstance;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public DungeonState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public List<DungeonPlayer> getPlayers() {
|
||||
List<DungeonPlayer> list = new ArrayList<>();
|
||||
players.values().forEach(list::add);
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
public DungeonPlayer getPlayer(Player player) {
|
||||
return players.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (overdue || worldInstance.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
boolean flag = true;
|
||||
while (flag) {
|
||||
if (!isWorldLoaded()) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
state = DungeonState.RUNNING;
|
||||
countdown = dungeon.getConfig().getOption().getCountdown();
|
||||
for (DungeonPlayer dungeonPlayer : getPlayers()) {
|
||||
dungeonPlayer.getPlayer().setGameMode(dungeon.getConfig().getOption().getGameMode());
|
||||
dungeonPlayer.getPlayer().teleport(dungeon.getConfig().getStartPoint().toLocation(worldInstance.getWorld()));
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()-> dungeon.getConfig().getStartScript().execute(this), 5L);
|
||||
tasks.add(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (overdue) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
time++;
|
||||
}
|
||||
}.runTaskTimer(TheWarDungeon.inst(), 0L, 1L));
|
||||
tasks.add(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (overdue) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if (countdown > 0) {
|
||||
countdown--;
|
||||
if (countdown == 0) {
|
||||
stop();
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(TheWarDungeon.inst(), 20L, 20L));
|
||||
tasks.add(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (DungeonPlayer dungeonPlayer : getPlayers()) {
|
||||
Player player = dungeonPlayer.getPlayer();
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player.getWorld());
|
||||
if (dungeonInstance == null || !dungeonInstance.getState().equals(DungeonState.RUNNING)) {
|
||||
return;
|
||||
}
|
||||
for (ObjectiveGourp gourp : dungeonInstance.getObjectiveGourps()) {
|
||||
List<LocationObjective> objectiveList1 = gourp.getObjectives(LocationObjective.class);
|
||||
if (objectiveList1.size() > 0) {
|
||||
for (LocationObjective locationObjective : objectiveList1) {
|
||||
if (locationObjective.isArrive(dungeonInstance, player)) {
|
||||
locationObjective.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<RegionObjective> objectiveList2 = gourp.getObjectives(RegionObjective.class);
|
||||
if (objectiveList2.size() > 0) {
|
||||
for (RegionObjective regionObjective : objectiveList2) {
|
||||
if (regionObjective.isInRegion(dungeonInstance, player)) {
|
||||
regionObjective.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dungeonInstance.checkObjectiveGroup();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(TheWarDungeon.inst(), 0L, 10L));
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWorldLoaded() {
|
||||
try {
|
||||
BukkitAdapter.adapt(worldInstance.getWorld());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (overdue) {
|
||||
return;
|
||||
}
|
||||
overdue = true;
|
||||
state = DungeonState.END;
|
||||
LogUtil.logTimeMap.remove(this.getUUID());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()-> {
|
||||
MobRegistry mobRegistry = MythicBukkit.inst().getMobManager().getMobRegistry();
|
||||
for (Entity entity : worldInstance.getWorld().getEntities()) {
|
||||
if (entity instanceof Player) {
|
||||
continue;
|
||||
}
|
||||
entity.remove();
|
||||
}
|
||||
for (ActiveMob activeMob : activeMobs) {
|
||||
activeMob.setDespawned();
|
||||
MythicBukkit.inst().getMobManager().unregisterActiveMob(activeMob);
|
||||
}
|
||||
}, 15L);
|
||||
|
||||
dungeon.getConfig().getEndScript().execute(this);
|
||||
tasks.forEach(bukkitTask -> {
|
||||
if (!bukkitTask.isCancelled()) {
|
||||
bukkitTask.cancel();
|
||||
}
|
||||
});
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()-> {
|
||||
for (DungeonPlayer dungeonPlayer : getPlayers()) {
|
||||
if (dungeonPlayer.getPlayer() != null && dungeonPlayer.getPlayer().isOnline()) {
|
||||
dungeonPlayer.getPlayer().setGameMode(dungeonPlayer.getGameMode());
|
||||
dungeonPlayer.getPlayer().teleport(dungeon.getConfig().getEndPoint());
|
||||
}
|
||||
}
|
||||
worldInstance.setOccupied(false);
|
||||
}, 20L);
|
||||
}
|
||||
|
||||
public boolean isOverdue() {
|
||||
return overdue;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public int getCountdown() {
|
||||
return countdown;
|
||||
}
|
||||
|
||||
public void setSpawnPoint(Point spawnPoint) {
|
||||
this.spawnPoint = spawnPoint;
|
||||
}
|
||||
|
||||
public Point getSpawnPoint() {
|
||||
return spawnPoint;
|
||||
}
|
||||
|
||||
public void setDungeonLobby(DungeonLobby dungeonLobby) {
|
||||
this.dungeonLobby = dungeonLobby;
|
||||
}
|
||||
|
||||
public DungeonLobby getDungeonLobby() {
|
||||
return dungeonLobby;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DungeonInstance that = (DungeonInstance) o;
|
||||
return Objects.equals(uuid, that.uuid);
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package com.io.yutian.thewardungeon.dungeon;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DungeonLobby extends BukkitRunnable {
|
||||
|
||||
private DungeonInstance dungeonInstance;
|
||||
|
||||
private int counter;
|
||||
private int maxTime;
|
||||
|
||||
private BossBar bossBar;
|
||||
|
||||
public DungeonLobby(DungeonInstance dungeonInstance) {
|
||||
this.dungeonInstance = dungeonInstance;
|
||||
this.maxTime = dungeonInstance.getDungeon().getConfig().getOption().getLobbyWaitTime();
|
||||
this.counter = maxTime;
|
||||
this.bossBar = BossBar.bossBar(Component.text(Lang.get("dungeon.lobby.bossbar", counter)), 1.0F, BossBar.Color.WHITE, BossBar.Overlay.PROGRESS);
|
||||
}
|
||||
|
||||
public void showBossBar(Player player) {
|
||||
player.showBossBar(bossBar);
|
||||
}
|
||||
|
||||
public void removeBossBar(Player player) {
|
||||
player.hideBossBar(bossBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<DungeonPlayer> players = this.dungeonInstance.getPlayers();
|
||||
if (this.dungeonInstance.getState() != DungeonState.WAITING) {
|
||||
this.dungeonInstance.setDungeonLobby(null);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
bossBar.progress((float) ((double) counter / (double) maxTime));
|
||||
bossBar.name(Component.text(Lang.get("dungeon.lobby.bossbar", counter)));
|
||||
if (this.counter == 15) {
|
||||
for (DungeonPlayer dungeonPlayer : players) {
|
||||
Player player = dungeonPlayer.getPlayer();
|
||||
player.sendMessage(Lang.prefix+Lang.get("dungeon.lobby.time-15"));
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.counter <= 3 && this.counter > 0) {
|
||||
for (DungeonPlayer dungeonPlayer : players) {
|
||||
Player player = dungeonPlayer.getPlayer();
|
||||
player.sendMessage(Lang.prefix+Lang.get("dungeon.lobby.time-lessthan-3", this.counter));
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
if (this.counter == 0) {
|
||||
if (dungeonInstance.getPlayers().size() < dungeonInstance.getDungeon().getConfig().getOption().getMin()) {
|
||||
this.counter = maxTime;
|
||||
for (DungeonPlayer dungeonPlayer : players) {
|
||||
Player player = dungeonPlayer.getPlayer();
|
||||
player.sendMessage(Lang.prefix+Lang.get("dungeon.lobby.min-reset"));
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
start();
|
||||
return;
|
||||
}
|
||||
this.counter--;
|
||||
|
||||
}
|
||||
|
||||
public void setCounter(int counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
dungeonInstance.setDungeonLobby(null);
|
||||
for (DungeonPlayer dungeonPlayer : this.dungeonInstance.getPlayers()) {
|
||||
Player player = dungeonPlayer.getPlayer();
|
||||
removeBossBar(player);
|
||||
}
|
||||
this.dungeonInstance.start();
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.io.yutian.thewardungeon.dungeon;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DungeonMap {
|
||||
|
||||
private String id;
|
||||
private File folder;
|
||||
|
||||
public DungeonMap(String id, File folder) {
|
||||
this.id = id;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.io.yutian.thewardungeon.dungeon;
|
||||
|
||||
public enum DungeonState {
|
||||
|
||||
WAITING,
|
||||
RUNNING,
|
||||
END
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.condition;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.hook.PluginHook;
|
||||
import com.io.yutian.thewardungeon.util.JSUtil;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Condition extends ICondition {
|
||||
|
||||
private String text;
|
||||
private String message;
|
||||
|
||||
public Condition(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.text = metadata.getString("text", null);
|
||||
this.message = metadata.getString("message", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Player player) {
|
||||
if (text == null) {
|
||||
Log.warning("运行条件时出现错误!");
|
||||
Log.warning("脚本: "+metadata.getSource());
|
||||
Log.warning("原因: text 参数错误");
|
||||
return false;
|
||||
}
|
||||
if (message == null) {
|
||||
Log.warning("运行条件时出现错误!");
|
||||
Log.warning("脚本: "+metadata.getSource());
|
||||
Log.warning("原因: message 参数错误");
|
||||
return false;
|
||||
}
|
||||
String s = text;
|
||||
if (PluginHook.isHookPlaceholderAPI()) {
|
||||
s = PlaceholderAPI.setPlaceholders(player, s);
|
||||
}
|
||||
try {
|
||||
Object result = JSUtil.eval(s);
|
||||
if (!(result instanceof Boolean)) {
|
||||
Log.warning("运行条件时出现错误!");
|
||||
Log.warning("脚本: "+metadata.getSource());
|
||||
Log.warning("原因: JS条件结果非布尔值");
|
||||
return false;
|
||||
}
|
||||
boolean r = (Boolean) result;
|
||||
if (!r) {
|
||||
String m = ChatColor.translateAlternateColorCodes('&', message);
|
||||
player.sendMessage(m);
|
||||
}
|
||||
return r;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.condition;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConditionGroup {
|
||||
|
||||
private List<ICondition> conditions;
|
||||
|
||||
public ConditionGroup(List<ICondition> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public boolean isValid(Player player) {
|
||||
boolean flag = true;
|
||||
for (ICondition condition : conditions) {
|
||||
if (!condition.isValid(player)) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.condition;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.script.SelectorType;
|
||||
import com.io.yutian.thewardungeon.util.ConsoleColor;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import javassist.bytecode.Opcode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ICondition {
|
||||
|
||||
public LineMetadata metadata;
|
||||
|
||||
public ICondition(LineMetadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public abstract boolean isValid(Player player);
|
||||
|
||||
public static ICondition getCondition(String arg) {
|
||||
String key;
|
||||
String s = arg.toLowerCase();
|
||||
if (s.contains("{")) {
|
||||
key = s.substring(0, s.indexOf("{"));
|
||||
} else if (s.contains("[")) {
|
||||
key = s.substring(0, s.indexOf("["));
|
||||
} else {
|
||||
key = s;
|
||||
}
|
||||
Map<String, String> valueMap = new HashMap<>();
|
||||
String s2 = arg;
|
||||
SelectorType selectorType1 = SelectorType.NULL;
|
||||
if (s2.contains("{") && s2.contains("}")) {
|
||||
int count = 0;
|
||||
String s3 = s2.substring(s2.indexOf(Opcode.LSHR) + 1, s2.lastIndexOf(Opcode.LUSHR));
|
||||
char[] charArray = s3.toCharArray();
|
||||
int length = charArray.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = charArray[i];
|
||||
count = c == '{' ? count + 1 : count;
|
||||
if (c == '}') {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
if (count != 0) {
|
||||
Log.error(ConsoleColor.RED + "加载条件时发生错误: 不平衡支撑" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s3);
|
||||
} else if (s3.length() != 0) {
|
||||
int start = 0;
|
||||
int pos = 0;
|
||||
int depth = 0;
|
||||
String s4 = s3 + "}";
|
||||
char[] charArray2 = s4.toCharArray();
|
||||
int length2 = charArray2.length;
|
||||
for (int i2 = 0; i2 < length2; i2++) {
|
||||
char c2 = charArray2[i2];
|
||||
depth = (c2 == '}' || c2 == ']') ? ((c2 == '{' || c2 == '[') ? depth + 1 : depth) - 1 : depth;
|
||||
if ((c2 == ';' && depth == 0) || (c2 == '}' && depth < 0)) {
|
||||
try {
|
||||
String element = s4.substring(start, pos);
|
||||
if (pos - start > 0 && element.length() > 0) {
|
||||
valueMap.put(element.substring(0, element.indexOf(61)).trim().toLowerCase(), element.substring(element.indexOf(61) + 1).trim());
|
||||
}
|
||||
start = pos + 1;
|
||||
} catch (Exception e) {
|
||||
start = pos + 1;
|
||||
} catch (Throwable th) {
|
||||
int i3 = pos + 1;
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
} else if (!s2.contains("[") || !s2.contains("]")) {
|
||||
key = s2;
|
||||
} else {
|
||||
try {
|
||||
s2 = s2.split("\\[")[1].split("\\]")[0];
|
||||
} catch (ArrayIndexOutOfBoundsException e2) {
|
||||
Log.error(ConsoleColor.RED + "加载条件时发生错误: 无效语法" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s2);
|
||||
}
|
||||
}
|
||||
|
||||
key = key.toLowerCase();
|
||||
if (!key.equalsIgnoreCase("condition")) {
|
||||
Log.error(ConsoleColor.RED + "加载条件时发生错误: 无效条件" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + key);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Constructor constructor = Condition.class.getConstructor(LineMetadata.class);
|
||||
ICondition condition = (ICondition) constructor.newInstance(new LineMetadata(arg, valueMap));
|
||||
return condition;
|
||||
} catch (Exception e) {
|
||||
Log.error(ConsoleColor.RED + "加载条件时发生错误: 未知错误" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + key);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,322 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.config;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.condition.ConditionGroup;
|
||||
import com.io.yutian.thewardungeon.dungeon.condition.ICondition;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.ObjectiveGourp;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.script.ScriptGourp;
|
||||
import com.io.yutian.thewardungeon.util.ConsoleColor;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import com.io.yutian.thewarskyblocklib.math.DirectionPoint;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class DungeonConfig {
|
||||
|
||||
protected File folder;
|
||||
|
||||
private String map;
|
||||
private DirectionPoint lobbyPoint;
|
||||
private DirectionPoint startPoint;
|
||||
private Location endPoint;
|
||||
|
||||
private DungeonOption option = new DungeonOption();
|
||||
|
||||
private ScriptGourp startScript;
|
||||
private ScriptGourp endScript;
|
||||
private Map<Integer, ScriptGourp> timingScripts;
|
||||
|
||||
private ObjectiveGourp defaultObjecive;
|
||||
private ConditionGroup conditionGroup;
|
||||
|
||||
private Map<String, ScriptGourp> scriptGourpMap = new HashMap<>();
|
||||
private Map<String, ObjectiveGourp> objectiveGourpMap = new HashMap<>();
|
||||
|
||||
public DungeonConfig(File folder) {
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public DungeonConfig(String map, File folder) {
|
||||
this.map = map;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public void read() {
|
||||
File configFile = new File(folder, "config.yml");
|
||||
File scriptFile = new File(folder, "script.yml");
|
||||
File objectiveFile = new File(folder, "objective.yml");
|
||||
File conditionFile = new File(folder, "condition.yml");
|
||||
if (!configFile.exists()) {
|
||||
initConfigFile();
|
||||
}
|
||||
if (!scriptFile.exists()) {
|
||||
initScriptFile();
|
||||
}
|
||||
if (!objectiveFile.exists()) {
|
||||
initObjectiveFile();
|
||||
}
|
||||
if (!conditionFile.exists()) {
|
||||
initConditionFile();
|
||||
}
|
||||
FileConfiguration configFileConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||
FileConfiguration scriptFileConfiguration = YamlConfiguration.loadConfiguration(scriptFile);
|
||||
FileConfiguration objectiveFileConfiguration = YamlConfiguration.loadConfiguration(objectiveFile);
|
||||
FileConfiguration conditionFileConfiguration = YamlConfiguration.loadConfiguration(conditionFile);
|
||||
|
||||
// config.yml //
|
||||
map = configFileConfiguration.getString("map");
|
||||
lobbyPoint = configFileConfiguration.contains("location.lobby") && configFileConfiguration.isConfigurationSection("location.lobby") ? DirectionPoint.deserialize(configFileConfiguration.getConfigurationSection("location.lobby")) : null;
|
||||
startPoint = configFileConfiguration.contains("location.start") && configFileConfiguration.isConfigurationSection("location.start") ? DirectionPoint.deserialize(configFileConfiguration.getConfigurationSection("location.start")) : null;
|
||||
if (configFileConfiguration.contains("location.end") && configFileConfiguration.isConfigurationSection("location.end")) {
|
||||
ConfigurationSection configurationSection = configFileConfiguration.getConfigurationSection("location.end");
|
||||
World world = Bukkit.getWorld(configurationSection.getString("world"));
|
||||
if (world != null) {
|
||||
double x = configurationSection.getDouble("x");
|
||||
double y = configurationSection.getDouble("y");
|
||||
double z = configurationSection.getDouble("z");
|
||||
float yaw = (float) configurationSection.getDouble("yaw", 0.0);
|
||||
float pitch = (float) configurationSection.getDouble("pitch", 0.0);
|
||||
endPoint = new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection section0 = configFileConfiguration.getConfigurationSection("options");
|
||||
option.load(section0);
|
||||
// config.yml //
|
||||
|
||||
// script.yml //
|
||||
for (String key : scriptFileConfiguration.getKeys(false)) {
|
||||
if (!scriptFileConfiguration.isList(key)) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 错误的数据结构" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Location]: " + ConsoleColor.WHITE +"./dungeons/"+folder.getName()+"/script.yml");
|
||||
Log.error(ConsoleColor.RED + "[Key]: " + ConsoleColor.WHITE + key);
|
||||
continue;
|
||||
}
|
||||
List<String> lines = scriptFileConfiguration.getStringList(key);
|
||||
List<Script> scripts = new ArrayList<>();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
Script script = Script.getScript(line);
|
||||
scripts.add(script);
|
||||
}
|
||||
ScriptGourp scriptGourp = new ScriptGourp(scripts);
|
||||
if (key.equalsIgnoreCase("start")) {
|
||||
startScript = scriptGourp;
|
||||
} else if (key.equalsIgnoreCase("end")) {
|
||||
endScript = scriptGourp;
|
||||
} else {
|
||||
this.scriptGourpMap.put(key, scriptGourp);
|
||||
}
|
||||
}
|
||||
// script.yml //
|
||||
|
||||
// objective.yml //
|
||||
for (String key : objectiveFileConfiguration.getKeys(false)) {
|
||||
if (!objectiveFileConfiguration.isConfigurationSection(key)) {
|
||||
Log.error(ConsoleColor.RED + "加载目标时发生错误: 错误的数据结构" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Location]: " + ConsoleColor.WHITE +"./dungeons/"+folder.getName()+"/objective.yml");
|
||||
Log.error(ConsoleColor.RED + "[Key]: " + ConsoleColor.WHITE + key);
|
||||
continue;
|
||||
}
|
||||
ConfigurationSection cs = objectiveFileConfiguration.getConfigurationSection(key);
|
||||
List<String> objectivesLines = cs.getStringList("objectives");
|
||||
List<String> scriptsLines = cs.getStringList("scripts");
|
||||
List<Objective> objectives = new ArrayList<>();
|
||||
|
||||
List<Script> scripts = new ArrayList<>();
|
||||
for (int i = 0; i < objectivesLines.size(); i++) {
|
||||
String line = objectivesLines.get(i);
|
||||
Objective objective = Objective.getObjective(line);
|
||||
objectives.add(objective);
|
||||
}
|
||||
for (int i = 0; i < scriptsLines.size(); i++) {
|
||||
String line = scriptsLines.get(i);
|
||||
Script script = Script.getScript(line);
|
||||
scripts.add(script);
|
||||
}
|
||||
this.objectiveGourpMap.put(key, new ObjectiveGourp(objectives, scripts));
|
||||
}
|
||||
// objective.yml //
|
||||
|
||||
// condition.yml //
|
||||
List<String> list = conditionFileConfiguration.getStringList("start");
|
||||
List<ICondition> conditions = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
ICondition condition = ICondition.getCondition(s);
|
||||
if (condition != null) {
|
||||
conditions.add(condition);
|
||||
}
|
||||
}
|
||||
conditionGroup = new ConditionGroup(conditions);
|
||||
// condition.yml //
|
||||
|
||||
}
|
||||
|
||||
public void initConfig() {
|
||||
initConfigFile();
|
||||
initScriptFile();
|
||||
initObjectiveFile();
|
||||
initConditionFile();
|
||||
}
|
||||
|
||||
protected void initConfigFile() {
|
||||
File file = new File(folder, "config.yml");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
fileConfiguration.set("map", map);
|
||||
ConfigurationSection section0 = fileConfiguration.createSection("location");
|
||||
section0.set("lobby.x", 0.0);
|
||||
section0.set("lobby.y", 0.0);
|
||||
section0.set("lobby.z", 0.0);
|
||||
section0.set("lobby.yaw", 0.0);
|
||||
section0.set("lobby.pitch", 0.0);
|
||||
|
||||
section0.set("start.x", 0.0);
|
||||
section0.set("start.y", 0.0);
|
||||
section0.set("start.z", 0.0);
|
||||
section0.set("start.yaw", 0.0);
|
||||
section0.set("start.pitch", 0.0);
|
||||
|
||||
section0.set("end.world", "world");
|
||||
section0.set("end.x", 0.0);
|
||||
section0.set("end.y", 0.0);
|
||||
section0.set("end.z", 0.0);
|
||||
section0.set("end.yaw", 0.0);
|
||||
section0.set("end.pitch", 0.0);
|
||||
|
||||
ConfigurationSection section = fileConfiguration.createSection("options");
|
||||
section.set("min", 1);
|
||||
section.set("max", 8);
|
||||
section.set("lobbyWaitTime", 60);
|
||||
section.set("gamemode", GameMode.ADVENTURE.toString());
|
||||
section.set("revive", true);
|
||||
section.set("reviveAmount", -1);
|
||||
section.set("reviveTime", 10);
|
||||
section.set("breakBlock", false);
|
||||
section.set("placeBlock", false);
|
||||
section.set("pvp", false);
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initScriptFile() {
|
||||
File file = new File(folder, "script.yml");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
fileConfiguration.set("start", Arrays.asList("setObjective{id=test}"));
|
||||
fileConfiguration.set("start", Arrays.asList("message{message=游戏开始}"));
|
||||
fileConfiguration.set("end", Arrays.asList("message{message=游戏结束}"));
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initObjectiveFile() {
|
||||
File file = new File(folder, "objective.yml");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
fileConfiguration.set("test.objectives", Arrays.asList("killmob{type=mm:test;amount=1}"));
|
||||
fileConfiguration.set("test.scripts", Arrays.asList("message{message=游戏结束}", "stop"));
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initConditionFile() {
|
||||
File file = new File(folder, "condition.yml");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
fileConfiguration.set("start", Arrays.asList("condition{text=%player_level%>=30;message=你的等级不足30}"));
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public String getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public Point getLobbyPoint() {
|
||||
return lobbyPoint;
|
||||
}
|
||||
|
||||
public Point getStartPoint() {
|
||||
return startPoint;
|
||||
}
|
||||
|
||||
public Location getEndPoint() {
|
||||
return endPoint;
|
||||
}
|
||||
|
||||
public ScriptGourp getStartScript() {
|
||||
return startScript;
|
||||
}
|
||||
|
||||
public ScriptGourp getEndScript() {
|
||||
return endScript;
|
||||
}
|
||||
|
||||
public Map<Integer, ScriptGourp> getTimingScripts() {
|
||||
return timingScripts;
|
||||
}
|
||||
|
||||
public ObjectiveGourp getDefaultObjecive() {
|
||||
return defaultObjecive;
|
||||
}
|
||||
|
||||
public ConditionGroup getConditionGroup() {
|
||||
return conditionGroup;
|
||||
}
|
||||
|
||||
public ScriptGourp getScriptGourp(String id) {
|
||||
ScriptGourp scriptGourp = scriptGourpMap.getOrDefault(id, null);
|
||||
if (scriptGourp == null) {
|
||||
return null;
|
||||
}
|
||||
return scriptGourp.clone();
|
||||
}
|
||||
|
||||
public ObjectiveGourp getObjectiveGourp(String id) {
|
||||
ObjectiveGourp gourp = objectiveGourpMap.getOrDefault(id, null);
|
||||
if (gourp == null) {
|
||||
return null;
|
||||
}
|
||||
return gourp.clone();
|
||||
}
|
||||
|
||||
public DungeonOption getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.config;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class DungeonOption {
|
||||
|
||||
private int maxInstance;
|
||||
|
||||
private int min;
|
||||
private int max;
|
||||
|
||||
private int lobbyWaitTime;
|
||||
|
||||
private int countdown;
|
||||
|
||||
private GameMode gameMode;
|
||||
|
||||
private boolean revive;
|
||||
private int reviveAmount;
|
||||
private int reviveTime;
|
||||
|
||||
private boolean breakBlock;
|
||||
private boolean placeBlock;
|
||||
|
||||
private boolean pvp;
|
||||
|
||||
public DungeonOption() {
|
||||
}
|
||||
|
||||
public void load(ConfigurationSection configurationSection) {
|
||||
maxInstance = configurationSection.getInt("maxInstance", 10);
|
||||
min = configurationSection.getInt("min", 1);
|
||||
max = configurationSection.getInt("max", 8);
|
||||
lobbyWaitTime = configurationSection.getInt("lobbyWaitTime", 60);
|
||||
countdown = configurationSection.getInt("countdown", -1);
|
||||
gameMode = GameMode.valueOf(configurationSection.getString("gamemode", GameMode.ADVENTURE.toString()));
|
||||
revive = configurationSection.getBoolean("revive", true);
|
||||
reviveAmount = configurationSection.getInt("reviveAmount", -1);
|
||||
reviveTime = configurationSection.getInt("reviveTime", 10);
|
||||
breakBlock = configurationSection.getBoolean("breakBlock", false);
|
||||
placeBlock = configurationSection.getBoolean("placeBlock", false);
|
||||
pvp = configurationSection.getBoolean("pvp", false);
|
||||
}
|
||||
|
||||
public int getMaxInstance() {
|
||||
return maxInstance;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public int getCountdown() {
|
||||
return countdown;
|
||||
}
|
||||
|
||||
public int getLobbyWaitTime() {
|
||||
return lobbyWaitTime;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public boolean isRevive() {
|
||||
return revive;
|
||||
}
|
||||
|
||||
public int getReviveAmount() {
|
||||
return reviveAmount;
|
||||
}
|
||||
|
||||
public int getReviveTime() {
|
||||
return reviveTime;
|
||||
}
|
||||
|
||||
public boolean isBreakBlock() {
|
||||
return breakBlock;
|
||||
}
|
||||
|
||||
public boolean isPlaceBlock() {
|
||||
return placeBlock;
|
||||
}
|
||||
|
||||
public boolean isPVP() {
|
||||
return pvp;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.manager.RegistryManager;
|
||||
import com.io.yutian.thewardungeon.util.ConsoleColor;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import javassist.bytecode.Opcode;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Objective implements Cloneable {
|
||||
|
||||
public LineMetadata metadata;
|
||||
|
||||
private int progress;
|
||||
private int maxProgress = -1;
|
||||
|
||||
public Objective(LineMetadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public void setMaxProgress(int maxProgress) {
|
||||
this.maxProgress = maxProgress;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
if (maxProgress == -1) {
|
||||
return;
|
||||
}
|
||||
if (progress >= maxProgress) {
|
||||
return;
|
||||
}
|
||||
progress++;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return maxProgress == -1 ? 0.0F : progress / maxProgress;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return progress == maxProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Objective clone() {
|
||||
try {
|
||||
return (Objective) super.clone();
|
||||
} catch (Exception e) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static Objective getObjective(String arg) {
|
||||
String key;
|
||||
String s = arg.toLowerCase();
|
||||
if (s.contains("{")) {
|
||||
key = s.substring(0, s.indexOf("{"));
|
||||
} else if (s.contains("[")) {
|
||||
key = s.substring(0, s.indexOf("["));
|
||||
} else {
|
||||
key = s;
|
||||
}
|
||||
Map<String, String> valueMap = new HashMap<>();
|
||||
String s2 = arg;
|
||||
if (s2.contains("{") && s2.contains("}")) {
|
||||
int count = 0;
|
||||
String s3 = s2.substring(s2.indexOf(Opcode.LSHR) + 1, s2.lastIndexOf(Opcode.LUSHR));
|
||||
char[] charArray = s3.toCharArray();
|
||||
int length = charArray.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = charArray[i];
|
||||
count = c == '{' ? count + 1 : count;
|
||||
if (c == '}') {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
if (count != 0) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 不平衡支撑" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s3);
|
||||
} else if (s3.length() != 0) {
|
||||
int start = 0;
|
||||
int pos = 0;
|
||||
int depth = 0;
|
||||
String s4 = s3 + "}";
|
||||
char[] charArray2 = s4.toCharArray();
|
||||
int length2 = charArray2.length;
|
||||
for (int i2 = 0; i2 < length2; i2++) {
|
||||
char c2 = charArray2[i2];
|
||||
depth = (c2 == '}' || c2 == ']') ? ((c2 == '{' || c2 == '[') ? depth + 1 : depth) - 1 : depth;
|
||||
if ((c2 == ';' && depth == 0) || (c2 == '}' && depth < 0)) {
|
||||
try {
|
||||
String element = s4.substring(start, pos);
|
||||
if (pos - start > 0 && element.length() > 0) {
|
||||
valueMap.put(element.substring(0, element.indexOf(61)).trim().toLowerCase(), element.substring(element.indexOf(61) + 1).trim());
|
||||
}
|
||||
start = pos + 1;
|
||||
} catch (Exception e) {
|
||||
start = pos + 1;
|
||||
} catch (Throwable th) {
|
||||
int i3 = pos + 1;
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
} else if (!s2.contains("[") || !s2.contains("]")) {
|
||||
key = s2;
|
||||
} else {
|
||||
try {
|
||||
s2 = s2.split("\\[")[1].split("\\]")[0];
|
||||
} catch (ArrayIndexOutOfBoundsException e2) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 无效语法" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s2);
|
||||
}
|
||||
}
|
||||
key = key.toLowerCase();
|
||||
Class<? extends Objective> clazz = RegistryManager.getObjectiveRegistry().get(key);
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Constructor constructor = clazz.getConstructor(LineMetadata.class);
|
||||
return (Objective) constructor.newInstance(new LineMetadata(arg, valueMap));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective;
|
||||
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ObjectiveGourp {
|
||||
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
|
||||
private List<Objective> objectives = new ArrayList<>();
|
||||
private List<Script> scripts = new ArrayList<>();
|
||||
|
||||
public ObjectiveGourp(List<Objective> objectives, List<Script> scripts) {
|
||||
this.objectives = objectives;
|
||||
this.scripts = scripts;
|
||||
}
|
||||
|
||||
public <O extends Objective> List<O> getObjectives(Class<O> oClass) {
|
||||
List<O> objectives1 = new ArrayList<>();
|
||||
objectives.forEach(objective -> {
|
||||
if (objective.getClass().equals(oClass)) {
|
||||
objectives1.add((O) objective);
|
||||
}
|
||||
});
|
||||
return objectives1;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public List<Objective> getObjectives() {
|
||||
return objectives;
|
||||
}
|
||||
|
||||
public List<Script> getScripts() {
|
||||
return scripts;
|
||||
}
|
||||
|
||||
public ObjectiveGourp clone() {
|
||||
List<Objective> objectives1 = new ArrayList<>();
|
||||
objectives.forEach(objective -> objectives1.add(objective.clone()));
|
||||
List<Script> scripts1 = new ArrayList<>();
|
||||
scripts.forEach(script -> scripts1.add(script.clone()));
|
||||
return new ObjectiveGourp(objectives1, scripts1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class KillMobObjective extends Objective {
|
||||
|
||||
private String type;
|
||||
private int amount;
|
||||
|
||||
public KillMobObjective(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", "minecraft:zombie");
|
||||
this.amount = metadata.getInt("amount", 1);
|
||||
this.setMaxProgress(amount);
|
||||
}
|
||||
|
||||
public boolean isValidEntity(DungeonInstance dungeonInstance, LivingEntity entity) {
|
||||
if (!type.contains(":") || type.startsWith(":") || type.endsWith(":")) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, KillMobObjective.class, "实体类型格式错误");
|
||||
return false;
|
||||
}
|
||||
String prefix = type.split(":")[0].toLowerCase();
|
||||
String type1 = type.split(":")[1];
|
||||
if (prefix.equalsIgnoreCase("minecraft")) {
|
||||
try {
|
||||
EntityType entityType = EntityType.valueOf(type1.toUpperCase());
|
||||
return entityType.equals(entity.getType());
|
||||
} catch (Exception e) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, KillMobObjective.class, "未知的实体类型");
|
||||
return false;
|
||||
}
|
||||
} else if (prefix.equalsIgnoreCase("mm") || prefix.equalsIgnoreCase("mythicmob")) {
|
||||
Optional<ActiveMob> optional = MythicBukkit.inst().getMobManager().getActiveMob(entity.getUniqueId());
|
||||
if (!optional.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
ActiveMob activeMob = optional.get();
|
||||
return activeMob.getMobType().equalsIgnoreCase(type1);
|
||||
} else {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, KillMobObjective.class, "未知的实体类型");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LocationObjective extends Objective {
|
||||
|
||||
private Point location;
|
||||
private double range;
|
||||
|
||||
public LocationObjective(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.location = LineMetadataUtil.readPoint(metadata, "location", null);
|
||||
this.range = metadata.getDouble("range", 1.0);
|
||||
setMaxProgress(1);
|
||||
}
|
||||
|
||||
public boolean isArrive(DungeonInstance dungeonInstance, Player player) {
|
||||
if (location == null) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, LocationObjective.class, "坐标参数错误");
|
||||
return false;
|
||||
}
|
||||
if (range <= 0) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, LocationObjective.class, "范围参数错误,必须大于0");
|
||||
return false;
|
||||
}
|
||||
return location.toLocation(dungeonInstance.getWorldInstance().getWorld()).distanceSquared(player.getLocation()) <= range;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import com.io.yutian.thewarskyblocklib.region.Region;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RegionObjective extends Objective {
|
||||
|
||||
private Point start;
|
||||
private Point end;
|
||||
|
||||
protected Region region;
|
||||
|
||||
public RegionObjective(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.start = LineMetadataUtil.readPoint(metadata, "start", null);
|
||||
this.end = LineMetadataUtil.readPoint(metadata, "end", null);
|
||||
setMaxProgress(1);
|
||||
}
|
||||
|
||||
public boolean isInRegion(DungeonInstance dungeonInstance, Player player) {
|
||||
if (start == null) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, RegionObjective.class, "开始坐标参数错误");
|
||||
return false;
|
||||
}
|
||||
if (end == null) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, RegionObjective.class, "结束坐标参数错误");
|
||||
return false;
|
||||
}
|
||||
if (region == null) {
|
||||
this.region = new Region(dungeonInstance.getWorldInstance().getWorld(), start, end);
|
||||
}
|
||||
return region.isInRegion(player.getLocation());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.objective.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonState;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class TimeObjective extends Objective {
|
||||
|
||||
private int time;
|
||||
|
||||
public TimeObjective(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.time = metadata.getInt("time", 72000);
|
||||
setMaxProgress(time);
|
||||
}
|
||||
|
||||
public BukkitTask createTask(DungeonInstance dungeonInstance) {
|
||||
if (time <= 0) {
|
||||
LogUtil.logObjective(dungeonInstance, metadata, TimeObjective.class, "时间参数错误,必须大于0");
|
||||
return null;
|
||||
}
|
||||
BukkitTask task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (dungeonInstance.isOverdue() || dungeonInstance.getState().equals(DungeonState.END)) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
TimeObjective.this.setProgress(time);
|
||||
dungeonInstance.checkObjectiveGroup();
|
||||
}
|
||||
}.runTaskLater(TheWarDungeon.inst(), time);
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.player;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DungeonPlayer {
|
||||
|
||||
private final Player player;
|
||||
|
||||
private PlayerState state = PlayerState.LIVING;
|
||||
|
||||
private GameMode gameMode;
|
||||
|
||||
private int death = 0;
|
||||
|
||||
public DungeonPlayer(Player player) {
|
||||
this.player = player;
|
||||
setGameMode(player.getGameMode());
|
||||
}
|
||||
|
||||
public void setGameMode(GameMode gameMode) {
|
||||
this.gameMode = gameMode;
|
||||
}
|
||||
|
||||
public void setState(PlayerState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public PlayerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void sendRespawnMessage(DungeonInstance dungeonInstance) {
|
||||
Component component1 = Component.text(Lang.get("dungeon.respawn.message_1", (dungeonInstance.getDungeon().getConfig().getOption().getReviveAmount() == -1 ? "无限" : dungeonInstance.getDungeon().getConfig().getOption().getReviveAmount() - death), dungeonInstance.getDungeon().getConfig().getOption().getReviveTime()) + " ");
|
||||
Component component2 = Component.text(Lang.get("dungeon.respawn.message_2")).clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeon dungeonevent " + player.getUniqueId() + " respawn"));
|
||||
Component component3 = Component.text(Lang.get("dungeon.respawn.message_3")).clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeon leave"));
|
||||
Component main = component1.append(component2).append(Component.text(" ")).append(component3);
|
||||
player.sendMessage(main);
|
||||
}
|
||||
|
||||
public void sendDeathMessage() {
|
||||
player.sendMessage(Component.text(Lang.get("dungeon.respawn.death")));
|
||||
}
|
||||
|
||||
public void addDeath(int death) {
|
||||
this.death += death;
|
||||
}
|
||||
|
||||
public void setDeath(int death) {
|
||||
this.death = death;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public int getDeath() {
|
||||
return death;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.player;
|
||||
|
||||
public enum PlayerState {
|
||||
|
||||
LIVING,
|
||||
DEAD
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.queue;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonState;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DungeonQueue {
|
||||
|
||||
private final Dungeon dungeon;
|
||||
private final int limit;
|
||||
|
||||
private List<DungeonInstanceEntry> dungeonInstanceEntries = new ArrayList<>();
|
||||
|
||||
public DungeonQueue(Dungeon dungeon) {
|
||||
this(dungeon, 10);
|
||||
}
|
||||
|
||||
public DungeonQueue(Dungeon dungeon, int limit) {
|
||||
this.dungeon = dungeon;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public DungeonInstance findFreeDungeonInstance() {
|
||||
checkOverdue();
|
||||
List<DungeonInstance> list = new ArrayList<>();
|
||||
dungeonInstanceEntries.forEach(f->list.add(f.dungeonInstance));
|
||||
for (DungeonInstance dungeonInstance : list) {
|
||||
if (dungeonInstance.getState().equals(DungeonState.WAITING)) {
|
||||
if (dungeonInstance.getPlayers().size() < dungeonInstance.getDungeon().getConfig().getOption().getMax()) {
|
||||
return dungeonInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<DungeonInstance> getAllFreeDungeonInstance() {
|
||||
checkOverdue();
|
||||
List<DungeonInstance> list = new ArrayList<>();
|
||||
dungeonInstanceEntries.forEach(f->list.add(f.dungeonInstance));
|
||||
List<DungeonInstance> list1 = new ArrayList<>();
|
||||
for (DungeonInstance dungeonInstance : list) {
|
||||
if (dungeonInstance.getState().equals(DungeonState.WAITING)) {
|
||||
if (dungeonInstance.getPlayers().size() < dungeonInstance.getDungeon().getConfig().getOption().getMax()) {
|
||||
list1.add(dungeonInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(list1);
|
||||
}
|
||||
|
||||
public List<DungeonInstance> getAllDungeonInstance() {
|
||||
checkOverdue();
|
||||
List<DungeonInstance> list = new ArrayList<>();
|
||||
dungeonInstanceEntries.forEach(f->list.add(f.dungeonInstance));
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
public void add(DungeonInstance dungeonInstance) {
|
||||
checkOverdue();
|
||||
if (dungeonInstanceEntries.size() >= limit) {
|
||||
return;
|
||||
}
|
||||
int id = getNextId();
|
||||
if (id == -1) {
|
||||
return;
|
||||
}
|
||||
dungeonInstance.setId(id);
|
||||
dungeonInstanceEntries.add(new DungeonInstanceEntry(id, dungeonInstance));
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
dungeonInstanceEntries.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
checkOverdue();
|
||||
return dungeonInstanceEntries.size();
|
||||
}
|
||||
|
||||
public int getNextId() {
|
||||
checkOverdue();
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
for (int i = 0; i < limit; i++) {
|
||||
ids.add(i);
|
||||
}
|
||||
for (DungeonInstanceEntry entry : dungeonInstanceEntries) {
|
||||
ids.remove(entry.id);
|
||||
}
|
||||
return ids.size() > 0 ? ids.get(0) : -1;
|
||||
}
|
||||
|
||||
public void checkOverdue() {
|
||||
Iterator<DungeonInstanceEntry> iterator = dungeonInstanceEntries.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
DungeonInstanceEntry instanceEntry = iterator.next();
|
||||
if (instanceEntry.dungeonInstance.isOverdue()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DungeonInstanceEntry {
|
||||
|
||||
private int id;
|
||||
private DungeonInstance dungeonInstance;
|
||||
|
||||
public DungeonInstanceEntry(int id, DungeonInstance dungeonInstance) {
|
||||
this.id = id;
|
||||
this.dungeonInstance = dungeonInstance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.io.yutian.thewardungeon.dungeon.world;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WorldInstance {
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
private File folder;
|
||||
private World world;
|
||||
|
||||
private boolean occupied = false;
|
||||
|
||||
protected boolean destroyed = false;
|
||||
|
||||
public WorldInstance(File folder, World world, UUID uuid) {
|
||||
this.folder = folder;
|
||||
this.world = world;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isOccupied() {
|
||||
return occupied;
|
||||
}
|
||||
|
||||
public void setOccupied(boolean occupied) {
|
||||
this.occupied = occupied;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (destroyed) {
|
||||
return;
|
||||
}
|
||||
destroyed = true;
|
||||
unloadWorld();
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()->{
|
||||
try {
|
||||
FileUtils.deleteDirectory(folder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 10L);
|
||||
}
|
||||
|
||||
private void unloadWorld() {
|
||||
if (world != null) {
|
||||
Bukkit.unloadWorld(world, false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.io.yutian.thewardungeon.event;
|
||||
|
||||
public class Event {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.io.yutian.thewardungeon.gui;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import com.io.yutian.thewarskyblocklib.gui.Gui;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.Button;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ClickType;
|
||||
import com.io.yutian.thewarskyblocklib.util.ItemStackBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DungeonRoomGui extends Gui {
|
||||
|
||||
private static int[] array = new int[] {0,1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,44,45,46,47,48,49,50,51,52,53};
|
||||
private static int[] array1 = new int[] {10,11,12,13,14,15,16,19,20,21,22,23,24,25,28,29,30,31,32,33,34,37,38,39,40,41,42,43};
|
||||
|
||||
private static List<DungeonRoomGui> guis = new ArrayList<>();
|
||||
|
||||
private Dungeon dungeon;
|
||||
|
||||
public DungeonRoomGui(Player player, Dungeon dungeon) {
|
||||
super(player, "房间列表", 54);
|
||||
this.dungeon = dungeon;
|
||||
init();
|
||||
initButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
ItemStack item0 = new ItemStackBuilder(Material.GRAY_STAINED_GLASS_PANE).setDisplayName("§7 ").build();
|
||||
for (int i : array) {
|
||||
addButton(i, new Button(item0));
|
||||
}
|
||||
int i = 0;
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllFreeDungeonInstance()) {
|
||||
if (i >= array1.length) {
|
||||
break;
|
||||
}
|
||||
addButton(array1[i], build(dungeonInstance));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private Button build(DungeonInstance dungeonInstance) {
|
||||
return new Button(new ItemStackBuilder(Material.WHITE_STAINED_GLASS_PANE).setDisplayName("§7#"+dungeonInstance.getId()).addLore(" ", "§a创建者: §f"+dungeonInstance.getPlayers().get(0).getPlayer().getName(), "§a人数: §f"+dungeonInstance.getPlayers().size()+"/"+dungeonInstance.getDungeon().getConfig().getOption().getMax(), " ", "§e点击加入").build()).click((player1, clickType) -> {
|
||||
if (clickType.equals(ClickType.LEFT_CLICK)) {
|
||||
if (!dungeon.getConfig().getConditionGroup().isValid(player)) {
|
||||
return;
|
||||
}
|
||||
if (!dungeonInstance.canJoin(player1)) {
|
||||
return;
|
||||
}
|
||||
dungeonInstance.join(player1, false);
|
||||
player1.closeInventory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
super.open();
|
||||
guis.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(InventoryCloseEvent event) {
|
||||
super.close(event);
|
||||
guis.remove(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.io.yutian.thewardungeon.hook;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.io.yutian.thewardungeon.hook.papi.DungeonExpansion;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class PluginHook {
|
||||
|
||||
private static boolean hookPlaceholderAPI = false;
|
||||
private static boolean hookProtocolLib = false;
|
||||
private static boolean hookVault = false;
|
||||
private static boolean hookLuckPerms = false;
|
||||
|
||||
private static ProtocolManager protocolManager;
|
||||
private static Permission permission;
|
||||
private static Economy economy;
|
||||
private static LuckPerms luckPerms;
|
||||
|
||||
public static void hook() {
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
hookPlaceholderAPI = true;
|
||||
new DungeonExpansion().register();
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
hookProtocolLib = true;
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
hookVault = true;
|
||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
|
||||
hookLuckPerms = true;
|
||||
luckPerms = Bukkit.getServicesManager().load(LuckPerms.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHookPlaceholderAPI() {
|
||||
return hookPlaceholderAPI;
|
||||
}
|
||||
|
||||
public static boolean isHookProtocolLib() {
|
||||
return hookProtocolLib;
|
||||
}
|
||||
|
||||
public static boolean isHookVault() {
|
||||
return hookVault;
|
||||
}
|
||||
|
||||
public static boolean isHookLuckPerms() {
|
||||
return hookLuckPerms;
|
||||
}
|
||||
|
||||
public static ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public static Permission getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public static LuckPerms getLuckPerms() {
|
||||
return luckPerms;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.io.yutian.thewardungeon.hook.papi;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DungeonExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "dungeon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "SuperYuTian";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (params.startsWith("room")) {
|
||||
if (!params.contains("_") || params.endsWith("_")) {
|
||||
return "NULL";
|
||||
}
|
||||
String id = params.split("_")[1];
|
||||
Dungeon dungeon = DungeonManager.getDungeon(id);
|
||||
if (dungeon == null) {
|
||||
return "NULL";
|
||||
}
|
||||
return String.valueOf(dungeon.getQueue().getAllFreeDungeonInstance().size());
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
}
|
59
src/main/java/com/io/yutian/thewardungeon/lang/Lang.java
Normal file
59
src/main/java/com/io/yutian/thewardungeon/lang/Lang.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package com.io.yutian.thewardungeon.lang;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewarskyblocklib.util.FileUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Lang {
|
||||
public static String prefix = "";
|
||||
|
||||
private static Map<String, String> langMap = new HashMap<>();
|
||||
|
||||
public static void reload() {
|
||||
prefix = "";
|
||||
langMap.clear();
|
||||
File file = new File(TheWarDungeon.inst().getDataFolder()+File.separator+ "lang.yml");
|
||||
if (!file.exists()) {
|
||||
FileUtil.saveResource(TheWarDungeon.inst(), "lang.yml", false);
|
||||
}
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
for (String key : fileConfiguration.getKeys(true)) {
|
||||
if (!fileConfiguration.isString(key)) {
|
||||
continue;
|
||||
}
|
||||
String string = fileConfiguration.getString(key);
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
if (key.equalsIgnoreCase("prefix")) {
|
||||
prefix = string;
|
||||
continue;
|
||||
}
|
||||
langMap.put(key, string);
|
||||
}
|
||||
}
|
||||
|
||||
public static FileConfiguration getFileConfiguration() {
|
||||
File file = new File(TheWarDungeon.inst().getDataFolder()+File.separator+ "lang.yml");
|
||||
if (!file.exists()) {
|
||||
FileUtil.saveResource(TheWarDungeon.inst(),"lang.yml", false);
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return langMap.getOrDefault(key, "§onull");
|
||||
}
|
||||
|
||||
public static String get(String key, Object... args) {
|
||||
String s = langMap.getOrDefault(key, "§onull");
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
s = s.replace("$"+i, String.valueOf(args[i]));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
package com.io.yutian.thewardungeon.listener;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.config.CommonConfig;
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.PlayerState;
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import net.minecraft.nbt.NBTCompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DungeonListener implements Listener {
|
||||
|
||||
private static Set<UUID> loginPlayers = new HashSet<>();
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
UUID uuid = event.getUniqueId();
|
||||
File playerDataFile = new File("world"+File.separator+"playerdata"+File.separator+uuid+".dat");
|
||||
if (!playerDataFile.exists()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
NBTTagCompound nbtTagCompound = NBTCompressedStreamTools.a(playerDataFile);
|
||||
String dimension = nbtTagCompound.l("Dimension");
|
||||
if (dimension != null && dimension.startsWith("minecraft:dw")) {
|
||||
loginPlayers.add(uuid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (loginPlayers.contains(player.getUniqueId())) {
|
||||
Location location = CommonConfig.safeLocation.get();
|
||||
if (location != null) {
|
||||
player.teleport(location);
|
||||
}
|
||||
loginPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String command = event.getMessage();
|
||||
if (!isInDungeon(player) || player.isOp()) {
|
||||
return;
|
||||
}
|
||||
if (!command.startsWith("/")) {
|
||||
return;
|
||||
}
|
||||
command = command.substring(1);
|
||||
String mainCommand = command.toLowerCase();
|
||||
if (command.contains(" ")) {
|
||||
mainCommand = command.split(" ")[0];
|
||||
}
|
||||
if (!CommonConfig.allowCommands.get().contains(mainCommand)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(Lang.prefix+"§c在副本内无法使用该命令");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!isInDungeon(player)) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
if (dungeonInstance == null) {
|
||||
return;
|
||||
}
|
||||
DungeonPlayer dungeonPlayer = dungeonInstance.getPlayer(player);
|
||||
event.setCancelled(true);
|
||||
if (dungeonInstance.getDungeon().getConfig().getOption().getReviveAmount() == -1) {
|
||||
dungeonInstance.respawn(dungeonPlayer);
|
||||
return;
|
||||
}
|
||||
dungeonPlayer.addDeath(1);
|
||||
dungeonPlayer.setState(PlayerState.DEAD);
|
||||
if (dungeonPlayer.getDeath() <= dungeonInstance.getDungeon().getConfig().getOption().getReviveAmount()) {
|
||||
dungeonPlayer.sendRespawnMessage(dungeonInstance);
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()-> {
|
||||
if (!dungeonPlayer.getState().equals(PlayerState.DEAD)) {
|
||||
return;
|
||||
}
|
||||
dungeonInstance.leave(player);
|
||||
}, dungeonInstance.getDungeon().getConfig().getOption().getReviveTime() * 20L);
|
||||
} else {
|
||||
dungeonPlayer.sendDeathMessage();
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()-> {
|
||||
DungeonPlayer dungeonPlayer1 = dungeonInstance.getPlayer(player);
|
||||
if (dungeonPlayer1 == null && !dungeonPlayer1.equals(dungeonPlayer)) {
|
||||
return;
|
||||
}
|
||||
dungeonInstance.leave(player);
|
||||
}, 5 * 20L);
|
||||
}
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!isInDungeon(player)) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
if (dungeonInstance == null) {
|
||||
return;
|
||||
}
|
||||
DungeonPlayer dungeonPlayer = dungeonInstance.getPlayer(player);
|
||||
if (dungeonPlayer.getState().equals(PlayerState.DEAD)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!isInDungeon(player)) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
World world = dungeonInstance.getWorldInstance().getWorld();
|
||||
Location respawnLocation = dungeonInstance.getDungeon().getConfig().getStartPoint().toLocation(world);
|
||||
if (dungeonInstance.getSpawnPoint() != null) {
|
||||
respawnLocation = dungeonInstance.getSpawnPoint().toLocation(world);
|
||||
}
|
||||
DungeonPlayer dungeonPlayer = dungeonInstance.getPlayer(player);
|
||||
if (dungeonPlayer.getState().equals(PlayerState.DEAD)) {
|
||||
dungeonPlayer.setState(PlayerState.LIVING);
|
||||
}
|
||||
event.setRespawnLocation(respawnLocation);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (isDungeonWorld(event.getPlayer().getWorld())) {
|
||||
Dungeon dungeon = DungeonManager.getDungeon(event.getPlayer().getWorld());
|
||||
if (!dungeon.getConfig().getOption().isBreakBlock()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (isDungeonWorld(event.getPlayer().getWorld())) {
|
||||
Dungeon dungeon = DungeonManager.getDungeon(event.getPlayer().getWorld());
|
||||
if (!dungeon.getConfig().getOption().isPlaceBlock()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
|
||||
World world = event.getDamager().getWorld();
|
||||
if (isDungeonWorld(world)) {
|
||||
Dungeon dungeon = DungeonManager.getDungeon(world);
|
||||
if (!dungeon.getConfig().getOption().isPVP()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(event.getPlayer());
|
||||
if (dungeonInstance != null) {
|
||||
dungeonInstance.leave(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDungeonWorld(World world) {
|
||||
return world.getName().startsWith("dw_");
|
||||
}
|
||||
|
||||
private boolean isInDungeon(Player player) {
|
||||
return DungeonManager.getDungeonInstance(player) != null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package com.io.yutian.thewardungeon.listener;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonState;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.ObjectiveGourp;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.KillMobObjective;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectiveListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (!isDungeonWorld(entity.getWorld())) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(entity.getWorld());
|
||||
if (dungeonInstance == null || !dungeonInstance.getState().equals(DungeonState.RUNNING)) {
|
||||
return;
|
||||
}
|
||||
for (ObjectiveGourp gourp : dungeonInstance.getObjectiveGourps()) {
|
||||
List<KillMobObjective> objectiveList = gourp.getObjectives(KillMobObjective.class);
|
||||
for (KillMobObjective killMobObjective : objectiveList) {
|
||||
if (killMobObjective.isValidEntity(dungeonInstance, entity)) {
|
||||
killMobObjective.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
dungeonInstance.checkObjectiveGroup();
|
||||
}
|
||||
|
||||
/*
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!isDungeonWorld(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player.getWorld());
|
||||
if (dungeonInstance == null || !dungeonInstance.getState().equals(DungeonState.RUNNING)) {
|
||||
return;
|
||||
}
|
||||
for (ObjectiveGourp gourp : dungeonInstance.getObjectiveGourps()) {
|
||||
List<LocationObjective> objectiveList1 = gourp.getObjectives(LocationObjective.class);
|
||||
if (objectiveList1.size() > 0) {
|
||||
for (LocationObjective locationObjective : objectiveList1) {
|
||||
if (locationObjective.isArrive(dungeonInstance, player)) {
|
||||
locationObjective.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<RegionObjective> objectiveList2 = gourp.getObjectives(RegionObjective.class);
|
||||
if (objectiveList2.size() > 0) {
|
||||
for (RegionObjective regionObjective : objectiveList2) {
|
||||
if (regionObjective.isInRegion(dungeonInstance, player)) {
|
||||
regionObjective.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dungeonInstance.checkObjectiveGroup();
|
||||
}
|
||||
*/
|
||||
|
||||
private boolean isDungeonWorld(World world) {
|
||||
return world.getName().startsWith("dw_");
|
||||
}
|
||||
|
||||
private boolean isInDungeon(Player player) {
|
||||
return DungeonManager.getDungeonInstance(player) != null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.io.yutian.thewardungeon.manager;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.config.DungeonConfig;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class DungeonManager {
|
||||
|
||||
public static final File MAIN_FOLDER = new File(TheWarDungeon.inst().getDataFolder()+File.separator+"dungeons");
|
||||
|
||||
private static Map<String, Dungeon> dungeons = new HashMap<>();
|
||||
|
||||
public static void load() {
|
||||
dungeons.clear();
|
||||
File path = MAIN_FOLDER;
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
for (File file : path.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
String id = file.getName();
|
||||
DungeonConfig dungeonConfig = new DungeonConfig(file);
|
||||
Dungeon dungeon = new Dungeon(id, dungeonConfig);
|
||||
dungeons.put(id, dungeon);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dungeon getDungeon(World world) {
|
||||
for (Dungeon dungeon : dungeons.values()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
if (dungeonInstance.getWorldInstance().getWorld().getName().equals(world.getName())) {
|
||||
return dungeon;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DungeonInstance getDungeonInstance(World world) {
|
||||
for (Dungeon dungeon : dungeons.values()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
if (dungeonInstance.getWorldInstance().getWorld().getName().equals(world.getName())) {
|
||||
return dungeonInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DungeonInstance getDungeonInstance(Player player) {
|
||||
for (Dungeon dungeon : dungeons.values()) {
|
||||
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) {
|
||||
if (dungeonInstance.getPlayer(player) != null) {
|
||||
return dungeonInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Dungeon getDungeon(String id) {
|
||||
return dungeons.get(id);
|
||||
}
|
||||
|
||||
public static Collection<Dungeon> getDungeons() {
|
||||
return dungeons.values();
|
||||
}
|
||||
|
||||
public static void registerDungeon(String id, Dungeon dungeon) {
|
||||
if (dungeons.containsKey(id)) {
|
||||
return;
|
||||
}
|
||||
dungeons.put(id, dungeon);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.io.yutian.thewardungeon.manager;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapManager {
|
||||
|
||||
private static Map<String, DungeonMap> dungeonMaps = new HashMap<>();
|
||||
|
||||
public static void load() {
|
||||
dungeonMaps.clear();
|
||||
File path = new File(TheWarDungeon.inst().getDataFolder()+File.separator+"maps");
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
for (File file : path.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
String id = file.getName();
|
||||
dungeonMaps.put(id, new DungeonMap(id, file));
|
||||
}
|
||||
}
|
||||
|
||||
public static DungeonMap getDungeonMap(String id) {
|
||||
return dungeonMaps.get(id);
|
||||
}
|
||||
|
||||
public static Map<String, DungeonMap> getDungeonMaps() {
|
||||
return dungeonMaps;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.io.yutian.thewardungeon.manager;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.KillMobObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.LocationObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.RegionObjective;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.list.TimeObjective;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.script.list.*;
|
||||
import com.io.yutian.thewarskyblocklib.registry.Registry;
|
||||
|
||||
public class RegistryManager {
|
||||
|
||||
private static Registry<String, Class<? extends Script>> scriptRegistry = new Registry<>();
|
||||
private static Registry<String, Class<? extends Objective>> objectiveRegistry = new Registry<>();
|
||||
|
||||
public static void init() {
|
||||
registerScript();
|
||||
registerObjective();
|
||||
}
|
||||
|
||||
private static void registerScript() {
|
||||
scriptRegistry.add("stop", StopScript.class);
|
||||
scriptRegistry.add("message", MessageScript.class);
|
||||
scriptRegistry.add("teleport", TeleportScript.class);
|
||||
scriptRegistry.add("time", TimeScript.class);
|
||||
scriptRegistry.add("weather", WeatherScript.class);
|
||||
scriptRegistry.add("spawnmob", SpawnMobScript.class);
|
||||
scriptRegistry.add("addobjective", AddObjectiveScript.class);
|
||||
scriptRegistry.add("setblock", SetBlockScript.class);
|
||||
scriptRegistry.add("fillblock", FillBlockScript.class);
|
||||
scriptRegistry.add("kill", KillScript.class);
|
||||
scriptRegistry.add("command", CommandScript.class);
|
||||
scriptRegistry.add("setrespawn", SetRespawnScript.class);
|
||||
scriptRegistry.add("sound", SoundScript.class);
|
||||
scriptRegistry.add("title", TitleScript.class);
|
||||
}
|
||||
|
||||
private static void registerObjective() {
|
||||
objectiveRegistry.add("time", TimeObjective.class);
|
||||
objectiveRegistry.add("killmob", KillMobObjective.class);
|
||||
objectiveRegistry.add("location", LocationObjective.class);
|
||||
objectiveRegistry.add("region", RegionObjective.class);
|
||||
}
|
||||
|
||||
public static Registry<String, Class<? extends Script>> getScriptRegistry() {
|
||||
return scriptRegistry;
|
||||
}
|
||||
|
||||
public static Registry<String, Class<? extends Objective>> getObjectiveRegistry() {
|
||||
return objectiveRegistry;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.io.yutian.thewardungeon.papi;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DungeonPAPI extends PlaceholderExpansion {
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "dungeon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "SuperYuTian";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||
DungeonInstance dungeonInstance = DungeonManager.getDungeonInstance(player);
|
||||
if (dungeonInstance == null) {
|
||||
return "NULL";
|
||||
}
|
||||
dungeonInstance.getCountdown();
|
||||
if (params.equalsIgnoreCase("countdown")) {
|
||||
return String.valueOf(dungeonInstance.getCountdown());
|
||||
} else if (params.equalsIgnoreCase("countdown_total")) {
|
||||
return String.valueOf(dungeonInstance.getDungeon().getConfig().getOption().getCountdown());
|
||||
}
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.io.yutian.thewardungeon.region;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.ConfigSerializable;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.SerializaUtil;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.Serializable;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DungeonRegion implements Serializable<DungeonRegion>, ConfigSerializable {
|
||||
|
||||
private Point min;
|
||||
private Point max;
|
||||
|
||||
public DungeonRegion(Point min, Point max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Point getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public Point getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("min", min.serialize());
|
||||
map.put("max", max.serialize());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("min", min.toJson());
|
||||
jsonObject.put("max", max.toJson());
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public static DungeonRegion deserialize(ConfigurationSection section) {
|
||||
return new DungeonRegion(SerializaUtil.deserialize(Point.class, section.getConfigurationSection("min")), SerializaUtil.deserialize(Point.class, section.getConfigurationSection("max")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DungeonRegion{" +
|
||||
"min=" + min +
|
||||
", max=" + max +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
203
src/main/java/com/io/yutian/thewardungeon/script/Script.java
Normal file
203
src/main/java/com/io/yutian/thewardungeon/script/Script.java
Normal file
|
@ -0,0 +1,203 @@
|
|||
package com.io.yutian.thewardungeon.script;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.manager.RegistryManager;
|
||||
import com.io.yutian.thewardungeon.util.ConsoleColor;
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.EnumUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.StringUtil;
|
||||
import javassist.bytecode.Opcode;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Script implements Cloneable {
|
||||
|
||||
public LineMetadata metadata;
|
||||
|
||||
public SelectorType selectorType;
|
||||
public Object trigger;
|
||||
|
||||
public Script(LineMetadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public abstract void execute(DungeonInstance dungeonInstance);
|
||||
|
||||
@Override
|
||||
public Script clone() {
|
||||
try {
|
||||
return (Script) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static Script getScript(String arg) {
|
||||
String key;
|
||||
String s = arg.toLowerCase();
|
||||
if (arg.startsWith("script ")) {
|
||||
try {
|
||||
String scriptId = arg.split(" ")[1];
|
||||
return new NestScript(null, scriptId);
|
||||
} catch (Exception e) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: Nest" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + arg);
|
||||
return null;
|
||||
}
|
||||
} else if (arg.startsWith("delay ")) {
|
||||
try {
|
||||
String time = arg.split(" ")[1];
|
||||
if (!StringUtil.isInt(time)) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: Delay" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + arg);
|
||||
Log.error(ConsoleColor.RED + "[Cause]: " + ConsoleColor.WHITE + time+ " 不是数字");
|
||||
return null;
|
||||
}
|
||||
int i = Integer.parseInt(time);
|
||||
return new DelayScript(null, i);
|
||||
} catch (Exception e) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: Delay" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + arg);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (s.contains("{")) {
|
||||
key = s.substring(0, s.indexOf("{"));
|
||||
} else if (s.contains("[")) {
|
||||
key = s.substring(0, s.indexOf("["));
|
||||
} else {
|
||||
key = s;
|
||||
}
|
||||
Map<String, String> valueMap = new HashMap<>();
|
||||
String s2 = arg;
|
||||
SelectorType selectorType1 = SelectorType.NULL;
|
||||
if (s2.contains("{") && s2.contains("}")) {
|
||||
int count = 0;
|
||||
String s3 = s2.substring(s2.indexOf(Opcode.LSHR) + 1, s2.lastIndexOf(Opcode.LUSHR));
|
||||
char[] charArray = s3.toCharArray();
|
||||
int length = charArray.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = charArray[i];
|
||||
count = c == '{' ? count + 1 : count;
|
||||
if (c == '}') {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
if (count != 0) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 不平衡支撑" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s3);
|
||||
} else if (s3.length() != 0) {
|
||||
int start = 0;
|
||||
int pos = 0;
|
||||
int depth = 0;
|
||||
String s4 = s3 + "}";
|
||||
char[] charArray2 = s4.toCharArray();
|
||||
int length2 = charArray2.length;
|
||||
for (int i2 = 0; i2 < length2; i2++) {
|
||||
char c2 = charArray2[i2];
|
||||
depth = (c2 == '}' || c2 == ']') ? ((c2 == '{' || c2 == '[') ? depth + 1 : depth) - 1 : depth;
|
||||
if ((c2 == ';' && depth == 0) || (c2 == '}' && depth < 0)) {
|
||||
try {
|
||||
String element = s4.substring(start, pos);
|
||||
if (pos - start > 0 && element.length() > 0) {
|
||||
valueMap.put(element.substring(0, element.indexOf(61)).trim().toLowerCase(), element.substring(element.indexOf(61) + 1).trim());
|
||||
}
|
||||
start = pos + 1;
|
||||
} catch (Exception e) {
|
||||
start = pos + 1;
|
||||
} catch (Throwable th) {
|
||||
int i3 = pos + 1;
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
String s5 = s2.substring(key.length()+pos+1);
|
||||
if (!s5.isEmpty()) {
|
||||
if (s5.contains(" @")) {
|
||||
String arg1 = s5.split("@")[1];
|
||||
if (!EnumUtil.isValidEnum(SelectorType.class, arg1.toUpperCase())) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 未知的选择器类型" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + arg1);
|
||||
return null;
|
||||
}
|
||||
selectorType1 = SelectorType.valueOf(arg1.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!s2.contains("[") || !s2.contains("]")) {
|
||||
key = s2;
|
||||
} else {
|
||||
try {
|
||||
s2 = s2.split("\\[")[1].split("\\]")[0];
|
||||
} catch (ArrayIndexOutOfBoundsException e2) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 无效语法" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + s2);
|
||||
}
|
||||
}
|
||||
|
||||
key = key.toLowerCase();
|
||||
Class<? extends Script> clazz = RegistryManager.getScriptRegistry().get(key);
|
||||
if (clazz == null) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 无效脚本" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + key);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Constructor constructor = clazz.getConstructor(LineMetadata.class);
|
||||
Script script = (Script) constructor.newInstance(new LineMetadata(arg, valueMap));
|
||||
script.selectorType = selectorType1;
|
||||
return script;
|
||||
} catch (Exception e) {
|
||||
Log.error(ConsoleColor.RED + "加载脚本时发生错误: 未知错误" + ConsoleColor.WHITE);
|
||||
Log.error(ConsoleColor.RED + "[Line]: " + ConsoleColor.WHITE + key);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class NestScript extends Script {
|
||||
|
||||
private String group;
|
||||
|
||||
public NestScript(LineMetadata metadata, String group) {
|
||||
super(metadata);
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
ScriptGourp gourp = dungeonInstance.getDungeon().getConfig().getScriptGourp(group);
|
||||
if (gourp == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, NestScript.class, "未知的脚本组");
|
||||
return;
|
||||
}
|
||||
gourp.execute(dungeonInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class DelayScript extends Script {
|
||||
|
||||
public int time;
|
||||
|
||||
public DelayScript(LineMetadata metadata, int time) {
|
||||
super(metadata);
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName()+"{"+ metadata +'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.io.yutian.thewardungeon.script;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptGourp {
|
||||
|
||||
private final List<Script> scripts;
|
||||
|
||||
public ScriptGourp(List<Script> scripts) {
|
||||
this.scripts = scripts;
|
||||
}
|
||||
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
List<Script> queue = new LinkedList<>();
|
||||
scripts.forEach((script -> {
|
||||
queue.add(script.clone());
|
||||
}));
|
||||
execute(queue, dungeonInstance);
|
||||
}
|
||||
|
||||
protected void execute(List<Script> queue, DungeonInstance dungeonInstance) {
|
||||
if (queue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < queue.size(); i++) {
|
||||
Script script = queue.get(i);
|
||||
if (script == null) {
|
||||
continue;
|
||||
}
|
||||
if (script instanceof Script.DelayScript delayScript) {
|
||||
if (i == queue.size()-1) {
|
||||
return;
|
||||
}
|
||||
int time = delayScript.time;
|
||||
List<Script> newQueue = new LinkedList<>();
|
||||
for (int k = i+1; k < queue.size(); k++) {
|
||||
Script script1 = queue.get(k);
|
||||
newQueue.add(script1);
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()->{
|
||||
execute(newQueue, dungeonInstance);
|
||||
}, time);
|
||||
return;
|
||||
}
|
||||
script.execute(dungeonInstance);
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptGourp clone() {
|
||||
List<Script> scripts1 = new ArrayList<>();
|
||||
scripts.forEach(script -> scripts1.add(script.clone()));
|
||||
return new ScriptGourp(scripts1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScriptGourp{" +
|
||||
"scripts=" + scripts +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.io.yutian.thewardungeon.script;
|
||||
|
||||
public enum SelectorType {
|
||||
|
||||
NULL,
|
||||
ALL,
|
||||
SELF,
|
||||
SYSTEM
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.ObjectiveGourp;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
|
||||
public class AddObjectiveScript extends Script {
|
||||
|
||||
private String objective;
|
||||
|
||||
public AddObjectiveScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.objective = metadata.getString("objective", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (this.objective == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, AddObjectiveScript.class, "未知的目标组");
|
||||
return;
|
||||
}
|
||||
ObjectiveGourp gourp = dungeonInstance.getDungeon().getConfig().getObjectiveGourp(objective);
|
||||
if (gourp == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, AddObjectiveScript.class, "未知的目标组");
|
||||
return;
|
||||
}
|
||||
dungeonInstance.addObjectiveGourp(gourp);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.hook.PluginHook;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.script.SelectorType;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandScript extends Script {
|
||||
|
||||
private String text;
|
||||
|
||||
public CommandScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.text = metadata.getString("text", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (text == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, CommandScript.class, "命令参数为空");
|
||||
return;
|
||||
}
|
||||
List<String> commands = new ArrayList<>();
|
||||
if (text.contains(",")) {
|
||||
String[] array = text.split(",");
|
||||
for (String arg : array) {
|
||||
if (arg.startsWith("/")) {
|
||||
commands.add(arg.substring(1));
|
||||
} else {
|
||||
commands.add(arg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (text.startsWith("/")) {
|
||||
commands.add(text.substring(1));
|
||||
} else {
|
||||
commands.add(text);
|
||||
}
|
||||
}
|
||||
if (selectorType.equals(SelectorType.NULL) || selectorType.equals(SelectorType.SYSTEM)) {
|
||||
for (String command : commands) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
} else if (selectorType.equals(SelectorType.ALL)) {
|
||||
for (DungeonPlayer player : dungeonInstance.getPlayers()) {
|
||||
Player player1 = player.getPlayer();
|
||||
for (String command : commands) {
|
||||
String s1 = command;
|
||||
if (PluginHook.isHookPlaceholderAPI()) {
|
||||
s1 = PlaceholderAPI.setPlaceholders(player1, s1);
|
||||
}
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import com.io.yutian.thewarskyblocklib.util.EnumUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.MathUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class FillBlockScript extends Script {
|
||||
|
||||
private String type;
|
||||
private Point start;
|
||||
private Point end;
|
||||
|
||||
public FillBlockScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", "STONE").toUpperCase();
|
||||
this.start = LineMetadataUtil.readPoint(metadata, "start", null);
|
||||
this.end = LineMetadataUtil.readPoint(metadata, "end", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (start == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, FillBlockScript.class, "开始坐标参数错误");
|
||||
return;
|
||||
}
|
||||
if (end == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, FillBlockScript.class, "结束坐标参数错误");
|
||||
return;
|
||||
}
|
||||
if (!EnumUtil.isValidEnum(Material.class, type)) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, FillBlockScript.class, "方块类型参数错误");
|
||||
return;
|
||||
}
|
||||
int minX = (int) MathUtil.round(Math.min(start.getX(), end.getX()), 0);
|
||||
int minY = (int) MathUtil.round(Math.min(start.getY(), end.getY()), 0);
|
||||
int minZ = (int) MathUtil.round(Math.min(start.getZ(), end.getZ()), 0);
|
||||
int maxX = (int) MathUtil.round(Math.max(start.getX(), end.getX()), 0);
|
||||
int maxY = (int) MathUtil.round(Math.max(start.getY(), end.getY()), 0);
|
||||
int maxZ = (int) MathUtil.round(Math.max(start.getZ(), end.getZ()), 0);
|
||||
World world = dungeonInstance.getWorldInstance().getWorld();
|
||||
Material material = Material.valueOf(type);
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
block.setType(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import io.lumine.mythic.api.mobs.MythicMob;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class KillScript extends Script {
|
||||
|
||||
private String type;
|
||||
|
||||
public KillScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", "minecraft:zombie");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (!type.contains(":") || type.startsWith(":") || type.endsWith(":")) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, KillScript.class, "实体类型格式错误");
|
||||
return;
|
||||
}
|
||||
String prefix = type.split(":")[0].toLowerCase();
|
||||
String type1 = type.split(":")[1];
|
||||
if (prefix.equalsIgnoreCase("minecraft")) {
|
||||
try {
|
||||
EntityType entityType = EntityType.valueOf(type1.toUpperCase());
|
||||
for (Entity entity : dungeonInstance.getWorldInstance().getWorld().getEntities()) {
|
||||
if (entity.getType().equals(entityType)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, KillScript.class, "未知的实体类型");
|
||||
}
|
||||
} else if (prefix.equalsIgnoreCase("mm") || prefix.equalsIgnoreCase("mythicmob")) {
|
||||
Optional<MythicMob> optional = MythicBukkit.inst().getMobManager().getMythicMob(type1);
|
||||
if (!optional.isPresent()) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, KillScript.class, "未知的实体类型");
|
||||
return;
|
||||
}
|
||||
for (Entity entity : dungeonInstance.getWorldInstance().getWorld().getEntities()) {
|
||||
Optional<ActiveMob> optional1 = MythicBukkit.inst().getMobManager().getActiveMob(entity.getUniqueId());
|
||||
if (!optional1.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
ActiveMob activeMob = optional1.get();
|
||||
if (activeMob.getMobType().equalsIgnoreCase(type1)) {
|
||||
activeMob.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogUtil.logScript(dungeonInstance, metadata, KillScript.class, "未知的实体类型");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.hook.PluginHook;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class MessageScript extends Script {
|
||||
|
||||
private String message;
|
||||
private boolean placeholder = false;
|
||||
|
||||
public MessageScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.message = metadata.getString("message", "NULL");
|
||||
this.placeholder = metadata.getBoolean("placeholder", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
for (DungeonPlayer player : dungeonInstance.getPlayers()) {
|
||||
String m = ChatColor.translateAlternateColorCodes('&', message);
|
||||
Component component = Component.text(m);
|
||||
if (placeholder && PluginHook.isHookPlaceholderAPI()) {
|
||||
component = Component.text(PlaceholderAPI.setPlaceholders(player.getPlayer(), m));
|
||||
} else {
|
||||
player.getPlayer().sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import com.io.yutian.thewarskyblocklib.util.EnumUtil;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class SetBlockScript extends Script {
|
||||
|
||||
private String type;
|
||||
private Point location;
|
||||
|
||||
public SetBlockScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", "STONE").toUpperCase();
|
||||
this.location = LineMetadataUtil.readPoint(metadata, "location", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (!EnumUtil.isValidEnum(Material.class, type)) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SetBlockScript.class, "方块类型参数错误");
|
||||
return;
|
||||
}
|
||||
if (location == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SetBlockScript.class, "坐标参数错误");
|
||||
return;
|
||||
}
|
||||
location.toLocation(dungeonInstance.getWorldInstance().getWorld()).getBlock().setType(Material.valueOf(type));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
|
||||
public class SetRespawnScript extends Script {
|
||||
|
||||
private Point location;
|
||||
|
||||
public SetRespawnScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
location = LineMetadataUtil.readPoint(metadata, "location", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (location == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SetRespawnScript.class, "坐标参数错误");
|
||||
return;
|
||||
}
|
||||
dungeonInstance.getWorldInstance().getWorld().setSpawnLocation(location.toLocation(dungeonInstance.getWorldInstance().getWorld()));
|
||||
dungeonInstance.setSpawnPoint(location);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.EnumUtil;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
public class SoundScript extends Script {
|
||||
|
||||
private String type;
|
||||
private float volume;
|
||||
private float pitch;
|
||||
|
||||
public SoundScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", Sound.UI_BUTTON_CLICK.toString());
|
||||
this.volume = metadata.getFloat("volume", 1.0f);
|
||||
this.pitch = metadata.getFloat("pitch", 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (!EnumUtil.isValidEnum(Sound.class, type.toUpperCase())) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SoundScript.class, "音效类型参数错误");
|
||||
return;
|
||||
}
|
||||
for (DungeonPlayer player : dungeonInstance.getPlayers()) {
|
||||
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.valueOf(type.toUpperCase()), this.volume, this.pitch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
import io.lumine.mythic.api.mobs.MythicMob;
|
||||
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpawnMobScript extends Script {
|
||||
|
||||
private String type;
|
||||
private int amount;
|
||||
private Point location;
|
||||
|
||||
public SpawnMobScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.type = metadata.getString("type", "minecraft:zombie");
|
||||
this.amount = metadata.getInt("amount", 1);
|
||||
this.location = LineMetadataUtil.readPoint(metadata, "location", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (!type.contains(":") || type.startsWith(":") || type.endsWith(":")) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SpawnMobScript.class, "实体类型格式错误");
|
||||
return;
|
||||
}
|
||||
if (location == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SpawnMobScript.class, "坐标参数错误");
|
||||
return;
|
||||
}
|
||||
String prefix = type.split(":")[0].toLowerCase();
|
||||
String type1 = type.split(":")[1];
|
||||
Location location1 = location.toLocation(dungeonInstance.getWorldInstance().getWorld());
|
||||
if (prefix.equalsIgnoreCase("minecraft")) {
|
||||
try {
|
||||
EntityType entityType = EntityType.valueOf(type1.toUpperCase());
|
||||
for (int i = 0; i < amount; i++) {
|
||||
dungeonInstance.getWorldInstance().getWorld().spawnEntity(location1, entityType);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SpawnMobScript.class, "未知的实体类型");
|
||||
}
|
||||
} else if (prefix.equalsIgnoreCase("mm") || prefix.equalsIgnoreCase("mythicmob")) {
|
||||
Optional<MythicMob> optional = MythicBukkit.inst().getMobManager().getMythicMob(type1);
|
||||
if (!optional.isPresent()) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SpawnMobScript.class, "未知的实体类型");
|
||||
return;
|
||||
}
|
||||
MythicMob mob = optional.get();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
ActiveMob activeMob = mob.spawn(BukkitAdapter.adapt(location1), 0.0);
|
||||
dungeonInstance.addActiveMob(activeMob);
|
||||
}
|
||||
} else {
|
||||
LogUtil.logScript(dungeonInstance, metadata, SpawnMobScript.class, "未知的实体类型");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
|
||||
public class StopScript extends Script {
|
||||
|
||||
public StopScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
dungeonInstance.stop();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.player.DungeonPlayer;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LineMetadataUtil;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
|
||||
public class TeleportScript extends Script {
|
||||
|
||||
private Point location;
|
||||
|
||||
public TeleportScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
this.location = LineMetadataUtil.readPoint(metadata, "location", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (location == null) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, TeleportScript.class, "坐标参数错误");
|
||||
return;
|
||||
}
|
||||
for (DungeonPlayer player : dungeonInstance.getPlayers()) {
|
||||
player.getPlayer().teleport(location.toLocation(dungeonInstance.getWorldInstance().getWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
|
||||
public class TimeScript extends Script {
|
||||
|
||||
private long time;
|
||||
|
||||
public TimeScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
time = metadata.getLong("time", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
if (time < 0) {
|
||||
LogUtil.logScript(dungeonInstance, metadata, TimeScript.class, "时间不得小于0");
|
||||
return;
|
||||
}
|
||||
dungeonInstance.getWorldInstance().getWorld().setTime(time);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class TitleScript extends Script {
|
||||
|
||||
private String title;
|
||||
private String subtitle;
|
||||
private int fadeIn;
|
||||
private int stay;
|
||||
private int fadeOut;
|
||||
|
||||
public TitleScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
title = metadata.getString("title");
|
||||
subtitle = metadata.getString("subtitle");
|
||||
fadeIn = metadata.getInt("fade_in");
|
||||
stay = metadata.getInt("stay");
|
||||
fadeOut = metadata.getInt("fade_out");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
dungeonInstance.getPlayers().forEach(player -> player.getPlayer().showTitle(Title.title(Component.text(title), Component.text(subtitle), Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut)))));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.io.yutian.thewardungeon.script.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
import com.io.yutian.thewardungeon.util.LogUtil;
|
||||
import org.bukkit.WeatherType;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class WeatherScript extends Script {
|
||||
|
||||
private String weatherType;
|
||||
private int time;
|
||||
|
||||
public WeatherScript(LineMetadata metadata) {
|
||||
super(metadata);
|
||||
weatherType = metadata.getString("type", WeatherType.CLEAR.toString()).toLowerCase();
|
||||
time = metadata.getInt("time", Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DungeonInstance dungeonInstance) {
|
||||
World world = dungeonInstance.getWorldInstance().getWorld();
|
||||
if (weatherType.equalsIgnoreCase("clear")) {
|
||||
world.setStorm(false);
|
||||
world.setThundering(false);
|
||||
world.setClearWeatherDuration(time);
|
||||
} else if (weatherType.equalsIgnoreCase("storm")) {
|
||||
world.setStorm(true);
|
||||
world.setThundering(false);
|
||||
world.setWeatherDuration(time);
|
||||
} else if (weatherType.equalsIgnoreCase("thunder")) {
|
||||
world.setStorm(true);
|
||||
world.setThundering(true);
|
||||
world.setWeatherDuration(time);
|
||||
} else {
|
||||
LogUtil.logScript(dungeonInstance, metadata, WeatherScript.class, "未知的天气类型");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClassUtil {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>();
|
||||
|
||||
static {
|
||||
PRIMITIVE_TO_WRAPPER.put(boolean.class, Boolean.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(byte.class, Byte.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(short.class, Short.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(char.class, Character.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(int.class, Integer.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(long.class, Long.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(float.class, Float.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(double.class, Double.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
public enum ConsoleColor {
|
||||
BLACK("\u001b[30m"),
|
||||
RED("\u001b[31m"),
|
||||
GREEN("\u001b[32m"),
|
||||
YELLOW("\u001b[33m"),
|
||||
BLUE("\u001b[34m"),
|
||||
PURPLE("\u001b[35m"),
|
||||
CYAN("\u001b[36m"),
|
||||
WHITE("\u001b[37m"),
|
||||
RESET("\u001b[0m"),
|
||||
BOLD("\u001b[1m"),
|
||||
ITALICS("\u001b[2m"),
|
||||
UNDERLINE("\u001b[4m"),
|
||||
CHECK_MARK("✓"),
|
||||
ERROR_MARK("✗");
|
||||
|
||||
private String ansiColor;
|
||||
|
||||
ConsoleColor(String ansiColor) {
|
||||
this.ansiColor = ansiColor;
|
||||
}
|
||||
|
||||
public String getAnsiColor() {
|
||||
return this.ansiColor;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.ansiColor;
|
||||
}
|
||||
}
|
18
src/main/java/com/io/yutian/thewardungeon/util/JSUtil.java
Normal file
18
src/main/java/com/io/yutian/thewardungeon/util/JSUtil.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
public class JSUtil {
|
||||
|
||||
@Nullable
|
||||
public static Object eval(String arg) throws ScriptException {
|
||||
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
|
||||
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("js");
|
||||
return scriptEngine.eval(arg);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewarskyblocklib.math.DirectionPoint;
|
||||
import com.io.yutian.thewarskyblocklib.math.Point;
|
||||
|
||||
public class LineMetadataUtil {
|
||||
|
||||
public static Point readPoint(LineMetadata lineMetadata, String key, Point defaultValue) {
|
||||
String arg = lineMetadata.getString(key, null);
|
||||
if (arg == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
String[] args = arg.split(",");
|
||||
if (args.length < 3) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
if (args.length == 5) {
|
||||
float yaw = Float.parseFloat(args[3]);
|
||||
float pitch = Float.parseFloat(args[4]);
|
||||
return new DirectionPoint(x, y, z, yaw, pitch);
|
||||
} else if (args.length == 3) {
|
||||
return new Point(x, y, z);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
src/main/java/com/io/yutian/thewardungeon/util/Log.java
Normal file
19
src/main/java/com/io/yutian/thewardungeon/util/Log.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Log {
|
||||
|
||||
public static void info(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("§7[TheWarDungeon] §f" + message);
|
||||
}
|
||||
|
||||
public static void warning(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("§7[TheWarDungeon] §e" + message);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("§7[TheWarDungeon] §c" + message);
|
||||
}
|
||||
|
||||
}
|
49
src/main/java/com/io/yutian/thewardungeon/util/LogUtil.java
Normal file
49
src/main/java/com/io/yutian/thewardungeon/util/LogUtil.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package com.io.yutian.thewardungeon.util;
|
||||
|
||||
import com.io.yutian.thewardungeon.data.LineMetadata;
|
||||
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
||||
import com.io.yutian.thewardungeon.dungeon.objective.Objective;
|
||||
import com.io.yutian.thewardungeon.script.Script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogUtil {
|
||||
|
||||
public static Map<UUID, Map<Class<? extends Objective>, Map<String, Long>>> logTimeMap = new HashMap<>();
|
||||
|
||||
public static void logScript(DungeonInstance instance, LineMetadata lineMetadata, Class<? extends Script> scriptType, String arg) {
|
||||
Log.warning("执行脚本时出现错误!");
|
||||
Log.warning("副本实例: ["+instance.getDungeon().getId()+"] - "+ instance.getUUID());
|
||||
Log.warning("脚本: "+lineMetadata.getSource()+"["+scriptType+"]");
|
||||
Log.warning("原因: "+arg);
|
||||
}
|
||||
|
||||
public static void logObjective(DungeonInstance instance, LineMetadata lineMetadata, Class<? extends Objective> objectiveType, String arg) {
|
||||
Log.warning("触发目标任务时出现错误!");
|
||||
Log.warning("副本实例: ["+instance.getDungeon().getId()+"] - "+ instance.getUUID());
|
||||
Log.warning("目标: "+lineMetadata.getSource()+"["+objectiveType+"]");
|
||||
Log.warning("原因: "+arg);
|
||||
}
|
||||
|
||||
private static boolean isInCooldown(DungeonInstance dungeonInstance, Class<? extends Objective> objectiveType, String arg) {
|
||||
Map<Class<? extends Objective>, Map<String, Long>> map1 = logTimeMap.getOrDefault(dungeonInstance.getUUID(), new HashMap<>());
|
||||
Map<String, Long> map2 = map1.getOrDefault(objectiveType, new HashMap<>());
|
||||
if (!map2.containsKey(arg)) {
|
||||
return false;
|
||||
} else {
|
||||
long time = map2.get(arg);
|
||||
long time1 = System.currentTimeMillis();
|
||||
if (time1 - time <= 10*1000L) {
|
||||
return false;
|
||||
} else {
|
||||
map2.put(arg, time1);
|
||||
map1.put(objectiveType, map2);
|
||||
logTimeMap.put(dungeonInstance.getUUID(), map1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.io.yutian.thewardungeon.world;
|
||||
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.raid.PersistentRaid;
|
||||
import net.minecraft.world.entity.raid.Raid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DungeonPersistentRaid extends PersistentRaid {
|
||||
|
||||
public DungeonPersistentRaid(WorldServer world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Raid a(EntityPlayer player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.io.yutian.thewardungeon.world;
|
||||
|
||||
public class DungeonWorldSetting {
|
||||
|
||||
private boolean thunder = true;
|
||||
private boolean iceAndSnow = true;
|
||||
private boolean randomTick = true;
|
||||
private boolean saveWorld = true;
|
||||
|
||||
public boolean isThunder() {
|
||||
return thunder;
|
||||
}
|
||||
|
||||
public boolean isIceAndSnow() {
|
||||
return iceAndSnow;
|
||||
}
|
||||
|
||||
public boolean isRandomTick() {
|
||||
return randomTick;
|
||||
}
|
||||
|
||||
public boolean isSaveWorld() {
|
||||
return saveWorld;
|
||||
}
|
||||
|
||||
public void setThunder(boolean thunder) {
|
||||
this.thunder = thunder;
|
||||
}
|
||||
|
||||
public void setIceAndSnow(boolean iceAndSnow) {
|
||||
this.iceAndSnow = iceAndSnow;
|
||||
}
|
||||
|
||||
public void setRandomTick(boolean randomTick) {
|
||||
this.randomTick = randomTick;
|
||||
}
|
||||
|
||||
public void setSaveWorld(boolean saveWorld) {
|
||||
this.saveWorld = saveWorld;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Command {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final String command;
|
||||
|
||||
private List<String> aliases = new ArrayList<>();
|
||||
|
||||
private final List<ICommand> commands = new ArrayList<>();
|
||||
|
||||
protected boolean frozen = false;
|
||||
|
||||
private Command(Plugin plugin, String command) {
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public Command register(ICommand... commandArray) {
|
||||
if (frozen) {
|
||||
return this;
|
||||
}
|
||||
for (ICommand iCommand : commandArray) {
|
||||
commands.add(iCommand);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command addAlias(String... aliases) {
|
||||
for (String arg : aliases) {
|
||||
this.aliases.add(arg);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
public void frozen() {
|
||||
frozen = true;
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public List<ICommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public static Command of(Plugin plugin, String command) {
|
||||
return new Command(plugin, command);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentValue;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandContext {
|
||||
|
||||
private String commandLabel;
|
||||
private String command;
|
||||
private CommandSender sender;
|
||||
private Map<String, ArgumentValue> argumentsValues;
|
||||
|
||||
public CommandContext(String commandLabel, String command, CommandSender sender, Map<String, ArgumentValue> argumentsValues) {
|
||||
this.commandLabel = commandLabel;
|
||||
this.command = command;
|
||||
this.sender = sender;
|
||||
this.argumentsValues = argumentsValues;
|
||||
}
|
||||
|
||||
public String getCommandLabel() {
|
||||
return commandLabel;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public ArgumentValue getArgumentsValue(String key) {
|
||||
return argumentsValues.getOrDefault(key, new ArgumentValue(null));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CommandNode {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<CommandNode> childrens = new ArrayList<>();
|
||||
private List<Argument> arguments = new ArrayList<>();
|
||||
|
||||
private List<String> alias = new ArrayList<>();
|
||||
|
||||
private Predicate<CommandSender> commandSenderPredicate = (commandSender -> true);
|
||||
private CommandPerformer commandPerformer;
|
||||
|
||||
public CommandNode(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CommandNode(String name, String[] alias) {
|
||||
this.name = name;
|
||||
this.alias = Arrays.asList(alias);
|
||||
}
|
||||
|
||||
public CommandNode(String name, List<String> alias) {
|
||||
this.name = name;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public CommandNode permission(Predicate<CommandSender> commandSenderPredicate) {
|
||||
this.commandSenderPredicate = commandSenderPredicate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public CommandNode setAlias(List<String> alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addAilas(String alias) {
|
||||
this.alias.add(alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addArgument(Argument argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addChildren(CommandNode commandNode) {
|
||||
this.childrens.add(commandNode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<CommandNode> getChildrens() {
|
||||
return childrens;
|
||||
}
|
||||
|
||||
public List<Argument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public CommandNode executes(CommandPerformer commandPerformer) {
|
||||
this.commandPerformer = commandPerformer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandPerformer getCommand() {
|
||||
return commandPerformer;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static CommandNode node(String name) {
|
||||
return new CommandNode(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CommandPerformer<S extends CommandContext> {
|
||||
|
||||
void run(S context);
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ICommand {
|
||||
|
||||
public static final String PERMISSION_PREFIX = "thewarskyblock.command.";
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
private List<CommandNode> commandNodes = new ArrayList<>();
|
||||
private List<Argument> arguments = new ArrayList<>();
|
||||
|
||||
public ICommand(String name) {
|
||||
this.name = name;
|
||||
this.description = null;
|
||||
}
|
||||
|
||||
public ICommand(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean hide() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void executes(CommandContext commandContext) {
|
||||
}
|
||||
|
||||
public boolean emptyExecutes(CommandSender commandSender) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.isOp() || sender.hasPermission(PERMISSION_PREFIX+name);
|
||||
}
|
||||
|
||||
public ICommand addArgument(Argument argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICommand addCommandNode(CommandNode commandNode) {
|
||||
this.commandNodes.add(commandNode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<CommandNode> getCommandNodes() {
|
||||
return commandNodes;
|
||||
}
|
||||
|
||||
public List<Argument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,351 @@
|
|||
package com.io.yutian.thewarskyblocklib.command;
|
||||
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentValue;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ITabCompleter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SimpleCommandHandler extends org.bukkit.command.@NotNull Command {
|
||||
|
||||
private final String name;
|
||||
private final Command command;
|
||||
|
||||
public SimpleCommandHandler(String name, Command command) {
|
||||
super(name);
|
||||
this.name = name;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args, String commandLabel) {
|
||||
if (args.length == 0) {
|
||||
execute(sender, new String[]{"help", "1"}, commandLabel);
|
||||
return;
|
||||
}
|
||||
List<ICommand> commands = command.getCommands();
|
||||
String command = args[0];
|
||||
Stream<ICommand> stream = commands.stream().filter((c) -> {
|
||||
return c.getName().equalsIgnoreCase(command);
|
||||
});
|
||||
Optional<ICommand> optional = stream.findFirst();
|
||||
if (!optional.isPresent()) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown", command));
|
||||
return;
|
||||
}
|
||||
ICommand iCommand = optional.get();
|
||||
if (!iCommand.hasPermission(sender)) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-no-permission"));
|
||||
return;
|
||||
}
|
||||
List<CommandNode> commandNodes = iCommand.getCommandNodes();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
stringBuilder.append(args[i]);
|
||||
if (i < args.length - 1) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
String commandString = stringBuilder.toString();
|
||||
if (commandNodes.size() == 0) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (iCommand.getArguments().size() > 0) {
|
||||
int argSize = args.length - 1;
|
||||
List<Argument> arguments = iCommand.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size() - 1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size() - k) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", index + 1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, arguments, args, 0);
|
||||
}
|
||||
iCommand.executes(new CommandContext(commandLabel, commandString, sender, map));
|
||||
return;
|
||||
}
|
||||
|
||||
int nodeSize = args.length - 1;
|
||||
|
||||
if (commandNodes.size() > 0 && nodeSize == 0) {
|
||||
if (!iCommand.emptyExecutes(sender)) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-short-arg"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String mainNode = args[1];
|
||||
Stream<CommandNode> nodeStream = commandNodes.stream().filter((n) -> {
|
||||
return n.getName().equalsIgnoreCase(mainNode) || n.getAlias().contains(mainNode);
|
||||
});
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", 2, mainNode));
|
||||
return;
|
||||
}
|
||||
CommandNode node = nodeOptional.get();
|
||||
|
||||
if (node.getChildrens().size() > 0) {
|
||||
checkClidren(commandLabel, commandString, sender, 1, args, node);
|
||||
} else {
|
||||
if (node.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node.getArguments().size() > 0) {
|
||||
int argSize = args.length - 2;
|
||||
List<Argument> arguments = node.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size() - 1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size() - k) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
if (index + 1 >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index + 1];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-error-arg", index + 1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node.getArguments(), args, 1);
|
||||
}
|
||||
node.getCommand().run(new CommandContext(commandLabel, commandString, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", 3, mainNode));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, ArgumentValue> parseArgumentValue(CommandSender commandSender, List<Argument> argumentList, String[] args, int i) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
List<Argument> arguments = argumentList;
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
if (i + 1 + l >= args.length) {
|
||||
if (a.isOptional()) {
|
||||
map.put(a.getName(), new ArgumentValue(a.getDefaultValue()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
String arg = args[i + 1 + l];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
continue;
|
||||
}
|
||||
ArgumentValue argumentValue = new ArgumentValue(a.getArgumentsType().get(arg));
|
||||
map.put(a.getName(), argumentValue);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void checkClidren(String commandLabel, String commandString, CommandSender sender, int i, String[] args, CommandNode node) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
if (node.getCommand() == null) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-short-arg"));
|
||||
} else {
|
||||
node.getCommand().run(new CommandContext(commandLabel, commandString, sender, new HashMap<>()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
String s = args[i];
|
||||
Stream<CommandNode> nodeStream = node.getChildrens().stream().filter((n) -> {
|
||||
return n.getName().equalsIgnoreCase(s) || n.getAlias().contains(s);
|
||||
});
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", i + 1, s));
|
||||
return;
|
||||
}
|
||||
CommandNode node1 = nodeOptional.get();
|
||||
|
||||
if (node1.getChildrens().size() > 0) {
|
||||
checkClidren(commandLabel, commandString, sender, i, args, node1);
|
||||
} else {
|
||||
if (node1.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node1.getArguments().size() > 0) {
|
||||
int argSize = args.length - i - 1;
|
||||
List<Argument> arguments = node1.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size() - 1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size() - k) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = i + l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", index + 1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node1.getArguments(), args, i);
|
||||
}
|
||||
node1.getCommand().run(new CommandContext(commandLabel, commandString, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.prefix + Lang.get("command-unknown-arg", i + 1, s));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
execute(sender, args, commandLabel);
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
||||
return onTabComplete(sender, alias, args);
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, String alias, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
int index = args.length;
|
||||
String arg = args[index - 1];
|
||||
List<ICommand> commands = command.getCommands();
|
||||
if (index == 1) {
|
||||
List<ICommand> commandList = commands.stream().filter((c) -> c.getName().startsWith(arg)).collect(Collectors.toList());
|
||||
if (commandList.size() > 0) {
|
||||
commandList.forEach(c -> {
|
||||
if (c.hasPermission(sender) && !c.hide()) {
|
||||
list.add(c.getName());
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
commandList = commands.stream().filter((c) -> c.getName().contains(arg)).collect(Collectors.toList());
|
||||
if (commandList.size() > 0) {
|
||||
commandList.forEach(c -> {
|
||||
if (c.hasPermission(sender) && !c.hide()) {
|
||||
list.add(c.getName());
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
} else {
|
||||
Optional<ICommand> iCommandOptional = commands.stream().filter((c) -> c.getName().equalsIgnoreCase(args[0])).findFirst();
|
||||
if (!iCommandOptional.isPresent()) {
|
||||
return list;
|
||||
}
|
||||
ICommand iCommand = iCommandOptional.get();
|
||||
if (!iCommand.hasPermission(sender) && iCommand.hide()) {
|
||||
return list;
|
||||
}
|
||||
if (iCommand instanceof ITabCompleter) {
|
||||
ITabCompleter tabCompleter = (ITabCompleter) iCommand;
|
||||
return tabCompleter.onTabComplete(sender, args, index - 2, arg);
|
||||
} else {
|
||||
Map<Integer, List<String>> map = new HashMap<>();
|
||||
if (iCommand.getCommandNodes().size() > 0) {
|
||||
List<String> list1 = new ArrayList<>();
|
||||
for (CommandNode node : iCommand.getCommandNodes()) {
|
||||
list1.add(node.getName());
|
||||
list1.addAll(node.getAlias());
|
||||
if (index >= 2) {
|
||||
if (!node.getName().equalsIgnoreCase(args[1])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (node.getChildrens().size() > 0) {
|
||||
getTabComplete(node, 2, map);
|
||||
} else if (node.getArguments().size() > 0) {
|
||||
List<Argument> arguments = node.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(2 + l + 1, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(2 + l + 1, Arrays.asList("<" + argument.getName() + ">"));
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(2, list1);
|
||||
return preseSuggest(map.getOrDefault(index, list), arg);
|
||||
} else if (iCommand.getArguments().size() > 0) {
|
||||
List<Argument> arguments = iCommand.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(1 + l + 1, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(1 + l + 1, Arrays.asList("<" + argument.getName() + ">"));
|
||||
}
|
||||
return preseSuggest(map.getOrDefault(index, list), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return preseSuggest(list, arg);
|
||||
}
|
||||
|
||||
public static List<String> preseSuggest(List<String> list, String arg) {
|
||||
List<String> newList = new ArrayList<>();
|
||||
List<String> list1 = list.stream().filter((c) -> c.startsWith(arg) || c.toLowerCase().startsWith(arg.toLowerCase())).collect(Collectors.toList());
|
||||
List<String> list2 = list.stream().filter((c) -> c.contains(arg) || c.toLowerCase().contains(arg.toLowerCase())).collect(Collectors.toList());
|
||||
List<String> list3 = list.stream().filter((c) -> c.equalsIgnoreCase(arg) || c.toLowerCase().equalsIgnoreCase(arg.toLowerCase())).collect(Collectors.toList());
|
||||
newList.addAll(list1);
|
||||
newList.addAll(list2);
|
||||
newList.addAll(list3);
|
||||
return newList;
|
||||
}
|
||||
|
||||
private void getTabComplete(CommandNode node, int i, Map<Integer, List<String>> map) {
|
||||
i++;
|
||||
List<String> list = map.getOrDefault(i, new ArrayList<>());
|
||||
for (CommandNode c : node.getChildrens()) {
|
||||
list.add(c.getName());
|
||||
if (c.getChildrens().size() > 0) {
|
||||
getTabComplete(c, i, map);
|
||||
} else if (c.getArguments().size() > 0) {
|
||||
List<Argument> arguments = c.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(i + l + 1, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(i + l + 1, Arrays.asList("<" + argument.getName() + ">"));
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(i, list);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
public class Argument {
|
||||
|
||||
private String name;
|
||||
|
||||
private ArgumentType argumentsType;
|
||||
|
||||
private Suggest suggest;
|
||||
|
||||
private boolean optional = false;
|
||||
private Object defaultValue = null;
|
||||
|
||||
public Argument(String name, ArgumentType argumentsType) {
|
||||
this.name = name;
|
||||
this.argumentsType = argumentsType;
|
||||
}
|
||||
|
||||
public Argument optional(Object defaultValue) {
|
||||
optional = true;
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArgumentType getArgumentsType() {
|
||||
return argumentsType;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Argument suggest(Suggest suggest) {
|
||||
this.suggest = suggest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Suggest getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public static Argument argument(String name, ArgumentType type) {
|
||||
return new Argument(name, type);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ArgumentType<T> {
|
||||
|
||||
private final String name;
|
||||
|
||||
private Predicate<String> predicate;
|
||||
private Function<String, T> function;
|
||||
|
||||
public ArgumentType(String name, Predicate<String> predicate, Function<String, T> function) {
|
||||
this.name = name;
|
||||
this.predicate = predicate;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean test(String string) {
|
||||
return predicate.test(string);
|
||||
}
|
||||
|
||||
public T get(String t) {
|
||||
return function.apply(t);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.util.StringUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArgumentTypes {
|
||||
|
||||
public static final ArgumentType<String> STRING = new ArgumentType<>("string", (s) -> true, (s) -> s);
|
||||
|
||||
public static final ArgumentType<Integer> INTEGER = new ArgumentType<>("integer", StringUtil::isInt, Integer::parseInt);
|
||||
|
||||
public static final ArgumentType<Double> DOUBLE = new ArgumentType<>("double", StringUtil::isDouble, Double::parseDouble);
|
||||
|
||||
public static final ArgumentType<UUID> UUID = new ArgumentType<>("uuid", StringUtil::isUUID, java.util.UUID::fromString);
|
||||
|
||||
public static final ArgumentType<Boolean> BOOLEAN = new ArgumentType<>("boolean", StringUtil::isBoolean, Boolean::parseBoolean);
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArgumentValue {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>();
|
||||
|
||||
static {
|
||||
PRIMITIVE_TO_WRAPPER.put(boolean.class, Boolean.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(byte.class, Byte.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(short.class, Short.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(char.class, Character.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(int.class, Integer.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(long.class, Long.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(float.class, Float.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(double.class, Double.class);
|
||||
}
|
||||
|
||||
private Object value;
|
||||
|
||||
public ArgumentValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public <V> V get(Class<V> clazz) {
|
||||
if (PRIMITIVE_TO_WRAPPER.getOrDefault(clazz, clazz).isAssignableFrom(value.getClass())) {
|
||||
return (V) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return (Integer) value;
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return (Double) value;
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return (UUID) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ArgumentValue{" +
|
||||
"value=" + value +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface ITabCompleter {
|
||||
|
||||
List<String> onTabComplete(CommandSender commandSender, String[] args, int index, String lastArg);
|
||||
|
||||
static List<String> getPlayerList(String arg) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
if (arg != null && !arg.trim().equalsIgnoreCase("")) {
|
||||
if (name.toLowerCase().startsWith(arg.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
} else {
|
||||
list.add(name);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Suggest {
|
||||
|
||||
List<String> getSuggest();
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.argument;
|
||||
|
||||
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
||||
import com.io.yutian.thewardungeon.manager.DungeonManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Suggests {
|
||||
|
||||
private static long updateTime = 0;
|
||||
private static List<String> allPlayers = new ArrayList<>();
|
||||
|
||||
public static final Suggest WORLD_LIST = ()->{
|
||||
List<String> list = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
list.add(world.getName());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
public static final Suggest PLAYER_LIST = ()->{
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
public static final Suggest DUNGEON_LIST = ()->{
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Dungeon dungeon : DungeonManager.getDungeons()) {
|
||||
list.add(dungeon.getId());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.io.yutian.thewarskyblocklib.command.list;
|
||||
|
||||
import com.io.yutian.thewardungeon.lang.Lang;
|
||||
import com.io.yutian.thewarskyblocklib.command.*;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.Argument;
|
||||
import com.io.yutian.thewarskyblocklib.command.argument.ArgumentTypes;
|
||||
import com.io.yutian.thewarskyblocklib.util.PageList;
|
||||
import com.io.yutian.thewarskyblocklib.util.TextComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CommandHelp extends ICommand {
|
||||
|
||||
private Command parent;
|
||||
private String helpTitle;
|
||||
|
||||
public CommandHelp(Command parent, String helpTitle) {
|
||||
super("help");
|
||||
this.parent = parent;
|
||||
this.helpTitle = helpTitle;
|
||||
addArgument(Argument.argument("page", ArgumentTypes.INTEGER).optional(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executes(CommandContext commandContext) {
|
||||
String label = commandContext.getCommandLabel();
|
||||
CommandSender sender = commandContext.getSender();
|
||||
int page = commandContext.getArgumentsValue("page").getInt();
|
||||
if (page <= 0) {
|
||||
sender.sendMessage(Lang.prefix+ Lang.get("command.help.page-error"));
|
||||
return;
|
||||
}
|
||||
List<ICommand> commands = parent.getCommands();
|
||||
Stream<ICommand> stream = commands.stream().filter((c) -> c.hasPermission(sender) && !c.hide());
|
||||
List<ICommand> list = stream.collect(Collectors.toList());
|
||||
PageList<ICommand> pageList = new PageList<>(list, 8);
|
||||
if (page > pageList.size()) {
|
||||
sender.sendMessage(Lang.prefix+ Lang.get("command.help.page-error"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(" ");
|
||||
List<ICommand> commandList = pageList.getList(page);
|
||||
sender.sendMessage("§7======[ §e§l"+helpTitle+" §7]======");
|
||||
for (ICommand command : commandList) {
|
||||
StringBuilder stringBuilder = new StringBuilder("§6/"+label+" "+command.getName());
|
||||
stringBuilder.append("§f");
|
||||
if (command.getCommandNodes().size() > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" [");
|
||||
int i = 0;
|
||||
for (CommandNode node : command.getCommandNodes()) {
|
||||
sb.append(node.getName());
|
||||
if (i + 1 < command.getCommandNodes().size()) {
|
||||
sb.append("/");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sb.append("]");
|
||||
stringBuilder.append(sb);
|
||||
} else {
|
||||
for (Argument argument : command.getArguments()) {
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append("<"+argument.getName()+">");
|
||||
}
|
||||
}
|
||||
if (command.getDescription() != null) {
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append("§7- §f"+command.getDescription());
|
||||
}
|
||||
sender.sendMessage(stringBuilder.toString());
|
||||
}
|
||||
TextComponentBuilder builder = new TextComponentBuilder();
|
||||
boolean hasUpPage = page > 1;
|
||||
boolean hasNextPage = page < pageList.size();
|
||||
builder.addText("§7=====");
|
||||
if (hasUpPage) {
|
||||
builder.addText(" §7["+getColor(true)+"◀§7] ", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+label+" help "+(page-1)), new HoverEvent(HoverEvent.Action.SHOW_TEXT, Arrays.asList(new Text("§f上一頁"))));
|
||||
} else {
|
||||
builder.addText(" §7["+getColor(false)+"◀§7] ");
|
||||
}
|
||||
builder.addText("§7====");
|
||||
builder.addText("(§a"+page+"§f/§e"+pageList.size()+"§7)");
|
||||
builder.addText("§7====");
|
||||
if (hasNextPage) {
|
||||
builder.addText(" §7["+getColor(true)+"▶§7] ", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+label+" help "+(page+1)), new HoverEvent(HoverEvent.Action.SHOW_TEXT, Arrays.asList(new Text("§f下一頁"))));
|
||||
} else {
|
||||
builder.addText(" §7["+getColor(false)+"▶§7] ");
|
||||
}
|
||||
builder.addText("§7=====");
|
||||
sender.spigot().sendMessage(builder.build());
|
||||
}
|
||||
|
||||
private String getColor(boolean hasPage) {
|
||||
return hasPage ? "§a" : "§c";
|
||||
}
|
||||
|
||||
}
|
318
src/main/java/com/io/yutian/thewarskyblocklib/config/Config.java
Normal file
318
src/main/java/com/io/yutian/thewarskyblocklib/config/Config.java
Normal file
|
@ -0,0 +1,318 @@
|
|||
package com.io.yutian.thewarskyblocklib.config;
|
||||
|
||||
import com.io.yutian.thewardungeon.util.Log;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.ConfigSerializable;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.SerializaUtil;
|
||||
import com.io.yutian.thewarskyblocklib.util.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Config {
|
||||
|
||||
private File file;
|
||||
private FileConfiguration fileConfiguration;
|
||||
private Class<?> configClass;
|
||||
|
||||
private Map<String, ConfigValue> registerMap = new HashMap<>();
|
||||
private Map<String, String> fieldMap = new HashMap<>();
|
||||
|
||||
public Config(File file, Class<?> configClass) {
|
||||
this.file = file;
|
||||
this.configClass = configClass;
|
||||
}
|
||||
|
||||
public void define(String fieldName, String path, ConfigValue configValue) {
|
||||
try {
|
||||
Field field = configClass.getDeclaredField(fieldName);
|
||||
if (field == null) {
|
||||
Logger.warning("TheWarSkyBlockLib","加载配置项时出现错误 原因: 目标成员变量不存在");
|
||||
return;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
field.set(null, configValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
fieldMap.put(path, fieldName);
|
||||
registerMap.put(path, configValue);
|
||||
}
|
||||
|
||||
public boolean load() {
|
||||
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
try {
|
||||
for (Map.Entry<String, ConfigValue> entry : registerMap.entrySet()) {
|
||||
ConfigValue configValue = registerMap.get(entry.getKey());
|
||||
Object obj = configValue.load(entry.getKey(), fileConfiguration);
|
||||
String fieldName = fieldMap.get(entry.getKey());
|
||||
Field field = configClass.getDeclaredField(fieldName);
|
||||
if (field == null) {
|
||||
Log.warning("加载配置项时出现错误 原因: 目标成员变量不存在");
|
||||
continue;
|
||||
}
|
||||
configValue.setValue(obj);
|
||||
|
||||
Class<?> configValueClass = ConfigValue.class;
|
||||
Field field1 = configValueClass.getDeclaredField("file");
|
||||
field1.setAccessible(true);
|
||||
field1.set(configValue, file);
|
||||
Field field2 = configValueClass.getDeclaredField("configuration");
|
||||
field2.setAccessible(true);
|
||||
field2.set(configValue, fileConfiguration);
|
||||
Field field3 = configValueClass.getDeclaredField("path");
|
||||
field3.setAccessible(true);
|
||||
field3.set(configValue, entry.getKey());
|
||||
Field field4 = configValueClass.getDeclaredField("field");
|
||||
field4.setAccessible(true);
|
||||
field4.set(configValue, field);
|
||||
field.setAccessible(true);
|
||||
field.set(null, configValue);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.warning("加载配置项时出现错误 原因: 未知");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringValue extends ConfigValue<String> {
|
||||
@Override
|
||||
public String load(String path, FileConfiguration config) {
|
||||
return ConfigReader.STRING.read(path, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefault() {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
public static class BooleanValue extends ConfigValue<Boolean> {
|
||||
@Override
|
||||
public Boolean load(String path, FileConfiguration config) {
|
||||
return ConfigReader.BOOLEAN.read(path, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefault() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntValue extends ConfigValue<Integer> {
|
||||
@Override
|
||||
public Integer load(String path, FileConfiguration config) {
|
||||
return ConfigReader.INTEGER.read(path, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDefault() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleValue extends ConfigValue<Double> {
|
||||
@Override
|
||||
public Double load(String path, FileConfiguration config) {
|
||||
return ConfigReader.DOUBLE.read(path, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getDefault() {
|
||||
return 0d;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FloatValue extends ConfigValue<Float> {
|
||||
@Override
|
||||
public Float load(String path, FileConfiguration config) {
|
||||
return ConfigReader.FLOAT.read(path, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getDefault() {
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LongValue extends ConfigValue<Long> {
|
||||
@Override
|
||||
public Long load(String path, FileConfiguration config) {
|
||||
return ConfigReader.LONG.read(path, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDefault() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class EnumValue<T extends Enum> extends ConfigValue<T> {
|
||||
|
||||
protected Class<T> enumType;
|
||||
|
||||
public EnumValue(Class<T> enumType) {
|
||||
this.enumType = enumType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T load(String path, FileConfiguration config) {
|
||||
String string = config.getString(path);
|
||||
return (T) Enum.valueOf(enumType, string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getDefault() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ListValue<V> extends ConfigValue<List<V>> {
|
||||
@Override
|
||||
public List<V> load(String path, FileConfiguration config) {
|
||||
return (List<V>) ConfigReader.LIST.read(path, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> getDefault() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringListValue extends ListValue<String> {
|
||||
@Override
|
||||
public List<String> load(String path, FileConfiguration config) {
|
||||
return ConfigReader.STRING_LIST.read(path, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefault() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public static class LocationValue extends ConfigValue<Location> {
|
||||
@Override
|
||||
public Location load(String path, FileConfiguration config) {
|
||||
return ConfigReader.LOCATION.read(path, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getDefault() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SerializaValue<J extends ConfigSerializable> extends ConfigValue<J> {
|
||||
|
||||
protected Class<J> typeClass;
|
||||
|
||||
public SerializaValue(Class<J> typeClass) {
|
||||
this.typeClass = typeClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public J load(String path, FileConfiguration config) {
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection(path);
|
||||
return SerializaUtil.deserialize(typeClass, configurationSection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String path, FileConfiguration configuration, J value) {
|
||||
Map<String, Object> map = value.serialize();
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
configuration.set(path+"."+entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public J getDefault() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectValue<K> extends ConfigValue<K> {
|
||||
|
||||
private ConfigObjectDeserializable<K> configObjectDeserializable;
|
||||
|
||||
public ObjectValue(ConfigObjectDeserializable<K> configObjectDeserializable) {
|
||||
this.configObjectDeserializable = configObjectDeserializable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K load(String path, FileConfiguration config) {
|
||||
return configObjectDeserializable.load(path, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String path, FileConfiguration configuration, K value) {
|
||||
this.configObjectDeserializable.save(path, configuration, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getDefault() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class ConfigValue<T> {
|
||||
|
||||
private T value;
|
||||
|
||||
protected File file;
|
||||
protected FileConfiguration configuration;
|
||||
protected String path;
|
||||
protected Field field;
|
||||
|
||||
public abstract T load(String path, FileConfiguration config);
|
||||
|
||||
public abstract T getDefault();
|
||||
|
||||
public void save(String path, FileConfiguration configuration, T value) {
|
||||
configuration.set(path, value);
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.save(path, configuration, value);
|
||||
try {
|
||||
configuration.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface ConfigObjectDeserializable<K> {
|
||||
|
||||
K load(String path, FileConfiguration config);
|
||||
void save(String path, FileConfiguration config, K value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.io.yutian.thewarskyblocklib.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ConfigReader<V> {
|
||||
|
||||
ConfigReader<String> STRING = (path, configuration) -> configuration.getString(path);
|
||||
ConfigReader<Boolean> BOOLEAN = (path, configuration) -> configuration.getBoolean(path);
|
||||
ConfigReader<Integer> INTEGER = (path, configuration) -> configuration.getInt(path);
|
||||
ConfigReader<Double> DOUBLE = (path, configuration) -> configuration.getDouble(path);
|
||||
ConfigReader<Float> FLOAT = (path, configuration) -> (float) configuration.getDouble(path);
|
||||
ConfigReader<Long> LONG = (path, configuration) -> configuration.getLong(path);
|
||||
ConfigReader<List<?>> LIST = (path, configuration) -> configuration.getList(path);
|
||||
ConfigReader<List<String>> STRING_LIST = (path, configuration) -> configuration.getStringList(path);
|
||||
ConfigReader<Location> LOCATION = (path, configuration) -> {
|
||||
World world = Bukkit.getWorld(configuration.getString(path+".world"));
|
||||
double x = configuration.getDouble(path+".x");
|
||||
double y = configuration.getDouble(path+".x");
|
||||
double z = configuration.getDouble(path+".x");
|
||||
float yaw = (float) configuration.getDouble(path+".yaw");
|
||||
float pitch = (float) configuration.getDouble(path+".pitch");
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
};
|
||||
|
||||
V read(String path, FileConfiguration configuration);
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.io.yutian.thewarskyblocklib.config;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileConfig {
|
||||
|
||||
private File file;
|
||||
private ConfigurationSection section;
|
||||
|
||||
protected Map<String, Object> valueMap = new HashMap<>();
|
||||
|
||||
public FileConfig(File file, ConfigurationSection section) {
|
||||
this.file = file;
|
||||
this.section = section;
|
||||
load();
|
||||
}
|
||||
|
||||
public Object getValue(String key) {
|
||||
return valueMap.get(key);
|
||||
}
|
||||
|
||||
public Object getValue(String[] keys) {
|
||||
for (String key : keys) {
|
||||
if (hasKey(key)) {
|
||||
return getValue(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> T getValue(String[] keys, Class<T> type) {
|
||||
for (String key : keys) {
|
||||
if (hasKey(key, type)) {
|
||||
return (T) getValue(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasKey(String key) {
|
||||
return valueMap.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean hasKey(String[] keys) {
|
||||
for (String key : keys) {
|
||||
if (hasKey(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasKey(String key, Class type) {
|
||||
if (!valueMap.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
Object value = getValue(key);
|
||||
return type.isInstance(value);
|
||||
}
|
||||
|
||||
public boolean hasKey(String[] keys, Class type) {
|
||||
for (String key : keys) {
|
||||
if (hasKey(key, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void load() {
|
||||
valueMap.clear();
|
||||
for (String key : section.getKeys(false)) {
|
||||
Object value = section.get(key);
|
||||
valueMap.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public ConfigurationSection getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
}
|
132
src/main/java/com/io/yutian/thewarskyblocklib/gui/Gui.java
Normal file
132
src/main/java/com/io/yutian/thewarskyblocklib/gui/Gui.java
Normal file
|
@ -0,0 +1,132 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.Button;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ClickType;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ItemButton;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Gui extends IGui {
|
||||
|
||||
private Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
public Gui(Player player, String title, int size) {
|
||||
super(player, title, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(Player player, int slot, InventoryClickEvent event) {
|
||||
if (buttons.containsKey(slot)) {
|
||||
Button button = buttons.get(slot);
|
||||
if (button == null) {
|
||||
if (slot < inventory.getSize()) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
clickButton(event, slot, button);
|
||||
if (button.isPlaySound()) {
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
|
||||
}
|
||||
InventoryAction action = event.getAction();
|
||||
ClickType clickType = ClickType.LEFT_CLICK;
|
||||
if (action.equals(InventoryAction.PICKUP_ALL)) {
|
||||
clickType = ClickType.LEFT_CLICK;
|
||||
} else if (action.equals(InventoryAction.PICKUP_HALF)) {
|
||||
clickType = ClickType.RIGHT_CLICK;
|
||||
} else if (action.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||
clickType = ClickType.SHIFT_CLICK;
|
||||
}
|
||||
if (button.getClickConsumer() != null) {
|
||||
button.getClickConsumer().accept(player, clickType);
|
||||
}
|
||||
} else {
|
||||
if (slot < inventory.getSize()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addButton(int index, Button button) {
|
||||
buttons.put(index, button);
|
||||
}
|
||||
|
||||
public Button getButton(int index) {
|
||||
return buttons.getOrDefault(index, null);
|
||||
}
|
||||
|
||||
public void initButton(int index) {
|
||||
inventory.setItem(index, null);
|
||||
Button button = getButton(index);
|
||||
if (button == null) {
|
||||
return;
|
||||
}
|
||||
if (button.isAsynchronous()) {
|
||||
TheWarDungeon.inst().getServer().getScheduler().runTaskAsynchronously(TheWarDungeon.inst(), ()->{
|
||||
if (button instanceof ItemButton itemButton) {
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(index, itemButton.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.setItem(index, button.getItemStack());
|
||||
});
|
||||
} else {
|
||||
if (button instanceof ItemButton itemButton) {
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(index, itemButton.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.setItem(index, button.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
public void initButton() {
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, null);
|
||||
}
|
||||
for (Map.Entry<Integer, Button> entry : buttons.entrySet()) {
|
||||
Button button = entry.getValue();
|
||||
if (button.isAsynchronous()) {
|
||||
TheWarDungeon.inst().getServer().getScheduler().runTaskAsynchronously(TheWarDungeon.inst(), ()->{
|
||||
if (button instanceof ItemButton itemButton) {
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(entry.getKey(), itemButton.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.setItem(entry.getKey(), button.getItemStack());
|
||||
});
|
||||
} else {
|
||||
if (button instanceof ItemButton itemButton) {
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(entry.getKey(), itemButton.getItem());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
inventory.setItem(entry.getKey(), button.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Button> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class GuiListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getInventory().getHolder() == null) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (!(holder instanceof IGui iGui)) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedInventory() != event.getInventory()) {
|
||||
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || event.getAction().equals(InventoryAction.COLLECT_TO_CURSOR)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (event.getAction().equals(InventoryAction.HOTBAR_SWAP) || event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
|
||||
event.setCancelled(true);
|
||||
player.getInventory().setItemInOffHand(player.getInventory().getItemInOffHand());
|
||||
return;
|
||||
}
|
||||
int slot = event.getRawSlot();
|
||||
iGui.handler(player, slot, event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
if (event.getInventory().getHolder() != null) {
|
||||
if (event.getInventory().getHolder() instanceof IGui) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (event.getInventory().getHolder() != null) {
|
||||
if (event.getInventory().getHolder() instanceof IGui) {
|
||||
IGui iGui = (IGui) event.getInventory().getHolder();
|
||||
iGui.close(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
136
src/main/java/com/io/yutian/thewarskyblocklib/gui/IGui.java
Normal file
136
src/main/java/com/io/yutian/thewarskyblocklib/gui/IGui.java
Normal file
|
@ -0,0 +1,136 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.Button;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ItemButton;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ItemSlotButton;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class IGui implements InventoryHolder {
|
||||
|
||||
public Inventory inventory;
|
||||
public Player player;
|
||||
|
||||
private String title;
|
||||
private int size;
|
||||
|
||||
public IGui(Player player, String title, int size) {
|
||||
this.inventory = Bukkit.createInventory(this, size, title);
|
||||
this.title = title;
|
||||
this.size = size;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract void handler(Player player, int slot, InventoryClickEvent event);
|
||||
|
||||
public void close(InventoryCloseEvent event) {
|
||||
}
|
||||
|
||||
public void open() {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void clickButton(InventoryClickEvent event, int slot, Button button) {
|
||||
if (button instanceof ItemButton itemButton) {
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
ItemStack item = event.getCursor();
|
||||
if (itemButton.isItem(itemStack)) {
|
||||
if (item != null & !item.getType().equals(Material.AIR)) {
|
||||
if (itemButton.getPutPredicate() != null && !itemButton.getPutPredicate().test(player, item)) {
|
||||
return;
|
||||
}
|
||||
if (itemButton.getClickItemConsumer() != null) {
|
||||
itemButton.getClickItemConsumer().accept(player, item);
|
||||
}
|
||||
player.setItemOnCursor(null);
|
||||
if (itemButton.getPutItemFunction() != null) {
|
||||
ItemStack itemStack1 = itemButton.getPutItemFunction().apply(item);
|
||||
itemButton.setItem(itemStack1);
|
||||
inventory.setItem(slot, itemStack1);
|
||||
} else {
|
||||
itemButton.setItem(item);
|
||||
inventory.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (item == null || item.getType().equals(Material.AIR)) {
|
||||
if (itemButton.getClickItemConsumer() != null) {
|
||||
itemButton.getClickItemConsumer().accept(player, item);
|
||||
}
|
||||
player.setItemOnCursor(itemStack);
|
||||
itemButton.setItem(null);
|
||||
inventory.setItem(slot, button.getItemStack());
|
||||
} else {
|
||||
if (itemButton.getPutPredicate() != null && !itemButton.getPutPredicate().test(player, item)) {
|
||||
return;
|
||||
}
|
||||
player.setItemOnCursor(itemStack);
|
||||
if (itemButton.getPutItemFunction() != null) {
|
||||
ItemStack itemStack1 = itemButton.getPutItemFunction().apply(item);
|
||||
if (itemButton.getClickItemConsumer() != null) {
|
||||
itemButton.getClickItemConsumer().accept(player, itemStack1);
|
||||
}
|
||||
itemButton.setItem(itemStack1);
|
||||
inventory.setItem(slot, itemStack1);
|
||||
} else {
|
||||
if (itemButton.getClickItemConsumer() != null) {
|
||||
itemButton.getClickItemConsumer().accept(player, item);
|
||||
}
|
||||
itemButton.setItem(item);
|
||||
inventory.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (button instanceof ItemSlotButton itemSlotButton) {
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
ItemStack item = event.getCursor();
|
||||
if (item == null || item.getType().equals(Material.AIR)) {
|
||||
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
|
||||
return;
|
||||
}
|
||||
inventory.setItem(slot, null);
|
||||
player.setItemOnCursor(itemStack);
|
||||
if (itemSlotButton.getPickItemFunction() != null) {
|
||||
itemSlotButton.getPickItemFunction().accept(itemStack);
|
||||
}
|
||||
} else {
|
||||
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
|
||||
if (!itemSlotButton.isCanPut()) {
|
||||
return;
|
||||
}
|
||||
player.setItemOnCursor(null);
|
||||
if (itemSlotButton.getPutItemFunction() != null) {
|
||||
itemSlotButton.getPutItemFunction().accept(item);
|
||||
}
|
||||
inventory.setItem(slot, item);
|
||||
return;
|
||||
} else {
|
||||
if (!itemSlotButton.isCanPut()) {
|
||||
return;
|
||||
}
|
||||
player.setItemOnCursor(itemStack);
|
||||
inventory.setItem(slot, item);
|
||||
if (itemSlotButton.getPutItemFunction() != null) {
|
||||
itemSlotButton.getPutItemFunction().accept(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
175
src/main/java/com/io/yutian/thewarskyblocklib/gui/PageGui.java
Normal file
175
src/main/java/com/io/yutian/thewarskyblocklib/gui/PageGui.java
Normal file
|
@ -0,0 +1,175 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui;
|
||||
|
||||
import com.io.yutian.thewardungeon.TheWarDungeon;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.Button;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ClickType;
|
||||
import com.io.yutian.thewarskyblocklib.gui.button.ItemButton;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PageGui extends IGui {
|
||||
|
||||
private int page = 1;
|
||||
private int maxPage = 1;
|
||||
|
||||
private Map<Integer, Page> pages = new HashMap<>();
|
||||
|
||||
public PageGui(Player player, String title, int size, int maxPage) {
|
||||
super(player, title, size);
|
||||
this.maxPage = maxPage;
|
||||
}
|
||||
|
||||
public void initButton() {
|
||||
initButton(this.page);
|
||||
}
|
||||
|
||||
public void initButton(int page) {
|
||||
if (page > pages.size()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, null);
|
||||
}
|
||||
if (pages.containsKey(page)) {
|
||||
Page page1 = pages.get(page);
|
||||
for (Map.Entry<Integer, Button> entry : page1.buttons.entrySet()) {
|
||||
Button button = entry.getValue();
|
||||
if (button.isAsynchronous()) {
|
||||
TheWarDungeon.inst().getServer().getScheduler().runTaskAsynchronously(TheWarDungeon.inst(), ()->{
|
||||
if (button instanceof ItemButton) {
|
||||
ItemButton itemButton = (ItemButton) button;
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(entry.getKey(), itemButton.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.setItem(entry.getKey(), button.getItemStack());
|
||||
});
|
||||
} else {
|
||||
if (button instanceof ItemButton) {
|
||||
ItemButton itemButton = (ItemButton) button;
|
||||
if (itemButton.getItem() != null) {
|
||||
inventory.setItem(entry.getKey(), itemButton.getItem());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
inventory.setItem(entry.getKey(), button.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(Player player, int slot, InventoryClickEvent event) {
|
||||
if (pages.containsKey(page)) {
|
||||
Page page1 = getPage(page);
|
||||
Button button = page1.getButton(slot);
|
||||
if (button == null) {
|
||||
if (slot < inventory.getSize()) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
clickButton(event, slot, button);
|
||||
if (button.isPlaySound()) {
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
|
||||
}
|
||||
InventoryAction action = event.getAction();
|
||||
ClickType clickType = ClickType.LEFT_CLICK;
|
||||
if (action.equals(InventoryAction.PICKUP_ALL)) {
|
||||
clickType = ClickType.LEFT_CLICK;
|
||||
} else if (action.equals(InventoryAction.PICKUP_HALF)) {
|
||||
clickType = ClickType.RIGHT_CLICK;
|
||||
} else if (action.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||
clickType = ClickType.SHIFT_CLICK;
|
||||
}
|
||||
if (button.getClickConsumer() != null) {
|
||||
button.getClickConsumer().accept(player, clickType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Page getPage(int page) {
|
||||
if (page <= 0 || page > maxPage) {
|
||||
return null;
|
||||
}
|
||||
if (!pages.containsKey(page)) {
|
||||
pages.put(page, new Page());
|
||||
}
|
||||
return pages.get(page);
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public void next() {
|
||||
if (page >= maxPage) {
|
||||
return;
|
||||
}
|
||||
this.page ++;
|
||||
initButton();
|
||||
}
|
||||
|
||||
public void up() {
|
||||
if (page <= 1) {
|
||||
return;
|
||||
}
|
||||
this.page --;
|
||||
initButton();
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public int getMaxPage() {
|
||||
return maxPage;
|
||||
}
|
||||
|
||||
public void setMaxPage(int maxPage) {
|
||||
this.maxPage = maxPage;
|
||||
}
|
||||
|
||||
public void addButton(int page, int index, Button button) {
|
||||
Page page1 = pages.getOrDefault(page, new Page());
|
||||
page1.buttons.put(index, button);
|
||||
pages.put(page, page1);
|
||||
}
|
||||
|
||||
public static class Page {
|
||||
|
||||
private Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
public Page() {
|
||||
}
|
||||
|
||||
public void addButton(int index, Button button) {
|
||||
buttons.put(index, button);
|
||||
}
|
||||
|
||||
public Button getButton(int index) {
|
||||
return buttons.getOrDefault(index, null);
|
||||
}
|
||||
|
||||
public Map<Integer, Button> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui.button;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class Button {
|
||||
|
||||
private ItemStack itemStack;
|
||||
|
||||
private BiConsumer<Player, ClickType> clickConsumer;
|
||||
|
||||
private boolean asynchronous = false;
|
||||
private boolean playSound = true;
|
||||
|
||||
public Button(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
public Button click(BiConsumer<Player, ClickType> consumer) {
|
||||
this.clickConsumer = consumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Button asyn() {
|
||||
this.asynchronous = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Button noSound() {
|
||||
this.playSound = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public BiConsumer<Player, ClickType> getClickConsumer() {
|
||||
return clickConsumer;
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
return asynchronous;
|
||||
}
|
||||
|
||||
public boolean isPlaySound() {
|
||||
return playSound;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui.button;
|
||||
|
||||
public enum ClickType {
|
||||
|
||||
LEFT_CLICK,
|
||||
RIGHT_CLICK,
|
||||
SHIFT_CLICK
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui.button;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.nms.item.NMSItemStack;
|
||||
import com.io.yutian.thewarskyblocklib.nms.nbt.NBTCompound;
|
||||
import com.io.yutian.thewarskyblocklib.nms.nbt.NBTString;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemButton extends Button {
|
||||
|
||||
private BiConsumer<Player, ItemStack> clickItemConsumer;
|
||||
|
||||
private Function<ItemStack, ItemStack> putItemFunction;
|
||||
private BiPredicate<Player, ItemStack> putPredicate;
|
||||
|
||||
private ItemStack item;
|
||||
|
||||
public ItemButton(ItemStack itemStack) {
|
||||
super(itemStack);
|
||||
NMSItemStack nmsItemStack = NMSItemStack.build(itemStack);
|
||||
NBTCompound nbtCompound = nmsItemStack.getTag();
|
||||
nbtCompound.putString("thewarskyblock_meta", "item_button");
|
||||
nmsItemStack.setTag(nbtCompound);
|
||||
setItemStack(nmsItemStack.getBukkitItemStack());
|
||||
}
|
||||
|
||||
public ItemButton setItem(ItemStack item) {
|
||||
this.item = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemButton itemPredicate(BiPredicate<Player, ItemStack> predicate) {
|
||||
this.putPredicate = predicate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemButton putItem(Function<ItemStack, ItemStack> putItemFunction) {
|
||||
this.putItemFunction = putItemFunction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isItem() {
|
||||
NBTCompound nbtCompound = NMSItemStack.build(item).getTag();
|
||||
return nbtCompound.hasKey("thewarskyblock_meta", NBTString.TYPE_ID) && nbtCompound.getString("thewarskyblock_meta").equalsIgnoreCase("item_button");
|
||||
}
|
||||
|
||||
public boolean isItem(ItemStack item) {
|
||||
NBTCompound nbtCompound = NMSItemStack.build(item).getTag();
|
||||
return nbtCompound.hasKey("thewarskyblock_meta", NBTString.TYPE_ID) && nbtCompound.getString("thewarskyblock_meta").equalsIgnoreCase("item_button");
|
||||
}
|
||||
|
||||
public ItemButton clickItem(BiConsumer<Player, ItemStack> consumer) {
|
||||
this.clickItemConsumer = consumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BiConsumer<Player, ItemStack> getClickItemConsumer() {
|
||||
return clickItemConsumer;
|
||||
}
|
||||
|
||||
public Function<ItemStack, ItemStack> getPutItemFunction() {
|
||||
return putItemFunction;
|
||||
}
|
||||
|
||||
public BiPredicate<Player, ItemStack> getPutPredicate() {
|
||||
return putPredicate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.io.yutian.thewarskyblocklib.gui.button;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ItemSlotButton extends Button {
|
||||
|
||||
private Consumer<ItemStack> putItemFunction;
|
||||
private Consumer<ItemStack> pickItemFunction;
|
||||
|
||||
private boolean canPut = true;
|
||||
|
||||
public ItemSlotButton() {
|
||||
super(new ItemStack(Material.AIR));
|
||||
}
|
||||
|
||||
public ItemSlotButton putItem(Consumer<ItemStack> putItemConsumer) {
|
||||
this.putItemFunction = putItemConsumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSlotButton pickItem(Consumer<ItemStack> pickItemConsumer) {
|
||||
this.pickItemFunction = pickItemConsumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSlotButton canPut(boolean can) {
|
||||
this.canPut = can;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isCanPut() {
|
||||
return canPut;
|
||||
}
|
||||
|
||||
public Consumer<ItemStack> getPickItemFunction() {
|
||||
return pickItemFunction;
|
||||
}
|
||||
|
||||
public Consumer<ItemStack> getPutItemFunction() {
|
||||
return putItemFunction;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.io.yutian.thewarskyblocklib.manager;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.command.Command;
|
||||
import com.io.yutian.thewarskyblocklib.command.SimpleCommandHandler;
|
||||
import com.io.yutian.thewarskyblocklib.util.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private static final List<Command> commands = new ArrayList<>();
|
||||
|
||||
protected static Map<String, org.bukkit.command.Command> bukkitCommandMap = new HashMap<>();
|
||||
protected static CommandMap commandMap;
|
||||
|
||||
private static Command command;
|
||||
|
||||
public static void register(Command command) {
|
||||
if (command.isFrozen() || commands.contains(command)) {
|
||||
return;
|
||||
}
|
||||
command.frozen();
|
||||
commands.add(command);
|
||||
if (command.getAliases().size() > 0) {
|
||||
for (String name : command.getAliases()) {
|
||||
registerBukkitCommand(command.getPlugin(), name, command);
|
||||
}
|
||||
}
|
||||
registerBukkitCommand(command.getPlugin(), command.getCommand(), command);
|
||||
}
|
||||
|
||||
public static void unregisterAll() {
|
||||
for (Command command : commands) {
|
||||
unregister(command);
|
||||
}
|
||||
commands.clear();
|
||||
}
|
||||
|
||||
public static void unregister(Command command) {
|
||||
try {
|
||||
Map<String, Command> map = (Map<String, Command>) commandMap.getClass().getMethod("getKnownCommands").invoke(commandMap);
|
||||
if (command.getAliases().size() > 0) {
|
||||
for (String arg : command.getAliases()) {
|
||||
map.remove(arg);
|
||||
org.bukkit.command.Command bukkitCommand = bukkitCommandMap.get(arg);
|
||||
bukkitCommand.unregister(commandMap);
|
||||
}
|
||||
}
|
||||
commandMap.getCommand(command.getCommand()).unregister(commandMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void registerBukkitCommand(Plugin plugin, String name, Command command) {
|
||||
SimpleCommandHandler simpleCommandHandler = new SimpleCommandHandler(name, command);
|
||||
bukkitCommandMap.put(name, simpleCommandHandler);
|
||||
commandMap.register(plugin.getName(), simpleCommandHandler);
|
||||
}
|
||||
|
||||
public static List<Command> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> c = Bukkit.getServer().getClass();
|
||||
for (Method method : c.getDeclaredMethods()) {
|
||||
if (method.getName().equals("getCommandMap")) {
|
||||
commandMap = (CommandMap) method.invoke(Bukkit.getServer(), new Object[0]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.error("TheWarSkyBlockLib", "未能正常初始化命令");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.io.yutian.thewarskyblocklib.math;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DirectionPoint extends Point {
|
||||
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
public DirectionPoint(int x, int y, int z, float yaw, float pitch) {
|
||||
super(x, y, z);
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public DirectionPoint(double x, double y, double z) {
|
||||
this(x, y, z, 0f, 0f);
|
||||
}
|
||||
|
||||
public DirectionPoint(double x, double y, double z, float yaw, float pitch) {
|
||||
super(x, y, z);
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location toLocation(World world) {
|
||||
return new Location(world, getX(), getY(), getZ(), yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject = super.toJson();
|
||||
jsonObject.put("yaw", yaw);
|
||||
jsonObject.put("pitch", pitch);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public static DirectionPoint of(Location location) {
|
||||
return new DirectionPoint(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
public static DirectionPoint of(JSONObject jsonObject) {
|
||||
return new DirectionPoint(jsonObject.getDouble("x"), jsonObject.getDouble("y"), jsonObject.getDouble("z"), jsonObject.getFloat("yaw"), jsonObject.getFloat("pitch"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DirectionPoint{" +
|
||||
"x=" + getX() +
|
||||
", y=" + getY() +
|
||||
", z=" + getZ() +
|
||||
", yaw=" + yaw +
|
||||
", pitch=" + pitch +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
DirectionPoint that = (DirectionPoint) o;
|
||||
return super.equals(o) && Float.compare(that.yaw, yaw) == 0 && Float.compare(that.pitch, pitch) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = super.serialize();
|
||||
map.put("yaw", yaw);
|
||||
map.put("pitch", pitch);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static DirectionPoint deserialize(ConfigurationSection section) {
|
||||
return new DirectionPoint(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"), (float) section.getDouble("yaw"), (float) section.getDouble("pitch"));
|
||||
}
|
||||
|
||||
}
|
115
src/main/java/com/io/yutian/thewarskyblocklib/math/Point.java
Normal file
115
src/main/java/com/io/yutian/thewarskyblocklib/math/Point.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
package com.io.yutian.thewarskyblocklib.math;
|
||||
|
||||
import com.io.yutian.thewarskyblocklib.serializa.ConfigSerializable;
|
||||
import com.io.yutian.thewarskyblocklib.serializa.Serializable;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Point implements Serializable<Point>, ConfigSerializable {
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public Point(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Point(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Point clone() {
|
||||
return new Point(x, y, z);
|
||||
}
|
||||
|
||||
public Location toLocation(World world) {
|
||||
return new Location(world, x, y, z, 0, 0);
|
||||
}
|
||||
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("x", x);
|
||||
jsonObject.put("y", y);
|
||||
jsonObject.put("z", z);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public static Point of(Location location) {
|
||||
return new Point(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static Point of(JSONObject jsonObject) {
|
||||
return new Point(jsonObject.getDouble("x"), jsonObject.getDouble("y"), jsonObject.getDouble("z"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("x", x);
|
||||
map.put("y", y);
|
||||
map.put("z", z);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Point deserialize(ConfigurationSection section) {
|
||||
return new Point(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Point point = (Point) o;
|
||||
return Double.compare(point.x, x) == 0 && Double.compare(point.y, y) == 0 && Double.compare(point.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.io.yutian.thewarskyblocklib.nms;
|
||||
|
||||
public interface NMS {
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user