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

Improve sign interaction handling #2142

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 pom.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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