use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandTeleport 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.TELEPORT.toString())) {
pp.sendNoPermission(PartiesPermission.TELEPORT);
return false;
}
PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_ADMIN_TELEPORT))
return false;
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.setParty(party);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandTeleport method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command handling
*/
long unixNow = -1;
if (ConfigParties.TELEPORT_COOLDOWN > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
Long unixTimestamp = plugin.getPlayerManager().getTeleportCooldown().get(pp.getPlayerUUID());
unixNow = System.currentTimeMillis() / 1000L;
if (unixTimestamp != null) {
pp.sendMessage(Messages.ADDCMD_TELEPORT_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.TELEPORT_COOLDOWN - (unixNow - unixTimestamp))));
return;
}
}
if (VaultHandler.payCommand(VaultHandler.VaultCommand.TELEPORT, pp, commandData.getCommandLabel(), commandData.getArgs()))
return;
/*
* Command starts
*/
if (unixNow != -1) {
plugin.getPlayerManager().getTeleportCooldown().put(pp.getPlayerUUID(), unixNow);
new TeleportTask(pp.getPlayerUUID(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.TELEPORT_COOLDOWN * 20);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_TELEPORT_START.replace("{value}", Integer.toString(ConfigParties.TELEPORT_COOLDOWN * 20)).replace("{player}", pp.getName()), true);
}
pp.sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTING);
for (Player pl : party.getOnlinePlayers()) {
if (!pl.getUniqueId().equals(pp.getPlayerUUID())) {
// Make it sync
plugin.getPartiesScheduler().runSync(() -> {
pl.teleport(commandData.getPlayer().getLocation());
plugin.getPlayerManager().getPlayer(pl.getUniqueId()).sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTED, pp);
});
}
}
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_TELEPORT.replace("{player}", pp.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class FightListener method onEntityDieKill.
@EventHandler
public void onEntityDieKill(EntityDeathEvent event) {
if (event.getEntity().getKiller() instanceof Player) {
Player killer = event.getEntity().getKiller();
PartyPlayerEntity ppKiller = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
if (!ppKiller.getPartyName().isEmpty()) {
PartyEntity party = plugin.getPartyManager().getParty(ppKiller.getPartyName());
if (ConfigParties.KILLS_ENABLE) {
boolean gotKill = false;
if (ConfigParties.KILLS_MOB_HOSTILE && event.getEntity() instanceof Monster)
gotKill = true;
else if (ConfigParties.KILLS_MOB_NEUTRAL && event.getEntity() instanceof Animals)
gotKill = true;
else if (ConfigParties.KILLS_MOB_PLAYERS && event.getEntity() instanceof Player)
gotKill = true;
if (gotKill) {
party.setKills(party.getKills() + 1);
party.updateParty();
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_KILL_ADD.replace("{party}", party.getName()).replace("{player}", killer.getName()), true);
}
}
}
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class FightListener method onEntityCombustByEntity.
@EventHandler
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getCombuster() instanceof Projectile && ((Projectile) event.getCombuster()).getShooter() instanceof Player) {
Player victim = (Player) event.getEntity();
Player attacker = (Player) ((Projectile) event.getCombuster()).getShooter();
// Found right attacker
if (!victim.getUniqueId().equals(attacker.getUniqueId()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
// Friendly fire not allowed here
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
if (!ppVictim.getPartyName().isEmpty() && ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
// Calling API event
PartiesCombustFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesCombustFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
PartyEntity party = plugin.getPartyManager().getParty(ppVictim.getPartyName());
ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(ppVictim, ppAttacker);
event.setCancelled(true);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class ChatListener method onPlayerChat.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (!event.isCancelled()) {
Player p = event.getPlayer();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
if (!pp.getPartyName().isEmpty() && pp.isChatParty()) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
if (PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_SENDMESSAGE)) {
// Chat allowed
boolean mustWait = false;
if (ConfigParties.GENERAL_CHAT_CHATCD > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
Long unixTimestamp = plugin.getPlayerManager().getChatCooldown().get(p.getUniqueId());
long unixNow = System.currentTimeMillis() / 1000L;
// Check cooldown
if (unixTimestamp != null) {
pp.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.GENERAL_CHAT_CHATCD - (unixNow - unixTimestamp))));
mustWait = true;
} else {
plugin.getPlayerManager().getChatCooldown().put(p.getUniqueId(), unixNow);
new ChatTask(p.getUniqueId(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.GENERAL_CHAT_CHATCD * 20);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_CMD_P_TASK.replace("{value}", Integer.toString(ConfigParties.GENERAL_CHAT_CHATCD * 20)).replace("{player}", p.getName()), true);
}
}
if (!mustWait) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
// Calling API event
PartiesChatEvent partiesChatEvent = new PartiesChatEvent(pp, party, event.getMessage());
Bukkit.getServer().getPluginManager().callEvent(partiesChatEvent);
String newMessage = partiesChatEvent.getMessage();
if (!partiesChatEvent.isCancelled()) {
party.sendPlayerMessage(pp, newMessage);
if (ConfigMain.STORAGE_LOG_CHAT)
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_P.replace("{party}", party.getName()).replace("{player}", p.getName()).replace("{message}", newMessage), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CHATEVENT_DENY.replace("{player}", p.getName()).replace("{message}", event.getMessage()), true);
}
} else
pp.sendNoPermission(PartiesPermission.PRIVATE_SENDMESSAGE);
});
event.setCancelled(true);
}
}
}
Aggregations