Search in sources :

Example 1 with LPlayer

use of biz.princeps.landlord.persistent.LPlayer in project LandLord by SpatiumPrinceps.

the class AbstractManage method formatFriendsSegment.

private List<String> formatFriendsSegment(UUID id) {
    OfflinePlayer op = Bukkit.getOfflinePlayer(id);
    CompletableFuture<List<Object>> future = new CompletableFuture<>();
    plugin.getExecutorService().submit(() -> {
        List<Object> listi = plugin.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", op.getUniqueId().toString()).create());
        future.complete(listi);
    });
    List<String> stringList = lm.getStringList("Commands.Manage.ManageFriends.friendSegment");
    List<String> newlist = new ArrayList<>();
    try {
        final String lastseen;
        if (op.isOnline()) {
            lastseen = lm.getRawString("Commands.Info.online");
        } else {
            if (future.get().size() > 0)
                lastseen = ((LPlayer) future.get().get(0)).getLastSeenAsString();
            else
                lastseen = "NaN";
        }
        stringList.forEach(s -> {
            String ss = s.replace("%seen%", lastseen);
            newlist.add(ss);
        });
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    return newlist;
}
Also used : Conditions(biz.princeps.lib.storage.requests.Conditions) LPlayer(biz.princeps.landlord.persistent.LPlayer) CompletableFuture(java.util.concurrent.CompletableFuture) OfflinePlayer(org.bukkit.OfflinePlayer) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with LPlayer

use of biz.princeps.landlord.persistent.LPlayer in project LandLord by SpatiumPrinceps.

the class Unclaim method onUnclaim.

public void onUnclaim(Player player, String chunkname) {
    if (this.worldDisabled(player)) {
        player.sendMessage(lm.getString("Disabled-World"));
        return;
    }
    Chunk chunk = null;
    if (chunkname.equals("null")) {
        chunk = player.getWorld().getChunkAt(player.getLocation());
    } else {
        String[] split = chunkname.split("_");
        try {
            if (split.length != 3) {
                Bukkit.dispatchCommand(player, "/ll help");
                return;
            }
            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.Unclaim.notOwnFreeLand"));
        return;
    }
    // is admin - allowed to unclaim
    boolean isAdmin = false;
    if (!player.hasPermission("landlord.admin.unclaim")) {
        if (!pr.isOwner(player.getUniqueId())) {
            player.sendMessage(lm.getString("Commands.Unclaim.notOwn").replace("%owner%", pr.printOwners()));
            return;
        }
    } else
        isAdmin = true;
    // Normal unclaim
    LandUnclaimEvent event = new LandUnclaimEvent(player, pr);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        double payback = -1;
        if (!isAdmin || pr.isOwner(player.getUniqueId())) {
            int regionCount = plugin.getWgHandler().getRegionCountOfPlayer(player.getUniqueId());
            int freeLands = plugin.getConfig().getInt("Freelands");
            if (Options.isVaultEnabled()) {
                if (regionCount <= freeLands)
                    payback = 0;
                else {
                    payback = plugin.getCostManager().calculateCost(player.getUniqueId()) * plugin.getConfig().getDouble("Payback");
                    // System.out.println(payback);
                    if (payback > 0)
                        plugin.getVaultHandler().give(player.getUniqueId(), payback);
                }
            }
        }
        plugin.getWgHandler().unclaim(player.getWorld(), pr.getName());
        // remove possible homes
        LPlayer lPlayer = plugin.getPlayerManager().get(pr.getOwner());
        if (lPlayer != null) {
            Location home = lPlayer.getHome();
            if (home != null) {
                if (pr.getWGLand().contains(home.getBlockX(), home.getBlockY(), home.getBlockZ())) {
                    player.sendMessage(lm.getString("Commands.SetHome.removed"));
                    plugin.getPlayerManager().get(pr.getOwner()).setHome(null);
                }
            }
        }
        // Remove possible advertisements
        plugin.getPlayerManager().removeOffer(pr.getName());
        player.sendMessage(lm.getString("Commands.Unclaim.success").replace("%chunk%", OwnedLand.getName(chunk)).replace("%world%", chunk.getWorld().getName()).replace("%money%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(payback) : "-eco disabled-")));
        plugin.getMapManager().updateAll();
    }
}
Also used : LPlayer(biz.princeps.landlord.persistent.LPlayer) LandUnclaimEvent(biz.princeps.landlord.api.events.LandUnclaimEvent) OwnedLand(biz.princeps.landlord.util.OwnedLand) Chunk(org.bukkit.Chunk) Location(org.bukkit.Location)

Example 3 with LPlayer

use of biz.princeps.landlord.persistent.LPlayer 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 4 with LPlayer

use of biz.princeps.landlord.persistent.LPlayer in project LandLord by SpatiumPrinceps.

the class Landlord method onEnable.

@Override
public void onEnable() {
    // Dependency stuff
    if (getWorldGuard() == null) {
        getLogger().warning("WorldGuard not found! Please ensure you have the correct version of WorldGuard in order to use LandLord");
        getPluginLoader().disablePlugin(this);
        return;
    } else
        wgHandler = new WorldGuardHandler(getWorldGuard());
    if (getVault() == null) {
        getLogger().warning("Vault not found! Not all features of landlord are working.");
    } else
        vaultHandler = new VaultHandler(getVault());
    if (!getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
        getLogger().warning("ProtocolLib not found! Please ensure you have the correct version of ProtocolLib in order to use LandLord");
        getPluginLoader().disablePlugin(this);
        return;
    }
    instance = this;
    PrincepsLib.setPluginInstance(this);
    checkWorldNames();
    saveDefaultConfig();
    ConfigUtil.handleConfigUpdate(this.getDataFolder() + "/config.yml", "/config.yml");
    saveDefaultConfig();
    langManager = new LangManager(this, getConfig().getString("Language", "en"));
    databaseAPI = new DatabaseAPI(DatabaseType.valueOf(getConfig().getString("DatabaseType")), getConfig(), new Requests(), "biz.princeps.landlord.persistent");
    handleDatabase();
    manageCommands();
    manageListeners();
    managePlaceholders();
    manageItems();
    lPlayerManager = new LPlayerManager(databaseAPI);
    lPlayerManager.onStartup();
    mapManager = new MapManager();
    ScoreboardLib.setPluginInstance(this);
    costManager = new CostManager();
    executorService = Executors.newCachedThreadPool();
    // Retrieve the LPlayer objects for all online players (in case of reload)
    Bukkit.getOnlinePlayers().forEach(p -> {
        List<Object> lPlayer = this.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", p.getUniqueId().toString()).create());
        LPlayer lp;
        if (lPlayer.size() > 0)
            lp = (LPlayer) lPlayer.get(0);
        else
            lp = new LPlayer(p.getUniqueId());
        this.getPlayerManager().add(p.getUniqueId(), lp);
    });
    if (getConfig().getBoolean("EnableMetrics")) {
        Metrics metrics = new Metrics(this);
    // TODO maybe add some interesting statistics
    }
}
Also used : LPlayerManager(biz.princeps.landlord.manager.LPlayerManager) LangManager(biz.princeps.landlord.manager.LangManager) WorldGuardHandler(biz.princeps.landlord.handler.WorldGuardHandler) VaultHandler(biz.princeps.landlord.handler.VaultHandler) DatabaseAPI(biz.princeps.lib.storage.DatabaseAPI) Requests(biz.princeps.landlord.persistent.Requests) Conditions(biz.princeps.lib.storage.requests.Conditions) LPlayer(biz.princeps.landlord.persistent.LPlayer) Metrics(biz.princeps.landlord.util.Metrics) CostManager(biz.princeps.landlord.manager.CostManager) MapManager(biz.princeps.landlord.manager.map.MapManager)

Example 5 with LPlayer

use of biz.princeps.landlord.persistent.LPlayer in project LandLord by SpatiumPrinceps.

the class JoinListener method onJoin.

@EventHandler
public void onJoin(PlayerJoinEvent event) {
    Player p = event.getPlayer();
    new BukkitRunnable() {

        @Override
        public void run() {
            List<Object> lPlayer = plugin.getDatabaseAPI().retrieveObjects(LPlayer.class, new Conditions.Builder().addCondition("uuid", p.getUniqueId().toString()).create());
            LPlayer lp;
            if (lPlayer.size() > 0)
                lp = (LPlayer) lPlayer.get(0);
            else
                lp = new LPlayer(p.getUniqueId());
            if (lp.getName() == null || lp.getName().isEmpty() || !p.getName().equals(lp.getName())) {
                lp.setName(p.getName());
            }
            plugin.getPlayerManager().add(p.getUniqueId(), lp);
            // The next to lines are needed to protect claiming of "inactive" lands although the owner is online right now
            // might just be a rare never happening edge case, but lets be safe
            plugin.getPlayerManager().get(p.getUniqueId()).setLastSeen(LocalDateTime.now());
            plugin.getPlayerManager().save(p.getUniqueId());
            Event event = new FinishedLoadingPlayerEvent(p, lp);
            Bukkit.getPluginManager().callEvent(event);
        }
    }.runTaskAsynchronously(plugin);
}
Also used : LPlayer(biz.princeps.landlord.persistent.LPlayer) FinishedLoadingPlayerEvent(biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent) LPlayer(biz.princeps.landlord.persistent.LPlayer) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) FinishedLoadingPlayerEvent(biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Event(org.bukkit.event.Event) List(java.util.List) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LPlayer (biz.princeps.landlord.persistent.LPlayer)8 OwnedLand (biz.princeps.landlord.util.OwnedLand)3 List (java.util.List)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Conditions (biz.princeps.lib.storage.requests.Conditions)2 Chunk (org.bukkit.Chunk)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 FinishedLoadingPlayerEvent (biz.princeps.landlord.api.events.FinishedLoadingPlayerEvent)1 LandUnclaimEvent (biz.princeps.landlord.api.events.LandUnclaimEvent)1 LandlordCommand (biz.princeps.landlord.commands.LandlordCommand)1 ManageGUIAll (biz.princeps.landlord.guis.ManageGUIAll)1 VaultHandler (biz.princeps.landlord.handler.VaultHandler)1 WorldGuardHandler (biz.princeps.landlord.handler.WorldGuardHandler)1 CostManager (biz.princeps.landlord.manager.CostManager)1 LPlayerManager (biz.princeps.landlord.manager.LPlayerManager)1 LangManager (biz.princeps.landlord.manager.LangManager)1 MapManager (biz.princeps.landlord.manager.map.MapManager)1 Offers (biz.princeps.landlord.persistent.Offers)1 Requests (biz.princeps.landlord.persistent.Requests)1