mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 09:05:47 +00:00
protocol lib added
This commit is contained in:
parent
37c411b2b0
commit
4682c50080
@ -61,6 +61,11 @@
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<!-- ProtocolLib Repo -->
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<!--Spigot API-->
|
||||
@ -84,11 +89,18 @@
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- BetterRTP -->
|
||||
<dependency>
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTP</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- ProtocolLib -->
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,96 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.portals.cmds;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
// The packet we will be modifying
|
||||
protected PacketContainer handle;
|
||||
|
||||
/**
|
||||
* Constructs a new strongly typed wrapper for the given packet.
|
||||
*
|
||||
* @param handle - handle to the raw packet data.
|
||||
* @param type - the packet type.
|
||||
*/
|
||||
protected AbstractPacket(PacketContainer handle, PacketType type) {
|
||||
// Make sure we're given a valid packet
|
||||
if (handle == null)
|
||||
throw new IllegalArgumentException("Packet handle cannot be NULL.");
|
||||
if (!Objects.equal(handle.getType(), type))
|
||||
throw new IllegalArgumentException(handle.getHandle()
|
||||
+ " is not a packet of type " + type);
|
||||
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a handle to the raw packet data.
|
||||
*
|
||||
* @return Raw packet data.
|
||||
*/
|
||||
public PacketContainer getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to the given receiver.
|
||||
*
|
||||
* @param receiver - the receiver.
|
||||
* @throws RuntimeException If the packet cannot be sent.
|
||||
*/
|
||||
public void sendPacket(Player receiver) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
|
||||
getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Cannot send packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to all online players.
|
||||
*/
|
||||
public void broadcastPacket() {
|
||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException If the packet cannot be received.
|
||||
* @deprecated Misspelled. recieve to receive
|
||||
* @see #receivePacket(Player)
|
||||
*/
|
||||
@Deprecated
|
||||
public void recievePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot recieve packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException if the packet cannot be received.
|
||||
*/
|
||||
public void receivePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot receive packet.", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,39 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.portals.cmds;
|
||||
|
||||
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.WrappedBlockData;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.addons.portals.AddonPortals;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class PortalsCommand_Loc1 implements PortalsCommands, LocationFinder {
|
||||
|
||||
private PacketContainer fakeBlock;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sendi, String label, String[] args, AddonPortals addonPortals) {
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.portals.cmds;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
|
||||
public class WrapperPlayServerBlockChange extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.BLOCK_CHANGE;
|
||||
|
||||
public WrapperPlayServerBlockChange() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerBlockChange(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Location.
|
||||
* <p>
|
||||
* Notes: block Coordinates
|
||||
*
|
||||
* @return The current Location
|
||||
*/
|
||||
public BlockPosition getLocation() {
|
||||
return handle.getBlockPositionModifier().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Location.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setLocation(BlockPosition value) {
|
||||
handle.getBlockPositionModifier().write(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the Bukkit Location.
|
||||
*
|
||||
* @param world World for the location
|
||||
* @return Bukkit Location
|
||||
*/
|
||||
public Location getBukkitLocation(World world) {
|
||||
return getLocation().toVector().toLocation(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Block Data.
|
||||
*
|
||||
* @return The current Block Data
|
||||
*/
|
||||
public WrappedBlockData getBlockData() {
|
||||
return handle.getBlockData().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Block Data.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setBlockData(WrappedBlockData value) {
|
||||
handle.getBlockData().write(0, value);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user