mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-03 16:38:51 +00:00
warnings
This commit is contained in:
1 parent
837b842c0e
commit
6176a61e05
6 files changed
+143
-157
No files matched your search
@@ -1,8 +1,6 @@
|
|||||||
package org.aubrithehuman.entitybingo;
|
package org.aubrithehuman.entitybingo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class BingoEvent {
|
public class BingoEvent {
|
||||||
|
|
||||||
@@ -10,11 +8,8 @@ public class BingoEvent {
|
|||||||
|
|
||||||
private boolean done = false;
|
private boolean done = false;
|
||||||
|
|
||||||
private final long age;
|
|
||||||
|
|
||||||
public BingoEvent() {
|
public BingoEvent() {
|
||||||
this.entries = new HashMap<>();
|
this.entries = new HashMap<>();
|
||||||
age = System.currentTimeMillis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Integer> getEntries() {
|
public HashMap<String, Integer> getEntries() {
|
||||||
@@ -25,12 +20,12 @@ public class BingoEvent {
|
|||||||
* return 0 if this is first guess, 1 if previous guess, 2 if guess already exists.
|
* return 0 if this is first guess, 1 if previous guess, 2 if guess already exists.
|
||||||
*
|
*
|
||||||
* @param player player
|
* @param player player
|
||||||
* @param value value
|
* @param value value
|
||||||
* @return previous guess
|
* @return previous guess
|
||||||
*/
|
*/
|
||||||
public int addEntry(String player, int value) {
|
public int addEntry(String player, int value) {
|
||||||
if(!entries.containsValue(value)) {
|
if (!entries.containsValue(value)) {
|
||||||
if(!entries.containsKey(player)) {
|
if (!entries.containsKey(player)) {
|
||||||
entries.put(player, value);
|
entries.put(player, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -41,29 +36,6 @@ public class BingoEvent {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int totalGuesses() {
|
|
||||||
return this.entries.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a player based on the entry, if none match then return null;
|
|
||||||
*
|
|
||||||
* @param i value
|
|
||||||
* @return player
|
|
||||||
*/
|
|
||||||
public String getByEntry(int i) {
|
|
||||||
for(String s : entries.keySet()) {
|
|
||||||
if (entries.get(s) == i) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getAge() {
|
|
||||||
return age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,14 +25,15 @@ public class DataManager {
|
|||||||
genDefaultFiles();
|
genDefaultFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
|
private final static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves data into a .yml format
|
* Saves data into a .yml format
|
||||||
|
*
|
||||||
* @param filePath - File's path after <PLUGIN>/Data/
|
* @param filePath - File's path after <PLUGIN>/Data/
|
||||||
* @param map - Map to be saved
|
* @param map - Map to be saved
|
||||||
*/
|
*/
|
||||||
public static void saveData(String filePath, HashMap<String,Object> map) {
|
public static void saveData(String filePath, HashMap<String, Object> map) {
|
||||||
File file = getFile(filePath);
|
File file = getFile(filePath);
|
||||||
PrintWriter writer = null;
|
PrintWriter writer = null;
|
||||||
try {
|
try {
|
||||||
@@ -57,20 +57,22 @@ public class DataManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data back as a HashMap
|
* Gets the data back as a HashMap
|
||||||
|
*
|
||||||
* @param filePath - FilePath of data
|
* @param filePath - FilePath of data
|
||||||
* @return HashMap of data or null
|
* @return HashMap of data or null
|
||||||
*/
|
*/
|
||||||
public static HashMap<String,Object> getData(String filePath) {
|
public static HashMap<String, Object> getData(String filePath) {
|
||||||
File file = getFile(filePath);
|
File file = getFile(filePath);
|
||||||
return getData(file);
|
return getData(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data back as a HashMap
|
* Gets the data back as a HashMap
|
||||||
|
*
|
||||||
* @param file - Data file
|
* @param file - Data file
|
||||||
* @return HashMap of data or null
|
* @return HashMap of data or null
|
||||||
*/
|
*/
|
||||||
public static HashMap<String,Object> getData(File file) {
|
public static HashMap<String, Object> getData(File file) {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
|
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
|
||||||
return null;
|
return null;
|
||||||
@@ -96,6 +98,7 @@ public class DataManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the specified file
|
* Deletes the specified file
|
||||||
|
*
|
||||||
* @param filePath - FilePath of deletion
|
* @param filePath - FilePath of deletion
|
||||||
* @return Boolean of success
|
* @return Boolean of success
|
||||||
*/
|
*/
|
||||||
@@ -117,6 +120,7 @@ public class DataManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts filePath into File
|
* Converts filePath into File
|
||||||
|
*
|
||||||
* @param path - File's path within data folder
|
* @param path - File's path within data folder
|
||||||
* @return File or null
|
* @return File or null
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class EntityBingo extends JavaPlugin {
|
public final class EntityBingo extends JavaPlugin {
|
||||||
|
|
||||||
static EntityBingo instance;
|
static EntityBingo instance;
|
||||||
|
|
||||||
static BingoEvent currrentEvent;
|
static BingoEvent currentEvent;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -33,28 +34,32 @@ public final class EntityBingo extends JavaPlugin {
|
|||||||
|
|
||||||
//Reload scoreboard
|
//Reload scoreboard
|
||||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
try {
|
||||||
//grab only entries with integer values, should be all, but we need to check anyway
|
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||||
Map<String, Integer> filtered = data.entrySet()
|
//grab only entries with integer values, should be all, but we need to check anyway
|
||||||
.stream()
|
Map<String, Integer> filtered = data.entrySet()
|
||||||
.filter(v -> v.getValue() instanceof Integer)
|
.stream()
|
||||||
.collect(Collectors.toMap(
|
.filter(v -> v.getValue() instanceof Integer)
|
||||||
Map.Entry::getKey,
|
.collect(Collectors.toMap(
|
||||||
v -> (int) v.getValue()));
|
Map.Entry::getKey,
|
||||||
|
v -> (int) v.getValue()));
|
||||||
|
|
||||||
//Save to static scoreboard reference
|
//Save to static scoreboard reference
|
||||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||||
|
} catch (ClassCastException ex) {
|
||||||
|
this.getLogger().log(Level.WARNING, "Failed to load scoreboard! Is scoreboard.yml broken?");
|
||||||
|
}
|
||||||
|
|
||||||
this.getLogger().info("EntityBingo loaded.");
|
this.getLogger().info("EntityBingo loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if(currrentEvent != null) {
|
if(currentEvent != null) {
|
||||||
if(!currrentEvent.isDone()) {
|
if(!currentEvent.isDone()) {
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Server Shutting down, clearing Bingo Event without results!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Server Shutting down, clearing Bingo Event without results!");
|
||||||
currrentEvent.setDone();
|
currentEvent.setDone();
|
||||||
currrentEvent = null;
|
currentEvent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,11 +68,11 @@ public final class EntityBingo extends JavaPlugin {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BingoEvent getCurrrentEvent() {
|
public static BingoEvent getCurrentEvent() {
|
||||||
return currrentEvent;
|
return currentEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCurrrentEvent(BingoEvent currrentEvent) {
|
public static void setCurrentEvent(BingoEvent currrentEvent) {
|
||||||
EntityBingo.currrentEvent = currrentEvent;
|
EntityBingo.currentEvent = currrentEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,20 +4,24 @@ import org.aubrithehuman.entitybingo.DataManager;
|
|||||||
import org.aubrithehuman.entitybingo.EntityBingo;
|
import org.aubrithehuman.entitybingo.EntityBingo;
|
||||||
import org.aubrithehuman.entitybingo.listeners.ChatListener;
|
import org.aubrithehuman.entitybingo.listeners.ChatListener;
|
||||||
import org.aubrithehuman.entitybingo.util.Helper;
|
import org.aubrithehuman.entitybingo.util.Helper;
|
||||||
import org.aubrithehuman.entitybingo.util.Pair;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
private final List<String> adminOptions = List.of(new String[] {
|
private final List<String> adminOptions = List.of(new String[]{
|
||||||
"scoreboard",
|
"scoreboard",
|
||||||
"guesses",
|
"guesses",
|
||||||
"reloadscoreboard",
|
"reloadscoreboard",
|
||||||
@@ -25,29 +29,29 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
|||||||
"reset"
|
"reset"
|
||||||
});
|
});
|
||||||
|
|
||||||
private final List<String> options = List.of(new String[] {
|
private final List<String> options = List.of(new String[]{
|
||||||
"scoreboard",
|
"scoreboard",
|
||||||
"guesses"
|
"guesses"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
public EntityBingoCommand(EntityBingo entityBingo) {
|
public EntityBingoCommand(EntityBingo entityBingo) {
|
||||||
entityBingo.getCommand("eb").setExecutor((CommandExecutor) this);
|
entityBingo.getCommand("eb").setExecutor(this);
|
||||||
entityBingo.getCommand("entb").setExecutor((CommandExecutor) this);
|
entityBingo.getCommand("entb").setExecutor(this);
|
||||||
entityBingo.getCommand("entitybingo").setExecutor((CommandExecutor) this);
|
entityBingo.getCommand("entitybingo").setExecutor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) {
|
||||||
final Player p = (Player) sender;
|
final Player p = (Player) sender;
|
||||||
if(args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
if(args[0].equalsIgnoreCase("scoreboard")) {
|
if (args[0].equalsIgnoreCase("scoreboard")) {
|
||||||
//check if we can do anything
|
//check if we can do anything
|
||||||
if(ChatListener.scoreboard == null) {
|
if (ChatListener.scoreboard == null) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(ChatListener.scoreboard.isEmpty()) {
|
if (ChatListener.scoreboard.isEmpty()) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -83,77 +87,81 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
|||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&7" + (i + 1) + ". " + name + ", " + ChatListener.scoreboard.get(s)));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&7" + (i + 1) + ". " + name + ", " + ChatListener.scoreboard.get(s)));
|
||||||
i++;
|
i++;
|
||||||
//page limit
|
//page limit
|
||||||
if(i > 7 + startIndex) break;
|
if (i > 7 + startIndex) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if(args[0].equalsIgnoreCase("guesses")) {
|
} else if (args[0].equalsIgnoreCase("guesses")) {
|
||||||
|
|
||||||
if (EntityBingo.getCurrrentEvent() == null) {
|
if (EntityBingo.getCurrentEvent() == null) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
||||||
}
|
}
|
||||||
|
|
||||||
//print off all guesses
|
//print off all guesses
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("List of all guesses in the " + (EntityBingo.getCurrrentEvent().isDone() ? "previous" : "current") + " event:"));
|
p.sendMessage(Helper.chatLabel() + Helper.color("List of all guesses in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event:"));
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("----------------------------------"));
|
p.sendMessage(Helper.chatLabel() + Helper.color("----------------------------------"));
|
||||||
|
|
||||||
for (String s : EntityBingo.getCurrrentEvent().getEntries().keySet()) {
|
for (String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||||
String name = Bukkit.getOfflinePlayer(UUID.fromString(s)).getName();
|
String name = Bukkit.getOfflinePlayer(UUID.fromString(s)).getName();
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&7 - " + name + ": " + EntityBingo.getCurrrentEvent().getEntries().get(s)));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&7 - " + name + ": " + EntityBingo.getCurrentEvent().getEntries().get(s)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if(args[0].equalsIgnoreCase("purge")) {
|
} else if (args[0].equalsIgnoreCase("purge")) {
|
||||||
if (!p.hasPermission("EntityBingo.admin")) {
|
if (!p.hasPermission("EntityBingo.admin")) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(EntityBingo.getCurrrentEvent() == null) {
|
if (EntityBingo.getCurrentEvent() == null) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
||||||
}
|
}
|
||||||
//clear entry pool
|
//clear entry pool
|
||||||
EntityBingo.getCurrrentEvent().getEntries().clear();
|
EntityBingo.getCurrentEvent().getEntries().clear();
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
||||||
return true;
|
return true;
|
||||||
} else if(args[0].equalsIgnoreCase("reset")) {
|
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||||
if (!p.hasPermission("EntityBingo.admin")) {
|
if (!p.hasPermission("EntityBingo.admin")) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear event
|
//clear event
|
||||||
EntityBingo.setCurrrentEvent(null);
|
EntityBingo.setCurrentEvent(null);
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cEnded current bingo event."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cEnded current bingo event."));
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEvent forcefully ended by and admin!"));
|
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEvent forcefully ended by and admin!"));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEvent forcefully ended by and admin!"));
|
EntityBingo.getInstance().getLogger().info(Helper.color("&cEvent forcefully ended by and admin!"));
|
||||||
return true;
|
return true;
|
||||||
} else if(args[0].equalsIgnoreCase("reloadscoreboard")) {
|
} else if (args[0].equalsIgnoreCase("reloadscoreboard")) {
|
||||||
if (!p.hasPermission("EntityBingo.admin")) {
|
if (!p.hasPermission("EntityBingo.admin")) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
try {
|
||||||
//grab only entries with integer values, should be all, but we need to check anyway
|
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||||
Map<String, Integer> filtered = data.entrySet()
|
//grab only entries with integer values, should be all, but we need to check anyway
|
||||||
.stream()
|
Map<String, Integer> filtered = data.entrySet()
|
||||||
.filter(v -> v.getValue() instanceof Integer)
|
.stream()
|
||||||
.collect(Collectors.toMap(
|
.filter(v -> v.getValue() instanceof Integer)
|
||||||
Map.Entry::getKey,
|
.collect(Collectors.toMap(
|
||||||
v -> (int) v.getValue()));
|
Map.Entry::getKey,
|
||||||
|
v -> (int) v.getValue()));
|
||||||
|
|
||||||
//Save to static scoreboard reference
|
//Save to static scoreboard reference
|
||||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||||
|
|
||||||
//clear event
|
//clear event
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cAdmin reloaded scoreboard!"));
|
EntityBingo.getInstance().getLogger().info(Helper.color("&cAdmin reloaded scoreboard!"));
|
||||||
|
} catch (ClassCastException ex) {
|
||||||
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is scoreboard.yml broken?");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError. Subcommand not found"));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cError. Subcommand not found"));
|
||||||
@@ -163,12 +171,11 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
public List<String> onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) {
|
||||||
final Player p = (Player) sender;
|
final Player p = (Player) sender;
|
||||||
if(args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
if(args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
if (p.hasPermission("EntityBingo.admin")) {
|
if (p.hasPermission("EntityBingo.admin")) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.aubrithehuman.entitybingo.listeners;
|
|||||||
import org.aubrithehuman.entitybingo.BingoEvent;
|
import org.aubrithehuman.entitybingo.BingoEvent;
|
||||||
import org.aubrithehuman.entitybingo.DataManager;
|
import org.aubrithehuman.entitybingo.DataManager;
|
||||||
import org.aubrithehuman.entitybingo.EntityBingo;
|
import org.aubrithehuman.entitybingo.EntityBingo;
|
||||||
import org.aubrithehuman.entitybingo.command.EntityBingoCommand;
|
|
||||||
import org.aubrithehuman.entitybingo.util.Helper;
|
import org.aubrithehuman.entitybingo.util.Helper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -26,16 +25,16 @@ public class ChatListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onBroadcast(BroadcastMessageEvent e) {
|
public void onBroadcast(BroadcastMessageEvent e) {
|
||||||
boolean matchFound = e.getMessage().equals(EntityBingo.getInstance().getConfig().getString("startMessage"));
|
boolean matchFound = e.getMessage().equals(EntityBingo.getInstance().getConfig().getString("startMessage"));
|
||||||
boolean matchFound2 = false;
|
boolean matchFound2;
|
||||||
if(matchFound) {
|
if(matchFound) {
|
||||||
//start the event, only if previous one is marked as done
|
//start the event, only if previous one is marked as done
|
||||||
if(EntityBingo.getCurrrentEvent() == null) {
|
if(EntityBingo.getCurrentEvent() == null) {
|
||||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
EntityBingo.setCurrentEvent(new BingoEvent());
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||||
} else {
|
} else {
|
||||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
if(EntityBingo.getCurrentEvent().isDone()) {
|
||||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
EntityBingo.setCurrentEvent(new BingoEvent());
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||||
} else {
|
} else {
|
||||||
@@ -43,7 +42,6 @@ public class ChatListener implements Listener {
|
|||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
//check for end broadcast
|
//check for end broadcast
|
||||||
String check = EntityBingo.getInstance().getConfig().getString("endMessage");
|
String check = EntityBingo.getInstance().getConfig().getString("endMessage");
|
||||||
@@ -51,8 +49,8 @@ public class ChatListener implements Listener {
|
|||||||
String p1 = e.getMessage().substring(0, 23);
|
String p1 = e.getMessage().substring(0, 23);
|
||||||
matchFound2 = p1.equals(check);
|
matchFound2 = p1.equals(check);
|
||||||
if(matchFound2) {
|
if(matchFound2) {
|
||||||
//check if we have an bingo event happening
|
//check if we have a bingo event happening
|
||||||
if(EntityBingo.getCurrrentEvent() != null) {
|
if(EntityBingo.getCurrentEvent() != null) {
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
||||||
|
|
||||||
//extract the result number
|
//extract the result number
|
||||||
@@ -66,7 +64,7 @@ public class ChatListener implements Listener {
|
|||||||
i = Integer.parseInt(numberOnly);
|
i = Integer.parseInt(numberOnly);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
||||||
EntityBingo.getCurrrentEvent().setDone();
|
EntityBingo.getCurrentEvent().setDone();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,8 +72,8 @@ public class ChatListener implements Listener {
|
|||||||
//look for winners
|
//look for winners
|
||||||
List<String> winners = new ArrayList<>();
|
List<String> winners = new ArrayList<>();
|
||||||
if(i >= 0) {
|
if(i >= 0) {
|
||||||
for(String s : EntityBingo.getCurrrentEvent().getEntries().keySet()) {
|
for(String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||||
if(EntityBingo.getCurrrentEvent().getEntries().get(s) == i) {
|
if(EntityBingo.getCurrentEvent().getEntries().get(s) == i) {
|
||||||
winners.add(s);
|
winners.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,42 +87,46 @@ public class ChatListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||||
if(raw.containsKey("scores")) {
|
if(raw.containsKey("scores")) {
|
||||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
try {
|
||||||
for (String s : winners) {
|
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||||
//broadcast winner
|
for (String s : winners) {
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
//broadcast winner
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||||
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||||
|
|
||||||
//get player uuid and save their wins
|
//get player uuid and save their wins
|
||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if(data != null) {
|
if (data != null) {
|
||||||
if(data.containsKey(uuid.toString())) {
|
if (data.containsKey(uuid.toString())) {
|
||||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||||
|
} else {
|
||||||
|
data.put(uuid.toString(), 1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data.put(uuid.toString(), 1);
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(data != null) {
|
if (data != null) {
|
||||||
//save scoreboard
|
//save scoreboard
|
||||||
HashMap<String, Object> out = new HashMap<String, Object>();
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
out.put("scores", data);
|
out.put("scores", data);
|
||||||
DataManager.saveData("scoreboard.yml", out);
|
DataManager.saveData("scoreboard.yml", out);
|
||||||
|
|
||||||
//grab only entries with integer values, should be all but we need to check anyway
|
//grab only entries with integer values, should be all, but we need to check anyway
|
||||||
Map<String, Integer> filtered = data.entrySet()
|
Map<String, Integer> filtered = data.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(v -> v.getValue() instanceof Integer)
|
.filter(v -> v.getValue() instanceof Integer)
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
Map.Entry::getKey,
|
Map.Entry::getKey,
|
||||||
v -> (int) v.getValue()));
|
v -> (int) v.getValue()));
|
||||||
|
|
||||||
//Save to static scoreboard reference
|
//Save to static scoreboard reference
|
||||||
scoreboard = Helper.sortData(filtered);
|
scoreboard = Helper.sortData(filtered);
|
||||||
|
}
|
||||||
|
} catch (ClassCastException ex) {
|
||||||
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is scoreboard.yml broken?");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
@@ -142,7 +144,7 @@ public class ChatListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//save scoreboard
|
//save scoreboard
|
||||||
HashMap<String, Object> out = new HashMap<String, Object>();
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
out.put("scores", data);
|
out.put("scores", data);
|
||||||
DataManager.saveData("scoreboard.yml", out);
|
DataManager.saveData("scoreboard.yml", out);
|
||||||
}
|
}
|
||||||
@@ -150,7 +152,7 @@ public class ChatListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityBingo.getCurrrentEvent().setDone();
|
EntityBingo.getCurrentEvent().setDone();
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -158,10 +160,6 @@ public class ChatListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(matchFound2) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,8 +168,8 @@ public class ChatListener implements Listener {
|
|||||||
public void onChat(AsyncPlayerChatEvent e) {
|
public void onChat(AsyncPlayerChatEvent e) {
|
||||||
//Entry detection
|
//Entry detection
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
||||||
if (EntityBingo.getCurrrentEvent() != null) {
|
if (EntityBingo.getCurrentEvent() != null) {
|
||||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
if(EntityBingo.getCurrentEvent().isDone()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String str = e.getMessage();
|
String str = e.getMessage();
|
||||||
@@ -193,7 +191,7 @@ public class ChatListener implements Listener {
|
|||||||
|
|
||||||
if (guess > 0) {
|
if (guess > 0) {
|
||||||
//do the entry
|
//do the entry
|
||||||
int result = EntityBingo.getCurrrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
|
int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
|
||||||
//feedback to entrant
|
//feedback to entrant
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case 0 -> e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&aYou have entered with the guess " + guess + "."));
|
case 0 -> e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&aYou have entered with the guess " + guess + "."));
|
||||||
|
|||||||
@@ -3,31 +3,31 @@ package org.aubrithehuman.entitybingo.util;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Helper {
|
public class Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sorts a map from the highest value to the lowest value
|
* sorts a map from the highest value to the lowest value
|
||||||
* @param data
|
*
|
||||||
* @return
|
* @param data map of uuid and values
|
||||||
|
* @return sorted map
|
||||||
*/
|
*/
|
||||||
public static HashMap<String, Integer> sortData(Map<String, Integer> data) {
|
public static HashMap<String, Integer> sortData(Map<String, Integer> data) {
|
||||||
|
|
||||||
// Create a list from elements of HashMap
|
// Create a list from elements of HashMap
|
||||||
List<Map.Entry<String, Integer> > list
|
List<Map.Entry<String, Integer>> list
|
||||||
= new LinkedList<Map.Entry<String, Integer> >(
|
= new LinkedList<>(
|
||||||
data.entrySet());
|
data.entrySet());
|
||||||
|
|
||||||
// Sort the list using lambda expression
|
// Sort the list using lambda expression
|
||||||
Collections.sort(
|
Collections.sort(
|
||||||
list,
|
list,
|
||||||
(i1,
|
(i1,
|
||||||
i2) -> (- i1.getValue().compareTo(i2.getValue())));
|
i2) -> (-i1.getValue().compareTo(i2.getValue())));
|
||||||
|
|
||||||
// put data from sorted list to hashmap
|
// put data from sorted list to hashmap
|
||||||
HashMap<String, Integer> temp
|
HashMap<String, Integer> temp
|
||||||
= new LinkedHashMap<String, Integer>();
|
= new LinkedHashMap<>();
|
||||||
for (Map.Entry<String, Integer> aa : list) {
|
for (Map.Entry<String, Integer> aa : list) {
|
||||||
temp.put(aa.getKey(), aa.getValue());
|
temp.put(aa.getKey(), aa.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user