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