use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class JoinLeaveListener method onPlayerJoin.
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
Player player = event.getPlayer();
PartyPlayerEntity pp = plugin.getPlayerManager().loadPlayer(player.getUniqueId());
// None database: stop deleting player/party
if (plugin.getDatabaseManager().getDatabaseType().isNone() && plugin.getPlayerManager().getListPartyPlayersToDelete().contains(player.getUniqueId()))
plugin.getPlayerManager().getListPartyPlayersToDelete().remove(player.getUniqueId());
// Spy listener
if (pp.isSpy())
plugin.getSpyManager().addSpy(pp.getPlayerUUID());
// Party checking
if (!pp.getPartyName().isEmpty() || ConfigParties.FIXED_DEFAULT_ENABLE) {
PartyEntity party = plugin.getPartyManager().loadParty(pp.getPartyName());
if (party != null) {
// Party found
party.getOnlinePlayers().add(player);
if (plugin.getPartyManager().getListPartiesToDelete().containsKey(party.getName().toLowerCase())) {
Bukkit.getScheduler().cancelTask(plugin.getPartyManager().getListPartiesToDelete().get(party.getName().toLowerCase()));
plugin.getPartyManager().getListPartiesToDelete().remove(party.getName().toLowerCase());
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_DELETE_STOP.replace("{party}", party.getName()), true);
}
if (!party.getMotd().isEmpty())
new MotdTask(plugin, player, pp.getCreateID()).runTaskLater(plugin, ConfigParties.MOTD_DELAY);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_JOIN.replace("{player}", player.getName()).replace("{party}", party.getName()), true);
} else {
// Party not found - checking for default one
if (ConfigParties.FIXED_DEFAULT_ENABLE) {
party = plugin.getPartyManager().loadParty(ConfigParties.FIXED_DEFAULT_PARTY);
if (party != null) {
party.getMembers().add(pp.getPlayerUUID());
party.getOnlinePlayers().add(player);
pp.setPartyName(party.getName());
pp.setRank(ConfigParties.RANK_SET_DEFAULT);
party.updateParty();
pp.updatePlayer();
if (!party.getMotd().isEmpty())
new MotdTask(plugin, player, pp.getCreateID()).runTaskLater(plugin, ConfigParties.MOTD_DELAY);
pp.sendMessage(Messages.OTHER_FIXED_DEFAULTJOIN, party);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_PLAYER_JOIN_DEFAULTJOIN.replace("{player}", player.getName()).replace("{party}", party.getName()), true);
} else {
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_PLAYER_JOIN_DEFAULTFAIL.replace("{party}", ConfigParties.FIXED_DEFAULT_PARTY), true, ConsoleColor.RED);
}
}
}
if (ConfigMain.PARTIES_JLMESSAGES && party != null) {
party.sendBroadcast(pp, Messages.OTHER_JOINLEAVE_SERVERJOIN);
}
}
if (ConfigMain.PARTIES_UPDATES_WARN && player.hasPermission(PartiesPermission.ADMIN_UPDATES.toString())) {
if (!ADPUpdater.getFoundVersion().isEmpty()) {
pp.sendMessage(Messages.PARTIES_UPDATEAVAILABLE.replace("%version%", ADPUpdater.getFoundVersion()).replace("%thisversion%", plugin.getDescription().getVersion()));
}
}
});
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class PartyEntity method acceptInvite.
public void acceptInvite(UUID to) {
plugin.getServer().getScheduler().cancelTask(invited.get(to));
UUID from = whoInvite.get(to);
PartyPlayerEntity fromPp = plugin.getPlayerManager().getPlayer(from);
PartyPlayerEntity toPp = plugin.getPlayerManager().getPlayer(to);
// Calling API Event
PartiesPlayerJoinEvent partiesJoinEvent = new PartiesPlayerJoinEvent(toPp, this, true, from);
Bukkit.getServer().getPluginManager().callEvent(partiesJoinEvent);
if (!partiesJoinEvent.isCancelled()) {
// Send accepted
fromPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTRECEIPT, toPp);
// Send you accepted
toPp.sendMessage(Messages.MAINCMD_ACCEPT_ACCEPTED, fromPp);
whoInvite.remove(to);
invited.remove(to);
toPp.setLastInvite("");
sendBroadcast(toPp, Messages.MAINCMD_ACCEPT_BROADCAST);
getMembers().add(to);
onlinePlayers.add(toPp.getPlayer());
toPp.setPartyName(getName());
toPp.setRank(ConfigParties.RANK_SET_DEFAULT);
updateParty();
toPp.updatePlayer();
callChange();
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_JOINEVENT_DENY.replace("{player}", toPp.getName()).replace("{party}", getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class PartyEntity method removeParty.
public void removeParty() {
plugin.getPartyManager().getListParties().remove(getName().toLowerCase());
DynmapHandler.removeMarker(getName());
plugin.getDatabaseManager().removeParty(this);
plugin.getTagManager().deleteTag(this);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_REMOVED.replace("{party}", getName()), true);
for (UUID uuid : getMembers()) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(uuid);
pp.cleanupPlayer(true);
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandIgnore method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
boolean isPrompt = false;
String ignoredParty = "";
if (commandData.getArgs().length == 1) {
// Shows ignore list
isPrompt = true;
} else {
// Edit party ignore
if (commandData.getArgs().length > 2) {
pp.sendMessage(Messages.MAINCMD_IGNORE_WRONGCMD);
return;
}
ignoredParty = commandData.getArgs()[1];
if (!plugin.getPartyManager().existParty(ignoredParty)) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", ignoredParty));
return;
}
}
/*
* Command starts
*/
if (isPrompt) {
StringBuilder builder = new StringBuilder();
for (String name : pp.getIgnoredParties()) {
if (builder.length() > 0) {
builder.append(Messages.MAINCMD_IGNORE_LIST_SEPARATOR);
}
builder.append(Messages.MAINCMD_IGNORE_LIST_PARTYPREFIX + name);
}
String ignores = builder.toString();
if (pp.getIgnoredParties().size() == 0 || ignores == null)
ignores = Messages.MAINCMD_IGNORE_LIST_EMPTY;
pp.sendMessage(Messages.MAINCMD_IGNORE_LIST_HEADER.replace("%number%", Integer.toString(pp.getIgnoredParties().size())));
pp.sendMessage(ignores);
} else {
if (pp.getIgnoredParties().contains(ignoredParty)) {
// Remove
pp.getIgnoredParties().remove(ignoredParty);
pp.sendMessage(Messages.MAINCMD_IGNORE_STOP.replace("%party%", ignoredParty));
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_START.replace("{player}", pp.getName()).replace("{party}", ignoredParty), true);
} else {
// Add
pp.getIgnoredParties().add(ignoredParty);
pp.sendMessage(Messages.MAINCMD_IGNORE_START.replace("%party%", ignoredParty));
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_STOP.replace("{player}", pp.getName()).replace("{party}", ignoredParty), true);
}
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandIgnore method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
Player player = (Player) commandData.getSender();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
/*
* Checks for command prerequisites
*/
if (!player.hasPermission(PartiesPermission.IGNORE.toString())) {
pp.sendNoPermission(PartiesPermission.IGNORE);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
return true;
}
Aggregations