use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.
the class RankUtils method parseTop.
/**
* Parse top placeholders (PTOP/GTOP-type-x) in text
*
* @param targetUser user for which text will be parsed
* @param text text to parse
* @return parsed text
*/
public static String parseTop(PluginConfiguration config, TablistConfiguration tablistConfig, MessageConfiguration messages, UserRankManager userRankManager, GuildRankManager guildRankManager, User targetUser, String text) {
if (text == null) {
return null;
}
if (!text.contains("TOP-")) {
return text;
}
Matcher matcher = TOP_PATTERN.matcher(text);
if (matcher.find()) {
String topType = matcher.group(1);
String comparatorType = matcher.group(2);
String indexString = matcher.group(3);
int index;
try {
index = Integer.parseInt(indexString);
} catch (NumberFormatException ex) {
FunnyGuilds.getPluginLogger().error(indexString + "is invalid " + topType + " index!");
return text;
}
if (index < 1) {
FunnyGuilds.getPluginLogger().error("Index in " + topType + " must be greater or equal to 1!");
return text;
}
if (topType.equalsIgnoreCase("PTOP")) {
Option<UserTop> userTopOption = userRankManager.getTop(comparatorType);
if (userTopOption.isEmpty()) {
return StringUtils.replace(text, "{PTOP-" + comparatorType + "-" + index + "}", messages.ptopNoValue);
}
UserTop userTop = userTopOption.get();
Option<User> userOption = userTop.getUser(index);
if (userOption.isEmpty()) {
return StringUtils.replace(text, "{PTOP-" + comparatorType + "-" + index + "}", messages.ptopNoValue);
}
User user = userOption.get();
Number topValue = userTop.getComparator().getValue(user.getRank());
String topFormat = config.top.format.ptop.getValue();
if (!topFormat.isEmpty()) {
List<RangeFormatting> valueFormatting = config.top.format.ptopValueFormatting.get(comparatorType.toLowerCase());
topFormat = topFormat.replace("{VALUE-FORMAT}", valueFormatting == null ? topValue.toString() : NumberRange.inRangeToString(topValue, valueFormatting));
topFormat = topFormat.replace("{VALUE}", topValue.toString());
}
return formatUserRank(config, text, "{PTOP-" + comparatorType + "-" + index + "}", targetUser, user, topFormat);
} else if (topType.equalsIgnoreCase("GTOP")) {
Option<GuildTop> guildTopOption = guildRankManager.getTop(comparatorType);
if (guildTopOption.isEmpty()) {
return StringUtils.replace(text, "{GTOP-" + comparatorType + "-" + index + "}", messages.gtopNoValue);
}
GuildTop guildTop = guildTopOption.get();
Option<Guild> guildOption = guildTop.getGuild(index);
if (guildOption.isEmpty()) {
return StringUtils.replace(text, "{GTOP-" + comparatorType + "-" + index + "}", messages.gtopNoValue);
}
Guild guild = guildOption.get();
Number topValue = guildTop.getComparator().getValue(guild.getRank());
String topFormat = config.top.format.gtop.getValue();
List<RangeFormatting> valueFormatting = config.top.format.gtopValueFormatting.get(comparatorType.toLowerCase());
topFormat = topFormat.replace("{VALUE-FORMAT}", valueFormatting == null ? topValue.toString() : NumberRange.inRangeToString(topValue, valueFormatting));
topFormat = topFormat.replace("{VALUE}", topValue.toString());
return formatGuildRank(config, tablistConfig, text, "{GTOP-" + comparatorType + "-" + index + "}", targetUser, guild, topFormat);
}
}
return text;
}
use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.
the class HologramUpdateLocationHandler method run.
@Override
public void run() {
HologramConfiguration hologramConfig = config.heart.hologram;
if (!hologramConfig.enabled) {
return;
}
HookManager.HOLOGRAPHIC_DISPLAYS.peek(hologramManager -> {
Bukkit.getScheduler().runTask(plugin, () -> {
for (Guild guild : guildManager.getGuilds()) {
hologramManager.getCorrectedLocation(guild).peek(location -> hologramManager.getFunnyHologram(guild).peek(hologram -> hologram.setLocation(location)));
}
});
});
}
use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.
the class WarUtils method message.
public static void message(Player player, int i, Object... values) {
MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
String message = null;
switch(i) {
case 0:
message = messages.warHasNotGuild;
break;
case 1:
message = messages.warAlly;
break;
case 2:
message = messages.warWait;
message = StringUtils.replace(message, "{TIME}", TimeUtils.getDurationBreakdown((long) values[0]));
break;
case 3:
message = messages.warAttacker;
message = StringUtils.replace(message, "{ATTACKED}", ((Guild) values[0]).getTag());
break;
case 4:
message = messages.warAttacked;
message = StringUtils.replace(message, "{ATTACKER}", ((Guild) values[0]).getTag());
break;
case 5:
message = messages.warDisabled;
break;
default:
throw new IllegalArgumentException("Unknown magic number " + i);
}
ChatUtils.sendMessage(player, message);
}
use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.
the class PvPCommand method execute.
@FunnyCommand(name = "${user.pvp.name}", description = "${user.pvp.description}", aliases = "${user.pvp.aliases}", permission = "funnyguilds.pvp", acceptsExceeded = true, playerOnly = true)
public void execute(Player player, @CanManage User user, Guild guild, String[] args) {
if (args.length > 0) {
when(!config.damageAlly, messages.generalAllyPvpDisabled);
Guild targetAlliedGuild = GuildValidation.requireGuildByTag(args[0]);
Formatter guildTagFormatter = new Formatter().register("{TAG}", targetAlliedGuild.getTag());
when(!guild.getAllies().contains(targetAlliedGuild), guildTagFormatter.format(messages.allyDoesntExist));
guild.setPvP(targetAlliedGuild, !guild.getPvP(targetAlliedGuild));
user.sendMessage(guildTagFormatter.format(guild.getPvP(targetAlliedGuild) ? messages.pvpAllyOn : messages.pvpAllyOff));
return;
}
guild.setPvP(!guild.getPvP());
user.sendMessage(guild.getPvP() ? messages.pvpOn : messages.pvpOff);
}
use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.
the class EntityInteract method onInteract.
@EventHandler
public void onInteract(PlayerInteractEntityEvent event) {
Player eventCaller = event.getPlayer();
Entity clickedEntity = event.getRightClicked();
if (clickedEntity instanceof Player) {
Player clickedPlayer = (Player) clickedEntity;
if (!config.infoPlayerEnabled || (config.infoPlayerSneaking && !eventCaller.isSneaking()) || informationMessageCooldowns.cooldown(eventCaller, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
return;
}
if (config.infoPlayerCommand) {
try {
playerExecutor.execute(eventCaller, new String[] { clickedPlayer.getName() });
} catch (ValidationException validatorException) {
validatorException.getValidationMessage().peek(message -> ChatUtils.sendMessage(eventCaller, message));
}
} else {
this.userManager.findByPlayer(clickedPlayer).peek(user -> playerExecutor.sendInfoMessage(messages.playerRightClickInfo, user, eventCaller));
}
}
if (config.regionExplodeBlockInteractions && clickedEntity instanceof InventoryHolder) {
this.userManager.findByPlayer(eventCaller).filter(user -> user.getGuild().map(Guild::canBuild).isEmpty()).peek(user -> event.setCancelled(true));
}
}
Aggregations