Search in sources :

Example 46 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class AbilityListener method onInteract.

@EventHandler
public void onInteract(PlayerInteractEvent event) {
    Action action = event.getAction();
    if (action == Action.PHYSICAL)
        return;
    UPlayer player = new UPlayer(event);
    if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
        for (Weapon weapon : Weapon.WEAPONS) {
            if (Weapon.itemStackIsWeapon(player.getInventory().getItemInMainHand().getItemStack(), weapon)) {
                player.doAbility(weapon.getLeftClickAbility());
            }
        }
    }
    if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
        for (Weapon weapon : Weapon.WEAPONS) {
            if (Weapon.itemStackIsWeapon(player.getInventory().getItemInMainHand().getItemStack(), weapon)) {
                player.doAbility(weapon.getRightClickAbility());
            }
        }
    }
}
Also used : Action(org.bukkit.event.block.Action) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Weapon(xyz.derkades.ublisk.weapons.Weapon) EventHandler(org.bukkit.event.EventHandler)

Example 47 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class CheckTown method run.

@Override
public void run() {
    for (UPlayer player : Ublisk.getOnlinePlayers()) {
        Town town = player.getTown();
        Town lastTown = player.getLastTown();
        if (town == null && !SENT_LEFT_MESSAGE.contains(player.getUniqueId())) {
            // If the player is no longer in a town
            player.sendSubTitle(ChatColor.GRAY + "You left " + lastTown.getName());
            SENT_LEFT_MESSAGE.add(player.getUniqueId());
            Logger.log(LogLevel.INFO, "Town", player.getName() + " left " + lastTown.getName());
        } else if (town != null && SENT_LEFT_MESSAGE.contains(player.getUniqueId())) {
            // As soon as the player enters a town and has got a left message
            player.sendSubTitle(ChatColor.GRAY + "You are now in " + town.getName());
            Logger.log(LogLevel.INFO, "Town", player.getName() + " is now in " + lastTown.getName());
            player.setLastTown(town);
            SENT_LEFT_MESSAGE.remove(player.getUniqueId());
        }
        if (town != null) {
            player.setWeather(town.getWeather());
        }
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Town(xyz.derkades.ublisk.Town)

Aggregations

UPlayer (xyz.derkades.ublisk.utils.UPlayer)47 EventHandler (org.bukkit.event.EventHandler)26 Player (org.bukkit.entity.Player)9 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)7 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)5 Item (xyz.derkades.ublisk.utils.inventory.Item)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)4 ArrayList (java.util.ArrayList)3 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)3 Material (org.bukkit.Material)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Chest (org.bukkit.block.Chest)3 Action (org.bukkit.event.block.Action)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Town (xyz.derkades.ublisk.Town)3 MainMenu (xyz.derkades.ublisk.iconmenus.MainMenu)3 UUID (java.util.UUID)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2