mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-10 10:27:44 +01:00
Fixed Double Chest opening sound on Paper
This commit is contained in:
parent
6b0f37de2c
commit
f931845ca5
@ -139,6 +139,7 @@ public class ChestsPlusPlus extends JavaPlugin {
|
|||||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new HopperListener(), this);
|
getServer().getPluginManager().registerEvents(new HopperListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
||||||
|
Config.getStorageTypes().forEach(storageType -> getServer().getPluginManager().registerEvents(storageType, this));
|
||||||
getLogger().info("Chests++ enabled!");
|
getLogger().info("Chests++ enabled!");
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,19 @@ import com.jamesdpeters.minecraft.chests.sort.InventorySorter;
|
|||||||
import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
|
import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.event.inventory.InventoryInteractEvent;
|
import org.bukkit.event.inventory.InventoryInteractEvent;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -32,38 +35,6 @@ public class InventoryListener implements Listener {
|
|||||||
inventoryUpdate(event);
|
inventoryUpdate(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
|
||||||
try {
|
|
||||||
if (event.getPlayer() instanceof Player) {
|
|
||||||
if (event.getInventory().getLocation() != null) {
|
|
||||||
ChestLinkStorage storage = Config.getChestLink().getStorage(event.getInventory().getLocation());
|
|
||||||
if (storage != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (event.getPlayer().hasPermission(Permissions.OPEN) && storage.hasPermission((Player) event.getPlayer())) {
|
|
||||||
storage.getInventory().getViewers().remove(event.getPlayer());
|
|
||||||
Utils.openChestInventory((Player) event.getPlayer(), storage, storage.getLocationInfo(event.getInventory().getLocation()));
|
|
||||||
} else {
|
|
||||||
Messages.NO_PERMISSION((Player) event.getPlayer());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//If no Inventory Storage here check for AutoCraft
|
|
||||||
AutoCraftingStorage craftingStorage = Config.getAutoCraft().getStorage(event.getInventory().getLocation());
|
|
||||||
|
|
||||||
if (craftingStorage != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (event.getPlayer().hasPermission(Permissions.AUTOCRAFT_OPEN) && craftingStorage.hasPermission((Player) event.getPlayer())) {
|
|
||||||
event.getPlayer().openInventory(craftingStorage.getInventory());
|
|
||||||
craftingStorage.getVirtualCraftingHolder().startAnimation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignore) {
|
|
||||||
} //Essentials does something weird with enderchests - shit fix but works :)
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClose(InventoryCloseEvent event) {
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
try {
|
try {
|
||||||
@ -103,7 +74,6 @@ public class InventoryListener implements Listener {
|
|||||||
craftingUpdate(event);
|
craftingUpdate(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//CRAFTING
|
//CRAFTING
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void inventoryDragEvent(InventoryDragEvent event) {
|
public void inventoryDragEvent(InventoryDragEvent event) {
|
||||||
|
@ -160,7 +160,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract StorageType getStorageType();
|
public abstract StorageType<?> getStorageType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if this storage should store the inventory to disk.
|
* @return true if this storage should store the inventory to disk.
|
||||||
@ -502,7 +502,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
|
|||||||
else removeArmorStandItem(location.getToolItemStand());
|
else removeArmorStandItem(location.getToolItemStand());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// anchor.getState().update();
|
anchor.getState().update();
|
||||||
removeArmorStandItem(location.getToolItemStand());
|
removeArmorStandItem(location.getToolItemStand());
|
||||||
removeArmorStandItem(location.getItemStand());
|
removeArmorStandItem(location.getItemStand());
|
||||||
removeArmorStandItem(location.getBlockStand());
|
removeArmorStandItem(location.getBlockStand());
|
||||||
|
@ -23,8 +23,12 @@ import org.bukkit.block.BlockState;
|
|||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
@ -37,7 +41,7 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class StorageType<T extends AbstractStorage> {
|
public abstract class StorageType<T extends AbstractStorage> implements Listener {
|
||||||
|
|
||||||
private final ConfigStorage store;
|
private final ConfigStorage store;
|
||||||
private final StorageUtils<StorageInfo<T>, T> storageUtils;
|
private final StorageUtils<StorageInfo<T>, T> storageUtils;
|
||||||
@ -119,6 +123,15 @@ public abstract class StorageType<T extends AbstractStorage> {
|
|||||||
|
|
||||||
public abstract StorageMessages getMessages();
|
public abstract StorageMessages getMessages();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerInteractEvent(PlayerInteractEvent event){
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getPlayer().isSneaking()) {
|
||||||
|
onBlockRightClick(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onBlockRightClick(PlayerInteractEvent event);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
STORAGE MAP SECTION
|
STORAGE MAP SECTION
|
||||||
*/
|
*/
|
||||||
@ -160,7 +173,9 @@ public abstract class StorageType<T extends AbstractStorage> {
|
|||||||
if (isValidBlockType(block)) {
|
if (isValidBlockType(block)) {
|
||||||
StorageInfo<T> storageInfo = storageUtils.getStorageInfo(location);
|
StorageInfo<T> storageInfo = storageUtils.getStorageInfo(location);
|
||||||
if (storageInfo != null) {
|
if (storageInfo != null) {
|
||||||
return storageInfo.getStorage(location);
|
storage = storageInfo.getStorage(location);
|
||||||
|
storageCache.put(location, storage);
|
||||||
|
return storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
|
|||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageInfo;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageInfo;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
||||||
|
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -18,6 +19,8 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -116,6 +119,22 @@ public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockRightClick(PlayerInteractEvent event) {
|
||||||
|
// AutoCraft Check
|
||||||
|
if (event.getClickedBlock() != null && isValidBlockType(event.getClickedBlock())) {
|
||||||
|
Location location = event.getClickedBlock().getLocation();
|
||||||
|
AutoCraftingStorage storage = getStorage(location);
|
||||||
|
if (storage != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (event.getPlayer().hasPermission(Permissions.AUTOCRAFT_OPEN) && storage.hasPermission(event.getPlayer())) {
|
||||||
|
event.getPlayer().openInventory(storage.getInventory());
|
||||||
|
storage.getVirtualCraftingHolder().startAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final AutoCraftMessages messages = new AutoCraftMessages();
|
private static final AutoCraftMessages messages = new AutoCraftMessages();
|
||||||
|
|
||||||
private static class AutoCraftMessages extends StorageMessages {
|
private static class AutoCraftMessages extends StorageMessages {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.jamesdpeters.minecraft.chests.storage.chestlink;
|
package com.jamesdpeters.minecraft.chests.storage.chestlink;
|
||||||
|
|
||||||
import com.jamesdpeters.minecraft.chests.lang.Message;
|
import com.jamesdpeters.minecraft.chests.lang.Message;
|
||||||
|
import com.jamesdpeters.minecraft.chests.misc.Messages;
|
||||||
import com.jamesdpeters.minecraft.chests.misc.Permissions;
|
import com.jamesdpeters.minecraft.chests.misc.Permissions;
|
||||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||||
import com.jamesdpeters.minecraft.chests.misc.Values;
|
import com.jamesdpeters.minecraft.chests.misc.Values;
|
||||||
@ -9,6 +10,7 @@ import com.jamesdpeters.minecraft.chests.serialize.Config;
|
|||||||
import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
|
import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -19,6 +21,8 @@ import org.bukkit.block.Chest;
|
|||||||
import org.bukkit.block.Container;
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -118,6 +122,24 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockRightClick(PlayerInteractEvent event) {
|
||||||
|
// ChestLink Check
|
||||||
|
if (event.getClickedBlock() != null && isValidBlockType(event.getClickedBlock())) {
|
||||||
|
Location location = event.getClickedBlock().getLocation();
|
||||||
|
ChestLinkStorage storage = getStorage(location);
|
||||||
|
if (storage != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (event.getPlayer().hasPermission(Permissions.OPEN) && storage.hasPermission(event.getPlayer())) {
|
||||||
|
storage.getInventory().getViewers().remove(event.getPlayer());
|
||||||
|
Utils.openChestInventory(event.getPlayer(), storage, storage.getLocationInfo(location));
|
||||||
|
} else {
|
||||||
|
Messages.NO_PERMISSION(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final ChestLinkMessages messages = new ChestLinkMessages();
|
private static final ChestLinkMessages messages = new ChestLinkMessages();
|
||||||
|
|
||||||
private static class ChestLinkMessages extends StorageMessages {
|
private static class ChestLinkMessages extends StorageMessages {
|
||||||
|
Loading…
Reference in New Issue
Block a user