diff --git a/src/main/java/pw/kaboom/extras/helpers/MessageInterceptingCommandRunner.java b/src/main/java/pw/kaboom/extras/helpers/MessageInterceptingCommandRunner.java new file mode 100644 index 0000000..ea763f9 --- /dev/null +++ b/src/main/java/pw/kaboom/extras/helpers/MessageInterceptingCommandRunner.java @@ -0,0 +1,167 @@ +package pw.kaboom.extras.helpers; + +import java.util.Set; + +import javax.annotation.Nullable; + +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationAbandonedEvent; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; + +public class MessageInterceptingCommandRunner implements ConsoleCommandSender { + private final ConsoleCommandSender wrappedSender; + private final Spigot spigotWrapper; + + private class Spigot extends CommandSender.Spigot { + /** + * Sends this sender a chat component. + * + * @param component the components to send + */ + @Override + public final void sendMessage(final @NotNull net.md_5.bungee.api.chat.BaseComponent component) { + wrappedSender.spigot().sendMessage(); + } + + /** + * Sends an array of components as a single message to the sender. + * + * @param components the components to send + */ + @Override + public final void sendMessage(final @NotNull net.md_5.bungee.api.chat.BaseComponent... components) { + wrappedSender.spigot().sendMessage(components); + } + } + + public MessageInterceptingCommandRunner(final ConsoleCommandSender wrappedSenderIn) { + this.wrappedSender = wrappedSenderIn; + spigotWrapper = new Spigot(); + } + + @Override + public final void sendMessage(final @NotNull String message) { + wrappedSender.sendMessage(message.substring(0, Math.min(message.length(), 256))); + } + + @Override + public final void sendMessage(final @NotNull String[] messages) { + wrappedSender.sendMessage(messages); + } + + @Override + public final @NotNull Server getServer() { + return wrappedSender.getServer(); + } + + @Override + public final @NotNull String getName() { + return "OrderFulfiller"; + } + + @Override + public final @NotNull CommandSender.Spigot spigot() { + return spigotWrapper; + } + + @Override + public final boolean isConversing() { + return wrappedSender.isConversing(); + } + + @Override + public final void acceptConversationInput(final @NotNull String input) { + wrappedSender.acceptConversationInput(input); + } + + @Override + public final boolean beginConversation(final @NotNull Conversation conversation) { + return wrappedSender.beginConversation(conversation); + } + + @Override + public final void abandonConversation(final @NotNull Conversation conversation) { + wrappedSender.abandonConversation(conversation); + } + + @Override + public final void abandonConversation(final @NotNull Conversation conversation, final @NotNull ConversationAbandonedEvent details) { + wrappedSender.abandonConversation(conversation, details); + } + + @Override + public final void sendRawMessage(final @NotNull String message) { + wrappedSender.sendRawMessage(message.substring(0, Math.min(message.length(), 256))); + } + + @Override + public final boolean isPermissionSet(final @NotNull String name) { + return wrappedSender.isPermissionSet(name); + } + + @Override + public final boolean isPermissionSet(final @NotNull Permission perm) { + return wrappedSender.isPermissionSet(perm); + } + + @Override + public final boolean hasPermission(final @NotNull String name) { + return wrappedSender.hasPermission(name); + } + + @Override + public final boolean hasPermission(final @NotNull Permission perm) { + return wrappedSender.hasPermission(perm); + } + + @Override + public final @NotNull PermissionAttachment addAttachment(final @NotNull Plugin plugin, final @NotNull String name, final boolean value) { + return wrappedSender.addAttachment(plugin, name, value); + } + + @Override + public final @NotNull PermissionAttachment addAttachment(final @NotNull Plugin plugin) { + return wrappedSender.addAttachment(plugin); + } + + @Override + public final @Nullable PermissionAttachment addAttachment(final @NotNull Plugin plugin, final @NotNull String name, final boolean value, final int ticks) { + return wrappedSender.addAttachment(plugin, name, value, ticks); + } + + @Override + public final @Nullable PermissionAttachment addAttachment(final @NotNull Plugin plugin, final int ticks) { + return wrappedSender.addAttachment(plugin, ticks); + } + + @Override + public final void removeAttachment(final @NotNull PermissionAttachment attachment) { + wrappedSender.removeAttachment(attachment); + } + + @Override + public final void recalculatePermissions() { + wrappedSender.recalculatePermissions(); + } + + @Override + public final @NotNull Set getEffectivePermissions() { + return wrappedSender.getEffectivePermissions(); + } + + @Override + public final boolean isOp() { + return wrappedSender.isOp(); + } + + @Override + public final void setOp(final boolean value) { + wrappedSender.setOp(value); + } +} \ No newline at end of file diff --git a/src/main/java/pw/kaboom/extras/helpers/NotNull.java b/src/main/java/pw/kaboom/extras/helpers/NotNull.java new file mode 100644 index 0000000..1964ee5 --- /dev/null +++ b/src/main/java/pw/kaboom/extras/helpers/NotNull.java @@ -0,0 +1,5 @@ +package pw.kaboom.extras.helpers; + +public @interface NotNull { + +} diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java b/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java index 51046f7..981b623 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java @@ -30,31 +30,6 @@ public final class BlockCheck implements Listener { } } - /*@EventHandler - void onPlayerPortal(final PlayerPortalEvent event) { - event.setCancelled(true); - event.getPlayer().teleportAsync(event.getTo()); - event.getPortalTravelAgent().findOrCreate(event.getTo()); - }*/ - - /*@EventHandler - void onPortalCreate(final PortalCreateEvent event) { - if (CreateReason.OBC_DESTINATION.equals(event.getReason())) { - event.setCancelled(true); - - for (Block block : event.getBlocks()) { - - System.out.println(block.getLocation().toString()); - } - } - }*/ - - /*@Subscribe - public void onEditSessionEvent(final EditSessionEvent event) { - event.setExtent(new NullExtent()); - - }*/ - @EventHandler void onSignChange(final SignChangeEvent event) { try { diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index 0b39358..8a9ef85 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -111,23 +111,9 @@ public final class BlockPhysics implements Listener { event.setCancelled(true); } return; - case TNT: - for (BlockFace face : getBlockFaces()) { - if (event.getBlock().getRelative(face).getType() != Material.REDSTONE_BLOCK - && event.getBlock().getRelative(face).getType() != Material.REDSTONE_TORCH) { - return; - } - } - return; default: break; } - - /*if (!event.getBlock().getType().isSolid()) { - for (BlockFace face : blockFaces) { - event.getBlock().getRelative(face).getType(); - } - }*/ } catch (Exception e) { event.setCancelled(true); } diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java index 9da4d74..f9316da 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -1,7 +1,8 @@ package pw.kaboom.extras.modules.entity; +import java.util.Random; + import org.bukkit.Chunk; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; @@ -20,6 +21,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.weather.LightningStrikeEvent; @@ -85,7 +87,7 @@ public final class EntitySpawn implements Listener { final int worldTntCount = !isAddToWorldEvent ? world.getEntitiesByClass(TNTPrimed.class).size() + 1 : world.getEntitiesByClass(TNTPrimed.class).size(); - final int worldTntCountLimit = 100; + final int worldTntCountLimit = 200; if (worldTntCount >= worldTntCountLimit) { return true; @@ -136,39 +138,9 @@ public final class EntitySpawn implements Listener { } } - public static Location limitLocation(final Location location) { - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - - final int maxValue = 30000000; - final int minValue = -30000000; - - if (x > maxValue) { - x = maxValue; - } - if (x < minValue) { - x = minValue; - } - if (y > maxValue) { - y = maxValue; - } - if (y < minValue) { - y = minValue; - } - if (z > maxValue) { - z = maxValue; - } - if (z < minValue) { - z = minValue; - } - - return new Location(location.getWorld(), x, y, z); - } - private void limitSlimeSize(final Slime slime) { - if (slime.getSize() > 50) { - slime.setSize(50); + if (slime.getSize() > 20) { + slime.setSize(20); } } @@ -202,19 +174,19 @@ public final class EntitySpawn implements Listener { @EventHandler void onEntityAddToWorld(final EntityAddToWorldEvent event) { final Entity entity = event.getEntity(); - final double x = entity.getLocation().getX(); - final double y = entity.getLocation().getY(); - final double z = entity.getLocation().getZ(); - - if (isOutsideBoundaries(x, y, z)) { - entity.remove(); - return; - } - - final World world = entity.getWorld(); final Chunk chunk = entity.getChunk(); if (chunk.isLoaded()) { + final double x = entity.getLocation().getX(); + final double y = entity.getLocation().getY(); + final double z = entity.getLocation().getZ(); + + if (isOutsideBoundaries(x, y, z)) { + entity.remove(); + return; + } + + final World world = entity.getWorld(); final EntityType entityType = entity.getType(); final boolean isAddToWorldEvent = true; @@ -223,13 +195,13 @@ public final class EntitySpawn implements Listener { entity.remove(); return; } + + if (checkShouldRemoveEntities(world)) { + return; + } } applyEntityChanges(entity); - - if (chunk.isLoaded()) { - checkShouldRemoveEntities(world); - } } @EventHandler @@ -266,6 +238,15 @@ public final class EntitySpawn implements Listener { applyEntityChanges(entity); } + @EventHandler + void onItemSpawn(final ItemSpawnEvent event) { + try { + event.getEntity().getItemStack().getItemMeta(); + } catch (Exception exception) { + event.setCancelled(true); + } + } + @EventHandler void onLightningStrike(final LightningStrikeEvent event) { final LightningStrike lightning = event.getLightning(); @@ -325,7 +306,7 @@ public final class EntitySpawn implements Listener { case EXPLOSION: case FIRE: case REDSTONE: - if (event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 100) { + if (new Random().nextBoolean()) { event.setCancelled(true); } return; diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntityTeleport.java b/src/main/java/pw/kaboom/extras/modules/entity/EntityTeleport.java index 001d0fc..bbf9869 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntityTeleport.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntityTeleport.java @@ -1,13 +1,43 @@ package pw.kaboom.extras.modules.entity; +import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; - import org.bukkit.event.entity.EntityTeleportEvent; public final class EntityTeleport implements Listener { + public static Location limitLocation(final Location location) { + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + + final int maxValue = 30000000; + final int minValue = -30000000; + + if (x > maxValue) { + x = maxValue; + } + if (x < minValue) { + x = minValue; + } + if (y > maxValue) { + y = maxValue; + } + if (y < minValue) { + y = minValue; + } + if (z > maxValue) { + z = maxValue; + } + if (z < minValue) { + z = minValue; + } + + return new Location(location.getWorld(), x, y, z); + } + @EventHandler void onEntityTeleport(final EntityTeleportEvent event) { - event.setTo(EntitySpawn.limitLocation(event.getTo())); + event.setTo(limitLocation(event.getTo())); } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java index c0cdd31..9b80582 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java @@ -43,6 +43,11 @@ public final class PlayerCommand implements Listener { event.setMessage(checkedCommand); } } + + /*final MessageInterceptingCommandRunner cmdRunner = new MessageInterceptingCommandRunner(Bukkit.getConsoleSender()); + Bukkit.dispatchCommand(cmdRunner, event.getMessage().substring(1)); + + event.setCancelled(true);*/ } public static HashMap getCommandMillisList() { diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 901e61a..0e65fc8 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -1,15 +1,11 @@ package pw.kaboom.extras.modules.player; -import java.io.File; -import java.io.IOException; +import java.util.HashSet; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.GameRule; import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -23,33 +19,12 @@ import org.bukkit.event.player.PlayerStatisticIncrementEvent; import org.bukkit.plugin.java.JavaPlugin; import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; -import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; import com.google.common.base.Charsets; import pw.kaboom.extras.Main; -import pw.kaboom.extras.helpers.SkinDownloader; public final class PlayerConnection implements Listener { - private long connectionMillis; - - private final File configFile = new File("spigot.yml"); - private final FileConfiguration spigotConfig = YamlConfiguration.loadConfiguration(configFile); - private final ConfigurationSection configSection = spigotConfig.getConfigurationSection("commands"); - - /*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) { @@ -61,7 +36,7 @@ public final class PlayerConnection implements Listener { } } - try { + /*try { final PlayerProfile profile = event.getPlayerProfile(); UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8)); @@ -71,26 +46,10 @@ public final class PlayerConnection implements Listener { SkinDownloader skinDownloader = new SkinDownloader(); skinDownloader.fillJoinProfile(profile, event.getName(), event.getUniqueId()); } catch (Exception ignored) { - } + }*/ } } - /*@EventHandler - void onInventoryClose(InventoryCloseEvent event) { - for (ItemStack item : event.getInventory().getContents()) { - if (isIllegalItem(item)) { - event.getInventory().clear(); - } - } - }*/ - - /*@EventHandler - void onPlayerCommandSend(final PlayerCommandSendEvent event) { - if (event.getPlayer().isOnline()) { - event.getCommands().clear(); - } - }*/ - @EventHandler void onPlayerJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); @@ -125,28 +84,8 @@ public final class PlayerConnection implements Listener { && event.getHostname().endsWith(":25565")) { event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw"); return; - } else if (System.currentTimeMillis() - connectionMillis < 2000) { - if (!configSection.getString("tab-complete").equals("-1")) { - configSection.set("tab-complete", -1); - try { - spigotConfig.save(configFile); - - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spigot reload"); - } catch (IOException ignored) { - } - } - } else if (configSection.getString("tab-complete").equals("-1")) { - configSection.set("tab-complete", 0); - try { - spigotConfig.save(configFile); - - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spigot reload"); - } catch (IOException ignored) { - } } - connectionMillis = System.currentTimeMillis(); - if (!JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableJoinRestrictions")) { event.allow(); } @@ -158,16 +97,16 @@ public final class PlayerConnection implements Listener { final Player player = event.getPlayer(); - try { - player.setPlayerProfile(SkinDownloader.getProfile(player.getUniqueId())); - SkinDownloader.removeProfile(player.getUniqueId()); - } catch (Exception ignored) { - } - if (JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("opOnJoin") && !player.isOp()) { player.setOp(true); } + + /*try { + player.setPlayerProfile(SkinDownloader.getProfile(player.getUniqueId())); + SkinDownloader.removeProfile(player.getUniqueId()); + } catch (Exception ignored) { + }*/ } @EventHandler @@ -200,7 +139,10 @@ public final class PlayerConnection implements Listener { @EventHandler void onPreLookupProfile(final PreLookupProfileEvent event) { + // Disable Mojang API calls, we don't need them UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8)); event.setUUID(offlineUUID); + + event.setProfileProperties(new HashSet()); } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java index f1c2259..99294c7 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java @@ -1,9 +1,11 @@ package pw.kaboom.extras.modules.player; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -44,5 +46,14 @@ public final class PlayerInteract implements Listener { item.addUnsafeEnchantment(Enchantment.RIPTIDE, riptideLimit); } } + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + final Block clickedBlock = event.getClickedBlock(); + + if (clickedBlock.getType() == Material.SIGN + || clickedBlock.getType() == Material.WALL_SIGN) { + clickedBlock.getState().update(); + } + } } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerTeleport.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerTeleport.java index e1f8d3e..6e0a98d 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerTeleport.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerTeleport.java @@ -6,7 +6,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import pw.kaboom.extras.modules.entity.EntitySpawn; +import pw.kaboom.extras.modules.entity.EntityTeleport; public final class PlayerTeleport implements Listener { @EventHandler @@ -22,6 +22,6 @@ public final class PlayerTeleport implements Listener { @EventHandler void onPlayerTeleport(final PlayerTeleportEvent event) { - event.setTo(EntitySpawn.limitLocation(event.getTo())); + event.setTo(EntityTeleport.limitLocation(event.getTo())); } }