mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-30 01:13:38 +01:00
Added /friend accept and /guild accept
This commit is contained in:
parent
a4eada2593
commit
32dd296eaa
@ -2,17 +2,18 @@ package net.Indyuce.mmocore.command;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.social.FriendRequest;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -34,34 +35,36 @@ public class FriendsCommand extends BukkitCommand {
|
||||
PlayerData data = PlayerData.get((Player) sender);
|
||||
MMOCommandEvent event = new MMOCommandEvent(data, "friends");
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) return true;
|
||||
if (event.isCancelled()) return true;
|
||||
|
||||
if (args.length > 1) {
|
||||
UUID uuid;
|
||||
|
||||
final @Nullable FriendRequest invite;
|
||||
if (args.length > 1)
|
||||
|
||||
// Search by request ID
|
||||
try {
|
||||
uuid = UUID.fromString(args[1]);
|
||||
} catch (Exception e) {
|
||||
final UUID uuid = UUID.fromString(args[1]);
|
||||
final Request req = MMOCore.plugin.requestManager.getRequest(uuid);
|
||||
Validate.isTrue(!req.isTimedOut() && req instanceof FriendRequest);
|
||||
Validate.isTrue(!data.hasFriend(req.getCreator().getUniqueId()));
|
||||
invite = (FriendRequest) req;
|
||||
} catch (Exception exception) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Request request = MMOCore.plugin.requestManager.getRequest(uuid);
|
||||
if (!(request instanceof FriendRequest))
|
||||
return true;
|
||||
// Search by target player
|
||||
else
|
||||
invite = MMOCore.plugin.requestManager.findRequest(data, FriendRequest.class);
|
||||
|
||||
if (request.isTimedOut()) {
|
||||
MMOCore.plugin.requestManager.unregisterRequest(uuid);
|
||||
// No invite found with given identifier/target player
|
||||
if (invite == null)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (OfflinePlayerData.get(((Player) sender).getUniqueId()).hasFriend(uuid)) {
|
||||
MMOCore.plugin.requestManager.unregisterRequest(uuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("accept"))
|
||||
request.accept();
|
||||
invite.accept();
|
||||
if (args[0].equalsIgnoreCase("deny"))
|
||||
request.deny();
|
||||
invite.deny();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.guild.provided.GuildInvite;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -12,10 +14,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.guild.provided.GuildInvite;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GuildCommand extends BukkitCommand {
|
||||
|
||||
@ -36,34 +37,36 @@ public class GuildCommand extends BukkitCommand {
|
||||
PlayerData data = PlayerData.get((OfflinePlayer) sender);
|
||||
MMOCommandEvent event = new MMOCommandEvent(data, "guild");
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) return true;
|
||||
if (event.isCancelled()) return true;
|
||||
|
||||
if (args.length > 1) {
|
||||
UUID uuid;
|
||||
|
||||
final @Nullable GuildInvite invite;
|
||||
if (args.length > 1)
|
||||
|
||||
// Search by request ID
|
||||
try {
|
||||
uuid = UUID.fromString(args[1]);
|
||||
} catch (Exception e) {
|
||||
final UUID uuid = UUID.fromString(args[1]);
|
||||
final Request req = MMOCore.plugin.requestManager.getRequest(uuid);
|
||||
Validate.isTrue(!req.isTimedOut() && req instanceof GuildInvite);
|
||||
invite = (GuildInvite) req;
|
||||
Validate.isTrue(MMOCore.plugin.dataProvider.getGuildManager().isRegistered(invite.getGuild()));
|
||||
} catch (Exception exception) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Request request = MMOCore.plugin.requestManager.getRequest(uuid);
|
||||
if (!(request instanceof GuildInvite))
|
||||
return true;
|
||||
// Search by target player
|
||||
else
|
||||
invite = MMOCore.plugin.requestManager.findRequest(data, GuildInvite.class);
|
||||
|
||||
if (request.isTimedOut()) {
|
||||
MMOCore.plugin.requestManager.unregisterRequest(uuid);
|
||||
// No invite found with given identifier/target player
|
||||
if (invite == null)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!MMOCore.plugin.dataProvider.getGuildManager().isRegistered(((GuildInvite) request).getGuild())) {
|
||||
MMOCore.plugin.requestManager.unregisterRequest(uuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("accept"))
|
||||
request.accept();
|
||||
invite.accept();
|
||||
if (args[0].equalsIgnoreCase("deny"))
|
||||
request.deny();
|
||||
invite.deny();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user