Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakePlayer Support #2

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic",
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
}
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@
<artifactId>hscore-bukkit-config</artifactId>
<version>${core.version}</version>
</dependency>

<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.8.1</version>
</dependency>
<dependency>
<groupId>me.chrommob</groupId>
<artifactId>fakeplayer</artifactId>
<scope>system</scope>
<version>1.0-SNAPSHOT</version>
<systemPath>${project.basedir}/libs/FakePlayer-1.0-SNAPSHOT-all.jar</systemPath>
</dependency>
</dependencies>
</project>
</project>
12 changes: 9 additions & 3 deletions src/main/java/me/hsgamer/yatpa/command/PlayerTabComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import me.chrommob.fakeplayer.api.FakePlayerAPI;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public interface PlayerTabComplete {
static @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
static @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
@NotNull String[] args) throws IllegalArgumentException {
if (args.length == 1) {
String argName = args[0];
return Bukkit.getOnlinePlayers().stream()
List<String> players = Bukkit.getOnlinePlayers().stream()
.map(Player::getName)
.filter(name -> name.toLowerCase(Locale.ROOT).startsWith(argName.toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
FakePlayerAPI.getInstance().getFakePlayerNames().stream()
.filter(name -> name.toLowerCase(Locale.ROOT).startsWith(argName.toLowerCase(Locale.ROOT)))
.forEach(players::add);
}
return Collections.emptyList();
}
}
}
23 changes: 18 additions & 5 deletions src/main/java/me/hsgamer/yatpa/command/TeleportRequestCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.hsgamer.yatpa.command;

import me.chrommob.fakeplayer.api.FakePlayerAPI;
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
import me.hsgamer.yatpa.YATPA;
import me.hsgamer.yatpa.request.RequestEntry;
Expand All @@ -11,11 +12,13 @@
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Set;

public abstract class TeleportRequestCommand extends Command {
protected final YATPA plugin;

protected TeleportRequestCommand(YATPA plugin, @NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
protected TeleportRequestCommand(YATPA plugin, @NotNull String name, @NotNull String description,
@NotNull List<String> aliases) {
super(name, description, "/" + name + " <player>", aliases);
this.plugin = plugin;
}
Expand Down Expand Up @@ -50,19 +53,28 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab

Player targetPlayer = sender.getServer().getPlayer(args[0]);

if (targetPlayer == null) {
Set<String> fakePlayerNames = FakePlayerAPI.getInstance().getFakePlayerNames();

if (targetPlayer == null && !fakePlayerNames.contains(args[0])) {
MessageUtils.sendMessage(sender, plugin.getMessageConfig().getPlayerNotFound());
return false;
}

if (targetPlayer == null) {
MessageUtils.sendMessage(sender, plugin.getMessageConfig().getRequestSent(targetPlayer));
plugin.getCooldownManager().addCooldown(senderPlayer.getUniqueId());
return true;
}

if (targetPlayer.equals(senderPlayer)) {
MessageUtils.sendMessage(sender, plugin.getMessageConfig().getCannotSendToYourself());
return false;
}

RequestType requestType = getRequestType();

RequestEntry requestEntry = new RequestEntry(senderPlayer.getUniqueId(), targetPlayer.getUniqueId(), requestType);
RequestEntry requestEntry = new RequestEntry(senderPlayer.getUniqueId(), targetPlayer.getUniqueId(),
requestType);

RequestStatus requestStatus = plugin.getRequestManager().request(requestEntry);
switch (requestStatus) {
Expand All @@ -82,7 +94,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
}

@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
@NotNull String[] args) throws IllegalArgumentException {
return PlayerTabComplete.tabComplete(sender, alias, args);
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: YATPA
version: '${project.version}'
main: me.hsgamer.yatpa.YATPA
depend: [ FakePlayer ]
authors: [ HSGamer ]
description: Yet Another TPA plugin
folia-supported: true
api-version: 1.13
api-version: 1.13
Loading