Search in sources :

Example 11 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project solinia3-core by mixxit.

the class CommandEffects method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        try {
            SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(player);
            if (spells == null)
                return true;
            if (args.length == 0) {
                player.sendMessage(ChatColor.GOLD + "Active Spell Effects on you:" + ChatColor.WHITE);
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                if (solplayer.getExperienceBonusExpires() != null) {
                    System.out.println("Experience Bonus was not null: " + solplayer.getExperienceBonusExpires().toString());
                    LocalDateTime datetime = LocalDateTime.now();
                    Timestamp nowtimestamp = Timestamp.valueOf(datetime);
                    Timestamp expiretimestamp = solplayer.getExperienceBonusExpires();
                    if (expiretimestamp != null) {
                        System.out.println("Experience Bonus expire timestamp " + solplayer.getExperienceBonusExpires() + " vs Now: " + nowtimestamp.toString());
                        if (!nowtimestamp.after(expiretimestamp)) {
                            System.out.println("Experience bonus was after, displaying in effects");
                            int secondsleft = (int) Math.floor(Utils.compareTwoTimeStamps(expiretimestamp, nowtimestamp));
                            TextComponent tc = new TextComponent();
                            tc.setText("- " + ChatColor.GREEN + "100% Experience Potion" + ChatColor.RESET + " " + secondsleft + " seconds");
                            sender.spigot().sendMessage(tc);
                        }
                    }
                } else {
                    System.out.println("Experience Bonus was null");
                }
                for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
                    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                    String removetext = "";
                    ChatColor spellcolor = ChatColor.GREEN;
                    if (spell.isBeneficial()) {
                        removetext = "/effects remove " + spell.getId();
                    } else {
                        removetext = "Unremovable spell";
                        spellcolor = ChatColor.RED;
                    }
                    TextComponent tc = new TextComponent();
                    tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
                    TextComponent tc2 = new TextComponent();
                    tc2.setText(removetext);
                    if (spell.isBeneficial()) {
                        tc2.setText(ChatColor.GRAY + "Click here to remove" + ChatColor.RESET);
                        tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, removetext));
                    }
                    tc.addExtra(tc2);
                    sender.spigot().sendMessage(tc);
                }
            } else {
                if (args.length < 2)
                    return true;
                int spellid = Integer.parseInt(args[1]);
                ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
                if (spell == null) {
                    player.sendMessage("That spell does not exist");
                    return true;
                }
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, player.getUniqueId(), spell.getId());
                if (!spell.isBeneficial()) {
                    player.sendMessage("Can only remove beneficial spells");
                    return true;
                }
                player.sendMessage("Spell Effect removed");
            }
        } catch (CoreStateInitException e) {
            player.sendMessage(e.getMessage());
        }
    }
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) Timestamp(java.sql.Timestamp) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 12 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project LandLord by SpatiumPrinceps.

the class AbstractManage method create.

