基本完成版版
This commit is contained in:
commit
d2dff8b7b4
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
.idea/SrDisassemble113.iml
generated
Normal file
9
.idea/SrDisassemble113.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
14
.idea/compiler.xml
generated
Normal file
14
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="SrDisassemble" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
17
.idea/dataSources.xml
generated
Normal file
17
.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@localhost" uuid="b791558a-98e8-4d1c-99ea-dec1bcf43726">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
10
.idea/libraries/lib.xml
generated
Normal file
10
.idea/libraries/lib.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
10
.idea/libraries/lib__2_.xml
generated
Normal file
10
.idea/libraries/lib__2_.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib (2)">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
10
.idea/libraries/lib__3_.xml
generated
Normal file
10
.idea/libraries/lib__3_.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib (3)">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
10
.idea/libraries/lib__4_.xml
generated
Normal file
10
.idea/libraries/lib__4_.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib (4)">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/SrDisassemble.iml" filepath="$PROJECT_DIR$/SrDisassemble.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../../giebach" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
13
SrDisassemble.iml
Normal file
13
SrDisassemble.iml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
72
dependency-reduced-pom.xml
Normal file
72
dependency-reduced-pom.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.yuyu</groupId>
|
||||
<artifactId>SrDisassemble</artifactId>
|
||||
<name>SrDisassemble</name>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
BIN
lib/GermPlugin-Snapshot-4.3.9-8.jar
Normal file
BIN
lib/GermPlugin-Snapshot-4.3.9-8.jar
Normal file
Binary file not shown.
BIN
lib/SrItem-1.1.4-2.jar
Normal file
BIN
lib/SrItem-1.1.4-2.jar
Normal file
Binary file not shown.
93
pom.xml
Normal file
93
pom.xml
Normal file
@ -0,0 +1,93 @@
|
||||
<?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>com.yuyu</groupId>
|
||||
<artifactId>SrDisassemble</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SrDisassemble</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>${java.version}</source>
|
||||
<target>${java.version}</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>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
38
src/main/java/com/yuyu/srdisassemble/SrDisassemble.java
Normal file
38
src/main/java/com/yuyu/srdisassemble/SrDisassemble.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.yuyu.srdisassemble;
|
||||
|
||||
import com.sakurarealm.sritem.bukkit.command.CommandBase;
|
||||
import com.sakurarealm.sritem.bukkit.command.OpenCommand;
|
||||
import com.yuyu.srdisassemble.command.DisCommand;
|
||||
import com.yuyu.srdisassemble.config.ConfigManager;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class SrDisassemble extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static SrDisassemble instance;//用于获取实例
|
||||
@Getter
|
||||
private static ConfigManager configManager;//用于鉴定
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
getLogger().info(ChatColor.GOLD+"分解插件开始运行!");
|
||||
this.configManager = new ConfigManager(this);
|
||||
|
||||
//注册指令
|
||||
CommandBase commandBase = new CommandBase();
|
||||
this.getCommand("srdisassemble").setExecutor(commandBase);
|
||||
commandBase.registerSubCommand("open",new DisCommand());
|
||||
commandBase.registerSubCommand("reload",new DisCommand());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
46
src/main/java/com/yuyu/srdisassemble/command/DisCommand.java
Normal file
46
src/main/java/com/yuyu/srdisassemble/command/DisCommand.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.yuyu.srdisassemble.command;
|
||||
|
||||
import com.sakurarealm.sritem.bukkit.command.SubCommand;
|
||||
import com.yuyu.srdisassemble.SrDisassemble;
|
||||
import com.yuyu.srdisassemble.disassemeble.DisassembleManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/11 16:11:24
|
||||
* @description
|
||||
*/
|
||||
public class DisCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSender commandSender, String[] strings) {
|
||||
if (strings.length == 1) {
|
||||
if (strings[0].equalsIgnoreCase("reload")){
|
||||
commandSender.sendMessage(ChatColor.RED+"分解配置文件重载!");
|
||||
//重载文件
|
||||
SrDisassemble.getConfigManager().reload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (strings.length < 2){
|
||||
commandSender.sendMessage(ChatColor.RED+"正确的格式为:/disassemble open 姓名 ");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(strings[1]);
|
||||
if (player == null){
|
||||
commandSender.sendMessage(ChatColor.RED+"玩家"+strings[1]+"不存在!");
|
||||
return;
|
||||
}
|
||||
|
||||
//为玩家打开GUI列表
|
||||
DisassembleManager.getInstance().open(player);
|
||||
|
||||
}
|
||||
}
|
156
src/main/java/com/yuyu/srdisassemble/config/ConfigManager.java
Normal file
156
src/main/java/com/yuyu/srdisassemble/config/ConfigManager.java
Normal file
@ -0,0 +1,156 @@
|
||||
package com.yuyu.srdisassemble.config;
|
||||
|
||||
import com.yuyu.srdisassemble.data.JdbcSqlClass;
|
||||
import com.yuyu.srdisassemble.pojo.CanDisItem;
|
||||
import com.yuyu.srdisassemble.pojo.DisProduct;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/11 16:11:01
|
||||
* @description 配置文件相关
|
||||
*/
|
||||
public class ConfigManager {
|
||||
private Logger logger;
|
||||
private HashMap<String, CanDisItem> disProductHashMap;
|
||||
private Plugin plugin;
|
||||
private String username;
|
||||
private String password;
|
||||
private String driver;
|
||||
private String url;
|
||||
public ConfigManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.logger = plugin.getLogger();
|
||||
this.loadDataBase();
|
||||
|
||||
plugin.saveResource("disProduct.yml",false);
|
||||
plugin.saveResource("disToItem.yml",false);
|
||||
plugin.saveResource("ItemDetail.yml",false);
|
||||
|
||||
File disProduct = new File(plugin.getDataFolder(), "disProduct.yml");
|
||||
File disToItem = new File(plugin.getDataFolder(), "disToItem.yml");
|
||||
File ItemDetail = new File(plugin.getDataFolder(), "ItemDetail.yml");
|
||||
|
||||
FileConfiguration disProductConfig = YamlConfiguration.loadConfiguration(disProduct);
|
||||
FileConfiguration disToItemProduct = YamlConfiguration.loadConfiguration(disToItem);
|
||||
FileConfiguration itemDetailProduct = YamlConfiguration.loadConfiguration(ItemDetail);
|
||||
this.disProductHashMap = new HashMap<>();
|
||||
|
||||
//先读取可分解的产物
|
||||
List<String> disProductConfigStringList = disProductConfig.getStringList("SrDisassemble");
|
||||
for (String disProductConfigString : disProductConfigStringList) {
|
||||
HashMap<String,DisProduct> disProductHashMap = new HashMap<>();
|
||||
//循环读取每个需要分解的产物
|
||||
int anInt = disToItemProduct.getInt("SrDisassemble." + disProductConfigString + ".disTime");
|
||||
String tagetIndex = disToItemProduct.getString("SrDisassemble." + disProductConfigString + ".index");
|
||||
CanDisItem canDisItem = new CanDisItem(disProductConfigString, anInt,disProductConfigString,tagetIndex);
|
||||
List<String> stringList = disToItemProduct.getStringList("SrDisassemble." + disProductConfigString +".disProduct");
|
||||
for (String product : stringList) {
|
||||
Double proMax = itemDetailProduct.getDouble("SrDisassemble."+disProductConfigString+"."+product+".probabilityMax");
|
||||
Double proMin = itemDetailProduct.getDouble("SrDisassemble."+disProductConfigString+"."+product+".probabilityMin");
|
||||
String index = itemDetailProduct.getString("SrDisassemble."+disProductConfigString+"."+product+".index");
|
||||
DisProduct disPojo = new DisProduct(product, index, proMax, proMin);
|
||||
logger.info(ChatColor.GREEN+disPojo.toString());
|
||||
disProductHashMap.put(product,disPojo);
|
||||
}
|
||||
canDisItem.setDisProductHashMap(disProductHashMap);
|
||||
|
||||
this.disProductHashMap.put(disProductConfigString,canDisItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void loadDataBase(){
|
||||
plugin.saveResource("datasource.yml",false);
|
||||
|
||||
File datasource = new File(plugin.getDataFolder(), "datasource.yml");
|
||||
|
||||
FileConfiguration datasourceConfig = YamlConfiguration.loadConfiguration(datasource);
|
||||
|
||||
JdbcSqlClass.setUser(datasourceConfig.getString("database.sql.username"));
|
||||
JdbcSqlClass.setPassword(datasourceConfig.getString("database.sql.password"));
|
||||
JdbcSqlClass.setDriver(datasourceConfig.getString("database.sql.driver"));
|
||||
JdbcSqlClass.setUrl(datasourceConfig.getString("database.sql.url"));
|
||||
|
||||
logger.info(ChatColor.GREEN+"username:"+JdbcSqlClass.getUser()+"\npassword:"+JdbcSqlClass.getPassword()
|
||||
+"\ndriver:"+JdbcSqlClass.getDriver()+"\nurl:"+JdbcSqlClass.getUrl());
|
||||
|
||||
JdbcSqlClass.initTable();
|
||||
JdbcSqlClass.setChartseUtf8();
|
||||
|
||||
//获取到datasource.yml的信息后建立数据库连接
|
||||
// SqlData.initTable();
|
||||
}
|
||||
|
||||
|
||||
public void reload() {
|
||||
//重载前先清零
|
||||
disProductHashMap.clear();
|
||||
loadDataBase();
|
||||
|
||||
plugin.saveResource("disProduct.yml",false);
|
||||
plugin.saveResource("disToItem.yml",false);
|
||||
plugin.saveResource("ItemDetail.yml",false);
|
||||
|
||||
File disProduct = new File(plugin.getDataFolder(), "disProduct.yml");
|
||||
File disToItem = new File(plugin.getDataFolder(), "disToItem.yml");
|
||||
File ItemDetail = new File(plugin.getDataFolder(), "ItemDetail.yml");
|
||||
|
||||
FileConfiguration disProductConfig = YamlConfiguration.loadConfiguration(disProduct);
|
||||
FileConfiguration disToItemProduct = YamlConfiguration.loadConfiguration(disToItem);
|
||||
FileConfiguration itemDetailProduct = YamlConfiguration.loadConfiguration(ItemDetail);
|
||||
this.disProductHashMap = new HashMap<>();
|
||||
|
||||
//先读取可分解的产物
|
||||
List<String> disProductConfigStringList = disProductConfig.getStringList("SrDisassemble");
|
||||
for (String disProductConfigString : disProductConfigStringList) {
|
||||
HashMap<String,DisProduct> disProductHashMap = new HashMap<>();
|
||||
//循环读取每个需要分解的产物
|
||||
int anInt = disToItemProduct.getInt("SrDisassemble." + disProductConfigString + ".disTime");
|
||||
String tagetIndex = disToItemProduct.getString("SrDisassemble." + disProductConfigString + ".index");
|
||||
CanDisItem canDisItem = new CanDisItem(disProductConfigString, anInt,disProductConfigString,tagetIndex);
|
||||
List<String> stringList = disToItemProduct.getStringList("SrDisassemble." + disProductConfigString +".disProduct");
|
||||
for (String product : stringList) {
|
||||
Double proMax = itemDetailProduct.getDouble("SrDisassemble."+disProductConfigString+"."+product+".probabilityMax");
|
||||
Double proMin = itemDetailProduct.getDouble("SrDisassemble."+disProductConfigString+"."+product+".probabilityMin");
|
||||
String index = itemDetailProduct.getString("SrDisassemble."+disProductConfigString+"."+product+".index");
|
||||
DisProduct disPojo = new DisProduct(product, index, proMax, proMin);
|
||||
logger.info(ChatColor.GREEN+disPojo.toString());
|
||||
disProductHashMap.put(product,disPojo);
|
||||
}
|
||||
canDisItem.setDisProductHashMap(disProductHashMap);
|
||||
|
||||
this.disProductHashMap.put(disProductConfigString,canDisItem);
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, CanDisItem> getDisProductHashMap() {
|
||||
return disProductHashMap;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
42
src/main/java/com/yuyu/srdisassemble/data/DataSource.java
Normal file
42
src/main/java/com/yuyu/srdisassemble/data/DataSource.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.yuyu.srdisassemble.data;
|
||||
|
||||
import com.yuyu.srdisassemble.SrDisassemble;
|
||||
import org.apache.ibatis.datasource.DataSourceFactory;
|
||||
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class DataSource implements DataSourceFactory {
|
||||
private static UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
|
||||
|
||||
|
||||
public DataSource(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties props) {
|
||||
props.setProperty("driver", SrDisassemble.getConfigManager().getDriver());
|
||||
props.setProperty("url", SrDisassemble.getConfigManager().getUrl());
|
||||
|
||||
|
||||
props.setProperty("username", SrDisassemble.getConfigManager().getUsername());
|
||||
props.setProperty("password", SrDisassemble.getConfigManager().getPassword());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.sql.DataSource getDataSource() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("driver", SrDisassemble.getConfigManager().getDriver());
|
||||
props.setProperty("url", SrDisassemble.getConfigManager().getUrl());
|
||||
props.setProperty("username", SrDisassemble.getConfigManager().getUsername());
|
||||
props.setProperty("password", SrDisassemble.getConfigManager().getPassword());
|
||||
|
||||
unpooledDataSourceFactory.setProperties(props);
|
||||
return unpooledDataSourceFactory.getDataSource();
|
||||
}
|
||||
}
|
316
src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java
Normal file
316
src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java
Normal file
@ -0,0 +1,316 @@
|
||||
package com.yuyu.srdisassemble.data;
|
||||
|
||||
import com.yuyu.srdisassemble.SrDisassemble;
|
||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/19 16:05:42
|
||||
* @description JDBC
|
||||
*/
|
||||
public class JdbcSqlClass {
|
||||
private static String driver;
|
||||
private static String url;
|
||||
private static String user;
|
||||
private static String password;
|
||||
private static Connection con;
|
||||
|
||||
|
||||
public static void openConnection() {
|
||||
//注册驱动
|
||||
try {
|
||||
Class.forName(JdbcSqlClass.driver);
|
||||
|
||||
//获取连接
|
||||
Connection conn = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||
JdbcSqlClass.con = conn;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static Statement getConnection() {
|
||||
try {
|
||||
//注册驱动
|
||||
Class.forName(JdbcSqlClass.driver);
|
||||
|
||||
//获取执行者对象
|
||||
Statement stmt = con.createStatement();
|
||||
|
||||
|
||||
return stmt;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initTable() {
|
||||
try {
|
||||
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
String createTable = " create table if not exists srdisassemble\t( id BIGINT auto_increment not null PRIMARY KEY comment 'ID'," +
|
||||
" playername varchar(255) null comment '玩家姓名'," +
|
||||
" disassembleTime varchar(255) null comment '分解的时间'," +
|
||||
" target varchar(255) null comment '分解的目标'," +
|
||||
" targetIndex varchar(255) null comment '分解目标的索引'," +
|
||||
" guiname varchar(255) null comment '打开gui的名称'," +
|
||||
" amount int null comment '分解的数量')";
|
||||
|
||||
boolean rs = connection.execute(createTable);
|
||||
|
||||
if (rs) {
|
||||
SrDisassemble.getInstance().getLogger().info(ChatColor.GREEN + "initTable执行完毕");
|
||||
}
|
||||
|
||||
|
||||
String sql = "select column_name\n" +
|
||||
"from INFORMATION_SCHEMA.COLUMNS\n" +
|
||||
"where TABLE_NAME = 'srdisassemble'";
|
||||
|
||||
//手动注入所有列
|
||||
List<String> columns = new ArrayList<>();
|
||||
columns.add("id");
|
||||
columns.add("playername");
|
||||
columns.add("disassembleTime");
|
||||
columns.add("target");
|
||||
columns.add("targetIndex");
|
||||
columns.add("guiname");
|
||||
columns.add("amount");
|
||||
|
||||
try {
|
||||
ResultSet resultSet = connection.executeQuery(sql);
|
||||
List<String> lists = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (resultSet.next()) {
|
||||
String columnName = resultSet.getString("column_name");
|
||||
lists.add(columnName);
|
||||
index++;
|
||||
}
|
||||
List<String> missColumn = new ArrayList<>();
|
||||
for (String columnName : columns) {
|
||||
if (!lists.contains(columnName)) {
|
||||
missColumn.add(columnName);
|
||||
}
|
||||
}
|
||||
//新增列
|
||||
for (String columnName : missColumn) {
|
||||
addColumn(columnName);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用于新增列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int addColumn(String columns) {
|
||||
String sql = null;
|
||||
if (columns.equals("id")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD id BIGINT auto_increment not null PRIMARY KEY comment 'ID'";
|
||||
} else if (columns.equals("playername")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD playername varchar(255) null comment '玩家姓名'";
|
||||
} else if (columns.equals("disassembleTime")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD disassembleTime varchar(255) null comment '分解的时间'";
|
||||
} else if (columns.equals("target")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD target varchar(255) null comment '分解的目标'";
|
||||
} else if (columns.equals("targetIndex")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD targetIndex varchar(255) null comment '分解目标的索引'";
|
||||
} else if (columns.equals("guiname")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD guiname varchar(255) null comment '打开gui的名称'";
|
||||
} else if (columns.equals("amount")) {
|
||||
sql = "ALTER TABLE srdisassemble\n" +
|
||||
"ADD amount int null comment '分解的数量'";
|
||||
}
|
||||
|
||||
if (sql != null) {
|
||||
Statement stmt = getConnection();
|
||||
try {
|
||||
int i = stmt.executeUpdate(sql);
|
||||
return i;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setChartseUtf8() {
|
||||
try {
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
|
||||
String sql = "ALTER TABLE srdisassemble CONVERT TO CHARACTER SET utf8mb4;";
|
||||
boolean rs = connection.execute(sql);
|
||||
|
||||
if (rs) {
|
||||
SrDisassemble.getInstance().getLogger().info(ChatColor.GREEN + "修改字符集成功");
|
||||
}
|
||||
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int insertData(DisassembleData data) {
|
||||
try {
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
String sql = "insert into srdisassemble(playername, disassembleTime, target, targetIndex, guiname) values('" +
|
||||
data.getPlayername() + "','" + data.getDisassembleTime().toString() + "','" + data.getTarget() + "','" + data.getTargetIndex() + "','" + data.getGuiName() + "')";
|
||||
int i = connection.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
ResultSet generatedKeys = connection.getGeneratedKeys();
|
||||
int id = 0;
|
||||
if (generatedKeys.next()) {
|
||||
id = generatedKeys.getInt(1);
|
||||
// SrDisassemble.getInstance().getLogger().info(ChatColor.GREEN+"数据插入成功");
|
||||
}
|
||||
|
||||
connection.close();
|
||||
connection.close();
|
||||
return id;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteData(int id) {
|
||||
try {
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
|
||||
String sql = "delete from srdisassemble where id=" + id;
|
||||
int i = connection.executeUpdate(sql);
|
||||
|
||||
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static DisassembleData getDisassembleData(int id) {
|
||||
try {
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
|
||||
String sql = "select * from srdisassemble where id=" + id;
|
||||
ResultSet rs = connection.executeQuery(sql);
|
||||
|
||||
DisassembleData data = new DisassembleData();
|
||||
while (rs.next()) {
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setPlayername(rs.getString("playername"));
|
||||
data.setDisassembleTime(rs.getTimestamp("disassembleTime").toLocalDateTime());
|
||||
data.setTarget(rs.getString("target"));
|
||||
data.setTargetIndex(rs.getString("targetIndex"));
|
||||
data.setGuiName(rs.getString("guiname"));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
connection.close();
|
||||
connection.close();
|
||||
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static DisassembleData getDataByGuiAndPlay(String playerName, String guiName) {
|
||||
try {
|
||||
Statement connection = getConnection();
|
||||
|
||||
//执行Sql语句
|
||||
|
||||
List<DisassembleData> disassembleDataList = new ArrayList<>();
|
||||
String sql = "select * from srdisassemble where playername= '" + playerName + "' and guiname= '" + guiName + "'";
|
||||
ResultSet rs = connection.executeQuery(sql);
|
||||
|
||||
DisassembleData data = new DisassembleData();
|
||||
|
||||
while (rs.next()) {
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setPlayername(rs.getString("playername"));
|
||||
data.setDisassembleTime(LocalDateTime.parse(rs.getString("disassembleTime")));
|
||||
data.setTarget(rs.getString("target"));
|
||||
data.setTargetIndex(rs.getString("targetIndex"));
|
||||
data.setGuiName(rs.getString("guiname"));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
connection.close();
|
||||
connection.close();
|
||||
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public static void setDriver(String driver) {
|
||||
JdbcSqlClass.driver = driver;
|
||||
}
|
||||
|
||||
public static String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public static void setUrl(String url) {
|
||||
JdbcSqlClass.url = url;
|
||||
}
|
||||
|
||||
public static String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void setUser(String user) {
|
||||
JdbcSqlClass.user = user;
|
||||
}
|
||||
|
||||
public static String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public static void setPassword(String password) {
|
||||
JdbcSqlClass.password = password;
|
||||
}
|
||||
}
|
63
src/main/java/com/yuyu/srdisassemble/data/SqlData.java
Normal file
63
src/main/java/com/yuyu/srdisassemble/data/SqlData.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.yuyu.srdisassemble.data;
|
||||
|
||||
import com.yuyu.srdisassemble.data.mapper.SqlDataMapper;
|
||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||
import com.yuyu.srdisassemble.utils.MybatisUtil;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/17 16:57:26
|
||||
* @description
|
||||
*/
|
||||
public class SqlData {
|
||||
/**
|
||||
* 插件启动时加载表
|
||||
*/
|
||||
public static void initTable(){
|
||||
SqlSession sqlSession = MybatisUtil.getSqlSession();
|
||||
// sqlSession.getConfiguration().addMapper(SqlDataMapper.class);
|
||||
SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
|
||||
|
||||
mapper.createTable();
|
||||
mapper.setChartseUtf8();
|
||||
|
||||
sqlSession.commit();
|
||||
sqlSession.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param data
|
||||
*/
|
||||
public static void addDisassemble(DisassembleData data){
|
||||
try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
|
||||
SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
|
||||
mapper.addDisassembleEvent(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DisassembleData> getDisassembleData(String playerName){
|
||||
try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
|
||||
SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
|
||||
List<DisassembleData> disassembleData = mapper.selectDisassembleEvent(playerName);
|
||||
return disassembleData;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DisassembleData> getDisassembleData(String playerName, String target){
|
||||
try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
|
||||
SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
|
||||
List<DisassembleData> disassembleData = mapper.selectDisassembleEventAndTarget(playerName,target);
|
||||
return disassembleData;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDisassemble(String playerName){
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.yuyu.srdisassemble.data.mapper;
|
||||
|
||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface SqlDataMapper {
|
||||
|
||||
|
||||
void createTable();
|
||||
void setChartseUtf8();
|
||||
void addDisassembleEvent(@Param("data") DisassembleData data);
|
||||
List<DisassembleData> selectDisassembleEvent(@Param("playername") String playername);
|
||||
List<DisassembleData> selectDisassembleEventAndTarget(@Param("playername")String playername, @Param("target") String target);
|
||||
void deleteDisassemble(@Param("playername") String playername, @Param("target") String target,@Param("disassembleTime") Date disassembleTime);
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.yuyu.srdisassemble.disassemeble;
|
||||
|
||||
import com.germ.germplugin.GermPlugin;
|
||||
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen;
|
||||
import com.germ.germplugin.api.dynamic.gui.GuiManager;
|
||||
import com.sakurarealm.sritem.germ.GermGuiService;
|
||||
import com.yuyu.srdisassemble.SrDisassemble;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/11 16:42:02
|
||||
* @description
|
||||
*/
|
||||
public class DisassembleManager {
|
||||
@Getter
|
||||
private final static DisassembleManager instance = new DisassembleManager();//用于获取实例
|
||||
|
||||
public DisassembleManager() {
|
||||
}
|
||||
|
||||
public static ConfigurationSection getGermGui(String directoryPath, String guiName) {
|
||||
if (directoryPath != null && !directoryPath.startsWith(File.separator))
|
||||
directoryPath = File.separator + directoryPath;
|
||||
|
||||
return YamlConfiguration.loadConfiguration(
|
||||
new File(GermGuiService.germPluginFilePath.getAbsolutePath()
|
||||
+ File.separator + "gui" + directoryPath + File.separator
|
||||
+ guiName + ".yml")
|
||||
).getConfigurationSection(guiName);
|
||||
}
|
||||
|
||||
//获取分解gui的背包
|
||||
public static ConfigurationSection getDisassemblePlayerInventory() {
|
||||
return DisassembleManager.getGermGui( "disassemble","player_inventory-disassemble");
|
||||
}
|
||||
|
||||
//获取分解gui
|
||||
public static ConfigurationSection getDisassembleGui() {
|
||||
return DisassembleManager.getGermGui( "disassemble","disassemble");
|
||||
}
|
||||
|
||||
|
||||
public static ConfigurationSection getTemporarilyBox(){
|
||||
return DisassembleManager.getGermGui( "disassemble","TemporarilyBox");
|
||||
}
|
||||
|
||||
//用于打开gui
|
||||
public void open(Player player) {
|
||||
// SassembleGuiService sassembleGuiService = (SassembleGuiService) TemporarilyBox.getGermGuiScreen(player.getName(), "disassemble");
|
||||
// if (sassembleGuiService == null) {
|
||||
//获取分解gui
|
||||
SassembleGuiService sassembleGuiService = new SassembleGuiService(getDisassembleGui(), "disassemble", player);
|
||||
// TemporarilyBox.addGuiScreen(player.getName(), "disassemble", sassembleGuiService);
|
||||
// }
|
||||
|
||||
// GermGuiScreen packscreen = TemporarilyBox.getGermGuiScreen(player.getName(), "player_inventory-disassemble");
|
||||
// if (packscreen == null) {
|
||||
GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory());
|
||||
// TemporarilyBox.addGuiScreen(player.getName(), "player_inventory-disassemble",packscreen);
|
||||
// }
|
||||
|
||||
sassembleGuiService.openGui(player);
|
||||
packscreen.openChildGui(player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,314 @@
|
||||
package com.yuyu.srdisassemble.disassemeble;
|
||||
|
||||
import com.germ.germplugin.api.dynamic.gui.*;
|
||||
import com.sakurarealm.sritem.api.ItemStackHelper;
|
||||
import com.sakurarealm.sritem.api.SrItemAPI;
|
||||
import com.sakurarealm.sritem.api.builder.SrItemHandler;
|
||||
import com.yuyu.srdisassemble.SrDisassemble;
|
||||
import com.yuyu.srdisassemble.data.JdbcSqlClass;
|
||||
import com.yuyu.srdisassemble.data.SqlData;
|
||||
import com.yuyu.srdisassemble.pojo.CanDisItem;
|
||||
import com.yuyu.srdisassemble.pojo.DisProduct;
|
||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||
import com.yuyu.srdisassemble.utils.MinUtil;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/11 17:01:05
|
||||
* @description 用于给分解gui提供服务的类
|
||||
*/
|
||||
public class SassembleGuiService extends GermGuiScreen {
|
||||
private DisassembleData data;
|
||||
private String name;
|
||||
private Random random ;
|
||||
private boolean disassemble = true;
|
||||
private Player playerHost;
|
||||
private GermGuiScreen temporarilyBoxScreen;
|
||||
|
||||
public SassembleGuiService(ConfigurationSection configurationSection, String guiName,Player playerHost) {
|
||||
super(guiName, configurationSection);
|
||||
this.playerHost = playerHost;
|
||||
this.data = JdbcSqlClass.getDataByGuiAndPlay(playerHost.getName(), guiName);
|
||||
this.registerDisassemble();
|
||||
this.random = new Random();
|
||||
this.name = playerHost.getName();
|
||||
this.getTemporarilyBox();
|
||||
this.boolGui();
|
||||
this.setClosedHandler(((player, germGuiScreen) -> {
|
||||
//窗口关闭事件
|
||||
this.returnItemStacks(player);
|
||||
this.saveTemporarilyBox();
|
||||
this.close();
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取暂存箱对象
|
||||
*/
|
||||
public void getTemporarilyBox(){
|
||||
this.temporarilyBoxScreen = TemporarilyBox.getGermGuiScreen(playerHost.getName(), "TemporarilyBox");
|
||||
if (temporarilyBoxScreen == null) {
|
||||
temporarilyBoxScreen = GermGuiScreen.getGermGuiScreen("TemporarilyBox", DisassembleManager.getTemporarilyBox());
|
||||
TemporarilyBox.addGuiScreen(playerHost.getName(),"TemporarilyBox",temporarilyBoxScreen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于关闭暂存箱
|
||||
*/
|
||||
public void closeTemporaryBox(){
|
||||
this.temporarilyBoxScreen.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* gui关闭时保存暂存箱
|
||||
*/
|
||||
public void saveTemporarilyBox(){
|
||||
TemporarilyBox.addGuiScreen(playerHost.getName(), "TemporarilyBox",this.temporarilyBoxScreen);
|
||||
}
|
||||
|
||||
public void boolGui(){
|
||||
if (data.getId() != 0 && data.getTargetIndex() != null) {
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
disassembleSlot.setInteract(false);
|
||||
disassembleSlot.setItemStack(SrItemAPI.getItem(data.getTargetIndex(),
|
||||
new HashMap<>(),null,true,true));
|
||||
|
||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
||||
GermGuiTexture doorPause = (GermGuiTexture) this.getGuiPart("doorPause");
|
||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
||||
|
||||
men1.setEnable(false);
|
||||
fire.setEnable(true);
|
||||
doorPause.setEnable(true);
|
||||
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
|
||||
// executor.schedule(() ->{
|
||||
// //打开暂存箱
|
||||
// temporarilyBoxScreen.openChildGui(playerHost);
|
||||
//
|
||||
// },100,TimeUnit.MILLISECONDS);
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
||||
if (calculateMinutesDifference <= 0) {
|
||||
//执行语句说明分解完成
|
||||
this.disassembleComplete();
|
||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
||||
JdbcSqlClass.deleteData(data.getId());
|
||||
|
||||
//赋予产物后把火关掉,门打开
|
||||
//TODO(此处后面可以让美术大佬做一个开炉门的gif
|
||||
fire.setEnable(false);
|
||||
door.setEnable(false);
|
||||
men1.setEnable(true);
|
||||
doorPause.setEnable(false);
|
||||
this.openTemporarilyBox();
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},0, 1 , TimeUnit.MINUTES);
|
||||
//0延迟,minTime分钟后执行
|
||||
}else {
|
||||
this.openTemporarilyBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void openTemporarilyBox(){
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.schedule(() -> {
|
||||
this.temporarilyBoxScreen.openChildGui(this.playerHost);
|
||||
},100,TimeUnit.MILLISECONDS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册分解事件
|
||||
*/
|
||||
public void registerDisassemble() {
|
||||
//获取画布
|
||||
GermGuiCanvas canvas = (GermGuiCanvas)this.getGuiPart("canvas");
|
||||
//通过画布获取按键
|
||||
GermGuiButton confirmButton = (GermGuiButton) canvas.getGuiPart("confirmButton");
|
||||
GermGuiButton cancleButton = (GermGuiButton) canvas.getGuiPart("cancleButton");
|
||||
GermGuiButton germGuiButton =(GermGuiButton) this.getGuiPart("youhu");
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
|
||||
confirmButton.registerCallbackHandler((player, btn) -> {
|
||||
this.disassemble(player);
|
||||
canvas.setEnable(false);
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
|
||||
//取消事件
|
||||
cancleButton.registerCallbackHandler((player, btn) -> {
|
||||
//取消事件,关闭画布gui
|
||||
canvas.setEnable(false);
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
|
||||
//油壶按钮绑定的事件触发画布显示
|
||||
germGuiButton.registerCallbackHandler((player, btn) -> {
|
||||
if ((boolean)disassembleSlot.getInteract()) {
|
||||
canvas.setEnable(true);
|
||||
}
|
||||
},GermGuiButton.EventType.LEFT_CLICK);
|
||||
}
|
||||
|
||||
public void disassemble(Player player){
|
||||
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
if ((boolean)disassembleSlot.getInteract() == false){
|
||||
//正在分解某种物品
|
||||
return;
|
||||
}
|
||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||
if (itemStack.getType() == Material.AIR || itemStack == null) {
|
||||
player.sendMessage(Color.RED+"在熔炉物品框中放上可分解的物品!");
|
||||
return;
|
||||
}
|
||||
SrItemHandler srItemHandler = ItemStackHelper.getSrItemHandler(itemStack);
|
||||
String title = srItemHandler.getTitle();
|
||||
//这个是item的名字
|
||||
String itemName = title.substring(title.indexOf('l') + 1);
|
||||
HashMap<String, CanDisItem> disProductHashMap = SrDisassemble.getConfigManager().getDisProductHashMap();
|
||||
CanDisItem canDisItem = disProductHashMap.get(itemName);
|
||||
if (!disProductHashMap.containsKey(itemName)){
|
||||
player.sendMessage(Color.RED+"放入的物品不可分解!");
|
||||
return;
|
||||
}
|
||||
disassembleSlot.setInteract(false);//关闭交互
|
||||
//上方if语句通过表示该物品可以分解
|
||||
//假如启动按钮是油壶,
|
||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
||||
door.setCycle(1);
|
||||
if ((boolean)door.getEnable() == true){
|
||||
return;
|
||||
}
|
||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
||||
men1.setEnable(false);
|
||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
||||
fire.setEnable(true);
|
||||
door.setEnable(true);
|
||||
this.data = new DisassembleData(player.getName(),
|
||||
MinUtil.calculateTimeAfterMinutes(canDisItem.getDisTime()),
|
||||
canDisItem.getTarget(), canDisItem.getTargetIndex(), this.getGuiName(),itemStack.getAmount());
|
||||
//此处向数据库中插入数据,并且注册定时器计算时间
|
||||
int i = JdbcSqlClass.insertData(data);
|
||||
data.setId(i);
|
||||
|
||||
//下面写注册逻辑,完成的时间已经记录在data里面了!!!
|
||||
|
||||
this.closeTemporaryBox();
|
||||
|
||||
int minTime = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
||||
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
// executor.schedule(() ->{
|
||||
// //打开暂存箱
|
||||
// temporarilyBoxScreen.openChildGui(playerHost);
|
||||
//
|
||||
// },1,TimeUnit.SECONDS);
|
||||
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
||||
if (calculateMinutesDifference <= 0) {
|
||||
//执行语句说明分解完成
|
||||
this.disassembleComplete();
|
||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
||||
JdbcSqlClass.deleteData(data.getId());
|
||||
|
||||
//赋予产物后把火关掉,门打开
|
||||
//TODO(此处后面可以让美术大佬做一个开炉门的gif
|
||||
fire.setEnable(false);
|
||||
door.setEnable(false);
|
||||
men1.setEnable(true);
|
||||
this.openTemporarilyBox();
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
},1, 1, TimeUnit.MINUTES);
|
||||
//1分钟延迟,minTime分钟后执行
|
||||
|
||||
|
||||
|
||||
|
||||
// //此处写分解逻辑
|
||||
// int itemAmount = itemStack.getAmount();
|
||||
// //分解物品返回原胚,理论上是只能单次分解一个然后得到一个。
|
||||
// HashMap<String, DisProduct> stringDisProductHashMap = disProductHashMap.get(itemName);
|
||||
// float v = random.nextFloat();
|
||||
// ItemStack product = null;
|
||||
// for (DisProduct disProduct : stringDisProductHashMap.values()) {
|
||||
// if (disProduct.getProMax() > v && disProduct.getProMin() <= v){
|
||||
// product = SrItemAPI.getItem(disProduct.getIndexName(),new HashMap<>(),null,true,true);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// disassembleSlot.setInteract(true);
|
||||
// //赋予产物
|
||||
// disassembleSlot.setItemStack(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此方法用于获取产物
|
||||
*/
|
||||
public void disassembleComplete(){
|
||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||
//此处写分解逻辑
|
||||
int itemAmount = itemStack.getAmount();
|
||||
SrItemHandler srItemHandler = ItemStackHelper.getSrItemHandler(itemStack);
|
||||
String title = srItemHandler.getTitle();
|
||||
//这个是item的名字
|
||||
String itemName = title.substring(title.indexOf('l') + 1);
|
||||
|
||||
HashMap<String, CanDisItem> disProductHashMap = SrDisassemble.getConfigManager().getDisProductHashMap();
|
||||
//分解物品返回原胚,理论上是只能单次分解一个然后得到一个。
|
||||
CanDisItem canDisItem = disProductHashMap.get(itemName);
|
||||
HashMap<String, DisProduct> disProducts = canDisItem.getDisProductHashMap();
|
||||
float v = random.nextFloat();
|
||||
ItemStack product = null;
|
||||
for (DisProduct disProduct : disProducts.values()) {
|
||||
if (disProduct.getProMax() > v && disProduct.getProMin() <= v){
|
||||
product = SrItemAPI.getItem(disProduct.getIndexName(),new HashMap<>(),null,true,true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
disassembleSlot.setInteract(true);
|
||||
//赋予产物
|
||||
disassembleSlot.setItemStack(product);
|
||||
}
|
||||
|
||||
//遍历gui的所有物品槽,并且返回到玩家背包中
|
||||
synchronized private void returnItemStacks(Player player) {
|
||||
this.disassemble = false;
|
||||
this.temporarilyBoxScreen.close();
|
||||
List<GermGuiSlot> allGuiParts = this.getAllGuiParts(GermGuiSlot.class);
|
||||
for (GermGuiSlot guiPart : allGuiParts) {
|
||||
if ((guiPart.getItemStack().getType() != Material.AIR || guiPart.getItemStack() == null) && (boolean)guiPart.getInteract()) {
|
||||
player.getInventory().addItem(guiPart.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.yuyu.srdisassemble.disassemeble;
|
||||
|
||||
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/21 18:50:18
|
||||
* @description 用于存放暂存箱
|
||||
*/
|
||||
public class TemporarilyBox {
|
||||
public static HashMap<String, HashMap<String,GermGuiScreen>> temporarilyBoxHashMap = new HashMap<>();
|
||||
|
||||
public static GermGuiScreen getGermGuiScreen(String playname,String guiName) {
|
||||
if(temporarilyBoxHashMap.containsKey(playname)) {
|
||||
HashMap<String, GermGuiScreen> stringGermGuiScreenHashMap = temporarilyBoxHashMap.get(playname);
|
||||
if(stringGermGuiScreenHashMap.containsKey(guiName)) {
|
||||
return stringGermGuiScreenHashMap.get(guiName);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteGuiScreen(String playname,String guiName) {
|
||||
if(temporarilyBoxHashMap.containsKey(playname)) {
|
||||
temporarilyBoxHashMap.get(playname).remove(guiName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addGuiScreen(String playname,String guiName,GermGuiScreen guiScreen) {
|
||||
if(temporarilyBoxHashMap.containsKey(playname)) {
|
||||
temporarilyBoxHashMap.get(playname).put(guiName, guiScreen);
|
||||
}else {
|
||||
HashMap<String,GermGuiScreen> stringGermGuiScreenHashMap = new HashMap<>();
|
||||
stringGermGuiScreenHashMap.put(guiName, guiScreen);
|
||||
temporarilyBoxHashMap.put(playname, stringGermGuiScreenHashMap);
|
||||
}
|
||||
}
|
||||
}
|
72
src/main/java/com/yuyu/srdisassemble/pojo/CanDisItem.java
Normal file
72
src/main/java/com/yuyu/srdisassemble/pojo/CanDisItem.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.yuyu.srdisassemble.pojo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/19 21:49:48
|
||||
* @description 可分解的物品
|
||||
*/
|
||||
public class CanDisItem {
|
||||
private String itemName;
|
||||
private int disTime;
|
||||
private String target;
|
||||
private String targetIndex;
|
||||
private HashMap<String,DisProduct> disProductHashMap;
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void setTargetIndex(String targetIndex) {
|
||||
this.targetIndex = targetIndex;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getTargetIndex() {
|
||||
return targetIndex;
|
||||
}
|
||||
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public int getDisTime() {
|
||||
return disTime;
|
||||
}
|
||||
|
||||
public HashMap<String, DisProduct> getDisProductHashMap() {
|
||||
return disProductHashMap;
|
||||
}
|
||||
|
||||
public void setItemName(String itemName) {
|
||||
this.itemName = itemName;
|
||||
}
|
||||
|
||||
public void setDisTime(int disTime) {
|
||||
this.disTime = disTime;
|
||||
}
|
||||
|
||||
public void setDisProductHashMap(HashMap<String, DisProduct> disProductHashMap) {
|
||||
this.disProductHashMap = disProductHashMap;
|
||||
}
|
||||
|
||||
public CanDisItem(String itemName, int disTime,String target,String targetIndex) {
|
||||
this.itemName = itemName;
|
||||
this.disTime = disTime;
|
||||
this.target = target;
|
||||
this.targetIndex = targetIndex;
|
||||
}
|
||||
|
||||
public CanDisItem(String itemName, int disTime, HashMap<String, DisProduct> disProductHashMap) {
|
||||
this.itemName = itemName;
|
||||
this.disTime = disTime;
|
||||
this.disProductHashMap = disProductHashMap;
|
||||
}
|
||||
}
|
67
src/main/java/com/yuyu/srdisassemble/pojo/DisProduct.java
Normal file
67
src/main/java/com/yuyu/srdisassemble/pojo/DisProduct.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.yuyu.srdisassemble.pojo;
|
||||
|
||||
import com.sakurarealm.sritem.api.SrItemAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @BelongsProject: SrAppraise
|
||||
* @BelongsPackage: com.yuyu.srappraise.pojo
|
||||
* @FileName: AppraiseProduct
|
||||
* @Author: 峰。
|
||||
* @Date: 2024/4/23-14:09
|
||||
* @Version: 1.0
|
||||
* @Description: 分解的产物
|
||||
*/
|
||||
public class DisProduct {
|
||||
//物品的名称
|
||||
private final String ItemName;
|
||||
//物品的索引
|
||||
private final String indexName;
|
||||
//最大的概率
|
||||
private final double ProMax;
|
||||
//最小的概率
|
||||
private final double ProMin;
|
||||
//获取ItemStack
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public String getItemName() {
|
||||
return ItemName;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public double getProMax() {
|
||||
return ProMax;
|
||||
}
|
||||
|
||||
public double getProMin() {
|
||||
return ProMin;
|
||||
}
|
||||
|
||||
public DisProduct(String itemName, String indexName, double proMax, double proMin) {
|
||||
ItemName = itemName;
|
||||
this.indexName = indexName;
|
||||
ProMax = proMax;
|
||||
ProMin = proMin;
|
||||
this.itemStack = SrItemAPI.getItem(indexName,new HashMap<>(),null,true,true);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DisProduct{" +
|
||||
"ItemName='" + ItemName + '\'' +
|
||||
", indexName='" + indexName + '\'' +
|
||||
", ProMax=" + ProMax +
|
||||
", ProMin=" + ProMin +
|
||||
", itemStack=" + itemStack +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.yuyu.srdisassemble.pojo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/17 18:08:55
|
||||
* @description 用于新增和接收分解的信息
|
||||
*/
|
||||
public class DisassembleData {
|
||||
private int id;
|
||||
private String playername;
|
||||
private LocalDateTime disassembleTime;
|
||||
private String target;
|
||||
private String targetIndex;
|
||||
private String guiName;
|
||||
private int size;
|
||||
|
||||
public DisassembleData() {
|
||||
}
|
||||
|
||||
|
||||
public DisassembleData(String playername, LocalDateTime disassembleTime, String target, String targetIndex, String guiName, int size) {
|
||||
this.playername = playername;
|
||||
this.disassembleTime = disassembleTime;
|
||||
this.target = target;
|
||||
this.targetIndex = targetIndex;
|
||||
this.guiName = guiName;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public DisassembleData(int id, String playername, LocalDateTime disassembleTime, String target, String targetIndex, String guiName) {
|
||||
this.id = id;
|
||||
this.playername = playername;
|
||||
this.disassembleTime = disassembleTime;
|
||||
this.target = target;
|
||||
this.targetIndex = targetIndex;
|
||||
this.guiName = guiName;
|
||||
}
|
||||
|
||||
public String getGuiName() {
|
||||
return guiName;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setPlayername(String playername) {
|
||||
this.playername = playername;
|
||||
}
|
||||
|
||||
public void setDisassembleTime(LocalDateTime disassembleTime) {
|
||||
this.disassembleTime = disassembleTime;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void setTargetIndex(String targetIndex) {
|
||||
this.targetIndex = targetIndex;
|
||||
}
|
||||
|
||||
public void setGuiName(String guiName) {
|
||||
this.guiName = guiName;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getPlayername() {
|
||||
return playername;
|
||||
}
|
||||
|
||||
public LocalDateTime getDisassembleTime() {
|
||||
return disassembleTime;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getTargetIndex() {
|
||||
return targetIndex;
|
||||
}
|
||||
}
|
54
src/main/java/com/yuyu/srdisassemble/utils/MinUtil.java
Normal file
54
src/main/java/com/yuyu/srdisassemble/utils/MinUtil.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.yuyu.srdisassemble.utils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author 峰。
|
||||
* @version 1.0
|
||||
* @project SrDisassemble
|
||||
* @date 2024/6/19 21:24:25
|
||||
* @description 用于计算时间
|
||||
*/
|
||||
public class MinUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 计算得出产物的时间
|
||||
* @param minutesToAdd
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime calculateTimeAfterMinutes(int minutesToAdd) {
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
// 使用plusMinutes方法添加分钟数
|
||||
LocalDateTime futureTime = currentTime.plusMinutes(minutesToAdd);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
futureTime.format(formatter);
|
||||
return futureTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算得出产物需要的时间,注意此处返回的可能是负数
|
||||
* @param givenTime
|
||||
* @return
|
||||
*/
|
||||
public static int calculateMinutesDifference(LocalDateTime givenTime) {
|
||||
// 获取当前时间
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
|
||||
// 计算两个时间之间的Duration
|
||||
Duration duration = Duration.between(currentTime, givenTime);
|
||||
|
||||
// 获取Duration中的分钟数(注意:Duration的toMinutes方法返回的是总分钟数,包括天数、小时等转换过来的分钟)
|
||||
int minutes =(int) duration.toMinutes();
|
||||
|
||||
// 如果givenTime在currentTime之后,则duration是负数,我们需要取绝对值
|
||||
// 但实际上我们可能想要返回负数来表示givenTime在未来
|
||||
// 这里取决于你的需求,是返回绝对值还是实际值
|
||||
// 如果要返回绝对值,则使用Math.abs(minutes)
|
||||
|
||||
// 返回分钟数
|
||||
return minutes;
|
||||
}
|
||||
}
|
51
src/main/java/com/yuyu/srdisassemble/utils/MybatisUtil.java
Normal file
51
src/main/java/com/yuyu/srdisassemble/utils/MybatisUtil.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.yuyu.srdisassemble.utils;
|
||||
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class MybatisUtil {
|
||||
private static final SqlSessionFactory factory;
|
||||
|
||||
static {
|
||||
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = Resources.getResourceAsStream("mybatis-config.xml");
|
||||
factory = new SqlSessionFactoryBuilder().build(inputStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to initialize MyBatis SqlSessionFactory", e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MybatisUtil( ) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static SqlSession getSqlSession() {
|
||||
return factory.openSession();
|
||||
}
|
||||
|
||||
public static void close(SqlSession sqlSession) {
|
||||
if (sqlSession != null) {
|
||||
sqlSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/main/resources/ItemDetail.yml
Normal file
14
src/main/resources/ItemDetail.yml
Normal file
@ -0,0 +1,14 @@
|
||||
#产物的详情
|
||||
SrDisassemble:
|
||||
巴尔伐楼伽的怨牙: #这一行填可以鉴定的物品
|
||||
环齿原胚: #这下面填鉴定物品可以得到的结果
|
||||
probabilityMax: 0.4 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间,若随机到0则为此产物,0.4则跳过
|
||||
probabilityMin: 0 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间,若随机到0则为此产物,0.4则跳过
|
||||
index: public.material.巴尔伐楼伽的怨牙 #这里填材料的索引名
|
||||
DisTime: 2 #分解需要的时间,单位为分钟
|
||||
保密试作品HC-03原胚: #这下面填鉴定物品可以得到的结果
|
||||
probabilityMax: 1 #概率
|
||||
probabilityMin: 0.4 #概率
|
||||
index: public.test.保密试作品HC-03原胚 #这里填材料的索引名
|
||||
DisTime: 2 #分解需要的时间,单位为分钟
|
||||
|
64
src/main/resources/SqlDataMapper.xml
Normal file
64
src/main/resources/SqlDataMapper.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yuyu.srdisassemble.data.mapper.SqlDataMapper">
|
||||
|
||||
|
||||
<update id="creatTable">
|
||||
create table if not exists srdisassemble
|
||||
(
|
||||
id BIGINT auto_increment comment 'ID',
|
||||
playername varchar(255) null comment '玩家姓名',
|
||||
disassembleTime datetime null comment '分解的时间',
|
||||
target varchar(255) null comment '分解的目标',
|
||||
targetIndex varchar(255) null comment '分解目标的索引'
|
||||
guiname varchar(255) null comment '打开gui的名称'
|
||||
);
|
||||
</update>
|
||||
|
||||
<update id="setChartseUtf8">
|
||||
ALTER TABLE srdisassemble CONVERT TO CHARACTER SET utf8mb4;
|
||||
</update>
|
||||
|
||||
<insert id="addDisassembleEvent" parameterType="com.yuyu.srdisassemble.pojo.DisassembleData">
|
||||
insert into srdisassemble(playername,disassembleTime,target,targetIndex)
|
||||
values(
|
||||
#{data.playername},
|
||||
#{data.disassembleTime},
|
||||
#{data.target},
|
||||
#{data.targetIndex}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="selectDisassembleEvent" resultMap="dataMap">
|
||||
select * from srdisassemble
|
||||
where playername = #{playername};
|
||||
</select>
|
||||
|
||||
<select id="selectDisassembleEventAndTarget" resultType="com.yuyu.srdisassemble.pojo.DisassembleData">
|
||||
select * from srdisassemble
|
||||
where playername = #{playername}
|
||||
and target = #{target};
|
||||
</select>
|
||||
|
||||
<delete id="deleteDisassemble">
|
||||
delete from srdisassemble where
|
||||
id = #{id}
|
||||
</delete>
|
||||
|
||||
<resultMap id="dataMap" type="com.yuyu.srdisassemble.pojo.DisassembleData">
|
||||
<result property="playername" javaType="java.lang.String" column="playername"></result>
|
||||
<result property="disassembleTime" javaType="java.util.Date" column="disassembleTime"></result>
|
||||
<result property="target" javaType="java.lang.String" column="target"></result>
|
||||
<result property="targetIndex" javaType="java.lang.String" column="targetIndex"></result>
|
||||
</resultMap>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
src/main/resources/datasource.yml
Normal file
6
src/main/resources/datasource.yml
Normal file
@ -0,0 +1,6 @@
|
||||
database:
|
||||
sql:
|
||||
user: root
|
||||
password:
|
||||
driver: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/mc_service
|
3
src/main/resources/disProduct.yml
Normal file
3
src/main/resources/disProduct.yml
Normal file
@ -0,0 +1,3 @@
|
||||
#可分解的物品
|
||||
SrDisassemble:
|
||||
巴尔伐楼伽的怨牙
|
8
src/main/resources/disToItem.yml
Normal file
8
src/main/resources/disToItem.yml
Normal file
@ -0,0 +1,8 @@
|
||||
#可分解的物品对应的产物
|
||||
SrDisassemble:
|
||||
巴尔伐楼伽的怨牙:
|
||||
disProduct:
|
||||
- 环齿原胚
|
||||
- 保密试作品HC-03原胚
|
||||
disTime: 2 #分解的时间,单位为分钟
|
||||
index: public.material.巴尔伐楼伽的怨牙
|
43
src/main/resources/mybatis-config.xml
Normal file
43
src/main/resources/mybatis-config.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<!--
|
||||
这些属性可以在外部进行配置,并可以进行动态替换。
|
||||
你既可以在典型的 Java 属性文件中配置这些属性,也可以在 properties 元素的子元素中设置
|
||||
-->
|
||||
|
||||
<!-- <settings>-->
|
||||
<!-- <setting name="logImpl" value="STDOUT_LOGGING"/>-->
|
||||
<!-- </settings>-->
|
||||
|
||||
|
||||
<environments default="development">
|
||||
<!--每个 environment 元素定义的环境 ID(比如:id="development")。-->
|
||||
<environment id="development">
|
||||
<!--事务管理器的配置(比如:type="JDBC")。-->
|
||||
<!--
|
||||
事务管理器(transactionManager)
|
||||
在 MyBatis 中有两种类型的事务管理器(也就是 type="[JDBC|MANAGED]"):
|
||||
JDBC – 这个配置直接使用了 JDBC 的提交和回滚设施,它依赖从数据源获得的连接来管理事务作用域。
|
||||
MANAGED – 这个配置几乎没做什么。它从不提交或回滚一个连接,而是让容器来管理事务的整个生命周期(比如 JEE 应用服务器的上下文)。
|
||||
默认情况下它会关闭连接。然而一些容器并不希望连接被关闭,因此需要将 closeConnection 属性设置为 false 来阻止默认的关闭行为。
|
||||
如果你正在使用 Spring + MyBatis,则没有必要配置事务管理器,因为 Spring 模块会使用自带的管理器来覆盖前面的配置。
|
||||
这两种事务管理器类型都不需要设置任何属性。它们其实是类型别名,换句话说,你可以用 TransactionFactory 接口实现类的全限定名或类型别名代替它们。
|
||||
-->
|
||||
<transactionManager type="JDBC"/>
|
||||
<!--数据源的配置(比如:type="POOLED")-->
|
||||
<dataSource type="com.yuyu.srdisassemble.data.DataSource">
|
||||
</dataSource>
|
||||
</environment>
|
||||
</environments>
|
||||
|
||||
<mappers>
|
||||
|
||||
<mapper resource="SqlDataMapper.xml" class="com.yuyu.srdisassemble.data.mapper.SqlDataMapper"/>
|
||||
</mappers>
|
||||
|
||||
</configuration>
|
||||
|
11
src/main/resources/plugin.yml
Normal file
11
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,11 @@
|
||||
name: SrDisassemble
|
||||
version: '${project.version}'
|
||||
main: com.yuyu.srdisassemble.SrDisassemble
|
||||
|
||||
depend:
|
||||
- SrItem
|
||||
commands:
|
||||
srdisassemble:
|
||||
description: srdisassemble command
|
||||
aliases: [ srd ]
|
||||
permission: srdisassemble.command
|
Loading…
x
Reference in New Issue
Block a user