/u/AllDayWarrior
Guest
Member
Hello everyone,
I am trying to create a minecraft paper 1.21 plugin that makes you see only the chunk you are standing in and all other chunks including entities and players should be invisible. When you walk into a new chunk the old one should be invisible and the new one visible. I am not really a minecraft plugin developer so I am trying to get ai to make it for me. As of now I managed to make only 1 chunk visible and when I hit entities into the other chunks they dissapear. The only problem is that when I try to enter a new chunk I get an error in the console. When I log out in a new chunk which is still invisible and log back in it is visible though. But I want it to be doing that without having to relog. I will post my java code along with the xml and the console error when trying to load a new chunk in. (Plugin works with protocollib)
Java: package com.example.renderdistanceLimiter;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.*; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException; import java.util.*;
public class RenderDistanceLimiter extends JavaPlugin implements Listener, TabCompleter {
}
xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
</project>
Error when entering new chunk:
When trying to enter a new chunk the following code is projected into the server console:
01.08 11:50:40 [Server] INFO at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:56) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:151) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1537) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:201) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1514) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1507) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:114) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1629) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1304) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:330) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
submitted by /u/AllDayWarrior
[link] [comments]
Continue reading...
free plugins
minecraft paid for free
spigotmc
SpigotMC
free minecraft paid plugins
free minecraft plugins
aac free
ewg free
Minecraft Premium Plugins
ewg free download
litebans free
epicworldgenerator free
free schematics
leaked schematics minecraft
schematics
schematics leaked
schematics free
minecraft schematics free
paid minecraft schematics free
paid minecraft schematics for free
free cracked plugins
free cracked minecraft plugins
plugins
featherboard download
featherboard plugin download
antiaura download
minecraft plugins
xenforo leaked
xenforo for free
xenforo addons
I am trying to create a minecraft paper 1.21 plugin that makes you see only the chunk you are standing in and all other chunks including entities and players should be invisible. When you walk into a new chunk the old one should be invisible and the new one visible. I am not really a minecraft plugin developer so I am trying to get ai to make it for me. As of now I managed to make only 1 chunk visible and when I hit entities into the other chunks they dissapear. The only problem is that when I try to enter a new chunk I get an error in the console. When I log out in a new chunk which is still invisible and log back in it is visible though. But I want it to be doing that without having to relog. I will post my java code along with the xml and the console error when trying to load a new chunk in. (Plugin works with protocollib)
Java: package com.example.renderdistanceLimiter;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.*; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException; import java.util.*;
public class RenderDistanceLimiter extends JavaPlugin implements Listener, TabCompleter {
private ProtocolManager protocolManager; private final Set<UUID> exempt = new HashSet<>(); private final Map<Player, Set<Integer>> chunkEntities = new HashMap<>(); private final Map<UUID, int[]> crouchLoaded = new HashMap<>(); @Override public void onEnable() { protocolManager = ProtocolLibrary.getProtocolManager(); Bukkit.getPluginManager().registerEvents(this, this); this.getCommand("onechunk").setTabCompleter(this); protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent event) { Player player = event.getPlayer(); Location playerLocation = player.getLocation(); Chunk playerChunk = playerLocation.getChunk(); int chunkX = event.getPacket().getIntegers().read(0); int chunkZ = event.getPacket().getIntegers().read(1); if (chunkX != playerChunk.getX() || chunkZ != playerChunk.getZ()) { event.setCancelled(true); } } }); getLogger().info("[RenderDistanceLimiter]: Plugin is enabled"); } @Override public void onDisable() { getLogger().info("[RenderDistanceLimiter]: Plugin is disabled"); } @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); init(player); Bukkit.getServer().broadcast(Component.text("Welcome " + player.getName())); player.sendMessage("Welcome to Minecraft, but with only one chunk of render distance!"); } @EventHandler public void onLeave(PlayerQuitEvent event) { exempt.remove(event.getPlayer().getUniqueId()); chunkEntities.remove(event.getPlayer()); } @EventHandler public void onTeleport(PlayerTeleportEvent event) { init(event.getPlayer()); } @EventHandler public void onRespawn(PlayerRespawnEvent event) { init(event.getPlayer()); } @EventHandler public void onDimensionChange(PlayerChangedWorldEvent event) { Bukkit.getScheduler().runTaskLater(this, () -> init(event.getPlayer()), 5L); } @EventHandler public void onMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if (hasMovedToNewChunk(from, to)) { Player player = event.getPlayer(); if (!exempt.contains(player.getUniqueId())) { handlePlayerMove(player, from, to); } } } @EventHandler public void onCrouch(PlayerToggleSneakEvent event) { Player player = event.getPlayer(); if (!exempt.contains(player.getUniqueId()) && !player.isSneaking()) { handlePlayerCrouch(player); } } private boolean hasMovedToNewChunk(Location from, Location to) { return from.getChunk().getX() != to.getChunk().getX() || from.getChunk().getZ() != to.getChunk().getZ(); } private void init(Player player) { Set<Integer> chunkEntitiesSet = new HashSet<>(); Location location = player.getLocation(); int posX = location.getChunk().getX(); int posZ = location.getChunk().getZ(); sendWorldChunk(player, posX, posZ, false); sendFillerChunk(player, posX + 1, posZ); sendFillerChunk(player, posX - 1, posZ); sendFillerChunk(player, posX, posZ + 1); sendFillerChunk(player, posX, posZ - 1); for (Entity entity : location.getChunk().getEntities()) { showEntity(player, entity); chunkEntitiesSet.add(entity.getEntityId()); } chunkEntities.put(player, chunkEntitiesSet); } private void sendFillerChunk(Player player, int x, int z) { sendWorldChunk(player, x, z, true); } private void sendWorldChunk(Player player, int x, int z, boolean fillWithAir) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.MAP_CHUNK); packet.getIntegers().write(0, x); packet.getIntegers().write(1, z); if (fillWithAir) { packet.getByteArrays().write(0, new byte[0]); // Sending empty data for the filler chunk } else { packet.getByteArrays().write(0, new byte[0]); // Placeholder for real chunk data } try { protocolManager.sendServerPacket(player, packet); } catch (InvocationTargetException e) { e.printStackTrace(); } } private void showEntity(Player player, Entity entity) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.SPAWN_ENTITY); packet.getIntegers().write(0, entity.getEntityId()); packet.getUUIDs().write(0, entity.getUniqueId()); packet.getDoubles().write(0, entity.getLocation().getX()); packet.getDoubles().write(1, entity.getLocation().getY()); packet.getDoubles().write(2, entity.getLocation().getZ()); try { protocolManager.sendServerPacket(player, packet); } catch (InvocationTargetException e) { e.printStackTrace(); } } private void handlePlayerMove(Player player, Location from, Location to) { int fromX = from.getChunk().getX(); int fromZ = from.getChunk().getZ(); int toX = to.getChunk().getX(); int toZ = to.getChunk().getZ(); sendFillerChunk(player, toX + 1, toZ); sendFillerChunk(player, toX - 1, toZ); sendFillerChunk(player, toX, toZ + 1); sendFillerChunk(player, toX, toZ - 1); sendWorldChunk(player, toX, toZ, false); hideEntitiesInChunk(player, fromX, fromZ); showEntitiesInChunk(player, toX, toZ); } private void handlePlayerCrouch(Player player) { String direction = player.getFacing().name(); List<int[]> directions = new ArrayList<>(); if (crouchLoaded.containsKey(player.getUniqueId())) { int[] last = crouchLoaded.get(player.getUniqueId()); if (player.getLocation().getChunk().getX() != last[0] || player.getLocation().getChunk().getZ() != last[1]) { sendFillerChunk(player, last[0], last[1]); hideEntitiesInChunk(player, last[0], last[1]); } } int playerX = player.getLocation().getChunk().getX(); int playerZ = player.getLocation().getChunk().getZ(); switch (direction) { case "NORTH": directions.add(new int[]{0, -2, 1}); directions.add(new int[]{-1, -1, 1}); directions.add(new int[]{1, -1, 1}); directions.add(new int[]{0, -1, 0}); break; case "EAST": directions.add(new int[]{2, 0, 1}); directions.add(new int[]{1, -1, 1}); directions.add(new int[]{1, 1, 1}); directions.add(new int[]{1, 0, 0}); break; case "SOUTH": directions.add(new int[]{0, 2, 1}); directions.add(new int[]{1, 1, 1}); directions.add(new int[]{-1, 1, 1}); directions.add(new int[]{0, 1, 0}); break; case "WEST": directions.add(new int[]{-2, 0, 1}); directions.add(new int[]{-1, 1, 1}); directions.add(new int[]{-1, -1, 1}); directions.add(new int[]{-1, 0, 0}); break; } for (int[] offset : directions) { boolean fillWithAir = offset[2] != 0; sendWorldChunk(player, playerX + offset[0], playerZ + offset[1], fillWithAir); if (!fillWithAir) { int[] crouchChunk = new int[]{playerX + offset[0], playerZ + offset[1]}; crouchLoaded.put(player.getUniqueId(), crouchChunk); showEntitiesInChunk(player, crouchChunk[0], crouchChunk[1]); } } } private void hideEntitiesInChunk(Player player, int x, int z) { World world = player.getWorld(); Chunk chunk = world.getChunkAt(x, z); for (Entity entity : chunk.getEntities()) { hideEntity(player, entity); } } private void showEntitiesInChunk(Player player, int x, int z) { World world = player.getWorld(); Chunk chunk = world.getChunkAt(x, z); for (Entity entity : chunk.getEntities()) { showEntity(player, entity); } } private void hideEntity(Player player, Entity entity) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_DESTROY); packet.getIntegerArrays().write(0, new int[]{entity.getEntityId()}); try { protocolManager.sendServerPacket(player, packet); } catch (InvocationTargetException e) { e.printStackTrace(); } } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("You must be a player to use this command."); return false; } Player player = (Player) sender; if (command.getName().equalsIgnoreCase("seeall")) { if (!sender.hasPermission("OneChunk.seeall")) { sender.sendMessage("You do not have permission."); return true; } exempt.add(player.getUniqueId()); for (Chunk chunk : player.getWorld().getLoadedChunks()) { showEntitiesInChunk(player, chunk.getX(), chunk.getZ()); } return true; } if (command.getName().equalsIgnoreCase("onechunk")) { if (args.length == 0) { sender.sendMessage("Arguments are required."); return true; } if (args[0].equalsIgnoreCase("disableCrouchLoading")) { if (!sender.hasPermission("OneChunk.SetCrouchStatus")) { sender.sendMessage("You do not have permission."); return true; } getConfig().set("OneChunk.CrouchingEnabled", false); saveConfig(); reloadConfig(); sender.sendMessage("Crouch loading disabled."); return true; } if (args[0].equalsIgnoreCase("enableCrouchLoading")) { if (!sender.hasPermission("OneChunk.SetCrouchStatus")) { sender.sendMessage("You do not have permission."); return true; } getConfig().set("OneChunk.CrouchingEnabled", true); saveConfig(); reloadConfig(); sender.sendMessage("Crouch loading enabled."); return true; } } return true; } @Override public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { if (sender.hasPermission("OneChunk.SetCrouchStatus") && args.length == 1) { return Arrays.asList("disableCrouchLoading", "enableCrouchLoading"); } return Collections.emptyList(); }
}
xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId> <artifactId>renderdistancelimiter</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <repositories> <repository> <id>papermc</id> <url>https://repo.papermc.io/repository/maven-public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>io.papermc.paper</groupId> <artifactId>paper-api</artifactId> <version>1.21-R0.1-SNAPSHOT</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.comphenix.protocol</groupId> <artifactId>ProtocolLib</artifactId> <version>5.1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> </configuration> </plugin> </plugins> </build>
</project>
Error when entering new chunk:
When trying to enter a new chunk the following code is projected into the server console:
01.08 11:50:40 [Server] INFO at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:56) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:151) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1537) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:201) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1514) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1507) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:114) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1629) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1304) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:330) ~[paper-1.21.jar:1.21-119-100d75a] 01.08 11:50:40 [Server] INFO at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
submitted by /u/AllDayWarrior
[link] [comments]
Continue reading...
free plugins
minecraft paid for free
spigotmc
SpigotMC
free minecraft paid plugins
free minecraft plugins
aac free
ewg free
Minecraft Premium Plugins
ewg free download
litebans free
epicworldgenerator free
free schematics
leaked schematics minecraft
schematics
schematics leaked
schematics free
minecraft schematics free
paid minecraft schematics free
paid minecraft schematics for free
free cracked plugins
free cracked minecraft plugins
plugins
featherboard download
featherboard plugin download
antiaura download
minecraft plugins
xenforo leaked
xenforo for free
xenforo addons