2 Commits
Author SHA1 Message Date
Aubri Seebauer 56efdb4892 v1.0.2 fixed several null errors and added age check 2023-04-23 15:18:12 -04:00
Aubri Seebauer 3b0573b712 v1.0.1 2023-04-23 12:15:43 -04:00
5 changed files with 26 additions and 5 deletions

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.aubrithehuman</groupId> <groupId>org.aubrithehuman</groupId>
<artifactId>EntityBingo</artifactId> <artifactId>EntityBingo</artifactId>
<version>1.0</version> <version>1.0.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>EntityBingo</name> <name>EntityBingo</name>
@@ -8,8 +8,11 @@ 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() {
@@ -43,4 +46,8 @@ public class BingoEvent {
public void setDone() { public void setDone() {
this.done = true; this.done = true;
} }
public long getAge() {
return this.age;
}
} }
@@ -93,9 +93,9 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
return true; return true;
} else if (args[0].equalsIgnoreCase("guesses")) { } else if (args[0].equalsIgnoreCase("guesses")) {
if (EntityBingo.getCurrentEvent() == 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."));
return true;
} }
//print off all guesses //print off all guesses
@@ -117,6 +117,7 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().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;
} }
//clear entry pool //clear entry pool
EntityBingo.getCurrentEvent().getEntries().clear(); EntityBingo.getCurrentEvent().getEntries().clear();
@@ -51,6 +51,7 @@ public class ChatListener implements Listener {
if(matchFound2) { if(matchFound2) {
//check if we have a bingo event happening //check if we have a bingo event happening
if(EntityBingo.getCurrentEvent() != null) { if(EntityBingo.getCurrentEvent() != null) {
if(!EntityBingo.getCurrentEvent().isDone()) {
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!"); Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
//extract the result number //extract the result number
@@ -159,6 +160,7 @@ public class ChatListener implements Listener {
} }
} }
} }
}
@@ -169,22 +171,31 @@ public class ChatListener implements Listener {
if(EntityBingo.getCurrentEvent().isDone()) { if(EntityBingo.getCurrentEvent().isDone()) {
return; 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(); String str = e.getMessage();
//remove all color codes from this message //remove all color codes from this message
str = ChatColor.stripColor(str); str = ChatColor.stripColor(str);
//remove all text other than numbers //remove all text other than numbers
str = str.replaceAll("[^0-9.]", ""); str = str.replaceAll("[^0-9.]", "");
if(!str.isEmpty()) { if(!str.isEmpty()) {
int guess; int guess = - 1;
//we need to check if the guess exists as an int //we need to check if the guess exists as an int
try { try {
guess = Integer.parseInt(str); guess = Integer.parseInt(str);
} catch (NumberFormatException exception) { } 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; return;
} }
if (guess > 0) { if (guess >= 0) {
//do the entry //do the entry
int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess); int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
//feedback to entrant //feedback to entrant
+2
View File
@@ -2,3 +2,5 @@
startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §cseconds!' startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §cseconds!'
#check against this to end #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