mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2026-01-04 15:41:35 +00:00
send bundle packets
This commit is contained in:
@@ -17,8 +17,10 @@
|
||||
|
||||
package net.momirealms.customfishing;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
|
||||
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
|
||||
@@ -55,11 +57,15 @@ import net.momirealms.customfishing.version.VersionManagerImpl;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class CustomFishingPluginImpl extends CustomFishingPlugin {
|
||||
@@ -340,4 +346,15 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
|
||||
public static ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
|
||||
public static void sendPackets(Player player, PacketContainer... packets) {
|
||||
List<PacketContainer> bundle = new ArrayList<>(Arrays.asList(packets));
|
||||
PacketContainer bundlePacket = new PacketContainer(PacketType.Play.Server.BUNDLE);
|
||||
bundlePacket.getPacketBundles().write(0, bundle);
|
||||
sendPacket(player, bundlePacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customfishing.gui.page.file;
|
||||
|
||||
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
|
||||
import net.momirealms.customfishing.adventure.component.ShadedAdventureComponentWrapper;
|
||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.gui.Icon;
|
||||
import net.momirealms.customfishing.gui.icon.BackGroundItem;
|
||||
import net.momirealms.customfishing.gui.icon.BackToFolderItem;
|
||||
@@ -90,12 +91,12 @@ public class FileSelector {
|
||||
.setGui(gui)
|
||||
.build();
|
||||
|
||||
gui.playAnimation(new SequentialAnimation(1, true), slotElement -> {
|
||||
if (slotElement instanceof SlotElement.ItemSlotElement itemSlotElement) {
|
||||
return !(itemSlotElement.getItem() instanceof Icon);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// gui.playAnimation(new SequentialAnimation(1, true), slotElement -> {
|
||||
// if (slotElement instanceof SlotElement.ItemSlotElement itemSlotElement) {
|
||||
// return !(itemSlotElement.getItem() instanceof Icon);
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
|
||||
window.open();
|
||||
}
|
||||
|
||||
@@ -50,8 +50,12 @@ public class BaitAnimationTask implements Runnable {
|
||||
this.player = player;
|
||||
this.fishHook = fishHook;
|
||||
entityID = ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE);
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, FakeItemUtils.getSpawnPacket(entityID, fishHook.getLocation()));
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, FakeItemUtils.getMetaPacket(entityID, baitItem));
|
||||
if (plugin.getVersionManager().isVersionNewerThan1_19_R3()) {
|
||||
CustomFishingPluginImpl.sendPackets(player, FakeItemUtils.getSpawnPacket(entityID, fishHook.getLocation()), FakeItemUtils.getMetaPacket(entityID, baitItem));
|
||||
} else {
|
||||
CustomFishingPluginImpl.sendPacket(player, FakeItemUtils.getSpawnPacket(entityID, fishHook.getLocation()));
|
||||
CustomFishingPluginImpl.sendPacket(player, FakeItemUtils.getMetaPacket(entityID, baitItem));
|
||||
}
|
||||
this.cancellableTask = plugin.getScheduler().runTaskAsyncTimer(this, 50, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,9 +191,13 @@ public class ArmorStandUtils {
|
||||
*/
|
||||
public static void sendFakeItem(Player player, Location location, ItemStack itemStack, int seconds) {
|
||||
int id = new Random().nextInt(Integer.MAX_VALUE);
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0)));
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getMetaPacket(id));
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getEquipPacket(id, itemStack));
|
||||
if (CustomFishingPlugin.get().getVersionManager().isVersionNewerThan1_19_R3()) {
|
||||
CustomFishingPluginImpl.sendPackets(player, getSpawnPacket(id, location.clone().subtract(0,1,0)), getMetaPacket(id), getEquipPacket(id, itemStack));
|
||||
} else {
|
||||
CustomFishingPluginImpl.sendPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0)));
|
||||
CustomFishingPluginImpl.sendPacket(player, getMetaPacket(id));
|
||||
CustomFishingPluginImpl.sendPacket(player, getEquipPacket(id, itemStack));
|
||||
}
|
||||
CustomFishingPlugin.get().getScheduler().runTaskAsyncLater(() -> CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getDestroyPacket(id)), seconds * 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@@ -207,8 +211,12 @@ public class ArmorStandUtils {
|
||||
*/
|
||||
public static void sendHologram(Player player, Location location, Component component, int seconds) {
|
||||
int id = new Random().nextInt(Integer.MAX_VALUE);
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0)));
|
||||
CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getMetaPacket(id, component));
|
||||
if (CustomFishingPlugin.get().getVersionManager().isVersionNewerThan1_19_R3()) {
|
||||
CustomFishingPluginImpl.sendPackets(player, getSpawnPacket(id, location.clone().subtract(0,1,0)), getMetaPacket(id, component));
|
||||
} else {
|
||||
CustomFishingPluginImpl.sendPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0)));
|
||||
CustomFishingPluginImpl.sendPacket(player, getMetaPacket(id, component));
|
||||
}
|
||||
CustomFishingPlugin.get().getScheduler().runTaskAsyncLater(() -> CustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getDestroyPacket(id)), seconds * 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class VersionManagerImpl implements VersionManager {
|
||||
|
||||
private final boolean isNewerThan1_19_R2;
|
||||
private final boolean isNewerThan1_19_R3;
|
||||
private final boolean isNewerThan1_20;
|
||||
private final boolean isNewerThan1_19;
|
||||
private final String serverVersion;
|
||||
@@ -55,14 +56,17 @@ public class VersionManagerImpl implements VersionManager {
|
||||
// Determine if the server version is newer than 1_19_R2 and 1_20_R1
|
||||
if (main_ver >= 20) {
|
||||
isNewerThan1_19_R2 = true;
|
||||
isNewerThan1_19_R3 = true;
|
||||
isNewerThan1_20 = true;
|
||||
isNewerThan1_19 = true;
|
||||
} else if (main_ver == 19) {
|
||||
isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
|
||||
isNewerThan1_19_R3 = Integer.parseInt(split[2].substring(1)) >= 3;
|
||||
isNewerThan1_20 = false;
|
||||
isNewerThan1_19 = true;
|
||||
} else {
|
||||
isNewerThan1_19_R2 = false;
|
||||
isNewerThan1_19_R3 = false;
|
||||
isNewerThan1_20 = false;
|
||||
isNewerThan1_19 = false;
|
||||
}
|
||||
@@ -96,6 +100,11 @@ public class VersionManagerImpl implements VersionManager {
|
||||
return isNewerThan1_19;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVersionNewerThan1_19_R3() {
|
||||
return isNewerThan1_19_R3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isVersionNewerThan1_19_R2() {
|
||||
|
||||
Reference in New Issue
Block a user