Skip to content

Commit

Permalink
Remove some outdated API
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 3, 2022
1 parent 16f4a03 commit 7b11cd1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/citizensnpcs/api/CitizensAPI.java
Expand Up @@ -93,6 +93,10 @@ public static InventoryHelper getInventoryHelper() {
return getImplementation().getInventoryHelper();
}

public static LocationLookup getLocationLookup() {
return getImplementation().getLocationLookup();
}

/**
* Retrieves the {@link NPCRegistry} previously created via {@link #createNamedNPCRegistry(String, NPCDataStore)}
* with the given name, or null if not found.
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/citizensnpcs/api/CitizensPlugin.java
Expand Up @@ -46,6 +46,13 @@ public interface CitizensPlugin extends Plugin {

public InventoryHelper getInventoryHelper();

/**
* Gets the Citizens {@link LocationLookup}
*
* @return
*/
public LocationLookup getLocationLookup();

/**
*
* @param name
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/citizensnpcs/api/LocationLookup.java
@@ -0,0 +1,45 @@
package net.citizensnpcs.api;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

import com.google.common.collect.Maps;

import ch.ethz.globis.phtree.PhTreeF;

public class LocationLookup implements Runnable {
private final Map<UUID, PhTreeF<Player>> worlds = Maps.newHashMap();

public Iterable<Player> getNearbyPlayers(Location base, double dist) {
PhTreeF<Player> tree = worlds.get(base.getWorld().getUID());
if (tree == null)
return Collections.emptyList();
return () -> tree.rangeQuery(dist, base.getX(), base.getY(), base.getZ());
}

@Override
public void run() {
worlds.clear();
for (World world : Bukkit.getServer().getWorlds()) {
List<Player> players = world.getPlayers();
if (players.isEmpty())
continue;
PhTreeF<Player> tree = PhTreeF.create(3);
worlds.put(world.getUID(), tree);
Location loc = new Location(null, 0, 0, 0);
for (Player player : players) {
if (player.hasMetadata("NPC"))
continue;
player.getLocation(loc);
tree.put(new double[] { loc.getX(), loc.getY(), loc.getZ() }, player);
}
}
}
}
12 changes: 1 addition & 11 deletions src/main/java/net/citizensnpcs/api/trait/TraitFactory.java
Expand Up @@ -24,7 +24,7 @@ public interface TraitFactory {

/**
* Returns all currently registered traits, including <em>internal</em> traits
*
*
* @return
*/
Collection<TraitInfo> getRegisteredTraits();
Expand Down Expand Up @@ -56,16 +56,6 @@ public interface TraitFactory {
*/
Class<? extends Trait> getTraitClass(String name);

/**
* Checks whether the given trait is 'internal'. An internal trait is implementation-defined and is default or
* built-in.
*
* @param trait
* The trait to check
* @return Whether the trait is an internal trait
*/
boolean isInternalTrait(Trait trait);

/**
* Registers a trait using the given information.
*
Expand Down

0 comments on commit 7b11cd1

Please sign in to comment.