getLosers() {
- return losers;
- }
-}
-
-
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java
new file mode 100644
index 000000000..c514e7c2c
--- /dev/null
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndPhaseMinigameEvent.java
@@ -0,0 +1,37 @@
+package au.com.mineauz.minigames.events;
+
+import au.com.mineauz.minigames.minigame.Minigame;
+import au.com.mineauz.minigames.objects.MinigamePlayer;
+
+import java.util.List;
+
+/**
+ * This event is called whenever a minigame enters it's endphase.
+ * This happens amongst others if a team wins or a finished sign was used.
+ * However, this is NOT a guaranteed indicator that a minigame is about to end.
+ * While the Endphase will lead to the end of a minigame, this event will NOT be called if certain circumstances happen,
+ * like if the /mg quit command was called.
+ *
+ * if you need an event for cleanup use {@link EndedMinigameEvent}
+ */
+public class EndPhaseMinigameEvent extends AbstractCancellableMinigameEvent {
+ private final List winners;
+ private final List losers;
+
+
+ public EndPhaseMinigameEvent(List winners, List losers, Minigame minigame) {
+ super(minigame);
+ this.winners = winners;
+ this.losers = losers;
+ }
+
+ public List getWinners() {
+ return winners;
+ }
+
+ public List getLosers() {
+ return losers;
+ }
+}
+
+
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java
new file mode 100644
index 000000000..6cf1254fe
--- /dev/null
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/EndedMinigameEvent.java
@@ -0,0 +1,12 @@
+package au.com.mineauz.minigames.events;
+
+import au.com.mineauz.minigames.minigame.Minigame;
+
+/**
+ * this event indicates the minigame has definitely ended now and is in the process of clearing up
+ */
+public class EndedMinigameEvent extends AbstractMinigameEvent {
+ public EndedMinigameEvent(Minigame minigame) {
+ super(minigame);
+ }
+}
\ No newline at end of file
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java
index 6cd341071..f8e56a225 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/FlagCaptureEvent.java
@@ -4,7 +4,7 @@
import au.com.mineauz.minigames.objects.CTFFlag;
import au.com.mineauz.minigames.objects.MinigamePlayer;
-public class FlagCaptureEvent extends AbstractMinigameEvent {
+public class FlagCaptureEvent extends AbstractCancellableMinigameEvent {
private final MinigamePlayer player;
private final CTFFlag flag;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java
index 84b71eb4b..7da259c51 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/JoinMinigameEvent.java
@@ -4,7 +4,7 @@
import au.com.mineauz.minigames.objects.MinigamePlayer;
import org.bukkit.entity.Player;
-public class JoinMinigameEvent extends AbstractMinigameEvent {
+public class JoinMinigameEvent extends AbstractCancellableMinigameEvent {
private final MinigamePlayer player;
private final boolean betting;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java
index 50d8bcae7..e02e430a1 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigameTimerTickEvent.java
@@ -3,7 +3,7 @@
import au.com.mineauz.minigames.MinigameTimer;
import au.com.mineauz.minigames.minigame.Minigame;
-public class MinigameTimerTickEvent extends AbstractMinigameEvent {
+public class MinigameTimerTickEvent extends AbstractCancellableMinigameEvent {
private final MinigameTimer timer;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java
index c5195e2e9..1f38b7473 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/MinigamesBroadcastEvent.java
@@ -2,7 +2,7 @@
import au.com.mineauz.minigames.minigame.Minigame;
-public class MinigamesBroadcastEvent extends AbstractMinigameEvent {
+public class MinigamesBroadcastEvent extends AbstractCancellableMinigameEvent {
private String message;
private final String prefix;
private boolean cancelled = false;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java
index 48f9a9c6d..c87c42756 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/QuitMinigameEvent.java
@@ -4,7 +4,7 @@
import au.com.mineauz.minigames.objects.MinigamePlayer;
import org.bukkit.entity.Player;
-public class QuitMinigameEvent extends AbstractMinigameEvent {
+public class QuitMinigameEvent extends AbstractCancellableMinigameEvent {
private final MinigamePlayer player;
private final boolean isForced;
private final boolean isWinner;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java
index a0c3424b3..75ae902ea 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/RevertCheckpointEvent.java
@@ -3,7 +3,7 @@
import au.com.mineauz.minigames.objects.MinigamePlayer;
import org.bukkit.entity.Player;
-public class RevertCheckpointEvent extends AbstractMinigameEvent {
+public class RevertCheckpointEvent extends AbstractCancellableMinigameEvent {
private final MinigamePlayer player;
public RevertCheckpointEvent(MinigamePlayer player) {
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java
index 691fcecdb..0d6f08245 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/SpectateMinigameEvent.java
@@ -4,7 +4,7 @@
import au.com.mineauz.minigames.objects.MinigamePlayer;
import org.bukkit.entity.Player;
-public class SpectateMinigameEvent extends AbstractMinigameEvent {
+public class SpectateMinigameEvent extends AbstractCancellableMinigameEvent {
private final MinigamePlayer player;
public SpectateMinigameEvent(MinigamePlayer player, Minigame minigame) {
@@ -19,6 +19,4 @@ public MinigamePlayer getMinigamePlayer() {
public Player getPlayer() {
return player.getPlayer();
}
-
-
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java
index 78c5f9d77..23f39f261 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartGlobalMinigameEvent.java
@@ -3,7 +3,7 @@
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.objects.MinigamePlayer;
-public class StartGlobalMinigameEvent extends AbstractMinigameEvent {
+public class StartGlobalMinigameEvent extends AbstractCancellableMinigameEvent {
private final String mechanic;
private final MinigamePlayer caller;
@@ -14,7 +14,6 @@ public StartGlobalMinigameEvent(Minigame mgm, MinigamePlayer caller) {
this.caller = caller;
}
-
public String getMechanic() {
return mechanic;
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java
index aaebcca6d..7b6dbd641 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StartMinigameEvent.java
@@ -9,7 +9,7 @@
/**
* You cannot cancel this event
*/
-public class StartMinigameEvent extends AbstractMinigameEvent {
+public class StartMinigameEvent extends AbstractCancellableMinigameEvent {
private final boolean willTeleport;
private final List players;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java
index 5ecf6f97b..0ffb47ff0 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/StopGlobalMinigameEvent.java
@@ -3,7 +3,7 @@
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.objects.MinigamePlayer;
-public class StopGlobalMinigameEvent extends AbstractMinigameEvent {
+public class StopGlobalMinigameEvent extends AbstractCancellableMinigameEvent {
private final String mechanic;
private final MinigamePlayer caller;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java
index 9eefee23c..84342ebac 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/TakeFlagEvent.java
@@ -4,7 +4,7 @@
import au.com.mineauz.minigames.objects.CTFFlag;
import au.com.mineauz.minigames.objects.MinigamePlayer;
-public class TakeFlagEvent extends AbstractMinigameEvent {
+public class TakeFlagEvent extends AbstractCancellableMinigameEvent {
private final CTFFlag flag;
private final String flagName;
private boolean displayMessage = true;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java b/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java
index 94f37ed9b..c489467ab 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/events/TimerExpireEvent.java
@@ -3,9 +3,7 @@
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.minigame.MinigameState;
-public class TimerExpireEvent extends AbstractMinigameEvent {
-
-
+public class TimerExpireEvent extends AbstractCancellableMinigameEvent {
public TimerExpireEvent(Minigame minigame) {
super(minigame);
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java
index 8062d50ab..856495e2e 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MinigameTypeBase.java
@@ -45,12 +45,12 @@ public void setType(MinigameType type) {
public void callGeneralQuit(MinigamePlayer player, Minigame minigame) {
if (!player.getPlayer().isDead()) {
- if (player.getPlayer().getWorld() != minigame.getQuitPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.quit") && plugin.getConfig().getBoolean("warnings")) {
+ if (player.getPlayer().getWorld() != minigame.getQuitLocation().getWorld() && player.getPlayer().hasPermission("minigame.set.quit") && plugin.getConfig().getBoolean("warnings")) {
player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Quit location is across worlds! This may cause some server performance issues!", MinigameMessageType.ERROR);
}
- player.teleport(minigame.getQuitPosition());
+ player.teleport(minigame.getQuitLocation());
} else {
- player.setQuitPos(minigame.getQuitPosition());
+ player.setQuitPos(minigame.getQuitLocation());
player.setRequiredQuit(true);
}
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java
index a1e425eba..de830740f 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/MultiplayerType.java
@@ -47,7 +47,7 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) {
boolean cannotStart;
cannotStart = mgm.getPlayers().size() >= mgm.getMaxPlayers();
if (cannotStart) message = MinigameUtils.getLang("minigame.full");
- cannotStart = mgm.getLobbyPosition() == null;
+ cannotStart = mgm.getLobbyLocation() == null;
if (cannotStart) message = MinigameUtils.getLang("minigame.error.noLobby");
if (cannotStart) player.sendMessage(message, MinigameMessageType.ERROR);
return cannotStart;
@@ -55,7 +55,7 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) {
@Override
public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) {
- Location location = mgm.getLobbyPosition();
+ Location location = mgm.getLobbyLocation();
boolean result = false;
if (location == null) {
plugin.getLogger().warning("Game has no lobby set and it was expected:" + mgm.getName(true));
@@ -151,7 +151,7 @@ public void quitMinigame(MinigamePlayer player, Minigame mgm, boolean forced) {
if (mgm.isTeamGame()) {
player.removeTeam();
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
- if (t.getPlayers().size() > 0)
+ if (!t.getPlayers().isEmpty())
teamsWithPlayers++;
}
@@ -179,7 +179,7 @@ public void quitMinigame(MinigamePlayer player, Minigame mgm, boolean forced) {
if (TeamsModule.getMinigameModule(mgm).getTeams().size() != 1) {
Team winner = null;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
- if (t.getPlayers().size() > 0) {
+ if (!t.getPlayers().isEmpty()) {
winner = t;
break;
}
@@ -262,7 +262,7 @@ public void playerRespawn(PlayerRespawnEvent event) {
}
ply.getLoadout().equiptLoadout(ply);
} else {
- respawnPos = mg.getLobbyPosition();
+ respawnPos = mg.getLobbyLocation();
}
} else {
if (mg.hasStarted() && !ply.isLatejoining()) {
@@ -276,7 +276,7 @@ public void playerRespawn(PlayerRespawnEvent event) {
ply.getLoadout().equiptLoadout(ply);
} else {
- respawnPos = mg.getLobbyPosition();
+ respawnPos = mg.getLobbyLocation();
}
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java
index 26fc94834..662cd4be2 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/gametypes/SingleplayerType.java
@@ -14,6 +14,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerRespawnEvent;
+import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Calendar;
@@ -39,6 +40,11 @@ public boolean cannotStart(Minigame mgm, MinigamePlayer player) {
@Override
public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) {
List locs = new ArrayList<>(mgm.getStartLocations());
+
+ if (locs.isEmpty()) {
+ return false;
+ }
+
Collections.shuffle(locs);
boolean result = player.teleport(locs.get(0));
if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() &&
@@ -51,8 +57,7 @@ public boolean teleportOnJoin(MinigamePlayer player, Minigame mgm) {
@Override
public boolean joinMinigame(MinigamePlayer player, Minigame mgm) {
-
- if (mgm.getLives() > 0 && !Float.isFinite(mgm.getLives())) {
+ if (mgm.getLives() > 0 && Math.abs(mgm.getLives()) < Integer.MAX_VALUE) {
player.sendInfoMessage(MessageManager.getMinigamesMessage("minigame.livesLeft", mgm.getLives()));
}
if (!mgm.isAllowedFlight()) {
@@ -117,7 +122,7 @@ public void endMinigame(List winners, List loser
}
@Override
- public void quitMinigame(final MinigamePlayer player, final Minigame mgm, boolean forced) {
+ public void quitMinigame(final @NotNull MinigamePlayer player, final @NotNull Minigame mgm, boolean forced) {
if (mgm.canSaveCheckpoint()) {
StoredPlayerCheckpoints spc = player.getStoredPlayerCheckpoints();
spc.addCheckpoint(mgm.getName(false), player.getCheckpoint());
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java
index b2c6e2ba3..c0f92ea01 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MessageManager.java
@@ -32,27 +32,27 @@ public class MessageManager {
* Stores each prop file with an identifier
*/
private static final Hashtable propertiesHashMap = new Hashtable<>();
- private static Locale locale = Locale.getDefault();
private static Logger logger = null;
- public static void setLocale(Locale locale) {
- MessageManager.locale = locale;
- }
-
public static void setLogger(Logger logger) {
MessageManager.logger = logger;
}
public static void registerCoreLanguage() {
String tag = Minigames.getPlugin().getConfig().getString("lang", Locale.getDefault().toLanguageTag());
- locale = Locale.forLanguageTag(tag);
+ Locale locale = Locale.forLanguageTag(tag.replace("_", "-"));
+
+ // fall back if locale is undefined
+ if (locale.getLanguage().isEmpty()) {
+ locale = Locale.getDefault();
+ }
+
Minigames.log().info("MessageManager set locale for language:" + locale.toLanguageTag());
File file = new File(new File(Minigames.getPlugin().getDataFolder(), "lang"), "minigames.properties");
- registerCoreLanguage(file, Locale.getDefault());
+ registerCoreLanguage(file, locale);
}
public static void registerCoreLanguage(File file, Locale locale) {
- MessageManager.setLocale(locale);
ResourceBundle minigames = null;
if (file.exists()) {
try {
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java
index 1987defa8..3ca9da771 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameManager.java
@@ -4,7 +4,6 @@
import au.com.mineauz.minigames.MinigameUtils;
import au.com.mineauz.minigames.Minigames;
import au.com.mineauz.minigames.PlayerLoadout;
-import au.com.mineauz.minigames.blockRecorder.RecorderData;
import au.com.mineauz.minigames.config.MinigameSave;
import au.com.mineauz.minigames.config.RewardsFlag;
import au.com.mineauz.minigames.events.StartGlobalMinigameEvent;
@@ -19,11 +18,13 @@
import au.com.mineauz.minigames.objects.MgRegion;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import au.com.mineauz.minigames.objects.ResourcePack;
+import au.com.mineauz.minigames.recorder.RecorderData;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -136,10 +137,9 @@ public void addMinigame(final Minigame game) {
if (Minigames.getPlugin().includesPapi()) {
Minigames.getPlugin().getPlaceHolderManager().addGameIdentifiers(game);
}
-
}
- public Minigame getMinigame(final String minigame) {
+ public @Nullable Minigame getMinigame(final String minigame) {
if (this.minigames.containsKey(minigame)) {
return this.minigames.get(minigame);
}
@@ -230,7 +230,6 @@ public Set getMinigameTypes() {
return this.minigameTypes.keySet();
}
-
public void addLoadout(final String name) {
this.globalLoadouts.put(name, new PlayerLoadout(name));
}
@@ -315,11 +314,11 @@ private void sendBroadcastMessage(Minigame minigame, String message, MinigameMes
type = MinigameMessageType.INFO;
}
finalMessage += message;
- final List sendto = new ArrayList<>();
+ final Set sendto = new HashSet<>();
sendto.addAll(minigame.getPlayers());
sendto.addAll(minigame.getSpectators());
if (exclude != null) {
- sendto.removeAll(exclude);
+ exclude.forEach(sendto::remove);
}
for (final MinigamePlayer pl : sendto) {
pl.sendMessage(finalMessage, type);
@@ -445,10 +444,10 @@ public boolean minigameStartStateCheck(final Minigame minigame, final MinigamePl
}
public boolean minigameStartSetupCheck(final Minigame minigame, final MinigamePlayer player) {
- if (minigame.getEndPosition() == null) {
+ if (minigame.getEndLocation() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), MinigameMessageType.ERROR);
return false;
- } else if (minigame.getQuitPosition() == null) {
+ } else if (minigame.getQuitLocation() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), MinigameMessageType.ERROR);
return false;
} else if (minigame.getType() == null || this.minigameType(minigame.getType()).cannotStart(minigame, player)) { //type specific reasons we cannot start.
@@ -467,7 +466,7 @@ public boolean minigameStartSetupCheck(final Minigame minigame, final MinigamePl
public boolean teleportPlayerOnJoin(@NotNull final Minigame minigame, final MinigamePlayer player) {
if (this.minigameType(minigame.getType()) == null) {
- Minigames.log().warning(MessageManager.getMinigamesMessage("error.invalidType") + " : " + minigame.getName(true));
+ Minigames.log().warning(MessageManager.getMinigamesMessage("minigame.error.invalidType") + " : " + minigame.getName(true));
}
return this.minigameType(minigame.getType()).teleportOnJoin(player, minigame);
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java
index 8959238de..2d46cb01d 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigamePlayerManager.java
@@ -4,7 +4,6 @@
import au.com.mineauz.minigames.MinigameUtils;
import au.com.mineauz.minigames.Minigames;
import au.com.mineauz.minigames.MultiplayerBets;
-import au.com.mineauz.minigames.blockRecorder.RegenRecorder;
import au.com.mineauz.minigames.events.*;
import au.com.mineauz.minigames.gametypes.MinigameType;
import au.com.mineauz.minigames.mechanics.GameMechanicBase;
@@ -15,6 +14,7 @@
import au.com.mineauz.minigames.minigame.modules.*;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import au.com.mineauz.minigames.objects.ResourcePack;
+import au.com.mineauz.minigames.recorder.RegenRecorder;
import au.com.mineauz.minigames.sounds.MGSounds;
import au.com.mineauz.minigames.sounds.PlayMGSound;
import au.com.mineauz.minigames.stats.DynamicMinigameStat;
@@ -34,6 +34,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -256,7 +257,9 @@ public void spectateMinigame(MinigamePlayer player, Minigame minigame) {
pl.getPlayer().hidePlayer(plugin, player.getPlayer());
}
- player.getPlayer().setScoreboard(minigame.getScoreboardManager());
+ if (minigame.canDisplayScoreboard()) {
+ player.getPlayer().setScoreboard(minigame.getScoreboardManager());
+ }
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
@@ -445,7 +448,6 @@ public void getStartLocations(List players, Minigame game) {
}
public void revertToCheckpoint(MinigamePlayer player) {
-
RevertCheckpointEvent event = new RevertCheckpointEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
@@ -469,7 +471,7 @@ public void revertToCheckpoint(MinigamePlayer player) {
}
}
- public void quitMinigame(MinigamePlayer player, boolean forced) {
+ public void quitMinigame(@NotNull MinigamePlayer player, boolean forced) {
Minigame minigame = player.getMinigame();
boolean isWinner = GameOverModule.getMinigameModule(minigame).getWinners().contains(player);
@@ -477,7 +479,48 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
QuitMinigameEvent event = new QuitMinigameEvent(player, minigame, forced, isWinner);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
- if (!minigame.isSpectator(player)) {
+ if (minigame.isSpectator(player)) {
+ if (player.getPlayer().getVehicle() != null) {
+ Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
+ vehicle.eject();
+ }
+ player.getPlayer().setFallDistance(0);
+ player.getPlayer().setNoDamageTicks(60);
+ final Player fplayer = player.getPlayer();
+ for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
+ player.getPlayer().removePotionEffect(potion.getType());
+ }
+ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> fplayer.setFireTicks(0));
+
+ player.getPlayer().closeInventory();
+ if (player.isLiving()) {
+ player.restorePlayerData();
+ }
+
+ Location loc;
+ if (minigame.getEndLocation() != null) {
+ loc = minigame.getEndLocation();
+ } else {
+ loc = minigame.getQuitLocation();
+ }
+
+ if (loc != null) {
+ player.teleport(loc);
+ } else {
+ Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end location set! (Player: " + player.getName() + ")");
+ }
+
+ player.setStartPos(null);
+ player.removeMinigame();
+ minigame.removeSpectator(player);
+
+ for (MinigamePlayer pl : minigame.getPlayers()) {
+ pl.getPlayer().showPlayer(plugin, player.getPlayer());
+ }
+
+ player.sendMessage(MessageManager.getMinigamesMessage("player.spectate.quit.plyMsg", minigame.getName(true)), MinigameMessageType.ERROR);
+ mgManager.sendMinigameMessage(minigame, MessageManager.getMinigamesMessage("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), MinigameMessageType.ERROR, player);
+ } else {
if (player.getEndTime() == 0)
player.setEndTime(System.currentTimeMillis());
@@ -488,8 +531,9 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
player.setCompleteTime(player.getEndTime() - player.getStartTime() + player.getStoredTime());
}
- } else
+ } else {
GameOverModule.getMinigameModule(minigame).getLosers().remove(player);
+ }
if (!isWinner) {
if (!minigame.canSaveCheckpoint() && minigame.isEnabled()) {
@@ -539,28 +583,29 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
player.restorePlayerData();
Location loc;
if (!isWinner) {
- if (minigame.getQuitPosition() != null) {
- loc = minigame.getQuitPosition();
+ if (minigame.getQuitLocation() != null) {
+ loc = minigame.getQuitLocation();
} else {
- loc = minigame.getEndPosition();
+ loc = minigame.getEndLocation();
}
} else {
- if (minigame.getEndPosition() != null) {
- loc = minigame.getEndPosition();
+ if (minigame.getEndLocation() != null) {
+ loc = minigame.getEndLocation();
} else {
- loc = minigame.getQuitPosition();
+ loc = minigame.getQuitLocation();
}
}
if (loc != null) {
player.teleport(loc);
} else {
- Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end position set! (Player: " + player.getName() + ")");
+ Minigames.log.warning("Minigame " + minigame.getName(true) + " has no end location set! (Player: " + player.getName() + ")");
}
} else {
- if (!isWinner)
- player.setQuitPos(minigame.getQuitPosition());
- else
- player.setQuitPos(minigame.getEndPosition());
+ if (!isWinner) {
+ player.setQuitPos(minigame.getQuitLocation());
+ } else {
+ player.setQuitPos(minigame.getEndLocation());
+ }
player.setRequiredQuit(true);
}
player.setStartPos(null);
@@ -572,7 +617,10 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
player.claimRewards();
//Reset Minigame
- if (minigame.getPlayers().size() == 0) {
+ if (minigame.getPlayers().isEmpty()) {
+ //call event about this minigame has come to an end (and therefor is past an optional end phase)
+ Bukkit.getServer().getPluginManager().callEvent(new EndedMinigameEvent(minigame));
+
if (minigame.getMinigameTimer() != null) {
minigame.getMinigameTimer().stopTimer();
minigame.setMinigameTimer(null);
@@ -602,15 +650,17 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
}
mgManager.clearClaimedScore(minigame);
+
WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(minigame);
if (mod != null) {
mod.stopTimeLoop();
}
+
GameOverModule.getMinigameModule(minigame).stopEndGameTimer();
+
for (Team team : TeamsModule.getMinigameModule(minigame).getTeams()) {
team.setScore(0);
}
-
}
minigame.getScoreboardManager().resetScores(player.getName());
@@ -629,34 +679,6 @@ public void quitMinigame(MinigamePlayer player, boolean forced) {
}
plugin.getLogger().info(player.getName() + " quit " + minigame);
player.updateInventory();
- } else {
- if (player.getPlayer().getVehicle() != null) {
- Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
- vehicle.eject();
- }
- player.getPlayer().setFallDistance(0);
- player.getPlayer().setNoDamageTicks(60);
- final Player fplayer = player.getPlayer();
- for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
- player.getPlayer().removePotionEffect(potion.getType());
- }
- Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> fplayer.setFireTicks(0));
-
- player.getPlayer().closeInventory();
- if (player.isLiving()) {
- player.restorePlayerData();
- }
- player.teleport(minigame.getQuitPosition());
- player.setStartPos(null);
- player.removeMinigame();
- minigame.removeSpectator(player);
-
- for (MinigamePlayer pl : minigame.getPlayers()) {
- pl.getPlayer().showPlayer(plugin, player.getPlayer());
- }
-
- player.sendMessage(MessageManager.getMinigamesMessage("player.spectate.quit.plyMsg", minigame.getName(true)), MinigameMessageType.ERROR);
- mgManager.sendMinigameMessage(minigame, MessageManager.getMinigamesMessage("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), MinigameMessageType.ERROR, player);
}
if (ResourcePackModule.getMinigameModule(minigame).isEnabled()) {
if (player.applyResourcePack(plugin.getResourceManager().getResourcePack("empty"))) {
@@ -681,11 +703,10 @@ public void endMinigame(MinigamePlayer player) {
endMinigame(player.getMinigame(), w, l);
}
-
public void endMinigame(Minigame minigame, List winners, List losers) {
//When the minigame ends, the flag for recognizing the start teleportation needs to be resetted
minigame.setPlayersAtStart(false);
- EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame);
+ EndPhaseMinigameEvent event = new EndPhaseMinigameEvent(winners, losers, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@@ -735,7 +756,7 @@ public void endMinigame(Minigame minigame, List winners, List winners, Minigame minigame) {
}
}
-
@Deprecated
public boolean playerInMinigame(Player player) {
return minigamePlayers.get(player.getName()).isInMinigame();
@@ -917,8 +937,9 @@ public void removeMinigamePlayer(Player player) {
public @Nullable MinigamePlayer getMinigamePlayer(UUID uuid) {
for (MinigamePlayer p : minigamePlayers.values()) {
- if (p.getUUID() == uuid)
+ if (p.getUUID() == uuid) {
return p;
+ }
}
return getMinigamePlayer(Bukkit.getPlayer(uuid));
@@ -1023,15 +1044,4 @@ public void saveDeniedCommands() {
public void loadDeniedCommands() {
setDeniedCommands(plugin.getConfig().getStringList("disabledCommands"));
}
-
- private class PlayerLocation {
- final Location location;
- final Integer position;
-
- public PlayerLocation(int pos) {
- location = null;
- this.position = pos;
- }
- }
-
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java
index 129bf6141..902c2d279 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/CTFMechanic.java
@@ -125,7 +125,7 @@ public void takeFlag(PlayerInteractEvent event) {
(TeamsModule.getMinigameModule(mgm).hasTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2)))) ||
sign.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) {
Team oTeam = TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2))));
- CTFFlag flag = new CTFFlag(event.getClickedBlock().getLocation(), oTeam, mgm);
+ CTFFlag flag = new CTFFlag(sign, oTeam, mgm);
ev = new TakeFlagEvent(mgm, ply, flag);
Bukkit.getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java
index 0216340a4..73cda201c 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/LivesMechanic.java
@@ -67,13 +67,13 @@ private void minigameStart(StartMinigameEvent event) {
final List players = event.getPlayers();
final Minigame minigame = event.getMinigame();
for (MinigamePlayer player : players) {
- if (!Float.isFinite(minigame.getLives())) {
- player.setScore(Integer.MAX_VALUE);
- minigame.setScore(player, Integer.MAX_VALUE);
- } else {
- int lives = Float.floatToIntBits(minigame.getLives());
+ if (Math.abs(minigame.getLives()) < Integer.MAX_VALUE) {
+ int lives = minigame.getLives();
player.setScore(lives);
minigame.setScore(player, lives);
+ } else {
+ player.setScore(Integer.MAX_VALUE);
+ minigame.setScore(player, Integer.MAX_VALUE);
}
}
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java
index d7849da18..d15486a71 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/TreasureHuntMechanic.java
@@ -18,6 +18,7 @@
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
+import org.bukkit.block.Container;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
@@ -68,7 +69,7 @@ public static void spawnTreasure(final Minigame mgm) {
double ry;
double rz;
final int maxradius;
- if (thm.getMaxRadius() == 0) {
+ if (thm.getMaxRadius() <= 0) {
maxradius = 1000;
} else {
maxradius = thm.getMaxRadius();
@@ -89,40 +90,41 @@ public static void spawnTreasure(final Minigame mgm) {
//Add a new Chest
//TODO: Improve so no invalid spawns (Not over void, Strict containment)
- switch (rpos.getBlock().getType()) {
- case AIR, CAVE_AIR, VOID_AIR -> {
- while (rpos.getBlock().getType() == Material.AIR && rpos.getY() > 1) {
- rpos.setY(rpos.getY() - 1);
- }
- rpos.setY(rpos.getY() + 1);
- Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
+ if (rpos.getBlock().getType().isAir()) {
+ int minWorldHeight = rpos.getWorld().getMinHeight();
+ // find first block below that is not air anymore to spawn on top of
+ while (rpos.getBlock().getType().isAir() && rpos.getY() > minWorldHeight) {
+ rpos.setY(rpos.getY() - 1);
}
- default -> {
- while (rpos.getBlock().getType() != Material.AIR && rpos.getY() < 255) {
- rpos.setY(rpos.getY() + 1);
- }
- Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
+ rpos.setY(rpos.getY() + 1);
+ } else {
+ int maxWorldHeight = rpos.getWorld().getMaxHeight();
+ // find first block above that is air to spawn into
+ while (!rpos.getBlock().getType().isAir() && rpos.getY() < maxWorldHeight) {
+ rpos.setY(rpos.getY() + 1);
}
}
- //Fill new chest
+ Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
+
+ //Fill new container
Bukkit.getScheduler().runTaskLater(plugin, () -> {
- if (rpos.getBlock().getState() instanceof Chest chest) {
+ if (rpos.getBlock().getState() instanceof Container container) {
// TODO: Treasure hunt needs own rewards specification
RewardsModule rewards = RewardsModule.getModule(mgm);
if (rewards.getScheme() instanceof StandardRewardScheme) {
if (!((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getRewards().isEmpty()) {
- int numitems = (int) Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure();
+ int numItems = (int) Math.min(container.getInventory().getSize(), Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure());
final ItemStack[] items = new ItemStack[27];
- for (int i = 0; i < numitems; i++) {
+ for (int i = 0; i < numItems; i++) {
RewardType rew = ((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getReward().get(0);
if (rew instanceof ItemReward irew) {
items[i] = irew.getRewardItem();
}
}
Collections.shuffle(Arrays.asList(items));
- chest.getInventory().setContents(items);
+ container.getInventory().setContents(items);
}
}
}
@@ -162,13 +164,14 @@ public void startMinigame(Minigame minigame, MinigamePlayer caller) {
if (thm.getLocation() != null) {
spawnTreasure(minigame);
- if (Bukkit.getOnlinePlayers().size() == 0)
+ if (Bukkit.getOnlinePlayers().isEmpty())
minigame.getMinigameTimer().stopTimer();
} else {
- if (caller == null)
+ if (caller == null) {
Bukkit.getLogger().info("Treasure Hunt requires a location name to run!");
- else
+ } else {
caller.sendMessage("Treasure Hunt requires a location name to run!", MinigameMessageType.ERROR);
+ }
}
}
@@ -343,5 +346,4 @@ private void interactEvent(PlayerInteractEvent event) {
}
}
}
-
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java
index a422fda0d..83ad857fa 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemAddWhitelistBlock.java
@@ -2,13 +2,13 @@
import au.com.mineauz.minigames.MinigameMessageType;
import au.com.mineauz.minigames.objects.MinigamePlayer;
+import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class MenuItemAddWhitelistBlock extends MenuItem {
-
private final List whitelist;
public MenuItemAddWhitelistBlock(String name, List whitelist) {
@@ -42,24 +42,37 @@ public ItemStack onClick() {
@Override
public void checkValidEntry(String entry) {
- entry = entry.toUpperCase();
- if (Material.getMaterial(entry) != null) {
- Material mat = Material.getMaterial(entry);
+ // try a direct match in case of a chat input
+ Material mat = Material.matchMaterial(entry);
+
+ // didn't work, now try the input as a block data, as we get when a block was clicked
+ if (mat == null) {
+ try {
+ mat = Bukkit.createBlockData(entry).getMaterial();
+
+ } catch (IllegalArgumentException ignored) {
+ }
+ }
+
+ if (mat == null) {
+ // still didn't work.
+ getContainer().getViewer().sendMessage("No material with BlockData \"" + entry + "\" was found!", MinigameMessageType.ERROR);
+ } else {
+ // nice we got a Material! try to add it!
if (!whitelist.contains(mat)) {
+ // intern
whitelist.add(mat);
+
+ // visual
getContainer().addItem(new MenuItemWhitelistBlock(mat, whitelist));
+
} else {
getContainer().getViewer().sendMessage("Whitelist/Blacklist already contains this material", MinigameMessageType.ERROR);
}
-
- getContainer().cancelReopenTimer();
- getContainer().displayMenu(getContainer().getViewer());
- return;
}
+ /* cancel automatic reopening and reopen {@link MenuItemDisplayWhitelist}*/
getContainer().cancelReopenTimer();
getContainer().displayMenu(getContainer().getViewer());
-
- getContainer().getViewer().sendMessage("No material by the name \"" + entry + "\" was found!", MinigameMessageType.ERROR);
}
}
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java
index af8052e25..e8d8d7302 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java
@@ -14,23 +14,23 @@
import java.util.List;
public class MenuItemBlockData extends MenuItem {
- private Callback data;
+ private Callback dataCallback;
public MenuItemBlockData(String name, Material displayItem) {
super(name, displayItem);
- data.setValue(displayItem.createBlockData());
- setDescription(createDescription(data.getValue()));
+ dataCallback.setValue(displayItem.createBlockData());
+ setDescription(createDescription(dataCallback.getValue()));
}
public MenuItemBlockData(String name, Material displayItem, Callback callback) {
super(name, displayItem);
- this.data = callback;
- setDescription(createDescription(data.getValue()));
+ this.dataCallback = callback;
+ setDescription(createDescription(dataCallback.getValue()));
}
@Override
public void update() {
- setDescription(createDescription(this.data.getValue()));
+ setDescription(createDescription(this.dataCallback.getValue()));
}
/**
@@ -61,7 +61,12 @@ private List createDescription(BlockData data) {
public ItemStack onClickWithItem(@Nullable ItemStack item) {
try {
BlockData data = item.getType().createBlockData();
- this.data.setValue(data);
+ this.dataCallback.setValue(data);
+
+ // update the display item
+ ItemStack stackUpdate = getItem();
+ stackUpdate.setType(item.getType());
+ setItem(stackUpdate);
} catch (IllegalArgumentException | NullPointerException e) {
String name = "unknown";
if (item != null) {
@@ -77,8 +82,16 @@ public void checkValidEntry(String entry) {
String err = "No MgBlockData detected";
try {
BlockData d = Bukkit.createBlockData(entry);
- data.setValue(d);
- setDescription(createDescription(data.getValue()));
+ dataCallback.setValue(d);
+
+ // update the display item
+ setDescription(createDescription(dataCallback.getValue()));
+ if (d.getMaterial().isItem()) {
+ ItemStack stackUpdate = getItem();
+ stackUpdate.setType(d.getMaterial());
+ setItem(stackUpdate);
+ }
+
getContainer().cancelReopenTimer();
getContainer().displayMenu(getContainer().getViewer());
return;
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java
index 40e6c0b42..b04188bdc 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java
@@ -72,10 +72,11 @@ public ItemStack onDoubleClick() {
@Override
public void checkValidEntry(String entry) {
- if (entry.equals("null") && allowNull)
+ if (entry.equals("null") && allowNull) {
str.setValue(null);
- else
+ } else {
str.setValue(entry);
+ }
updateDescription();
getContainer().cancelReopenTimer();
diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java
index 3267939f9..fe580feea 100644
--- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java
+++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java
@@ -1,7 +1,6 @@
package au.com.mineauz.minigames.minigame;
import au.com.mineauz.minigames.*;
-import au.com.mineauz.minigames.blockRecorder.RecorderData;
import au.com.mineauz.minigames.config.*;
import au.com.mineauz.minigames.gametypes.MinigameType;
import au.com.mineauz.minigames.mechanics.GameMechanicBase;
@@ -15,6 +14,7 @@
import au.com.mineauz.minigames.objects.MgRegion;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import au.com.mineauz.minigames.objects.RegenRegionSetResult;
+import au.com.mineauz.minigames.recorder.RecorderData;
import au.com.mineauz.minigames.script.ScriptCollection;
import au.com.mineauz.minigames.script.ScriptObject;
import au.com.mineauz.minigames.script.ScriptReference;
@@ -32,10 +32,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.scoreboard.DisplaySlot;
-import org.bukkit.scoreboard.Objective;
-import org.bukkit.scoreboard.Scoreboard;
-import org.bukkit.scoreboard.ScoreboardManager;
+import org.bukkit.scoreboard.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,9 +63,9 @@ public class Minigame implements ScriptObject {
private final BooleanFlag respawn = new BooleanFlag(Minigames.getPlugin().getConfig().getBoolean("has-respawn"), "respawn");
private final LocationListFlag startLocations = new LocationListFlag(null, "startpos");
private final BooleanFlag randomizeStart = new BooleanFlag(false, "ranndomizeStart");
- private final LocationFlag endPosition = new LocationFlag(null, "endpos");
- private final LocationFlag quitPosition = new LocationFlag(null, "quitpos");
- private final LocationFlag lobbyPosition = new LocationFlag(null, "lobbypos");
+ private final LocationFlag endLocation = new LocationFlag(null, "endpos");
+ private final LocationFlag quitLocation = new LocationFlag(null, "quitpos");
+ private final LocationFlag lobbyLocation = new LocationFlag(null, "lobbypos");
private final LocationFlag spectatorPosition = new LocationFlag(null, "spectatorpos");
private final BooleanFlag usePermissions = new BooleanFlag(false, "usepermissions");
@@ -102,6 +99,7 @@ public class Minigame implements ScriptObject {
private final BooleanFlag unlimitedAmmo = new BooleanFlag(false, "unlimitedammo");
private final BooleanFlag saveCheckpoints = new BooleanFlag(false, "saveCheckpoints");
private final BooleanFlag lateJoin = new BooleanFlag(false, "latejoin");
+ // just to stay backwards compatible we have
private final FloatFlag lives = new FloatFlag(0F, "lives");
private final RegionMapFlag regenRegions = new RegionMapFlag(new HashMap<>(), "regenRegions", "regenarea.1", "regenarea.2");
@@ -122,6 +120,7 @@ public class Minigame implements ScriptObject {
@NotNull
private final ScoreboardData sbData = new ScoreboardData();
private final Map statSettings = Maps.newHashMap();
+ private final BooleanFlag activatePlayerRecorder = new BooleanFlag(true, "activatePlayerRecorder");
//Unsaved data
private final List players = new ArrayList<>();
@@ -170,19 +169,19 @@ private void setup(MinigameType type, Location start) {
if (start != null)
startLocations.getFlag().add(start);
if (sbManager != null) {
- sbManager.registerNewObjective(this.name, "dummy", this.name);
- sbManager.getObjective(this.name).setDisplaySlot(DisplaySlot.SIDEBAR);
+ sbManager.registerNewObjective(this.name, Criteria.DUMMY, this.name).setDisplaySlot(DisplaySlot.SIDEBAR);
}
for (Class extends MinigameModule> mod : Minigames.getPlugin().getMinigameManager().getModules()) {
try {
addModule(mod.getDeclaredConstructor(Minigame.class).newInstance(this));
} catch (Exception e) {
- e.printStackTrace();
+ Minigames.getPlugin().getLogger().log(Level.WARNING, "Couldn't construct Module.", e);
}
}
flags.setFlag(new ArrayList<>());
+ addConfigFlag(activatePlayerRecorder);
addConfigFlag(allowEnderPearls);
addConfigFlag(allowFlight);
addConfigFlag(allowMPCheckpoints);
@@ -197,7 +196,7 @@ private void setup(MinigameType type, Location start) {
addConfigFlag(displayName);
addConfigFlag(enableFlight);
addConfigFlag(enabled);
- addConfigFlag(endPosition);
+ addConfigFlag(endLocation);
addConfigFlag(flags);
addConfigFlag(floorDegen);
addConfigFlag(floorDegenTime);
@@ -206,7 +205,7 @@ private void setup(MinigameType type, Location start) {
addConfigFlag(itemPickup);
addConfigFlag(lateJoin);
addConfigFlag(lives);
- addConfigFlag(lobbyPosition);
+ addConfigFlag(lobbyLocation);
addConfigFlag(maxChestRandom);
addConfigFlag(maxPlayers);
addConfigFlag(maxScore);
@@ -222,7 +221,7 @@ private void setup(MinigameType type, Location start) {
addConfigFlag(objective);
addConfigFlag(paintBallDamage);
addConfigFlag(paintBallMode);
- addConfigFlag(quitPosition);
+ addConfigFlag(quitLocation);
addConfigFlag(randomizeChests);
addConfigFlag(regenRegions);
addConfigFlag(regenDelay);
@@ -309,7 +308,11 @@ public boolean removeFlag(String flag) {
}
public void setStartLocation(Location loc) {
- startLocations.getFlag().set(0, loc);
+ if (startLocations.getFlag().isEmpty()) {
+ startLocations.getFlag().add(loc);
+ } else {
+ startLocations.getFlag().set(0, loc);
+ }
}
public void addStartLocation(Location loc) {
@@ -452,28 +455,28 @@ public void setDegenRandomChance(int degenRandomChance) {
this.degenRandomChance.setFlag(degenRandomChance);
}
- public Location getEndPosition() {
- return endPosition.getFlag();
+ public @Nullable Location getEndLocation() {
+ return endLocation.getFlag();
}
- public void setEndPosition(Location endPosition) {
- this.endPosition.setFlag(endPosition);
+ public void setEndLocation(Location endLocation) {
+ this.endLocation.setFlag(endLocation);
}
- public Location getQuitPosition() {
- return quitPosition.getFlag();
+ public @Nullable Location getQuitLocation() {
+ return quitLocation.getFlag();
}
- public void setQuitPosition(Location quitPosition) {
- this.quitPosition.setFlag(quitPosition);
+ public void setQuitLocation(Location quitLocation) {
+ this.quitLocation.setFlag(quitLocation);
}
- public Location getLobbyPosition() {
- return lobbyPosition.getFlag();
+ public @Nullable Location getLobbyLocation() {
+ return lobbyLocation.getFlag();
}
- public void setLobbyPosition(Location lobbyPosisiton) {
- this.lobbyPosition.setFlag(lobbyPosisiton);
+ public void setLobbyLocation(Location lobbyLocation) {
+ this.lobbyLocation.setFlag(lobbyLocation);
}
public String getName(boolean useDisplay) {
@@ -897,6 +900,14 @@ public void setMaxChestRandom(int maxChestRandom) {
this.maxChestRandom.setFlag(maxChestRandom);
}
+ public boolean getActivatePlayerRecorder() {
+ return activatePlayerRecorder.getFlag();
+ }
+
+ public void setActivatePlayerRecorder(boolean activatePlayerRecorder) {
+ this.activatePlayerRecorder.setFlag(activatePlayerRecorder);
+ }
+
public Collection getRegenRegions() {
return regenRegions.getFlag().values();
}
@@ -962,12 +973,12 @@ public void setRegenDelay(int regenDelay) {
this.regenDelay.setFlag(regenDelay);
}
- public float getLives() {
- return lives.getFlag();
+ public int getLives() {
+ return lives.getFlag().intValue();
}
- public void setLives(float lives) {
- this.lives.setFlag(lives);
+ public void setLives(int lives) {
+ this.lives.setFlag((float) lives);
}
public int getFloorDegenTime() {
@@ -1120,10 +1131,10 @@ public void setValue(String value) {
MenuItemString obj = (MenuItemString) objective.getMenuItem("Objective Description", Material.DIAMOND);
obj.setAllowNull(true);
itemsMain.add(obj);
- obj = (MenuItemString) gameTypeName.getMenuItem("Gametype Description", Material.OAK_WALL_SIGN);
+ obj = (MenuItemString) gameTypeName.getMenuItem("Gametype Description", Material.OAK_SIGN);
obj.setAllowNull(true);
itemsMain.add(obj);
- obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_WALL_SIGN);
+ obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_SIGN);
obj.setAllowNull(true);
itemsMain.add(obj);
itemsMain.add(new MenuItemNewLine());
@@ -1217,7 +1228,7 @@ public void setValue(Integer value) {
}, 0, null));
itemsMain.add(new MenuItemNewLine());
itemsMain.add(new MenuItemPage("Player Settings", Material.SKELETON_SKULL, playerMenu));
-// List thDes = new ArrayList<>();
+// List thDes = new ArrayList<>();
// thDes.add("Treasure hunt related");
// thDes.add("settings.");
// itemsMain.add(new MenuItemPage("Treasure Hunt Settings", thDes, Material.CHEST, treasureHunt));
@@ -1237,6 +1248,7 @@ public void setValue(Integer value) {
rndChstDes.add("Max. item randomization");
itemsMain.add(maxChestRandom.getMenuItem("Max. Chest Random", Material.STONE, rndChstDes, 0, null));
itemsMain.add(new MenuItemStatisticsSettings(this, "Stat Settings", Material.WRITABLE_BOOK));
+ itemsMain.add(activatePlayerRecorder.getMenuItem("Activate Player Block Recorder", Material.COMMAND_BLOCK));
itemsMain.add(new MenuItemNewLine());
//--------------//
@@ -1302,7 +1314,7 @@ public void setValue(Integer value) {
//--------------//
List