inventory click bug fix

This commit is contained in:
mikx 2023-11-27 18:45:18 -05:00
parent 4ee326733c
commit b5c626cf3e
3 changed files with 60 additions and 45 deletions

View File

@ -17,6 +17,7 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
@ -51,6 +52,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
Block clickedBlock; Block clickedBlock;
String curCubeName = ""; String curCubeName = "";
boolean curCubePrivate = false; boolean curCubePrivate = false;
boolean inCubeTPInventory = false;
double curCubeX = 0; double curCubeX = 0;
double curCubeY = 0; double curCubeY = 0;
double curCubeZ = 0; double curCubeZ = 0;
@ -102,6 +104,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
curCubeX = clickedBlock.getLocation().getBlockX(); curCubeX = clickedBlock.getLocation().getBlockX();
curCubeY = clickedBlock.getLocation().getBlockY(); curCubeY = clickedBlock.getLocation().getBlockY();
curCubeZ = clickedBlock.getLocation().getBlockZ(); curCubeZ = clickedBlock.getLocation().getBlockZ();
inCubeTPInventory = true;
ShowUI(player); ShowUI(player);
} }
if(action == Action.RIGHT_CLICK_BLOCK){ if(action == Action.RIGHT_CLICK_BLOCK){
@ -109,6 +112,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
if(mhi.getItemMeta() != null){ if(mhi.getItemMeta() != null){
String mainhand = mhi.getItemMeta().getDisplayName(); String mainhand = mhi.getItemMeta().getDisplayName();
if(mainhand.equals("Tome de portail")){ if(mainhand.equals("Tome de portail")){
inCubeTPInventory = true;
ShowUIPortal(player); ShowUIPortal(player);
mhi.setAmount(0); mhi.setAmount(0);
} }
@ -119,6 +123,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
@EventHandler @EventHandler
public void onInventoryClick(final InventoryClickEvent e) throws SQLException { public void onInventoryClick(final InventoryClickEvent e) throws SQLException {
if(inCubeTPInventory){
e.setCancelled(true); e.setCancelled(true);
if (!e.isLeftClick()) return; if (!e.isLeftClick()) return;
@ -142,6 +147,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
p.sendMessage(MessageFormat.format("§bLe cube {0} a été ajouté.", curCubeName)); p.sendMessage(MessageFormat.format("§bLe cube {0} a été ajouté.", curCubeName));
ShowUI(p); ShowUI(p);
} }
inCubeTPInventory = false;
} }
// create a tome of portal from a book // create a tome of portal from a book
@ -153,6 +159,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
} else { } else {
p.sendMessage("§bVous devez posséder un livre pour créer cet objet."); p.sendMessage("§bVous devez posséder un livre pour créer cet objet.");
} }
inCubeTPInventory = false;
} }
// unregister a cube // unregister a cube
@ -164,14 +171,22 @@ public final class CubeTP extends JavaPlugin implements Listener {
} else { } else {
p.sendMessage(MessageFormat.format("§bLe cube {0} n'existe pas.", curCubeName)); p.sendMessage(MessageFormat.format("§bLe cube {0} n'existe pas.", curCubeName));
} }
inCubeTPInventory = false;
} }
// tp to a remote cube // tp to a remote cube
if (e.getRawSlot() >= 9){ if (e.getRawSlot() >= 9){
String name = e.getCurrentItem().getItemMeta().getDisplayName(); String name = e.getCurrentItem().getItemMeta().getDisplayName();
CubeTP(p,name); CubeTP(p,name);
inCubeTPInventory = false;
} }
} }
}
@EventHandler
public void InventoryCloseEvent(final InventoryCloseEvent e) throws SQLException {
inCubeTPInventory = false;
}
@EventHandler @EventHandler
public void onBlockBreakWithSignOnIt(BlockBreakEvent event){ public void onBlockBreakWithSignOnIt(BlockBreakEvent event){

View File

@ -1,4 +1,4 @@
name: CubeTP name: CubeTP
version: '1.2.0' version: '1.2.1'
main: ovh.mxg.cubetp.CubeTP main: ovh.mxg.cubetp.CubeTP
api-version: '1.20' api-version: '1.20'

View File

@ -1,4 +1,4 @@
name: CubeTP name: CubeTP
version: '1.2.0' version: '1.2.1'
main: ovh.mxg.cubetp.CubeTP main: ovh.mxg.cubetp.CubeTP
api-version: '1.20' api-version: '1.20'