mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-01 15:58:46 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a1fab48e5 | ||
|
|
37823ee981 | ||
|
|
e2fb8a36a0 | ||
|
|
16f112febe | ||
|
|
cca3f3b348 | ||
|
|
56efdb4892 | ||
|
|
3b0573b712 | ||
|
|
6fcbf28d88 |
No files matched your search
@@ -2,3 +2,9 @@
|
||||
A fun game with the ClearLag plugin!
|
||||
|
||||
Try and guess how many entities get deleted every time it goes off. Designed for AlathraMC, however it should work just fine anywhere. Can be configured to any plugin like ClearLag by changing the config.
|
||||
|
||||
If using ClearLag, make sure these two config options are changed. Then give the default group the permission "lagg.broadcast".
|
||||
```
|
||||
use-permission-for-broadcasts: true
|
||||
permission: lagg.broadcast
|
||||
```
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.aubrithehuman</groupId>
|
||||
<artifactId>EntityBingo</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.0.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EntityBingo</name>
|
||||
|
||||
@@ -8,8 +8,11 @@ public class BingoEvent {
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
private final long age;
|
||||
|
||||
public BingoEvent() {
|
||||
this.entries = new HashMap<>();
|
||||
age = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getEntries() {
|
||||
@@ -43,4 +46,8 @@ public class BingoEvent {
|
||||
public void setDone() {
|
||||
this.done = true;
|
||||
}
|
||||
|
||||
public long getAge() {
|
||||
return this.age;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
package org.aubrithehuman.entitybingo;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.event.entity.EntityTameEvent;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@@ -9,6 +14,8 @@ import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Manages file IO & Deletion for other data classes.
|
||||
@@ -20,12 +27,9 @@ public class DataManager {
|
||||
|
||||
public static void init() {
|
||||
plugin = EntityBingo.getInstance();
|
||||
|
||||
createFolders();
|
||||
genDefaultFiles();
|
||||
}
|
||||
|
||||
private final static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
|
||||
private static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
|
||||
|
||||
/**
|
||||
* Saves data into a .yml format
|
||||
@@ -34,25 +38,62 @@ public class DataManager {
|
||||
* @param map - Map to be saved
|
||||
*/
|
||||
public static void saveData(String filePath, HashMap<String, Object> map) {
|
||||
File file = getFile(filePath);
|
||||
PrintWriter writer = null;
|
||||
// File file = getFile(filePath);
|
||||
// Bukkit.getLogger().log(Level.WARNING, "scoreboard.yml printout1");
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isAbsolute: " + (file == null ? "" : file.isAbsolute()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isFile: " + (file == null ? "" : file.isFile()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print canWrite: " + (file == null ? "" : file.canWrite()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print exists: " + (file == null ? "" : file.exists()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print canRead: " + (file == null ? "" : file.canRead()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isHidden: " + (file == null ? "" : file.isHidden()));
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print path: " + (file == null ? "" : file.getPath()));
|
||||
// PrintWriter writer = null;
|
||||
// try {
|
||||
// file.setWritable(true);
|
||||
// Bukkit.getLogger().log(Level.WARNING, "scoreboard.yml printout2");
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isAbsolute: " + file.isAbsolute());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isFile: " + file.isFile());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print canWrite: " + file.canWrite());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print exists: " + file.exists());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print canRead: " + file.canRead());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print isHidden: " + file.isHidden());
|
||||
// Bukkit.getLogger().log(Level.WARNING, "Error Print path: " + file.getPath());
|
||||
// writer = new PrintWriter(file);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered FileNotFound error when creating PrintWriter for " + filePath);
|
||||
// e.printStackTrace();
|
||||
// return;
|
||||
// } catch (NullPointerException e) {
|
||||
// EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered NullPointer error when creating PrintWriter for " + filePath);
|
||||
// e.printStackTrace();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (options == null) {
|
||||
// options = new DumperOptions();
|
||||
// options.setIndent(2);
|
||||
// options.setPrettyFlow(true);
|
||||
// options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
// }
|
||||
//
|
||||
// Yaml yaml = new Yaml(options);
|
||||
// yaml.dump(map, writer);
|
||||
// writer.flush();
|
||||
// writer.close();
|
||||
|
||||
MemorySection data = (MemorySection) EntityBingo.getInstance().getConfig().get("scores");
|
||||
Map<String, Object> raw = (Map<String, Object>) map.get("scores");
|
||||
for (String s : raw.keySet()) {
|
||||
Bukkit.getLogger().info("saving: " + s + ": " + raw.get(s));
|
||||
data.set(s, raw.get(s));
|
||||
}
|
||||
Bukkit.getLogger().info(data.toString());
|
||||
|
||||
try {
|
||||
writer = new PrintWriter(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().info("Encountered error when creating PrintWriter for " + filePath);
|
||||
return;
|
||||
EntityBingo.getInstance().getConfig().save("plugins" + File.separator + "EntityBingo" + File.separator + "config.yml");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (options == null) {
|
||||
options = new DumperOptions();
|
||||
options.setIndent(2);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml(options);
|
||||
yaml.dump(map, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +102,7 @@ public class DataManager {
|
||||
* @param filePath - FilePath of data
|
||||
* @return HashMap of data or null
|
||||
*/
|
||||
public static HashMap<String, Object> getData(String filePath) {
|
||||
public static Map<String, Object> getData(String filePath) {
|
||||
File file = getFile(filePath);
|
||||
return getData(file);
|
||||
}
|
||||
@@ -72,28 +113,40 @@ public class DataManager {
|
||||
* @param file - Data file
|
||||
* @return HashMap of data or null
|
||||
*/
|
||||
public static HashMap<String, Object> getData(File file) {
|
||||
if (!file.exists()) {
|
||||
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
|
||||
return null;
|
||||
}
|
||||
public static Map<String, Object> getData(File file) {
|
||||
// if (!file.exists()) {
|
||||
// EntityBingo.getInstance().getLogger().log(Level.WARNING, "Attempted to retrieve non-existant file: " + file.getPath());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// InputStream inputStream = null;
|
||||
// try {
|
||||
// inputStream = new FileInputStream(file);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered error when creating FileInputStream for " + file.getPath());
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// Yaml yaml = new Yaml();
|
||||
// HashMap<String, Object> data = yaml.load(inputStream);
|
||||
// try {
|
||||
// inputStream.close();
|
||||
// } catch (IOException e) {
|
||||
// EntityBingo.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
Bukkit.getLogger().info("Encountered error when creating FileInputStream for " + file.getPath());
|
||||
return null;
|
||||
EntityBingo.getInstance().getConfig().load("plugins" + File.separator + "EntityBingo" + File.separator + "config.yml");
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Yaml yaml = new Yaml();
|
||||
HashMap<String, Object> data = yaml.load(inputStream);
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().info(e.getMessage());
|
||||
}
|
||||
|
||||
return data;
|
||||
MemorySection data = ((MemorySection) EntityBingo.getInstance().getConfig().get("scores"));
|
||||
Bukkit.getLogger().info(data.toString());
|
||||
Bukkit.getLogger().info(data.getValues(true).toString());
|
||||
Map<String,Object> raw = new HashMap<>();
|
||||
raw.put("scores", data.getValues(true));
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +159,7 @@ public class DataManager {
|
||||
File file = getFile(filePath);
|
||||
|
||||
if (!file.exists()) {
|
||||
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + filePath + ".yml");
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Attempted to retrieve non-existant file: " + filePath + ".yml");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -132,49 +185,12 @@ public class DataManager {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().info("Encountered error when creating file - " + path);
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered error when creating file - " + path);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Default Files
|
||||
*/
|
||||
private static void genDefaultFiles() {
|
||||
List<String> paths = List.of(
|
||||
"scoreboard.yml"
|
||||
);
|
||||
|
||||
for (String path : paths) {
|
||||
File file = new File(dataFolder + File.separator + path);
|
||||
if (!file.exists()) {
|
||||
HashMap<String, Object> raw = new HashMap<>();
|
||||
raw.put("scores", new HashMap<String, Object>());
|
||||
saveData(path, raw);
|
||||
EntityBingo.getInstance().getLogger().info("Couldn't find file \"" + path + "\", generated default.");
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().info("Found existing scoreboard file at " + dataFolder + File.separator + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial creation of all needed folders
|
||||
*/
|
||||
private static void createFolders() {
|
||||
List<String> paths = Arrays.asList(
|
||||
"plugins" + File.separator + "EntityBingo" + File.separator + "data"
|
||||
);
|
||||
|
||||
for (String path : paths) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
EntityBingo.getInstance().getLogger().info("Couldn't find folder \"" + path + "\", generated default.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,9 +33,9 @@ public final class EntityBingo extends JavaPlugin {
|
||||
DataManager.init();
|
||||
|
||||
//Reload scoreboard
|
||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
try {
|
||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||
Map<String, Object> data = (Map<String, Object>) raw.get("scores");
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
@@ -47,7 +47,7 @@ public final class EntityBingo extends JavaPlugin {
|
||||
//Save to static scoreboard reference
|
||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||
} catch (ClassCastException ex) {
|
||||
this.getLogger().log(Level.WARNING, "Failed to load scoreboard! Is scoreboard.yml broken?");
|
||||
this.getLogger().log(Level.WARNING, "Failed to load scoreboard! Is config.yml broken?");
|
||||
}
|
||||
|
||||
this.getLogger().info("EntityBingo loaded.");
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.aubrithehuman.entitybingo.EntityBingo;
|
||||
import org.aubrithehuman.entitybingo.listeners.ChatListener;
|
||||
import org.aubrithehuman.entitybingo.util.Helper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -26,7 +27,9 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
"guesses",
|
||||
"reloadscoreboard",
|
||||
"purge",
|
||||
"reset"
|
||||
"reset",
|
||||
"addscore",
|
||||
"setscore"
|
||||
});
|
||||
|
||||
private final List<String> options = List.of(new String[]{
|
||||
@@ -43,16 +46,15 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) {
|
||||
final Player p = (Player) sender;
|
||||
if (args.length >= 1) {
|
||||
if (args[0].equalsIgnoreCase("scoreboard")) {
|
||||
//check if we can do anything
|
||||
if (ChatListener.scoreboard == null) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
||||
return true;
|
||||
}
|
||||
if (ChatListener.scoreboard.isEmpty()) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError loading scoreboard."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cScoreboard empty! Try again later!."));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,14 +68,14 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
page = Math.max(1, page);
|
||||
page = Math.min((int) pages, page);
|
||||
} catch (NumberFormatException ex) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cPage number not a value."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cPage number not a value."));
|
||||
}
|
||||
|
||||
int startIndex = (page - 1) * 8;
|
||||
|
||||
//print
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("Entity Bingo Scoreboard:"));
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("-------------[" + page + "/" + (int) pages + "]-------------"));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("Entity Bingo Scoreboard:"));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("-------------[" + page + "/" + (int) pages + "]-------------"));
|
||||
|
||||
int i = 0;
|
||||
for (String s : ChatListener.scoreboard.keySet()) {
|
||||
@@ -84,7 +86,7 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
//format and push to player
|
||||
String name = Bukkit.getOfflinePlayer(UUID.fromString(s)).getName();
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&7" + (i + 1) + ". " + name + ", " + ChatListener.scoreboard.get(s)));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&7" + (i + 1) + ". " + name + ", " + ChatListener.scoreboard.get(s)));
|
||||
i++;
|
||||
//page limit
|
||||
if (i > 7 + startIndex) break;
|
||||
@@ -93,58 +95,59 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("guesses")) {
|
||||
|
||||
if (EntityBingo.getCurrentEvent() == null) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
||||
return true;
|
||||
}
|
||||
|
||||
//print off all guesses
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("List of all guesses in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event:"));
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("----------------------------------"));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("List of all guesses in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event:"));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("----------------------------------"));
|
||||
|
||||
for (String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||
String name = Bukkit.getOfflinePlayer(UUID.fromString(s)).getName();
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&7 - " + name + ": " + EntityBingo.getCurrentEvent().getEntries().get(s)));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&7 - " + name + ": " + EntityBingo.getCurrentEvent().getEntries().get(s)));
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("purge")) {
|
||||
if (!p.hasPermission("EntityBingo.admin")) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
if (!sender.hasPermission("EntityBingo.admin")) {
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (EntityBingo.getCurrentEvent() == null) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
||||
sender.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!"));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
||||
return true;
|
||||
}
|
||||
//clear entry pool
|
||||
EntityBingo.getCurrentEvent().getEntries().clear();
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
||||
sender.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!"));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||
if (!p.hasPermission("EntityBingo.admin")) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
if (!sender.hasPermission("EntityBingo.admin")) {
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
return true;
|
||||
}
|
||||
|
||||
//clear event
|
||||
EntityBingo.setCurrentEvent(null);
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cEnded current bingo event."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cEnded current bingo event."));
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEvent forcefully ended by and admin!"));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEvent forcefully ended by and admin!"));
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("reloadscoreboard")) {
|
||||
if (!p.hasPermission("EntityBingo.admin")) {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
if (!sender.hasPermission("EntityBingo.admin")) {
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cYou do not have permissions to run this command."));
|
||||
return true;
|
||||
}
|
||||
|
||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
try {
|
||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||
Map<String, Object> data = (Map<String, Object>) raw.get("scores");
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
@@ -157,28 +160,140 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||
|
||||
//clear event
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded 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?");
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is config.yml broken?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cError. Subcommand not found"));
|
||||
} else if (args[0].equalsIgnoreCase("addscore")) {
|
||||
if(args.length >= 3) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(args[1]);
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
try {
|
||||
Map<String, Object> data = (Map<String, Object>) raw.get("scores");
|
||||
|
||||
try {
|
||||
int old = (int) data.get(p.getUniqueId().toString());
|
||||
data.put(p.getUniqueId().toString(), old + Integer.parseInt(args[2]));
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage(Helper.chatLabel() + "Failed to parse value");
|
||||
return true;
|
||||
}
|
||||
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
|
||||
//Save to static scoreboard reference
|
||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", filtered);
|
||||
DataManager.saveData("config.yml", out);
|
||||
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&eEB score for player " + args[1] + " added " + args[2]));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&eEB score for player " + args[1] + " added " + args[2]));
|
||||
|
||||
//clear event
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cAdmin reloaded scoreboard!"));
|
||||
} catch (ClassCastException ex) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is config.yml broken?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
reloadScoreboard(sender);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("setscore")) {
|
||||
if(args.length >= 3) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(args[1]);
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
try {
|
||||
Map<String, Object> data = (Map<String, Object>) raw.get("scores");
|
||||
|
||||
try {
|
||||
data.put(p.getUniqueId().toString(), Integer.parseInt(args[2]));
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage(Helper.chatLabel() + "Failed to parse value");
|
||||
return true;
|
||||
}
|
||||
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
|
||||
//Save to static scoreboard reference
|
||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", filtered);
|
||||
DataManager.saveData("config.yml", out);
|
||||
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cSet EB score for player " + args[1] + " to " + args[2]));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cSet EB score for player " + args[1] + " to " + args[2]));
|
||||
|
||||
//clear event
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cAdmin reloaded scoreboard!"));
|
||||
} catch (ClassCastException ex) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is config.yml broken?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
reloadScoreboard(sender);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cError. Subcommand not found"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void reloadScoreboard(CommandSender sender) {
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
try {
|
||||
Map<String, Object> data = (Map<String, Object>) raw.get("scores");
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
//Save to static scoreboard reference
|
||||
ChatListener.scoreboard = Helper.sortData(filtered);
|
||||
|
||||
//clear event
|
||||
sender.sendMessage(Helper.chatLabel() + Helper.color("&cReloaded scoreboard."));
|
||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cAdmin reloaded scoreboard!"));
|
||||
} catch (ClassCastException ex) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is config.yml broken?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) {
|
||||
final Player p = (Player) sender;
|
||||
if (args.length >= 1) {
|
||||
if (args.length >= 2) {
|
||||
return null;
|
||||
} else {
|
||||
if (p.hasPermission("EntityBingo.admin")) {
|
||||
if (sender.hasPermission("EntityBingo.admin")) {
|
||||
return adminOptions;
|
||||
}
|
||||
return options;
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.server.BroadcastMessageEvent;
|
||||
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -38,7 +39,7 @@ public class ChatListener implements Listener {
|
||||
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!");
|
||||
} else {
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
}
|
||||
}
|
||||
@@ -51,112 +52,113 @@ public class ChatListener implements Listener {
|
||||
if(matchFound2) {
|
||||
//check if we have a bingo event happening
|
||||
if(EntityBingo.getCurrentEvent() != null) {
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
||||
if(!EntityBingo.getCurrentEvent().isDone()) {
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
||||
|
||||
//extract the result number
|
||||
String str = e.getMessage();
|
||||
str = ChatColor.stripColor(str);
|
||||
String numberOnly = str.replaceAll("[^0-9]", "");
|
||||
int i = -1;
|
||||
if(!str.isEmpty()) {
|
||||
//we need to check if the guess exists as an int
|
||||
try {
|
||||
i = Integer.parseInt(numberOnly);
|
||||
} catch (NumberFormatException exception) {
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
||||
EntityBingo.getCurrentEvent().setDone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//look for winners
|
||||
List<String> winners = new ArrayList<>();
|
||||
if(i >= 0) {
|
||||
for(String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||
if(EntityBingo.getCurrentEvent().getEntries().get(s) == i) {
|
||||
winners.add(s);
|
||||
//extract the result number
|
||||
String str = e.getMessage();
|
||||
str = ChatColor.stripColor(str);
|
||||
String numberOnly = str.replaceAll("[^0-9]", "");
|
||||
int i = -1;
|
||||
if(!str.isEmpty()) {
|
||||
//we need to check if the guess exists as an int
|
||||
try {
|
||||
i = Integer.parseInt(numberOnly);
|
||||
} catch (NumberFormatException exception) {
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
||||
EntityBingo.getCurrentEvent().setDone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//broadcast winners
|
||||
if(winners.isEmpty()) {
|
||||
//no winners??????
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
||||
} else {
|
||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||
if(raw.containsKey("scores")) {
|
||||
try {
|
||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||
//look for winners
|
||||
List<String> winners = new ArrayList<>();
|
||||
if(i >= 0) {
|
||||
for(String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||
if(EntityBingo.getCurrentEvent().getEntries().get(s) == i) {
|
||||
winners.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//broadcast winners
|
||||
if(winners.isEmpty()) {
|
||||
//no winners??????
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
||||
} else {
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
if(raw.containsKey("scores")) {
|
||||
try {
|
||||
HashMap<String, Integer> data = (HashMap<String, Integer>) raw.get("scores");
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||
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
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if (data != null) {
|
||||
if (data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/config.yml may be broken.");
|
||||
}
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("config.yml", out);
|
||||
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
//Save to static scoreboard reference
|
||||
scoreboard = Helper.sortData(filtered);
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is config.yml broken?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
||||
|
||||
//get player uuid and save their wins
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if (data != null) {
|
||||
if (data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
if(data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
|
||||
//grab only entries with integer values, should be all, but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
//Save to static scoreboard reference
|
||||
scoreboard = Helper.sortData(filtered);
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is scoreboard.yml broken?");
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("config.yml", out);
|
||||
}
|
||||
} else {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
||||
|
||||
//get player uuid and save their wins
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if(data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
}
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
|
||||
}
|
||||
|
||||
EntityBingo.getCurrentEvent().setDone();
|
||||
|
||||
}
|
||||
|
||||
EntityBingo.getCurrentEvent().setDone();
|
||||
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().info("Match not found for any part");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,29 +169,35 @@ public class ChatListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
//Entry detection
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
||||
if (EntityBingo.getCurrentEvent() != null) {
|
||||
if(EntityBingo.getCurrentEvent().isDone()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Force end event if it's too old.
|
||||
int maxEventAge = EntityBingo.getInstance().getConfig().getInt("maxEventAge");
|
||||
if(System.currentTimeMillis() - EntityBingo.getCurrentEvent().getAge() > (maxEventAge * 1000L)) {
|
||||
EntityBingo.getCurrentEvent().setDone();
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cForcefully ended bingo event as it has been more than " + maxEventAge + " seconds."));
|
||||
return;
|
||||
}
|
||||
|
||||
String str = e.getMessage();
|
||||
//remove all color codes from this message
|
||||
str = ChatColor.stripColor(str);
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "purges codes for: " + "\"" + str + "\"");
|
||||
//remove all text other than numbers
|
||||
str = str.replaceAll("[^0-9.]", "");
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "numbers only: " + "\"" + str + "\"");
|
||||
if(!str.isEmpty()) {
|
||||
int guess;
|
||||
int guess = - 1;
|
||||
//we need to check if the guess exists as an int
|
||||
try {
|
||||
guess = Integer.parseInt(str);
|
||||
} catch (NumberFormatException exception) {
|
||||
e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&cDetected a number that could not be formatted, make sure not to use decimals."));
|
||||
e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&cDetected a number that could not be formatted, make sure not to use decimals or seperators."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (guess > 0) {
|
||||
if (guess >= 0) {
|
||||
//do the entry
|
||||
int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
|
||||
//feedback to entrant
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#check against this to start
|
||||
startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §cseconds!'
|
||||
#check against this to end
|
||||
endMessage: '§6[ClearLag] §aRemoved '
|
||||
endMessage: '§6[ClearLag] §aRemoved '
|
||||
#max age for event (in seconds), used in case the ending fails
|
||||
maxEventAge: 120
|
||||
#score data
|
||||
scores: {}
|
||||
Reference in new issue
Block a user