Skip to content

Commit

Permalink
FactionsCreate and FF fixed
Browse files Browse the repository at this point in the history
Fixed error on FactionsCreate
Fixed friendly fire still active on group modes
  • Loading branch information
RoinujNosde committed Jul 25, 2020
1 parent c58ecc4 commit 7515863
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.roinujnosde</groupId>
<artifactId>TitansBattle</artifactId>
<version>3.0.3</version>
<version>3.0.4</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/me/roinujnosde/titansbattle/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,11 @@ public boolean areInSameGroup(@NotNull UUID player1, @NotNull UUID player2) {
Clan clan1 = plugin.getClanManager().getClanPlayer(player1).getClan();
return clan1.isMember(player2);
}

if (plugin.isFactions()) {
Faction faction1 = MPlayer.get(player1).getFaction();
Faction faction2 = MPlayer.get(player2).getFaction();
return faction1.equals(faction2);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.roinujnosde.titansbattle.utils.Groups;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

Expand All @@ -16,8 +17,12 @@ public CreateFactionListener(@NotNull TitansBattle plugin) {
this.plugin = plugin;
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCreate(EventFactionsCreate event) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> Groups.getGroup(event.getMPlayer().getUuid()));
//Running later so that the factions gets created
Bukkit.getScheduler().runTask(plugin, () -> {
//Loading into memory
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> Groups.getGroup(event.getMPlayer().getUuid()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.roinujnosde.titansbattle.Helper;
import me.roinujnosde.titansbattle.TitansBattle;
import me.roinujnosde.titansbattle.managers.GameManager;
import me.roinujnosde.titansbattle.types.Game;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -26,6 +27,12 @@ public void onDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}

Game currentGame = gm.getCurrentGame();
if (currentGame == null) {
return;
}

Player defender = (Player) event.getEntity();
if (gm.getParticipants().contains(defender.getUniqueId())) {
if (!gm.isBattle()) {
Expand All @@ -38,7 +45,8 @@ public void onDamage(EntityDamageEvent event) {
if (attacker == null || !gm.getParticipants().contains(attacker.getUniqueId())) {
return;
}
if (helper.isFun(gm.getCurrentGame())) {
Game.Mode mode = currentGame.getMode();
if (mode.equals(Game.Mode.FREEFORALL_FUN) || mode.equals(Game.Mode.FREEFORALL_REAL)) {
event.setCancelled(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.function.Consumer;

import me.roinujnosde.titansbattle.Helper;
import me.roinujnosde.titansbattle.TitansBattle;
import me.roinujnosde.titansbattle.types.Game.Mode;
Expand All @@ -54,7 +47,6 @@
import me.roinujnosde.titansbattle.types.Winners;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -84,7 +76,7 @@ private enum CountType {
}

private enum WinnerType {
KILLER, WINNER_GROUP, PLAYER_WINNER;
KILLER, WINNER_GROUP, PLAYER_WINNER
}

public void load() {
Expand Down Expand Up @@ -487,7 +479,7 @@ private void loopThroughWinners() {
Map<Date, Map<WinnerType, Map<Mode, Object>>> winnersData = new HashMap<>();

while (rs.next()) {
Date date = null;
Date date;
try {
date = new SimpleDateFormat("dd/MM/yyyy").parse(rs.getString("date"));
} catch (ParseException ex) {
Expand Down Expand Up @@ -562,7 +554,7 @@ private void loopThroughWinners() {
}

private void sortWinners() {
winners.sort((w, w2) -> w.getDate().compareTo(w2.getDate()));
winners.sort(Comparator.comparing(Winners::getDate));
}

public void loadDataToMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private void processGroupMemberLeaving(@NotNull Game game, @NotNull Player playe
plugin.debug(String.format("Player %s is not in a group", player.getName()), false);
return;
}
int members = groups.get(group);
int members = groups.getOrDefault(group, 0);
groups.replace(group, --members);

if (members < 1) {
Expand Down

0 comments on commit 7515863

Please sign in to comment.