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 |
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.2</version>
|
||||
<version>1.0.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EntityBingo</name>
|
||||
|
||||
@@ -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,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -21,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
|
||||
@@ -35,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) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,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);
|
||||
}
|
||||
@@ -73,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()) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "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) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "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) {
|
||||
EntityBingo.getInstance().getLogger().log(Level.SEVERE, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,48 +186,11 @@ public class DataManager {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
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;
|
||||
@@ -94,58 +96,58 @@ 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()
|
||||
@@ -158,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;
|
||||
@@ -86,10 +87,10 @@ public class ChatListener implements Listener {
|
||||
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");
|
||||
Map<String, Object> raw = DataManager.getData("config.yml");
|
||||
if(raw.containsKey("scores")) {
|
||||
try {
|
||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||
HashMap<String, Integer> data = (HashMap<String, Integer>) raw.get("scores");
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||
@@ -105,7 +106,7 @@ public class ChatListener implements Listener {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/config.yml may be broken.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ public class ChatListener implements Listener {
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
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()
|
||||
@@ -127,7 +128,8 @@ public class ChatListener implements Listener {
|
||||
scoreboard = Helper.sortData(filtered);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
} else {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
@@ -147,7 +149,7 @@ public class ChatListener implements Listener {
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
DataManager.saveData("config.yml", out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,4 +3,6 @@ startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §
|
||||
#check against this to end
|
||||
endMessage: '§6[ClearLag] §aRemoved '
|
||||
#max age for event (in seconds), used in case the ending fails
|
||||
maxEventAge: 120
|
||||
maxEventAge: 120
|
||||
#score data
|
||||
scores: {}
|
||||
Reference in new issue
Block a user