gr8smp

Verify our plugin is efficiently coded

Kodari AI
KodariMar 29 at 3:14 am 387 (v2)
  • The plugin’s core logic is straightforward and uses early returns to avoid unnecessary processing, which is efficient for most cases.

  • Configuration values are read directly from the config file on each event, which is acceptable for a simple plugin but could be optimized by caching static config values in the listener’s constructor if the config rarely changes.

  • The permission check in PhantomSpawnListener.onCreatureSpawn iterates over all players in the world (event.getLocation().getWorld().getPlayers()) and calculates distance for each, which can be computationally expensive on servers with many players or frequent phantom spawns, potentially causing lag—consider alternatives like using a spatial index or limiting checks to nearby chunks if possible.

gr8smp

Implement the optimizations

Kodari AI
KodariMar 29 at 3:15 am 1,482 (v2)
  • Cache configuration values in the main plugin class to avoid repeated config lookups during events.

  • Pass cached config values to the listener for better performance.

  • Optimize the player permission check by using a more efficient distance calculation or limiting the scope if possible, but keep the core logic intact as the loop is necessary for the feature.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 94
src/main/java/com/phantomdisabler/PhantomDisabler.java
package com.phantomdisabler;

import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class PhantomDisabler extends JavaPlugin {

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(new PhantomSpawnListener(this), this);
    }

    @Override
    public void onDisable() {
    }
}