Skip to content

Commit

Permalink
Step 12 lang rework
Browse files Browse the repository at this point in the history
Change throwables to Exceptions to not deal with Errors
Rename Notifier appropriately
Don't use normal logger anymore!
added second interface for set commands to make the difference to normal commands clearer
Move MinigameSpecific Broadcasts out of MinigameManager
merged stop command with end command to simplify code and don't make exemption just for global minigames. This means it is necessary now to have the permission to end minigames for others in order to stop global minigames!
  • Loading branch information
FireInstall committed Feb 1, 2024
1 parent 3314e72 commit a06f7c0
Show file tree
Hide file tree
Showing 156 changed files with 1,650 additions and 1,519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void onPlayerDeath(PlayerDeathEvent event) {
}

if (msg != null && !PlainTextComponentSerializer.plainText().serialize(msg).isEmpty()) { //components really need a better way to check if they are empty
mdata.sendMinigameMessage(mgm, msg, MinigameMessageType.ERROR);
MinigameMessageManager.sendMinigameMessage(mgm, msg, MinigameMessageType.ERROR);
}
if (mgm.getState() == MinigameState.STARTED) {
if (mgm.getLives() > 0 && mgm.getLives() <= mgPlayer.getDeaths()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void runTimer() {
}
if (timeMsg.contains(time) && broadcastTime) {
PlayMGSound.playSound(minigame, MGSounds.TIMER_TICK.getSound());
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_TIMELEFT,
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_TIMELEFT,
Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(time))));
}

Expand All @@ -91,7 +91,7 @@ public void stopTimer() {
}
}

public int getTimeLeft() {
public long getTimeLeft() {
return time;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void onEnable() {
final CommandDispatcher disp = new CommandDispatcher();
PluginCommand command = this.getCommand("minigame");
if (command == null) {
throw (new Throwable("Could not find command `minigame`"));
throw (new NoSuchElementException("Could not find command `minigame`"));
}
command.setExecutor(disp);
command.setTabCompleter(disp);
Expand All @@ -234,7 +234,7 @@ public void onEnable() {

logger.info(desc.getName() + " successfully enabled.");
this.hookPlaceHolderApi();
} catch (final Throwable e) {
} catch (final Exception e) {
plugin = null;
logger.error("Failed to enable Minigames " + this.getDescription().getVersion() + ": ", e);
Bukkit.getPluginManager().disablePlugin(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import au.com.mineauz.minigames.managers.MinigameMessageManager;
import au.com.mineauz.minigames.managers.MinigamePlayerManager;
import au.com.mineauz.minigames.managers.language.langkeys.MinigameLangKey;
import au.com.mineauz.minigames.managers.language.MinigameMessageType;
import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey;
import au.com.mineauz.minigames.managers.language.langkeys.MinigameLangKey;
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.minigame.MinigameState;
import au.com.mineauz.minigames.minigame.modules.LobbySettingsModule;
Expand Down Expand Up @@ -64,22 +64,22 @@ private void doTimer() {
if (currentLobbyWaitTime != 0 && !paused) {
if (currentLobbyWaitTime == oLobbyWaitTime) {

plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_WAITINGFORPLAYERS), MinigameMessageType.INFO);
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_WAITINGFORPLAYERS), MinigameMessageType.INFO);
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
Placeholder.unparsed(MinigamePlaceHolderKey.TIME.getKey(), String.valueOf(currentLobbyWaitTime))), MinigameMessageType.INFO);
allowInteraction(LobbySettingsModule.getMinigameModule(minigame).canInteractPlayerWait());
freezePlayers(!LobbySettingsModule.getMinigameModule(minigame).canMovePlayerWait());
minigame.setState(MinigameState.WAITING);
} else if (timeMsg.contains(currentLobbyWaitTime)) {
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
Placeholder.unparsed(MinigamePlaceHolderKey.TIME.getKey(), String.valueOf(currentLobbyWaitTime))), MinigameMessageType.INFO);
PlayMGSound.playSound(minigame, MGSounds.TIMER_TICK.getSound());
}
} else if (currentLobbyWaitTime == 0 && startWaitTime != 0 && !paused) {
//wait time done game will start.
if (startWaitTime == oStartWaitTime) {
minigame.setState(MinigameState.STARTING);
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_MINIGAMESTARTS), MinigameMessageType.INFO);
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_MINIGAMESTARTS), MinigameMessageType.INFO);

