增加了修复和回炉的指令

This commit is contained in:
yuyu 2024-07-25 22:29:44 +08:00
parent 68bec76225
commit 24e05819c7
10 changed files with 296 additions and 37 deletions

View File

@ -2,6 +2,8 @@ package com.yuyu.srdisassemble;
import com.sakurarealm.sritem.bukkit.command.CommandBase;
import com.yuyu.srdisassemble.command.DisCommand;
import com.yuyu.srdisassemble.command.MeltCommand;
import com.yuyu.srdisassemble.command.RepairCommand;
import com.yuyu.srdisassemble.config.ConfigManager;
import com.yuyu.srdisassemble.data.JdbcSqlClass;
import com.yuyu.srdisassemble.disassemeble.TemporarilyBox;
@ -28,6 +30,14 @@ public final class SrDisassemble extends JavaPlugin {
commandBase.registerSubCommand("open",new DisCommand());
commandBase.registerSubCommand("reload",new DisCommand());
this.getCommand("srmeltagain").setExecutor(commandBase);
commandBase.registerSubCommand("open",new MeltCommand());
commandBase.registerSubCommand("reload",new MeltCommand());
this.getCommand("srrepair").setExecutor(commandBase);
commandBase.registerSubCommand("open",new RepairCommand());
commandBase.registerSubCommand("reload",new RepairCommand());
//读取暂存箱
JdbcSqlClass.createPauseBoxTable();
// JdbcSqlClass.setPauseBox2UTF();

View File

@ -1,8 +1,11 @@
package com.yuyu.srdisassemble.command;
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen;
import com.sakurarealm.sritem.bukkit.command.SubCommand;
import com.yuyu.srdisassemble.SrDisassemble;
import com.yuyu.srdisassemble.disassemeble.DisassembleManager;
import com.yuyu.srdisassemble.disassemeble.SassembleGuiService;
import com.yuyu.srdisassemble.disassemeble.TemporarilyBox;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -0,0 +1,47 @@
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 SrDisassemble113
* @date 2024/7/25 20:42:26
* @description 回炉指令类
*/
public class MeltCommand 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+"正确的格式为:/srmeltagain open 姓名 ");
return;
}
Player player = Bukkit.getPlayer(strings[1]);
if (player == null){
commandSender.sendMessage(ChatColor.RED+"玩家"+strings[1]+"不存在!");
return;
}
//为玩家打开GUI列表
DisassembleManager.getInstance().openMeltAgain(player);
}
}

View 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 SrDisassemble113
* @date 2024/7/25 20:55:21
* @description 维修指令
*/
public class RepairCommand 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+"正确的格式为:/srrepair open 姓名 ");
return;
}
Player player = Bukkit.getPlayer(strings[1]);
if (player == null){
commandSender.sendMessage(ChatColor.RED+"玩家"+strings[1]+"不存在!");
return;
}
//为玩家打开GUI列表
DisassembleManager.getInstance().openRepair(player);
}
}

View File

