🛠️API

This page helps you to understand how to use our SpooferAPI on different platforms. We offer a abstract layer for Spigot, BungeeCord & Velocity.

Usage

To get started using our api, import our library via either gradle or maven. Create a `libs` folder in your current working directory with our plugin inside of it.

Don't forget to add our plugin as dependency inside your plugin.yml / bungee-plugin.yml / velocity-plugin.json.

The name of the plugin will always be HalosPlayerSpoofer for all platforms

Groovy Gradle

dependencies {
    implementation files('libs/HalosPlayerSpoofer-2.0.0.jar')
}

Kotlin DSL Gradle

dependencies {
    implementation(files("libs/HalosPlayerSpoofer-2.0.0.jar"))
}

Maven

<dependencies>
    <dependency>
        <groupId>com.halos</groupId>
        <artifactId>spoofer-api</artifactId>
        <version>2.0.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/HalosPlayerSpoofer-2.0.0.jar</systemPath>
    </dependency>
</dependencies>

Fake Player

You can get the instance of a fake player from all platform.

import com.halos.spoofer.shared.core.player.FakePlayer;
import com.halos.spoofer.shared.core.account.type.UsernameAccount;
import com.halos.spoofer.shared.core.account.type.UUIDAccount;
import java.util.UUID;
import com.halos.spoofer.shared.core.profile.Profile;

var player = (FakePlayer) null;

player.account(); // can be null; either a UsernameAccount or UUIDAccount
String name = player.profile().name(); // name of fake player
UUID uniqueId = player.profile().uniqueId(); // uuid of fake player
Profile.Texture = texture = player.profile().texture(); // skin texture of fake player
long joinedAt = player.joinedAt(); // join time stamp
long expiresAt = player.expiresAt(); // when the player will leave the server
boolean chatter = player.chatter(); // if the player can chat
FakePlayerMetadata metadata = player.metadata(); // metadata for fake player

// use metadata to store different values
// caution: metadata will be saved. For example the Vote & Rank Module utilizes this.
// so clear keys on the destroy event to prevent many files

boolean createdByFluctuation = metadata.has(MetadataKey.FLUCTUATION); // check if player is created by fluctuation

metadata.put("rank", "default"); // store a property
metadata.getOrDefault("rank", "default") // retrieve a property

Spigot

We provide several events, that are called when a fake player is created on the current server

import com.halos.spoofer.api.spigot.event.FakePlayerCreatedEvent;
import com.halos.spoofer.api.spigot.event.FakePlayerDestroyEvent;
import com.halos.spoofer.api.spigot.event.FakePlayerLoginEvent;

// This event is called after a fake player is created & joined the server.
var playerCreatedEvent = (FakePlayerCreatedEvent) null;
// This event is called before a fake player gets destroyed.
var playerDestroyEvent = (FakePlayerDestroyEvent) null;
// This event is called before a fake player logs in.
var playerLoginEvent = (FakePlayerLoginEvent) null;

playerCreatedEvent.fakePlayer(); // get the fake player
playerCreatedEvent.player(); // get the bukkit player

playerDestroyEvent.fakePlayer(); // get the fake player
playerDestroyEvent.player(); // get the bukkit player

playerLoginEvent.fakePlayer(); // get the fake player
import com.halos.spoofer.api.spigot.SpigotSpooferAPI;
import com.halos.spoofer.shared.core.player.FakePlayer;

var api = SpigotSpooferAPI.get(); // access the spigot spoofer api

api.isFakePlayer("username");
api.isFakePlayer(UUID.randomUUID());
api.isFakePlayer(Bukkit.getPlayer("username"));

// careful: all find methods return optionals with FakePlayer
FakePlayer fakePlayer = api.find("username").orElseThrow();
FakePlayer fakePlayer = api.find(UUID.randomUUID().orElseThrow());
FakePlayer fakePlayer = api.find(Bukkit.getPlayer("username").orElseThrow());

CompletableFuture<FakePlayer> future = api.createFakePlayer(new Profile("username", UUID.randomUUID(), new Profile.Texture("value", "signature")));
CompletableFuture<FakePlayer> future = api.createFakePlayer(new UsernameAccount("rexlManu")); // this fetches the profile from a profile fetcher type
CompletableFuture<FakePlayer> future = api.createFakePlayer(new UUIDAccount(UUID.randomUUID())); // this fetches the profile from a profile fetcher type

// future will fail with a FakePlayerNotFoundException if player can't be found
CompletableFuture<Void> future = api.removeFakePlayer(UUID.randomUUID());
CompletableFuture<Void> future = api.removeFakePlayer("username");
CompletableFuture<Void> future = api.removeFakePlayer(Bukkit.getPlayer("username"));
CompletableFuture<Void> future = api.removeFakePlayer(fakePlayer);

BungeeCord / Velocity

Both platforms provide a similar api like spigot with the exception of creating / removing fake players. When creating a fake player on spigot, the fake player will also be created on the proxy.

import com.halos.spoofer.api.bungee.event.FakePlayerCreatedEvent;
import com.halos.spoofer.api.bungee.event.FakePlayerDestroyEvent;
import com.halos.spoofer.api.velocity.event.FakePlayerCreatedEvent;
import com.halos.spoofer.api.velocity.event.FakePlayerDestroyEvent;

// all events give access to fakePlayer via FakePlayerEvent#fakePlayer() 
// and FakePlayerCreatedEvent#player() for velocity
// or proxied player instance on bungeecord

import com.halos.spoofer.api.velocity.VelocitySpooferAPI;
import com.halos.spoofer.api.bungee.BungeeSpooferAPI;

// both apis are called similar like the spigot variant exempt the creation / removing methods.
// the native platforms give access to get fake players by ProxiedPlayer or Player from velocity

Last updated