Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public enum TranslatableLine {
MINE_RESET_WARNING("Mines.Reset.Warning", ReplacableVar.MINE),
MINE_TELEPORT("Mines.Teleport", ReplacableVar.MINE),
MINE_TELEPORT_SET("Mines.Teleport-Set", ReplacableVar.MINE),
MINE_COUNTDOWN_SET("Mines.Countdown-Set", ReplacableVar.MINE, ReplacableVar.TIME),
MINE_COUNTDOWN_SET_UNSUCCESSFUL("Mines.Countdown-Set-Unsuccessful", ReplacableVar.MINE),
MINE_NO_TELEPORT_LOCATION("Mines.No-Teleport-Location"),
// break actions
MINE_BREAK_ACTION_GIVE_MONEY("Mines.Break-Actions.Give-Money", ReplacableVar.MONEY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -106,7 +107,7 @@ public BlockSetsMode next() {
}
}

public enum MineData {BLOCKS, ICON, RESET, TELEPORT, SIGNS, POS, NAME, DISPLAYNAME, FACES, COLOR, MINE_TYPE, ALL}
public enum MineData {BLOCKS, ICON, RESET, COUNTDOWN, TELEPORT, SIGNS, POS, NAME, DISPLAYNAME, FACES, COLOR, MINE_TYPE, ALL}

protected String name, displayName;

Expand Down Expand Up @@ -225,6 +226,7 @@ public RMine(String name, Section mineConfigSection) throws RMFailedToLoadExcept
this.config.set("reset.percentage.value", mineConfigSection.getInt("Settings.Reset.ByPercentageValue"));
this.config.set("reset.time.active", mineConfigSection.getBoolean("Settings.Reset.ByTime"));
this.config.set("reset.time.value", mineConfigSection.getInt("Settings.Reset.ByTimeValue"));
this.config.set("reset.time.countdown", mineConfigSection.getInt("Settings.Reset.ByTimeCountdown"));

this.config.set(RMineSettings.BREAK_PERMISSION.getConfigKey(), mineConfigSection.getBoolean("Settings.Break-Permission"));
this.config.set(RMineSettings.DISCARD_BREAK_ACTION_MESSAGES.getConfigKey(), mineConfigSection.getBoolean("Settings.Discard-Break-Action-Messages"));
Expand Down Expand Up @@ -514,7 +516,9 @@ private void loadMineConfig() throws RMFailedToLoadException {

this.timer = new MineTimer(this);
if (this.resetByTime) {
int countdown = this.config.getInt("reset.time.countdown", this.resetByTimeValue);
this.timer.start();
this.setCountdown(countdown);
}
}

Expand Down Expand Up @@ -653,6 +657,32 @@ public MineTimer getMineTimer() {
return this.timer;
}

public @Nullable Integer getCountdown() {
if (this.timer == null || this.timer.getCountdown() == null) {
return null;
}
return this.timer.getCountdown().getSecondsLeft();
}

public boolean setCountdown(int seconds) {
return setCountdown(seconds, true);
}

public boolean setCountdown(int seconds, boolean saveData) {
if (this.timer == null || this.timer.getCountdown() == null) {
return false;
}
this.timer.getCountdown().setSecondsLeft(seconds);
if (saveData) {
this._save(MineData.COUNTDOWN, true);
}
return true;
}

public boolean resetCountdown(boolean saveData) {
return this.setCountdown(this.resetByTimeValue, saveData);
}

public Location getPOS1() {
return _pos1;
}
Expand Down Expand Up @@ -884,6 +914,15 @@ public void saveData(final MineData t) {
}
}

public void saveAllOf(final Collection<MineData> types, boolean save) {
for (MineData t : types) {
this._save(t, false);
}
if (save) {
saveConfig();
}
}

