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);
}
}
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);
}
}
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[] {}));
}
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());
}
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);
}
Aggregations