use of net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest in project FunnyGuilds by FunnyGuilds.
the class User method removeGuild.
public void removeGuild() {
this.guild = null;
this.changes();
// IndependentThread.action(ActionType.RANK_UPDATE_USER, this);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new RankUpdateUserRequest(this));
}
use of net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest 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);
}
use of net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest in project FunnyGuilds by FunnyGuilds.
the class PlayerJoin method onJoin.
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
User user = User.get(player);
PluginConfig config = Settings.getConfig();
if (config.playerlistEnable && !AbstractTablist.hasTablist(player)) {
AbstractTablist.createTablist(config.playerList, config.playerListHeader, config.playerListFooter, config.playerListPing, player);
}
user.getScoreboard();
/*
IndependentThread.actions(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
IndependentThread.actions(ActionType.DUMMY_GLOBAL_UPDATE_USER, user);
IndependentThread.actions(ActionType.RANK_UPDATE_USER, user);
*/
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player), new DummyGlobalUpdateUserRequest(user), new RankUpdateUserRequest(user));
this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
PacketExtension.registerPlayer(player);
Version.isNewAvailable(player, false);
Region region = RegionUtils.getAt(player.getLocation());
if (region == null || region.getGuild() == null) {
return;
}
if (config.createEntityType != null) {
EntityUtil.spawn(region.getGuild(), player);
}
}, 30L);
}
Aggregations