Skip to content

Commit

Permalink
Added a way to specify a time left to the players to go inside the ne…
Browse files Browse the repository at this point in the history
…xt border

/uh border warning <newDiameter> [minutesBeforeReduction]

Also, fixed some translations in French.
  • Loading branch information
AmauryCarrade committed Aug 2, 2014
1 parent 9ebd79f commit 85c1048
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
.settings
bin/
screenshots/
*~
77 changes: 74 additions & 3 deletions src/main/java/me/azenet/UHPlugin/UHBorderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

Expand All @@ -17,6 +18,10 @@ public class UHBorderManager {
private Integer warningSize = 0;
private BukkitRunnable warningTask = null;

private Boolean warningFinalTimeEnabled = false;
private Long warningFinalTime = 0L;
private CommandSender warningSender = null;

private Boolean isCircularBorder = null;


Expand Down Expand Up @@ -111,24 +116,79 @@ public int getWarningSize() {
return this.warningSize;
}

/**
* Returns the time stamp of the end of the warning time
* (i.e. the time before the players have to go inside the new border).
*
* @return
*/
public long getWarningFinalTime() {
return this.warningFinalTime;
}

/**
* Returns true if there is currently a warning with a time left displayed.
*
* @return
*/
public boolean getWarningFinalTimeEnabled() {
return this.warningFinalTimeEnabled;
}

/**
* Returns the sender of the last warning configured.
*
* @return
*/
public CommandSender getWarningSender() {
return this.warningSender;
}

/**
* Sets the size of the future border, used in the warning messages sent to the
* players out of this future border.
*
* This also starts the display of the warning messages, every 90 seconds by default
* (configurable, see config.yml, map.border.warningInterval).
*
* If timeLeft is not null, the time available for the players to go inside the future
* border is displayed in the warning message.
*
* @param diameter
* @param timeLeft The time available for the players to go inside the future border (minutes).
*/
public void setWarningSize(int diameter) {
public void setWarningSize(int diameter, int timeLeft, CommandSender sender) {
cancelWarning();

this.warningSize = diameter;

if(timeLeft != 0) {
this.warningFinalTime = System.currentTimeMillis() + 60000L*timeLeft;
this.warningFinalTimeEnabled = true;
}

if(sender != null) {
this.warningSender = sender;
}

warningTask = new BorderWarningTask(p);
warningTask.runTaskTimer(p, 20L, 20L * p.getConfig().getInt("map.border.warningInterval", 90));
}

/**
* Sets the size of the future border, used in the warning messages sent to the
* players out of this future border.
*
* This also starts the display of the warning messages, every 90 seconds by default
* (configurable, see config.yml, map.border.warningInterval).
*
* @param diameter
* @param timeLeft The time available for the players to go inside the future border (minutes).
*/
public void setWarningSize(int diameter) {
setWarningSize(diameter, 0, null);
}

/**
* Stops the display of the warning messages.
*/
Expand All @@ -140,6 +200,17 @@ public void cancelWarning() {

}
}

stopWarningTime();
}

/**
* Stops the display of the time left in the warning message.
*/
public void stopWarningTime() {
this.warningFinalTimeEnabled = false;
this.warningFinalTime = 0l;
this.warningSender = null;
}

/**
Expand Down Expand Up @@ -250,9 +321,9 @@ else if(x < limitXInf && z < limitZInf) { // N-O
/** Circular border **/

private boolean isInsideCircularBorder(Location location, int diameter) {
Double halfMapSize = Math.floor(diameter/2);
Double radius = Math.floor(diameter/2);

return !(location.distance(Bukkit.getWorlds().get(0).getSpawnLocation()) > halfMapSize);
return !(location.distance(Bukkit.getWorlds().get(0).getSpawnLocation()) >= radius);
}

