use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class ApiHandler method createParty.
@Override
public Status createParty(PartyPlayer paramPartyPlayer, String paramPartyName) {
Status ret = Status.ALREADYINPARTY;
// Get an instance of PartyPlayerEntity, used to save same player
PartyPlayerEntity player = null;
if (paramPartyPlayer instanceof PartyPlayerEntity) {
player = (PartyPlayerEntity) paramPartyPlayer;
} else {
player = (PartyPlayerEntity) getPartyPlayer(paramPartyPlayer.getPlayerUUID());
}
if (player.getPartyName().isEmpty()) {
if (!plugin.getPartyManager().existParty(paramPartyName)) {
PartyEntity party = new PartyEntity(paramPartyName, plugin);
party.getMembers().add(player.getPlayerUUID());
Player p = player.getPlayer();
if (p != null)
party.getOnlinePlayers().add(p);
party.setLeader(player.getPlayerUUID());
plugin.getPartyManager().getListParties().put(party.getName().toLowerCase(), party);
player.setRank(ConfigParties.RANK_SET_HIGHER);
player.setPartyName(party.getName());
party.updateParty();
player.updatePlayer();
party.callChange();
return Status.SUCCESS;
} else
ret = Status.ALREADYEXISTPARTY;
}
return ret;
}
use of com.alessiodp.parties.parties.objects.PartyEntity 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.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class PAPIHook method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player p, String identifier) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
return ph != null ? ph.formatPlaceholder(pp, party) : "";
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CrackShotHandler method onWeaponDamageEntity.
@EventHandler
public void onWeaponDamageEntity(WeaponDamageEntityEvent event) {
if (active && ConfigParties.FRIENDLYFIRE_ENABLE) {
if (event.getVictim() instanceof Player) {
PartyPlayerEntity shooterPp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
Player victim = (Player) event.getVictim();
if (!victim.getUniqueId().equals(shooterPp.getPlayerUUID()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
PartyPlayerEntity victimPp = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
if (!shooterPp.getPartyName().isEmpty() && shooterPp.getPartyName().equalsIgnoreCase(victimPp.getPartyName())) {
// Calling API event
PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(victimPp, shooterPp, null);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
PartyEntity party = plugin.getPartyManager().getParty(victimPp.getPartyName());
shooterPp.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(victimPp, shooterPp);
event.setCancelled(true);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class FightListener method onPlayerHit.
@EventHandler
public void onPlayerHit(EntityDamageByEntityEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player) {
Player victim = (Player) event.getEntity();
Player attacker = null;
// 0=Basic, 1=Arrow, 2=EnderPearl, 3=Snowball
DamageType type = DamageType.UNSUPPORTED;
if (event.getDamager() instanceof Player)
type = DamageType.PLAYER;
else if (event.getDamager() instanceof Arrow)
type = DamageType.ARROW;
else if (event.getDamager() instanceof EnderPearl)
type = DamageType.ENDERPEARL;
else if (event.getDamager() instanceof Snowball)
type = DamageType.SNOWBALL;
if (!type.equals(DamageType.UNSUPPORTED)) {
ProjectileSource shooterSource;
switch(type) {
case PLAYER:
attacker = (Player) event.getDamager();
break;
case ARROW:
shooterSource = ((Arrow) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case ENDERPEARL:
shooterSource = ((EnderPearl) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case SNOWBALL:
shooterSource = ((Snowball) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case UNSUPPORTED:
}
if (attacker != null) {
// 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
PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(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}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
}
}
Aggregations