use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class ExcValidity method execute.
@Override
public void execute(CommandSender sender, String[] args) {
PluginConfig config = Settings.getConfig();
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
User user = User.get(player);
Guild guild = user.getGuild();
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
if (!user.isOwner() && !user.isDeputy()) {
player.sendMessage(messages.generalIsNotOwner);
return;
}
if (config.validityWhen != 0) {
long c = guild.getValidity();
long d = c - System.currentTimeMillis();
if (d > config.validityWhen) {
long when = d - config.validityWhen;
player.sendMessage(messages.validityWhen.replace("{TIME}", TimeUtils.getDurationBreakdown(when)));
return;
}
}
List<ItemStack> requiredItems = config.validityItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.validityItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(EventCause.USER, user, guild, config.validityTime))) {
return;
}
player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
long c = guild.getValidity();
if (c == 0) {
c = System.currentTimeMillis();
}
c += config.validityTime;
guild.setValidity(c);
player.sendMessage(messages.validityDone.replace("{DATE}", config.dateFormat.format(new Date(c))));
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class GuildUtils method deleteGuild.
public static void deleteGuild(final Guild guild) {
PluginConfig config = Settings.getConfig();
if (guild == null) {
return;
}
Manager.getInstance().stop();
if (config.regionsEnabled) {
Region region = RegionUtils.get(guild.getRegion());
if (region != null) {
if (config.createEntityType != null) {
EntityUtil.despawn(guild);
} else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
if (block.getLocation().getBlockY() > 1) {
block.setType(Material.AIR);
}
});
}
}
for (String name : guild.getRegions()) {
Region r = RegionUtils.get(name);
if (r != null) {
RegionUtils.delete(r);
}
}
RegionUtils.delete(Region.get(guild.getRegion()));
}
// IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_GUILD, guild);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalRemoveGuildRequest(guild));
UserUtils.removeGuild(guild.getMembers());
RankManager.getInstance().remove(guild);
for (Guild allay : guild.getAllies()) {
allay.removeAlly(guild);
}
for (Guild enemy : guild.getEnemies()) {
enemy.removeEnemy(guild);
}
if (Settings.getConfig().dataType.flat) {
Flat.getGuildFile(guild).delete();
}
if (Settings.getConfig().dataType.mysql) {
new DatabaseGuild(guild).delete();
}
guild.delete();
Manager.getInstance().start();
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class ExcEnlarge method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
PluginConfig config = Settings.getConfig();
Player player = (Player) sender;
User user = User.get(player);
if (!config.regionsEnabled) {
player.sendMessage(messages.regionsDisabled);
return;
}
if (!config.enlargeEnable) {
return;
}
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
if (!user.isOwner() && !user.isDeputy()) {
player.sendMessage(messages.generalIsNotOwner);
return;
}
Region region = Region.get(user.getGuild().getRegion());
int enlarge = region.getEnlarge();
if (enlarge > config.enlargeItems.size() - 1) {
player.sendMessage(messages.enlargeMaxSize);
return;
}
ItemStack need = config.enlargeItems.get(enlarge);
if (!player.getInventory().containsAtLeast(need, need.getAmount())) {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(need.getAmount());
messageBuilder.append(" ");
messageBuilder.append(need.getType().toString().toLowerCase());
player.sendMessage(messages.enlargeItem.replace("{ITEM}", messageBuilder.toString()));
return;
}
if (RegionUtils.isNear(region.getCenter())) {
player.sendMessage(messages.enlargeIsNear);
return;
}
if (!SimpleEventHandler.handle(new GuildEnlargeEvent(EventCause.USER, user, user.getGuild()))) {
return;
}
player.getInventory().removeItem(need);
region.setEnlarge(++enlarge);
region.setSize(region.getSize() + config.enlargeSize);
String enlargeDoneMessage = messages.enlargeDone.replace("{SIZE}", Integer.toString(region.getSize())).replace("{LEVEL}", Integer.toString(region.getEnlarge()));
user.getGuild().broadcast(enlargeDoneMessage);
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class ExcEscape method execute.
@Override
public void execute(CommandSender sender, String[] args) {
PluginConfig config = Settings.getConfig();
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
if (!config.regionsEnabled) {
player.sendMessage(messages.regionsDisabled);
return;
}
if (!config.escapeEnable || !config.baseEnable) {
player.sendMessage(messages.escapeDisabled);
return;
}
User user = User.get(player);
if (!user.hasGuild()) {
player.sendMessage(messages.escapeNoUserGuild);
return;
}
if (user.getTeleportation() != null) {
player.sendMessage(messages.escapeInProgress);
return;
}
Location playerLocation = player.getLocation();
Region region = RegionUtils.getAt(playerLocation);
if (region == null) {
player.sendMessage(messages.escapeNoNeedToRun);
return;
}
Guild guild = user.getGuild();
if (guild.equals(region.getGuild())) {
player.sendMessage(messages.escapeOnYourRegion);
return;
}
int time = Settings.getConfig().escapeDelay;
if (time < 1) {
player.teleport(guild.getHome());
player.sendMessage(messages.escapeSuccessfulUser);
for (User member : region.getGuild().getOnlineMembers()) {
member.getPlayer().sendMessage(messages.escapeSuccessfulOpponents.replace("{PLAYER}", player.getName()));
}
return;
}
player.sendMessage(messages.escapeStartedUser.replace("{TIME}", Integer.toString(time)));
String msg = messages.escapeStartedOpponents.replace("{TIME}", Integer.toString(time)).replace("{PLAYER}", player.getName()).replace("{X}", Integer.toString(playerLocation.getBlockX())).replace("{Y}", Integer.toString(playerLocation.getBlockY())).replace("{Z}", Integer.toString(playerLocation.getBlockZ()));
for (User member : region.getGuild().getOnlineMembers()) {
member.getPlayer().sendMessage(msg);
}
Location before = player.getLocation();
AtomicInteger i = new AtomicInteger(0);
user.setTeleportation(Bukkit.getScheduler().runTaskTimer(FunnyGuilds.getInstance(), () -> {
if (!player.isOnline()) {
user.getTeleportation().cancel();
user.setTeleportation(null);
return;
}
if (!LocationUtils.equals(player.getLocation(), before)) {
user.getTeleportation().cancel();
player.sendMessage(messages.escapeCancelled);
user.setTeleportation(null);
return;
}
if (i.getAndIncrement() > time) {
user.getTeleportation().cancel();
player.teleport(guild.getHome());
player.sendMessage(messages.escapeSuccessfulUser);
for (User member : region.getGuild().getOnlineMembers()) {
member.getPlayer().sendMessage(messages.escapeSuccessfulOpponents.replace("{PLAYER}", player.getName()));
}
user.setTeleportation(null);
}
}, 0L, 20L));
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class ExcItems method execute.
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
PluginConfig config = Settings.getConfig();
List<ItemStack> guildItems = config.createItems;
List<ItemStack> guiItems = config.guiItems;
String title = config.guiItemsTitle;
if (!config.useCommonGUI && player.hasPermission("funnyguilds.vip.items")) {
guildItems = config.createItemsVip;
guiItems = config.guiItemsVip;
title = config.guiItemsVipTitle;
}
GuiWindow gui = new GuiWindow(title, guiItems.size() / 9 + (guiItems.size() % 9 != 0 ? 1 : 0));
gui.setCloseEvent(close -> gui.unregister());
for (ItemStack item : guiItems) {
item = item.clone();
if (config.addLoreLines && guildItems.contains(item)) {
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
int pinvAmount = ItemUtils.getItemAmount(item, player.getInventory());
int ecAmount = ItemUtils.getItemAmount(item, player.getEnderChest());
for (String line : config.guiItemsLore) {
line = StringUtils.replace(line, "{PINV-AMOUNT}", Integer.toString(pinvAmount));
line = StringUtils.replace(line, "{PINV-PERCENT}", StringUtils.getPercent(pinvAmount, item.getAmount()));
line = StringUtils.replace(line, "{EC-AMOUNT}", Integer.toString(ecAmount));
line = StringUtils.replace(line, "{EC-PERCENT}", StringUtils.getPercent(ecAmount, item.getAmount()));
line = StringUtils.replace(line, "{ALL-AMOUNT}", Integer.toString(pinvAmount + ecAmount));
line = StringUtils.replace(line, "{ALL-PERCENT}", StringUtils.getPercent(pinvAmount + ecAmount, item.getAmount()));
lore.add(line);
}
meta.setLore(lore);
item.setItemMeta(meta);
}
gui.setToNextFree(new GuiItem(item));
}
gui.open(player);
}
Aggregations