Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
7 changes: 4 additions & 3 deletions src/main/java/pw/kaboom/extras/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);

/* Custom worlds */
this.getServer().createWorld(
new WorldCreator("world_flatlands").generateStructures(false).type(WorldType.FLAT)
);
if (this.getConfig().getBoolean("generateFlatlands"))
this.getServer().createWorld(
new WorldCreator("world_flatlands").generateStructures(false).type(WorldType.FLAT)
);

final Messenger messenger = this.getServer().getMessenger();
final PlayerMessaging playerMessaging = new PlayerMessaging(this);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/pw/kaboom/extras/commands/CommandPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.modules.player.PlayerPrefix;

import javax.annotation.Nonnull;

public final class CommandPrefix implements CommandExecutor {
private static final int MAX_PREFIX_LENGTH = 1024;
private static final int MAX_PREFIX_LENGTH = JavaPlugin.getPlugin(Main.class)
.getConfig()
.getInt("maxPrefixLength");

public boolean onCommand(final @Nonnull CommandSender sender,
final @Nonnull Command cmd,
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/pw/kaboom/extras/modules/entity/EntityExplosion.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package pw.kaboom.extras.modules.entity;

import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Fireball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;

public final class EntityExplosion implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();

private static final int MAX_EXPLOSION_RADIUS = CONFIG.getInt("maxExplosionRadius");
private static final int MAX_FIREBALL_COUNT = CONFIG.getInt("maxFireballCount");

@EventHandler
void onExplosionPrime(final ExplosionPrimeEvent event) {
final int maxRadius = 20;

if (event.getRadius() > maxRadius) {
event.setRadius(maxRadius);
if (event.getRadius() > MAX_EXPLOSION_RADIUS) {
event.setRadius(MAX_EXPLOSION_RADIUS);
}

final World world = event.getEntity().getWorld();
final int maxFireballCount = 30;

if (world.getEntitiesByClass(Fireball.class).size() > maxFireballCount
if (world.getEntitiesByClass(Fireball.class).size() > MAX_FIREBALL_COUNT
&& event.getRadius() > 1) {
event.setRadius(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import pw.kaboom.extras.Main;

public final class EntityKnockback implements Listener {
private static final double KNOCKBACK_LIMIT = 20; // translates to enchantment level 40
// default translates to enchantment level 40
private static final double KNOCKBACK_LIMIT = JavaPlugin.getPlugin(Main.class)
.getConfig()
.getDouble("maxKnockbackVelocity");
private static final double KNOCKBACK_LIMIT_SQUARED = KNOCKBACK_LIMIT * KNOCKBACK_LIMIT;

@EventHandler
Expand Down
79 changes: 39 additions & 40 deletions src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Slime;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -42,6 +34,23 @@ public final class EntitySpawn implements Listener {
private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
public static final int MAX_ENTITIES_PER_WORLD = CONFIG.getInt("maxEntitiesPerWorld");
private static final int MAX_TNTS_PER_WORLD = CONFIG.getInt("maxTntsPerWorld");
private static final int MAX_DRAGONS_PER_WORLD = CONFIG.getInt("maxDragonsPerWorld");
private static final int MAX_WITHERS_PER_WORLD = CONFIG.getInt("maxWithersPerWorld");
private static final int MAX_TNT_MINECARTS_PER_WORLD = CONFIG.getInt("maxTntMinecartsPerWorld");

private static final int SPAWNER_MIN_SPAWN_DELAY = CONFIG.getInt("spawnerMinSpawnDelay");
private static final int SPAWNER_MAX_SPAWN_COUNT = CONFIG.getInt("spawnerMaxSpawnCount");
private static final int SPAWNER_MAX_SPAWN_RANGE = CONFIG.getInt("spawnerMaxSpawnRange");

private static final int EFFECT_CLOUD_MAX_RADIUS =
CONFIG.getInt("effectCloudMaxRadius");
private static final int EFFECT_CLOUD_MAX_RADIUS_ON_USE =
CONFIG.getInt("effectCloudMaxRadiusOnUse");
private static final int EFFECT_CLOUD_MAX_RADIUS_PER_TICK =
CONFIG.getInt("effectCloudMaxRadiusPerTick");

private static final int MAX_SLIME_SIZE =
CONFIG.getInt("maxSlimeSize");

private void applyEntityChanges(final Entity entity) {
switch (entity.getType()) {
Expand Down Expand Up @@ -84,9 +93,15 @@ private boolean isEntityLimitReached(final EntityType entityType, final Chunk ch
switch (entityType) {
case ENDER_DRAGON:
final int worldDragonCount = world.getEntitiesByClass(EnderDragon.class).size();
final int worldDragonCountLimit = 24;

if (worldDragonCount >= worldDragonCountLimit) {
if (worldDragonCount >= MAX_DRAGONS_PER_WORLD) {
return true;
}
break;
case WITHER:
final int worldWitherCount = world.getEntitiesByClass(Wither.class).size();

if (worldWitherCount >= MAX_WITHERS_PER_WORLD) {
return true;
}
break;
Expand All @@ -111,25 +126,20 @@ private boolean isEntityLimitReached(final EntityType entityType, final Chunk ch
}

private void limitAreaEffectCloudRadius(final AreaEffectCloud cloud) {
if (cloud.getRadius() > 40) {
cloud.setRadius(40);
}

if (cloud.getRadiusOnUse() > 0.01f) {
cloud.setRadiusOnUse(0.1f);
}

if (cloud.getRadiusPerTick() > 0) {
cloud.setRadiusPerTick(0);
}
cloud.setRadius(Math.min(EFFECT_CLOUD_MAX_RADIUS, cloud.getRadius()));
cloud.setRadiusOnUse(Math.min(EFFECT_CLOUD_MAX_RADIUS_ON_USE, cloud.getRadiusPerTick()));
cloud.setRadiusPerTick(Math.min(
EFFECT_CLOUD_MAX_RADIUS_PER_TICK,
cloud.getRadiusPerTick())
);
}

private void limitSlimeSize(final Slime slime) {
final AttributeInstance scaleInstance = slime.getAttribute(Attribute.SCALE);
final double scale = scaleInstance != null ? scaleInstance.getValue() : 1.0f;

if ((slime.getSize() * scale) > 20) {
slime.setSize(20);
if ((slime.getSize() * scale) > MAX_SLIME_SIZE) {
slime.setSize(MAX_SLIME_SIZE);
Utility.resetAttribute(slime, Attribute.SCALE);
}
}
Expand All @@ -139,21 +149,10 @@ private void limitSpawner(final CreatureSpawner spawner) {
spawner.setSpawnedType(EntityType.MINECART);
}

if (spawner.getMinSpawnDelay() < 1000) {
spawner.setMinSpawnDelay(1000);
}

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

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

if (spawner.getSpawnRange() > 50) {
spawner.setSpawnRange(50);
}
spawner.setMinSpawnDelay(Math.max(SPAWNER_MIN_SPAWN_DELAY, spawner.getMinSpawnDelay()));
spawner.setMaxSpawnDelay(Math.max(SPAWNER_MIN_SPAWN_DELAY, spawner.getMaxSpawnDelay()));
spawner.setSpawnCount(Math.min(SPAWNER_MAX_SPAWN_COUNT, spawner.getSpawnCount()));
spawner.setSpawnRange(Math.min(SPAWNER_MAX_SPAWN_RANGE, spawner.getSpawnRange()));
}

@EventHandler
Expand All @@ -165,7 +164,7 @@ void onAreaEffectCloudApply(final AreaEffectCloudApplyEvent event) {
void onExplosionPrime(final ExplosionPrimeEvent event) {
if (EntityType.TNT_MINECART.equals(event.getEntityType())
&& event.getEntity().getWorld()
.getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
.getEntitiesByClass(ExplosiveMinecart.class).size() > MAX_TNT_MINECARTS_PER_WORLD) {
event.setCancelled(true);
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand All @@ -20,22 +22,25 @@

public final class PlayerChat implements Listener {
private static final PlayerChatRenderer CHAT_RENDERER = new PlayerChatRenderer();
private static final long MIN_CHAT_DELAY_MILLIS = JavaPlugin.getPlugin(Main.class)
.getConfig()
.getLong("minChatDelayMillis");

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
void onAsyncChatEventProcess(final AsyncChatEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();

if (PlayerCommand.getCommandMillisList().get(playerUuid) != null) {
final long lastCommandTime = PlayerCommand.getCommandMillisList().get(playerUuid);
if (PlayerCommand.getLastCommandExec().get(playerUuid) != null) {
final long lastCommandTime = PlayerCommand.getLastCommandExec().get(playerUuid);
final long millisDifference = System.currentTimeMillis() - lastCommandTime;

if (millisDifference < 50) {
if (millisDifference < MIN_CHAT_DELAY_MILLIS) {
event.setCancelled(true);
return;
}
}

PlayerCommand.getCommandMillisList().put(playerUuid, System.currentTimeMillis());
PlayerCommand.getLastCommandExec().put(playerUuid, System.currentTimeMillis());
}

@EventHandler(priority = EventPriority.MONITOR)
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pw.kaboom.extras.modules.player;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
Expand All @@ -10,26 +11,31 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.modules.server.ServerCommand;

public final class PlayerCommand implements Listener {
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
private static final Map<UUID, Long> LAST_COMMAND_EXEC = new HashMap<>();
private static final long MIN_COMMAND_DELAY_MILLIS = JavaPlugin.getPlugin(Main.class)
.getConfig()
.getLong("minCommandDelayMillis");

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();

if (getCommandMillisList().get(playerUuid) != null) {
final long lastCommandTime = getCommandMillisList().get(playerUuid);
if (getLastCommandExec().get(playerUuid) != null) {
final long lastCommandTime = getLastCommandExec().get(playerUuid);
final long millisDifference = System.currentTimeMillis() - lastCommandTime;

if (millisDifference < 75) {
if (millisDifference < MIN_COMMAND_DELAY_MILLIS) {
event.setCancelled(true);
return;
}
}

getCommandMillisList().put(playerUuid, System.currentTimeMillis());
getLastCommandExec().put(playerUuid, System.currentTimeMillis());

final CommandSender sender = event.getPlayer();
final String command = event.getMessage();
Expand All @@ -50,7 +56,7 @@ void onPlayerSignCommandPreprocess(final PlayerSignCommandPreprocessEvent event)
this.onPlayerCommandPreprocess(event);
}

public static HashMap<UUID, Long> getCommandMillisList() {
return commandMillisList;
public static Map<UUID, Long> getLastCommandExec() {
return LAST_COMMAND_EXEC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ public final class PlayerConnection implements Listener {
""
)
);
private static final Duration FADE_IN = Duration.ofMillis(50);
private static final Duration STAY = Duration.ofMillis(8000);
private static final Duration FADE_OUT = Duration.ofMillis(250);
private static final boolean SEND_TITLE = CONFIG.getBoolean("playerJoinSendTitle");
private static final Duration FADE_IN = Duration.ofMillis(
CONFIG.getLong("playerJoinTitleFadeIn")
);
private static final Duration STAY = Duration.ofMillis(
CONFIG.getLong("playerJoinTitleStay")
);
private static final Duration FADE_OUT = Duration.ofMillis(
CONFIG.getLong("playerJoinTitleFadeOut")
);

private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean(
Expand All @@ -57,6 +64,9 @@ public final class PlayerConnection implements Listener {
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");

private static final double RANDOMIZE_SPAWN_RADIUS = CONFIG.getDouble("randomizeSpawnRadius");
private static final double RANDOMIZE_SPAWN_Y = CONFIG.getDouble("randomizeSpawnY");

private static final EnumSet<PlayerKickEvent.Cause> ALLOWED_KICK_CAUSES = EnumSet.of(
PlayerKickEvent.Cause.TIMEOUT, PlayerKickEvent.Cause.INVALID_VEHICLE_MOVEMENT,
PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT,
Expand Down Expand Up @@ -102,7 +112,7 @@ void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();

player.showTitle(Title.title(
if (SEND_TITLE) player.showTitle(Title.title(
TITLE,
SUBTITLE,
Title.Times.times(FADE_IN, STAY, FADE_OUT)
Expand Down Expand Up @@ -160,20 +170,19 @@ void onPlayerSpawn(final AsyncPlayerSpawnLocationEvent event) {
final World world = event.getSpawnLocation().getWorld();
final ThreadLocalRandom random = ThreadLocalRandom.current();

final double teleportAmount = 500000D;
final Location location = new Location(
world,
random.nextDouble(-teleportAmount, teleportAmount),
100,
random.nextDouble(-teleportAmount, teleportAmount)
random.nextDouble(-RANDOMIZE_SPAWN_RADIUS, RANDOMIZE_SPAWN_RADIUS),
RANDOMIZE_SPAWN_Y,
random.nextDouble(-RANDOMIZE_SPAWN_RADIUS, RANDOMIZE_SPAWN_RADIUS)
);

event.setSpawnLocation(location);
}

@EventHandler
void onPlayerQuit(final PlayerQuitEvent event) {
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
PlayerCommand.getLastCommandExec().remove(event.getPlayer().getUniqueId());
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
ServerTabComplete.getLoginNameList().remove(event.getPlayer().getUniqueId());
}
Expand Down
Loading
Loading