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 #1

Closed
wants to merge 1 commit 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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,12 @@
<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>
10 changes: 8 additions & 2 deletions src/main/java/me/hsgamer/yatpa/command/PlayerTabComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
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();
}
Expand Down
20 changes: 16 additions & 4 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 @@ -10,12 +11,14 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

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

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,10 +53,17 @@ 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());
Expand All @@ -62,7 +72,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab

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 +93,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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: YATPA
version: '${project.version}'
main: me.hsgamer.yatpa.YATPA
depend: [ FakePlayer ]
authors: [ HSGamer ]
description: Yet Another TPA plugin
folia-supported: true
Expand Down
Loading