use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class AxcPoints method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
PluginConfig config = Settings.getConfig();
if (args.length < 1) {
sender.sendMessage(messages.generalNoNickGiven);
return;
}
if (!UserUtils.playedBefore(args[0])) {
sender.sendMessage(messages.generalNotPlayedBefore);
return;
}
if (args.length < 2) {
sender.sendMessage(messages.adminNoPointsGiven);
return;
}
int points;
try {
points = Integer.valueOf(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
return;
}
User user = User.get(args[0]);
Rank userRank = user.getRank();
int change = points - userRank.getDeaths();
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new PointsChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, userRank, admin, change))) {
return;
}
user.getRank().setPoints(points);
RankManager.getInstance().update(user);
String message = messages.adminPointsChanged.replace("{PLAYER}", user.getName());
message = message.replace("{POINTS-FORMAT}", IntegerRange.inRange(points, config.pointsFormat));
message = message.replace("{POINTS}", String.valueOf(points));
sender.sendMessage(message);
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class AxcValidity method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
PluginConfig config = Settings.getConfig();
if (args.length < 1) {
sender.sendMessage(messages.generalNoTagGiven);
return;
} else if (args.length < 2) {
sender.sendMessage(messages.adminNoValidityTimeGiven);
return;
}
Guild guild = GuildUtils.getByTag(args[0]);
if (guild == null) {
sender.sendMessage(messages.generalNoGuildFound);
return;
}
if (guild.isBanned()) {
sender.sendMessage(messages.adminGuildBanned);
return;
}
long time = Parser.parseTime(args[1]);
if (time < 1) {
sender.sendMessage(messages.adminTimeError);
return;
}
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time))) {
return;
}
long validity = guild.getValidity();
if (validity == 0) {
validity = System.currentTimeMillis();
}
validity += time;
guild.setValidity(validity);
String date = config.dateFormat.format(new Date(validity));
sender.sendMessage(messages.adminNewValidity.replace("{GUILD}", guild.getName()).replace("{VALIDITY}", date));
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class BungeeTabListPlusHook method initVariableHook.
public static void initVariableHook() {
FunnyGuilds plugin = FunnyGuilds.getInstance();
PluginConfig config = Settings.getConfig();
MessagesConfig messages = Messages.getInstance();
// Guilds number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_guilds") {
@Override
public String getReplacement(Player player) {
return String.valueOf(GuildUtils.getGuilds().size());
}
});
// Users number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_users") {
@Override
public String getReplacement(Player player) {
return String.valueOf(UserUtils.getUsers().size());
}
});
// User deaths
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_deaths") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return String.valueOf(u.getRank().getDeaths());
}
});
// User KDR
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_kdr") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return String.format(Locale.US, "%.2f", u.getRank().getKDR());
}
});
// User kills
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_kills") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return String.valueOf(u.getRank().getKills());
}
});
// User points (formatted)
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_points-format") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return IntegerRange.inRange(u.getRank().getPoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(u.getRank().getPoints()));
}
});
// User points
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_points") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return String.valueOf(u.getRank().getPoints());
}
});
// User position
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_position") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
return String.valueOf(u.getRank().getPosition());
}
});
// Guild allies number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-allies") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getAllies().size());
}
});
// Guild deaths
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-deaths") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getRank().getDeaths());
}
});
// Guild deputies number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-deputies") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gDeputiesNoValue : (g.getDeputies().isEmpty() ? messages.gDeputiesNoValue : StringUtils.toString(UserUtils.getNames(g.getDeputies()), false));
}
});
// Guild deputy (random name)
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-deputy") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gDeputyNoValue : (g.getDeputies().isEmpty() ? messages.gDeputyNoValue : g.getDeputies().get(RandomUtils.RANDOM_INSTANCE.nextInt(g.getDeputies().size())).getName());
}
});
// Guild KDR
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-kdr") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0.00" : String.format(Locale.US, "%.2f", g.getRank().getKDR());
}
});
// Guild kills
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-kills") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getRank().getKills());
}
});
// Guild lives
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-lives") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getLives());
}
});
// Guild members number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-members-all") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getMembers().size());
}
});
// Guild online members number
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-members-online") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getOnlineMembers().size());
}
});
// Guild name
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-name") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gNameNoValue : g.getName();
}
});
// Guild owner name
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-owner") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gOwnerNoValue : g.getOwner().getName();
}
});
// Guild points (formatted)
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-points-format") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? IntegerRange.inRange(0, config.pointsFormat).replace("{POINTS}", "0") : IntegerRange.inRange(g.getRank().getPoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(g.getRank().getPoints()));
}
});
// Guild points
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-points") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getRank().getPoints());
}
});
// Guild position
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-position") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? "0" : String.valueOf(g.getRank().getPosition());
}
});
// Guild region size
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-region-size") {
@Override
public String getReplacement(Player player) {
if (!config.regionsEnabled) {
return messages.gRegionSizeNoValue;
}
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gRegionSizeNoValue : String.valueOf(g.getRegionData().getSize());
}
});
// Guild tag
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-tag") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gTagNoValue : g.getTag();
}
});
// Guild validity
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_g-validity") {
@Override
public String getReplacement(Player player) {
User u = User.get(player);
if (u == null) {
return "";
}
Guild g = u.getGuild();
return g == null ? messages.gValidityNoValue : config.dateFormat.format(g.getValidityDate());
}
});
// Guild TOP, positions 1-100
for (int i = 1; i <= 100; i++) {
final int index = i;
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_gtop-" + index) {
@Override
public String getReplacement(Player player) {
return Parser.parseRank("{GTOP-" + index + "}");
}
});
}
// User TOP, positions 1-100
for (int i = 1; i <= 100; i++) {
final int index = i;
BungeeTabListPlusBukkitAPI.registerVariable(plugin, new Variable("funnyguilds_ptop-" + index) {
@Override
public String getReplacement(Player player) {
return Parser.parseRank("{PTOP-" + index + "}");
}
});
}
FunnyLogger.info("BungeeTabListPlus hook has been enabled!");
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class PlayerDeath method getEloValues.
private int[] getEloValues(int vP, int aP) {
PluginConfig config = Settings.getConfig();
int[] rankChanges = new int[2];
int aC = IntegerRange.inRange(aP, config.eloConstants);
int vC = IntegerRange.inRange(vP, config.eloConstants);
rankChanges[0] = (int) Math.round(aC * (1 - (1.0D / (1.0D + Math.pow(config.eloExponent, (vP - aP) / config.eloDivider)))));
rankChanges[1] = (int) Math.round(vC * (0 - (1.0D / (1.0D + Math.pow(config.eloExponent, (aP - vP) / config.eloDivider)))) * -1);
return rankChanges;
}
use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.
the class PlayerDeath method onDeath.
@EventHandler
public void onDeath(PlayerDeathEvent event) {
Player v = event.getEntity();
Player a = event.getEntity().getKiller();
User victim = User.get(v);
victim.getRank().addDeath();
if (a == null) {
return;
}
User attacker = User.get(a);
if (victim.equals(attacker)) {
return;
}
if (PluginHook.isPresent(PluginHook.PLUGIN_WORLDGUARD)) {
if (WorldGuardHook.isOnNonPointsRegion(v.getLocation()) || WorldGuardHook.isOnNonPointsRegion(a.getLocation())) {
return;
}
}
PluginConfig config = Settings.getConfig();
MessagesConfig messages = Messages.getInstance();
if (config.rankFarmingProtect) {
if (attacker.getLastVictim() != null && attacker.getLastVictim().equals(victim)) {
if (attacker.getLastVictimTime() + (config.rankFarmingCooldown * 1000) >= System.currentTimeMillis()) {
v.sendMessage(messages.rankLastVictimV);
a.sendMessage(messages.rankLastVictimA);
event.setDeathMessage(null);
return;
}
} else if (victim.getLastAttacker() != null && victim.getLastAttacker().equals(attacker)) {
if (victim.getLastVictimTime() + (config.rankFarmingCooldown * 1000) >= System.currentTimeMillis()) {
v.sendMessage(messages.rankLastAttackerV);
a.sendMessage(messages.rankLastAttackerA);
event.setDeathMessage(null);
return;
}
}
}
if (config.rankIPProtect) {
if (a.getAddress().getHostString().equalsIgnoreCase(v.getAddress().getHostString())) {
v.sendMessage(messages.rankIPVictim);
a.sendMessage(messages.rankIPAttacker);
event.setDeathMessage(null);
return;
}
}
int[] rankChanges = new int[2];
int aP = attacker.getRank().getPoints();
int vP = victim.getRank().getPoints();
switch(config.rankSystem) {
case ELO:
rankChanges = getEloValues(vP, aP);
break;
case PERCENT:
Double d = victim.getRank().getPoints() * (config.percentRankChange / 100);
rankChanges[0] = d.intValue();
rankChanges[1] = d.intValue();
break;
case STATIC:
rankChanges[0] = config.staticAttackerChange;
rankChanges[1] = config.staticVictimChange;
break;
default:
rankChanges = getEloValues(vP, aP);
break;
}
RankChangeEvent attackerEvent = new PointsChangeEvent(EventCause.USER, attacker.getRank(), attacker, rankChanges[0]);
RankChangeEvent victimEvent = new PointsChangeEvent(EventCause.USER, victim.getRank(), attacker, rankChanges[1]);
List<String> assistEntries = new ArrayList<>();
if (SimpleEventHandler.handle(attackerEvent) && SimpleEventHandler.handle(victimEvent)) {
double attackerDamage = victim.killedBy(attacker);
if (config.assistEnable && victim.isAssisted()) {
double toShare = attackerEvent.getChange() * (1 - config.assistKillerShare);
double totalDamage = victim.getTotalDamage() + attackerDamage;
int givenPoints = 0;
Map<User, Double> damage = MapUtil.sortByValue(victim.getDamage());
int assists = 0;
for (Entry<User, Double> assist : damage.entrySet()) {
double assistFraction = assist.getValue() / totalDamage;
int addedPoints = (int) Math.round(assistFraction * toShare);
if (addedPoints <= 0) {
continue;
}
if (config.assistsLimit > 0) {
if (assists >= config.assistsLimit) {
continue;
}
assists++;
}
givenPoints += addedPoints;
String assistEntry = StringUtils.replace(messages.rankAssistEntry, "{PLAYER}", assist.getKey().getName());
assistEntry = StringUtils.replace(assistEntry, "{+}", Integer.toString(addedPoints));
assistEntry = StringUtils.replace(assistEntry, "{SHARE}", StringUtils.getPercent(assistFraction));
assistEntries.add(assistEntry);
assist.getKey().getRank().addPoints(addedPoints);
}
double attackerPoints = attackerEvent.getChange() - toShare + (givenPoints < toShare ? toShare - givenPoints : 0);
attackerEvent.setChange((int) Math.round(attackerPoints));
}
attacker.getRank().addKill();
attacker.getRank().addPoints(attackerEvent.getChange());
attacker.setLastVictim(victim);
victim.getRank().removePoints(victimEvent.getChange());
victim.setLastAttacker(attacker);
victim.clearDamage();
}
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
ConcurrencyTaskBuilder taskBuilder = ConcurrencyTask.builder();
if (config.dataType.mysql) {
if (victim.hasGuild()) {
// IndependentThread.actions(ActionType.MYSQL_UPDATE_GUILD_POINTS, victim.getGuild());
taskBuilder.delegate(new DatabaseUpdateGuildPointsRequest(victim.getGuild()));
}
if (attacker.hasGuild()) {
// IndependentThread.actions(ActionType.MYSQL_UPDATE_GUILD_POINTS, attacker.getGuild());
taskBuilder.delegate(new DatabaseUpdateGuildPointsRequest(attacker.getGuild()));
}
// IndependentThread.actions(ActionType.MYSQL_UPDATE_USER_POINTS, victim);
// IndependentThread.actions(ActionType.MYSQL_UPDATE_USER_POINTS, attacker);
taskBuilder.delegate(new DatabaseUpdateUserPointsRequest(victim));
taskBuilder.delegate(new DatabaseUpdateUserPointsRequest(attacker));
}
/*
IndependentThread.actions(ActionType.DUMMY_GLOBAL_UPDATE_USER, victim);
IndependentThread.actions(ActionType.DUMMY_GLOBAL_UPDATE_USER, attacker);
IndependentThread.actions(ActionType.RANK_UPDATE_USER, victim);
IndependentThread.action(ActionType.RANK_UPDATE_USER, attacker);
*/
ConcurrencyTask task = taskBuilder.delegate(new DummyGlobalUpdateUserRequest(victim)).delegate(new DummyGlobalUpdateUserRequest(attacker)).delegate(new RankUpdateUserRequest(victim)).delegate(new RankUpdateUserRequest(attacker)).build();
concurrencyManager.postTask(task);
String deathMessage = messages.rankDeathMessage;
deathMessage = StringUtils.replace(deathMessage, "{ATTACKER}", attacker.getName());
deathMessage = StringUtils.replace(deathMessage, "{VICTIM}", victim.getName());
deathMessage = StringUtils.replace(deathMessage, "{+}", Integer.toString(attackerEvent.getChange()));
deathMessage = StringUtils.replace(deathMessage, "{-}", Integer.toString(victimEvent.getChange()));
deathMessage = StringUtils.replace(deathMessage, "{POINTS-FORMAT}", IntegerRange.inRange(vP, config.pointsFormat));
deathMessage = StringUtils.replace(deathMessage, "{POINTS}", String.valueOf(victim.getRank().getPoints()));
deathMessage = StringUtils.replace(deathMessage, "{WEAPON}", MaterialUtil.getMaterialName(a.getItemInHand().getType()));
deathMessage = StringUtils.replace(deathMessage, "{REMAINING-HEALTH}", Double.toString(a.getHealth()));
deathMessage = StringUtils.replace(deathMessage, "{REMAINING-HEARTS}", Double.toString(a.getHealth() / 2));
if (victim.hasGuild()) {
deathMessage = StringUtils.replace(deathMessage, "{VTAG}", StringUtils.replace(config.chatGuild, "{TAG}", victim.getGuild().getTag()));
}
if (attacker.hasGuild()) {
deathMessage = StringUtils.replace(deathMessage, "{ATAG}", StringUtils.replace(config.chatGuild, "{TAG}", attacker.getGuild().getTag()));
}
deathMessage = StringUtils.replace(deathMessage, "{VTAG}", "");
deathMessage = StringUtils.replace(deathMessage, "{ATAG}", "");
event.setDeathMessage(deathMessage);
}
Aggregations