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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.7-R0.1-SNAPSHOT</version>
<version>1.21.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
25 changes: 3 additions & 22 deletions src/main/java/pw/kaboom/extras/commands/CommandSpawn.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package pw.kaboom.extras.commands;

import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import pw.kaboom.extras.util.Utility;

import javax.annotation.Nonnull;

Expand All @@ -24,23 +21,7 @@ public boolean onCommand(final @Nonnull CommandSender sender,
return true;
}

final World defaultWorld = Bukkit.getWorld("world");
final World world = (defaultWorld == null) ? Bukkit.getWorlds().get(0) : defaultWorld;
final Location spawnLocation = world.getSpawnLocation();
final int maxWorldHeight = 256;

for (double y = spawnLocation.getY(); y <= maxWorldHeight; y++) {
final Location yLocation = new Location(world, spawnLocation.getX(), y,
spawnLocation.getZ());
final Block coordBlock = world.getBlockAt(yLocation);

if (!coordBlock.getType().isSolid()
&& !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
player.teleportAsync(yLocation);
break;
}
}

Utility.teleportToSpawn(player, PlayerTeleportEvent.TeleportCause.COMMAND);
player.sendMessage(Component
.text("Successfully moved to spawn"));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public boolean onCommand(final @Nonnull CommandSender sender,

// Preserve UUIDs, as changing them breaks clients
final PlayerProfile newProfile = Bukkit.createProfileExact(player.getUniqueId(), name);
newProfile.setProperties(player.getPlayerProfile().getProperties());

player.setPlayerProfile(newProfile);
lastUsedMillis.put(player, System.currentTimeMillis());
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pw.kaboom.extras.modules.player;

import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.common.base.Charsets;
import io.papermc.paper.event.player.AsyncPlayerSpawnLocationEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
Expand All @@ -17,14 +17,12 @@
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.modules.server.ServerTabComplete;
import pw.kaboom.extras.modules.player.skin.SkinManager;
import pw.kaboom.extras.util.Utility;

import java.time.Duration;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -133,21 +131,21 @@ void onPlayerLogin(final PlayerLoginEvent event) {
}

@EventHandler
void onPlayerSpawn(final PlayerSpawnLocationEvent event) {
if (RANDOMIZE_SPAWN
&& event.getPlayer().getRespawnLocation() != event.getSpawnLocation()) {
final World world = event.getPlayer().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)
);
event.setSpawnLocation(location);
}
void onPlayerSpawn(final AsyncPlayerSpawnLocationEvent event) {
if (!RANDOMIZE_SPAWN || !event.isNewPlayer()) return;

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)
);

event.setSpawnLocation(location);
}

@EventHandler
Expand All @@ -163,7 +161,5 @@ void onPreLookupProfile(final PreLookupProfileEvent event) {
UUID offlineUUID = UUID.nameUUIDFromBytes(
("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
event.setUUID(offlineUUID);

event.setProfileProperties(new HashSet<ProfileProperty>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import pw.kaboom.extras.util.Utility;
Expand Down Expand Up @@ -103,8 +104,7 @@ void onPlayerDeath(final PlayerDeathEvent event) {
if (player.getRespawnLocation() != null) {
player.teleportAsync(player.getRespawnLocation());
} else {
final World world = Bukkit.getWorld("world");
player.teleportAsync(world.getSpawnLocation());
Utility.teleportToSpawn(player, PlayerTeleportEvent.TeleportCause.UNKNOWN);
}
} catch (Exception exception) {
Utility.resetAttribute(player, Attribute.MAX_HEALTH);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/pw/kaboom/extras/modules/server/ServerGameRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,36 @@
import java.util.Map;

public final class ServerGameRule implements Listener {
private static final Map<GameRule<?>, ?> FORCED_GAMERULES = Map.of(
GameRule.COMMAND_BLOCKS_ENABLED, true,
GameRule.SPAWNER_BLOCKS_ENABLED, false
);

private static final Map<GameRule<Integer>, Integer> GAMERULE_LIMITS = Map.of(
GameRule.RANDOM_TICK_SPEED, 6,
GameRule.SPAWN_RADIUS, 100,
GameRule.COMMAND_MODIFICATION_BLOCK_LIMIT, 32768,
GameRule.MAX_COMMAND_FORK_COUNT, EntitySpawn.MAX_ENTITIES_PER_WORLD
);

private static<T> void setGameRule(final World world, final GameRule<T> gameRule,
final Object value) {
assert value.getClass() == gameRule.getType();

//noinspection unchecked
world.setGameRule(gameRule, (T) value);
}

@EventHandler
void onGameRuleChange(final WorldGameRuleChangeEvent event) {
final GameRule<?> gameRule = event.getGameRule();

final Object forcedValue = FORCED_GAMERULES.get(gameRule);
if (forcedValue != null) {
event.setValue(forcedValue.toString());
return;
}

final Integer limit = GAMERULE_LIMITS.get(gameRule);
if (limit == null) {
return;
Expand All @@ -43,6 +62,13 @@ private static void enableAutoSave() {

private static void fixGameRules() {
for (final World world : Bukkit.getWorlds()) {
for (final var entry : FORCED_GAMERULES.entrySet()) {
final GameRule<?> gameRule = entry.getKey();
final Object value = entry.getValue();

setGameRule(world, gameRule, value);
}

for (final var entry : GAMERULE_LIMITS.entrySet()) {
final GameRule<Integer> gameRule = entry.getKey();
final int limit = entry.getValue();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/pw/kaboom/extras/util/Utility.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package pw.kaboom.extras.util;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.Callable;
import java.util.function.Function;

public final class Utility {
public static void teleportToSpawn(final Player player,
final PlayerTeleportEvent.TeleportCause cause) {
final World world = player.getServer().getRespawnWorld();
final Location spawnLocation = world.getSpawnLocation();

final int y = world.getHighestBlockYAt(spawnLocation);
final Location location = new Location(world,
spawnLocation.x(), y + 1, spawnLocation.z(),
spawnLocation.getYaw(), spawnLocation.getPitch());
player.teleportAsync(location, cause);
}

public static @Nullable Player getPlayerExactIgnoreCase(final String username) {
return Bukkit.getOnlinePlayers()
.stream()
Expand Down