use of com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent in project Parties by AlessioDP.
the class CommandLeave method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command starts
*/
// Calling API event
PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, false, null);
Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
if (!partiesLeaveEvent.isCancelled()) {
if (party.getLeader().equals(pp.getPlayerUUID())) {
// Is leader
// Calling Pre API event
PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, null, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
party.removeParty();
party.callChange();
// Calling Post API event
PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, null, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE_DISBAND.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
} else {
party.getMembers().remove(pp.getPlayerUUID());
party.getOnlinePlayers().remove(commandData.getPlayer());
pp.cleanupPlayer(true);
pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_BROADCAST);
party.updateParty();
party.callChange();
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
use of com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent in project Parties by AlessioDP.
the class BMHook method onPlayerBan.
@EventHandler(ignoreCancelled = true)
public void onPlayerBan(PlayerBannedEvent event) {
PlayerData pl = event.getBan().getPlayer();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(pl.getUUID());
// Spy listener
if (pp.isSpy())
plugin.getSpyManager().removeSpy(pp.getPlayerUUID());
// Party checking
if (!pp.getPartyName().isEmpty()) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
if (party != null) {
PartyPlayerEntity kickerPp = plugin.getPlayerManager().getPlayer(event.getBan().getActor().getUUID());
// Calling API event
PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, true, kickerPp);
Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
if (!partiesLeaveEvent.isCancelled()) {
if (party.getLeader().equals(pl.getUUID())) {
// Calling Pre API event
PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.BAN, pp, kickerPp);
Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
party.removeParty();
// Calling Post API event
PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.BAN, pp, kickerPp);
Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_LIB_BANMANAGER_BAN.replace("{party}", party.getName()).replace("{player}", pl.getName()), true, ConsoleColor.CYAN);
} else {
// Event is cancelled, block ban chain
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY_GENERIC.replace("{party}", party.getName()), true);
return;
}
} else {
party.getMembers().remove(pl.getUUID());
party.getOnlinePlayers().remove(pl.getPlayer());
party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST);
party.updateParty();
}
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{player}", pl.getName()).replace("{party}", party.getName()), true);
}
pp.cleanupPlayer(true);
}
}
use of com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent in project Parties by AlessioDP.
the class CommandKick method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
// Players conflict handler
List<PartyPlayer> listPlayers = plugin.getDatabaseManager().getPartyPlayersByName(playerName).join();
UUID[] playerSelection = new UUID[listPlayers.size()];
if (listPlayers.size() < 1) {
// Other player not in party
pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER.replace("%player%", playerName));
return;
} else if (listPlayers.size() == 1) {
// Get the player
playerUUID = listPlayers.get(0).getPlayerUUID();
} else {
// Found multiple players name
StringBuilder sb = new StringBuilder();
for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (PartyPlayer pl : listPlayers) {
String mojangName = getNameFromMojangAPI(playerName, pl.getPlayerUUID());
if (mojangName == null)
mojangName = pl.getName();
Date date = new Date(pl.getNameTimestamp() * 1000);
Time time = new Time(date.getTime());
sb.append(Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", mojangName).replace("%party%", pl.getPartyName()).replace("%date%", date.toString()).replace("%time%", time.toString()) + "\n");
playerSelection[i - 1] = pl.getPlayerUUID();
i++;
}
} else
sb.append(str + "\n");
}
// Selection handling
if (commandData.getArgs().length == 2) {
// Print content
pp.sendMessage(sb.toString());
return;
}
int sel = -1;
try {
sel = Integer.parseInt(commandData.getArgs()[2]);
playerUUID = playerSelection[sel - 1];
} catch (Exception ex) {
// Problem with selection, print content
pp.sendMessage(sb.toString());
return;
}
}
OfflinePlayer kickedPlayer = Bukkit.getOfflinePlayer(playerUUID);
PartyPlayerEntity kickedPp = plugin.getPlayerManager().getPlayer(playerUUID);
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
boolean otherParty = false;
if (party == null || !party.getMembers().contains(kickedPlayer.getUniqueId()) && commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
// Other party
otherParty = true;
party = plugin.getPartyManager().getParty(kickedPp.getPartyName());
if (party == null) {
pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER, kickedPp);
return;
}
} else {
// Same party
if (party == null || !party.getMembers().contains(playerUUID)) {
pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
return;
}
if (pp.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
pp.sendMessage(Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
return;
}
}
/*
* Command starts
*/
// Calling API event
PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(kickedPp, party, otherParty, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
if (!partiesLeaveEvent.isCancelled()) {
if (party.getLeader().equals(kickedPlayer.getUniqueId())) {
// Leader
// Calling Pre API event
PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST_DISBAND);
party.removeParty();
party.callChange();
// Calling Post API event
PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK_DISBAND.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
} else {
// Normal
party.getMembers().remove(kickedPlayer.getUniqueId());
Player kickedPl = kickedPp.getPlayer();
if (kickedPl != null) {
// Online
party.getOnlinePlayers().remove(kickedPl);
pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, pp);
party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
kickedPp.cleanupPlayer(true);
party.callChange();
} else {
pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
kickedPp.cleanupPlayer(true);
}
party.updateParty();
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
}
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
Aggregations