Skip to content

Commit

Permalink
v1.3.4.278 - add github issue #124 - add timer configs to add/remove/…
Browse files Browse the repository at this point in the history
…change timer interval messages
  • Loading branch information
slipcor committed May 10, 2017
1 parent 6decc1b commit 367a8e3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- v1.3.4.278 - add github issue #124 - add timer configs to add/remove/change timer interval messages
- v1.3.4.277 - add github issue #117 - BossBar for Domination

- v1.3.4.276 - do not setup a scoreboard if spectating is cancelled/not possible
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Users tutorials :

## Changelog

- v1.3.4.277 - add github issue #117 - BossBar for Domination, add config for Beacons
- v1.3.4.278 - add github issue #124 - add timer configs to add/remove/change timer interval messages
- [read more](doc/changelog.md)

***
Expand Down
30 changes: 30 additions & 0 deletions src/net/slipcor/pvparena/core/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.slipcor.pvparena.core.Config.CFG;
import net.slipcor.pvparena.managers.StatisticsManager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
Expand All @@ -24,6 +25,7 @@ private Language() {
}

private static final Debug debugger = new Debug(17);
private static FileConfiguration config;

public enum MSG {

Expand Down Expand Up @@ -735,6 +737,10 @@ public static MSG getByName(final String string) {
}
}

public static FileConfiguration getConfig() {
return config;
}

/**
* create a language manager instance
*/
Expand All @@ -761,9 +767,33 @@ public static void init(final String langString) {
config.addDefault(m.getNode(), m.toString());
}

if (config.get("time_intervals") == null) {
String prefix = "time_intervals.";
config.addDefault(prefix + "1", "1..");
config.addDefault(prefix + "2", "2..");
config.addDefault(prefix + "3", "3..");
config.addDefault(prefix + "4", "4..");
config.addDefault(prefix + "5", "5..");
config.addDefault(prefix + "10", "10 %s");
config.addDefault(prefix + "20", "20 %s");
config.addDefault(prefix + "30", "30 %s");
config.addDefault(prefix + "60", "60 %s");
config.addDefault(prefix + "120", "2 %m");
config.addDefault(prefix + "180", "3 %m");
config.addDefault(prefix + "240", "4 %m");
config.addDefault(prefix + "300", "5 %m");
config.addDefault(prefix + "600", "10 %m");
config.addDefault(prefix + "1200", "20 %m");
config.addDefault(prefix + "1800", "30 %m");
config.addDefault(prefix + "2400", "40 %m");
config.addDefault(prefix + "3000", "50 %m");
config.addDefault(prefix + "3600", "60 %m");
}

config.options().copyDefaults(true);
try {
config.save(configFile);
Language.config = config;
} catch (final Exception e) {
e.printStackTrace();
}
Expand Down
23 changes: 23 additions & 0 deletions src/net/slipcor/pvparena/managers/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ public static boolean configParse(final Arena arena, final Config cfg) {
}
}

if (config.get("time_intervals") == null) {
String prefix = "time_intervals.";
config.addDefault(prefix + "1", "1..");
config.addDefault(prefix + "2", "2..");
config.addDefault(prefix + "3", "3..");
config.addDefault(prefix + "4", "4..");
config.addDefault(prefix + "5", "5..");
config.addDefault(prefix + "10", "10 %s");
config.addDefault(prefix + "20", "20 %s");
config.addDefault(prefix + "30", "30 %s");
config.addDefault(prefix + "60", "60 %s");
config.addDefault(prefix + "120", "2 %m");
config.addDefault(prefix + "180", "3 %m");
config.addDefault(prefix + "240", "4 %m");
config.addDefault(prefix + "300", "5 %m");
config.addDefault(prefix + "600", "10 %m");
config.addDefault(prefix + "1200", "20 %m");
config.addDefault(prefix + "1800", "30 %m");
config.addDefault(prefix + "2400", "40 %m");
config.addDefault(prefix + "3000", "50 %m");
config.addDefault(prefix + "3600", "60 %m");
}

PVPArena.instance.getAgm().setDefaults(arena, config);

config.options().copyDefaults(true);
Expand Down
70 changes: 46 additions & 24 deletions src/net/slipcor/pvparena/runnables/ArenaRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.slipcor.pvparena.core.Language.MSG;
import net.slipcor.pvparena.loadables.ArenaModuleManager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