freezePlayers(!LobbySettingsModule.getMinigameModule(minigame).canMoveStartWait());
allowInteraction(LobbySettingsModule.getMinigameModule(minigame).canInteractStartWait());
Expand All @@ -94,13 +94,13 @@ private void doTimer() {
}
}
} else if (timeMsg.contains(startWaitTime)) {
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_TIME,
Placeholder.unparsed(MinigamePlaceHolderKey.TIME.getKey(), String.valueOf(startWaitTime))), MinigameMessageType.INFO);
PlayMGSound.playSound(minigame, MGSounds.TIMER_TICK.getSound());
}
} else if (currentLobbyWaitTime == 0 && startWaitTime == 0) {
//game should start..
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_GO), MinigameMessageType.INFO);
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_GO), MinigameMessageType.INFO);
reclearInventories(minigame);
if (!LobbySettingsModule.getMinigameModule(minigame).isTeleportOnPlayerWait()) {
playerManager.balanceGame(minigame);
Expand All @@ -115,7 +115,7 @@ private void doTimer() {
} else {
playerManager.startMPMinigame(minigame);
if (!minigame.isPlayersAtStart()) {
Minigames.getPlugin().getLogger().info("Minigame started and Players not teleported check configs:" + minigame.getName(false));
Minigames.getCmpnntLogger().info("Minigame started and Players not teleported check configs:" + minigame.getName(false));
}
}
freezePlayers(false);
Expand All @@ -128,7 +128,7 @@ private void doTimer() {

if (minigame.getTimer() > 0) {
minigame.setMinigameTimer(new MinigameTimer(minigame, minigame.getTimer()));
plugin.getMinigameManager().sendMinigameMessage(minigame,
MinigameMessageManager.sendMinigameMessage(minigame,
MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_TIMELEFT,
Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(minigame.getTimer())))));
}
Expand Down Expand Up @@ -184,7 +184,7 @@ public void pauseTimer() {

public void pauseTimer(Component reason) {
paused = true;
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_PAUSED,
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_PAUSED,
Placeholder.component(MinigamePlaceHolderKey.TEXT.getKey(), reason)), MinigameMessageType.INFO);
}

Expand All @@ -196,7 +196,7 @@ public void removeTimer() {

public void resumeTimer() {
paused = false;
plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_RESUMED), MinigameMessageType.INFO);
MinigameMessageManager.sendMinigameMessage(minigame, MinigameMessageManager.getMgMessage(MinigameLangKey.TIME_STARTUP_RESUMED), MinigameMessageType.INFO);
}

