summaryrefslogtreewikicommitdiff
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-05-05 12:22:04 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2022-05-05 12:22:04 -0400
commit36027e007e512d54e7e3cd8fb66774cc9c5e43f2 (patch)
tree3ebf0f2868f8b2be243124f7f69e8681a7ff0124
parentactionbar messages (diff)
downloadkenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.tar.gz
kenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.tar.bz2
kenshinshideandseek-36027e007e512d54e7e3cd8fb66774cc9c5e43f2.zip
countdown titles, and possible config save for utf8
Diffstat (limited to '')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java11
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java29
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/Game.java37
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/CountdownDisplay.java26
-rw-r--r--src/main/resources/config.yml13
5 files changed, 87 insertions, 29 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index 79571fc..ee2f8b6 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -22,6 +22,8 @@ package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.util.CountdownDisplay;
import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -136,6 +138,9 @@ public class Config {
public static XSound
ringingSound,
heartbeatSound;
+
+ public static CountdownDisplay
+ countdownDisplay;
public static void loadConfig() {
@@ -249,6 +254,12 @@ public class Config {
locale = config.getString("locale", "local");
blockedCommands = config.getStringList("blockedCommands");
leaveOnEnd = config.getBoolean("leaveOnEnd");
+ try {
+ countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
+ } catch (IllegalArgumentException e){
+ countdownDisplay = CountdownDisplay.CHAT;
+ Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
+ }
blockedInteracts = new ArrayList<>();
List<String> tempInteracts = config.getStringList("blockedInteracts");
for(String id : tempInteracts){
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 3546fa8..0168dc5 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -52,16 +52,20 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file);
- InputStream input = Main.plugin.getResource(file.getName());
- if(input == null){
+ FileInputStream input = null;
+ try{
+ input = new FileInputStream(file);
+ } catch (Exception e){
throw new RuntimeException("Could not create input stream for "+file.getPath());
}
- InputStreamReader reader = new InputStreamReader(input);
+
+ InputStreamReader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{
input.close();
reader.close();
- } catch (IOException ignored){}
+ } catch (IOException ignored){
+ }
}
public ConfigManager(String filename, String defaultFilename){
@@ -221,7 +225,7 @@ public class ConfigManager {
while((c = reader.read()) != -1){
textBuilder.append((char) c);
}
- String yamlString = textBuilder.toString();
+ String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
Map<String, Object> temp = config.getValues(true);
for(Map.Entry<String, Object> entry: temp.entrySet()){
if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List){
@@ -246,26 +250,25 @@ public class ConfigManager {
if(entry.getValue() instanceof List){
if(((List<?>) entry.getValue()).isEmpty()) continue;
replace = "[";
- for(Object o : (List<Object>)entry.getValue()){
- replace = replace + o.toString() + ", ";
+ for(Object o : (List<?>)entry.getValue()){
+ replace = replace + new String(o.toString().getBytes(), StandardCharsets.UTF_8) + ", ";
}
replace = replace.substring(0, replace.length()-2);
replace = replace + "]";
} else {
- replace = entry.getValue().toString();
+ replace = new String(entry.getValue().toString().getBytes(), StandardCharsets.UTF_8);
}
if(entry.getValue() instanceof String){
replace = "\"" + replace + "\"";
}
StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace);
- yamlString = builder.toString();
+ yamlString = new String(builder.toString().getBytes(), StandardCharsets.UTF_8);
}
}
- OutputStream os = new FileOutputStream(file);
- PrintWriter out = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8), true);
- out.print(yamlString);
- out.close();
+ Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
+ fileWriter.write(yamlString);
+ fileWriter.close();
} catch (IOException e){
e.printStackTrace();
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
index 992570d..a886247 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
@@ -28,9 +28,7 @@ import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database;
-import net.tylermurphy.hideAndSeek.util.Status;
-import net.tylermurphy.hideAndSeek.util.Version;
-import net.tylermurphy.hideAndSeek.util.WinType;
+import net.tylermurphy.hideAndSeek.util.*;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
@@ -41,13 +39,11 @@ import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.util.Packet;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-import javax.swing.*;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
@@ -137,16 +133,18 @@ public class Game {
Board.reloadGameBoards();
status = Status.STARTING;
int temp = gameId;
- broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
- sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
+ if(countdownDisplay != CountdownDisplay.TITLE) {
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30), gameId, 0);
+ }
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
+ sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
if(temp != gameId) return;
- broadcastMessage(messagePrefix + message("START"));
+ sendHideCountdownMessage(messagePrefix + message("START"), gameId, 0);
for(Player player : Board.getPlayers()) resetPlayer(player);
status = Status.PLAYING;
}, 20 * 30);
@@ -422,12 +420,19 @@ public class Game {
}
}
- private static void sendDelayedActionbar(String message, int gameId, int delay) {
+ private static void sendHideCountdownMessage(String message, int gameId, int delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
if(gameId == Game.gameId){
for(Player player : Board.getPlayers()){
- ActionBar.clearActionBar(player);
- ActionBar.sendActionBar(player,message);
+ if(countdownDisplay == CountdownDisplay.CHAT){
+ player.sendMessage(message);
+ } else if(countdownDisplay == CountdownDisplay.ACTIONBAR){
+ ActionBar.clearActionBar(player);
+ ActionBar.sendActionBar(player,message);
+ } else if(countdownDisplay == CountdownDisplay.TITLE){
+ Titles.clearTitle(player);
+ Titles.sendTitle(player, 10, 71, 10, null, message);
+ }
}
}
}, delay);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CountdownDisplay.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CountdownDisplay.java
new file mode 100644
index 0000000..477f7ca
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CountdownDisplay.java
@@ -0,0 +1,26 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2022 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.util;
+
+public enum CountdownDisplay {
+ CHAT,
+ ACTIONBAR,
+ TITLE
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 8e52343..cdf88ac 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -14,6 +14,19 @@ gameLength: 1200
# default: true
announceMessagesToNonPlayers: true
+# When the game is starting, the plugin will state there is x seconds left to hide.
+# You change where countdown messages to be displayed: in the chat, action bar, or a title.
+# Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT.
+#
+# CHAT - Messages will be displayed in the chat
+#
+# ACTIONBAR - Messages will be displayed in the action bar (area above the hotbar)
+#
+# TITLE - Messages will be displayed as a title
+#
+# default: CHAT
+hideCountdownDisplay: CHAT
+
# Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless.
# default: false
nametagsVisible: false