Search in sources :

Example 11 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcLives method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.adminNoLivesGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    int lives;
    try {
        lives = Integer.valueOf(args[1]);
    } catch (NumberFormatException e) {
        sender.sendMessage(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildLivesChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, lives))) {
        return;
    }
    guild.setLives(lives);
    sender.sendMessage(messages.adminLivesChanged.replace("{GUILD}", guild.getTag()).replace("{LIVES}", Integer.toString(lives)));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildLivesChangeEvent(net.dzikoysk.funnyguilds.event.guild.GuildLivesChangeEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 12 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcMove method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        player.sendMessage(messages.generalNoGuildFound);
        return;
    }
    Location location = player.getLocation();
    if (config.createCenterY != 0) {
        location.setY(config.createCenterY);
    }
    int d = config.regionSize + config.createDistance;
    if (config.enlargeItems != null) {
        d = config.enlargeItems.size() * config.enlargeSize + d;
    }
    if (d > player.getWorld().getSpawnLocation().distance(location)) {
        player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(d)));
        return;
    }
    if (RegionUtils.isNear(location)) {
        player.sendMessage(messages.createIsNear);
        return;
    }
    User admin = User.get(player);
    if (!SimpleEventHandler.handle(new GuildMoveEvent(EventCause.ADMIN, admin, guild, location))) {
        return;
    }
    Region region = RegionUtils.get(guild.getRegion());
    if (region == null) {
        region = new Region(guild, location, config.regionSize);
    } else {
        if (config.createEntityType != null) {
            EntityUtil.despawn(guild);
        } else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
            Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
            Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
                if (block.getLocation().getBlockY() > 1) {
                    block.setType(Material.AIR);
                }
            });
        }
        region.setCenter(location);
    }
    if (config.createCenterSphere) {
        List<Location> sphere = SpaceUtils.sphere(location, 3, 3, false, true, 0);
        for (Location l : sphere) {
            if (l.getBlock().getType() != Material.BEDROCK) {
                l.getBlock().setType(Material.AIR);
            }
        }
    }
    if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
        Block heart = location.getBlock().getRelative(BlockFace.DOWN);
        heart.setType(config.createMaterialData.getItemType());
        heart.setData(config.createMaterialData.getData());
    } else if (config.createEntityType != null) {
        EntityUtil.spawn(guild);
    }
    player.sendMessage(messages.adminGuildRelocated.replace("{GUILD}", guild.getName()).replace("{REGION}", region.getName()));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMoveEvent(net.dzikoysk.funnyguilds.event.guild.GuildMoveEvent) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) Location(org.bukkit.Location)

Example 13 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class DatabaseBasic method load.