public boolean isPaused() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void saveCheckpoints() {
save.getConfig().set(mgm + ".reverts", getReverts(mgm));
} catch (Exception e) {
// When an error is detected, remove the stored erroneous checkpoint
Minigames.getPlugin().getLogger().warning("Unable to save checkpoint for " + mgm + "! It has been been removed.");
Minigames.getCmpnntLogger().warn("Unable to save checkpoint for " + mgm + "! It has been been removed.");
Minigames.getCmpnntLogger().error("", e);

// Remove the checkpoint from memory, so it doesn't cause an error again
Expand All @@ -175,8 +175,7 @@ public void saveCheckpoints() {
} catch (Exception e) {
// When an error is detected, remove the global checkpoint
save.getConfig().set("globalcheckpoint", null);
Minigames.getPlugin().getLogger().warning("Unable to save global checkpoint!");
Minigames.getCmpnntLogger().error("", e);
Minigames.getCmpnntLogger().warn("Unable to save global checkpoint!", e);
}
}
save.saveConfig();
Expand All @@ -198,7 +197,7 @@ public void loadCheckpoints() {

World w = Minigames.getPlugin().getServer().getWorld(world);
if (w == null) {
Minigames.getPlugin().getLogger().warning("WARNING: Invalid world \"" + world + "\" found in checkpoint for " + mgm + "! Checkpoint has been removed.");
Minigames.getCmpnntLogger().warn("WARNING: Invalid world \"" + world + "\" found in checkpoint for " + mgm + "! Checkpoint has been removed.");
continue;
}

Expand Down Expand Up @@ -237,7 +236,7 @@ public void loadCheckpoints() {

World w = Minigames.getPlugin().getServer().getWorld(world);
if (w == null) {
Minigames.getPlugin().getLogger().warning("WARNING: Invalid world \"" + world + "\" found in global checkpoint! Checkpoint has been removed.");
Minigames.getCmpnntLogger().warn("WARNING: Invalid world \"" + world + "\" found in global checkpoint! Checkpoint has been removed.");
} else {
globalCheckpoint = new Location(Minigames.getPlugin().getServer().getWorld(world), x, y, z, yaw, pitch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public abstract class Backend {
* @param other The backend to export to
* @param notifier A callback to receive progress updates
*/
public abstract void exportTo(Backend other, ExportNotifier notifier);
public abstract void exportTo(Backend other, Notifier notifier);

protected abstract BackendImportCallback getImportCallback();

Expand All @@ -107,5 +107,5 @@ protected final BackendImportCallback getImportCallback(Backend other) {
* @param notifier A notifier for progress updates
* @return True if the conversion succeeded
*/
public abstract boolean doConversion(ExportNotifier notifier);
public abstract boolean doConversion(Notifier notifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public boolean initialize(ConfigurationSection config) {

// Handle conversion
if (backendSection.getBoolean("convert", false)) {
ExportNotifier notifier = new ExportNotifier() {
Notifier convertNotifier = new Notifier() {
@Override
public void onProgress(String state, int count) {
logger.info("Conversion: " + state + " " + count);
}

@Override
public void onError(Throwable e, String state, int count) {
public void onError(Exception e, String state, int count) {
logger.error("Conversion error: " + state + " " + count, e);
}

Expand All @@ -111,7 +111,7 @@ public void onComplete() {
}
};

if (backend.doConversion(notifier)) {
if (backend.doConversion(convertNotifier)) {
backendSection.set("convert", false);
} else {
return false;
Expand Down Expand Up @@ -224,7 +224,7 @@ public <T> void addServerThreadCallback(ListenableFuture<T> future, FutureCallba
* @return A future to let you know when the process is finished
* @throws IllegalArgumentException Thrown if the backend chosen cannot be used. Reason given in message
*/
public ListenableFuture<Void> exportTo(String type, ConfigurationSection config, final ExportNotifier notifier) throws IllegalArgumentException {
public ListenableFuture<Void> exportTo(String type, ConfigurationSection config, final Notifier notifier) throws IllegalArgumentException {
final Backend destination = makeBackend(type);
if (destination == null) {
throw new IllegalArgumentException("Invalid backend type");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package au.com.mineauz.minigames.backend;

public interface ExportNotifier {
public interface Notifier {
void onProgress(String state, int count);

void onComplete();

void onError(Throwable e, String state, int count);
void onError(Exception e, String state, int count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class SQLExport {
private final ConnectionPool pool;
private final BackendImportCallback callback;
private final ExportNotifier notifier;
private final Notifier notifier;

private final StatementKey getPlayers;
private final StatementKey getMinigames;
Expand All @@ -24,7 +24,7 @@ public class SQLExport {
private long notifyTime;


public SQLExport(ConnectionPool pool, BackendImportCallback callback, ExportNotifier notifier) {
public SQLExport(ConnectionPool pool, BackendImportCallback callback, Notifier notifier) {
this.pool = pool;
this.callback = callback;
this.notifier = notifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class LegacyExporter {
private final ConnectionPool pool;
private final String database;
private final BackendImportCallback callback;
private final ExportNotifier notifier;
private final Notifier notifier;
private final StatementKey selectTables;
private final StatementKey selectPlayers;
private final StatementKey selectStats;
Expand All @@ -20,7 +20,7 @@ public class LegacyExporter {
private int notifyCount;
private long notifyTime;

public LegacyExporter(ConnectionPool pool, String database, BackendImportCallback callback, ExportNotifier notifier) {
public LegacyExporter(ConnectionPool pool, String database, BackendImportCallback callback, Notifier notifier) {
this.pool = pool;
this.database = database;
this.callback = callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ protected BackendImportCallback getImportCallback() {
}

@Override
public void exportTo(Backend other, ExportNotifier notifier) {
public void exportTo(Backend other, Notifier notifier) {
BackendImportCallback callback = getImportCallback(other);
SQLExport exporter = new SQLExport(pool, callback, notifier);
exporter.beginExport();
}

@Override
public boolean doConversion(ExportNotifier notifier) {
public boolean doConversion(Notifier notifier) {
BackendImportCallback callback = getImportCallback();
LegacyExporter exporter = new LegacyExporter(pool, database, callback, notifier);
return exporter.doExport();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package au.com.mineauz.minigames.backend.sqlite;

import au.com.mineauz.minigames.backend.BackendImportCallback;
import au.com.mineauz.minigames.backend.ExportNotifier;
import au.com.mineauz.minigames.backend.Notifier;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
Expand All @@ -22,7 +22,7 @@
public class FlatFileExporter {
private final File file;
private final FileConfiguration config;
private final ExportNotifier notifier;
private final Notifier notifier;
private final BackendImportCallback callback;
private final Map<String, Integer> minigameIds;
private SetMultimap<String, UUID> completions;
Expand All @@ -32,7 +32,7 @@ public class FlatFileExporter {
private int notifyCount;
private long notifyTime;

public FlatFileExporter(File file, BackendImportCallback callback, ExportNotifier notifier) {
public FlatFileExporter(File file, BackendImportCallback callback, Notifier notifier) {
this.file = file;
this.callback = callback;
this.notifier = notifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ protected BackendImportCallback getImportCallback() {
}

@Override
public void exportTo(Backend other, ExportNotifier notifier) {
public void exportTo(Backend other, Notifier notifier) {
BackendImportCallback callback = getImportCallback(other);
SQLExport exporter = new SQLExport(pool, callback, notifier);
exporter.beginExport();
}

@Override
public boolean doConversion(ExportNotifier notifier) {
public boolean doConversion(Notifier notifier) {
BackendImportCallback callback = getImportCallback();
FlatFileExporter exporter = new FlatFileExporter(new File(Minigames.getPlugin().getDataFolder(), "completion.yml"), callback, notifier);
return exporter.doExport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import au.com.mineauz.minigames.backend.Backend;
import au.com.mineauz.minigames.backend.BackendImportCallback;
import au.com.mineauz.minigames.backend.ExportNotifier;
import au.com.mineauz.minigames.backend.Notifier;
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.minigame.ScoreboardOrder;
import au.com.mineauz.minigames.stats.*;
Expand Down Expand Up @@ -154,7 +154,7 @@ public void saveStatSettings(Minigame minigame, Collection<StatSettings> setting
* @param notifier A callback to receive progress updates
*/
@Override
public void exportTo(Backend other, ExportNotifier notifier) {
public void exportTo(Backend other, Notifier notifier) {

}

Expand All @@ -170,7 +170,7 @@ protected BackendImportCallback getImportCallback() {
* @return True if the conversion succeeded
*/
@Override
public boolean doConversion(ExportNotifier notifier) {
public boolean doConversion(Notifier notifier) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ public class MgBlockData {

public MgBlockData(@NotNull Block original, @Nullable MinigamePlayer modifier) {
location = original.getLocation();
state = original.getState();
state = original.getState(); // this already makes a copy of the data - not a reference!
blockData = original.getBlockData().getAsString();
if (modifier != null) playerUUID = modifier.getUUID();
}

/**
* Please make sure, the blocksate is a copy not a reference.
* Obtaining through {@link Block#getState()} should be fine.
*/
public MgBlockData(@NotNull BlockState original, @Nullable MinigamePlayer modifier) {
location = original.getLocation();
state = original;
Expand Down
Loading

0 comments on commit a06f7c0

Please sign in to comment.