Search in sources :

Example 1 with EasterlynCore

use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.

the class EffectTunnelBore method applyEffect.

@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
    if (!(event instanceof BlockBreakEvent) || event instanceof IndirectBreakEvent) {
        return;
    }
    BlockBreakEvent breakEvent = (BlockBreakEvent) event;
    Player player = breakEvent.getPlayer();
    if (player.isSneaking()) {
        // Sneak to mine single blocks
        return;
    }
    Block block = breakEvent.getBlock();
    if (!BlockUtil.isCorrectTool(player.getInventory().getItemInMainHand(), breakEvent.getBlock().getType())) {
        // Require correct tool used
        return;
    }
    RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (registration == null) {
        return;
    }
    BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
    /*
     * Forgiveness of .25 hardness allows indirect breaking of most common related materials
     * while not excessively increasing risk of accidents inside builds. Allows for mining gravel
     * via sand and dirt, etc.
     */
    float hardness = block.getType().getHardness() + 0.25F;
    for (BlockFace yLevel : levels) {
        if (block.getY() == 0 && yLevel == BlockFace.DOWN) {
            continue;
        }
        Block relativeCenter = block.getRelative(yLevel);
        if (yLevel != BlockFace.SELF) {
            if (handleBlock(hardness, relativeCenter, player, budManager)) {
                return;
            }
        }
        for (BlockFace face : faces) {
            if (handleBlock(hardness, relativeCenter.getRelative(face), player, budManager)) {
                return;
            }
        }
    }
    player.updateInventory();
}
Also used : Player(org.bukkit.entity.Player) EasterlynCore(com.easterlyn.EasterlynCore) IndirectBreakEvent(com.easterlyn.effect.event.IndirectBreakEvent) BlockFace(org.bukkit.block.BlockFace) BlockUpdateManager(com.easterlyn.util.BlockUpdateManager) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block)

Example 2 with EasterlynCore

use of com.easterlyn.EasterlynCore 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 EasterlynCore

use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.

the class PVPKeepInventory method onPlayerDeath.

@EventHandler(ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(event.getEntity().getUniqueId());
    Object object = user.getTemporaryStorage().get(key);
    if (!(object instanceof Long)) {
        return;
    }
    long timestamp = (long) object;
    if (timestamp < System.currentTimeMillis() - 6000L) {
        return;
    }
    event.setDroppedExp(ExperienceUtil.getExp(event.getEntity()));
    int dropped = ExperienceUtil.getExp(event.getEntity()) / 10;
    if (dropped > 30) {
        dropped = 30;
    }
    event.setDroppedExp(dropped);
    ExperienceUtil.changeExp(event.getEntity(), -dropped);
    event.setKeepLevel(true);
    event.setKeepInventory(true);
    event.getDrops().clear();
}
Also used : User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) EventHandler(org.bukkit.event.EventHandler)

Example 4 with EasterlynCore

use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.

the class BottleExperience method onPlayerItemConsume.

@EventHandler(ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
    user.getTemporaryStorage().put(keyBottleCreate, System.currentTimeMillis() + 2000);
}
Also used : User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) EventHandler(org.bukkit.event.EventHandler)

Example 5 with EasterlynCore

use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.

the class MinecraftBridge method setup.

