v1.6.4: Added support for 1.20.5, 1.20.6 and 1.21 #30
12 changed files with 2587 additions and 120 deletions
|
@ -117,13 +117,4 @@ public interface MapController extends IMapController {
|
|||
* @param frame {@link ItemFrame} to clear
|
||||
*/
|
||||
void clearFrame(Player player, ItemFrame frame);
|
||||
|
||||
/**
|
||||
* Get an {@link ItemFrame} by its entity ID
|
||||
*
|
||||
* @param world The world the {@link ItemFrame} is in
|
||||
* @param entityId Entity-ID of the {@link ItemFrame}
|
||||
* @return The found {@link ItemFrame}, or <code>null</code>
|
||||
*/
|
||||
ItemFrame getItemFrameById(World world, int entityId);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,13 @@
|
|||
package tech.sbdevelopment.mapreflectionapi.api;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.exceptions.MapLimitExceededException;
|
||||
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashSet;
|
||||
|
@ -30,6 +33,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtils.*;
|
||||
|
||||
/**
|
||||
* The {@link MapManager} manages all the maps. It also contains functions for wrapping.
|
||||
*/
|
||||
|
@ -172,6 +177,30 @@ public class MapManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an {@link ItemFrame} by its entity ID
|
||||
*
|
||||
* @param world The world the {@link ItemFrame} is in
|
||||
* @param entityId Entity-ID of the {@link ItemFrame}
|
||||
* @return The found {@link ItemFrame}, or <code>null</code>
|
||||
*/
|
||||
public ItemFrame getItemFrameById(World world, int entityId) {
|
||||
Object worldHandle = getHandle(world);
|
||||
Object nmsEntity = ReflectionUtil.callMethod(worldHandle, supports(18) ? "a" : "getEntity", entityId);
|
||||
if (nmsEntity == null) return null;
|
||||
|
||||
Object craftEntity = ReflectionUtil.callMethod(nmsEntity, "getBukkitEntity");
|
||||
if (craftEntity == null) return null;
|
||||
|
||||
Class<?> itemFrameClass = getNMSClass("world.entity.decoration", "EntityItemFrame");
|
||||
if (itemFrameClass == null) return null;
|
||||
|
||||
if (craftEntity.getClass().isAssignableFrom(itemFrameClass))
|
||||
return (ItemFrame) itemFrameClass.cast(craftEntity);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an occupied map ID
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@ import tech.sbdevelopment.mapreflectionapi.api.events.MapContentUpdateEvent;
|
|||
import tech.sbdevelopment.mapreflectionapi.api.exceptions.MapLimitExceededException;
|
||||
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.XMaterial;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -45,15 +46,9 @@ import static tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtils.*;
|
|||
*/
|
||||
@Getter
|
||||
public class MapWrapper extends AbstractMapWrapper {
|
||||
private static final String REFERENCE_METADATA = "MAP_WRAPPER_REF";
|
||||
public static final String REFERENCE_METADATA = "MAP_WRAPPER_REF";
|
||||
protected ArrayImage content;
|
||||
|
||||
private static final Material MAP_MATERIAL;
|
||||
|
||||
static {
|
||||
MAP_MATERIAL = supports(13) ? Material.FILLED_MAP : Material.MAP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link MapWrapper}
|
||||
*
|
||||
|
@ -215,7 +210,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
|
||||
@Override
|
||||
public void showInHand(Player player, boolean force) {
|
||||
if (player.getInventory().getItemInMainHand().getType() != MAP_MATERIAL && !force)
|
||||
if (player.getInventory().getItemInMainHand().getType() != XMaterial.FILLED_MAP.parseMaterial() && !force)
|
||||
return;
|
||||
|
||||
showInInventory(player, player.getInventory().getHeldItemSlot(), force);
|
||||
|
@ -233,7 +228,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
|
||||
@Override
|
||||
public void showInFrame(Player player, ItemFrame frame, boolean force) {
|
||||
if (frame.getItem().getType() != MAP_MATERIAL && !force)
|
||||
if (frame.getItem().getType() != XMaterial.FILLED_MAP.parseMaterial() && !force)
|
||||
return;
|
||||
|
||||
showInFrame(player, frame.getEntityId());
|
||||
|
@ -248,7 +243,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
public void showInFrame(Player player, int entityId, String debugInfo) {
|
||||
if (!isViewing(player)) return;
|
||||
|
||||
ItemStack stack = new ItemStack(MAP_MATERIAL, 1);
|
||||
ItemStack stack = new ItemStack(XMaterial.FILLED_MAP.parseMaterial(), 1);
|
||||
if (debugInfo != null) {
|
||||
ItemMeta itemMeta = stack.getItemMeta();
|
||||
itemMeta.setDisplayName(debugInfo);
|
||||
|
@ -256,7 +251,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(MapReflectionAPI.getInstance(), () -> {
|
||||
ItemFrame frame = getItemFrameById(player.getWorld(), entityId);
|
||||
ItemFrame frame = MapReflectionAPI.getMapManager().getItemFrameById(player.getWorld(), entityId);
|
||||
if (frame != null) {
|
||||
frame.removeMetadata(REFERENCE_METADATA, MapReflectionAPI.getInstance());
|
||||
frame.setMetadata(REFERENCE_METADATA, new FixedMetadataValue(MapReflectionAPI.getInstance(), MapWrapper.this));
|
||||
|
@ -270,7 +265,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
public void clearFrame(Player player, int entityId) {
|
||||
sendItemFramePacket(player, entityId, null, -1);
|
||||
Bukkit.getScheduler().runTask(MapReflectionAPI.getInstance(), () -> {
|
||||
ItemFrame frame = getItemFrameById(player.getWorld(), entityId);
|
||||
ItemFrame frame = MapReflectionAPI.getMapManager().getItemFrameById(player.getWorld(), entityId);
|
||||
if (frame != null) frame.removeMetadata(REFERENCE_METADATA, MapReflectionAPI.getInstance());
|
||||
});
|
||||
}
|
||||
|
@ -280,29 +275,8 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
clearFrame(player, frame.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFrame getItemFrameById(World world, int entityId) {
|
||||
Object worldHandle = getHandle(world);
|
||||
Object nmsEntity = ReflectionUtil.callMethod(worldHandle, supports(18) ? "a" : "getEntity", entityId);
|
||||
if (nmsEntity == null) return null;
|
||||
|
||||
Object craftEntity = ReflectionUtil.callMethod(nmsEntity, "getBukkitEntity");
|
||||
if (craftEntity == null) return null;
|
||||
|
||||
Class<?> itemFrameClass = getNMSClass("world.entity.decoration", "EntityItemFrame");
|
||||
if (itemFrameClass == null) return null;
|
||||
|
||||
if (craftEntity.getClass().isAssignableFrom(itemFrameClass))
|
||||
return (ItemFrame) itemFrameClass.cast(craftEntity);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object asCraftItemStack(Player player) {
|
||||
return createCraftItemStack(supports(13)
|
||||
? new ItemStack(MAP_MATERIAL, 1)
|
||||
: new ItemStack(MAP_MATERIAL, 1, (short) getMapId(player)
|
||||
), (short) getMapId(player));
|
||||
return createCraftItemStack(new ItemStack(XMaterial.FILLED_MAP.parseMaterial(), 1, (short) getMapId(player)), (short) getMapId(player));
|
||||
}
|
||||
|
||||
private Object createCraftItemStack(@NotNull ItemStack stack, int mapId) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
* Copyright (c) 2022-2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,28 +20,24 @@ package tech.sbdevelopment.mapreflectionapi.api.events;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import tech.sbdevelopment.mapreflectionapi.MapReflectionAPI;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.events.types.CancellableEvent;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtils;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.XMaterial;
|
||||
|
||||
/**
|
||||
* This event gets fired when a map in the creative inventory gets updated
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class CreativeInventoryMapUpdateEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
public class CreativeInventoryMapUpdateEvent extends CancellableEvent {
|
||||
private final Player player;
|
||||
private final int slot;
|
||||
private final ItemStack item;
|
||||
|
@ -62,11 +58,6 @@ public class CreativeInventoryMapUpdateEvent extends Event implements Cancellabl
|
|||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link MapWrapper} of the map of this event
|
||||
*
|
||||
|
@ -76,7 +67,7 @@ public class CreativeInventoryMapUpdateEvent extends Event implements Cancellabl
|
|||
public MapWrapper getMapWrapper() {
|
||||
if (mapWrapper == null) {
|
||||
if (item == null) return null;
|
||||
if (item.getType() != Material.MAP) return null;
|
||||
if (!XMaterial.FILLED_MAP.isSimilar(item)) return null;
|
||||
mapWrapper = MapReflectionAPI.getMapManager().getWrapperForId(player, item.getDurability());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
* Copyright (c) 2022-2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,23 +20,15 @@ package tech.sbdevelopment.mapreflectionapi.api.events;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.events.types.CancellableEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when a map creation is cancelled
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class MapCancelEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
public class MapCancelEvent extends CancellableEvent {
|
||||
private final Player player;
|
||||
private final int id;
|
||||
|
||||
|
@ -52,9 +44,4 @@ public class MapCancelEvent extends Event implements Cancellable {
|
|||
this.player = player;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
* Copyright (c) 2022-2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -21,11 +21,9 @@ package tech.sbdevelopment.mapreflectionapi.api.events;
|
|||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.ArrayImage;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.events.types.Event;
|
||||
|
||||
/**
|
||||
* This event gets fired when the content of a {@link MapWrapper} is updated
|
||||
|
@ -33,8 +31,6 @@ import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
|||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class MapContentUpdateEvent extends Event {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private final MapWrapper wrapper;
|
||||
private final ArrayImage content;
|
||||
@Setter
|
||||
|
@ -52,9 +48,4 @@ public class MapContentUpdateEvent extends Event {
|
|||
this.wrapper = wrapper;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
* Copyright (c) 2022-2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,28 +20,20 @@ package tech.sbdevelopment.mapreflectionapi.api.events;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import tech.sbdevelopment.mapreflectionapi.MapReflectionAPI;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||
import tech.sbdevelopment.mapreflectionapi.api.events.types.CancellableEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when a player interact with a map
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class MapInteractEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
public class MapInteractEvent extends CancellableEvent {
|
||||
private final Player player;
|
||||
private final int entityID;
|
||||
private final int action;
|
||||
|
@ -69,11 +61,6 @@ public class MapInteractEvent extends Event implements Cancellable {
|
|||
this.hand = hand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ItemFrame} the map is in
|
||||
*
|
||||
|
@ -81,10 +68,8 @@ public class MapInteractEvent extends Event implements Cancellable {
|
|||
*/
|
||||
@Nullable
|
||||
public ItemFrame getFrame() {
|
||||
if (getMapWrapper() == null) return null;
|
||||
|
||||
if (frame == null) {
|
||||
frame = getMapWrapper().getController().getItemFrameById(player.getWorld(), entityID);
|
||||
frame = MapReflectionAPI.getMapManager().getItemFrameById(player.getWorld(), entityID);
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
@ -96,10 +81,11 @@ public class MapInteractEvent extends Event implements Cancellable {
|
|||
*/
|
||||
@Nullable
|
||||
public MapWrapper getMapWrapper() {
|
||||
if (getFrame() == null) return null;
|
||||
if (mapWrapper == null) {
|
||||
mapWrapper = MapReflectionAPI.getMapManager().getWrapperForId(player, entityID);
|
||||
if (!frame.hasMetadata(MapWrapper.REFERENCE_METADATA)) return null;
|
||||
mapWrapper = (MapWrapper) frame.getMetadata(MapWrapper.REFERENCE_METADATA).get(0).value();
|
||||
}
|
||||
|
||||
return mapWrapper;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tech.sbdevelopment.mapreflectionapi.api.events.types;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class CancellableEvent extends Event implements Cancellable {
|
||||
/**
|
||||
* If this event gets cancelled.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
|
||||
public CancellableEvent(boolean isAsync) {
|
||||
super(isAsync);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this event gets cancelled.
|
||||
*
|
||||
* @return true if cancelled, false if not
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if this event gets cancelled.
|
||||
*
|
||||
* @param cancelled true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tech.sbdevelopment.mapreflectionapi.api.events.types;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class Event extends org.bukkit.event.Event {
|
||||
public Event(boolean isAsync) {
|
||||
super(isAsync);
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of EventHandlers listening to this event.
|
||||
*/
|
||||
@Getter
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
/**
|
||||
* Get the EventHandlers listening to this event.
|
||||
*
|
||||
* @return The EventHandlers listening to this event.
|
||||
*/
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
|
@ -72,6 +72,8 @@ public class PacketListener implements Listener {
|
|||
ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() {
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
||||
boolean cancel = false;
|
||||
|
||||
if (packet.getClass().isAssignableFrom(packetPlayOutMapClass)) {
|
||||
Object packetPlayOutMap = packetPlayOutMapClass.cast(packet);
|
||||
|
||||
|
@ -83,18 +85,19 @@ public class PacketListener implements Listener {
|
|||
boolean async = !MapReflectionAPI.getInstance().getServer().isPrimaryThread();
|
||||
MapCancelEvent event = new MapCancelEvent(player, id, async);
|
||||
if (MapReflectionAPI.getMapManager().isIdUsedBy(player, id)) event.setCancelled(true);
|
||||
if (event.getHandlers().getRegisteredListeners().length > 0)
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
super.write(ctx, packet, promise);
|
||||
if (!cancel) super.write(ctx, packet, promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||
boolean cancel = false;
|
||||
|
||||
if (packet.getClass().isAssignableFrom(packetPlayInUseEntityClass)) {
|
||||
Object packetPlayInEntity = packetPlayInUseEntityClass.cast(packet);
|
||||
|
||||
|
@ -105,9 +108,20 @@ public class PacketListener implements Listener {
|
|||
Object pos;
|
||||
if (supports(17)) {
|
||||
Object action = getDeclaredField(packetPlayInEntity, "b");
|
||||
actionEnum = (Enum<?>) callDeclaredMethod(action, "a"); //action type
|
||||
hand = hasField(action, "a") ? (Enum<?>) getDeclaredField(action, "a") : null;
|
||||
pos = hasField(action, "b") ? getDeclaredField(action, "b") : null;
|
||||
actionEnum = (Enum<?>) callDeclaredMethod(action, "a");
|
||||
Class<?> d = getNMSClass("network.protocol.game", "PacketPlayInUseEntity$d");
|
||||
Class<?> e = getNMSClass("network.protocol.game", "PacketPlayInUseEntity$e");
|
||||
if (action.getClass().isAssignableFrom(e)) {
|
||||
hand = (Enum<?>) getDeclaredField(action, "a");
|
||||
pos = getDeclaredField(action, "b");
|
||||
} else {
|
||||
pos = null;
|
||||
if (action.getClass().isAssignableFrom(d)) {
|
||||
hand = (Enum<?>) getDeclaredField(action, "a");
|
||||
} else {
|
||||
hand = null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
actionEnum = (Enum<?>) callDeclaredMethod(packetPlayInEntity, supports(13) ? "b" : "a"); //1.13 = b, 1.12 = a
|
||||
hand = (Enum<?>) callDeclaredMethod(packetPlayInEntity, supports(13) ? "c" : "b"); //1.13 = c, 1.12 = b
|
||||
|
@ -122,7 +136,7 @@ public class PacketListener implements Listener {
|
|||
return event.isCancelled();
|
||||
}
|
||||
return false;
|
||||
}).get(1, TimeUnit.SECONDS)) return;
|
||||
}).get(1, TimeUnit.SECONDS)) cancel = true;
|
||||
} else if (packet.getClass().isAssignableFrom(packetPlayInSetCreativeSlotClass)) {
|
||||
Object packetPlayInSetCreativeSlot = packetPlayInSetCreativeSlotClass.cast(packet);
|
||||
|
||||
|
@ -134,11 +148,11 @@ public class PacketListener implements Listener {
|
|||
CreativeInventoryMapUpdateEvent event = new CreativeInventoryMapUpdateEvent(player, slot, craftStack, async);
|
||||
if (event.getMapWrapper() != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
super.channelRead(ctx, packet);
|
||||
if (!cancel) super.channelRead(ctx, packet);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -143,14 +143,12 @@ public class UpdateManager {
|
|||
File pluginFile = getPluginFile(); // /plugins/XXX.jar
|
||||
if (pluginFile == null) {
|
||||
this.downloadResponse.accept(DownloadResponse.ERROR, null);
|
||||
Bukkit.getLogger().info("Pluginfile is null");
|
||||
return;
|
||||
}
|
||||
File updateFolder = Bukkit.getUpdateFolderFile();
|
||||
if (!updateFolder.exists()) {
|
||||
if (!updateFolder.mkdirs()) {
|
||||
this.downloadResponse.accept(DownloadResponse.ERROR, null);
|
||||
Bukkit.getLogger().info("Updatefolder doesn't exists, and can't be made");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue