Search in sources :

Example 6 with EventHandler

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) {
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell) EventHandler(org.bukkit.event.EventHandler)

Example 7 with EventHandler

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
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) UUID(java.util.UUID) Map(java.util.Map) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 8 with EventHandler

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);
    }
}
Also used : Entity(org.bukkit.entity.Entity) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ArmorStand(org.bukkit.entity.ArmorStand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 9 with EventHandler

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();
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PacketSpyAction(fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction) IOException(java.io.IOException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 10 with EventHandler

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());
    });
}
Also used : User(me.lucko.luckperms.common.model.User) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)37 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)7 IOException (java.io.IOException)5 User (me.lucko.luckperms.common.model.User)4 EventHandler (org.bukkit.event.EventHandler)4 UserPreference (com.github.games647.changeskin.core.model.UserPreference)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Message (io.github.lxgaming.discordbot.entries.Message)3 Tristate (me.lucko.luckperms.api.Tristate)3 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)3 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)3 Entity (org.bukkit.entity.Entity)3 Player (org.bukkit.entity.Player)3 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2