Skip to content

Commit

Permalink
Add PrePlayerKickedClanEvent (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Aug 15, 2024
1 parent e97065c commit 4c959cc
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package net.sacredlabyrinth.phaed.simpleclans.commands.clan;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.sacredlabyrinth.phaed.simpleclans.*;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.HelpSearchTags;
import co.aikar.commands.annotation.Name;
import co.aikar.commands.annotation.Single;
import co.aikar.commands.annotation.Subcommand;
import net.sacredlabyrinth.phaed.simpleclans.ChatBlock;
import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.ClanPlayer;
import net.sacredlabyrinth.phaed.simpleclans.Helper;
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanInput;
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanPlayerInput;
import net.sacredlabyrinth.phaed.simpleclans.conversation.ResignPrompt;
import net.sacredlabyrinth.phaed.simpleclans.conversation.SCConversation;
import net.sacredlabyrinth.phaed.simpleclans.events.PrePlayerKickedClanEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.TagChangeEvent;
import net.sacredlabyrinth.phaed.simpleclans.managers.*;
import net.sacredlabyrinth.phaed.simpleclans.managers.ClanManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.ProtectionManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.RequestManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.StorageManager;
import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils;
import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat;
import org.bukkit.entity.Player;
Expand All @@ -19,7 +38,12 @@
import java.util.Optional;

import static net.sacredlabyrinth.phaed.simpleclans.SimpleClans.lang;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.*;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MAX_ALLIANCES;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MAX_DESCRIPTION_LENGTH;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MAX_MEMBERS;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MIN_DESCRIPTION_LENGTH;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.ECONOMY_MAX_MEMBER_FEE;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.WAR_START_REQUEST_ENABLED;
import static org.bukkit.ChatColor.AQUA;
import static org.bukkit.ChatColor.RED;

Expand Down Expand Up @@ -348,15 +372,16 @@ public void kick(@Conditions("clan_member") Player sender,
ChatBlock.sendMessage(sender, RED + lang("you.cannot.kick.yourself", sender));
return;
}

Clan clan = cm.getClanByPlayerUniqueId(sender.getUniqueId());
if (Objects.requireNonNull(clan).isLeader(clanPlayer.getUniqueId())) {
ChatBlock.sendMessage(sender, RED + lang("you.cannot.kick.another.leader", sender));
return;
}

clan.addBb(sender.getName(), lang("has.been.kicked.by", clanPlayer.getName(),
sender.getName(), sender));
if (new PrePlayerKickedClanEvent(clan, clanPlayer).callEvent()) {
ChatBlock.sendMessage(sender, RED + lang("error.event.cancelled", sender));
return;
}
clan.addBb(sender.getName(), lang("has.been.kicked.by", clanPlayer.getName(), sender.getName(), sender));
clan.removePlayerFromClan(clanPlayer.getUniqueId());
}

