mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 09:05:47 +00:00
protocol lib null pointer error
This commit is contained in:
parent
4682c50080
commit
628dd55b43
@ -101,6 +101,7 @@
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,8 +1,24 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.portals;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
||||
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.Main;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.addons.portals.cmds.WrapperPlayServerBlockChange;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PortalsCache {
|
||||
@ -21,10 +37,66 @@ public class PortalsCache {
|
||||
PortalsCreation portal;
|
||||
if (portalsBeingCreated.containsKey(p)) {
|
||||
portal = portalsBeingCreated.get(p);
|
||||
} else
|
||||
} else {
|
||||
portal = new PortalsCreation(p);
|
||||
portalsBeingCreated.put(p, portal);
|
||||
}
|
||||
Location old_loc1 = portal.loc_1;
|
||||
Location old_loc2 = portal.loc_1;
|
||||
if (loc2) portal.loc_2 = loc;
|
||||
else portal.loc_1 = loc;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
||||
WrapperPlayServerBlockChange block = new WrapperPlayServerBlockChange(pm.createPacket(PacketType.Play.Server.BLOCK_CHANGE));
|
||||
block.setBlockData(WrappedBlockData.createData(Material.GLOWSTONE));
|
||||
block.setLocation(new BlockPosition(loc.toVector()));
|
||||
block.sendPacket(p);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (portal.loc_1 != null && portal.loc_2 != null) {
|
||||
//if (Math.abs(portal.loc_1.getBlockX() - portal.loc_2.getBlockX()) <= 10)
|
||||
//if (Math.abs(portal.loc_1.getBlockZ() - portal.loc_2.getBlockZ()) <= 10)
|
||||
//if (Math.abs(portal.loc_1.getBlockY() - portal.loc_2.getBlockY()) <= 10) {
|
||||
preview(portal.loc_1, portal.loc_2);
|
||||
//}
|
||||
} else {
|
||||
p.sendMessage((portal.loc_1 == null) + " " + (portal.loc_2 == null));
|
||||
}
|
||||
}
|
||||
|
||||
private void preview(Location loc1, Location loc2) {
|
||||
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
||||
Bukkit.getScheduler().runTask(Main.getInstance(), () -> {
|
||||
PacketContainer packet = pm
|
||||
.createPacket(PacketType.Play.Server.MULTI_BLOCK_CHANGE);
|
||||
Chunk chunk = loc1.getChunk();
|
||||
ChunkCoordIntPair chunkcoords = new ChunkCoordIntPair(chunk.getX(),
|
||||
chunk.getZ());
|
||||
MultiBlockChangeInfo[] change = new MultiBlockChangeInfo[256];
|
||||
|
||||
|
||||
for (int x = 0; x <= 15; x++) {
|
||||
for(int z = 0; z <= 15; z++) {
|
||||
change[(16 * x) + z] = new MultiBlockChangeInfo(new Location(loc1.getWorld(), loc1.getX() + x, 100, loc1.getZ() + z), WrappedBlockData.createData(Material.GOLD_BLOCK));
|
||||
}
|
||||
}
|
||||
|
||||
packet.getChunkCoordIntPairs().write(0, chunkcoords);
|
||||
packet.getMultiBlockChangeInfoArrays().write(0, change);
|
||||
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
pm.sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public PortalsCreation getPortal(Player p) {
|
||||
|
@ -4,8 +4,10 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.addons.portals.AddonPortals;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -22,18 +24,6 @@ public class PortalsCommand_Loc1 implements PortalsCommands, LocationFinder {
|
||||
Player p = (Player) sendi;
|
||||
Location loc = getTargetBlock(p, 10).getLocation();
|
||||
addonPortals.getPortals().setPortal(p, loc, false);
|
||||
sendi.sendMessage("Location 1 set to this location " + loc.toString());
|
||||
//p.sendBlockChange(loc, Material.GLOWSTONE, (byte) 0);
|
||||
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
WrapperPlayServerBlockChange fakeBlock = new WrapperPlayServerBlockChange();
|
||||
fakeBlock.setLocation(BlockLocation);
|
||||
try {
|
||||
//System.out.println(fakeBlock.toString());
|
||||
protocolManager.sendServerPacket(p, fakeBlock);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(
|
||||
"Cannot send packet " + fakeBlock, e);
|
||||
}
|
||||
sendi.sendMessage("Location 1 set to this location!");
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ public class PortalsCommand_Loc2 implements PortalsCommands, LocationFinder {
|
||||
Player p = (Player) sendi;
|
||||
Location loc = getTargetBlock(p, 10).getLocation();
|
||||
addonPortals.getPortals().setPortal(p, loc, true);
|
||||
sendi.sendMessage("Location 2 set to this location " + loc.toString());
|
||||
sendi.sendMessage("Location 2 set to this location!");
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ version: 1.0
|
||||
api-version: '1.13'
|
||||
name: BetterRTPAddons
|
||||
depend: [BetterRTP]
|
||||
softdepend: [ProtocolLib]
|
||||
|
||||
permissions:
|
||||
betterrtp.addon.portals:
|
||||
|
Loading…
x
Reference in New Issue
Block a user