use of net.md_5.bungee.event.EventHandler in project solinia3-core by mixxit.
the class Solinia3CoreEntityListener method onEntityDamage.
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled())
return;
if (!(event instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
// If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
if (event.getCause().equals(DamageCause.THORNS)) {
damagecause.setDamage(DamageModifier.BLOCKING, 0);
} else {
// Only give them 15% blocking
double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
}
}
// and check they are not mezzed
try {
if (damagecause.getDamager() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) attacker;
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
// cancel attacks on mobs mezzed
if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
if (mezExpiry != null) {
((Creature) attacker).setTarget(null);
if (solCreatureEntity.isPet()) {
Wolf wolf = (Wolf) attacker;
wolf.setTarget(null);
solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
}
event.setCancelled(true);
return;
}
}
}
try {
Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
if (mzExpiry != null) {
if (attacker instanceof Player) {
attacker.sendMessage("* You are mezzed!");
}
Utils.CancelEvent(event);
;
return;
}
} catch (CoreStateInitException e) {
}
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
}
}
} catch (CoreStateInitException e) {
// skip
}
// Remove buffs on recipient (invis should drop)
try {
if (event.getEntity() instanceof LivingEntity) {
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.isInvulnerable()) {
event.setDamage(0);
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
}
}
}
// see if any runes want to reduce this damage
if (event.getEntity() instanceof LivingEntity) {
if (!event.getCause().equals(DamageCause.THORNS)) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.getRune() > 0) {
event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
if (event.getDamage() <= 0) {
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
}
return;
}
}
}
} catch (CoreStateInitException e) {
// skip
}
if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
// code
if (event.getCause().equals(DamageCause.THORNS)) {
if (damagecause.getDamager() instanceof Player) {
LivingEntity recipient = (LivingEntity) event.getEntity();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
String name = recipient.getName();
if (recipient.getCustomName() != null)
name = recipient.getCustomName();
((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
}
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solentity;
try {
solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
Utils.CancelEvent(event);
solentity.removeDeathSaves(plugin);
solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
return;
}
solentity.damageHook(event.getDamage(), damagecause.getDamager());
} catch (CoreStateInitException e) {
// skip
}
}
return;
}
try {
Entity damager = damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
damager = (LivingEntity) arr.getShooter();
// Modify Player Bow Damage
if (arr.getShooter() instanceof Player) {
Player shooter = (Player) arr.getShooter();
ItemStack mainitem = shooter.getInventory().getItemInMainHand();
if (mainitem != null) {
if (mainitem.getType() == Material.BOW) {
int dmgmodifier = 0;
if (Utils.IsSoliniaItem(mainitem)) {
try {
ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
dmgmodifier = item.getDamage();
}
} catch (SoliniaItemException e) {
// sok just skip
}
}
event.setDamage(event.getDamage() + dmgmodifier);
}
}
}
} else {
}
}
if (!(damager instanceof LivingEntity))
return;
LivingEntity attacker = (LivingEntity) damager;
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
if (attacker == null)
return;
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
if (soldefender.isPet()) {
Wolf wolf = (Wolf) event.getEntity();
if (wolf != null) {
if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
Utils.CancelEvent(event);
;
return;
}
} else {
Utils.CancelEvent(event);
;
return;
}
}
}
if (!(event instanceof EntityDamageByEntityEvent)) {
soldefender.damageHook(event.getDamage(), damagecause.getDamager());
return;
}
solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
} catch (CoreStateInitException e) {
}
}
}
use of net.md_5.bungee.event.EventHandler in project solinia3-core by mixxit.
the class Solinia3CoreItemPickupListener method PickupItem.
@EventHandler
public void PickupItem(PlayerPickupItemEvent e) {
ItemStack pickedUpItemStack = e.getItem().getItemStack();
// Replace oxygen items with durability items
if (pickedUpItemStack.getEnchantmentLevel(Enchantment.OXYGEN) > 999) {
e.getPlayer().sendMessage("Detected an item in the old format, converting to the new format. Please drop all your old items and pick them up if you are having problems with them");
try {
ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItemByOxygen(pickedUpItemStack);
if (pickedUpItemStack != null) {
if (latestitem != null) {
ItemStack latestitemstack = latestitem.asItemStack();
pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
} else {
// this is an item that is broken
e.getPlayer().sendMessage("This item is no longer implemented");
Utils.CancelEvent(e);
e.getItem().remove();
}
}
} catch (CoreStateInitException eOxy) {
}
}
String temporaryGuid = null;
Integer augmentationItemId = null;
try {
if (Utils.IsSoliniaItem(pickedUpItemStack) && pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
e.getPlayer().sendMessage(ChatColor.GRAY + "You have picked up an ability! To use it, hold it in your hand and right click!");
ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
if (pickedUpItemStack != null) {
if (latestitem != null) {
ItemStack latestitemstack = latestitem.asItemStack();
pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
} else {
// this is an item that is broken
e.getPlayer().sendMessage("This item is no longer implemented");
Utils.CancelEvent(e);
e.getItem().remove();
}
}
if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
latestitem.setDiscoverer(e.getPlayer().getCustomName());
e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
}
}
if (Utils.IsSoliniaItem(pickedUpItemStack) && !(pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK))) {
Map<Enchantment, Integer> oldenchantments = pickedUpItemStack.getEnchantments();
ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
latestitem.setDiscoverer(e.getPlayer().getCustomName());
e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
}
if (pickedUpItemStack != null) {
ItemStack latestitemstack = latestitem.asItemStack();
// We need to store this information before we change the itemmeta, so we can update it afterwards
if (latestitem.isTemporary()) {
temporaryGuid = ItemStackUtils.getTemporaryItemGuid(pickedUpItemStack);
}
augmentationItemId = ItemStackUtils.getAugmentationItemId(pickedUpItemStack);
// Now go and replace the itemmeta
pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
// Now re-apply enchantments that it had before
for (Map.Entry<Enchantment, Integer> entry : oldenchantments.entrySet()) {
Enchantment key = entry.getKey();
Integer value = entry.getValue();
if (value < 1000) {
pickedUpItemStack.addUnsafeEnchantment(key, value);
}
}
// Since the item is temporary, attempt to apply the temporary timestamp it had prior to this
if (latestitem.isTemporary()) {
pickedUpItemStack.setItemMeta(ItemStackUtils.applyTemporaryStamp(pickedUpItemStack, temporaryGuid));
}
if (augmentationItemId != null && augmentationItemId != 0) {
pickedUpItemStack.setItemMeta(ItemStackUtils.applyAugmentationToItemStack(pickedUpItemStack, augmentationItemId));
}
}
}
// group messages
if (Utils.IsSoliniaItem(pickedUpItemStack)) {
ISoliniaItem item;
try {
item = SoliniaItemAdapter.Adapt(pickedUpItemStack);
if (item.getAllowedClassNames().size() > 0) {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(e.getPlayer());
if (solPlayer.getGroup() != null && solPlayer.getGroup().getMembers() != null)
for (UUID playerUuid : solPlayer.getGroup().getMembers()) {
if (playerUuid.equals(e.getPlayer().getUniqueId()))
continue;
Player groupMember = Bukkit.getPlayer(playerUuid);
ISoliniaPlayer groupSolPlayer = SoliniaPlayerAdapter.Adapt(groupMember);
if (groupSolPlayer != null) {
if (groupSolPlayer.getClassObj() != null)
if (item.getAllowedClassNames().contains(groupSolPlayer.getClassObj().getName().toUpperCase())) {
TextComponent tc = new TextComponent();
tc.setText("* " + groupSolPlayer.getFullName() + " picked up an item of interest to your class: [" + ChatColor.AQUA + item.getDisplayname() + ChatColor.RESET + "]");
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
groupSolPlayer.getBukkitPlayer().spigot().sendMessage(tc);
}
}
}
}
} catch (SoliniaItemException e1) {
}
}
} catch (CoreStateInitException coreException) {
// do nothing
}
}
use of net.md_5.bungee.event.EventHandler in project Ublisk by Derkades.
the class PlayerInteractEntity method onPlayerInteractEntityEvent.
@EventHandler
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getHand() != EquipmentSlot.HAND)
return;
Entity entity = event.getRightClicked();
final UPlayer player = new UPlayer(event);
if (entity instanceof ArmorStand && player.getGameMode() != GameMode.CREATIVE) {
event.setCancelled(true);
}
if (entity instanceof Player && player.isSneaking()) {
UPlayer target = new UPlayer(entity);
BaseComponent[] stats = new ComponentBuilder("View statistics").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to open website").color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://ublisk.robinmc.com/stats/player.php?player=" + target.getName())).create();
BaseComponent[] addAsFriend = new ComponentBuilder("Add as friend").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to run /friend add " + target.getName()).color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend add " + target.getName())).create();
BaseComponent[] inviteToGuild = new ComponentBuilder("Invite to guild").bold(true).color(DARK_AQUA).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to run /guild invite " + target.getName()).color(GOLD).create())).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild invite " + target.getName())).create();
player.sendSpacers(2);
player.sendMessage(stats);
player.sendMessage(addAsFriend);
player.sendMessage(inviteToGuild);
}
}
use of net.md_5.bungee.event.EventHandler in project FireAPI by FireBlade-Serv.
the class Events method onLoginSuccefull.
@EventHandler
public void onLoginSuccefull(LoginSuccessEvent e) {
ProxiedPlayer pp = e.getPlayer();
this.stillconnected.remove(pp);
pp.connect(this.instance.getBungeePlugin().getProxy().getServerInfo("hub"));
this.friends.sendFriendsAlert(pp);
try {
this.c.sendPacket(new PacketSpyAction(pp.getName(), pp.getAddress().getAddress().getHostAddress(), "Le joueur vient de passer les sécurités du login.", SpyAction.PLAYER_LOGGED));
} catch (IOException e1) {
e1.printStackTrace();
}
}
use of net.md_5.bungee.event.EventHandler in project LuckPerms by lucko.
the class BungeeConnectionListener method onPlayerLogin.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(LoginEvent e) {
/* Called when the player first attempts a connection with the server.
Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins)
Delay the login here, as we want to cache UUID data before the player is connected to a backend bukkit server.
This means that a player will have the same UUID across the network, even if parts of the network are running in
Offline mode. */
/* registers the plugins intent to modify this events state going forward.
this will prevent the event from completing until we're finished handling. */
e.registerIntent(this.plugin.getBootstrap());
final PendingConnection c = e.getConnection();
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
this.plugin.getLogger().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
}
this.plugin.getBootstrap().getScheduler().doAsync(() -> {
recordConnection(c.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
This includes:
- loading uuid data
- loading permissions
- creating a user instance in the UserManager for this connection.
- setting up cached data. */
try {
User user = loadUser(c.getUniqueId(), c.getName());
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
ex.printStackTrace();
// there was some error loading
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// cancel the login attempt
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
e.setCancelled(true);
}
}
// finally, complete our intent to modify state, so the proxy can continue handling the connection.
e.completeIntent(this.plugin.getBootstrap());
});
}
Aggregations