diff --git a/pom.xml b/pom.xml index b4b23806..145f1540 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 me.roinujnosde TitansBattle - 3.0.3 + 3.0.4 jar UTF-8 diff --git a/src/main/java/me/roinujnosde/titansbattle/Helper.java b/src/main/java/me/roinujnosde/titansbattle/Helper.java index 66fdaff5..5de383d5 100644 --- a/src/main/java/me/roinujnosde/titansbattle/Helper.java +++ b/src/main/java/me/roinujnosde/titansbattle/Helper.java @@ -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; } diff --git a/src/main/java/me/roinujnosde/titansbattle/listeners/CreateFactionListener.java b/src/main/java/me/roinujnosde/titansbattle/listeners/CreateFactionListener.java index 0866a4d4..a54a4e09 100644 --- a/src/main/java/me/roinujnosde/titansbattle/listeners/CreateFactionListener.java +++ b/src/main/java/me/roinujnosde/titansbattle/listeners/CreateFactionListener.java @@ -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; @@ -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())); + }); } } diff --git a/src/main/java/me/roinujnosde/titansbattle/listeners/EntityDamageListener.java b/src/main/java/me/roinujnosde/titansbattle/listeners/EntityDamageListener.java index 6a7ba928..f551ff71 100644 --- a/src/main/java/me/roinujnosde/titansbattle/listeners/EntityDamageListener.java +++ b/src/main/java/me/roinujnosde/titansbattle/listeners/EntityDamageListener.java @@ -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; @@ -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()) { @@ -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; } diff --git a/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java b/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java index 9103a650..894ab732 100644 --- a/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java +++ b/src/main/java/me/roinujnosde/titansbattle/managers/DatabaseManager.java @@ -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; @@ -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; @@ -84,7 +76,7 @@ private enum CountType { } private enum WinnerType { - KILLER, WINNER_GROUP, PLAYER_WINNER; + KILLER, WINNER_GROUP, PLAYER_WINNER } public void load() { @@ -487,7 +479,7 @@ private void loopThroughWinners() { Map>> 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) { @@ -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() { diff --git a/src/main/java/me/roinujnosde/titansbattle/managers/GameManager.java b/src/main/java/me/roinujnosde/titansbattle/managers/GameManager.java index e5e93248..8a56a9f3 100644 --- a/src/main/java/me/roinujnosde/titansbattle/managers/GameManager.java +++ b/src/main/java/me/roinujnosde/titansbattle/managers/GameManager.java @@ -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) {