mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 01:45:44 -05:00
Various cleanups for consistency
This commit is contained in:
parent
23da0661b3
commit
28c78be287
6 changed files with 36 additions and 38 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
@ -15,7 +15,7 @@ jobs:
|
|||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 18
|
||||
java-version: 8
|
||||
|
||||
- name: Cache maven packages to speed up build
|
||||
uses: actions/cache@v1
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -5,8 +5,8 @@
|
|||
<version>master</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package pw.kaboom.extras.commands;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
@ -11,18 +13,13 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
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) {
|
||||
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 World world = player.getWorld();
|
||||
final int explosionCount = 20;
|
||||
|
@ -31,9 +28,9 @@ public final class CommandKaboom implements CommandExecutor {
|
|||
world.createExplosion(location, power, true, true);
|
||||
|
||||
for (int i = 0; i < explosionCount; i++) {
|
||||
final double posX = location.getX() + getRandom(-15, 15);
|
||||
final double posY = location.getY() + getRandom(-6, 6);
|
||||
final double posZ = location.getZ() + getRandom(-15, 15);
|
||||
final double posX = location.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
|
||||
final double posY = location.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
|
||||
final double posZ = location.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
|
||||
|
||||
final Location explodeLocation = new Location(world, posX, posY, posZ);
|
||||
final int power2 = 4;
|
||||
|
@ -49,4 +46,4 @@ public final class CommandKaboom implements CommandExecutor {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package pw.kaboom.extras.modules.entity;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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.PreSpawnerSpawnEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
import pw.kaboom.extras.Main;
|
||||
|
||||
public final class EntitySpawn implements Listener {
|
||||
private static final Main PLUGIN = JavaPlugin.getPlugin(Main.class);
|
||||
private static final FileConfiguration CONFIG = PLUGIN.getConfig();
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
||||
private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
|
||||
|
||||
private void applyEntityChanges(final Entity entity) {
|
||||
switch (entity.getType()) {
|
||||
|
@ -96,9 +91,8 @@ public final class EntitySpawn implements Listener {
|
|||
default:
|
||||
if (!EntityType.PLAYER.equals(entityType)) {
|
||||
final int chunkEntityCount = chunk.getEntities().length;
|
||||
final int chunkEntityCountLimit = CONFIG.getInt("maxEntitiesPerChunk");
|
||||
|
||||
if (chunkEntityCount >= chunkEntityCountLimit) {
|
||||
if (chunkEntityCount >= MAX_ENTITIES_PER_CHUNK) {
|
||||
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
|
||||
void onEntitySpawn(final EntitySpawnEvent event) {
|
||||
final double x = event.getLocation().getX();
|
||||
|
@ -284,7 +268,7 @@ public final class EntitySpawn implements Listener {
|
|||
case EXPLOSION:
|
||||
case FIRE:
|
||||
case REDSTONE:
|
||||
if (new Random().nextBoolean()) {
|
||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -2,8 +2,11 @@ package pw.kaboom.extras.modules.player;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
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.plugin.java.JavaPlugin;
|
||||
|
||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
|
||||
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
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 ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer");
|
||||
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
|
||||
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");
|
||||
|
||||
@EventHandler
|
||||
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
|
||||
void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
|
||||
|
|
|
@ -4,9 +4,8 @@ enableKick: false
|
|||
enableJoinRestrictions: false
|
||||
opOnJoin: true
|
||||
randomizeSpawn: false
|
||||
# Set to -1 to disable
|
||||
maxEntitiesPerChunk: 30
|
||||
maxEntitiesPerChunk: 30 # Set to -1 to disable
|
||||
playerJoinTitle: "§7Welcome to Kaboom!"
|
||||
playerJoinSubtitle: "Free OP • Anarchy • Creative"
|
||||
opTag: "§4§l[§c§lOP§4§l] §c"
|
||||
deOpTag: "§8§l[§7§lDeOP§8§l] §7"
|
||||
deOpTag: "§8§l[§7§lDeOP§8§l] §7"
|
||||
|
|
Loading…
Reference in a new issue