Skip to content

Commit

Permalink
Removed unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Aug 4, 2022
1 parent fc46e08 commit 606a52f
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 403 deletions.
8 changes: 0 additions & 8 deletions src/main/java/com/bgsoftware/wildchests/nms/NMSAdapter.java
Expand Up @@ -14,10 +14,6 @@

public interface NMSAdapter {

int getHopperTransfer(World world);

int getHopperAmount(World world);

String serialize(ItemStack itemStack);

String serialize(Inventory[] inventories);
Expand All @@ -26,10 +22,6 @@ public interface NMSAdapter {

ItemStack deserialzeItem(String serialized);

Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted);

void spawnSuctionParticle(Location location);

void playChestAction(Location location, boolean open);

ItemStack setChestType(ItemStack itemStack, ChestType chestType);
Expand Down
@@ -1,14 +1,9 @@
package com.bgsoftware.wildchests.nms.v1_12_R1;

import com.bgsoftware.wildchests.api.objects.ChestType;
import com.bgsoftware.wildchests.key.KeySet;
import com.bgsoftware.wildchests.objects.inventory.InventoryHolder;
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.Chunk;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.EntityItem;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
Expand All @@ -17,13 +12,10 @@
import net.minecraft.server.v1_12_R1.World;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.Inventory;

import java.io.ByteArrayInputStream;
Expand All @@ -32,25 +24,11 @@
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@SuppressWarnings({"unused", "ConstantConditions"})
public final class NMSAdapter implements com.bgsoftware.wildchests.nms.NMSAdapter {

@Override
public int getHopperTransfer(org.bukkit.World world) {
return ((CraftWorld) world).getHandle().spigotConfig.hopperTransfer;
}

@Override
public int getHopperAmount(org.bukkit.World world) {
return ((CraftWorld) world).getHandle().spigotConfig.hopperAmount;
}

@Override
public String serialize(org.bukkit.inventory.ItemStack itemStack) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand All @@ -60,17 +38,17 @@ public String serialize(org.bukkit.inventory.ItemStack itemStack) {

ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);

if(nmsItem.isEmpty())
if (nmsItem.isEmpty())
return "";

if(nmsItem != null) {
if (nmsItem != null) {
nmsItem.setCount(1);
nmsItem.save(tagCompound);
}

try {
NBTCompressedStreamTools.a(tagCompound, dataOutput);
}catch(Exception ex){
} catch (Exception ex) {
return null;
}

Expand All @@ -85,15 +63,15 @@ public String serialize(Inventory[] inventories) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInt("Length", inventories.length);

for(int slot = 0; slot < inventories.length; slot++) {
for (int slot = 0; slot < inventories.length; slot++) {
NBTTagCompound inventoryCompound = new NBTTagCompound();
serialize(inventories[slot], inventoryCompound);
tagCompound.set(slot + "", inventoryCompound);
}

try {
NBTCompressedStreamTools.a(tagCompound, dataOutput);
}catch(Exception ex){
} catch (Exception ex) {
return null;
}

Expand All @@ -104,10 +82,9 @@ public String serialize(Inventory[] inventories) {
public InventoryHolder[] deserialze(String serialized) {
byte[] buff;

if(serialized.toCharArray()[0] == '*'){
if (serialized.toCharArray()[0] == '*') {
buff = Base64.getDecoder().decode(serialized.substring(1));
}
else{
} else {
buff = new BigInteger(serialized, 32).toByteArray();
}

Expand All @@ -119,29 +96,29 @@ public InventoryHolder[] deserialze(String serialized) {
int length = tagCompound.getInt("Length");
inventories = new InventoryHolder[length];

for(int i = 0; i < length; i++){
if(tagCompound.hasKey(i + "")) {
for (int i = 0; i < length; i++) {
if (tagCompound.hasKey(i + "")) {
NBTTagCompound nbtTagCompound = tagCompound.getCompound(i + "");
inventories[i] = deserialize(nbtTagCompound);
}
}

}catch(Exception ignored){}
} catch (Exception ignored) {
}

return inventories;
}

@Override
public org.bukkit.inventory.ItemStack deserialzeItem(String serialized) {
if(serialized.isEmpty())
if (serialized.isEmpty())
return new org.bukkit.inventory.ItemStack(Material.AIR);

byte[] buff;

if(serialized.toCharArray()[0] == '*'){
if (serialized.toCharArray()[0] == '*') {
buff = Base64.getDecoder().decode(serialized.substring(1));
}
else{
} else {
buff = new BigInteger(serialized, 32).toByteArray();
}

Expand All @@ -153,43 +130,17 @@ public org.bukkit.inventory.ItemStack deserialzeItem(String serialized) {
ItemStack nmsItem = new ItemStack(nbtTagCompoundRoot);

return CraftItemStack.asBukkitCopy(nmsItem);
}catch(Exception ex){
} catch (Exception ex) {
return null;
}
}

@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
World world = ((CraftWorld) location.getWorld()).getHandle();
List<Entity> entityList = new ArrayList<>();

if(onlyChunk){
Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
for(int i = 0; i < chunk.entitySlices.length; i++)
entityList.addAll(chunk.entitySlices[i]);
entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
}
else {
AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range,
location.getX() - range, location.getY() - range, location.getZ() - range);
entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
}

return entityList.stream().map(entity -> (Item) entity.getBukkitEntity())
.filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}

@Override
public void spawnSuctionParticle(Location location) {
location.getWorld().spawnParticle(Particle.CLOUD, location, 0);
}

@Override
public void playChestAction(Location location, boolean open) {
World world = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
TileEntityChest tileChest = (TileEntityChest) world.getTileEntity(blockPosition);
if(tileChest != null)
if (tileChest != null)
world.playBlockAction(blockPosition, tileChest.getBlock(), 1, open ? 1 : 0);
}

Expand Down Expand Up @@ -217,23 +168,23 @@ public void dropItemAsPlayer(HumanEntity humanEntity, org.bukkit.inventory.ItemS
entityHuman.drop(itemStack, false);
}

private org.bukkit.inventory.ItemStack setItemTag(org.bukkit.inventory.ItemStack itemStack, String key, String value){
private org.bukkit.inventory.ItemStack setItemTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getTag();

if(tagCompound == null)
if (tagCompound == null)
nmsItem.setTag((tagCompound = new NBTTagCompound()));

tagCompound.setString(key, value);

return CraftItemStack.asCraftMirror(nmsItem);
}

private void serialize(Inventory inventory, NBTTagCompound tagCompound){
private void serialize(Inventory inventory, NBTTagCompound tagCompound) {
NBTTagList itemsList = new NBTTagList();
org.bukkit.inventory.ItemStack[] items = inventory.getContents();

for(int i = 0; i < items.length; ++i) {
for (int i = 0; i < items.length; ++i) {
if (items[i] != null) {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
nbtTagCompound.setByte("Slot", (byte) i);
Expand All @@ -246,11 +197,11 @@ private void serialize(Inventory inventory, NBTTagCompound tagCompound){
tagCompound.set("Items", itemsList);
}

private InventoryHolder deserialize(NBTTagCompound tagCompound){
private InventoryHolder deserialize(NBTTagCompound tagCompound) {
InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
NBTTagList itemsList = tagCompound.getList("Items", 10);

for(int i = 0; i < itemsList.size(); i++){
for (int i = 0; i < itemsList.size(); i++) {
NBTTagCompound nbtTagCompound = itemsList.get(i);
inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(new ItemStack(nbtTagCompound)));
}
Expand Down

0 comments on commit 606a52f

Please sign in to comment.