Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ProtocolLib v5, which is needed for 1.19.x #106

Merged
merged 5 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ paper = "1.19-R0.1-SNAPSHOT"

# Plugins
worldedit = "7.2.11"
protocollib = "4.8.0"
protocollib = "5.0.0-SNAPSHOT"

# Third party
bstats = "3.0.0"
Expand Down
38 changes: 26 additions & 12 deletions src/main/java/com/plotsquared/plothider/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.plothider.storage.BlockStorage;
import com.plotsquared.plothider.storage.palette.PalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainerType;
Expand All @@ -61,11 +60,11 @@ public class PacketHandler {
new PacketAdapter(main, ListenerPriority.NORMAL, PacketType.Play.Server.BLOCK_CHANGE) {
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
PlotPlayer<?> pp = BukkitUtil.adapt(player);
if (Permissions.hasPermission(pp, "plots.plothider.bypass")) { // Admin bypass
PlotPlayer<?> plotPlayer = BukkitUtil.adapt(player);
if (plotPlayer.hasPermission("plots.plothider.bypass")) { // Admin bypass
return;
}
World<?> world = pp.getLocation().getWorld();
World<?> world = plotPlayer.getLocation().getWorld();
if (!hasPlotArea(world)) { // Not a plot area
return;
}
Expand All @@ -74,7 +73,7 @@ public void onPacketSending(PacketEvent event) {
BlockPosition position = positions.read(0);
Location loc = Location.at(world, position.getX(), 0, position.getZ());
Plot plot = loc.getOwnedPlot();
if (plot != null && (plot.isDenied(pp.getUUID()) || (!plot.isAdded(pp.getUUID())
if (plot != null && (plot.isDenied(plotPlayer.getUUID()) || (!plot.isAdded(plotPlayer.getUUID())
&& plot.getFlag(HideFlag.class)))) {
event.setCancelled(true);
}
Expand All @@ -87,7 +86,7 @@ public void onPacketSending(PacketEvent event) {
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
PlotPlayer<?> plotPlayer = BukkitUtil.adapt(player);
if (Permissions.hasPermission(plotPlayer, "plots.plothider.bypass")) { // Admin bypass
if (plotPlayer.hasPermission("plots.plothider.bypass")) { // Admin bypass
return;
}
World<?> world = plotPlayer.getLocation().getWorld();
Expand Down Expand Up @@ -176,7 +175,7 @@ public void onPacketSending(PacketEvent event) {
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
PlotPlayer<?> plotPlayer = BukkitUtil.adapt(player);
if (Permissions.hasPermission(plotPlayer, "plots.plothider.bypass")) { // Admin bypass
if (plotPlayer.hasPermission("plots.plothider.bypass")) { // Admin bypass
return;
}

Expand Down Expand Up @@ -381,7 +380,7 @@ private static BitSet intToBitSet(int n) {
}

/**
* Worldaround method to dynamically inject fields into a custom non-implemented structure modifier.
* Workaround method to dynamically inject fields into a custom non-implemented structure modifier.
*
* @param structureModifier the custom structureModifier where to inject the fields
* @param type the structure modifier hold class type
Expand All @@ -390,10 +389,25 @@ private static void loadInternalFields(StructureModifier<?> structureModifier, C
List<Field> fields = getFields(type);

try {
Field data = StructureModifier.class.getDeclaredField("data");
data.setAccessible(true);
data.set(structureModifier, fields);
} catch (NoSuchFieldException | IllegalAccessException e) {
// New v5 management, "data" field has been removed since c5f05509531eb22e9a0580f07bc0bf17a901b729.
List<Object> fieldAccessors = new ArrayList<>(fields.size());
for (Field field : fields) {
fieldAccessors.add(com.comphenix.protocol.reflect.accessors.Accessors.getFieldAccessor(field));
}

Field accessors = StructureModifier.class.getDeclaredField("accessors");
accessors.setAccessible(true);
accessors.set(structureModifier, fieldAccessors);
} catch (NoSuchFieldException e) {
// Former v5 management.
try {
Field data = StructureModifier.class.getDeclaredField("data");
data.setAccessible(true);
data.set(structureModifier, fields);
} catch (NoSuchFieldException | IllegalAccessException ex) {
throw new RuntimeException(ex);
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/plotsquared/plothider/PlotHiderPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private void loadCaptions() throws IOException {
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
PlotPlayer<?> pp = BukkitUtil.adapt(player);
if (Permissions.hasPermission(pp, "plots.plothider.bypass")) {
PlotPlayer<?> plotPlayer = BukkitUtil.adapt(player);
if (plotPlayer.hasPermission("plots.plothider.bypass")) {
return;
}
Plot plot = pp.getCurrentPlot();
if (plot != null && (plot.isDenied(pp.getUUID()) || (!plot.isAdded(pp.getUUID()) && plot
Plot plot = plotPlayer.getCurrentPlot();
if (plot != null && (plot.isDenied(plotPlayer.getUUID()) || (!plot.isAdded(plotPlayer.getUUID()) && plot
.getFlag(HideFlag.class)))) {
Location to = event.getTo();
Location from = event.getFrom();
Expand Down