mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-25 12:25:37 +01:00
Fixed item frame & armor stand logging under Folia
This commit is contained in:
parent
7170e29452
commit
ace870b930
@ -90,6 +90,7 @@ import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.paper.PaperAdapter;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.thread.Scheduler;
|
||||
import net.coreprotect.utility.Chat;
|
||||
@ -650,7 +651,7 @@ public class Rollback extends Queue {
|
||||
|
||||
if (!exists) {
|
||||
Entity entity = block.getLocation().getWorld().spawnEntity(location1, EntityType.ARMOR_STAND);
|
||||
entity.teleport(location1);
|
||||
PaperAdapter.ADAPTER.teleportAsync(entity, location1);
|
||||
}
|
||||
}
|
||||
else if ((rowType == Material.END_CRYSTAL)) {
|
||||
@ -671,7 +672,7 @@ public class Rollback extends Queue {
|
||||
Entity entity = block.getLocation().getWorld().spawnEntity(location1, EntityType.ENDER_CRYSTAL);
|
||||
EnderCrystal enderCrystal = (EnderCrystal) entity;
|
||||
enderCrystal.setShowingBottom((rowData != 0));
|
||||
entity.teleport(location1);
|
||||
PaperAdapter.ADAPTER.teleportAsync(entity, location1);
|
||||
}
|
||||
}
|
||||
else if ((rowType == Material.AIR) && ((oldTypeMaterial == Material.WATER))) {
|
||||
@ -728,7 +729,7 @@ public class Rollback extends Queue {
|
||||
}
|
||||
|
||||
entityLocation.setY(entityLocation.getY() - 1.99);
|
||||
entity.teleport(entityLocation);
|
||||
PaperAdapter.ADAPTER.teleportAsync(entity, entityLocation);
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,7 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -34,19 +33,12 @@ public class ContainerLogger extends Queue {
|
||||
ItemStack[] contents = null;
|
||||
String faceData = null;
|
||||
|
||||
if (type == Material.ARMOR_STAND) {
|
||||
EntityEquipment equipment = (EntityEquipment) container;
|
||||
if (equipment != null) {
|
||||
contents = Util.getArmorStandContents(equipment);
|
||||
}
|
||||
if (type == Material.ITEM_FRAME) {
|
||||
contents = (ItemStack[]) ((Object[]) container)[1];
|
||||
faceData = ((BlockFace) ((Object[]) container)[2]).name();
|
||||
}
|
||||
else if (type == Material.ITEM_FRAME) {
|
||||
ItemFrame itemFrame = (ItemFrame) container;
|
||||
contents = Util.getItemFrameItem(itemFrame);
|
||||
faceData = itemFrame.getFacing().name();
|
||||
}
|
||||
else if (type == Material.JUKEBOX) {
|
||||
contents = new ItemStack[] { ((ItemStack[]) container)[1] };
|
||||
else if (type == Material.JUKEBOX || type == Material.ARMOR_STAND) {
|
||||
contents = (ItemStack[]) ((Object[]) container)[1];
|
||||
}
|
||||
else {
|
||||
Inventory inventory = (Inventory) container;
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
@ -45,7 +46,9 @@ public final class EntityDamageByBlockListener extends Queue implements Listener
|
||||
if (entity instanceof ItemFrame && Config.getConfig(entity.getWorld()).ITEM_TRANSACTIONS) {
|
||||
ItemFrame frame = (ItemFrame) entity;
|
||||
if (frame.getItem().getType() != Material.AIR) {
|
||||
PlayerInteractEntityListener.queueContainerSingleItem(user, Material.ITEM_FRAME, frame, frame.getLocation(), false);
|
||||
ItemStack[] oldState = new ItemStack[] { frame.getItem().clone() };
|
||||
ItemStack[] newState = new ItemStack[] { new ItemStack(Material.AIR) };
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(user, Material.ITEM_FRAME, new Object[] { oldState, newState, frame.getFacing() }, frame.getLocation(), false);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof ArmorStand && Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
|
||||
|
@ -113,7 +113,9 @@ public final class EntityDamageByEntityListener extends Queue implements Listene
|
||||
if (entity instanceof ItemFrame && Config.getConfig(entityLocation.getWorld()).ITEM_TRANSACTIONS) {
|
||||
ItemFrame frame = (ItemFrame) entity;
|
||||
if (frame.getItem().getType() != Material.AIR) {
|
||||
PlayerInteractEntityListener.queueContainerSingleItem(user, Material.ITEM_FRAME, frame, frame.getLocation(), logDrops);
|
||||
ItemStack[] oldState = new ItemStack[] { frame.getItem().clone() };
|
||||
ItemStack[] newState = new ItemStack[] { new ItemStack(Material.AIR) };
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(user, Material.ITEM_FRAME, new Object[] { oldState, newState, frame.getFacing() }, frame.getLocation(), logDrops);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof EnderCrystal && Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.Config;
|
||||
@ -133,7 +134,9 @@ public final class HangingBreakByEntityListener extends Queue implements Listene
|
||||
|
||||
if (!event.isCancelled() && Config.getConfig(entity.getWorld()).ITEM_TRANSACTIONS && !inspecting) {
|
||||
if (itemframe.getItem().getType() != Material.AIR) {
|
||||
PlayerInteractEntityListener.queueContainerSingleItem(culprit, Material.ITEM_FRAME, itemframe, itemframe.getLocation(), logDrops);
|
||||
ItemStack[] oldState = new ItemStack[] { itemframe.getItem().clone() };
|
||||
ItemStack[] newState = new ItemStack[] { new ItemStack(Material.AIR) };
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(culprit, Material.ITEM_FRAME, new Object[] { oldState, newState, itemframe.getFacing() }, itemframe.getLocation(), logDrops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.Config;
|
||||
@ -61,7 +62,9 @@ public final class HangingBreakListener extends Queue implements Listener {
|
||||
|
||||
if (!event.isCancelled() && Config.getConfig(entity.getWorld()).ITEM_TRANSACTIONS) {
|
||||
if (itemframe.getItem().getType() != Material.AIR) {
|
||||
PlayerInteractEntityListener.queueContainerSingleItem(causeName, Material.ITEM_FRAME, itemframe, itemframe.getLocation(), logDrops);
|
||||
ItemStack[] oldState = new ItemStack[] { itemframe.getItem().clone() };
|
||||
ItemStack[] newState = new ItemStack[] { new ItemStack(Material.AIR) };
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(causeName, Material.ITEM_FRAME, new Object[] { oldState, newState, itemframe.getFacing() }, itemframe.getLocation(), logDrops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ package net.coreprotect.listener.player;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -87,7 +84,8 @@ public final class ArmorStandManipulateListener extends Queue implements Listene
|
||||
Player player = event.getPlayer();
|
||||
final ArmorStand armorStand = event.getRightClicked();
|
||||
EntityEquipment equipment = armorStand.getEquipment();
|
||||
ItemStack[] contents = Util.getArmorStandContents(equipment);
|
||||
ItemStack[] oldContents = Util.getArmorStandContents(equipment);
|
||||
ItemStack[] newContents = oldContents.clone();
|
||||
ItemStack item = event.getArmorStandItem();
|
||||
ItemStack playerItem = event.getPlayerItem();
|
||||
|
||||
@ -110,49 +108,45 @@ public final class ArmorStandManipulateListener extends Queue implements Listene
|
||||
return;
|
||||
}
|
||||
|
||||
if (item == null && playerItem == null) {
|
||||
int slot = 0;
|
||||
switch (event.getSlot()) {
|
||||
case LEGS:
|
||||
slot = 1;
|
||||
break;
|
||||
case CHEST:
|
||||
slot = 2;
|
||||
break;
|
||||
case HEAD:
|
||||
slot = 3;
|
||||
break;
|
||||
case HAND:
|
||||
slot = 4;
|
||||
break;
|
||||
case OFF_HAND:
|
||||
slot = 5;
|
||||
break;
|
||||
default:
|
||||
slot = 0;
|
||||
}
|
||||
// 0: BOOTS, 1: LEGGINGS, 2: CHESTPLATE, 3: HELMET, 4: MAINHAND, 5: OFFHAND
|
||||
|
||||
if (item.getType() == playerItem.getType()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
if (item!=null && playerItem==null){
|
||||
//player gets item
|
||||
}
|
||||
if (item==null && playerItem!=null){
|
||||
//players item placed on armor stands
|
||||
}
|
||||
if (item!=null && playerItem!=null){
|
||||
//items are swapped
|
||||
}
|
||||
*/
|
||||
|
||||
Material type = Material.ARMOR_STAND;
|
||||
Location standLocation = armorStand.getLocation();
|
||||
int x = standLocation.getBlockX();
|
||||
int y = standLocation.getBlockY();
|
||||
int z = standLocation.getBlockZ();
|
||||
|
||||
String transactingChestId = standLocation.getWorld().getUID().toString() + "." + x + "." + y + "." + z;
|
||||
String loggingChestId = player.getName().toLowerCase(Locale.ROOT) + "." + x + "." + y + "." + z;
|
||||
int chestId = Queue.getChestId(loggingChestId);
|
||||
if (chestId > 0) {
|
||||
if (ConfigHandler.forceContainer.get(loggingChestId) != null) {
|
||||
int force_size = ConfigHandler.forceContainer.get(loggingChestId).size();
|
||||
List<ItemStack[]> list = ConfigHandler.oldContainer.get(loggingChestId);
|
||||
|
||||
if (list.size() <= force_size) {
|
||||
list.add(Util.getContainerState(contents));
|
||||
ConfigHandler.oldContainer.put(loggingChestId, list);
|
||||
}
|
||||
}
|
||||
else if (item.getType() != Material.AIR && playerItem.getType() == Material.AIR) {
|
||||
oldContents[slot] = item.clone();
|
||||
newContents[slot] = new ItemStack(Material.AIR);
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(player.getName(), Material.ARMOR_STAND, new Object[] { oldContents, newContents }, armorStand.getLocation(), false);
|
||||
}
|
||||
else {
|
||||
List<ItemStack[]> list = new ArrayList<>();
|
||||
list.add(Util.getContainerState(contents));
|
||||
ConfigHandler.oldContainer.put(loggingChestId, list);
|
||||
else if (item.getType() == Material.AIR && playerItem.getType() != Material.AIR) {
|
||||
oldContents[slot] = new ItemStack(Material.AIR);
|
||||
newContents[slot] = playerItem.clone();
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(player.getName(), Material.ARMOR_STAND, new Object[] { oldContents, newContents }, armorStand.getLocation(), false);
|
||||
}
|
||||
else if (item.getType() != Material.AIR && playerItem.getType() != Material.AIR) {
|
||||
oldContents[slot] = item.clone();
|
||||
newContents[slot] = playerItem.clone();
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(player.getName(), Material.ARMOR_STAND, new Object[] { oldContents, newContents }, armorStand.getLocation(), false);
|
||||
}
|
||||
|
||||
ConfigHandler.transactingChest.computeIfAbsent(transactingChestId, k -> Collections.synchronizedList(new ArrayList<>()));
|
||||
Queue.queueContainerTransaction(player.getName(), standLocation, type, equipment, chestId);
|
||||
}
|
||||
}
|
||||
|
@ -38,14 +38,14 @@ public final class PlayerInteractEntityListener extends Queue implements Listene
|
||||
final Entity entity = event.getRightClicked(); // change item in ItemFrame, etc
|
||||
if (entity instanceof ItemFrame) {
|
||||
ItemFrame frame = (ItemFrame) entity;
|
||||
Material handType = Material.AIR;
|
||||
ItemStack handItem = new ItemStack(Material.AIR);
|
||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||
if (event.getHand().equals(EquipmentSlot.HAND) && mainHand.getType() != Material.AIR) {
|
||||
handType = mainHand.getType();
|
||||
handItem = mainHand;
|
||||
}
|
||||
else if (event.getHand().equals(EquipmentSlot.OFF_HAND) && offHand.getType() != Material.AIR) {
|
||||
handType = offHand.getType();
|
||||
handItem = offHand;
|
||||
}
|
||||
else if (event.getHand().equals(EquipmentSlot.OFF_HAND)) {
|
||||
return;
|
||||
@ -72,8 +72,10 @@ public final class PlayerInteractEntityListener extends Queue implements Listene
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.getItem().getType().equals(Material.AIR) && !handType.equals(Material.AIR)) {
|
||||
queueContainerSingleItem(player.getName(), Material.ITEM_FRAME, frame, frame.getLocation(), false);
|
||||
if (frame.getItem().getType().equals(Material.AIR) && !handItem.getType().equals(Material.AIR)) { // add item to item frame
|
||||
ItemStack[] oldState = new ItemStack[] { new ItemStack(Material.AIR) };
|
||||
ItemStack[] newState = new ItemStack[] { handItem.clone() };
|
||||
queueContainerSpecifiedItems(player.getName(), Material.ITEM_FRAME, new Object[] { oldState, newState, frame.getFacing() }, frame.getLocation(), false);
|
||||
}
|
||||
}
|
||||
else if (!event.isCancelled() && entity instanceof Creature && entity.getType().name().equals("ALLAY")) {
|
||||
@ -108,8 +110,8 @@ public final class PlayerInteractEntityListener extends Queue implements Listene
|
||||
}
|
||||
}
|
||||
|
||||
public static void queueContainerSingleItem(String user, Material type, Object container, Location location, boolean logDrop) {
|
||||
ItemStack[] contents = type == Material.ITEM_FRAME ? Util.getItemFrameItem((ItemFrame) container) : new ItemStack[] { ((ItemStack[]) container)[0] };
|
||||
public static void queueContainerSpecifiedItems(String user, Material type, Object container, Location location, boolean logDrop) {
|
||||
ItemStack[] contents = (ItemStack[]) ((Object[]) container)[0];
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
@ -659,7 +659,9 @@ public final class PlayerInteractListener extends Queue implements Listener {
|
||||
|
||||
if (Config.getConfig(block.getWorld()).ITEM_TRANSACTIONS) {
|
||||
boolean logDrops = player.getGameMode() != GameMode.CREATIVE;
|
||||
PlayerInteractEntityListener.queueContainerSingleItem(player.getName(), Material.JUKEBOX, new ItemStack[] { oldItemState, newItemState }, jukebox.getLocation(), logDrops);
|
||||
ItemStack[] oldState = new ItemStack[] { oldItemState };
|
||||
ItemStack[] newState = new ItemStack[] { newItemState };
|
||||
PlayerInteractEntityListener.queueContainerSpecifiedItems(player.getName(), Material.JUKEBOX, new Object[] { oldState, newState }, jukebox.getLocation(), logDrops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.coreprotect.paper;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
@ -62,4 +64,9 @@ public class PaperAdapter implements PaperInterface {
|
||||
return sign.getLine(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportAsync(Entity entity, Location location) {
|
||||
entity.teleport(location);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.coreprotect.paper;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class PaperHandler extends PaperAdapter implements PaperInterface {
|
||||
|
||||
@ -9,4 +11,9 @@ public class PaperHandler extends PaperAdapter implements PaperInterface {
|
||||
return server.isStopping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportAsync(Entity entity, Location location) {
|
||||
entity.teleportAsync(location);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.coreprotect.paper;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
@ -13,4 +15,6 @@ public interface PaperInterface {
|
||||
|
||||
public String getLine(Sign sign, int line);
|
||||
|
||||
public void teleportAsync(Entity entity, Location location);
|
||||
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ public class Scheduler {
|
||||
else if (regionData instanceof Entity) { // ENTITY
|
||||
Entity entity = (Entity) regionData;
|
||||
if (delay == 0) {
|
||||
entity.getScheduler().run(plugin, value -> task.run(), null);
|
||||
entity.getScheduler().run(plugin, value -> task.run(), task);
|
||||
}
|
||||
else {
|
||||
entity.getScheduler().runDelayed(plugin, value -> task.run(), null, delay);
|
||||
entity.getScheduler().runDelayed(plugin, value -> task.run(), task, delay);
|
||||
}
|
||||
}
|
||||
else { // GLOBAL
|
||||
|
Loading…
Reference in New Issue
Block a user