Search in sources :

Example 6 with OwnedLand

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

the class Addfriend method onAddfriend.

public void onAddfriend(Player player, String[] names) {
    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.Addfriend.notOwn").replace("%owner%", land.printOwners()));
            return;
        }
        if (names.length == 0) {
            player.sendMessage(lm.getString("Commands.Addfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
            return;
        }
        for (String target : names) {
            plugin.getPlayerManager().getOfflinePlayer(target, lPlayer -> {
                if (lPlayer == null) {
                    player.sendMessage(lm.getString("Commands.Addfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
                } else {
                    // Success
                    if (!land.getWGLand().getOwners().getUniqueIds().contains(lPlayer.getUuid())) {
                        land.getWGLand().getMembers().addPlayer(lPlayer.getUuid());
                        player.sendMessage(lm.getString("Commands.Addfriend.success").replace("%players%", Arrays.asList(names).toString()));
                    } else {
                        player.sendMessage(lm.getString("Commands.Addfriend.alreadyOwn"));
                    }
                }
            });
            // lets delay it, because we cant be sure, that the requests are done when executing this piece of code
            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 7 with OwnedLand

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

the class ListLands method onListLands.

public void onListLands(Player sender, LPlayer target, int page) {
    List<ProtectedRegion> lands = new ArrayList<>(plugin.getWgHandler().getRegions(target.getUuid()));
    if (lands.size() > 0) {
        String mode = plugin.getConfig().getString("CommandSettings.ListLands.mode");
        if (mode.equals("gui")) {
            MultiPagedGUI landGui = new MultiPagedGUI(sender, 5, plugin.getLangManager().getRawString("Commands.ListLands.header").replace("%player%", target.getName()));
            lands.forEach(land -> landGui.addIcon(new Icon(new ItemStack(Material.GRASS)).setName(land.getId())));
            landGui.setIcon(52, new Icon(new ItemStack(Material.BEACON)).setName(lm.getRawString("Commands.ListLands.manageAll")).addClickAction((p, ic2) -> {
                ManageGUIAll manageGUIAll = new ManageGUIAll(sender, landGui, plugin.getWgHandler().getRegionsAsOL(target.getUuid()));
                manageGUIAll.display();
            }));
            landGui.display();
        } else {
            // Chat based system
            List<String> formatted = new ArrayList<>();
            String segment = lm.getRawString("Commands.ListLands.chat.segment");
            lands.forEach(land -> {
                OwnedLand ol = plugin.getLand(land);
                formatted.add(segment.replace("%landname%", ol.getName()).replace("%members%", ol.printMembers()));
            });
            String prev = lm.getRawString("Commands.ListLands.chat.previous");
            String next = lm.getRawString("Commands.ListLands.chat.next");
            MultiPagedMessage message = new MultiPagedMessage("/land list", plugin.getLangManager().getRawString("Commands.ListLands.header").replace("%player%", target.getName()), plugin.getConfig().getInt("CommandSettings.ListLands.landsPerPage"), formatted, prev, next, page);
            sender.spigot().sendMessage(message.create());
        }
    } else {
        sender.sendMessage(plugin.getLangManager().getString("Commands.ListLands.noLands"));
    }
}
Also used : MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) LandlordCommand(biz.princeps.landlord.commands.LandlordCommand) ManageGUIAll(biz.princeps.landlord.guis.ManageGUIAll) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) LPlayer(biz.princeps.landlord.persistent.LPlayer) OwnedLand(biz.princeps.landlord.util.OwnedLand) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) List(java.util.List) MultiPagedMessage(biz.princeps.lib.chat.MultiPagedMessage) Icon(biz.princeps.lib.gui.simple.Icon) Material(org.bukkit.Material) ManageGUIAll(biz.princeps.landlord.guis.ManageGUIAll) MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) OwnedLand(biz.princeps.landlord.util.OwnedLand) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) ArrayList(java.util.ArrayList) Icon(biz.princeps.lib.gui.simple.Icon) MultiPagedMessage(biz.princeps.lib.chat.MultiPagedMessage) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with OwnedLand

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

the class LandAlerter method onMove.

@EventHandler
public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    Location comingFrom = e.getFrom();
    Location headingTowards = e.getTo();
    OwnedLand landFrom = pl.getWgHandler().getRegion(comingFrom);
    OwnedLand landTowards = pl.getWgHandler().getRegion(headingTowards);
    if (landTowards == null) {
        // System.out.println(playerInLand.get(p.getUniqueId()) + " removed");
        playerInLand.remove(p.getUniqueId());
    } else if (!landTowards.equals(landFrom)) {
        playerInLand.put(p.getUniqueId(), landTowards);
    // System.out.println(landTowards.getName() + " added");
    }
}
Also used : Player(org.bukkit.entity.Player) OwnedLand(biz.princeps.landlord.util.OwnedLand) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 9 with OwnedLand

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

the class TresholdListener method onBreak.

@EventHandler
public void onBreak(BlockBreakEvent e) {
    Player p = e.getPlayer();
    OwnedLand land = plugin.getLand(e.getBlock().getLocation());
    handleLand(p, e.getBlock().getLocation(), land, e);
}
Also used : Player(org.bukkit.entity.Player) OwnedLand(biz.princeps.landlord.util.OwnedLand) EventHandler(org.bukkit.event.EventHandler)

Example 10 with OwnedLand

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

the class TresholdListener method onPlace.

@EventHandler
public void onPlace(BlockPlaceEvent e) {
    Player p = e.getPlayer();
    OwnedLand land = plugin.getLand(e.getBlock().getLocation());
    handleLand(p, e.getBlockPlaced().getLocation(), land, e);
}
Also used : Player(org.bukkit.entity.Player) OwnedLand(biz.princeps.landlord.util.OwnedLand) EventHandler(org.bukkit.event.EventHandler)

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