Expand All @@ -365,18 +390,18 @@ public void kick(@Conditions("clan_member") Player sender,
@Description("{@@command.description.resign}")
@HelpSearchTags("leave")
public void resignConfirm(Player player, ClanPlayer cp, Clan clan) {
if (clan.isPermanent() || !clan.isLeader(player) || clan.getLeaders().size() > 1) {
if (new PrePlayerKickedClanEvent(clan, cp).callEvent()) {
ChatBlock.sendMessage(player, RED + lang("error.event.cancelled", player));
} else if (clan.isPermanent() || !clan.isLeader(player) || clan.getLeaders().size() > 1) {
clan.addBb(player.getName(), lang("0.has.resigned", player.getName()));
cp.addResignTime(clan.getTag());
clan.removePlayerFromClan(player.getUniqueId());

ChatBlock.sendMessage(cp, AQUA + lang("resign.success", player));
} else if (clan.isLeader(player) && clan.getLeaders().size() == 1) {
clan.disband(player, true, false);
ChatBlock.sendMessage(cp, RED + lang("clan.has.been.disbanded", player, clan.getName()));
} else {
ChatBlock.sendMessage(cp, RED +
lang("last.leader.cannot.resign.you.must.appoint.another.leader.or.disband.the.clan", player));
ChatBlock.sendMessage(cp, RED + lang("last.leader.cannot.resign.you.must.appoint.another.leader.or.disband.the.clan", player));
}
}

Expand All @@ -385,6 +410,10 @@ public void resignConfirm(Player player, ClanPlayer cp, Clan clan) {
@Description("{@@command.description.resign}")
@HelpSearchTags("leave")
public void resign(@Conditions("clan_member") Player player) {
if (new PrePlayerKickedClanEvent(cm.getClanByPlayerUniqueId(player.getUniqueId()), cm.getClanPlayer(player)).callEvent()) {
ChatBlock.sendMessage(player, RED + lang("error.event.cancelled", player));
return;
}
new SCConversation(plugin, player, new ResignPrompt()).begin();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
package net.sacredlabyrinth.phaed.simpleclans.commands.clan;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.sacredlabyrinth.phaed.simpleclans.*;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Name;
import co.aikar.commands.annotation.Subcommand;
import net.sacredlabyrinth.phaed.simpleclans.ChatBlock;
import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.ClanPlayer;
import net.sacredlabyrinth.phaed.simpleclans.ClanRequest;
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanPlayerInput;
import net.sacredlabyrinth.phaed.simpleclans.conversation.DisbandPrompt;
import net.sacredlabyrinth.phaed.simpleclans.conversation.SCConversation;
import net.sacredlabyrinth.phaed.simpleclans.events.PrePlayerKickedClanEvent;
import net.sacredlabyrinth.phaed.simpleclans.hooks.discord.DiscordHook;
import net.sacredlabyrinth.phaed.simpleclans.hooks.discord.exceptions.DiscordHookException;
import net.sacredlabyrinth.phaed.simpleclans.managers.*;
import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat;
import net.sacredlabyrinth.phaed.simpleclans.managers.ChatManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.ClanManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.RequestManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.StorageManager;
import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils;
import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.Objects;

import static net.sacredlabyrinth.phaed.simpleclans.SimpleClans.lang;
import static net.sacredlabyrinth.phaed.simpleclans.events.EconomyTransactionEvent.Cause.DISCORD_CREATION;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.*;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_CONFIRMATION_FOR_DEMOTE;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_CONFIRMATION_FOR_PROMOTE;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MAX_LENGTH;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MIN_LENGTH;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.CLAN_MIN_TO_VERIFY;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.ECONOMY_DISCORD_CREATION_PRICE;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.ECONOMY_PURCHASE_CLAN_VERIFY;
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.ECONOMY_PURCHASE_DISCORD_CREATE;
import static org.bukkit.ChatColor.AQUA;
import static org.bukkit.ChatColor.RED;

Expand Down Expand Up @@ -106,11 +130,14 @@ public void promote(Player player,
@CommandPermission("simpleclans.leader.disband")
@Description("{@@command.description.disband}")
public void disband(Player player, ClanPlayer cp, Clan clan) {
if (new PrePlayerKickedClanEvent(clan, cp).callEvent()) {
ChatBlock.sendMessage(player, RED + lang("error.event.cancelled", player));
return;
}

if (clan.getLeaders().size() != 1) {
requestManager.requestAllLeaders(cp, ClanRequest.DISBAND, clan.getTag(), "asking.to.disband",
player.getName());
ChatBlock.sendMessage(player, AQUA +
lang("clan.disband.vote.has.been.requested.from.all.leaders", player));
requestManager.requestAllLeaders(cp, ClanRequest.DISBAND, clan.getTag(), "asking.to.disband", player.getName());
ChatBlock.sendMessage(player, AQUA + lang("clan.disband.vote.has.been.requested.from.all.leaders", player));
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package net.sacredlabyrinth.phaed.simpleclans.commands.staff;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.sacredlabyrinth.phaed.simpleclans.*;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.HelpSearchTags;
import co.aikar.commands.annotation.Name;
import co.aikar.commands.annotation.Single;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Values;
import net.sacredlabyrinth.phaed.simpleclans.ChatBlock;
import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.ClanPlayer;
import net.sacredlabyrinth.phaed.simpleclans.Helper;
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanInput;
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanPlayerInput;
import net.sacredlabyrinth.phaed.simpleclans.events.PrePlayerKickedClanEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.PlayerHomeSetEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.PlayerResetKdrEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.TagChangeEvent;
Expand All @@ -15,7 +30,6 @@
import net.sacredlabyrinth.phaed.simpleclans.managers.StorageManager;
import net.sacredlabyrinth.phaed.simpleclans.ui.InventoryController;
import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils;
import net.sacredlabyrinth.phaed.simpleclans.utils.TagValidator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -58,11 +72,16 @@ public void place(CommandSender sender, @Name("player") ClanPlayerInput cpInput,

if (oldCp != null) {
Clan oldClan = Objects.requireNonNull(oldCp.getClan());
if (new PrePlayerKickedClanEvent(oldClan, oldCp).callEvent()) {
ChatBlock.sendMessage(sender, RED + lang("error.event.cancelled", sender));
return;
}

if (oldClan.equals(newClan)) {
ChatBlock.sendMessage(sender, lang("player.already.in.this.clan", sender));
return;
}

if (!oldClan.isPermanent() && oldClan.isLeader(uuid) && oldClan.getLeaders().size() <= 1) {
ChatBlock.sendMessage(sender, RED + lang("you.cannot.move.the.last.leader", sender));
return;
Expand Down Expand Up @@ -247,8 +266,13 @@ public void purge(CommandSender sender, @Name("player") ClanPlayerInput player)

Clan clan = player.getClanPlayer().getClan();
if (clan != null && clan.getMembers().size() == 1) {
if (new PrePlayerKickedClanEvent(clan, player.getClanPlayer()).callEvent()) {
ChatBlock.sendMessage(sender, RED + lang("error.event.cancelled", sender));
return;
}
clan.disband(sender, false, false);
}

cm.deleteClanPlayer(player.getClanPlayer());
ChatBlock.sendMessage(sender, AQUA + lang("player.purged", sender));
}
Expand All @@ -260,13 +284,17 @@ public void purge(CommandSender sender, @Name("player") ClanPlayerInput player)
public void kick(CommandSender sender, @Conditions("clan_member") @Name("player") ClanPlayerInput cp) {
ClanPlayer clanPlayer = cp.getClanPlayer();
Clan clan = Objects.requireNonNull(clanPlayer.getClan());
if (new PrePlayerKickedClanEvent(clan, clanPlayer).callEvent()) {
ChatBlock.sendMessage(sender, RED + lang("error.event.cancelled", sender));
return;
}

if (clanPlayer.isLeader() && clan.getLeaders().size() == 1) {
ChatBlock.sendMessageKey(sender, "cannot.kick.last.leader");
return;
}

clan.addBb(sender.getName(), lang("has.been.kicked.by", clanPlayer.getName(),
sender.getName(), sender));
clan.addBb(sender.getName(), lang("has.been.kicked.by", clanPlayer.getName(), sender.getName(), sender));
clan.removePlayerFromClan(clanPlayer.getUniqueId());
}

Expand All @@ -286,8 +314,7 @@ public void promote(CommandSender sender, @Conditions("online|clan_member") @Nam
ClanPlayer clanPlayer = promote.getClanPlayer();
Player promotePl = Objects.requireNonNull(clanPlayer.toPlayer());
if (!permissions.has(promotePl, "simpleclans.leader.promotable")) {
ChatBlock.sendMessage(sender, RED + lang("the.player.does.not.have.the.permissions.to.lead.a.clan",
sender));
ChatBlock.sendMessage(sender, RED + lang("the.player.does.not.have.the.permissions.to.lead.a.clan", sender));
return;
}
Clan clan = Objects.requireNonNull(clanPlayer.getClan());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.sacredlabyrinth.phaed.simpleclans.events;

import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.ClanPlayer;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* @author ThiagoROX
*/
public class PrePlayerKickedClanEvent extends Event {

private static final HandlerList handlers = new HandlerList();
private final Clan clan;
private final ClanPlayer target;
private boolean cancelled;

public PrePlayerKickedClanEvent(Clan clan, ClanPlayer target) {
this.clan = clan;
this.target = target;
}

public Clan getClan() {
return this.clan;
}

public ClanPlayer getClanPlayer() {
return this.target;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,4 @@ invitedplayer.invite.off=This player has disabled clan invites
user.hasnt.played.before=&cThis user has not played before
clan.list.balance.header=\n{0} &7top balance &8-----------------------\n \n&8Total clans: &7{1}\n \n&8#&7. &8Clan &7- &8Balance
clan.list.balance.line=&f{0}. {1}{2}{3}&b{4} &7- &e{5}$
error.event.cancelled=&cThe event was cancelled

0 comments on commit 4c959cc

Please sign in to comment.