Various cleanups for consistency

This commit is contained in:
kaboom 2022-05-20 01:44:22 +03:00
parent 23da0661b3
commit 28c78be287
6 changed files with 36 additions and 38 deletions

View file

@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-java@v2 - uses: actions/setup-java@v2
with: with:
distribution: 'temurin' distribution: 'temurin'
java-version: 18 java-version: 8
- name: Cache maven packages to speed up build - name: Cache maven packages to speed up build
uses: actions/cache@v1 uses: actions/cache@v1

View file

@ -5,8 +5,8 @@
<version>master</version> <version>master</version>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<maven.test.skip>true</maven.test.skip> <maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

View file

@ -1,5 +1,7 @@
package pw.kaboom.extras.commands; package pw.kaboom.extras.commands;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -11,18 +13,13 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Random;
public final class CommandKaboom implements CommandExecutor { public final class CommandKaboom implements CommandExecutor {
private double getRandom(final int min, final int max) {
return new Random().nextInt(max - min + 1) + min;
}
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
final Player player = (Player) sender; final Player player = (Player) sender;
int random = new Random().nextBoolean() ? 0 : 1; boolean explode = ThreadLocalRandom.current().nextBoolean();
if (random == 0) { if (explode) {
final Location location = player.getLocation(); final Location location = player.getLocation();
final World world = player.getWorld(); final World world = player.getWorld();
final int explosionCount = 20; final int explosionCount = 20;
@ -31,9 +28,9 @@ public final class CommandKaboom implements CommandExecutor {
world.createExplosion(location, power, true, true); world.createExplosion(location, power, true, true);
for (int i = 0; i < explosionCount; i++) { for (int i = 0; i < explosionCount; i++) {
final double posX = location.getX() + getRandom(-15, 15); final double posX = location.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
final double posY = location.getY() + getRandom(-6, 6); final double posY = location.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
final double posZ = location.getZ() + getRandom(-15, 15); final double posZ = location.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
final Location explodeLocation = new Location(world, posX, posY, posZ); final Location explodeLocation = new Location(world, posX, posY, posZ);
final int power2 = 4; final int power2 = 4;

View file

@ -1,13 +1,10 @@
package pw.kaboom.extras.modules.entity; package pw.kaboom.extras.modules.entity;
import java.security.SecureRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.Random;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.AreaEffectCloud;
@ -34,13 +31,11 @@ import com.destroystokyo.paper.event.block.TNTPrimeEvent;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import pw.kaboom.extras.Main; import pw.kaboom.extras.Main;
public final class EntitySpawn implements Listener { public final class EntitySpawn implements Listener {
private static final Main PLUGIN = JavaPlugin.getPlugin(Main.class); private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final FileConfiguration CONFIG = PLUGIN.getConfig(); private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
private static final SecureRandom RANDOM = new SecureRandom();
private void applyEntityChanges(final Entity entity) { private void applyEntityChanges(final Entity entity) {
switch (entity.getType()) { switch (entity.getType()) {
@ -96,9 +91,8 @@ public final class EntitySpawn implements Listener {
default: default:
if (!EntityType.PLAYER.equals(entityType)) { if (!EntityType.PLAYER.equals(entityType)) {
final int chunkEntityCount = chunk.getEntities().length; final int chunkEntityCount = chunk.getEntities().length;
final int chunkEntityCountLimit = CONFIG.getInt("maxEntitiesPerChunk");
if (chunkEntityCount >= chunkEntityCountLimit) { if (chunkEntityCount >= MAX_ENTITIES_PER_CHUNK) {
return true; return true;
} }
} }
@ -180,16 +174,6 @@ public final class EntitySpawn implements Listener {
} }
} }
@EventHandler
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
final World world = event.getPlayer().getWorld();
final WorldBorder worldBorder = world.getWorldBorder();
if (CONFIG.getBoolean("randomizeSpawn") && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
event.setSpawnLocation(new Location(world, RANDOM.nextDouble(-300000000D, 30000000D) + .5, 100D, RANDOM.nextDouble(-300000000D, 30000000D) + .5));
}
}
@EventHandler @EventHandler
void onEntitySpawn(final EntitySpawnEvent event) { void onEntitySpawn(final EntitySpawnEvent event) {
final double x = event.getLocation().getX(); final double x = event.getLocation().getX();
@ -284,7 +268,7 @@ public final class EntitySpawn implements Listener {
case EXPLOSION: case EXPLOSION:
case FIRE: case FIRE:
case REDSTONE: case REDSTONE:
if (new Random().nextBoolean()) { if (ThreadLocalRandom.current().nextBoolean()) {
event.setCancelled(true); event.setCancelled(true);
} }
return; return;

View file

@ -2,8 +2,11 @@ package pw.kaboom.extras.modules.player;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -16,6 +19,8 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.ProfileProperty; import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
@ -36,6 +41,7 @@ public final class PlayerConnection implements Listener {
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean("enableJoinRestrictions"); private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean("enableJoinRestrictions");
private static final boolean ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer"); private static final boolean ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer");
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin"); private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");
@EventHandler @EventHandler
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) { void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
@ -105,6 +111,18 @@ public final class PlayerConnection implements Listener {
}*/ }*/
} }
@EventHandler
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
if (RANDOMIZE_SPAWN && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
final World world = event.getPlayer().getWorld();
final double x = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
final double y = 100;
final double z = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5;
event.setSpawnLocation(new Location(world, x, y, z));
}
}
@EventHandler @EventHandler
void onPlayerQuit(final PlayerQuitEvent event) { void onPlayerQuit(final PlayerQuitEvent event) {
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId()); PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());

View file

@ -4,8 +4,7 @@ enableKick: false
enableJoinRestrictions: false enableJoinRestrictions: false
opOnJoin: true opOnJoin: true
randomizeSpawn: false randomizeSpawn: false
# Set to -1 to disable maxEntitiesPerChunk: 30 # Set to -1 to disable
maxEntitiesPerChunk: 30
playerJoinTitle: "§7Welcome to Kaboom!" playerJoinTitle: "§7Welcome to Kaboom!"
playerJoinSubtitle: "Free OP • Anarchy • Creative" playerJoinSubtitle: "Free OP • Anarchy • Creative"
opTag: "§4§l[§c§lOP§4§l] §c" opTag: "§4§l[§c§lOP§4§l] §c"