Search in sources :

Example 16 with OwnedLand

use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.

the class LandMap method buildMap.

private String[] buildMap(Player p) {
    final int radius = 3;
    String[][] mapBoard = getMapDir(getPlayerDirection(p));
    String[] mapRows = new String[mapBoard.length + 3];
    if (!currChunk.equals(mapViewer.getLocation().getChunk())) {
        updateMap();
    }
    Map<Chunk, OwnedLand> nearby = plugin.getWgHandler().getNearbyLands(p.getLocation(), radius, radius);
    for (int z = 0; z < mapBoard.length; z++) {
        StringBuilder row = new StringBuilder();
        for (int x = 0; x < mapBoard[z].length; x++) {
            int xx = x - radius;
            int zz = z - radius;
            OwnedLand land = nearby.get(p.getWorld().getChunkAt(xx + p.getLocation().getChunk().getX(), zz + p.getLocation().getChunk().getZ()));
            String currSpot = mapBoard[z][x];
            if (land != null) {
                if (land.getWGLand().getOwners().getUniqueIds().contains(p.getUniqueId())) {
                    currSpot = ChatColor.GREEN + currSpot;
                } else if (land.getWGLand().getMembers().getUniqueIds().contains(p.getUniqueId())) {
                    currSpot = ChatColor.YELLOW + currSpot;
                } else {
                    currSpot = ChatColor.RED + currSpot;
                }
            } else {
                if (currSpot.equals("∞") || currSpot.equals("\u2062")) {
                    currSpot = ChatColor.RESET + currSpot;
                } else {
                    currSpot = ChatColor.GRAY + currSpot;
                }
            }
            row.append(currSpot);
        }
        mapRows[z] = row.toString();
    }
    LangManager messages = plugin.getLangManager();
    final String yours = messages.getRawString("Commands.LandMap.yours");
    final String friends = messages.getRawString("Commands.LandMap.friends");
    final String others = messages.getRawString("Commands.LandMap.others");
    if (yours.length() <= 25) {
        mapRows[mapRows.length - 3] = ChatColor.GREEN + "█- " + yours;
    } else {
        mapRows[mapRows.length - 3] = ChatColor.GREEN + "█- " + yours.substring(0, 25);
    }
    if (friends.length() <= 25) {
        mapRows[mapRows.length - 2] = ChatColor.YELLOW + "█- " + friends;
    } else {
        mapRows[mapRows.length - 2] = ChatColor.YELLOW + "█- " + friends.substring(0, 25);
    }
    if (others.length() <= 25) {
        mapRows[mapRows.length - 1] = ChatColor.RED + "█- " + others;
    } else {
        mapRows[mapRows.length - 1] = ChatColor.RED + "█- " + others.substring(0, 25);
    }
    return mapRows;
}
Also used : LangManager(biz.princeps.landlord.manager.LangManager) OwnedLand(biz.princeps.landlord.util.OwnedLand) Chunk(org.bukkit.Chunk)

Example 17 with OwnedLand

use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.

the class RemoveAdvertise method onAdvertise.

