2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2021-12-04 15:40:06 +01:00
|
|
|
import com.earth2me.essentials.IUser;
|
2011-03-19 23:39:51 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2021-12-04 15:40:06 +01:00
|
|
|
import net.essentialsx.api.v2.events.TeleportRequestResponseEvent;
|
|
|
|
import org.bukkit.Bukkit;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Server;
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2021-12-04 15:40:06 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commandtpdeny extends EssentialsCommand {
|
|
|
|
public Commandtpdeny() {
|
|
|
|
super("tpdeny");
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
2021-12-04 15:40:06 +01:00
|
|
|
final boolean denyAll;
|
|
|
|
if (args.length > 0) {
|
|
|
|
denyAll = args[0].equals("*") || args[0].equalsIgnoreCase("all");
|
|
|
|
} else {
|
|
|
|
denyAll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user.hasPendingTpaRequests(false, false)) {
|
|
|
|
throw new Exception(tl("noPendingRequest"));
|
|
|
|
}
|
|
|
|
|
|
|
|
final IUser.TpaRequest denyRequest;
|
|
|
|
if (args.length > 0) {
|
|
|
|
if (denyAll) {
|
|
|
|
denyAllRequests(user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
denyRequest = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false);
|
|
|
|
} else {
|
|
|
|
denyRequest = user.getNextTpaRequest(false, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (denyRequest == null) {
|
2017-05-04 14:41:27 +02:00
|
|
|
throw new Exception(tl("noPendingRequest"));
|
|
|
|
}
|
2021-12-04 15:40:06 +01:00
|
|
|
|
|
|
|
final User player = ess.getUser(denyRequest.getRequesterUuid());
|
|
|
|
if (player == null || !player.getBase().isOnline()) {
|
2015-04-15 06:06:16 +02:00
|
|
|
throw new Exception(tl("noPendingRequest"));
|
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
|
2021-12-04 15:40:06 +01:00
|
|
|
if (sendEvent(user, player, denyRequest)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
user.sendMessage(tl("requestDenied"));
|
|
|
|
player.sendMessage(tl("requestDeniedFrom", user.getDisplayName()));
|
2021-12-04 15:40:06 +01:00
|
|
|
user.removeTpaRequest(denyRequest.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void denyAllRequests(User user) {
|
|
|
|
IUser.TpaRequest request;
|
|
|
|
int count = 0;
|
|
|
|
while ((request = user.getNextTpaRequest(false, true, false)) != null) {
|
|
|
|
final User player = ess.getUser(request.getRequesterUuid());
|
|
|
|
|
|
|
|
if (sendEvent(user, player, request)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player != null && player.getBase().isOnline()) {
|
|
|
|
player.sendMessage(tl("requestDeniedFrom", user.getDisplayName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
user.removeTpaRequest(request.getName());
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
user.sendMessage(tl("requestDeniedAll", count));
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean sendEvent(User user, User player, IUser.TpaRequest request) {
|
|
|
|
final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, request, false);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
final boolean cancelled = event.isCancelled();
|
|
|
|
if (cancelled && ess.getSettings().isDebug()) {
|
2022-06-27 20:54:10 +02:00
|
|
|
ess.getLogger().info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")");
|
2021-12-04 15:40:06 +01:00
|
|
|
}
|
|
|
|
return event.isCancelled();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
final List<String> options = new ArrayList<>(user.getPendingTpaKeys());
|
|
|
|
options.add("*");
|
|
|
|
return options;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|