fix: remove unused InventoryUtils class and related event registration
This commit is contained in:
@@ -597,7 +597,6 @@ public class App extends JavaPlugin {
|
||||
pM.registerEvents(new LoginListener(), this);
|
||||
pM.registerEvents(new EnvironmentExListeners(), this);
|
||||
pM.registerEvents(new InvisibleFrame(), this);
|
||||
pM.registerEvents(new BookshelfListeners(), this);
|
||||
pM.registerEvents(new HealthBarListener(), this);
|
||||
pM.registerEvents(new DoubleDoorListener(), this);
|
||||
pM.registerEvents(new ExpBottleListener(), this);
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
package de.hessj.environmentex;
|
||||
import org.bukkit.event.Listener;
|
||||
/*
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import net.kyori.adventure.text.Component;
|
||||
*/
|
||||
public class BookshelfListeners implements Listener {
|
||||
/*
|
||||
public Inventory inv;
|
||||
public static HashMap<Player, Block> hm = new HashMap<Player, Block>();
|
||||
public de.hessj.helper.Helper helper= new de.hessj.helper.Helper();
|
||||
@EventHandler
|
||||
public void onBookshelfClick(PlayerInteractEvent e) throws IllegalArgumentException, IOException {
|
||||
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (e.getClickedBlock().getType().equals(Material.BOOKSHELF) && !e.getPlayer().isSneaking()) {
|
||||
hm.put(e.getPlayer(), e.getClickedBlock());
|
||||
inv = Bukkit.createInventory(null, 18, Component.translatable("Bücherregal"));
|
||||
e.getPlayer().openInventory(inv);
|
||||
e.setCancelled(true);
|
||||
if (e.getPlayer().getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
if (App.main.getConfig()
|
||||
.contains("bookshelfs." + ((hm.get(e.getPlayer())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockZ()))) {
|
||||
inv.setContents(EnvironmentExListeners.itemStackArrayFromBase64(App.main.getConfig()
|
||||
.getString("bookshelfs." + ((hm.get(e.getPlayer())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockZ()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBookshelfClose(InventoryCloseEvent e) {
|
||||
if (e.getInventory() == inv && inv != null) {
|
||||
App.main.getConfig()
|
||||
.set("bookshelfs." + ((hm.get(e.getPlayer())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockZ()),
|
||||
EnvironmentExListeners.itemStackArrayToBase64(e.getInventory().getContents()));
|
||||
App.main.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBookshelfDestroy(BlockBreakEvent e) throws IOException {
|
||||
try {
|
||||
if (e.getBlock().getType().equals(Material.BOOKSHELF)) {
|
||||
if (App.main.getConfig().contains("bookshelfs." + (e.getBlock().getLocation().getBlockX()) + "~"
|
||||
+ (e.getBlock().getLocation().getBlockY()) + "~" + (e.getBlock().getLocation().getBlockZ()))) {
|
||||
ItemStack[] is = EnvironmentExListeners.itemStackArrayFromBase64(App.main.getConfig()
|
||||
.getString("bookshelfs." + ((hm.get(e.getPlayer())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getPlayer())).getLocation().getBlockZ())));
|
||||
|
||||
for (ItemStack iss : is) {
|
||||
if (iss != null) {
|
||||
Bukkit.getWorlds().get(0).dropItem(e.getBlock().getLocation(), iss);
|
||||
}
|
||||
}
|
||||
App.main.getConfig().set("bookshelfs." + (e.getBlock().getLocation().getBlockX()) + "~"
|
||||
+ (e.getBlock().getLocation().getBlockY()) + "~" + (e.getBlock().getLocation().getBlockZ()),
|
||||
null);
|
||||
App.main.saveConfig();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvMove(InventoryDragEvent e) {
|
||||
if (e.getInventory() != null && e.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (e.getWhoClicked().getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
|
||||
for (Object s : e.getRawSlots()) {
|
||||
if ((int) s > e.getWhoClicked().getOpenInventory().getTopInventory().getSize()) {
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getOldCursor() != null) {
|
||||
if (!e.getOldCursor().getType().equals(Material.BOOK)
|
||||
&& !e.getOldCursor().getType().equals(Material.WRITABLE_BOOK)
|
||||
&& !e.getOldCursor().getType().equals(Material.WRITTEN_BOOK)
|
||||
&& !e.getOldCursor().getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvMove(InventoryClickEvent e) {
|
||||
if (e.getClickedInventory() != null) {
|
||||
if (e.getWhoClicked().getOpenInventory().title().equals(Component.translatable("Bücherregal"))
|
||||
&& e.getRawSlot() < e.getWhoClicked().getOpenInventory().getTopInventory().getSize()) {
|
||||
if (e.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD
|
||||
|| e.getAction() == InventoryAction.HOTBAR_SWAP) {
|
||||
ItemStack itm = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
|
||||
if (itm != null) {
|
||||
if (!itm.getType().equals(Material.BOOK) && !itm.getType().equals(Material.WRITABLE_BOOK)
|
||||
&& !itm.getType().equals(Material.WRITTEN_BOOK)
|
||||
&& !itm.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getAction() == InventoryAction.PLACE_ALL || e.getAction() == InventoryAction.PLACE_ONE
|
||||
|| e.getAction() == InventoryAction.PLACE_SOME) {
|
||||
if (e.getCursor() != null) {
|
||||
if (!e.getCursor().getType().equals(Material.BOOK)
|
||||
&& !e.getCursor().getType().equals(Material.WRITABLE_BOOK)
|
||||
&& !e.getCursor().getType().equals(Material.WRITTEN_BOOK)
|
||||
&& !e.getCursor().getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (e.isShiftClick() && e.getClickedInventory() != null && e.getClickedInventory() instanceof PlayerInventory && e.getWhoClicked().getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
if (e.getClickedInventory() != null && e.getClickedInventory().getItem(e.getSlot()) != null
|
||||
&& (e.getClickedInventory().getItem(e.getSlot()).getType().equals(Material.BOOK)
|
||||
|| e.getClickedInventory().getItem(e.getSlot()).getType().equals(Material.WRITABLE_BOOK)
|
||||
|| e.getClickedInventory().getItem(e.getSlot()).getType().equals(Material.WRITTEN_BOOK)
|
||||
|| e.getClickedInventory().getItem(e.getSlot()).getType()
|
||||
.equals(Material.ENCHANTED_BOOK))) {
|
||||
} else if (e.getClickedInventory() != null && e.getClickedInventory().getItem(e.getSlot()) == null
|
||||
&& e.getCursor() != null
|
||||
&& (e.getCursor().getType().equals(Material.BOOK)
|
||||
|| e.getCursor().getType().equals(Material.WRITABLE_BOOK)
|
||||
|| e.getCursor().getType().equals(Material.WRITTEN_BOOK)
|
||||
|| e.getCursor().getType().equals(Material.ENCHANTED_BOOK))) {
|
||||
|
||||
} else if (e.getClickedInventory() == null) {
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
App.main.getConfig()
|
||||
.set("bookshelfs." + ((hm.get(e.getWhoClicked())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getWhoClicked())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getWhoClicked())).getLocation().getBlockZ()),
|
||||
EnvironmentExListeners.itemStackArrayToBase64(e.getInventory().getContents()));
|
||||
App.main.saveConfig();
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (p.getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
try {
|
||||
inv = Bukkit.createInventory(null, 18, Component.translatable("Bücherregal"));
|
||||
inv.setContents(EnvironmentExListeners.itemStackArrayFromBase64(App.main.getConfig()
|
||||
.getString("bookshelfs." + ((hm.get(p)).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(p)).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(p)).getLocation().getBlockZ()))));
|
||||
p.getOpenInventory().getTopInventory().setContents(inv.getContents());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskLaterAsynchronously(App.main, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvDrag(InventoryDragEvent e) {
|
||||
if (e.getWhoClicked().getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
App.main.getConfig()
|
||||
.set("bookshelfs." + ((hm.get(e.getWhoClicked())).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(e.getWhoClicked())).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(e.getWhoClicked())).getLocation().getBlockZ()),
|
||||
EnvironmentExListeners.itemStackArrayToBase64(e.getInventory().getContents()));
|
||||
App.main.saveConfig();
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (p.getOpenInventory().title().equals(Component.translatable("Bücherregal"))) {
|
||||
try {
|
||||
inv = Bukkit.createInventory(null, 18, Component.translatable("Bücherregal"));
|
||||
inv.setContents(EnvironmentExListeners.itemStackArrayFromBase64(App.main.getConfig()
|
||||
.getString("bookshelfs." + ((hm.get(p)).getLocation().getBlockX()) + "~"
|
||||
+ ((hm.get(p)).getLocation().getBlockY()) + "~"
|
||||
+ ((hm.get(p)).getLocation().getBlockZ()))));
|
||||
p.getOpenInventory().getTopInventory().setContents(inv.getContents());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskLaterAsynchronously(App.main, 1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*package de.hessj.environmentex;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class InventoryUtils {
|
||||
|
||||
public static String serializeItem(ItemStack item){
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
// dataOutput.writeInt(1);
|
||||
dataOutput.writeObject(item);
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error occured while serializing item");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack deserializeItem(String string){
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(string));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
ItemStack item = (ItemStack)dataInput.readObject();
|
||||
if(item != null){
|
||||
return item;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error occured while deserializing item");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
Reference in New Issue
Block a user