public void setup() {
    client.getEventDispatcher().on(MessageCreateEvent.class).flatMap(event -> Mono.fromRunnable(() -> {
        if (event.getMessage().getAuthor().isEmpty() || event.getMessage().getAuthor().get().isBot()) {
            return;
        }
        User author = event.getMessage().getAuthor().get();
        String msg = event.getMessage().getContent();
        MessageChannel channel = event.getMessage().getChannel().block();
        String command = null;
        String commandData = null;
        if (msg.startsWith(plugin.getCommandPrefix())) {
            int prefixLength = plugin.getCommandPrefix().length();
            int space = msg.indexOf(' ');
            if (space < prefixLength) {
                space = msg.length();
            }
            command = msg.substring(prefixLength, space).toLowerCase();
            commandData = msg.substring(space < msg.length() ? space + 1 : space);
        }
        if (command != null && command.equals("link")) {
            UUID pendingLink = plugin.getPendingLink(commandData);
            if (pendingLink == null) {
                channel.createMessage("Invalid link code! If your code expired, rerun `/link` in" + " Minecraft.\n" + "If you're having trouble, try clicking the message to" + " copy the code!");
            } else {
                plugin.addLink(pendingLink, author.getId());
            }
        }
        boolean main = channel instanceof GuildMessageChannel && plugin.isChannelType(channel.getId(), ChannelType.MAIN);
        if (!main && command == null) {
            return;
        }
        DiscordUser sender = plugin.getUser(author.getId());
        if (sender == null) {
            Snowflake id = author.getId();
            if (warnings.getIfPresent(id) != null) {
                return;
            }
            warnings.put(id, true);
            channel.createMessage(author.getMention() + ", you must run `/link` in Minecraft to use this" + " feature!").subscribe();
            return;
        }
        if (command != null) {
            handleCommand(sender, channel, command, commandData);
            return;
        }
        handleDiscordChat(sender, event.getMessage());
    }).onErrorResume(error -> {
        System.out.println("Caught exception handling Discord event:");
        error.printStackTrace();
        return Mono.empty();
    }).thenReturn(event)).subscribe();
    Event.register(UserChatEvent.class, event -> {
        // TODO may want to try to softdepend on chat instead of hard
        if (event.isAsynchronous()) {
            handleMinecraftChat(event);
        } else {
            // Ensure handling is done asynchronously even if chat is somehow sent on main thread
            plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> handleMinecraftChat(event));
        }
    }, plugin);
    Event.register(PlayerCommandPreprocessEvent.class, event -> {
        if (event.getPlayer().hasPermission("easterlyn.discord.exempt.commandlog")) {
            return;
        }
        RegisteredServiceProvider<EasterlynCore> registration = plugin.getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return;
        }
        int space = event.getMessage().indexOf(' ');
        String commandName = event.getMessage().substring(1, space > 0 ? space : event.getMessage().length()).toLowerCase();
        SimpleCommandMap commandMap = registration.getProvider().getSimpleCommandMap();
        if (commandMap == null) {
            return;
        }
        Command command = commandMap.getCommand(commandName);
        if (command != null && !plugin.getConfig().getStringList("command-log-blacklist").contains(command.getName())) {
            plugin.postMessage(ChannelType.LOG, event.getPlayer().getName() + " issued command: " + event.getMessage());
        }
    }, plugin, EventPriority.MONITOR);
    Event.register(PlayerJoinEvent.class, event -> plugin.postMessage(ChannelType.MAIN, ChatColor.stripColor(event.getPlayer().getDisplayName()) + " logs in."), plugin, EventPriority.MONITOR);
    Event.register(PlayerQuitEvent.class, event -> plugin.postMessage(ChannelType.MAIN, ChatColor.stripColor(event.getPlayer().getDisplayName()) + " logs out."), plugin);
}
Also used : MessageChannel(discord4j.core.object.entity.channel.MessageChannel) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) Snowflake(discord4j.common.util.Snowflake) Attachment(discord4j.core.object.entity.Attachment) GuildChannel(discord4j.core.object.entity.channel.GuildChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Matcher(java.util.regex.Matcher) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) EasterlynDiscord(com.easterlyn.EasterlynDiscord) ChatColor(net.md_5.bungee.api.ChatColor) User(discord4j.core.object.entity.User) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) EasterlynCore(com.easterlyn.EasterlynCore) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) ReactionEmoji(discord4j.core.object.reaction.ReactionEmoji) TimeUnit(java.util.concurrent.TimeUnit) Event(com.github.jikoo.planarwrappers.event.Event) Message(discord4j.core.object.entity.Message) EventPriority(org.bukkit.event.EventPriority) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Channel(discord4j.core.object.entity.channel.Channel) Command(org.bukkit.command.Command) CacheBuilder(com.google.common.cache.CacheBuilder) GatewayDiscordClient(discord4j.core.GatewayDiscordClient) Pattern(java.util.regex.Pattern) Cache(com.google.common.cache.Cache) NotNull(org.jetbrains.annotations.NotNull) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) EasterlynChat(com.easterlyn.EasterlynChat) User(discord4j.core.object.entity.User) EasterlynCore(com.easterlyn.EasterlynCore) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Command(org.bukkit.command.Command) Snowflake(discord4j.common.util.Snowflake) UUID(java.util.UUID)

Aggregations

EasterlynCore (com.easterlyn.EasterlynCore)17 User (com.easterlyn.user.User)11 Player (org.bukkit.entity.Player)11 EventHandler (org.bukkit.event.EventHandler)9 UserChatEvent (com.easterlyn.chat.event.UserChatEvent)5 AutoUser (com.easterlyn.user.AutoUser)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 EasterlynChat (com.easterlyn.EasterlynChat)3 Channel (com.easterlyn.chat.channel.Channel)3 StringUtil (com.easterlyn.util.StringUtil)3 Collections (java.util.Collections)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 UserCreationEvent (com.easterlyn.event.UserCreationEvent)2 BlockUpdateManager (com.easterlyn.util.BlockUpdateManager)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2