Merge pull request #36 from allinkdev/bugs

Fix bugs
This commit is contained in:
Telesphoreo 2022-05-02 12:58:37 -05:00 committed by GitHub
commit 6756f2db76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 1 deletions

View File

@ -4,14 +4,18 @@ import dev.plex.cache.PlayerCache;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.listener.annotation.Toggleable; import dev.plex.listener.annotation.Toggleable;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags; import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -19,6 +23,14 @@ import org.jetbrains.annotations.NotNull;
@Toggleable("chat.enabled") @Toggleable("chat.enabled")
public class ChatListener extends PlexListener public class ChatListener extends PlexListener
{ {
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig
.builder()
.match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
.replacement((matchResult, builder) -> Component.empty()
.content(matchResult.group())
.clickEvent(ClickEvent.openUrl(
matchResult.group()
))).build();
private final PlexChatRenderer renderer = new PlexChatRenderer(); private final PlexChatRenderer renderer = new PlexChatRenderer();
@EventHandler @EventHandler
@ -48,6 +60,8 @@ public class ChatListener extends PlexListener
@Override @Override
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer) public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
{ {
message = message.replaceText(URL_REPLACEMENT_CONFIG);
if (hasPrefix) if (hasPrefix)
{ {
return Component.empty() return Component.empty()

View File

@ -5,6 +5,7 @@ import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class FreezeListener extends PlexListener public class FreezeListener extends PlexListener
{ {
@ -17,4 +18,14 @@ public class FreezeListener extends PlexListener
e.setCancelled(true); e.setCancelled(true);
} }
} }
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e)
{
PlexPlayer player = DataUtils.getPlayer(e.getPlayer().getUniqueId());
if (player.isFrozen())
{
e.setCancelled(true);
}
}
} }

View File

@ -1,6 +1,7 @@
package dev.plex.listener.impl; package dev.plex.listener.impl;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.util.BlockUtils;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -55,7 +56,7 @@ public class SpawnListener extends PlexListener
if (SPAWN_EGGS.contains(itemType)) if (SPAWN_EGGS.contains(itemType))
{ {
Block block = event.getBlock(); Block block = event.getBlock();
Location blockLoc = block.getLocation().add(0.5, 0.5, 0.5).add(((Directional)block.getBlockData()).getFacing().getDirection().multiply(0.8)); Location blockLoc = BlockUtils.relative(block.getLocation(), ((Directional)block.getBlockData()).getFacing()).add(.5, 0, .5);
EntityType eggType = spawnEggToEntityType(itemType); EntityType eggType = spawnEggToEntityType(itemType);
if (eggType != null) if (eggType != null)
{ {

View File

@ -0,0 +1,21 @@
package dev.plex.util;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
public class BlockUtils
{
public static Location relative(Location origin, BlockFace face)
{
return switch (face)
{
case UP -> origin.add(0, 1, 0);
case DOWN -> origin.subtract(0, 1, 0);
case NORTH -> origin.subtract(0, 0, 1);
case SOUTH -> origin.add(0, 0, 1);
case WEST -> origin.subtract(1, 0, 0);
case EAST -> origin.add(1, 0, 0);
default -> origin.add(face.getModX(), face.getModY(), face.getModZ());
};
}
}