public void onAdvertise(Player player, String landname) {
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = null;
    if (landname.equals("this")) {
        chunk = player.getWorld().getChunkAt(player.getLocation());
    } else {
        String[] split = landname.split("_");
        try {
            int x = Integer.valueOf(split[1]);
            int z = Integer.valueOf(split[2]);
            chunk = Bukkit.getWorld(split[0]).getChunkAt(x, z);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
    OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
    if (pr == null) {
        player.sendMessage(lm.getString("Commands.Advertise.notOwnFreeLand"));
        return;
    }
    if (!pr.isOwner(player.getUniqueId())) {
        player.sendMessage(lm.getString("Commands.Advertise.notOwn").replace("%owner%", pr.printOwners()));
        return;
    }
    Offers offer = plugin.getPlayerManager().getOffer(pr.getName());
    if (offer == null) {
        player.sendMessage(lm.getString("Commands.RemoveAdvertise.noAdvertise").replace("%landname%", pr.getName()));
    } else {
        plugin.getPlayerManager().removeOffer(offer.getLandname());
        player.sendMessage(lm.getString("Commands.RemoveAdvertise.success").replace("%landname%", landname));
    }
}
Also used : OwnedLand(biz.princeps.landlord.util.OwnedLand) Offers(biz.princeps.landlord.persistent.Offers) Chunk(org.bukkit.Chunk)

Example 18 with OwnedLand

use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.

the class Unfriend method onUnfriend.

public void onUnfriend(Player player, String[] names) {
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    OwnedLand land = plugin.getWgHandler().getRegion(chunk);
    if (land != null) {
        if (!land.isOwner(player.getUniqueId()) && !player.hasPermission("landlord.admin.modifyfriends")) {
            player.sendMessage(lm.getString("Commands.Unfriend.notOwn").replace("%owner%", land.printOwners()));
            return;
        }
        for (String target : names) {
            plugin.getPlayerManager().getOfflinePlayer(target, lPlayer -> {
                if (lPlayer == null) {
                    // Failure
                    player.sendMessage(lm.getString("Commands.Unfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
                } else {
                    // Success
                    land.removeFriend(lPlayer.getUuid());
                    player.sendMessage(lm.getString("Commands.Unfriend.success").replace("%players%", Arrays.asList(names).toString()));
                }
            });
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                plugin.getMapManager().updateAll();
            }
        }.runTaskLater(plugin, 60L);
    }
}
Also used : OwnedLand(biz.princeps.landlord.util.OwnedLand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Chunk(org.bukkit.Chunk)

Example 19 with OwnedLand

use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.

the class SetHome method onSetHome.

// requires permission landlord.player.home
public void onSetHome(Player player) {
    if (!Options.enabled_homes()) {
        player.sendMessage(lm.getString("Commands.SetHome.disabled"));
        return;
    }
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    OwnedLand land = plugin.getWgHandler().getRegion(chunk);
    if (land == null) {
        player.sendMessage(lm.getString("Commands.SetHome.nullLand"));
        return;
    }
    if (!land.isOwner(player.getUniqueId())) {
        player.sendMessage(lm.getString("Commands.SetHome.notOwn").replace("%owner%", land.printOwners()));
        return;
    }
    plugin.getPlayerManager().get(player.getUniqueId()).setHome(player.getLocation());
    player.sendMessage(lm.getString("Commands.SetHome.success"));
}
Also used : OwnedLand(biz.princeps.landlord.util.OwnedLand) Chunk(org.bukkit.Chunk)

Example 20 with OwnedLand

use of biz.princeps.landlord.util.OwnedLand in project LandLord by SpatiumPrinceps.

the class Info method onInfo.

public void onInfo(Player player) {
    if (plugin.getConfig().getStringList("disabled-worlds").contains(player.getWorld().getName())) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = player.getLocation().getChunk();
    OwnedLand land = plugin.getWgHandler().getRegion(chunk);
    new BukkitRunnable() {

        @Override
        public void run() {
            // claimed
            if (land != null) {
                String lastseen;
                LocalDateTime lastSeenDate = null;
                OfflinePlayer op = Bukkit.getOfflinePlayer(land.getOwner());
                if (op.isOnline()) {
                    lastseen = lm.getRawString("Commands.Info.online");
                } else {
                    List<Object> list = plugin.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", op.getUniqueId().toString()).create());
                    if (list.size() > 0) {
                        lastseen = ((LPlayer) list.get(0)).getLastSeenAsString();
                        lastSeenDate = ((LPlayer) list.get(0)).getLastSeen();
                    } else {
                        lastseen = lm.getRawString("Commands.Info.noLastSeen");
                    }
                }
                if (Util.isInactive(lastSeenDate)) {
                    player.sendMessage(replaceInMessage(inactive, land.getName(), land.printOwners(), land.printMembers(), lastseen, Util.formatCash(plugin.getCostManager().calculateCost(player.getUniqueId()))));
                    OwnedLand.highlightLand(player, CParticle.DRIPLAVA);
                    return;
                }
                Offers offer = plugin.getPlayerManager().getOffer(land.getName());
                if (offer != null) {
                    // advertised land
                    player.sendMessage(replaceInMessage(advertised, land.getName(), land.printOwners(), land.printMembers(), lastseen, Util.formatCash(offer.getPrice())));
                } else {
                    // normal owned land
                    player.sendMessage(replaceInMessage(owned, land.getName(), land.printOwners(), land.printMembers(), lastseen, ""));
                }
                OwnedLand.highlightLand(player, CParticle.DRIPWATER);
            } else {
                // unclaimed
                player.sendMessage(replaceInMessage(free, OwnedLand.getName(chunk), "", "", "", Util.formatCash(plugin.getCostManager().calculateCost(player.getUniqueId()))));
                OwnedLand.highlightLand(player, CParticle.DRIPLAVA);
            }
        }
    }.runTaskAsynchronously(plugin);
}
Also used : LocalDateTime(java.time.LocalDateTime) LPlayer(biz.princeps.landlord.persistent.LPlayer) OwnedLand(biz.princeps.landlord.util.OwnedLand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) Offers(biz.princeps.landlord.persistent.Offers) Chunk(org.bukkit.Chunk)

Aggregations

OwnedLand (biz.princeps.landlord.util.OwnedLand)20 Chunk (org.bukkit.Chunk)9 Player (org.bukkit.entity.Player)7 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)6 LPlayer (biz.princeps.landlord.persistent.LPlayer)4 Offers (biz.princeps.landlord.persistent.Offers)4 EventHandler (org.bukkit.event.EventHandler)4 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Landlord (biz.princeps.landlord.Landlord)2 ManageGUIAll (biz.princeps.landlord.guis.ManageGUIAll)2 LangManager (biz.princeps.landlord.manager.LangManager)2 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)2 MultiPagedGUI (biz.princeps.lib.gui.MultiPagedGUI)2 Icon (biz.princeps.lib.gui.simple.Icon)2 DefaultFlag (com.sk89q.worldguard.protection.flags.DefaultFlag)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)2 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)2