Search in sources :

Example 6 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer 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 7 with UPlayer

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

the class PlayerLoginRoom method onMove.

@EventHandler(priority = EventPriority.MONITOR)
public void onMove(PlayerMoveEvent event) {
    final UPlayer player = new UPlayer(event);
    if (TELEPORT_COOLDOWN.contains(player.getName())) {
        return;
    }
    if (!isInRange(player)) {
        return;
    }
    Block blockStandingOn = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    if (blockStandingOn.getType() == Material.BEDROCK) {
        TELEPORT_COOLDOWN.add(player.getName());
        new BukkitRunnable() {

            public void run() {
                if (TELEPORT_COOLDOWN.contains(player.getName())) {
                    TELEPORT_COOLDOWN.remove(player.getName());
                }
            }
        }.runTaskLater(Main.getInstance(), 10 * 20);
        YamlConfiguration config = DataFile.PLAYER_LOCATION.getConfig();
        String locationString = config.getString(player.getUniqueId().toString());
        Location location;
        if (locationString == null) {
            location = new Location(Var.WORLD, 1, 67, -2, 0, 0);
        } else {
            location = LocationUtils.getLocationFromString(locationString);
        }
        player.teleport(location);
        Ublisk.spawnParticle(Particle.EXPLOSION_NORMAL, location, 20, 0, 0, 0, 0.1);
        player.removePotionEffect(PotionEffectType.INVISIBILITY);
        if (IN_PORTAL_ROOM.contains(player.getName())) {
            IN_PORTAL_ROOM.remove(player.getName());
        }
        player.setAbilitiesEnabled(true);
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 8 with UPlayer

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

the class Scoreboard method getScoreboard.

public static Sidebar getScoreboard(UPlayer player) {
    String r = ChatColor.RESET.toString();
    String redBold = RED + "" + BOLD;
    List<String> strings = new ArrayList<String>();
    strings.add(DARK_GRAY + "---------------");
    strings.add(redBold + "XP");
    strings.add(GRAY + "" + player.getXP() + " / " + CustomXP.getRequiredXP(player.getLevel() + 1));
    strings.add(r + " ");
    strings.add(redBold + "Health");
    strings.add(GRAY + "" + player.getHealth() + " / " + player.getMaxHealth());
    if (player.getFriends().size() > 1) {
        boolean displayedOnlineFriends = false;
        for (OfflinePlayer friend : player.getFriends()) {
            if (friend != null && friend.isOnline()) {
                if (!displayedOnlineFriends) {
                    strings.add(redBold + "Online Friends");
                    strings.add(r + r + r + "");
                    displayedOnlineFriends = true;
                }
                UPlayer online = new UPlayer(friend);
                strings.add(ChatColor.DARK_AQUA + friend.getName() + DARK_GRAY + ": " + ChatColor.AQUA + Math.round(online.getHealth()) + "HP");
            }
        }
    }
    strings.add(r + DARK_GRAY + "---------------");
    List<SidebarString> sidebarStrings = new ArrayList<SidebarString>();
    for (String string : strings) sidebarStrings.add(new SidebarString(string));
    String title = DARK_AQUA + "" + BOLD + "Information";
    return new Sidebar(title, Main.getInstance(), Integer.MAX_VALUE, sidebarStrings.toArray(new SidebarString[] {}));
}
Also used : SidebarString(xyz.derkades.ublisk.ext.com.coloredcarrot.api.sidebar.SidebarString) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer) SidebarString(xyz.derkades.ublisk.ext.com.coloredcarrot.api.sidebar.SidebarString) Sidebar(xyz.derkades.ublisk.ext.com.coloredcarrot.api.sidebar.Sidebar)

Example 9 with UPlayer

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

the class Chat method log.

@EventHandler(priority = EventPriority.MONITOR)
public void log(AsyncPlayerChatEvent event) {
    UPlayer player = new UPlayer(event);
    player.tracker(PlayerInfo.CHAT_MESSAGES);
    Logger.log(LogLevel.CHAT, player.getName(), event.getMessage());
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 10 with UPlayer

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

the class EntityDeath method entityDeath.

@EventHandler
public void entityDeath(EntityDeathEvent event) {
    // Never let the entity drop any XP on death
    event.setDroppedExp(0);
    LivingEntity entity = event.getEntity();
    if (entity.getType() == EntityType.PLAYER) {
        return;
    }
    if (entity.getLastDamageCause().getCause() != DamageCause.ENTITY_ATTACK) {
        return;
    }
    if (!Mobs.getEntityTypes().contains(entity.getType())) {
        return;
    }
    // Now we know that the entity has been killed by the player, so it is safe to call getKiller()
    UPlayer player = new UPlayer(entity.getKiller());
    // Track player kills for statistics
    player.tracker(PlayerInfo.MOB_KILLS);
    if (!Mobs.SPAWNED_MOBS.containsKey(entity.getUniqueId())) {
        player.sendActionBarMessage(ChatColor.RED + "Error :(", 0);
    }
    // Get mob from entity UUID
    Mob mob = Mobs.SPAWNED_MOBS.get(entity.getUniqueId());
    // Drop gold and items
    if (mob.getMobDrops().length > 0) {
        for (MobDrop drop : mob.getMobDrops()) drop.drop(entity.getLocation());
    }
    for (MobDrop drop : mob.getGoldDrop().getMobDrops()) drop.drop(entity.getLocation());
    String name = mob.getName();
    String color;
    int xp;
    if (DoubleXP.isActive()) {
        xp = mob.getXP() * 2;
        color = ChatColor.GOLD.toString();
    } else {
        xp = mob.getXP();
        color = ChatColor.GREEN.toString();
    }
    player.sendActionBarMessage(color + "+ " + xp + " XP", 15);
    player.addXP(xp);
    Logger.log(LogLevel.INFO, "XP", "Given " + player.getName() + " " + xp + " for killing a " + name);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MobDrop(xyz.derkades.ublisk.mob.MobDrop) Mob(xyz.derkades.ublisk.mob.Mob) UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

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