public void load() {
    Database db = Database.getInstance();
    PluginConfig config = Settings.getConfig();
    usersTable(db);
    regionsTable(db);
    guildsTable(db);
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.usersTableName + "`", usersResult -> {
        try {
            while (usersResult.next()) {
                User user = DatabaseUser.deserialize(usersResult);
                if (user != null) {
                    user.changed();
                }
            }
            FunnyLogger.info("Loaded users: " + UserUtils.getUsers().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    if (Settings.getConfig().regionsEnabled) {
        Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.regionsTableName + "`", regionsResult -> {
            try {
                while (regionsResult.next()) {
                    Region region = DatabaseRegion.deserialize(regionsResult);
                    if (region != null) {
                        region.changed();
                    }
                }
                FunnyLogger.info("Loaded regions: " + RegionUtils.getRegions().size());
            } catch (Exception e) {
                if (FunnyLogger.exception(e.getCause())) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        FunnyLogger.info("Regions are disabled and thus - not loaded");
    }
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.guildsTableName + "`", guildsResult -> {
        try {
            while (guildsResult.next()) {
                Guild guild = DatabaseGuild.deserialize(guildsResult);
                if (guild != null) {
                    guild.changed();
                }
            }
            FunnyLogger.info("Loaded guilds: " + GuildUtils.getGuilds().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    // TODO
    for (Guild guild : GuildUtils.getGuilds()) {
        if (guild.getOwner() != null) {
            continue;
        }
        GuildUtils.deleteGuild(guild);
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalUpdateRequest());
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Region(net.dzikoysk.funnyguilds.basic.Region) Guild(net.dzikoysk.funnyguilds.basic.Guild) SQLException(java.sql.SQLException) PrefixGlobalUpdateRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)

Example 14 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class DatabaseGuild method deserialize.

public static Guild deserialize(ResultSet rs) {
    if (rs == null) {
        return null;
    }
    try {
        String id = rs.getString("uuid");
        String name = rs.getString("name");
        String tag = rs.getString("tag");
        String os = rs.getString("owner");
        String dp = rs.getString("deputy");
        String home = rs.getString("home");
        String region = rs.getString("region");
        String m = rs.getString("members");
        String rgs = rs.getString("regions");
        String als = rs.getString("allies");
        String ens = rs.getString("enemies");
        boolean pvp = rs.getBoolean("pvp");
        long born = rs.getLong("born");
        long validity = rs.getLong("validity");
        long attacked = rs.getLong("attacked");
        long ban = rs.getLong("ban");
        int lives = rs.getInt("lives");
        if (name == null || tag == null || os == null) {
            FunnyLogger.error("Cannot deserialize guild! Caused by: uuid/name/tag/owner is null");
            return null;
        }
        UUID uuid = UUID.randomUUID();
        if (id != null) {
            uuid = UUID.fromString(id);
        }
        User owner = User.get(os);
        List<User> deputies = new ArrayList<>();
        if (dp != null && !dp.isEmpty()) {
            deputies = UserUtils.getUsers(StringUtils.fromString(dp));
        }
        List<User> members = new ArrayList<>();
        if (m != null && !m.equals("")) {
            members = UserUtils.getUsers(StringUtils.fromString(m));
        }
        List<String> regions = StringUtils.fromString(rgs);
        List<Guild> allies = new ArrayList<>();
        if (als != null && !als.equals("")) {
            allies = GuildUtils.getGuilds(StringUtils.fromString(als));
        }
        List<Guild> enemies = new ArrayList<>();
        if (ens != null && !ens.equals("")) {
            enemies = GuildUtils.getGuilds(StringUtils.fromString(ens));
        }
        if (born == 0) {
            born = System.currentTimeMillis();
        }
        if (validity == 0) {
            validity = System.currentTimeMillis() + Settings.getConfig().validityStart;
        }
        if (lives == 0) {
            lives = Settings.getConfig().warLives;
        }
        Object[] values = new Object[17];
        values[0] = uuid;
        values[1] = name;
        values[2] = tag;
        values[3] = owner;
        values[4] = Parser.parseLocation(home);
        values[5] = region;
        values[6] = members;
        values[7] = regions;
        values[8] = allies;
        values[9] = enemies;
        values[10] = born;
        values[11] = validity;
        values[12] = attacked;
        values[13] = lives;
        values[14] = ban;
        values[15] = deputies;
        values[16] = pvp;
        return DeserializationUtils.deserializeGuild(values);
    } catch (Exception e) {
        if (FunnyLogger.exception(e.getCause())) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : User(net.dzikoysk.funnyguilds.basic.User) ArrayList(java.util.ArrayList) Guild(net.dzikoysk.funnyguilds.basic.Guild) UUID(java.util.UUID)

Example 15 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class Flat method loadUsers.

private void loadUsers() {
    int i = 0;
    File[] path = USERS.listFiles();
    if (path != null) {
        for (File file : path) {
            if (file.isDirectory() || file.length() == 0) {
                file.delete();
                i++;
                continue;
            }
            User user = FlatUser.deserialize(file);
            if (user == null) {
                file.delete();
                i++;
            } else {
                user.changed();
            }
        }
    }
    if (i > 0) {
        FunnyLogger.warning("Repaired conflicts: " + i);
    }
    FunnyLogger.info("Loaded users: " + UserUtils.getUsers().size());
}
Also used : User(net.dzikoysk.funnyguilds.basic.User) File(java.io.File)

Aggregations

User (net.dzikoysk.funnyguilds.basic.User)66 Player (org.bukkit.entity.Player)50 Guild (net.dzikoysk.funnyguilds.basic.Guild)43 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)39 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)25 Region (net.dzikoysk.funnyguilds.basic.Region)13 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)11 EventHandler (org.bukkit.event.EventHandler)10 Location (org.bukkit.Location)8 ItemStack (org.bukkit.inventory.ItemStack)6 ArrayList (java.util.ArrayList)5 Rank (net.dzikoysk.funnyguilds.basic.Rank)5 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)4 Date (java.util.Date)3 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 GuildDeleteEvent (net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent)3