use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class PlayerManager method getPlayer.
public PartyPlayerEntity getPlayer(UUID uuid) {
PartyPlayerEntity ret = null;
if (getListPartyPlayers().containsKey(uuid)) {
ret = getListPartyPlayers().get(uuid);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_GET_LIST.replace("{player}", ret.getName()).replace("{party}", ret.getPartyName()), true);
} else {
if (ret == null) {
PartyPlayer pp = plugin.getDatabaseManager().getPlayer(uuid).join();
if (pp != null) {
ret = new PartyPlayerEntity(pp, plugin);
// Compare name
Player pl = ret.getPlayer();
if (pl != null) {
ret.compareName(pl.getName());
}
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PLAYER_GET_DATABASE.replace("{player}", ret.getName()).replace("{party}", ret.getPartyName()), true);
}
}
if (ret == null)
ret = new PartyPlayerEntity(uuid, plugin);
}
return ret;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandInfo 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.INFO.toString())) {
pp.sendNoPermission(PartiesPermission.INFO);
return false;
}
if (commandData.getArgs().length == 1 && pp.getPartyName().isEmpty()) {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.addPermission(PartiesPermission.INFO_OTHERS);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandJoin method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
String partyName = commandData.getArgs()[1];
PartyEntity party = plugin.getPartyManager().getParty(partyName);
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
return;
}
if (commandData.getArgs().length == 2) {
if (!commandData.havePermission(PartiesPermission.JOIN_BYPASS)) {
if (party.getPassword() != null && !party.getPassword().isEmpty()) {
pp.sendMessage(Messages.ADDCMD_JOIN_WRONGPASSWORD);
return;
}
}
} else {
if (!hash(commandData.getArgs()[2]).equals(party.getPassword())) {
pp.sendMessage(Messages.ADDCMD_JOIN_WRONGPASSWORD);
return;
}
}
if ((ConfigParties.GENERAL_MEMBERSLIMIT != -1) && (party.getMembers().size() >= ConfigParties.GENERAL_MEMBERSLIMIT)) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYFULL);
return;
}
if (VaultHandler.payCommand(VaultHandler.VaultCommand.JOIN, pp, commandData.getCommandLabel(), commandData.getArgs()))
return;
/*
* Command starts
*/
// Calling API Event
PartiesPlayerJoinEvent partiesJoinEvent = new PartiesPlayerJoinEvent(pp, party, false, null);
Bukkit.getServer().getPluginManager().callEvent(partiesJoinEvent);
if (!partiesJoinEvent.isCancelled()) {
pp.sendMessage(Messages.ADDCMD_JOIN_JOINED);
party.sendBroadcast(pp, Messages.ADDCMD_JOIN_PLAYERJOINED);
party.getMembers().add(pp.getPlayerUUID());
party.getOnlinePlayers().add(pp.getPlayer());
pp.setPartyName(party.getName());
pp.setRank(ConfigParties.RANK_SET_DEFAULT);
party.updateParty();
pp.updatePlayer();
party.callChange();
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_JOIN.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_JOINEVENT_DENY.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandJoin 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.JOIN.toString())) {
pp.sendNoPermission(PartiesPermission.JOIN);
return false;
}
if (!pp.getPartyName().isEmpty()) {
pp.sendMessage(Messages.ADDCMD_JOIN_ALREADYINPARTY);
return false;
}
if (commandData.getArgs().length < 2 || commandData.getArgs().length > 3) {
pp.sendMessage(Messages.ADDCMD_JOIN_WRONGCMD);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.addPermission(PartiesPermission.JOIN_BYPASS);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandInvite method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command handling
*/
Player invitedPlayer = plugin.getServer().getPlayer(commandData.getArgs()[1]);
if ((invitedPlayer == null) || (!invitedPlayer.isOnline())) {
pp.sendMessage(Messages.MAINCMD_INVITE_PLAYEROFFLINE);
return;
}
PartyPlayerEntity invitedPp = plugin.getPlayerManager().getPlayer(invitedPlayer.getUniqueId());
if (!invitedPp.getPartyName().isEmpty()) {
pp.sendMessage(Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPp);
return;
}
if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && !invitedPlayer.hasPermission(PartiesPermission.ACCEPT.toString())) {
pp.sendMessage(Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPp);
return;
}
if (invitedPp.getIgnoredParties().contains(party.getName())) {
// Invited player ignoring the party, fake sent
pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
return;
}
if (invitedPp.isPreventNotify() && ConfigMain.ADDITIONAL_NOTIFY_ENABLE && ConfigMain.ADDITIONAL_NOTIFY_BLOCK_INVITE) {
// Invited player has disabled notifications, fake sent
pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
return;
}
boolean isRevoke = false;
if (invitedPp.getLastInvite().contains(party.getName())) {
isRevoke = true;
if (!ConfigParties.GENERAL_INVITE_REVOKE) {
pp.sendMessage(Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPp);
return;
}
}
if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE) {
// Check invite cooldown
ArrayList<InviteCooldown> list = plugin.getPlayerManager().getInviteCooldown().get(pp.getPlayerUUID());
if (list != null) {
for (InviteCooldown ic : list) {
long diff = ic.getDiffTime();
if (ic.getType() == InviteCooldown.CooldownType.GLOBAL || ic.getInvited().equals(invitedPp.getPlayerUUID())) {
if (diff < ic.getType().getTick()) {
String msg = "";
switch(ic.getType()) {
case GLOBAL:
msg = Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL;
break;
case INDIVIDUAL:
msg = Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL;
}
pp.sendMessage(msg.replace("%seconds%", String.valueOf(ic.getType().getTick() - diff)));
return;
}
}
}
}
}
/*
* Command starts
*/
if (isRevoke) {
// Revoke
plugin.getServer().getScheduler().cancelTask(party.getInvited().get(invitedPp.getPlayerUUID()));
party.getInvited().remove(invitedPp.getPlayerUUID());
party.getWhoInvite().remove(invitedPp.getPlayerUUID());
invitedPp.setLastInvite("");
pp.sendMessage(Messages.MAINCMD_INVITE_REVOKE_SENT, invitedPp);
invitedPp.sendMessage(Messages.MAINCMD_INVITE_REVOKE_REVOKED, party);
} else {
// Invite
invitedPp.setLastInvite(party.getName());
pp.sendMessage(Messages.MAINCMD_INVITE_SENT, invitedPp);
invitedPp.sendMessage(Messages.MAINCMD_INVITE_PLAYERINVITED.replace("%player%", pp.getName()), party);
party.invitePlayer(pp.getPlayerUUID(), invitedPlayer.getUniqueId());
if (ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE) {
if (ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL > 0) {
new InviteCooldown(plugin, pp.getPlayerUUID()).createTask(ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
}
if (ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL > 0) {
new InviteCooldown(plugin, pp.getPlayerUUID(), invitedPp.getPlayerUUID()).createTask(ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
}
}
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_INVITE.replace("{player}", pp.getName()).replace("{victim}", invitedPlayer.getName()).replace("{party}", party.getName()), true);
}
}
Aggregations