Expand All @@ -27,30 +28,8 @@
public abstract class ArenaRunnable extends BukkitRunnable {

protected static final Map<Integer, String> MESSAGES = new HashMap<>();

static {
final String seconds = Language.parse(MSG.TIME_SECONDS);
final String minutes = Language.parse(MSG.TIME_MINUTES);
MESSAGES.put(1, "1..");
MESSAGES.put(2, "2..");
MESSAGES.put(3, "3..");
MESSAGES.put(4, "4..");
MESSAGES.put(5, "5..");
MESSAGES.put(10, "10 " + seconds);
MESSAGES.put(20, "20 " + seconds);
MESSAGES.put(30, "30 " + seconds);
MESSAGES.put(60, "60 " + seconds);
MESSAGES.put(120, "2 " + minutes);
MESSAGES.put(180, "3 " + minutes);
MESSAGES.put(240, "4 " + minutes);
MESSAGES.put(300, "5 " + minutes);
MESSAGES.put(600, "10 " + minutes);
MESSAGES.put(1200, "20 " + minutes);
MESSAGES.put(1800, "30 " + minutes);
MESSAGES.put(2400, "40 " + minutes);
MESSAGES.put(3000, "50 " + minutes);
MESSAGES.put(3600, "60 " + minutes);
}
final String sSeconds = Language.parse(MSG.TIME_SECONDS);
final String sMinutes = Language.parse(MSG.TIME_MINUTES);

protected final String message;
protected Integer seconds;
Expand All @@ -75,6 +54,49 @@ protected ArenaRunnable(final String message, final Integer seconds, final Playe
this.arena = arena;
this.global = global;

ConfigurationSection section = null;

if (arena == null) {
if (Language.getConfig() != null) {
section = Language.getConfig().getConfigurationSection("time_intervals");
}
} else {
section = arena.getArenaConfig().getYamlConfiguration().getConfigurationSection("time_intervals");
}
if (section == null) {
PVPArena.instance.getLogger().warning("Language strings 'time_intervals' not found, loading defaults!");
MESSAGES.put(1, "1..");
MESSAGES.put(2, "2..");
MESSAGES.put(3, "3..");
MESSAGES.put(4, "4..");
MESSAGES.put(5, "5..");
MESSAGES.put(10, "10 " + sSeconds);
MESSAGES.put(20, "20 " + sSeconds);
MESSAGES.put(30, "30 " + sSeconds);
MESSAGES.put(60, "60 " + sSeconds);
MESSAGES.put(120, "2 " + sMinutes);
MESSAGES.put(180, "3 " + sMinutes);
MESSAGES.put(240, "4 " + sMinutes);
MESSAGES.put(300, "5 " + sMinutes);
MESSAGES.put(600, "10 " + sMinutes);
MESSAGES.put(1200, "20 " + sMinutes);
MESSAGES.put(1800, "30 " + sMinutes);
MESSAGES.put(2400, "40 " + sMinutes);
MESSAGES.put(3000, "50 " + sMinutes);
MESSAGES.put(3600, "60 " + sMinutes);
} else {
for (String key : section.getKeys(true)) {
String content = section.getString(key);
System.out.println(key + ":" + content);
try {
Integer value = Integer.parseInt(key);
MESSAGES.put(value, content.replace("%m", sMinutes).replace("%s", sSeconds));
} catch (Exception e) {

}
}
}

runTaskTimer(PVPArena.instance, 20L, 20L);
}

Expand Down

1 comment on commit 367a8e3

@mibby
Copy link

@mibby mibby commented on 367a8e3 May 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slipcor This outputs to console when a game starts.

[00:43:52] [Server thread/INFO]: 1:1..
[00:43:52] [Server thread/INFO]: 2:2..
[00:43:52] [Server thread/INFO]: 3:3..
[00:43:52] [Server thread/INFO]: 4:4..
[00:43:52] [Server thread/INFO]: 5:5..
[00:43:52] [Server thread/INFO]: 10:10 %s
[00:43:52] [Server thread/INFO]: 20:20 %s
[00:43:52] [Server thread/INFO]: 30:30 %s
[00:43:52] [Server thread/INFO]: 60:60 %s
[00:43:52] [Server thread/INFO]: 120:2 %m
[00:43:52] [Server thread/INFO]: 180:3 %m
[00:43:52] [Server thread/INFO]: 240:4 %m
[00:43:52] [Server thread/INFO]: 300:5 %m
[00:43:52] [Server thread/INFO]: 600:10 %m
[00:43:52] [Server thread/INFO]: 1200:20 %m
[00:43:52] [Server thread/INFO]: 1800:30 %m
[00:43:52] [Server thread/INFO]: 2400:40 %m
[00:43:52] [Server thread/INFO]: 3000:50 %m
[00:43:52] [Server thread/INFO]: 3600:60 %m

Please sign in to comment.