cfi packet listener

Dieser Commit ist enthalten in:
Jesse Boyd 2019-10-30 12:58:21 +01:00
Ursprung 72951cdf23
Commit c383fab2c2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
8 geänderte Dateien mit 153 neuen und 114 gelöschten Zeilen

Datei anzeigen

@ -141,15 +141,15 @@ public class FaweBukkit implements IFawe, Listener {
PluginManager manager = Bukkit.getPluginManager(); PluginManager manager = Bukkit.getPluginManager();
if (manager.getPlugin("PacketListenerApi") == null) { if (manager.getPlugin("PacketListenerApi") == null) {
File output = new File(plugin.getDataFolder().getParentFile(), "PacketListenerAPI_v3.6.0-SNAPSHOT.jar"); File output = new File(plugin.getDataFolder().getParentFile(), "PacketListenerAPI_v3.7.3-SNAPSHOT.jar");
byte[] jarData = Jars.PL_v3_6_0.download(); byte[] jarData = Jars.PL_v3_7_3.download();
try (FileOutputStream fos = new FileOutputStream(output)) { try (FileOutputStream fos = new FileOutputStream(output)) {
fos.write(jarData); fos.write(jarData);
} }
} }
if (manager.getPlugin("MapManager") == null) { if (manager.getPlugin("MapManager") == null) {
File output = new File(plugin.getDataFolder().getParentFile(), "MapManager_v1.4.0-SNAPSHOT.jar"); File output = new File(plugin.getDataFolder().getParentFile(), "MapManager_v1.7.3-SNAPSHOT.jar");
byte[] jarData = Jars.MM_v1_4_0.download(); byte[] jarData = Jars.MM_v1_7_3.download();
try (FileOutputStream fos = new FileOutputStream(output)) { try (FileOutputStream fos = new FileOutputStream(output)) {
fos.write(jarData); fos.write(jarData);
} }

Datei anzeigen

@ -20,6 +20,7 @@
package com.boydti.fawe.bukkit.adapter.mc1_14; package com.boydti.fawe.bukkit.adapter.mc1_14;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.ChunkPacket; import com.boydti.fawe.beta.implementation.ChunkPacket;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
@ -679,7 +680,12 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
nmsPacket = MapChunkUtil_1_14.create(this, packet); nmsPacket = MapChunkUtil_1_14.create(this, packet);
packet.setNativePacket(nmsPacket); packet.setNativePacket(nmsPacket);
} }
entityPlayer.playerConnection.sendPacket(nmsPacket); try {
FaweCache.IMP.CHUNK_FLAG.get().set(true);
entityPlayer.playerConnection.sendPacket(nmsPacket);
} finally {
FaweCache.IMP.CHUNK_FLAG.get().set(false);
}
} }
}); });
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.bukkit.listener; package com.boydti.fawe.bukkit.listener;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.command.CFICommands; import com.boydti.fawe.command.CFICommands;
import com.boydti.fawe.object.RunnableVal3; import com.boydti.fawe.object.RunnableVal3;
import com.boydti.fawe.object.brush.visualization.VirtualWorld; import com.boydti.fawe.object.brush.visualization.VirtualWorld;
@ -15,20 +16,32 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.EnumWrappers;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.event.platform.BlockInteractEvent; import com.sk89q.worldedit.event.platform.BlockInteractEvent;
import com.sk89q.worldedit.event.platform.Interaction; import com.sk89q.worldedit.event.platform.Interaction;
import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.List;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
/** /**
* The CFIPacketListener handles packets for editing the VirtualWorld * The CFIPacketListener handles packets for editing the VirtualWorld
@ -45,99 +58,90 @@ public class CFIPacketListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
this.protocolmanager = ProtocolLibrary.getProtocolManager(); this.protocolmanager = ProtocolLibrary.getProtocolManager();
// TODO NOT IMPLEMENTED // Direct digging to the virtual world
// // Direct digging to the virtual world registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
// registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() { @Override
// @Override public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
// public void run(Builder event, URI gen, String pt) { try {
// try { Player plr = event.getPlayer();
// Player plr = event.getPlayer(); BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint());
// BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint()); if (!sendBlockChange(plr, gen, pt, Interaction.HIT)) {
// if (!sendBlockChange(plr, gen, pt, Interaction.HIT)) { gen.setBlock(pt, BlockTypes.AIR.getDefaultState());
// gen.setBlock(pt, BlockTypes.AIR.getDefaultState()); }
// } } catch (WorldEditException e) {
// } catch (WorldEditException e) { e.printStackTrace();
// e.printStackTrace(); }
// } }
// } });
// });
// // Direct placing to the virtual world
// // Direct placing to the virtual world RunnableVal3<PacketEvent, VirtualWorld, BlockVector3> placeTask = new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
// RunnableVal3<PacketEvent, VirtualWorld, BlockVector3> placeTask = new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() { @Override
// @Override public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
// public void run(Builder event, URI gen, String pt) { try {
// try { Player plr = event.getPlayer();
// Player plr = event.getPlayer(); List<EnumWrappers.Hand> hands = event.getPacket().getHands().getValues();
// List<EnumWrappers.Hand> hands = event.getPacket().getHands().getValues();
// EnumWrappers.Hand enumHand = hands.isEmpty() ? EnumWrappers.Hand.MAIN_HAND : hands.get(0);
// EnumWrappers.Hand enumHand = hands.isEmpty() ? EnumWrappers.Hand.MAIN_HAND : hands.get(0); PlayerInventory inv = plr.getInventory();
// PlayerInventory inv = plr.getInventory(); ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand();
// ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand(); if (hand.getType().isBlock()) {
// if (hand.getType().isBlock()) { Material type = hand.getType();
// Material type = hand.getType(); switch (type) {
// switch (type) { case AIR:
// case AIR: case CAVE_AIR:
// case CAVE_AIR: case VOID_AIR:
// case VOID_AIR: break;
// break; default: {
// default: { BlockStateHolder block = BukkitAdapter.asBlockState(hand);
// BlockStateHolder block = BukkitAdapter.asBlockState(hand); if (block != null) {
// if (block != null) { gen.setBlock(pt, block);
// gen.setBlock(pt, block); return;
// return; }
// } }
// } }
// } }
// } pt = getRelPos(event, gen);
// pt = getRelPos(event, gen); sendBlockChange(plr, gen, pt, Interaction.OPEN);
// sendBlockChange(plr, gen, pt, Interaction.OPEN); } catch (WorldEditException e) {
// } catch (WorldEditException e) { e.printStackTrace();
// e.printStackTrace(); }
// } }
// } };
// }; registerBlockEvent(PacketType.Play.Client.BLOCK_PLACE, true, placeTask);
// registerBlockEvent(PacketType.Play.Client.BLOCK_PLACE, true, placeTask); registerBlockEvent(PacketType.Play.Client.USE_ITEM, true, placeTask);
// registerBlockEvent(PacketType.Play.Client.USE_ITEM, true, placeTask);
// // Cancel block change packets where the real world overlaps with the virtual one
// // Cancel block change packets where the real world overlaps with the virtual one registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
// registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() { @Override
// @Override public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
// public void run(Builder event, URI gen, String pt) { // Do nothing
// // Do nothing }
// } });
// });
// // Modify chunk packets where the real world overlaps with the virtual one
// // Modify chunk packets where the real world overlaps with the virtual one protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) {
// protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) { @Override
// @Override public void onPacketSending(PacketEvent event) {
// public void onPacketSending(PacketEvent event) { if (!event.isServerPacket() || FaweCache.IMP.CHUNK_FLAG.get().get()) return;
// if (!event.isServerPacket()) return; VirtualWorld gen = getGenerator(event);
// if (gen != null) {
// VirtualWorld gen = getGenerator(event); BlockVector3 origin = gen.getOrigin().toBlockPoint();
// if (gen != null) { PacketContainer packet = event.getPacket();
// BlockVector3 origin = gen.getOrigin().toBlockPoint(); StructureModifier<Integer> ints = packet.getIntegers();
// PacketContainer packet = event.getPacket(); int cx = ints.read(0);
// StructureModifier<Integer> ints = packet.getIntegers(); int cz = ints.read(1);
// int cx = ints.read(0);
// int cz = ints.read(1); int ocx = origin.getBlockX() >> 4;
// int ocz = origin.getBlockZ() >> 4;
// int ocx = origin.getBlockX() >> 4;
// int ocz = origin.getBlockZ() >> 4; if (gen.contains(BlockVector3.at((cx - ocx) << 4, 0, (cz - ocz) << 4))) {
// event.setCancelled(true);
// if (gen.contains(BlockVector3.at((cx - ocx) << 4, 0, (cz - ocz) << 4))) { gen.refreshChunk(cx - ocx, cz - ocz);
// event.setCancelled(true); }
// }
// Player plr = event.getPlayer(); }
// });
// FaweQueue queue = SetQueue.IMP.getNewQueue(plr.getWorld().getName(), true, false);
//
// FaweChunk toSend = gen.getSnapshot(cx - ocx, cz - ocz);
// toSend.setLoc(gen, cx, cz);
// queue.sendChunkUpdate(toSend, FawePlayer.wrap(plr));
// }
// }
// }
// });
// The following few listeners are to ignore block collisions where the virtual and real world overlap // The following few listeners are to ignore block collisions where the virtual and real world overlap

Datei anzeigen

@ -45,6 +45,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -104,6 +105,7 @@ public enum FaweCache implements Trimable {
@Override @Override
public synchronized boolean trim(boolean aggressive) { public synchronized boolean trim(boolean aggressive) {
CHUNK_FLAG.clean();
BYTE_BUFFER_8192.clean(); BYTE_BUFFER_8192.clean();
BLOCK_TO_PALETTE.clean(); BLOCK_TO_PALETTE.clean();
PALETTE_TO_BLOCK.clean(); PALETTE_TO_BLOCK.clean();
@ -205,6 +207,7 @@ public enum FaweCache implements Trimable {
/* /*
thread cache thread cache
*/ */
public final CleanableThreadLocal<AtomicBoolean> CHUNK_FLAG = new CleanableThreadLocal<>(AtomicBoolean::new); // resets to false
public final CleanableThreadLocal<byte[]> BYTE_BUFFER_8192 = new CleanableThreadLocal<>(() -> new byte[8192]); public final CleanableThreadLocal<byte[]> BYTE_BUFFER_8192 = new CleanableThreadLocal<>(() -> new byte[8192]);

