Skip to content

Commit

Permalink
Performance fix for future updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 4, 2024
1 parent 40efb78 commit f1da748
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/lewmc/essence/Essence.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class Essence extends JavaPlugin {
*/
public boolean hasPendingUpdate = false;

/**
* Manages random numbers.
*/
public Random rand = new Random();

/**
* This function runs when Essence is enabled.
*/
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/net/lewmc/essence/utils/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.bukkit.WorldBorder;
import org.bukkit.entity.Player;

import java.util.Random;

/**
* Essence location utility.
*/
Expand Down Expand Up @@ -40,15 +38,14 @@ public void UpdateLastLocation(Player player) {
public Location GetRandomLocation(Player player, WorldBorder wb) {
World world = player.getWorld();

Random rand = new Random();
Location center = wb.getCenter();
double maxX = (center.getBlockX() + (wb.getSize()/2));
double minX = (center.getBlockX() - (wb.getSize()/2));
double maxZ = (center.getBlockZ() + (wb.getSize()/2));
double minZ = (center.getBlockZ() - (wb.getSize()/2));

int x = (int) (minX + (maxX - minX) * rand.nextDouble());
int z = (int) (minZ + (maxZ - minZ) * rand.nextDouble());
int x = (int) (minX + (maxX - minX) * this.plugin.rand.nextDouble());
int z = (int) (minZ + (maxZ - minZ) * this.plugin.rand.nextDouble());

int attempt = 1;
int y = GetGroundY(world, x, z);
Expand Down

0 comments on commit f1da748

Please sign in to comment.