Skip to content

Commit

Permalink
Improve sign interaction handling (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Oct 4, 2023
1 parent 5d428d8 commit ee0d17b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -140,7 +140,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Worldguard dependency -->
Expand Down
Expand Up @@ -61,6 +61,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -3697,7 +3698,7 @@ static void banPlayer(Player player, String reason, String source)
else
{
BanList bans = Bukkit.getServer().getBanList(Type.NAME);
bans.addBan(player.getName(), reason, null, source);
bans.addBan(player.getName(), reason, (Date) null, source);

//kick
if (player.isOnline())
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.Waterlogged;
Expand Down Expand Up @@ -81,6 +80,7 @@
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerSignOpenEvent;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
Expand All @@ -92,6 +92,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BlockIterator;
import org.jetbrains.annotations.NotNull;

import java.net.InetAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -1171,7 +1172,7 @@ public void onPlayerTriggerRaid(RaidTriggerEvent event)
}

//when a player interacts with a specific part of entity...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event)
{
//treat it the same as interacting with an entity in general
Expand All @@ -1182,7 +1183,7 @@ public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event)
}

//when a player interacts with an entity...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
{
Player player = event.getPlayer();
Expand Down Expand Up @@ -1599,8 +1600,30 @@ public void onPlayerBucketFill(PlayerBucketFillEvent bucketEvent)
}
}

@EventHandler(priority = EventPriority.LOW)
void onPlayerSignOpen(@NotNull PlayerSignOpenEvent event)
{
if (event.getCause() != PlayerSignOpenEvent.Cause.INTERACT || event.getSign().getBlock().getType() != event.getSign().getType())
{
// If the sign is not opened by interaction or the corresponding block is no longer a sign,
// it is either the initial sign placement or another plugin is at work. Do not interfere.
return;
}

Player player = event.getPlayer();
String denial = instance.allowBuild(player, event.getSign().getLocation(), event.getSign().getType());

// If user is allowed to build, do nothing.
if (denial == null)
return;

// If user is not allowed to build, prevent sign UI opening and send message.
GriefPrevention.sendMessage(player, TextMode.Err, denial);
event.setCancelled(true);
}

//when a player interacts with the world
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOW)
void onPlayerInteract(PlayerInteractEvent event)
{
//not interested in left-click-on-air actions
Expand Down Expand Up @@ -1824,10 +1847,7 @@ else if (clickedBlock != null &&
clickedBlockType == Material.COMPARATOR ||
clickedBlockType == Material.REDSTONE_WIRE ||
Tag.FLOWER_POTS.isTagged(clickedBlockType) ||
Tag.CANDLES.isTagged(clickedBlockType) ||
// Only block interaction with un-editable signs to allow command signs to function.
// TODO: When we are required to update Spigot API to 1.20 to support a change, swap to Sign#isWaxed
Tag.SIGNS.isTagged(clickedBlockType) && clickedBlock.getState() instanceof Sign sign && sign.isEditable()
Tag.CANDLES.isTagged(clickedBlockType)
))
{
if (playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId());
Expand Down

0 comments on commit ee0d17b

Please sign in to comment.