Search in sources :

Example 1 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class BackCommand method onPlayerTeleport.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    switch(event.getCause()) {
        case COMMAND:
        case END_GATEWAY:
        case PLUGIN:
            break;
        case CHORUS_FRUIT:
        case END_PORTAL:
        case ENDER_PEARL:
        case NETHER_PORTAL:
        case SPECTATE:
        case UNKNOWN:
        default:
            return;
    }
    User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
    user.getStorage().set(BACK_LOCATION, event.getFrom());
}
Also used : User(com.easterlyn.user.User) EventHandler(org.bukkit.event.EventHandler)

Example 2 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class Transportalizer method getFailureMessage.

@Nullable
private String getFailureMessage(Player player, Entity entity, boolean push, Location from, Location to, ConfigurationSection storage, int cost) {
    if (push && entity instanceof Player) {
        // Sender must have button access to send players
        if (!ProtectionUtil.canUseButtonsAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    if (!push && entity instanceof Player) {
        RegisteredServiceProvider<EasterlynCore> registration = getMachines().getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return "Easterlyn core plugin not loaded! Cannot pull players.";
        }
        if (player.getUniqueId().equals(entity.getUniqueId())) {
            return null;
        }
        User target = registration.getProvider().getUserManager().getUser(entity.getUniqueId());
        User issuer = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        if (target.setPendingRequest(new Request() {

            @Override
            public void accept() {
                if (getFuel(storage) < cost) {
                    target.sendMessage("Transportalizer is too low on fuel! Ask " + issuer.getDisplayName() + " to add more!");
                }
                Player localTarget = target.getPlayer();
                if (localTarget == null) {
                    return;
                }
                teleport(entity, from, to);
                setFuel(storage, getFuel(storage) - cost);
            }

            @Override
            public void decline() {
                target.sendMessage("Request declined!");
            }
        })) {
            target.sendMessage(issuer.getUniqueId(), issuer.getDisplayName() + " is requesting to transportalize you!\n" + "Use /accept or /decline to manage the request.");
            // Blank message won't actually send, but will preclude immediate transportalization.
            return "";
        }
        return null;
    }
    // Ender dragon or ender dragon parts
    if (entity instanceof ComplexLivingEntity || entity instanceof ComplexEntityPart) {
        return ChatColor.RED + "Great effort, but you can't transportalize a dragon.";
    }
    if (entity instanceof ArmorStand) {
        // Armor stand manipulation requires the ability to build
        if (!ProtectionUtil.canBuildAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    if (entity instanceof Monster || entity instanceof Explosive || entity instanceof ExplosiveMinecart) {
        // Hostiles, TNT, wither projectiles, fireballs, etc. require build permissions
        if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    // Generic push/pull requires chest access in send location and full access in arrival location
    if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canMobsSpawn(to) && !ProtectionUtil.canBuildAt(player, to)) {
        return ChatColor.RED + "You do not have access to the location specified!";
    }
    return null;
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Player(org.bukkit.entity.Player) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) User(com.easterlyn.user.User) Explosive(org.bukkit.entity.Explosive) ArmorStand(org.bukkit.entity.ArmorStand) EasterlynCore(com.easterlyn.EasterlynCore) Monster(org.bukkit.entity.Monster) Request(com.easterlyn.util.Request) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class EasterlynSpectators method onEnable.

@Override
public void onEnable() {
    PermissionUtil.addParent("easterlyn.spectators.unrestricted", UserRank.STAFF.getPermission());
    PermissionUtil.addParent("easterlyn.spectators.nightvision", UserRank.MODERATOR.getPermission());
    Event.register(BlockBreakEvent.class, event -> {
        if (event.getPlayer().hasPermission("easterlyn.spectators.unrestricted")) {
            return;
        }
        RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        User user = registration.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
        long spectatore = user.getStorage().getLong(USER_SPECTATE_COOLDOWN, 0);
        if (spectatore < System.currentTimeMillis()) {
            return;
        }
        for (BlockFace face : new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.SELF, BlockFace.DOWN }) {
            Block block = event.getBlock().getRelative(face);
            if (block.getType() == Material.NETHER_QUARTZ_ORE) {
                block.setType(Material.NETHERRACK);
            }
            if (block.getType().name().endsWith("_ORE")) {
                block.setType(Material.STONE);
            }
        }
    }, this, EventPriority.LOW);
    Event.register(PlayerQuitEvent.class, event -> {
        RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        Player player = event.getPlayer();
        if (player.getGameMode() != GameMode.SPECTATOR) {
            return;
        }
        User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
        if (spectateReturn == null) {
            return;
        }
        player.teleport(spectateReturn);
    }, this);
    Event.register(PlayerJoinEvent.class, event -> {
        RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        Player player = event.getPlayer();
        User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
        if (spectateReturn == null) {
            return;
        }
        user.getStorage().set(USER_SPECTATE_RETURN, null);
        user.getStorage().set(USER_SPECTATE_COOLDOWN, System.currentTimeMillis() + 480000L);
        player.teleport(spectateReturn);
        if (player.getGameMode() == GameMode.SPECTATOR) {
            player.setGameMode(GameMode.SURVIVAL);
        }
    }, this);
    Event.register(PlayerTeleportEvent.class, event -> {
        if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
            return;
        }
        RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        Player player = event.getPlayer();
        User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        // Don't block request-based teleportation
        if (user.getStorage().getBoolean(USER_SPECTPA)) {
            return;
        }
        Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
        if (spectateReturn != null) {
            event.setCancelled(true);
            player.sendMessage("Spectating via hotbar is currently disabled. Please use `/spectpa`!");
        }
    }, this);
    Event.register(PlayerGameModeChangeEvent.class, event -> {
        RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        Player player = event.getPlayer();
        if (player.getGameMode() != GameMode.SPECTATOR) {
            return;
        }
        User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
        if (spectateReturn != null) {
            event.setCancelled(true);
        }
    }, this);
    RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (registration != null) {
        register(registration.getProvider());
    }
    Event.register(PluginEnableEvent.class, pluginEnableEvent -> {
        if (pluginEnableEvent.getPlugin() instanceof EasterlynCore) {
            register((EasterlynCore) pluginEnableEvent.getPlugin());
        }
    }, this);
}
Also used : Player(org.bukkit.entity.Player) User(com.easterlyn.user.User) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Example 4 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class DeathPointCommand method onPlayerTeleport.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerDeathEvent event) {
    User user = core.getUserManager().getUser(event.getEntity().getUniqueId());
    user.getStorage().set(DEATH_LOCATION, event.getEntity().getLocation());
}
Also used : User(com.easterlyn.user.User) EventHandler(org.bukkit.event.EventHandler)

Example 5 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class LoginCommands method onPlayerJoin.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
    user.getStorage().getStringList(ONLOGIN).forEach(string -> event.getPlayer().chat(string));
}
Also used : User(com.easterlyn.user.User) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (com.easterlyn.user.User)22 EasterlynCore (com.easterlyn.EasterlynCore)12 Player (org.bukkit.entity.Player)12 EventHandler (org.bukkit.event.EventHandler)11 Channel (com.easterlyn.chat.channel.Channel)7 AutoUser (com.easterlyn.user.AutoUser)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)6 StringUtil (com.easterlyn.util.StringUtil)5 List (java.util.List)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)5 Nullable (org.jetbrains.annotations.Nullable)5 EasterlynChat (com.easterlyn.EasterlynChat)4 UserChatEvent (com.easterlyn.chat.event.UserChatEvent)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 NotNull (org.jetbrains.annotations.NotNull)4 CommandAlias (co.aikar.commands.annotation.CommandAlias)3