Fix compilation errors

This commit is contained in:
Telesphoreo 2023-08-25 17:31:06 -05:00
parent 68562146c6
commit db8afa5001
4 changed files with 99 additions and 42 deletions

View File

@ -3,20 +3,19 @@ plugins {
} }
group = "dev.plex" group = "dev.plex"
version = "1.0" version = "1.4-SNAPSHOT"
description = "Module-FalseOp" description = "Module-FalseOp"
repositories { repositories {
mavenCentral() mavenCentral()
maven { url "https://repo.papermc.io/repository/maven-public/" } maven { url "https://repo.papermc.io/repository/maven-public/" }
// maven { url "https://nexus.telesphoreo.me/repository/plex/" } maven { url "https://nexus.telesphoreo.me/repository/plex/" }
maven { url "https://repo.dmulloy2.net/repository/public/" } maven { url "https://repo.dmulloy2.net/repository/public/" }
} }
dependencies { dependencies {
compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT" compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT"
// compileOnly "dev.plex:server:1.3" compileOnly "dev.plex:server:1.4-SNAPSHOT"
compileOnly files("libs/Plex-1.4-SNAPSHOT.jar")
implementation "com.comphenix.protocol:ProtocolLib:5.1.0" implementation "com.comphenix.protocol:ProtocolLib:5.1.0"
} }

View File

@ -5,11 +5,13 @@ import dev.plex.module.PlexModule;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class FalseOp extends PlexModule { public class FalseOp extends PlexModule
{
@Override @Override
public void enable() { public void enable()
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) { {
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"))
{
PlexLog.error("The Plex-FalseOp module requires the ProtocolLib plugin to work."); PlexLog.error("The Plex-FalseOp module requires the ProtocolLib plugin to work.");
return; return;
} }
@ -17,7 +19,7 @@ public class FalseOp extends PlexModule {
} }
@Override @Override
public void disable() { public void disable()
// {
} }
} }

View File