@Override
protected void create() {
    List<String> regenerateDesc = lm.getStringList("Commands.Manage.Regenerate.description");
    List<String> greetDesc = lm.getStringList("Commands.Manage.SetGreet.description");
    List<String> farewellDesc = lm.getStringList("Commands.Manage.SetFarewell.description");
    int position = 0;
    if (regions.size() < 1)
        return;
    OwnedLand land = regions.get(0);
    for (LLFlag iFlag : land.getFlags()) {
        // For every IFlag of the land we wanna display an icon in the gui IF the flag is enabled for change
        String flagName = iFlag.getWGFlag().getName();
        String title = lm.getRawString("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".title");
        List<String> description = lm.getStringList("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".description");
        if (plugin.getConfig().getBoolean("Manage." + flagName + ".enable")) {
            int finalPosition = position;
            this.setIcon(position, new Icon(createItem(iFlag.getMaterial(), 1, title, formatList(description, iFlag.getStatus()))).addClickAction((p, icon) -> {
                for (OwnedLand region : regions) {
                    for (LLFlag llFlag : region.getFlags()) {
                        if (llFlag.getWGFlag().equals(iFlag.getWGFlag())) {
                            llFlag.toggle();
                        }
                    }
                }
                updateLore(finalPosition, formatList(description, iFlag.getStatus()));
            }));
            position++;
        }
    }
    // Reminder: Regenerate is not implemented in Manageall, cos it might cos some trouble. Calculating costs might be a bit tedious
    if (plugin.getConfig().getBoolean("Manage.regenerate.enable") && regions.size() == 1) {
        double cost = plugin.getConfig().getDouble("ResetCost");
        this.setIcon(position, new Icon(createItem(Material.BARRIER, 1, lm.getRawString("Commands.Manage.Regenerate.title"), formatList(regenerateDesc, (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")))).addClickAction((p, ic) -> {
            if (land.isOwner(player.getUniqueId())) {
                ConfirmationGUI confi = new ConfirmationGUI(p, lm.getRawString("Commands.Manage.Regenerate.confirmation").replace("%cost%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")), (p1, ic1) -> {
                    boolean flag = false;
                    if (Options.isVaultEnabled())
                        if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
                            plugin.getVaultHandler().take(player.getUniqueId(), cost);
                            flag = true;
                        } else
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)).replace("%name%", land.getName()));
                    else
                        flag = true;
                    if (flag) {
                        if (land.isOwner(player.getUniqueId())) {
                            player.getWorld().regenerateChunk(land.getChunk().getX(), land.getChunk().getZ());
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.success").replace("%land%", land.getName()));
                            display();
                        }
                    }
                }, (p2, ic2) -> {
                    player.sendMessage(lm.getString("Commands.Manage.Regenerate.abort").replace("%land%", land.getName()));
                    display();
                }, this);
                confi.setConfirm(lm.getRawString("Confirmation.accept"));
                confi.setDecline(lm.getRawString("Confirmation.decline"));
                confi.display();
            }
        }));
        position++;
    }
    // Set greet icon
    if (plugin.getConfig().getBoolean("Manage.setgreet.enable")) {
        String currentGreet = land.getWGLand().getFlag(DefaultFlag.GREET_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setgreet.item")), 1, lm.getRawString("Commands.Manage.SetGreet.title"), formatList(greetDesc, currentGreet))).addClickAction(((p, ic) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetGreet.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreetall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreet "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // TODO add functionality for manageall
    if (plugin.getConfig().getBoolean("Manage.mob-spawning.enable")) {
        String title = lm.getRawString("Commands.Manage.AllowMob-spawning.title");
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.mob-spawning.item")), 1, title, lm.getStringList("Commands.Manage.AllowMob-spawning.description"))).addClickAction((p, icon) -> {
            // Open a new gui with spawneggs where you can manage the spawns by clicking on them
            List<Icon> icons = new ArrayList<>();
            EntityType[] types = EntityType.values();
            List<String> lore = lm.getStringList("Commands.Manage.AllowMob-spawning.toggleItem.description");
            MultiPagedGUI gui = new MultiPagedGUI(p, 4, title, icons, this) {
            };
            for (EntityType t : types) {
                if (t.isAlive() && t.isSpawnable()) {
                    if (!toggleMobs.contains(t.name()))
                        continue;
                    ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
                    SpawnEggMeta meta = (SpawnEggMeta) spawnEgg.getItemMeta();
                    meta.setSpawnedType(t);
                    meta.setDisplayName(lm.getRawString("Commands.Manage.AllowMob-spawning.toggleItem.title").replace("%mob%", t.name()));
                    Set<EntityType> flag = land.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                    String state;
                    if (flag != null)
                        state = (flag.contains(t) ? "DENY" : "ALLOW");
                    else
                        state = "ALLOW";
                    List<String> formattedLore = new ArrayList<>();
                    for (String s : lore) {
                        formattedLore.add(s.replace("%mob%", t.name()).replace("%value%", state));
                    }
                    meta.setLore(formattedLore);
                    spawnEgg.setItemMeta(meta);
                    Icon ic = new Icon(spawnEgg).addClickAction((clickingPlayer, ic3) -> {
                        for (OwnedLand region : regions) {
                            Set<EntityType> localFlag = region.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                            // Toggle spawning of specific mob
                            if (localFlag != null) {
                                if (localFlag.contains(t))
                                    localFlag.remove(t);
                                else
                                    localFlag.add(t);
                            } else {
                                Set<EntityType> set = new HashSet<>();
                                set.add(t);
                                region.getWGLand().setFlag(DefaultFlag.DENY_SPAWN, set);
                            }
                        }
                        // update icon text
                        String iconState;
                        if (flag != null)
                            iconState = (flag.contains(t) ? "DENY" : "ALLOW");
                        else
                            iconState = "ALLOW";
                        List<String> newLore = new ArrayList<>();
                        for (String s : lore) {
                            newLore.add(s.replace("%mob%", t.name()).replace("%value%", iconState));
                        }
                        // System.out.println(newLore + " :" + finalIconPos);
                        ic3.setLore(newLore);
                        gui.refresh();
                    });
                    icons.add(ic);
                }
            }
            gui.display();
        }));
        position++;
    }
    // set farewell icon
    if (plugin.getConfig().getBoolean("Manage.setfarewell.enable")) {
        String currentFarewell = land.getWGLand().getFlag(DefaultFlag.FAREWELL_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setfarewell.item")), 1, lm.getRawString("Commands.Manage.SetFarewell.title"), formatList(farewellDesc, currentFarewell))).addClickAction(((p, icon) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetFarewell.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewellall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewell "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // set friends icon
    if (plugin.getConfig().getBoolean("Manage.friends.enable")) {
        ItemStack skull = createSkull(player.getName(), lm.getRawString("Commands.Manage.ManageFriends.title"), lm.getStringList("Commands.Manage.ManageFriends.description"));
        Set<UUID> friends = land.getWGLand().getMembers().getUniqueIds();
        MultiPagedGUI friendsGui = new MultiPagedGUI(player, (int) Math.ceil((double) friends.size() / 9.0), lm.getRawString("Commands.Manage.ManageFriends.title"), new ArrayList<>(), this) {
        };
        friends.forEach(id -> friendsGui.addIcon(new Icon(createSkull(Bukkit.getOfflinePlayer(id).getName(), Bukkit.getOfflinePlayer(id).getName(), formatFriendsSegment(id))).addClickAction((player, icon) -> {
            ConfirmationGUI confirmationGUI = new ConfirmationGUI(player, lm.getRawString("Commands.Manage.ManageFriends.unfriend").replace("%player%", Bukkit.getOfflinePlayer(id).getName()), (p, ic1) -> {
                friendsGui.removeIcon(friendsGui.filter(Bukkit.getOfflinePlayer(id).getName()).get(0));
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(player, "land unfriendall " + Bukkit.getOfflinePlayer(id).getName());
                else
                    Bukkit.dispatchCommand(player, "land unfriend " + Bukkit.getOfflinePlayer(id).getName());
                player.closeInventory();
                friendsGui.display();
            }, (p, ic2) -> {
                player.closeInventory();
                friendsGui.display();
            }, friendsGui);
            confirmationGUI.setConfirm(lm.getRawString("Confirmation.accept"));
            confirmationGUI.setDecline(lm.getRawString("Confirmation.decline"));
            confirmationGUI.display();
        })));
        this.setIcon(position, new Icon(skull).setName(lm.getRawString("Commands.Manage.ManageFriends.title")).addClickAction((p, ic) -> friendsGui.display()));
        position++;
    }
    if (plugin.getConfig().getBoolean("Manage.unclaim.enable")) {
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.unclaim.item")), 1, lm.getRawString("Commands.Manage.Unclaim.title"), lm.getStringList("Commands.Manage.Unclaim.description"))).addClickAction(((player1, icon) -> {
            ConfirmationGUI gui = new ConfirmationGUI(player1, lm.getRawString("Commands.Manage.Unclaim.confirmationTitle").replace("%land%", land.getName()), (p, ic2) -> {
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(p, "ll unclaimall");
                else
                    Bukkit.dispatchCommand(p, "ll unclaim " + land.getName());
                p.closeInventory();
            }, (p, ic) -> {
                p.closeInventory();
                display();
            }, this);
            gui.setConfirm(lm.getRawString("Confirmation.accept"));
            gui.setDecline(lm.getRawString("Confirmation.decline"));
            gui.display();
        })));
        position++;
    }
}
Also used : MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Landlord(biz.princeps.landlord.Landlord) OwnedLand(biz.princeps.landlord.util.OwnedLand) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Conditions(biz.princeps.lib.storage.requests.Conditions) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) LPlayer(biz.princeps.landlord.persistent.LPlayer) Options(biz.princeps.landlord.api.Options) EntityType(org.bukkit.entity.EntityType) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) ExecutionException(java.util.concurrent.ExecutionException) AbstractGUI(biz.princeps.lib.gui.simple.AbstractGUI) LangManager(biz.princeps.landlord.manager.LangManager) Icon(biz.princeps.lib.gui.simple.Icon) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) OwnedLand(biz.princeps.landlord.util.OwnedLand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) EntityType(org.bukkit.entity.EntityType) MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) Icon(biz.princeps.lib.gui.simple.Icon) ItemStack(org.bukkit.inventory.ItemStack) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 13 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project LandLord by SpatiumPrinceps.