private int getDistanceToCircularBorder(Location location, int diameter) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,13 @@ else if(args[2].equalsIgnoreCase("cancel")) { // /uh border warning cancel
else { // /uh border warning <?>
try {
Integer warnDiameter = Integer.valueOf(args[2]);
p.getBorderManager().setWarningSize(warnDiameter);

Integer warnTime = 0;
if(args.length >= 4) { // /uh border warning <?> <?>
warnTime = Integer.valueOf(args[3]);
}

p.getBorderManager().setWarningSize(warnDiameter, warnTime, sender);
sender.sendMessage(i.t("borders.warning.set", p.getConfig().getString("map.border.warningInterval", "90")));

} catch(NumberFormatException e) {
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/me/azenet/UHPlugin/task/BorderWarningTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public BorderWarningTask(UHPlugin p) {
@Override
public void run() {

int minutesLeft = 0;

if(p.getBorderManager().getWarningFinalTimeEnabled()) {
minutesLeft = (int) ((p.getBorderManager().getWarningFinalTime() - System.currentTimeMillis()) / (60 * 1000) % 60);
int secondsLeft = (int) ((p.getBorderManager().getWarningFinalTime() - System.currentTimeMillis()) / 1000 % 60);

if(secondsLeft > 30) {
minutesLeft++;
}
if(secondsLeft < 0) { // Timer is up, but "-0" minutes
minutesLeft = -1;
}
}
else {
minutesLeft = -1;
}

// Message sent to all players outside the border
for(Player player : p.getBorderManager().getPlayersOutside(p.getBorderManager().getWarningSize())) {
int distance = p.getBorderManager().getDistanceToBorder(player.getLocation(), p.getBorderManager().getWarningSize());

Expand All @@ -29,9 +47,19 @@ public void run() {
else {
player.sendMessage(i.t("borders.warning.messageSquared", String.valueOf(p.getBorderManager().getWarningSize())));
}
player.sendMessage(i.t("borders.warning.messageDistance", String.valueOf(distance)));

if(minutesLeft <= 0) {
player.sendMessage(i.t("borders.warning.messageDistance", String.valueOf(distance)));
}
else {
player.sendMessage(i.t("borders.warning.messageDistanceTime", String.valueOf(distance), String.valueOf(minutesLeft)));
}
}

// Message sent to the sender of the warning if the timer is up
if(p.getBorderManager().getWarningFinalTimeEnabled() && minutesLeft <= 0) {
p.getBorderManager().getWarningSender().sendMessage(i.t("borders.warning.timerUp"));
p.getBorderManager().stopWarningTime();
}
}

}
5 changes: 4 additions & 1 deletion src/main/resources/i18n/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ keys:
borderHelpAvailable: "{ci}Available options are listed below."
borderHelpCurrent: "{cc}/uh border current{ci}: returns the current size of the map."
borderHelpSet: "{cc}/uh border set <diameter> [force]{ci}: change the size of the map. If force is not given, the operation will be canceled if there is a player outside the border."
borderHelpWarning: "{cc}/uh border warning <futureDiameter>{ci}: warns all players outside the given future diameter. It's just a notice, nothing else."
borderHelpWarning: "{cc}/uh border warning <futureDiameter> [minutesBeforeReduction]{ci}: warns all players outside the given future diameter. It's just a notice, nothing else."
borderHelpWarningCancel: "{cc}/uh border warning cancel{ci}: cancels a previously-set warning."
borderHelpCheck: "{cc}/uh border check <diameter>{ci}: returns a list of the players outside the given border size."

Expand Down Expand Up @@ -238,6 +238,9 @@ keys:
messageCircular: "{ce}You are currently out of the future border (diameter of {0} blocks)."

messageDistance: "{ci}You have {0} blocks to go before being inside."
messageDistanceTime: "{ci}You have {0} blocks to go before being inside, and {1} minutes to do so."

timerUp: "{cs}The timer before the new border is up!"

check:
allPlayersInside: "{cs}All players are inside the given border."
Expand Down
31 changes: 17 additions & 14 deletions src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ keys:
helpBorder: "{cc}/uh border {ci}: gère la bordure. Exécutez /uh border pour plus de détails."

titleBugCmd: "{aqua}------ Commandes liées aux bugs ------"
helpHeal: "{cc}/uh heal <player> [half-hearts=20] {ci}: change la vie d'un joueur avec le nombre de demi-coeurs donné (par défaut, 20)."
helpHealall: "{cc}/uh healall [half-hearts=20] {ci}: change la vie de tous les joueurs, et non d'un seul."
helpResurrect: "{cc}/uh resurrect <player> {ci}: fait revivre un joueur."
helpTpback: "{cc}/uh tpback <player> [force] {ci}: téléporte un joueur au lieu de sa mort en toute sécurité."
helpHeal: "{cc}/uh heal <joueur> [demi-coeurs=20] {ci}: change la vie d'un joueur avec le nombre de demi-coeurs donné (par défaut, 20)."
helpHealall: "{cc}/uh healall [demi-coeurs=20] {ci}: change la vie de tous les joueurs, et non d'un seul."
helpResurrect: "{cc}/uh resurrect <joueur> {ci}: fait revivre un joueur."
helpTpback: "{cc}/uh tpback <joueur> [force] {ci}: téléporte un joueur au lieu de sa mort en toute sécurité."

teamHelpAvailable: "{ci}Les options disponibles sont listées ci-dessous."
teamHelpAdd: "{cc}/uh team add <color> {ci}: ajoute une équipe de la couleur donnée."
teamHelpAddName: "{cc}/uh team add <color> <name> {ci}: ajoute une équipe avec le nom et la couleur donnés."
teamHelpRemove: "{cc}/uh team remove <name> {ci}: supprime une équipe."
teamHelpAddplayer: "{cc}/uh team addplayer <teamName> <player> {ci}: ajoute un joueur dans l'équipe donnée. Le nom de l'équipe est sa couleur, ou le nom explicite donné."
teamHelpRemoveplayer: "{cc}/uh team removeplayer <player> {ci}: retire un joueur de son équipe."
teamHelpAdd: "{cc}/uh team add <couleur> {ci}: ajoute une équipe de la couleur donnée."
teamHelpAddName: "{cc}/uh team add <couleur> <nom> {ci}: ajoute une équipe avec le nom et la couleur donnés."
teamHelpRemove: "{cc}/uh team remove <nomÉquipe> {ci}: supprime une équipe."
teamHelpAddplayer: "{cc}/uh team addplayer <nomÉquipe> <joueur> {ci}: ajoute un joueur dans l'équipe donnée. Le nom de l'équipe est sa couleur, ou le nom explicite donné."
teamHelpRemoveplayer: "{cc}/uh team removeplayer <joueur> {ci}: retire un joueur de son équipe."
teamHelpList: "{cc}/uh team list {ci}: liste toutes les équipes et leurs membres."
teamHelpReset: "{cc}/uh team reset {ci}: supprime toutes les équipes."

specHelpAvailable: "{ci}Les options disponibles sont listées ci-dessous."
specHelpNoticeSpectatorPlusNotInstalled: "{ce}Attention{ci}: SpectatorPlus n'étant pas installé, un spectateur n'est qu'un joueur ignoré."
specHelpAdd: "{cc}/uh spec add <player>{ci}: ajoute un spectateur."
specHelpRemove: "{cc}/uh spec remove <player>{ci}: supprime un spectateur."
specHelpAdd: "{cc}/uh spec add <joueur>{ci}: ajoute un spectateur."
specHelpRemove: "{cc}/uh spec remove <joueur>{ci}: supprime un spectateur."
specHelpList: "{cc}/uh spec list{ci}: liste les spectateurs."

borderHelpAvailable: "{ci}Les options disponibles sont listées ci-dessous."
borderHelpCurrent: "{cc}/uh border current{ci}: retourne la taille actuelle de la carte."
borderHelpSet: "{cc}/uh border set <diameter> [force]{ci}: change la taille de la carte. Si le paramètre “force” n'est pas donné, l'opération sera annulée s'il existe des joueurs hors de la bordure."
borderHelpWarning: "{cc}/uh border warning <futureDiameter>{ci}: avertit tous les joueurs hors de la future bordure donnée. Ce n'est qu'un avertissement, rien de plus."
borderHelpSet: "{cc}/uh border set <diamètre> [force]{ci}: change la taille de la carte. Si le paramètre “force” n'est pas donné, l'opération sera annulée s'il existe des joueurs hors de la bordure."
borderHelpWarning: "{cc}/uh border warning <futurDiamètre> [minutesAvantRéduction]{ci}: avertit tous les joueurs hors de la future bordure donnée. Ce n'est qu'un avertissement, rien de plus."
borderHelpWarningCancel: "{cc}/uh border warning cancel{ci}: annule un précédent avertissement."
borderHelpCheck: "{cc}/uh border check <diameter>{ci}: retourne la liste des joueurs hors de la bordure."
borderHelpCheck: "{cc}/uh border check <diamètre>{ci}: retourne la liste des joueurs hors de la bordure."

start:
already: "{ce}Le jeu est déjà démarré ! Rechargez ou redémarrez le serveur pour redémarrer."
Expand Down Expand Up @@ -237,6 +237,9 @@ keys:
messageCircular: "{ce}Vous êtes hors de la future bordure de {0} blocs de diamètre."

messageDistance: "{ci}Il vous reste {0} blocs à parcourir avant d'y être."
messageDistanceTime: "{ci}Il vous reste {0} blocs à parcourir, et {1} minutes pour ce faire."

timerUp: "{cs}Le temps imparti avant la nouvelle bordure est écoulé !"

check:
allPlayersInside: "{cs}Tous les joueurs sont à l'intérieur de cette bordure."
Expand Down

0 comments on commit 85c1048

Please sign in to comment.