@ -1,10 +1,7 @@
package com.yuyu.srdisassemble.data;
import com.google.common.annotations.VisibleForTesting;
import com.yuyu.srdisassemble.SrDisassemble;
import com.yuyu.srdisassemble.pojo.DisassembleData;
import com.yuyu.srdisassemble.pojo.PauseBox;
import org.bukkit.ChatColor;
import java.sql.*;
import java.time.LocalDateTime;
@ -157,8 +154,9 @@ public class JdbcSqlClass {
" slotnumber int null comment '槽位',\n" +
" nums int null comment '数量',\n" +
" productindex varchar(255) null comment '原胚索引',\n" +
" guiname varchar(255) null comment 'gui的姓名'\n" +
") CHARACTER SET utf8mb4 COLLATE utf8mb4_bin";
" guiname varchar(255) null comment 'gui的姓名',\n" +
" lores text null comment '材料的lores'\n" +
" ) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin";
boolean rs = connection.execute(createTable);
@ -176,6 +174,7 @@ public class JdbcSqlClass {
columns.add("nums");
columns.add("productindex");
columns.add("guiname");
columns.add("lores");
try {
ResultSet resultSet = connection.executeQuery(sql);
@ -210,17 +209,19 @@ public class JdbcSqlClass {
/**
* 插入数据
*
* @param username
* @param slotNumber
* @param nums
* @param productindex
* @param guiname
* @param lore
*/
public static void insertPauseBoxData(String username,int slotNumber,int nums,String productindex,String guiname){
public static void insertPauseBoxData(String username, int slotNumber, int nums, String productindex, String guiname, String lore){
try {
String sql = "insert into pausebox(username, slotnumber, nums, productindex, guiname)" +
" VALUES ('"+username+"',"+slotNumber+","+nums+",'"+productindex+"','"+guiname+"')";
String sql = "insert into pausebox(username, slotnumber, nums, productindex, guiname,lores)" +
" VALUES ('"+username+"',"+slotNumber+","+nums+",'"+productindex+"','"+guiname+"','"+lore+"')";
Statement statement = getConnection();
@ -271,6 +272,9 @@ public class JdbcSqlClass {
} else if (columns.equals("guiname")) {
sql = "ALTER TABLE pausebox\n" +
"ADD guiname varchar(255) null comment 'gui的姓名'";
}else if (columns.equals("lores")) {
sql = "ALTER TABLE pausebox\n" +
"ADD lores text null comment '材料的lores'";
}
if (sql != null) {
@ -507,11 +511,18 @@ public class JdbcSqlClass {
try {
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()){
String lore = resultSet.getString("lores");
List<String> lores = new ArrayList<>();
String[] split = lore.split("\\|");
for (String s : split) {
lores.add(s);
}
PauseBox pauseBox = new PauseBox(resultSet.getString("username"),
resultSet.getInt("slotnumber"),
resultSet.getInt("nums"),
resultSet.getString("productindex"),
resultSet.getString("guiname"));
resultSet.getString("guiname"),lores);
pauseBoxList.add(pauseBox);
}

View File

@ -55,21 +55,40 @@ public class DisassembleManager {
//用于打开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) {
if (TemporarilyBox.isHasGui(player.getName(), "disassemble")){
SassembleGuiService germGuiScreen = (SassembleGuiService) TemporarilyBox.getGermGuiScreen(player.getName(), "disassemble");
GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory());
if (germGuiScreen != null) {
germGuiScreen.openGui(player);
packscreen.openChildGui(player);
return;
}
}
//分解gui
SassembleGuiService sassembleGuiService = new SassembleGuiService(getDisassembleGui(), "disassemble", player);
GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory());
// TemporarilyBox.addGuiScreen(player.getName(), "player_inventory-disassemble",packscreen);
// }
sassembleGuiService.openGui(player);
packscreen.openChildGui(player);
}
/**
* 用于打开回炉gui
* @param player
*/
public void openMeltAgain(Player player) {
}
/**
* 用于打开维修gui
* @param player
*/
public void openRepair(Player player) {
}
}

View File

@ -37,7 +37,7 @@ public class SassembleGuiService extends GermGuiScreen {
private DisassembleData data;
private String name;
private Random random ;
private boolean disassembleFlag = true;
// private boolean disassembleFlag = true;
private Player playerHost;
private GermGuiScreen temporarilyBoxScreen;
private List<GermGuiSlot> guiSlots = new ArrayList<>();
@ -83,9 +83,9 @@ public class SassembleGuiService extends GermGuiScreen {
}
synchronized public void setItemToPauseBox(ItemStack item){
if (!this.disassembleFlag){
return;
}
// if (!this.disassembleFlag){
// return;
// }
for (int i = 0; i <= 15 ; i++){
GermGuiSlot germGuiSlot = guiSlots.get(i);
if (germGuiSlot.getItemStack().getType() == Material.AIR){
@ -107,6 +107,7 @@ public class SassembleGuiService extends GermGuiScreen {
*/
public void saveTemporarilyBox(){
TemporarilyBox.addGuiScreen(playerHost.getName(), "TemporarilyBox",this.temporarilyBoxScreen);
TemporarilyBox.addGuiScreen(playerHost.getName(),"disassemble",this);
}
public void boolGui(){
@ -122,6 +123,7 @@ public class SassembleGuiService extends GermGuiScreen {
GermGuiButton men1 = (GermGuiButton) bgCanvas.getGuiPart("men1");
GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause");
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
GermGuiLabel label = (GermGuiLabel) bgCanvas.getGuiPart("label");
men1.setEnable(false);
fire.setEnable(true);
@ -144,16 +146,25 @@ public class SassembleGuiService extends GermGuiScreen {
}else {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
List<String> texts = new ArrayList<>();
texts.add("#C80800FF距离分解完成");
texts.add("#ACDA70D6还有"+calculateMinutesDifference+"分钟");
label.setTexts(texts);
label.setEnable(true);
executor.scheduleWithFixedDelay(() -> {
int nums = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
String text = "##ACDA70D6还有"+nums+"分钟";
texts.remove(1);
texts.add(text);
label.setTexts(texts);
if (nums <= 0) {
if(!this.disassembleFlag){
executor.shutdown();
return;
}
// if(!this.disassembleFlag){
// executor.shutdown();
// return;
// }
//执行语句说明分解完成
this.disassembleComplete();
@ -167,6 +178,7 @@ public class SassembleGuiService extends GermGuiScreen {
door.setEnable(false);
men1.setEnable(true);
doorPause.setEnable(false);
label.setEnable(false);
this.temporarilyBoxScreen.openChildGui(this.playerHost);
executor.shutdown();
}
@ -278,6 +290,7 @@ public class SassembleGuiService extends GermGuiScreen {
//上方if语句通过表示该物品可以分解
//假如启动按钮是油壶
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause");
door.setCycle(1);
door.setPause(14);
if ((boolean)door.getEnable() == true){
@ -299,21 +312,35 @@ public class SassembleGuiService extends GermGuiScreen {
this.closeTemporaryBox();
GermGuiLabel label = (GermGuiLabel) bgCanvas.getGuiPart("label");
List<String> texts = new ArrayList<>();
texts.add("#C80800FF距离分解完成");
int minTime = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
texts.add("#ACDA70D6还有"+minTime+"分钟");
label.setTexts(texts);
label.setEnable(true);
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.schedule(() -> {
if (!doorPause.isEnable()){
doorPause.setEnable(true);
}
if (door.isEnable()){
door.setEnable(false);
}
},2,TimeUnit.SECONDS);
executor.scheduleWithFixedDelay(() -> {
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
String text = "#ACDA70D6还有"+calculateMinutesDifference+"分钟";
texts.remove(1);
texts.add(text);
label.setTexts(texts);
if (calculateMinutesDifference <= 0) {
//执行语句说明分解完成
label.setEnable(false);
if (!this.disassembleFlag){
//disassembleFlag == false 说明gui已经关闭即已经放弃了,下次打开时会打开新的gui
executor.shutdown();
return;
}
this.disassembleComplete();
if ((boolean)disassembleSlot.getInteract()){
@ -374,7 +401,7 @@ public class SassembleGuiService extends GermGuiScreen {
//遍历gui的所有物品槽并且返回到玩家背包中
synchronized private void returnItemStacks(Player player) {
this.disassembleFlag = false;
// this.disassembleFlag = false;
this.temporarilyBoxScreen.close();
List<GermGuiSlot> allGuiParts = this.getAllGuiParts(GermGuiSlot.class);
for (GermGuiSlot guiPart : allGuiParts) {
@ -392,6 +419,18 @@ public class SassembleGuiService extends GermGuiScreen {
player.sendMessage(ChatColor.GREEN+"暂存箱只能存放RPG物品!");
player.getInventory().addItem(itemStack);
guiPart.setItemStack(null);
continue;
}
String index = srItemHandler.getLore().get(0);
//\\.转义符号
String[] split = index.split("\\.");
String s = split[1];
if (s.equals("equip")){
player.sendMessage(ChatColor.GREEN+"暂存箱只能存放材料和原胚物品!");
player.getInventory().addItem(itemStack);
guiPart.setItemStack(null);
continue;
}
}

View File

@ -6,12 +6,14 @@ import com.germ.germplugin.api.dynamic.gui.GermGuiScroll;
import com.germ.germplugin.api.dynamic.gui.GermGuiSlot;
import com.sakurarealm.sritem.api.ItemStackHelper;
import com.sakurarealm.sritem.api.SrItemAPI;
import com.sakurarealm.sritem.api.SrItemManager;
import com.sakurarealm.sritem.api.builder.SrItemHandler;
import com.yuyu.srdisassemble.data.JdbcSqlClass;
import com.yuyu.srdisassemble.pojo.PauseBox;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.List;
@ -56,6 +58,18 @@ public class TemporarilyBox {
}
/**
* 用于判断当前服务器缓存中是否存在该gui
*/
public static boolean isHasGui(String playname,String guiName) {
if(temporarilyBoxHashMap.containsKey(playname)) {
return temporarilyBoxHashMap.get(playname).containsKey(guiName);
}else {
return false;
}
}
/**
* 用于插件启动时读取玩家的数据库存储
*/
@ -81,10 +95,14 @@ public class TemporarilyBox {
GermGuiSlot germGuiSlot = (GermGuiSlot) scroll.getGuiPart(slot);
ItemStack item = SrItemAPI.getItem(index, new HashMap<>(), null, true, true);
if (item == null){
continue;
}
item.setAmount(nums);
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setLore(p.getLores());
item.setItemMeta(itemMeta);
germGuiSlot.setItemStack(item);
}
@ -109,7 +127,12 @@ public class TemporarilyBox {
SrItemHandler srItemHandler = ItemStackHelper.getSrItemHandler(itemStack);
String index = srItemHandler.getLore().get(0);
index = index.substring(1);
JdbcSqlClass.insertPauseBoxData(username,i,itemStack.getAmount(),index,"TemporarilyBox");
List<String> lore = itemStack.getItemMeta().getLore();
String lores = "";
for (String s : lore){
lores = lores+s+"|";
}
JdbcSqlClass.insertPauseBoxData(username,i,itemStack.getAmount(),index,"TemporarilyBox",lores);
}
}
}

View File

@ -0,0 +1,53 @@
package com.yuyu.srdisassemble.pojo;
import java.util.List;
/**
* @author
* @version 1.0
* @project SrDisassemble113
* @date 2024/7/20 13:21:50
* @description
*/
public class PauseBox {
private String username;
private int slotnumber;
private int nums;
private String productindex;
private String guiname;
private List<String> lores;
public PauseBox(String username, int slotnumber, int nums, String productindex, String guiname, List<String> lores) {
this.username = username;
this.slotnumber = slotnumber;
this.nums = nums;
this.productindex = productindex;
this.guiname = guiname;
this.lores = lores;
}
public List<String> getLores() {
return lores;
}
public String getUsername() {
return username;
}
public int getSlotnumber() {
return slotnumber;
}
public int getNums() {
return nums;
}
public String getProductindex() {
return productindex;
}
public String getGuiname() {
return guiname;
}
}

View File

@ -10,3 +10,11 @@ commands:
description: srdisassemble command
aliases: [ srd ]
permission: srdisassemble.command
srmeltagain:
description: srmeltagain command
aliases: [ srm ]
permission: srmeltagain.command
srrepair:
description: srrepair command
aliases: [ srr ]
permission: srrepair.command