use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class FightListener method onPotionSplash.
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getPotion().getShooter() instanceof Player) {
Player attacker = (Player) event.getPotion().getShooter();
PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
if (!ppAttacker.getPartyName().isEmpty() && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(attacker.getWorld().getName()))) {
boolean cancel = false;
for (PotionEffect pe : event.getEntity().getEffects()) {
switch(pe.getType().getName().toLowerCase()) {
case "harm":
case "blindness":
case "confusion":
case "poison":
case "slow":
case "slow_digging":
case "weakness":
case "unluck":
cancel = true;
}
if (cancel)
break;
}
if (cancel) {
// Friendly fire not allowed here
PartyEntity party = plugin.getPartyManager().getParty(ppAttacker.getPartyName());
for (LivingEntity e : event.getAffectedEntities()) {
if (e instanceof Player) {
Player victim = (Player) e;
if (!attacker.equals(victim)) {
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
if (ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
// Calling API event
PartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesPotionsFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(ppVictim, ppAttacker);
event.setIntensity(e, 0);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
}
}
}
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class ChatListener method onPlayerCommandPreprocess.
/*
* Auto-command
*/
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (!event.isCancelled() && ConfigMain.ADDITIONAL_AUTOCMD_ENABLE) {
if (event.getMessage().endsWith("\t")) {
// This is an auto command
event.setMessage(event.getMessage().replace("\t", ""));
} else {
// This is a normal command to replicate
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
boolean cancel = false;
for (String str : ConfigMain.ADDITIONAL_AUTOCMD_BLACKLIST) {
if (str.equalsIgnoreCase("*") || event.getMessage().toLowerCase().startsWith(str.toLowerCase())) {
cancel = true;
break;
}
}
for (String str : ConfigMain.ADDITIONAL_AUTOCMD_WHITELIST) {
if (str.equalsIgnoreCase("*") || event.getMessage().toLowerCase().startsWith(str.toLowerCase())) {
cancel = false;
break;
}
}
if (!cancel) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
if (!pp.getPartyName().isEmpty()) {
if (PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_AUTOCOMMAND)) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
for (Player pl : party.getOnlinePlayers()) {
if (!pl.getUniqueId().equals(event.getPlayer().getUniqueId())) {
// Make it sync
plugin.getPartiesScheduler().runSync(() -> {
pl.chat(event.getMessage() + "\t");
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_AUTOCMD_PERFORM.replace("{player}", pl.getName()).replace("{command}", event.getMessage()), true);
});
}
}
}
}
}
});
}
}
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class FollowListener method onChangeWorld.
@EventHandler
public void onChangeWorld(PlayerChangedWorldEvent event) {
if (ConfigMain.ADDITIONAL_FOLLOW_ENABLE) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
if (ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains("*") || ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains(event.getPlayer().getWorld().getName())) {
Player player = event.getPlayer();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
if (!pp.getPartyName().isEmpty()) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
if (party != null) {
if (pp.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKNEEDED) {
// Init teleport
for (Player pl : party.getOnlinePlayers()) {
if (!pl.getUniqueId().equals(player.getUniqueId()) && !pl.getWorld().equals(player.getWorld())) {
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(pl.getUniqueId());
if (ppVictim.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKMINIMUM) {
// Make it sync
plugin.getPartiesScheduler().runSync(() -> {
switch(ConfigMain.ADDITIONAL_FOLLOW_TYPE) {
case 1:
ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
pl.teleport(player.getWorld().getSpawnLocation());
break;
case 2:
ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
pl.teleport(player);
}
});
}
}
}
}
}
}
}
});
}
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class JoinLeaveListener method globalQuit.
private void globalQuit(Player p) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
boolean removePlFromList = true;
// Spy listener
if (pp.isSpy())
plugin.getSpyManager().removeSpy(pp.getPlayerUUID());
// Party checking
if (!pp.getPartyName().isEmpty()) {
if (pp.getHomeTask() != -1)
plugin.getPlayerManager().remHomeCount();
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
if (party != null) {
party.getOnlinePlayers().remove(p);
if (ConfigMain.PARTIES_JLMESSAGES) {
party.sendBroadcast(pp, Messages.OTHER_JOINLEAVE_SERVERLEAVE);
}
if (plugin.getDatabaseManager().getDatabaseType().isNone()) {
// Start delete timeout
if (ConfigMain.STORAGE_SETTINGS_NONE_DISBANDONLEADERLEFT && party.getLeader().equals(p.getUniqueId())) {
// Leader left, delete now
plugin.getPartyManager().deleteTimedParty(party.getName(), true);
} else if (party.getOnlinePlayers().size() == 0) {
// All players left, start timer
if (ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY > 0) {
plugin.getPlayerManager().getListPartyPlayersToDelete().add(p.getUniqueId());
PartyDeleteTask task = (PartyDeleteTask) new PartyDeleteTask(party.getName());
task.runTaskLaterAsynchronously(plugin, ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY * 20);
plugin.getPartyManager().getListPartiesToDelete().put(party.getName().toLowerCase(), task.getTaskId());
removePlFromList = false;
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_DELETE_START.replace("{party}", party.getName()).replace("{value}", Integer.toString(ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY * 20)), true);
} else
plugin.getPartyManager().deleteTimedParty(party.getName(), false);
}
} else {
if (party.getNumberOnlinePlayers() == 0) {
plugin.getPartyManager().unloadParty(party.getName());
}
}
}
}
if (removePlFromList)
plugin.getPlayerManager().unloadPlayer(p.getUniqueId());
});
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class PlayerManager method reload.
public void reload() {
listPartyPlayers = new HashMap<UUID, PartyPlayerEntity>();
listPartyPlayersToDelete = new HashSet<UUID>();
homeCounts = 0;
chatCooldown = new HashMap<>();
inviteCooldown = new HashMap<>();
teleportCooldown = new HashMap<>();
plugin.getSpyManager().refreshSpyList();
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
PartyPlayerEntity pp = loadPlayer(p.getUniqueId());
PartyEntity party = plugin.getPartyManager().loadParty(pp.getPartyName());
if (party != null)
party.getOnlinePlayers().add(p);
}
}
Aggregations