use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.
the class Main method onEnable.
@Override
public void onEnable() {
instance = this;
Ublisk.RESTART_ERROR = false;
PacketListener.RUNNING = true;
Listeners.register();
Command.registerAll();
Mobs.clearMobs();
MobSpawn.startMobSpawning();
for (Task task : Task.values()) task.start();
Logger.startSiteLogger();
TodoList.initialize(DataFile.MYSQL.getConfig().getString("todo.ip"), DataFile.MYSQL.getConfig().getInt("todo.port"), DataFile.MYSQL.getConfig().getString("todo.database"), DataFile.MYSQL.getConfig().getString("todo.user"), DataFile.MYSQL.getConfig().getString("todo.password"));
for (UModule module : UModule.ALL_MODULES) {
try {
module.initialize();
} catch (Exception e) {
Logger.log(LogLevel.SEVERE, "Modules", "An error occured while initializing " + module.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace();
}
}
Bukkit.clearRecipes();
Ublisk.NMS = new V1_12_R1();
new SidebarAPI().onEnable();
new URunnable() {
public void run() {
Logger.log(LogLevel.INFO, "Cache", "Building up cache, expect some lag..");
for (Guild guild : Guild.getGuildsList()) {
guild.getDescription();
guild.getMembers();
guild.getOwner();
guild.getPoints();
}
for (UPlayer player : Ublisk.getOnlinePlayers()) {
player.getXP();
}
Logger.log(LogLevel.INFO, "Cache", "Complete! Now containing " + Cache.size() + " objects.");
Logger.log(LogLevel.INFO, "Guilds", "Deleting empty guilds...");
for (Guild guild : Guild.getGuildsList()) {
if (guild.getMembers().size() == 0) {
Logger.log(LogLevel.WARNING, "Guilds", "Automatically deleted " + guild.getName() + ", because it does not have any members.");
guild.remove();
}
}
}
}.runLater(10 * 20);
for (UPlayer player : Ublisk.getOnlinePlayers()) {
PlayerInfo.resetHashMaps(player);
}
Ublisk.openDatabaseConnection();
}
use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.
the class Builder method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(Message.NOT_A_PLAYER.toString());
return true;
}
if (args.length != 0) {
sender.sendMessage(Message.WRONG_USAGE.toString());
return true;
}
UPlayer player = new UPlayer(sender);
if (!player.hasPermission(Permission.BUILDER_MODE)) {
player.sendMessage(Message.NO_PERMISSION);
return true;
}
player.toggleBuilderMode();
return true;
}
use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.
the class FriendsCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
UPlayer player = new UPlayer(sender);
if (args.length == 0) {
new FriendsMenu(player).open();
} else if (args.length == 2) {
if (args[0].equals("add")) {
OfflinePlayer target = Ublisk.getOfflinePlayer(args[1]);
if (target == null) {
player.sendMessage(Message.PLAYER_NOT_FOUND);
return true;
}
if (player.isFriend(target)) {
player.sendPrefixedMessage("Friends", ChatColor.RED + target.getName() + " is already in your friends list.");
return true;
}
player.addFriend(target);
player.sendPrefixedMessage("Friends", target.getName() + " has been added to your friends list");
} else if (args[0].equals("remove") || args[0].equals("delete")) {
OfflinePlayer target = Ublisk.getOfflinePlayer(args[1]);
if (target == null) {
player.sendMessage(Message.PLAYER_NOT_FOUND);
return true;
}
if (!player.isFriend(target)) {
player.sendMessage(Message.FRIEND_NOT_EXIST);
return true;
}
player.removeFriend(target);
player.sendPrefixedMessage("Friends", target.getName() + " has been removed from your friends list");
} else {
player.sendMessage(Message.WRONG_USAGE);
}
} else {
player.sendMessage(Message.WRONG_USAGE);
}
} else {
sender.sendMessage(Message.NOT_A_PLAYER.toString());
}
return true;
}
use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.
the class LifeCrystalInventory method run.
@Override
public void run() {
for (UPlayer player : Ublisk.getOnlinePlayers()) {
if (player.isInBuilderMode()) {
Item helmet = new Item(Material.GOLD_HELMET).setName(ChatColor.GOLD + "Builder's Helmet");
player.getInventory().setHelmet(helmet);
} else {
Item menuChest = new Item(Material.CHEST).setName(ChatColor.BLUE + "" + ChatColor.BOLD + "Chest").setLore(ChatColor.GRAY + "Right click to open menu.", ChatColor.GRAY + "TIP: You can also use /menu").setDroppable(false);
player.getInventory().set(7, menuChest);
Item item = new Item(Material.NETHER_STAR).setAmount(player.getLifeCrystals()).setName(ChatColor.BLUE + "Life Crystals: " + ChatColor.AQUA + player.getLifeCrystals()).setLore("You have " + player.getLifeCrystals() + " life crystals").setDroppable(false);
player.getInventory().set(8, item);
}
}
}
use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.
the class GuildCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(Message.NOT_A_PLAYER.toString());
}
UPlayer player = new UPlayer(sender);
if (args.length == 1) {
if (args[0].equalsIgnoreCase("accept")) {
if (Guild.GUILD_INVITES.containsKey(player.getName())) {
// Player has got an invite
GuildInvite invite = Guild.GUILD_INVITES.get(player.getName());
Guild guild = invite.getGuild();
player.setGuild(guild);
player.sendPrefixedMessage("Guilds", "You joined " + guild.getName() + "!");
for (UPlayer guildMember : guild.getMembers()) {
if (guildMember.isOnline() && guildMember.getUniqueId() != player.getUniqueId()) {
guildMember.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + player.getName() + " has joined your guild!");
}
}
Guild.GUILD_INVITES.remove(player.getName());
return true;
} else {
// Player does not have an invite
player.sendPrefixedMessage("Guilds", "You don't have any pending invites.");
return true;
}
} else if (args[0].equalsIgnoreCase("leave")) {
if (player.getGuild() == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild");
return true;
}
Guild guild = player.getGuild();
if (guild.getMembers().size() <= 1) {
// If player is last person in guild (player can be owner if they're the only one left)
player.sendPrefixedMessage("Guilds", "You left " + guild.getName() + ". Because you were the last player in the guild, your guild has been queued for deletion. If you regret leaving this guild, ask a staff member to add you back.");
player.leaveGuild();
return true;
} else if (guild.getOwner().getUniqueId().equals(player.getUniqueId())) {
// If player is owner - don't allow them to leave
player.sendMessage("You are owner of this guild. You can only leave this guild if you transfer ownership to another guild member.");
return true;
} else {
// Otherwise it's just a normal player - allow leaving
player.sendPrefixedMessage("Guilds", "You have left " + guild.getName());
player.leaveGuild();
return true;
}
} else if (args[0].equalsIgnoreCase("list")) {
player.sendMessage(ChatColor.AQUA + "----------={" + ChatColor.DARK_AQUA + " Guilds " + ChatColor.AQUA + "}=----------");
for (Guild guild : Guild.getGuildsList(10)) {
BaseComponent[] members = new BaseComponent[] {};
for (UPlayer member : guild.getMembers()) {
BaseComponent[] components = member.getDisplayName(ChatColor.BLUE, false);
members = ArrayUtils.addAll(members, components);
}
player.sendMessage(ArrayUtils.addAll(TextComponent.fromLegacyText(ChatColor.YELLOW + guild.getName() + ChatColor.DARK_GRAY + " | " + ChatColor.RED + guild.getPoints() + " Points" + ChatColor.DARK_GRAY + " | "), members));
}
return true;
} else if (args[0].equalsIgnoreCase("help")) {
return false;
} else if (args[0].equalsIgnoreCase("info")) {
Guild guild = player.getGuild();
if (guild == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild. Use /guild info [guild] to check information about another guild.");
return true;
}
player.executeCommand("guild info " + guild.getName());
return true;
} else {
return false;
}
} else if (args.length == 2) {
if (args[0].equals("create")) {
Ublisk.runAsync(() -> {
if (args[1].length() > 20) {
Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "This guild name is too long."));
return;
}
if (!StringUtils.validateString(args[1])) {
Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "Guild names can only contain alphanumerical characters and underscores (a-z, A-Z, 0-9, _)"));
return;
}
if (player.getGuild() != null) {
Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "You are already in a guild. Please leave your current guild before creating a new one."));
return;
}
Guild guild = new Guild(args[1]);
if (guild.exists()) {
Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "A guild with this name already exists."));
return;
}
guild.create(player);
Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "The guild has been created."));
});
return true;
} else if (args[0].equals("info")) {
Guild guild = new Guild(args[1]);
if (!guild.exists()) {
player.sendPrefixedMessage("Guilds", "This guild does not exist.");
return true;
}
player.sendMessage(new ComponentBuilder("Name: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getName()).color(ChatColor.AQUA).create());
player.sendMessage(new ComponentBuilder("Points: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getPoints() + "").color(ChatColor.AQUA).create());
player.sendMessage(new ComponentBuilder("Description: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getDescription()).color(ChatColor.AQUA).create());
player.sendMessage(new ComponentBuilder("Members: ").color(ChatColor.DARK_AQUA).create());
for (UPlayer member : guild.getMembers()) {
player.sendMessage(new ComponentBuilder("- ").color(ChatColor.DARK_GRAY).bold(true).create(), member.getDisplayName(ChatColor.AQUA, false));
}
return true;
} else if (args[0].equalsIgnoreCase("invite")) {
if (player.getGuild() == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild.");
return true;
}
UPlayer target = null;
try {
target = new UPlayer(args[1]);
} catch (PlayerNotFoundException e) {
player.sendMessage(Message.PLAYER_NOT_FOUND);
return true;
}
Guild guild = player.getGuild();
guild.invitePlayer(player, target);
player.sendPrefixedMessage("Guilds", "You have invited " + target.getName() + " to your guild.");
return true;
} else if (args[0].equalsIgnoreCase("rename")) {
if (player.getGuild() == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild.");
return true;
}
if (!StringUtils.validateString(args[1])) {
player.sendPrefixedMessage("Guilds", "Guild names can only contain alphanumerical characters and underscores (a-z, A-Z, 0-9, _).");
return true;
}
Guild guild = new Guild(args[1]);
if (guild.exists()) {
player.sendPrefixedMessage("Guilds", "A guild with this name already exists.");
return true;
}
player.sendPrefixedMessage("Guilds", "Your guild has been renamed to " + args[1]);
Ublisk.runAsync(() -> {
guild.rename(args[1]);
});
return true;
} else if (args[0].equalsIgnoreCase("owner")) {
if (player.getGuild() == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild.");
return true;
}
UPlayer target;
try {
target = new UPlayer(args[1]);
} catch (PlayerNotFoundException e) {
player.sendPrefixedMessage("Guilds", "This player could not be found.");
return true;
}
Guild guild = player.getGuild();
if (!player.getGuild().getName().equals(target.getGuild().getName())) {
player.sendPrefixedMessage("Guilds", "You cannot transfer ownership to a player who is not in your guild.");
return true;
}
player.sendPrefixedMessage("Guilds", target.getName() + " is now the owner of " + guild.getName());
Ublisk.runAsync(() -> {
guild.setOwner(target);
});
return true;
} else {
return false;
}
} else if (args[0].equalsIgnoreCase("description") || args[0].equalsIgnoreCase("desc")) {
String description = String.join(" ", ListUtils.removeFirstStringFromArray(args));
if (description.length() > 100) {
player.sendPrefixedMessage("Guilds", "This description is too long.");
return true;
}
if (description.length() < 6) {
player.sendPrefixedMessage("Guilds", "This description is too short.");
return true;
}
Guild guild = player.getGuild();
if (guild == null) {
player.sendPrefixedMessage("Guilds", "You are not in a guild.");
return true;
}
player.sendPrefixedMessage("Guilds", "You have changed your guild's description to " + StringUtils.addDotIfNecessary(description));
Ublisk.runAsync(() -> {
guild.setDescription(description);
});
return true;
} else {
return false;
}
}
Aggregations