Handle invalid translations

This commit is contained in:
mathiascode 2020-01-04 23:17:55 +02:00
parent 2f6081a62c
commit 03b66ccb2c
9 changed files with 87 additions and 8 deletions

View file

@ -17,6 +17,11 @@
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
<repositories>
@ -24,6 +29,10 @@
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/content/groups/public/</url>
</repository>
</repositories>
<build>

View file

@ -2,6 +2,11 @@ package pw.kaboom.extras;
import java.util.Collections;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.java.JavaPlugin;
@ -424,6 +429,17 @@ public final class Main extends JavaPlugin {
this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks());
this.getCommand("username").setExecutor(new CommandUsername());
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
@Override
public void onPacketReceiving(PacketEvent event) {
final int maxInventorySize = 46;
if (event.getPacket().getIntegers().read(1) > maxInventorySize ||
event.getPacket().getIntegers().read(1) < 0) {
event.setCancelled(true);
}
}
});
/* Block-related modules */
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
this.getServer().getPluginManager().registerEvents(new BlockPhysics(), this);

View file

@ -3,6 +3,8 @@ package pw.kaboom.extras.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -19,6 +21,9 @@ public final class CommandClearChat implements CommandExecutor {
}
onlinePlayer.sendMessage(ChatColor.DARK_GREEN + "The chat has been cleared");
}
//for (final Chunk chunk : ((Player)sender).getWorld().getLoadedChunks()) {
// ((Player)sender).getWorld().regenerateChunk(chunk.getX(), chunk.getZ());
// }
return true;
}
}

View file

@ -9,13 +9,13 @@ import org.bukkit.event.block.SignChangeEvent;
public final class BlockCheck implements Listener {
@EventHandler
void onBlockPlace(final BlockPlaceEvent event) {
final int maxItemStringLength = 3019;
if (event.getItemInHand().toString().length() > maxItemStringLength) {
event.setCancelled(true);
}
try {
final int maxItemStringLength = 3019;
if (event.getItemInHand().toString().length() > maxItemStringLength) {
event.setCancelled(true);
}
event.getBlockPlaced().getState();
} catch (Exception exception) {
event.setCancelled(true);

View file

@ -5,6 +5,7 @@ import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -94,6 +95,16 @@ public final class BlockPhysics implements Listener {
event.setCancelled(true);
}
break;
case SIGN:
case WALL_SIGN:
/*try {
event.getBlock().getState();
event.getSourceBlock().getState();
} catch (Exception exception) {
event.getBlock().setType(Material.AIR, false);
event.setCancelled(true);
}*/
break;
case TNT:
for (BlockFace face : blockFaces) {
if (event.getBlock().getRelative(face).getType() != Material.REDSTONE_BLOCK

View file

@ -7,18 +7,34 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.helpers.SkinDownloader;
public final class PlayerConnection implements Listener {
/*public static boolean isIllegalItem(ItemStack item) {
//try {
if (item != null &&
item.getItemMeta() != null) {
System.out.println("itit");
System.out.println(item.getItemMeta().getDisplayName());
}
/*} catch (Exception | StackOverflowError exception) {
System.out.println("yes");
return true;
}
return false;
}*/
@EventHandler
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
if (event.getName().length() > 16) {
@ -32,6 +48,15 @@ public final class PlayerConnection implements Listener {
}
}
/*@EventHandler
void onInventoryClose(InventoryCloseEvent event) {
for (ItemStack item : event.getInventory().getContents()) {
if (isIllegalItem(item)) {
event.getInventory().clear();
}
}
}*/
@EventHandler
void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
@ -98,7 +123,7 @@ public final class PlayerConnection implements Listener {
PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
SkinDownloader.skinInProgress.remove(event.getPlayer().getUniqueId());
final World world = event.getPlayer().getWorld();
/*final World world = event.getPlayer().getWorld();
for (final Chunk chunk : world.getLoadedChunks()) {
try {
@ -113,6 +138,6 @@ public final class PlayerConnection implements Listener {
} catch (Exception exception) {
world.regenerateChunk(chunk.getX(), chunk.getZ());
}
}
}*/
}
}

View file

@ -5,11 +5,21 @@ import java.util.UUID;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public final class PlayerInteract implements Listener {
static HashMap<UUID, Long> interactMillisList = new HashMap<UUID, Long>();
@EventHandler
void onInventoryClick(final InventoryClickEvent event) {
try {
event.getSlot();
} catch (Exception exception) {
event.setCancelled(true);
}
}
@EventHandler
void onPlayerInteract(final PlayerInteractEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();

View file

@ -32,6 +32,8 @@ public final class ServerCommand implements Listener {
if ("run".equalsIgnoreCase(arr[i])) {
if (i + 1 < arr.length) {
if ("execute".equalsIgnoreCase(arr[i + 1])
|| "clone".equalsIgnoreCase(arr[i + 1])
|| "fill".equalsIgnoreCase(arr[i + 1])
|| "particle".equalsIgnoreCase(arr[i + 1])
|| "save-off".equalsIgnoreCase(arr[i + 1])
|| "spreadplayers".equalsIgnoreCase(arr[i + 1])

View file

@ -1,6 +1,7 @@
name: Extras
main: pw.kaboom.extras.Main
description: Plugin that adds extra functionality to the server.
depend: [ProtocolLib]
api-version: 1.13
version: master