private void _save(MineData t, boolean save) {
switch (t) {
case ICON:
Expand All @@ -900,6 +939,8 @@ private void _save(MineData t, boolean save) {
this.config.set("reset.time.active", isResetBy(Reset.TIME));
this.config.set("reset.time.value", getResetValue(Reset.TIME));
break;
case COUNTDOWN:
this.config.set("reset.time.countdown", getCountdown());
case SIGNS:
this.config.set("signs", this.getSignList());
break;
Expand Down Expand Up @@ -970,6 +1011,7 @@ private void _save(MineData t, boolean save) {
this._save(MineData.FACES, false);
this._save(MineData.COLOR, false);
this._save(MineData.MINE_TYPE, false);
this._save(MineData.COUNTDOWN, false);
break;
}
if (save)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public int getSecondsLeft() {
return this.secondsLeft;
}

/**
* Sets the seconds left for this timer
* @param secondsLeft Seconds left
*/
public void setSecondsLeft(int secondsLeft) {
this.secondsLeft = secondsLeft;
}

public Integer getTaskId() {
return this.assignedTaskId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -166,6 +163,18 @@ public void onEnable() {
(sender, context) -> realMines.getMineResetTasksManager().getRegisteredTasks()
);

commandManager.registerSuggestion(SuggestionKey.of("#minecountdowns"),
(sender, context) -> {
RMine mine = realMines.getMineManager().getMine(context.getArgs().get(0));
if (mine != null && mine.getMineTimer() != null && mine.getMineTimer().getCountdown() != null) {
Integer countdown = mine.getCountdown();
if (countdown == null) return List.of();
return List.of(countdown.toString());
}
return List.of();
}
);

//registo de comandos #portugal
Map<String, BaseCommandWA> commands = new HashMap<>();
registerCommand("realmines", new MineCMD(realMines), commands, commandManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,45 @@ public void settpcmd(final CommandSender commandSender, @Suggestion("#mines") fi
}
}

@SubCommand("setcountdown")
@Permission("realmines.admin")
@WrongUsage("&c/mine setcountdown <name> <seconds>")
public void setcountdowncmd(final CommandSender commandSender, @Suggestion("#mines") final String name, @Suggestion("#minecountdowns") final Integer seconds) {
final RMine m = rm.getMineManager().getMine(name);
if (m != null) {
boolean success = m.setCountdown(seconds, true);
if (success) {
TranslatableLine.MINE_COUNTDOWN_SET.setV1(TranslatableLine.ReplacableVar.MINE.eq(m.getDisplayName())).setV2(TranslatableLine.ReplacableVar.TIME.eq(String.valueOf(seconds))).send(commandSender);
} else {
TranslatableLine.MINE_COUNTDOWN_SET_UNSUCCESSFUL.setV1(TranslatableLine.ReplacableVar.MINE.eq(m.getDisplayName())).send(commandSender);
}
} else {
TranslatableLine.SYSTEM_MINE_DOESNT_EXIST.send(commandSender);
}
}

@SubCommand("resetcountdown")
@Permission("realmines.admin")
@WrongUsage("&c/mine resetcountdown <name>")
public void resetcountdowncmd(final CommandSender commandSender, @Suggestion("#mines") final String name) {
final RMine m = rm.getMineManager().getMine(name);
if (m != null) {
boolean success = m.resetCountdown(true);
if (success) {
TranslatableLine line = TranslatableLine.MINE_COUNTDOWN_SET.setV1(TranslatableLine.ReplacableVar.MINE.eq(m.getDisplayName()));
Integer countdown = m.getCountdown();
if (countdown != null) {
line.setV2(TranslatableLine.ReplacableVar.TIME.eq(String.valueOf(countdown)));
}
line.send(commandSender);
} else {
TranslatableLine.MINE_COUNTDOWN_SET_UNSUCCESSFUL.setV1(TranslatableLine.ReplacableVar.MINE.eq(m.getDisplayName())).send(commandSender);
}
} else {
TranslatableLine.SYSTEM_MINE_DOESNT_EXIST.send(commandSender);
}
}

@SubCommand("tp")
@Permission("realmines.tp")
@WrongUsage("&c/mine tp <name>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ public List<MineSign> getSigns() {
@Override
public void unloadMines() {
for (RMine mine : this.getMines().values()) {
mine.saveAllOf(List.of(RMine.MineData.COUNTDOWN), true);
if (mine.getMineTimer() != null) {
mine.getMineTimer().kill();
}
Expand Down
2 changes: 2 additions & 0 deletions realmines-plugin/src/main/resources/language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Mines:
Warning: "&7[&6Warning&7] &r%mine% &fwill reset in &b%time% &9seconds."
Teleport: "&fTeleported to mine &9%mine%"
Teleport-Set: "&fTeleport &Aset &ffor mine %mine%"
Countdown-Set: "&fCountdown &aset &ffor mine %mine% to &b%time% &fseconds."
Countdown-Set-Unsuccessful: "&cCould not set countdown for mine %mine%. Invalid time or mine cannot be reset by time."
No-Teleport-Location: "&fThis mine &cdoesnt have a teleport location."
Break-Actions:
Give-Money: "&fYou just recieved &b%money% coins &ffor breaking this block! &eLucky you!"
Expand Down