Datei anzeigen

@ -289,12 +289,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
int lenCX = (getWidth() + 15) >> 4; int lenCX = (getWidth() + 15) >> 4;
int lenCZ = (getLength() + 15) >> 4; int lenCZ = (getLength() + 15) >> 4;
int OX = chunkOffset.getBlockX();
int OZ = chunkOffset.getBlockZ();
Location position = player.getLocation(); Location position = player.getLocation();
int pcx = (position.getBlockX() >> 4) - OX; int pcx = (position.getBlockX() >> 4) - chunkOffset.getBlockX();
int pcz = (position.getBlockZ() >> 4) - OZ; int pcz = (position.getBlockZ() >> 4) - chunkOffset.getBlockZ();
int scx = Math.max(0, pcx - 15); int scx = Math.max(0, pcx - 15);
int scz = Math.max(0, pcz - 15); int scz = Math.max(0, pcz - 15);
@ -303,21 +301,23 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int chunkZ = scz; chunkZ <= ecz; chunkZ++) { for (int chunkZ = scz; chunkZ <= ecz; chunkZ++) {
for (int chunkX = scx; chunkX <= ecx; chunkX++) { for (int chunkX = scx; chunkX <= ecx; chunkX++) {
int finalChunkX = chunkX;
int finalChunkZ = chunkZ;
int realWorldX = chunkX + OX; refreshChunk(world, chunkX, chunkZ);
int realWorldZ = chunkZ + OZ;
Supplier<IBlocks> blocksSupplier = () -> getChunk(finalChunkX, finalChunkZ);
ChunkPacket packet = new ChunkPacket(realWorldX, realWorldZ, blocksSupplier, true);
world.sendFakeChunk(player, packet);
} }
} }
} }
} }
public void refreshChunk(World world, int chunkX, int chunkZ) {
Supplier<IBlocks> blocksSupplier = () -> getChunk(chunkX, chunkZ);
int realChunkX = chunkX + chunkOffset.getBlockX();
int realChunkZ = chunkZ + chunkOffset.getBlockZ();
ChunkPacket packet = new ChunkPacket(realChunkX, realChunkZ, blocksSupplier, true);
world.sendFakeChunk(player, packet);
}
@Override @Override
public void sendFakeChunk(@Nullable Player player, ChunkPacket packet) { public void sendFakeChunk(@Nullable Player player, ChunkPacket packet) {
if (this.player != null) { if (this.player != null) {
@ -328,7 +328,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
@Override @Override
public void refreshChunk(int chunkX, int chunkZ) { public void refreshChunk(int chunkX, int chunkZ) {
if (chunkOffset != null && player != null) { if (chunkOffset != null && player != null) {
player.getWorld().refreshChunk(chunkX, chunkZ); refreshChunk(player.getWorld(), chunkX, chunkZ);
} }
} }

Datei anzeigen

@ -10,10 +10,10 @@ import java.util.Base64;
public enum Jars { public enum Jars {
MM_v1_4_0("https://github.com/InventivetalentDev/MapManager/releases/download/1.7.3-SNAPSHOT/MapManager_v1.7.3-SNAPSHOT.jar", MM_v1_7_3("https://github.com/InventivetalentDev/MapManager/releases/download/1.7.3-SNAPSHOT/MapManager_v1.7.3-SNAPSHOT.jar",
"M3YLUQZZ66K2DMVDCYLEU38U3ZKRKHRAXQGGPVKFO6G=", 554831), "M3YLUQZZ66K2DMVDCYLEU38U3ZKRKHRAXQGGPVKFO6G=", 554831),
PL_v3_6_0("https://github.com/InventivetalentDev/PacketListenerAPI/releases/download/3.7.3-SNAPSHOT/PacketListenerAPI_v3.7.3-SNAPSHOT.jar", PL_v3_7_3("https://github.com/InventivetalentDev/PacketListenerAPI/releases/download/3.7.3-SNAPSHOT/PacketListenerAPI_v3.7.3-SNAPSHOT.jar",
"ETDBRZLN5PRVDFR/MSQDPM6JJER3WQOKHCN8FUXO5ZM=", 167205), "ETDBRZLN5PRVDFR/MSQDPM6JJER3WQOKHCN8FUXO5ZM=", 167205),
; ;

Datei anzeigen

@ -39,6 +39,7 @@ import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.wrappers.WorldWrapper; import com.boydti.fawe.wrappers.WorldWrapper;
import com.google.common.collect.Maps;
import com.sk89q.jchronic.Chronic; import com.sk89q.jchronic.Chronic;
import com.sk89q.jchronic.Options; import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.utils.Span; import com.sk89q.jchronic.utils.Span;
@ -90,7 +91,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -167,6 +170,7 @@ public class LocalSession implements TextureHolder {
private boolean useServerCUI = false; // Save this to not annoy players. private boolean useServerCUI = false; // Save this to not annoy players.
private ItemType wandItem; private ItemType wandItem;
private ItemType navWandItem; private ItemType navWandItem;
private Map<String, String> macros = new HashMap<>();
/** /**
* Construct the object. * Construct the object.
@ -296,6 +300,19 @@ public class LocalSession implements TextureHolder {
} }
} }
public Map<String, String> getMacros() {
return Collections.unmodifiableMap(this.macros);
}
public void setMacro(String key, String value) {
this.macros.put(key, value);
setDirty();
}
public String getMacro(String key) {
return this.macros.get(key);
}
/** /**
* Get whether this session is "dirty" and has changes that needs to * Get whether this session is "dirty" and has changes that needs to
* be committed. * be committed.

Datei anzeigen

@ -111,6 +111,15 @@ public class UtilityCommands {
this.we = we; this.we = we;
} }
@Command(
name = "/macro",
desc = "Generate or run a macro"
)
@CommandPermissions("worldedit.macro")
public void macro(Player player, LocalSession session, String name, String argument) throws IOException {
}
@Command( @Command(
name = "/heightmapinterface", name = "/heightmapinterface",
desc = "Generate the heightmap interface: https://github.com/boy0001/HeightMap" desc = "Generate the heightmap interface: https://github.com/boy0001/HeightMap"