use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class BukkitFollowListener method onChangeWorld.
@EventHandler(ignoreCancelled = true)
public void onChangeWorld(PlayerChangedWorldEvent event) {
if (BukkitConfigMain.ADDITIONAL_FOLLOW_ENABLE) {
// Make it async
Player bukkitPlayer = event.getPlayer();
plugin.getScheduler().scheduleAsyncLater(() -> {
if (allowedWorld(event.getPlayer().getWorld().getName())) {
PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
if (party != null && party.isFollowEnabled() && (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID()))) {
// Let other players follow him
sendMembers(party, player, bukkitPlayer, event.getFrom());
}
}
}, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class BungeeFollowListener method onConnected.
@EventHandler
public void onConnected(ServerSwitchEvent event) {
if (!BungeeConfigMain.ADDITIONAL_FOLLOW_ENABLE)
return;
// Not connected to the network yet
if (event.getPlayer().getServer() == null)
return;
plugin.getScheduler().scheduleAsyncLater(() -> {
if (allowedServer(event.getPlayer().getServer().getInfo().getName())) {
PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
if (party != null && party.isFollowEnabled() && (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID()))) {
String playerServer = event.getPlayer().getServer().getInfo().getName();
ServerInfo serverInfo = ((BungeePartiesBootstrap) plugin.getBootstrap()).getProxy().getServerInfo(playerServer);
// Calling API event
BungeePartiesPartyFollowEvent partyFollowEvent = ((BungeeEventManager) plugin.getEventManager()).preparePartyFollowEvent(party, playerServer);
plugin.getEventManager().callEvent(partyFollowEvent);
if (!partyFollowEvent.isCancelled()) {
// Let other players follow him
sendMembers(party, player, serverInfo);
}
}
}
}, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class BukkitPartiesBungeecordListener method handleAddHome.
public void handleAddHome(PartiesPacket packet) {
((PartiesPlugin) plugin).getPartyManager().reloadParty(packet.getParty());
PartyImpl party = ((PartiesPlugin) plugin).getPartyManager().getParty(packet.getParty());
PartyPlayerImpl partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(packet.getPlayer());
if (party != null && partyPlayer != null) {
try {
String name = packet.getText();
String server = packet.getSecondaryText();
PartyHomeImpl home = BukkitCommandSetHome.getHomeLocationOfPlayer(partyPlayer, name, server);
if (home != null) {
if (((PartiesPlugin) plugin).isBungeeCordEnabled())
((BukkitPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(party, home.toString());
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME, home, party.getId(), partyPlayer.getPlayerUUID(), server), true);
}
} catch (Exception ex) {
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_HOME_ERROR, ex);
}
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class BungeeCommandHome method teleportToPartyHome.
public static void teleportToPartyHome(PartiesPlugin plugin, User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
if (home.getServer() != null && !home.getServer().isEmpty()) {
boolean serverChange = false;
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(home.getServer());
IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
plugin.getEventManager().callEvent(partiesPreHomeEvent);
if (!partiesPreHomeEvent.isCancelled()) {
if (((BungeeUser) player).getServer() == null)
// Cannot get player server
return;
if (BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((BungeeUser) player).getServer().getName().equalsIgnoreCase(home.getServer())) {
if (serverInfo == null) {
plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
return;
}
((BungeeUser) player).connectTo(serverInfo);
serverChange = true;
}
String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
if (serverChange) {
plugin.getScheduler().scheduleAsyncLater(() -> ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo), BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
} else {
((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo);
}
IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(partyPlayer, party, home);
plugin.getEventManager().callEvent(partiesPostHomeEvent);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_HOME_NO_SERVER, party.getId()));
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandColor method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = ((PartiesCommandData) commandData).getParty();
// Command handling
Set<PartyColorImpl> availableColors = getPlugin().getColorManager().getAvailableColors(sender);
if (commandData.getArgs().length == 1) {
if (party.getColor() != null)
sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_INFO, availableColors));
else
sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_EMPTY, availableColors));
return;
}
boolean isRemove = false;
PartyColor color = null;
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
} else {
// Normal command
for (PartyColorImpl pc : availableColors) {
if (pc.getCommand().equalsIgnoreCase(commandData.getArgs()[1])) {
color = pc;
break;
}
}
if (color == null) {
// Color doesn't exist
sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_WRONGCOLOR, availableColors));
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.COLOR, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
party.setColor(color);
if (isRemove) {
sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_REMOVED, availableColors));
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_CHANGED, availableColors), party);
party.broadcastMessage(parseWithAvailableColors(Messages.ADDCMD_COLOR_BROADCAST, availableColors), partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", color.getName()), true);
}
}
Aggregations