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));
}
}
});
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations