优化gui
This commit is contained in:
parent
057b9e834d
commit
d591378938
@ -44,6 +44,11 @@ public class JdbcSqlClass {
|
|||||||
//注册驱动
|
//注册驱动
|
||||||
Class.forName(JdbcSqlClass.driver);
|
Class.forName(JdbcSqlClass.driver);
|
||||||
|
|
||||||
|
//判断是否因为长时间闲置导致连接丢失
|
||||||
|
if (con.isClosed()){
|
||||||
|
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||||
|
}
|
||||||
|
|
||||||
//获取执行者对象
|
//获取执行者对象
|
||||||
Statement stmt = con.createStatement();
|
Statement stmt = con.createStatement();
|
||||||
|
|
||||||
@ -56,6 +61,7 @@ public class JdbcSqlClass {
|
|||||||
|
|
||||||
public static void initTable() {
|
public static void initTable() {
|
||||||
try {
|
try {
|
||||||
|
//此处获取连接并保存
|
||||||
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
con = DriverManager.getConnection(JdbcSqlClass.url, JdbcSqlClass.user, JdbcSqlClass.password);
|
||||||
|
|
||||||
Statement connection = getConnection();
|
Statement connection = getConnection();
|
||||||
|
@ -11,6 +11,7 @@ import com.yuyu.srdisassemble.pojo.CanDisItem;
|
|||||||
import com.yuyu.srdisassemble.pojo.DisProduct;
|
import com.yuyu.srdisassemble.pojo.DisProduct;
|
||||||
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
import com.yuyu.srdisassemble.pojo.DisassembleData;
|
||||||
import com.yuyu.srdisassemble.utils.MinUtil;
|
import com.yuyu.srdisassemble.utils.MinUtil;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -61,7 +62,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void savePauseSlots(){
|
private void savePauseSlots(){
|
||||||
GermGuiScroll scroll = (GermGuiScroll) this.temporarilyBoxScreen.getGuiPart("scroll");
|
GermGuiCanvas canvas = (GermGuiCanvas) this.temporarilyBoxScreen.getGuiPart("canvas");
|
||||||
|
GermGuiScroll scroll = (GermGuiScroll) canvas.getGuiPart("scroll");
|
||||||
for (int i = 1; i <= 16 ; i++){
|
for (int i = 1; i <= 16 ; i++){
|
||||||
String slotName = "slot_"+i;
|
String slotName = "slot_"+i;
|
||||||
GermGuiSlot slot = (GermGuiSlot) scroll.getGuiPart(slotName);
|
GermGuiSlot slot = (GermGuiSlot) scroll.getGuiPart(slotName);
|
||||||
@ -86,13 +88,6 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
if (germGuiSlot.getItemStack().getType() == Material.AIR){
|
if (germGuiSlot.getItemStack().getType() == Material.AIR){
|
||||||
germGuiSlot.setItemStack(item);
|
germGuiSlot.setItemStack(item);
|
||||||
return;
|
return;
|
||||||
}else {
|
|
||||||
ItemStack itemStack = germGuiSlot.getItemStack();
|
|
||||||
if (itemStack.getAmount() < itemStack.getMaxStackSize() && itemStack.getItemMeta().getDisplayName().equals(item.getItemMeta().getDisplayName())){
|
|
||||||
itemStack.setAmount(itemStack.getAmount()+1);
|
|
||||||
germGuiSlot.setItemStack(itemStack);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,16 +108,17 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
|
|
||||||
public void boolGui(){
|
public void boolGui(){
|
||||||
if (data.getId() != 0 && data.getTargetIndex() != null) {
|
if (data.getId() != 0 && data.getTargetIndex() != null) {
|
||||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||||
|
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||||
disassembleSlot.setInteract(false);
|
disassembleSlot.setInteract(false);
|
||||||
//此处为获取分解的物品的item
|
//此处为获取分解的物品的item
|
||||||
disassembleSlot.setItemStack(SrItemAPI.getItem(data.getTargetIndex(),
|
disassembleSlot.setItemStack(SrItemAPI.getItem(data.getTargetIndex(),
|
||||||
new HashMap<>(),null,true,true));
|
new HashMap<>(),null,true,true));
|
||||||
|
|
||||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
GermGuiGif fire = (GermGuiGif) bgCanvas.getGuiPart("fire");
|
||||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
GermGuiTexture men1 = (GermGuiTexture) bgCanvas.getGuiPart("men1");
|
||||||
GermGuiTexture doorPause = (GermGuiTexture) this.getGuiPart("doorPause");
|
GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause");
|
||||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
|
||||||
|
|
||||||
men1.setEnable(false);
|
men1.setEnable(false);
|
||||||
fire.setEnable(true);
|
fire.setEnable(true);
|
||||||
@ -135,7 +131,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
if (calculateMinutesDifference <= 0) {
|
if (calculateMinutesDifference <= 0) {
|
||||||
//执行语句说明分解完成
|
//执行语句说明分解完成
|
||||||
this.disassembleComplete();
|
this.disassembleComplete();
|
||||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
if ((boolean)disassembleSlot.getInteract()){
|
||||||
|
|
||||||
JdbcSqlClass.deleteData(data.getId());
|
JdbcSqlClass.deleteData(data.getId());
|
||||||
|
|
||||||
//赋予产物后把火关掉,门打开
|
//赋予产物后把火关掉,门打开
|
||||||
@ -169,7 +166,8 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
|
|
||||||
|
|
||||||
public void openPauseBox(){
|
public void openPauseBox(){
|
||||||
GermGuiButton germGuiButton = (GermGuiButton)this.getGuiPart("pauseBoxButton");
|
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||||
|
GermGuiButton germGuiButton = (GermGuiButton)bgCanvas.getGuiPart("pauseBoxButton");
|
||||||
germGuiButton.registerCallbackHandler(((player, btn) -> {
|
germGuiButton.registerCallbackHandler(((player, btn) -> {
|
||||||
|
|
||||||
if (this.temporarilyBoxScreen.isOpened()){
|
if (this.temporarilyBoxScreen.isOpened()){
|
||||||
@ -186,40 +184,42 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
*/
|
*/
|
||||||
public void registerDisassemble() {
|
public void registerDisassemble() {
|
||||||
//获取画布
|
//获取画布
|
||||||
GermGuiCanvas canvas = (GermGuiCanvas)this.getGuiPart("canvas");
|
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||||
|
GermGuiCanvas cCanvas = (GermGuiCanvas) this.getGuiPart("confirmCanvas");
|
||||||
//通过画布获取按键
|
//通过画布获取按键
|
||||||
GermGuiButton confirmButton = (GermGuiButton) canvas.getGuiPart("confirmButton");
|
GermGuiButton confirmButton = (GermGuiButton) cCanvas.getGuiPart("confirmButton");
|
||||||
GermGuiButton cancleButton = (GermGuiButton) canvas.getGuiPart("cancleButton");
|
GermGuiButton cancleButton = (GermGuiButton) cCanvas.getGuiPart("cancleButton");
|
||||||
GermGuiButton germGuiButton =(GermGuiButton) this.getGuiPart("youhu");
|
GermGuiButton germGuiButton =(GermGuiButton) bgCanvas.getGuiPart("youhu");
|
||||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||||
|
|
||||||
confirmButton.registerCallbackHandler((player, btn) -> {
|
confirmButton.registerCallbackHandler((player, btn) -> {
|
||||||
this.disassemble(player);
|
this.disassemble(player);
|
||||||
canvas.setEnable(false);
|
cCanvas.setEnable(false);
|
||||||
},GermGuiButton.EventType.LEFT_CLICK);
|
},GermGuiButton.EventType.LEFT_CLICK);
|
||||||
|
|
||||||
//取消事件
|
//取消事件
|
||||||
cancleButton.registerCallbackHandler((player, btn) -> {
|
cancleButton.registerCallbackHandler((player, btn) -> {
|
||||||
//取消事件,关闭画布gui
|
//取消事件,关闭画布gui
|
||||||
canvas.setEnable(false);
|
cCanvas.setEnable(false);
|
||||||
},GermGuiButton.EventType.LEFT_CLICK);
|
},GermGuiButton.EventType.LEFT_CLICK);
|
||||||
|
|
||||||
//油壶按钮绑定的事件触发画布显示
|
//油壶按钮绑定的事件触发画布显示
|
||||||
germGuiButton.registerCallbackHandler((player, btn) -> {
|
germGuiButton.registerCallbackHandler((player, btn) -> {
|
||||||
if ((boolean)disassembleSlot.getInteract()) {
|
if ((boolean)disassembleSlot.getInteract()) {
|
||||||
canvas.setEnable(true);
|
cCanvas.setEnable(true);
|
||||||
}
|
}
|
||||||
},GermGuiButton.EventType.LEFT_CLICK);
|
},GermGuiButton.EventType.LEFT_CLICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disassemble(Player player){
|
public void disassemble(Player player){
|
||||||
|
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||||
if ((boolean)disassembleSlot.getInteract() == false){
|
if ((boolean)disassembleSlot.getInteract() == false){
|
||||||
//正在分解某种物品
|
//正在分解某种物品
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||||
|
|
||||||
if (itemStack.getType() == Material.AIR || itemStack == null) {
|
if (itemStack.getType() == Material.AIR || itemStack == null) {
|
||||||
player.sendMessage(Color.RED+"在熔炉物品框中放上可分解的物品!");
|
player.sendMessage(Color.RED+"在熔炉物品框中放上可分解的物品!");
|
||||||
return;
|
return;
|
||||||
@ -235,16 +235,29 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
disassembleSlot.setInteract(false);//关闭交互
|
disassembleSlot.setInteract(false);//关闭交互
|
||||||
|
|
||||||
|
int amount = itemStack.getAmount();
|
||||||
|
if (amount > 1){
|
||||||
|
ItemStack itemStack1 = itemStack.clone();
|
||||||
|
itemStack1.setAmount(amount - 1);
|
||||||
|
player.getInventory().addItem(itemStack1);
|
||||||
|
player.sendMessage(ChatColor.GREEN+"多余的物品放进背包!");
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStack.setAmount(1);
|
||||||
|
|
||||||
|
disassembleSlot.setItemStack(itemStack);
|
||||||
//上方if语句通过表示该物品可以分解
|
//上方if语句通过表示该物品可以分解
|
||||||
//假如启动按钮是油壶,
|
//假如启动按钮是油壶,
|
||||||
GermGuiGif door = (GermGuiGif) this.getGuiPart("door");
|
GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door");
|
||||||
door.setCycle(1);
|
door.setCycle(1);
|
||||||
|
door.setPause(14);
|
||||||
if ((boolean)door.getEnable() == true){
|
if ((boolean)door.getEnable() == true){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GermGuiTexture men1 = (GermGuiTexture) this.getGuiPart("men1");
|
GermGuiTexture men1 = (GermGuiTexture) bgCanvas.getGuiPart("men1");
|
||||||
men1.setEnable(false);
|
men1.setEnable(false);
|
||||||
GermGuiGif fire = (GermGuiGif) this.getGuiPart("fire");
|
GermGuiGif fire = (GermGuiGif) bgCanvas.getGuiPart("fire");
|
||||||
fire.setEnable(true);
|
fire.setEnable(true);
|
||||||
door.setEnable(true);
|
door.setEnable(true);
|
||||||
this.data = new DisassembleData(player.getName(),
|
this.data = new DisassembleData(player.getName(),
|
||||||
@ -262,18 +275,14 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
|
|
||||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
// executor.schedule(() ->{
|
|
||||||
// //打开暂存箱
|
|
||||||
// temporarilyBoxScreen.openChildGui(playerHost);
|
|
||||||
//
|
|
||||||
// },1,TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
executor.scheduleAtFixedRate(() -> {
|
executor.scheduleAtFixedRate(() -> {
|
||||||
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime());
|
||||||
if (calculateMinutesDifference <= 0) {
|
if (calculateMinutesDifference <= 0) {
|
||||||
//执行语句说明分解完成
|
//执行语句说明分解完成
|
||||||
this.disassembleComplete();
|
this.disassembleComplete();
|
||||||
if ((boolean)disassembleSlot.getInteract() == true && disassemble){
|
if ((boolean)disassembleSlot.getInteract()){
|
||||||
|
|
||||||
JdbcSqlClass.deleteData(data.getId());
|
JdbcSqlClass.deleteData(data.getId());
|
||||||
|
|
||||||
//赋予产物后把火关掉,门打开
|
//赋予产物后把火关掉,门打开
|
||||||
@ -290,30 +299,14 @@ public class SassembleGuiService extends GermGuiScreen {
|
|||||||
//1分钟延迟,minTime分钟后执行
|
//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(){
|
public void disassembleComplete(){
|
||||||
GermGuiSlot disassembleSlot = (GermGuiSlot) this.getGuiPart("disassembleSlot");
|
GermGuiCanvas bgCanvas = (GermGuiCanvas) this.getGuiPart("background");
|
||||||
|
GermGuiSlot disassembleSlot = (GermGuiSlot) bgCanvas.getGuiPart("disassembleSlot");
|
||||||
ItemStack itemStack = disassembleSlot.getItemStack();
|
ItemStack itemStack = disassembleSlot.getItemStack();
|
||||||
//此处写分解逻辑
|
//此处写分解逻辑
|
||||||
int itemAmount = itemStack.getAmount();
|
int itemAmount = itemStack.getAmount();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user