the class Claim method onClaim.

public void onClaim(Player player) {
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
    String landname = chunk.getWorld().getName() + "_" + chunk.getX() + "_" + chunk.getZ();
    // Check if there is an overlapping wg-region
    if (!plugin.getWgHandler().canClaim(player, chunk)) {
        if (plugin.getPlayerManager().getOffer(landname) == null && !Util.isInactive(pr.getOwner())) {
            player.sendMessage(lm.getString("Commands.Claim.notAllowed"));
            return;
        }
    }
    if (pr != null) {
        if (pr.getOwner().equals(player.getUniqueId())) {
            // cannot buy own land
            player.sendMessage(lm.getString("Commands.Claim.alreadyClaimed").replace("%owner%", pr.printOwners()));
            return;
        }
        Offers offer = plugin.getPlayerManager().getOffer(pr.getName());
        if (!Util.isInactive(pr.getOwner()) && offer == null) {
            player.sendMessage(lm.getString("Commands.Claim.notYetInactive").replace("%owner%", pr.printOwners()).replace("%days%", "" + Util.getInactiveRemainingDays(pr.getOwner())));
            return;
        }
    }
    int regionCount = plugin.getWgHandler().getWG().getRegionManager(player.getWorld()).getRegionCountOfPlayer(plugin.getWgHandler().getWG().wrapPlayer(player));
    List<Integer> limitlist = plugin.getConfig().getIntegerList("limits");
    if (!player.hasPermission("landlord.limit.override")) {
        int highestAllowedLandCount = -1;
        for (Integer integer : limitlist) {
            if (regionCount <= integer)
                if (player.hasPermission("landlord.limit." + integer)) {
                    highestAllowedLandCount = integer;
                }
        }
        if (regionCount >= highestAllowedLandCount) {
            player.sendMessage(lm.getString("Commands.Claim.hardcap").replace("%regions%", highestAllowedLandCount + ""));
            return;
        }
    }
    if (plugin.getConfig().getBoolean("Shop.enable") && Options.isVaultEnabled()) {
        int claims = plugin.getPlayerManager().get(player.getUniqueId()).getClaims();
        if (regionCount >= claims) {
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Claim.limit").replace("%regions%", regionCount + "").replace("%claims%", claims + "")).color(ChatColor.YELLOW).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ll shop"));
            player.spigot().sendMessage(builder.create());
            return;
        }
    }
    LandPreClaimEvent event = new LandPreClaimEvent(player, chunk);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        if (plugin.getConfig().getBoolean("CommandSettings.Claim.claimOnlyAdjacent")) {
            // Only allow claiming of adjacent chunks
            int amountOfOwnedLands = plugin.getWgHandler().getRegionCountOfPlayer(player.getUniqueId());
            if (amountOfOwnedLands > 0) {
                // Get adjacent lands of the land, which a player wants to claim.
                // Only when one of the 4 adjacent is already owned, allow to claim
                World world = player.getWorld();
                OwnedLand[] adjLands = new OwnedLand[4];
                adjLands[0] = plugin.getLand(world.getChunkAt(chunk.getX() + 1, chunk.getZ()));
                adjLands[1] = plugin.getLand(world.getChunkAt(chunk.getX() - 1, chunk.getZ()));
                adjLands[2] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() + 1));
                adjLands[3] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() - 1));
                boolean hasNearbyLand = false;
                for (OwnedLand adjLand : adjLands) {
                    if (adjLand != null) {
                        if (adjLand.isOwner(player.getUniqueId())) {
                            hasNearbyLand = true;
                            break;
                        }
                    }
                }
                if (!hasNearbyLand) {
                    // no nearby land is already claimed => Display error msg
                    player.sendMessage(lm.getString("Commands.Claim.onlyClaimAdjacentChunks").replace("%land%", OwnedLand.getName(chunk)));
                    return;
                }
            }
        }
        if (plugin.getConfig().getBoolean("CommandSettings.Claim.needsGapBetweenOwners")) {
            // Get adjacent lands of the land, which a player wants to claim.
            // Only when all of the 4 adj lands are either owned by the player or are free => allow the claim
            World world = player.getWorld();
            OwnedLand[] adjLands = new OwnedLand[4];
            adjLands[0] = plugin.getLand(world.getChunkAt(chunk.getX() + 1, chunk.getZ()));
            adjLands[1] = plugin.getLand(world.getChunkAt(chunk.getX() - 1, chunk.getZ()));
            adjLands[2] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() + 1));
            adjLands[3] = plugin.getLand(world.getChunkAt(chunk.getX(), chunk.getZ() - 1));
            boolean differentOwner = false;
            for (OwnedLand adjLand : adjLands) {
                if (adjLand != null) {
                    if (!adjLand.isOwner(player.getUniqueId())) {
                        differentOwner = true;
                        break;
                    }
                }
            }
            if (differentOwner) {
                // one of the nearby lands is not owned by the player nor its free
                player.sendMessage(lm.getString("Commands.Claim.needsGap").replace("%land%", OwnedLand.getName(chunk)));
                return;
            }
        }
        boolean moneyFlag = false;
        // Money stuff
        if (Options.isVaultEnabled()) {
            if (pr != null && Util.isInactive(pr.getOwner())) {
                // Inactive sale
                double costForBuyer = plugin.getCostManager().calculateCost(player.getUniqueId());
                double payBackForInactive = plugin.getCostManager().calculateCost(pr.getOwner());
                String originalOwner = Bukkit.getOfflinePlayer(pr.getOwner()).getName();
                if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), costForBuyer)) {
                    plugin.getVaultHandler().take(player.getUniqueId(), costForBuyer);
                    plugin.getVaultHandler().give(pr.getOwner(), payBackForInactive);
                    pr.getWGLand().getOwners().clear();
                    pr.getWGLand().getOwners().addPlayer(player.getUniqueId());
                    player.sendMessage(lm.getString("Commands.Claim.boughtUp").replace("%player%", originalOwner).replace("%price%", Util.formatCash(costForBuyer)).replace("%chunk%", pr.getName()));
                    OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
                    plugin.getMapManager().updateAll();
                    return;
                } else {
                    // Not enough money
                    player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", Util.formatCash(costForBuyer)).replace("%chunk%", OwnedLand.getName(chunk)));
                    return;
                }
            }
            Offers offer = plugin.getPlayerManager().getOffer(landname);
            if (offer != null && pr != null) {
                // Player 2 player sale
                if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), offer.getPrice())) {
                    String sellDesc = pr.getName() + " | " + plugin.getVaultHandler().format(offer.getPrice());
                    ConfirmationGUI confirm = new ConfirmationGUI(player, sellDesc, (player1, icon) -> {
                        plugin.getVaultHandler().take(player.getUniqueId(), offer.getPrice());
                        plugin.getVaultHandler().give(offer.getSeller(), offer.getPrice());
                        plugin.getPlayerManager().removeOffer(offer.getLandname());
                        pr.getWGLand().getOwners().clear();
                        pr.getWGLand().getOwners().addPlayer(player.getUniqueId());
                        player.sendMessage(lm.getString("Commands.Claim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()));
                        if (Bukkit.getPlayer(offer.getSeller()).isOnline()) {
                            Bukkit.getPlayer(offer.getSeller()).sendMessage(lm.getString("Commands.Claim.p2pSuccess").replace("%player%", player1.getName()).replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()).replace("%price%", plugin.getVaultHandler().format(offer.getPrice())));
                        }
                        OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
                        plugin.getMapManager().updateAll();
                        player.closeInventory();
                    }, (player12, ic2) -> {
                        player.sendMessage(lm.getString("Commands.Claim.aborted"));
                        player.closeInventory();
                    }, null);
                    confirm.display();
                } else {
                    // Not enough money
                    player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", plugin.getVaultHandler().format(offer.getPrice())).replace("%chunk%", OwnedLand.getName(chunk)));
                    return;
                }
            } else {
                // Normal sale
                moneyFlag = true;
                double calculatedCost = plugin.getCostManager().calculateCost(player.getUniqueId());
                if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), calculatedCost)) {
                    plugin.getVaultHandler().take(player.getUniqueId(), calculatedCost);
                    if (calculatedCost > 0)
                        player.sendMessage(lm.getString("Commands.Claim.moneyTook").replace("%money%", plugin.getVaultHandler().format(calculatedCost)).replace("%chunk%", OwnedLand.getName(chunk)));
                } else {
                    // NOT ENOUGH MONEY
                    player.sendMessage(lm.getString("Commands.Claim.notEnoughMoney").replace("%money%", plugin.getVaultHandler().format(calculatedCost)).replace("%chunk%", OwnedLand.getName(chunk)));
                    return;
                }
            }
        } else {
            // flag is always true, if eco is disabled
            moneyFlag = true;
        }
        if (moneyFlag) {
            plugin.getWgHandler().claim(chunk, player.getUniqueId());
            player.sendMessage(lm.getString("Commands.Claim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()));
            OwnedLand.highlightLand(player, CParticle.VILLAGERHAPPY);
            if (plugin.getConfig().getBoolean("Homes.enable")) {
                if (plugin.getPlayerManager().get(player.getUniqueId()).getHome() == null)
                    Bukkit.dispatchCommand(player, "ll sethome");
            }
            if (plugin.getConfig().getBoolean("CommandSettings.Claim.enableDelimit")) {
                delimit(chunk);
            }
            plugin.getMapManager().updateAll();
            LandPostClaimEvent postEvent = new LandPostClaimEvent(player, plugin.getLand(chunk));
            Bukkit.getPluginManager().callEvent(postEvent);
        }
    }
}
Also used : OwnedLand(biz.princeps.landlord.util.OwnedLand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Offers(biz.princeps.landlord.persistent.Offers) Chunk(org.bukkit.Chunk) World(org.bukkit.World) LandPreClaimEvent(biz.princeps.landlord.api.events.LandPreClaimEvent) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) LandPostClaimEvent(biz.princeps.landlord.api.events.LandPostClaimEvent)

