Search in sources :

Example 76 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.

the class UnfriendAll method onUnfriendall.

public void onUnfriendall(Player player, String name) {
    if (name == null || name.isEmpty()) {
        player.sendMessage(lm.getString("Commands.Addfriend.noPlayer").replace("%players%", Collections.singletonList("[]").toString()));
        return;
    }
    plugin.getPlayerManager().getOfflinePlayer(name, lPlayer -> {
        // Failure
        if (lPlayer == null) {
            player.sendMessage(lm.getString("Commands.UnfriendAll.noPlayer").replace("%players%", Collections.singletonList(name).toString()));
        } else {
            // Success
            int count = 0;
            for (ProtectedRegion protectedRegion : plugin.getWgHandler().getRegions(player.getUniqueId())) {
                if (protectedRegion.getMembers().contains(lPlayer.getUuid())) {
                    protectedRegion.getMembers().removePlayer(lPlayer.getUuid());
                    count++;
                }
            }
            if (count > 0) {
                player.sendMessage(lm.getString("Commands.UnfriendAll.success").replace("%count%", String.valueOf(count)).replace("%players%", name));
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        plugin.getMapManager().updateAll();
                    }
                }.runTask(plugin);
            } else {
                player.sendMessage(lm.getString("Commands.UnfriendAll.noFriend").replace("%player%", name));
            }
        }
    });
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 77 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable 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)

Example 78 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.

the class JoinListener method onDisconnect.

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

        @Override
        public void run() {
            plugin.getPlayerManager().get(p.getUniqueId()).setLastSeen(LocalDateTime.now());
            plugin.getPlayerManager().save(p.getUniqueId());
            plugin.getPlayerManager().remove(p.getUniqueId());
        }
    }.runTaskAsynchronously(plugin);
}
Also used : LPlayer(biz.princeps.landlord.persistent.LPlayer) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 79 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.

the class LPlayerManager method addOffer.

public void addOffer(Offers offer) {
    offers.put(offer.getLandname(), offer);
    new BukkitRunnable() {

        @Override
        public void run() {
            Landlord.getInstance().getDatabaseAPI().saveObject(offer);
        }
    }.runTaskAsynchronously(plugin);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 80 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.

the class Landlordbase method migrate.

void migrate(AbstractDatabase db, String tablename, String ownerColumn, String worldColumn, String xColumn, String zColumn) {
    List<DataObject> objs = new ArrayList<>();
    db.executeQuery("SELECT * FROM " + tablename, res -> {
        try {
            while (res.next()) {
                UUID owner = UUID.fromString(res.getString(ownerColumn));
                String world = res.getString(worldColumn);
                int x = res.getInt(xColumn);
                int z = res.getInt(zColumn);
                objs.add(new DataObject(owner, world, x, z));
            }
        } catch (SQLException e) {
            Landlord.getInstance().getLogger().warning("There was an error while trying to fetching original data: " + e);
        }
    });
    db.getLogger().info("Finished fetching data from old database. Size: " + objs.size() + " lands");
    db.getLogger().info("The next step will take around " + objs.size() / 20 / 60 + " minutes");
    new BukkitRunnable() {

        int counter = 0;

        @Override
        public void run() {
            if (counter >= objs.size() - 1) {
                db.getLogger().info("Finished migrating database. Migrated " + objs.size() + " lands!");
                cancel();
            }
            DataObject next = objs.get(counter);
            World world1 = Bukkit.getWorld(next.world);
            if (world1 != null) {
                Chunk chunk = world1.getChunkAt(next.x, next.z);
                Landlord.getInstance().getWgHandler().claim(chunk, next.owner);
            }
            counter++;
            if (counter % 600 == 0)
                db.getLogger().info("Processed " + counter + " lands already. " + (objs.size() - counter) / 20 / 60 + " minutes remaining!");
        }
    }.runTaskTimer(Landlord.getInstance(), 0, 1);
}
Also used : SQLException(java.sql.SQLException) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10