@ -24,14 +24,18 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class PlayerListener extends PlexListener { public class PlayerListener extends PlexListener
{
private final ProtocolManager protocolManager; private final ProtocolManager protocolManager;
public PlayerListener() {
public PlayerListener()
{
protocolManager = ProtocolLibrary.getProtocolManager(); protocolManager = ProtocolLibrary.getProtocolManager();
} }
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event)
{
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS); PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS);
packet.getIntegers().write(0, event.getPlayer().getEntityId()); packet.getIntegers().write(0, event.getPlayer().getEntityId());
packet.getBytes().write(0, (byte) 28); packet.getBytes().write(0, (byte) 28);
@ -39,84 +43,136 @@ public class PlayerListener extends PlexListener {
} }
@EventHandler @EventHandler
private void onBlock(PlayerInteractEvent event) { private void onBlock(PlayerInteractEvent event)
if (event.useInteractedBlock() == Event.Result.DENY) return; {
if (event.useInteractedBlock() == Event.Result.DENY)
{
return;
}
var type = event.getMaterial(); var type = event.getMaterial();
var player = event.getPlayer(); var player = event.getPlayer();
Block clicked = event.getClickedBlock(); Block clicked = event.getClickedBlock();
if (clicked == null) return; if (clicked == null)
{
return;
}
boolean canPlace = player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SURVIVAL; boolean canPlace = player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SURVIVAL;
boolean canBreak = player.getGameMode() == GameMode.CREATIVE; boolean canBreak = player.getGameMode() == GameMode.CREATIVE;
if (player.getGameMode() == GameMode.ADVENTURE) { if (player.getGameMode() == GameMode.ADVENTURE)
{
ItemStack item = event.getItem(); ItemStack item = event.getItem();
if (item != null) { if (item != null)
{
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta != null) { if (meta != null)
{
canPlace = meta.getPlaceableKeys().contains(clicked.getType().getKey()); canPlace = meta.getPlaceableKeys().contains(clicked.getType().getKey());
canBreak = meta.getDestroyableKeys().contains(clicked.getType().getKey()); canBreak = meta.getDestroyableKeys().contains(clicked.getType().getKey());
} }
} }
} }
boolean clickedTargetBlock = clicked.getType() == Material.COMMAND_BLOCK || clicked.getType() == Material.CHAIN_COMMAND_BLOCK || clicked.getType() == Material.REPEATING_COMMAND_BLOCK || clicked.getType() == Material.STRUCTURE_BLOCK || clicked.getType() == Material.JIGSAW; boolean clickedTargetBlock = clicked.getType() == Material.COMMAND_BLOCK || clicked.getType() == Material.CHAIN_COMMAND_BLOCK || clicked.getType() == Material.REPEATING_COMMAND_BLOCK || clicked.getType() == Material.STRUCTURE_BLOCK || clicked.getType() == Material.JIGSAW;
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (type == Material.COMMAND_BLOCK || type == Material.CHAIN_COMMAND_BLOCK || type == Material.REPEATING_COMMAND_BLOCK || type == Material.STRUCTURE_BLOCK || type == Material.JIGSAW) && (!clickedTargetBlock || player.isSneaking())) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (type == Material.COMMAND_BLOCK || type == Material.CHAIN_COMMAND_BLOCK || type == Material.REPEATING_COMMAND_BLOCK || type == Material.STRUCTURE_BLOCK || type == Material.JIGSAW) && (!clickedTargetBlock || player.isSneaking()))
if (!canPlace) return; {
if (isInteractable(clicked.getType()) && !player.isSneaking()) return; if (!canPlace)
{
return;
}
if (isInteractable(clicked.getType()) && !player.isSneaking())
{
return;
}
Location loc = clicked.isReplaceable() ? clicked.getLocation() : clicked.getLocation().add(event.getBlockFace().getDirection()); Location loc = clicked.isReplaceable() ? clicked.getLocation() : clicked.getLocation().add(event.getBlockFace().getDirection());
Block block = loc.getBlock(); Block block = loc.getBlock();
if (!block.isReplaceable()) return; if (!block.isReplaceable())
if (!block.getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5).isEmpty()) return; {
return;
}
if (!block.getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5).isEmpty())
{
return;
}
Material oldType = block.getType(); Material oldType = block.getType();
BlockData oldData = block.getBlockData(); BlockData oldData = block.getBlockData();
block.setType(type); block.setType(type);
BlockFace face = calcVecBlockFace(player.getLocation().getDirection()); BlockFace face = calcVecBlockFace(player.getLocation().getDirection());
if (block.getBlockData() instanceof Directional directional) { if (block.getBlockData() instanceof Directional directional)
{
directional.setFacing(face.getOppositeFace()); directional.setFacing(face.getOppositeFace());
block.setBlockData(directional); block.setBlockData(directional);
} }
BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), clicked, event.getItem(), player, true, player.getHandRaised()); BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), clicked, event.getItem(), player, true, player.getHandRaised());
plugin.getServer().getPluginManager().callEvent(placeEvent); plugin.getServer().getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled()) { if (placeEvent.isCancelled())
{
block.setType(oldType); block.setType(oldType);
block.setBlockData(oldData); block.setBlockData(oldData);
return; return;
} }
if (player.getGameMode() != GameMode.CREATIVE && event.getItem() != null) event.getItem().setAmount(event.getItem().getAmount() - 1); if (player.getGameMode() != GameMode.CREATIVE && event.getItem() != null)
{
event.getItem().setAmount(event.getItem().getAmount() - 1);
}
player.closeInventory(); player.closeInventory();
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK && clickedTargetBlock) { }
if (!canBreak) return; else if (event.getAction() == Action.LEFT_CLICK_BLOCK && clickedTargetBlock)
if (event.getItem() != null && (EnchantmentTarget.WEAPON.includes(event.getItem().getType()) || event.getItem().getType() == Material.DEBUG_STICK || event.getItem().getType() == Material.TRIDENT)) return; {
if (!canBreak)
{
return;
}
if (event.getItem() != null && (EnchantmentTarget.WEAPON.includes(event.getItem().getType()) || event.getItem().getType() == Material.DEBUG_STICK || event.getItem().getType() == Material.TRIDENT))
{
return;
}
BlockBreakEvent breakEvent = new BlockBreakEvent(clicked, player); BlockBreakEvent breakEvent = new BlockBreakEvent(clicked, player);
plugin.getServer().getPluginManager().callEvent(breakEvent); plugin.getServer().getPluginManager().callEvent(breakEvent);
if (breakEvent.isCancelled()) return; if (breakEvent.isCancelled())
{
return;
}
clicked.breakNaturally(event.getItem()); clicked.breakNaturally(event.getItem());
} }
} }
private static BlockFace calcVecBlockFace(Vector vector) { private static BlockFace calcVecBlockFace(Vector vector)
{
double x = Math.abs(vector.getX()); double x = Math.abs(vector.getX());
double y = Math.abs(vector.getY()); double y = Math.abs(vector.getY());
double z = Math.abs(vector.getZ()); double z = Math.abs(vector.getZ());
if (x > z) { if (x > z)
if (x > y) { {
if (x > y)
{
return calcFacing(vector.getX(), BlockFace.EAST, BlockFace.WEST); return calcFacing(vector.getX(), BlockFace.EAST, BlockFace.WEST);
} else { }
else
{
return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN); return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN);
} }
} else { }
if (z > y) { else
{
if (z > y)
{
return calcFacing(vector.getZ(), BlockFace.SOUTH, BlockFace.NORTH); return calcFacing(vector.getZ(), BlockFace.SOUTH, BlockFace.NORTH);
} else { }
else
{
return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN); return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN);
} }
} }
} }
private static BlockFace calcFacing(double value, BlockFace positive, BlockFace negative) { private static BlockFace calcFacing(double value, BlockFace positive, BlockFace negative)
{
return value > 0 ? positive : negative; return value > 0 ? positive : negative;
} }
private boolean isInteractable(Material material) { private boolean isInteractable(Material material)
return switch (material) { {
return switch (material)
{
case BREWING_STAND, CAKE, CHEST, HOPPER, TRAPPED_CHEST, ENDER_CHEST, CAULDRON, COMMAND_BLOCK, REPEATING_COMMAND_BLOCK, CHAIN_COMMAND_BLOCK, BEACON, REPEATER, COMPARATOR, BARREL, DISPENSER, DROPPER, LEVER, CRAFTING_TABLE, CARTOGRAPHY_TABLE, SMITHING_TABLE, ENCHANTING_TABLE, FLETCHING_TABLE, BLAST_FURNACE, LOOM, GRINDSTONE, FURNACE, STONECUTTER, BELL, DAYLIGHT_DETECTOR, JIGSAW, STRUCTURE_BLOCK -> case BREWING_STAND, CAKE, CHEST, HOPPER, TRAPPED_CHEST, ENDER_CHEST, CAULDRON, COMMAND_BLOCK, REPEATING_COMMAND_BLOCK, CHAIN_COMMAND_BLOCK, BEACON, REPEATER, COMPARATOR, BARREL, DISPENSER, DROPPER, LEVER, CRAFTING_TABLE, CARTOGRAPHY_TABLE, SMITHING_TABLE, ENCHANTING_TABLE, FLETCHING_TABLE, BLAST_FURNACE, LOOM, GRINDSTONE, FURNACE, STONECUTTER, BELL, DAYLIGHT_DETECTOR, JIGSAW, STRUCTURE_BLOCK ->
true; true;
default -> default ->

View File

@ -1,4 +1,4 @@
name: Module-FalseOp name: Module-FalseOp
main: dev.plex.FalseOp main: dev.plex.FalseOp
description: Make clients think they have OP! description: Make clients think they have OP!
version: 1.0 version: 1.4-SNAPSHOT