Example 14 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project LandLord by SpatiumPrinceps.

the class Home method teleport.

private void teleport(Location toGo, Player player, String playerHome) {
    double cost = plugin.getConfig().getDouble("Homes.teleportCost");
    if (Options.isVaultEnabled()) {
        if (!plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
            player.sendMessage(lm.getString("Commands.Home.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)));
            return;
        }
    }
    if (toGo == null) {
        ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Home.noHome"));
        builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ll sethome"));
        player.spigot().sendMessage(builder.create());
        return;
    }
    if (cost > 0 && Options.isVaultEnabled()) {
        plugin.getVaultHandler().take(player.getUniqueId(), cost);
        player.sendMessage(lm.getString("Commands.Home.costing").replace("%cost%", plugin.getVaultHandler().format(cost)));
    }
    player.teleport(toGo);
    player.sendMessage(lm.getString("Commands.Home.welcomeHome").replace("%player%", playerHome));
}
Also used : ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 15 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project LandLord by SpatiumPrinceps.

the class Borders method onToggleBorder.

public void onToggleBorder(Player p) {
    if (!Options.enabled_borders()) {
        return;
    }
    if (tasks.get(p) == null) {
        ComponentBuilder cp = new ComponentBuilder(lm.getString("Commands.Borders.activated")).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ll borders"));
        p.spigot().sendMessage(cp.create());
        this.tasks.put(p, new BukkitRunnable() {

            int counter = 0;

            @Override
            public void run() {
                if (counter <= 360 / plugin.getConfig().getInt("Borders.refreshRate"))
                    OwnedLand.highlightLand(p, CParticle.DRIPLAVA);
                else
                    cancel();
                counter++;
            }
        }.runTaskTimer(plugin, 0, plugin.getConfig().getInt("Borders.refreshRate") * 20));
    } else {
        p.sendMessage(lm.getString("Commands.Borders.deactivated"));
        tasks.get(p).cancel();
        tasks.remove(p);
    }
}
Also used : ClickEvent(net.md_5.bungee.api.chat.ClickEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

ClickEvent (net.md_5.bungee.api.chat.ClickEvent)30 TextComponent (net.md_5.bungee.api.chat.TextComponent)21 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)15 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)10 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)7 Player (org.bukkit.entity.Player)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 UPlayer (xyz.derkades.ublisk.utils.UPlayer)3 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)2 ArrayList (java.util.ArrayList)2 ChatColor (net.md_5.bungee.api.ChatColor)2 Material (org.bukkit.Material)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 World (org.bukkit.World)2 Landlord (biz.princeps.landlord.Landlord)1 Options (biz.princeps.landlord.api.Options)1 LandPostClaimEvent (biz.princeps.landlord.api.events.LandPostClaimEvent)1