Skip to content
Open
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
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/main/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -204,5 +208,17 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>
<version>2.2.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.cumulus</groupId>
<artifactId>cumulus</artifactId>
<version>1.1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions src/main/java/com/zetaplugins/essentialz/EssentialZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class EssentialZ extends ZetaCorePlugin {

private final boolean hasPlaceholderApi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
private final boolean hasVault = Bukkit.getPluginManager().getPlugin("Vault") != null;
private final boolean hasFloodgate = Bukkit.getPluginManager().getPlugin("floodgate") != null;

@Override
public void onEnable() {
Expand All @@ -64,10 +65,22 @@ public void onEnable() {

initPlaceholderAPI();
initBstats();
initFloodgate();

getLogger().info("EssentialZ enabled!");
}

private void initFloodgate() {
if (hasFloodgate) {
boolean formsEnabled = getConfig().getBoolean("tpa.bedrock.formsEnabled", true);
if (formsEnabled) {
getLogger().info("Floodgate detected, TPA Bedrock forms enabled.");
} else {
getLogger().info("Floodgate detected, but TPA Bedrock forms are disabled in config.");
}
}
}

@Override
public void onDisable() {
getLogger().info("EssentialZ disabled!");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.zetaplugins.essentialz.commands.tpa;

import com.zetaplugins.essentialz.EssentialZ;
import com.zetaplugins.essentialz.features.tpa.*;
import com.zetaplugins.essentialz.util.MessageManager;
import com.zetaplugins.essentialz.util.PluginMessage;
import com.zetaplugins.essentialz.util.commands.EszCommand;
import com.zetaplugins.zetacore.annotations.AutoRegisterCommand;
import com.zetaplugins.zetacore.annotations.InjectManager;
import com.zetaplugins.zetacore.commands.ArgumentList;
import com.zetaplugins.zetacore.commands.exceptions.CommandSenderMustBePlayerException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

@AutoRegisterCommand(
commands = "tpaccept",
description = "Accept a teleport request",
usage = "/tpaccept",
permission = "essentialz.tpaccept",
aliases = {"tpyes"}
)
public class TpAcceptCommand extends EszCommand {

@InjectManager
private TpaManager tpaManager;

@InjectManager
private TpaToggleManager toggleManager;

@InjectManager
private TpaBedrockFormHandler bedrockFormHandler;

private boolean floodgateEnabled = false;

public TpAcceptCommand(EssentialZ plugin) {
super(plugin);
initFloodgate();
}

private void initFloodgate() {
if (getPlugin().getServer().getPluginManager().getPlugin("floodgate") != null) {
try {
Class.forName("org.geysermc.floodgate.api.FloodgateApi");
floodgateEnabled = true;
} catch (ClassNotFoundException e) {
floodgateEnabled = false;
}
}
}

@Override
public boolean execute(CommandSender sender, Command command, String label, ArgumentList args) throws CommandSenderMustBePlayerException {
if (!(sender instanceof Player player)) {
throw new CommandSenderMustBePlayerException();
}

List<TeleportRequest> requests = tpaManager.getIncomingRequests(player.getUniqueId());

if (requests.isEmpty()) {
sender.sendMessage(getMessageManager().getAndFormatMsg(PluginMessage.TPA_NO_PENDING_REQUESTS));
return true;
}

// Bedrock player with multiple requests - show form
if (floodgateEnabled && isBedrockPlayer(player) && requests.size() > 1) {
bedrockFormHandler.sendPendingRequestsForm(player);
return true;
}

// Accept the most recent request
TeleportRequest request = requests.get(requests.size() - 1);
acceptRequest(player, request);
tpaManager.removeRequest(request);

TpaUtils.playSound(player, getPlugin().getConfig().getString("tpa.sounds.accept", "ENTITY_PLAYER_LEVELUP"), getPlugin());

return true;
}

private void acceptRequest(Player acceptor, TeleportRequest request) {
Player senderPlayer = request.getSenderPlayer();
Player targetPlayer = request.getTargetPlayer();

if (senderPlayer == null || !senderPlayer.isOnline()) {
acceptor.sendMessage(getMessageManager().getAndFormatMsg(PluginMessage.PLAYER_NOT_FOUND));
return;
}

if (targetPlayer == null || !targetPlayer.isOnline()) {
return;
}

if (request.getType() == TpaRequestType.TPA) {
senderPlayer.teleport(targetPlayer.getLocation());
} else {
targetPlayer.teleport(senderPlayer.getLocation());
}

senderPlayer.sendMessage(getMessageManager().getAndFormatMsg(
PluginMessage.TPA_ACCEPTED_SENDER,
new MessageManager.Replaceable<>("{player}", targetPlayer.getName())
));

targetPlayer.sendMessage(getMessageManager().getAndFormatMsg(
PluginMessage.TPA_ACCEPTED_TARGET,
new MessageManager.Replaceable<>("{player}", senderPlayer.getName())
));
}

@Override
public List<String> tabComplete(CommandSender sender, Command command, ArgumentList args) {
return List.of();
}

private boolean isBedrockPlayer(Player player) {
try {
return org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
} catch (Exception e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.zetaplugins.essentialz.commands.tpa;

import com.zetaplugins.essentialz.EssentialZ;
import com.zetaplugins.essentialz.features.tpa.TeleportRequest;
import com.zetaplugins.essentialz.features.tpa.TpaManager;
import com.zetaplugins.essentialz.features.tpa.TpaUtils;
import com.zetaplugins.essentialz.util.MessageManager;
import com.zetaplugins.essentialz.util.PluginMessage;
import com.zetaplugins.essentialz.util.commands.EszCommand;
import com.zetaplugins.zetacore.annotations.AutoRegisterCommand;
import com.zetaplugins.zetacore.annotations.InjectManager;
import com.zetaplugins.zetacore.commands.ArgumentList;
import com.zetaplugins.zetacore.commands.exceptions.CommandSenderMustBePlayerException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

@AutoRegisterCommand(
commands = "tpdeny",
description = "Deny a teleport request",
usage = "/tpdeny",
permission = "essentialz.tpdeny",
aliases = {"tpno"}
)
public class TpDenyCommand extends EszCommand {

@InjectManager
private TpaManager tpaManager;

public TpDenyCommand(EssentialZ plugin) {
super(plugin);
}

@Override
public boolean execute(CommandSender sender, Command command, String label, ArgumentList args) throws CommandSenderMustBePlayerException {
if (!(sender instanceof Player player)) {
throw new CommandSenderMustBePlayerException();
}

List<TeleportRequest> requests = tpaManager.getIncomingRequests(player.getUniqueId());

if (requests.isEmpty()) {
sender.sendMessage(getMessageManager().getAndFormatMsg(PluginMessage.TPA_NO_PENDING_REQUESTS));
return true;
}

// Deny the most recent request
TeleportRequest request = requests.get(requests.size() - 1);
denyRequest(player, request);
tpaManager.removeRequest(request);

TpaUtils.playSound(player, getPlugin().getConfig().getString("tpa.sounds.deny", "ENTITY_VILLAGER_NO"), getPlugin());

return true;
}

private void denyRequest(Player denier, TeleportRequest request) {
Player senderPlayer = request.getSenderPlayer();

if (senderPlayer != null && senderPlayer.isOnline()) {
senderPlayer.sendMessage(getMessageManager().getAndFormatMsg(
PluginMessage.TPA_DENIED_SENDER,
new MessageManager.Replaceable<>("{player}", denier.getName())
));
}

denier.sendMessage(getMessageManager().getAndFormatMsg(PluginMessage.TPA_DENIED_TARGET));
}

@Override
public List<String> tabComplete(CommandSender sender, Command command, ArgumentList args) {
return List.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.zetaplugins.essentialz.commands.tpa;

import com.zetaplugins.essentialz.EssentialZ;
import com.zetaplugins.essentialz.features.tpa.TeleportRequest;
import com.zetaplugins.essentialz.features.tpa.TpaManager;
import com.zetaplugins.essentialz.util.MessageManager;
import com.zetaplugins.essentialz.util.PluginMessage;
import com.zetaplugins.essentialz.util.commands.EszCommand;
import com.zetaplugins.zetacore.annotations.AutoRegisterCommand;
import com.zetaplugins.zetacore.annotations.InjectManager;
import com.zetaplugins.zetacore.commands.ArgumentList;
import com.zetaplugins.zetacore.commands.exceptions.CommandSenderMustBePlayerException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

@AutoRegisterCommand(
commands = "tpacancel",
description = "Cancel all outgoing teleport requests",
usage = "/tpacancel",
permission = "essentialz.tpacancel"
)
public class TpaCancelCommand extends EszCommand {

@InjectManager
private TpaManager tpaManager;

public TpaCancelCommand(EssentialZ plugin) {
super(plugin);
}

@Override
public boolean execute(CommandSender sender, Command command, String label, ArgumentList args) throws CommandSenderMustBePlayerException {
if (!(sender instanceof Player player)) {
throw new CommandSenderMustBePlayerException();
}

List<TeleportRequest> requests = tpaManager.getOutgoingRequests(player.getUniqueId());

if (requests.isEmpty()) {
sender.sendMessage(getMessageManager().getAndFormatMsg(PluginMessage.TPA_NO_OUTGOING_REQUESTS));
return true;
}

// Cancel all outgoing requests
for (TeleportRequest request : requests) {
tpaManager.removeRequest(request);
}

sender.sendMessage(getMessageManager().getAndFormatMsg(
PluginMessage.TPA_REQUESTS_CANCELLED,
new MessageManager.Replaceable<>("{count}", String.valueOf(requests.size()))
));

return true;
}

@Override
public List<String> tabComplete(CommandSender sender, Command command, ArgumentList args) {
return List.of();
}
}
Loading