Skip to content
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
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<version>master</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand All @@ -15,14 +15,14 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21.7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.5</version>
<version>6.6.5</version>
<!-- This is a vanilla dependency, as of 1.20.4 -->
<scope>provided</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public boolean onCommand(final @Nonnull CommandSender sender,
final Component senderName = sender.name();
final String input = String.join(" ", args);
final Component component = LEGACY_COMPONENT_SERIALIZER.deserialize(input);
final Component broadcastComponent = Component.translatable("chat.type.admin")
final Component broadcastComponent =
Component.translatable("chat.type.admin", senderName, component)
.decorate(TextDecoration.ITALIC)
.color(NamedTextColor.GRAY)
.args(senderName, component);
.color(NamedTextColor.GRAY);

sender.sendMessage(component);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package pw.kaboom.extras.commands;

import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

Expand All @@ -30,7 +34,9 @@ public boolean onCommand(final @Nonnull CommandSender sender,
return true;
}

for (Enchantment enchantment : Enchantment.values()) {
final Registry<@NotNull Enchantment> registry = RegistryAccess.registryAccess()
.getRegistry(RegistryKey.ENCHANTMENT);
for (Enchantment enchantment : registry) {
item.addUnsafeEnchantment(enchantment, Short.MAX_VALUE);
}
player.sendMessage(Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public final class CommandJumpscare implements CommandExecutor {
private void createJumpscare(final Player player) {
final int count = 4;
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), count);
player.spawnParticle(Particle.ELDER_GUARDIAN, player.getLocation(), count);

final int maxIterator = 10;
for (int i = 0; i <= maxIterator; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pw/kaboom/extras/commands/CommandPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean onCommand(final @Nonnull CommandSender sender,
return true;
}

final int ping = target.spigot().getPing();
final int ping = target.getPing();
final int d = (int) Math.floor((float) ping / 100);
NamedTextColor highlighting = NamedTextColor.WHITE;

Expand Down
19 changes: 0 additions & 19 deletions src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.scheduler.BukkitScheduler;
Expand All @@ -18,24 +17,6 @@ public final class BlockPhysics implements Listener {
// from crashing the server
private static double tps = 20;

@EventHandler
void onBlockPhysics(final BlockPhysicsEvent event) {
try {
switch (event.getChangedType()) {
case COMMAND_BLOCK:
case CHAIN_COMMAND_BLOCK:
case REPEATING_COMMAND_BLOCK:
if (Material.STRUCTURE_BLOCK.equals(event.getSourceBlock().getType())) {
event.setCancelled(true);
}
default:
break;
}
} catch (Exception | StackOverflowError e) {
event.setCancelled(true);
}
}

@EventHandler
void onBlockRedstone(final BlockRedstoneEvent event) {
if (tps < MINIMUM_TPS) {
Expand Down
33 changes: 10 additions & 23 deletions src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
package pw.kaboom.extras.modules.entity;

import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import io.papermc.paper.event.entity.EntityKnockbackEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;

import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
import org.bukkit.util.Vector;

public final class EntityKnockback implements Listener {
@EventHandler
void onEntityKnockbackByEntity(final EntityKnockbackByEntityEvent event) {
final int knockbackLimit = 60;

if (event.getKnockbackStrength() > knockbackLimit) {
event.getAcceleration().multiply(
knockbackLimit / event.getKnockbackStrength()
);
}
}
private static final double KNOCKBACK_LIMIT = 20; // translates to enchantment level 40
private static final double KNOCKBACK_LIMIT_SQUARED = KNOCKBACK_LIMIT * KNOCKBACK_LIMIT;

@EventHandler
void onProjectileHit(final ProjectileHitEvent event) {
if (event.getHitEntity() != null
&& EntityType.ARROW.equals(event.getEntityType())) {
final Arrow arrow = (Arrow) event.getEntity();
final int knockbackLimit = 60;

if (arrow.getKnockbackStrength() > knockbackLimit) {
arrow.setKnockbackStrength(knockbackLimit);
}
void onEntityKnockbackByEntity(final EntityKnockbackEvent event) {
final Vector knockback = event.getKnockback();
final double length = knockback.lengthSquared();
if (length > KNOCKBACK_LIMIT_SQUARED) {
event.setKnockback(knockback.normalize()
.multiply(KNOCKBACK_LIMIT));
}
}
}
28 changes: 15 additions & 13 deletions src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private boolean isEntityLimitReached(final EntityType entityType, final Chunk ch
return true;
}
break;
case PRIMED_TNT:
case TNT:
final int worldTntCount = world.getEntitiesByClass(TNTPrimed.class).size();

if (worldTntCount >= MAX_TNTS_PER_WORLD) {
Expand Down Expand Up @@ -131,24 +131,24 @@ private void limitSlimeSize(final Slime slime) {
}

private void limitSpawner(final CreatureSpawner spawner) {
if (EntityType.MINECART_MOB_SPAWNER.equals(spawner.getSpawnedType())) {
if (EntityType.SPAWNER_MINECART.equals(spawner.getSpawnedType())) {
spawner.setSpawnedType(EntityType.MINECART);
}

if (spawner.getDelay() > 100) {
spawner.setMaxSpawnDelay(100);
spawner.setDelay(100);
spawner.update();
if (spawner.getMinSpawnDelay() < 1000) {
spawner.setMinSpawnDelay(1000);
}

if (spawner.getMaxSpawnDelay() < 1000) {
spawner.setMaxSpawnDelay(1000);
}

if (spawner.getSpawnCount() > 200) {
spawner.setSpawnCount(200);
spawner.update();
}

if (spawner.getSpawnRange() > 50) {
spawner.setSpawnRange(50);
spawner.update();
}
}

Expand All @@ -159,7 +159,7 @@ void onAreaEffectCloudApply(final AreaEffectCloudApplyEvent event) {

@EventHandler
void onExplosionPrime(final ExplosionPrimeEvent event) {
if (EntityType.MINECART_TNT.equals(event.getEntityType())
if (EntityType.TNT_MINECART.equals(event.getEntityType())
&& event.getEntity().getWorld()
.getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
event.setCancelled(true);
Expand Down Expand Up @@ -197,7 +197,7 @@ void onItemSpawn(final ItemSpawnEvent event) {
@EventHandler
void onLightningStrike(final LightningStrikeEvent event) {
final LightningStrike lightning = event.getLightning();
final EntityType entityType = EntityType.LIGHTNING;
final EntityType entityType = EntityType.LIGHTNING_BOLT;
final Chunk chunk = lightning.getChunk();
final World world = event.getWorld();

Expand All @@ -220,7 +220,7 @@ void onPreCreatureSpawn(final PreCreatureSpawnEvent event) {
@EventHandler
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
try {
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState());
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState(false));
} catch (Exception exception) {
event.setCancelled(true);
}
Expand All @@ -231,8 +231,10 @@ void onSpawnerSpawn(final SpawnerSpawnEvent event) {
if (EntityType.FALLING_BLOCK.equals(event.getEntityType())) {
final FallingBlock block = (FallingBlock) event.getEntity();

if (block.getBlockData().getMaterial().equals(Material.SPAWNER)) {
event.setCancelled(true);
if (!block.getBlockData().getMaterial().equals(Material.SPAWNER)) return;
event.setCancelled(true);

if (event.getSpawner() != null) {
event.getSpawner().setSpawnedType(EntityType.FALLING_BLOCK);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void onPlayerLogin(final PlayerLoginEvent event) {
@EventHandler
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
if (RANDOMIZE_SPAWN
&& event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
&& event.getPlayer().getRespawnLocation() != event.getSpawnLocation()) {
final World world = event.getPlayer().getWorld();
final ThreadLocalRandom random = ThreadLocalRandom.current();

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerDamage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void onEntityRegainHealth(final EntityRegainHealthEvent event) {
@EventHandler
void onFoodLevelChange(final FoodLevelChangeEvent event) {
final HumanEntity player = event.getEntity();
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
final AttributeInstance attribute = player.getAttribute(Attribute.MAX_HEALTH);
if (attribute == null) return;
if (attribute.getValue() <= 0) {
Utility.resetAttribute(attribute);
Expand Down Expand Up @@ -97,21 +97,21 @@ void onPlayerDeath(final PlayerDeathEvent event) {
xp.setExperience(event.getDroppedExp());
}

final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
final AttributeInstance attribute = player.getAttribute(Attribute.MAX_HEALTH);
if (attribute != null) {
Utility.resetAttribute(attribute);
}

player.setHealth(20);

if (player.getBedSpawnLocation() != null) {
player.teleportAsync(player.getBedSpawnLocation());
if (player.getRespawnLocation() != null) {
player.teleportAsync(player.getRespawnLocation());
} else {
final World world = Bukkit.getWorld("world");
player.teleportAsync(world.getSpawnLocation());
}
} catch (Exception exception) {
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
final AttributeInstance attribute = player.getAttribute(Attribute.MAX_HEALTH);
if (attribute != null) {
Utility.resetAttribute(attribute);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class PlayerTeleport implements Listener {
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
final Player player = event.getPlayer();

final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
final AttributeInstance attribute = player.getAttribute(Attribute.MAX_HEALTH);
if (attribute == null) return;
if (attribute.getValue() <= 0) {
Utility.resetAttribute(attribute);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Extras
main: pw.kaboom.extras.Main
description: Plugin that adds extra functionality to the server.
api-version: '1.19'
api-version: '1.21'
version: master

commands:
Expand Down