inventory click bug fix
This commit is contained in:
parent
4ee326733c
commit
b5c626cf3e
|
@ -17,6 +17,7 @@ import org.bukkit.event.block.SignChangeEvent;
|
|||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
@ -51,6 +52,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
|
|||
Block clickedBlock;
|
||||
String curCubeName = "";
|
||||
boolean curCubePrivate = false;
|
||||
boolean inCubeTPInventory = false;
|
||||
double curCubeX = 0;
|
||||
double curCubeY = 0;
|
||||
double curCubeZ = 0;
|
||||
|
@ -102,6 +104,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
|
|||
curCubeX = clickedBlock.getLocation().getBlockX();
|
||||
curCubeY = clickedBlock.getLocation().getBlockY();
|
||||
curCubeZ = clickedBlock.getLocation().getBlockZ();
|
||||
inCubeTPInventory = true;
|
||||
ShowUI(player);
|
||||
}
|
||||
if(action == Action.RIGHT_CLICK_BLOCK){
|
||||
|
@ -109,6 +112,7 @@ public final class CubeTP extends JavaPlugin implements Listener {
|
|||
if(mhi.getItemMeta() != null){
|
||||
String mainhand = mhi.getItemMeta().getDisplayName();
|
||||
if(mainhand.equals("Tome de portail")){
|
||||
inCubeTPInventory = true;
|
||||
ShowUIPortal(player);
|
||||
mhi.setAmount(0);
|
||||
}
|
||||
|
@ -119,58 +123,69 @@ public final class CubeTP extends JavaPlugin implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryClickEvent e) throws SQLException {
|
||||
e.setCancelled(true);
|
||||
if (!e.isLeftClick()) return;
|
||||
if(inCubeTPInventory){
|
||||
e.setCancelled(true);
|
||||
if (!e.isLeftClick()) return;
|
||||
|
||||
final ItemStack clickedItem = e.getCurrentItem();
|
||||
final ItemStack clickedItem = e.getCurrentItem();
|
||||
|
||||
// verify current item is not null
|
||||
if (clickedItem == null || clickedItem.getType().isAir()) return;
|
||||
// verify current item is not null
|
||||
if (clickedItem == null || clickedItem.getType().isAir()) return;
|
||||
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
// register the cube
|
||||
if (e.getRawSlot() == 3){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} existe déjà. Changez le nom.", curCubeName));
|
||||
} else {
|
||||
if(curCubePrivate){
|
||||
SQL.AddCube(curCubeName, curCubeX, curCubeY, curCubeZ, p.getUniqueId().toString());
|
||||
// register the cube
|
||||
if (e.getRawSlot() == 3){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} existe déjà. Changez le nom.", curCubeName));
|
||||
} else {
|
||||
SQL.AddCube(curCubeName, curCubeX, curCubeY, curCubeZ, null);
|
||||
if(curCubePrivate){
|
||||
SQL.AddCube(curCubeName, curCubeX, curCubeY, curCubeZ, p.getUniqueId().toString());
|
||||
} else {
|
||||
SQL.AddCube(curCubeName, curCubeX, curCubeY, curCubeZ, null);
|
||||
}
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} a été ajouté.", curCubeName));
|
||||
ShowUI(p);
|
||||
}
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} a été ajouté.", curCubeName));
|
||||
ShowUI(p);
|
||||
inCubeTPInventory = false;
|
||||
}
|
||||
|
||||
// create a tome of portal from a book
|
||||
if (e.getRawSlot() == 4){
|
||||
Inventory pinv = p.getInventory();
|
||||
if(HaveBook(p)){
|
||||
TakeBook(p);
|
||||
pinv.addItem(createGuiItem(Material.ENCHANTED_BOOK, "Tome de portail", "Permets d'aller vers un cube, pas de revenir."));
|
||||
} else {
|
||||
p.sendMessage("§bVous devez posséder un livre pour créer cet objet.");
|
||||
}
|
||||
inCubeTPInventory = false;
|
||||
}
|
||||
|
||||
// unregister a cube
|
||||
if (e.getRawSlot() == 5){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
SQL.DeleteCubeByName(curCubeName);
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} a été supprimé.", curCubeName));
|
||||
ShowUI(p);
|
||||
} else {
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} n'existe pas.", curCubeName));
|
||||
}
|
||||
inCubeTPInventory = false;
|
||||
}
|
||||
|
||||
// tp to a remote cube
|
||||
if (e.getRawSlot() >= 9){
|
||||
String name = e.getCurrentItem().getItemMeta().getDisplayName();
|
||||
CubeTP(p,name);
|
||||
inCubeTPInventory = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create a tome of portal from a book
|
||||
if (e.getRawSlot() == 4){
|
||||
Inventory pinv = p.getInventory();
|
||||
if(HaveBook(p)){
|
||||
TakeBook(p);
|
||||
pinv.addItem(createGuiItem(Material.ENCHANTED_BOOK, "Tome de portail", "Permets d'aller vers un cube, pas de revenir."));
|
||||
} else {
|
||||
p.sendMessage("§bVous devez posséder un livre pour créer cet objet.");
|
||||
}
|
||||
}
|
||||
|
||||
// unregister a cube
|
||||
if (e.getRawSlot() == 5){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
SQL.DeleteCubeByName(curCubeName);
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} a été supprimé.", curCubeName));
|
||||
ShowUI(p);
|
||||
} else {
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} n'existe pas.", curCubeName));
|
||||
}
|
||||
}
|
||||
|
||||
// tp to a remote cube
|
||||
if (e.getRawSlot() >= 9){
|
||||
String name = e.getCurrentItem().getItemMeta().getDisplayName();
|
||||
CubeTP(p,name);
|
||||
}
|
||||
@EventHandler
|
||||
public void InventoryCloseEvent(final InventoryCloseEvent e) throws SQLException {
|
||||
inCubeTPInventory = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
name: CubeTP
|
||||
version: '1.2.0'
|
||||
version: '1.2.1'
|
||||
main: ovh.mxg.cubetp.CubeTP
|
||||
api-version: '1.20'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
name: CubeTP
|
||||
version: '1.2.0'
|
||||
version: '1.2.1'
|
||||
main: ovh.mxg.cubetp.CubeTP
|
||||
api-version: '1.20'
|
||||
|
|
Loading…
Reference in New Issue