summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/util
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2021-10-29 19:57:40 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2021-10-29 19:57:40 -0400
commit4188dadbe3825178349417ba8d594bca00761dc4 (patch)
treea69504786a52d1263cd8face36e93608dd440d12 /src/main/java/net/tylermurphy/hideAndSeek/util
parent1.3.1 build 2 (diff)
downloadkenshinshideandseek-4188dadbe3825178349417ba8d594bca00761dc4.tar.gz
kenshinshideandseek-4188dadbe3825178349417ba8d594bca00761dc4.tar.bz2
kenshinshideandseek-4188dadbe3825178349417ba8d594bca00761dc4.zip
1.3.1 build 3
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/util')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/Board.java108
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java117
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/Util.java86
3 files changed, 249 insertions, 62 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java
index 17a60b1..59b9ac8 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java
@@ -26,7 +26,8 @@ public class Board {
private List<String> Hider, Seeker, Spectator;
private Map<String, Player> playerList = new HashMap<String,Player>();
-
+ private Map<String, CustomBoard> customBoards = new HashMap<String, CustomBoard>();
+
public boolean isPlayer(Player player) {
return playerList.containsKey(player.getName());
}
@@ -145,64 +146,81 @@ public class Board {
seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
}
}
-
- private void createLobbyBoard(Player player) {
-
- Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
- Objective obj = board.registerNewObjective("LobbyScoreboard", "dummy",
- ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK"));
- createTeamsForBoard(board);
- obj.setDisplaySlot(DisplaySlot.SIDEBAR);
- Score waiting = obj.getScore("Waiting to start...");
- waiting.setScore(6);
- Score blank1 = obj.getScore(ChatColor.RESET.toString());
- blank1.setScore(5);
- Score players = obj.getScore("Players: "+playerList.values().size());
- players.setScore(4);
- Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString());
- blank2.setScore(3);
- Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent());
- seeker.setScore(2);
- Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDER%" + ChatColor.WHITE + getHiderPercent());
- hider.setScore(1);
- player.setScoreboard(board);
+
+ public void createLobbyBoard(Player player) {
+ createLobbyBoard(player, true);
}
-
- private void createGameBoard(Player player) {
- Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
- Objective obj = board.registerNewObjective("GameScoreboard", "dummy",
- ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK"));
- createTeamsForBoard(board);
- obj.setDisplaySlot(DisplaySlot.SIDEBAR);
- Score team = obj.getScore("Team: " + getTeam(player));
- team.setScore(6);
- Score blank1 = obj.getScore(ChatColor.RESET.toString());
- blank1.setScore(5);
- if(gameLength > 0) {
- Score waiting = obj.getScore(ChatColor.GREEN + "Time Left: " + ChatColor.WHITE + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s");
- waiting.setScore(4);
- Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString());
- blank2.setScore(3);
+
+ private void createLobbyBoard(Player player, boolean recreate) {
+ CustomBoard board = customBoards.get(player.getName());
+ if(recreate) {
+ board = new CustomBoard(player, "&l&eHIDE AND SEEK");
+ board.updateTeams();
}
- Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size());
- seeker.setScore(2);
- Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDERS:" + ChatColor.WHITE + " " + Hider.size());
- hider.setScore(1);
- player.setScoreboard(board);
+ board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent());
+ board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent());
+ board.addBlank(recreate);
+ board.setLine("players", "Players: " + playerList.values().size());
+ board.addBlank(recreate);
+ board.setLine("waiting", "Waiting to start...");
+ board.display();
+ customBoards.put(player.getName(), board);
+ }
+
+ public void createGameBoard(Player player){
+ createGameBoard(player, true);
+ }
+
+ private void createGameBoard(Player player, boolean recreate){
+ CustomBoard board = customBoards.get(player.getName());
+ if(recreate) {
+ board = new CustomBoard(player, "&l&eHIDE AND SEEK");
+ board.updateTeams();
+ }
+ board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size());
+ board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size());
+ board.addBlank(recreate);
+ if(glowEnabled){
+ if(Main.plugin.glow == null || !Main.plugin.glow.isRunning())
+ board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive");
+ else
+ board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active");
+ }
+ if(tauntEnabled && tauntCountdown){
+ if(Main.plugin.taunt == null)
+ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s");
+ else if(!Main.plugin.taunt.isRunning())
+ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s");
+ else
+ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active");
+ }
+ if(glowEnabled || (tauntEnabled && tauntCountdown))
+ board.addBlank(recreate);
+ board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s");
+ board.addBlank(recreate);
+ board.setLine("team", "Team: " + getTeam(player));
+ board.display();
+ customBoards.put(player.getName(), board);
}
public void removeBoard(Player player) {
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
+ customBoards.remove(player.getName());
}
public void reloadLobbyBoards() {
for(Player player : playerList.values())
- createLobbyBoard(player);
+ createLobbyBoard(player, false);
}
public void reloadGameBoards() {
for(Player player : playerList.values())
- createGameBoard(player);
+ createGameBoard(player, false);
+ }
+
+ public void reloadBoardTeams() {
+ for(CustomBoard board : customBoards.values())
+ board.updateTeams();
}
private String getSeekerPercent() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java
new file mode 100644
index 0000000..a01d965
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java
@@ -0,0 +1,117 @@
+package net.tylermurphy.hideAndSeek.util;
+
+import net.tylermurphy.hideAndSeek.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.scoreboard.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+
+public class CustomBoard {
+
+ private final Scoreboard board;
+ private final Objective obj;
+ private final Player player;
+ private final Map<String,Line> LINES;
+ private int blanks;
+
+ public CustomBoard(Player player, String title){
+ this.board = Bukkit.getScoreboardManager().getNewScoreboard();
+ this.LINES = new HashMap<String,Line>();
+ this.player = player;
+ this.obj = board.registerNewObjective(
+ "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
+ this.blanks = 0;
+ }
+
+ public void updateTeams() {
+ try{ board.registerNewTeam("Hider"); } catch (Exception e){}
+ try{ board.registerNewTeam("Seeker"); } catch (Exception e){}
+ Team hiderTeam = board.getTeam("Hider");
+ for(String entry : hiderTeam.getEntries())
+ hiderTeam.removeEntry(entry);
+ for(Player player : Main.plugin.board.getHiders())
+ hiderTeam.addEntry(player.getName());
+ Team seekerTeam = board.getTeam("Seeker");
+ for(String entry : seekerTeam.getEntries())
+ seekerTeam.removeEntry(entry);
+ for(Player player : Main.plugin.board.getSeekers())
+ seekerTeam.addEntry(player.getName());
+ if(nametagsVisible) {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
+ } else {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ }
+ hiderTeam.setColor(ChatColor.GOLD);
+ seekerTeam.setColor(ChatColor.RED);
+ }
+
+ public void setLine(String key, String message){
+ Line line = LINES.get(key);
+ if(line == null)
+ addLine(key, message);
+ else
+ updateLine(key, message);
+ }
+
+ private void addLine(String key, String message){
+ Score score = obj.getScore(message);
+ score.setScore(LINES.values().size()+1);
+ Line line = new Line(LINES.values().size()+1, message);
+ LINES.put(key, line);
+ }
+
+ public void addBlank(boolean value){
+ if(!value) return;
+ String temp = "";
+ for(int i = 0; i <= blanks; i ++)
+ temp += ChatColor.RESET;
+ blanks++;
+ addLine("blank"+blanks, temp);
+ }
+
+ private void updateLine(String key, String message){
+ Line line = LINES.get(key);
+ board.resetScores(line.getMessage());
+ line.setMessage(message);
+ Score newScore = obj.getScore(message);
+
+ newScore.setScore(line.getScore());
+ }
+
+ public void display() {
+ obj.setDisplaySlot(DisplaySlot.SIDEBAR);
+ player.setScoreboard(board);
+ }
+
+}
+
+class Line {
+
+ private int score;
+ private String message;
+
+ public Line(int score, String message){
+ this.score = score;
+ this.message = message;
+ }
+
+ public int getScore() {
+ return score;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java
index 9c6c1eb..3ab04a9 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java
@@ -3,14 +3,25 @@ package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.PotionMeta;
+import org.bukkit.potion.PotionData;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.potion.PotionType;
public class Util {
@@ -39,27 +50,68 @@ public class Util {
}, delay);
}
- public YamlConfiguration loadDefaultConfig(String name) {
+ public static void resetPlayer(Player player) {
+ player.getInventory().clear();
+ for (PotionEffect effect : player.getActivePotionEffects()) {
+ player.removePotionEffect(effect.getType());
+ }
+ player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
+ if (Main.plugin.board.isSeeker(player)) {
+ ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD, 1);
+ diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
+ ItemMeta diamondSwordMeta = diamondSword.getItemMeta();
+ diamondSwordMeta.setDisplayName("Seeker Sword");
+ diamondSwordMeta.setUnbreakable(true);
+ diamondSword.setItemMeta(diamondSwordMeta);
+ player.getInventory().addItem(diamondSword);
+
+ ItemStack wackyStick = new ItemStack(Material.STICK, 1);
+ wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3);
+ ItemMeta wackyStickMeta = wackyStick.getItemMeta();
+ wackyStickMeta.setDisplayName("Wacky Stick");
+ wackyStick.setItemMeta(wackyStickMeta);
+ player.getInventory().addItem(wackyStick);
+
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false));
+ player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false));
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false));
+ player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false));
+ } else if (Main.plugin.board.isHider(player)) {
+ ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1);
+ stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
+ ItemMeta stoneSwordMeta = stoneSword.getItemMeta();
+ stoneSwordMeta.setDisplayName("Hider Sword");
+ stoneSwordMeta.setUnbreakable(true);
+ stoneSword.setItemMeta(stoneSwordMeta);
+ player.getInventory().addItem(stoneSword);
- YamlConfiguration defaultConfig = null;
+ ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION, 1);
+ PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta();
+ splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN));
+ splashPotion.setItemMeta(splashPotionMeta);
+ player.getInventory().addItem(splashPotion);
- InputStream deafult_stream = null;
- InputStreamReader default_stream_reader = null;
- try {
- deafult_stream = Class.class.getResourceAsStream(name + ".yml");
- default_stream_reader = new InputStreamReader(deafult_stream);
- defaultConfig = YamlConfiguration.loadConfiguration(default_stream_reader);
- } catch (Exception e) {
- // No Issue Here
- } finally {
- try {
- deafult_stream.close();
- default_stream_reader.close();
- } catch (IOException e) {
- e.printStackTrace();
+ ItemStack potion = new ItemStack(Material.POTION, 2);
+ PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
+ potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL));
+ potion.setItemMeta(potionMeta);
+ player.getInventory().addItem(potion);
+
+ if(glowEnabled) {
+ ItemStack snowball = new ItemStack(Material.SNOWBALL, 1);
+ ItemMeta snowballMeta = snowball.getItemMeta();
+ snowballMeta.setDisplayName("Glow Powerup");
+ List<String> snowballLore = new ArrayList<String>();
+ snowballLore.add("Throw to make all seekers glow");
+ snowballLore.add("Last 30s, all hiders can see it");
+ snowballLore.add("Time stacks on multi use");
+ snowballMeta.setLore(snowballLore);
+ snowball.setItemMeta(snowballMeta);
+ player.getInventory().addItem(snowball);
}
+
+ player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
- return defaultConfig;
}
} \ No newline at end of file