Skip to content

Commit

Permalink
Add title messages, remove legacy formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonHorkles committed Dec 31, 2024
1 parent 26e455a commit fc65f5b
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 121 deletions.
1 change: 1 addition & 0 deletions checksums.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"3.8.0": "66EE45C670F83E2AF7234B619CEFF26C",
"3.7.2": "667E5D1630FA3D61BC39B059A991629B",
"3.7.1": "192F4A25D138DF6D5765C4698B07BE3D",
"3.7.0": "9958F067E96DB53627967BDBE165C714",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>net.silverstonemc</groupId>
<artifactId>EntityClearer</artifactId>
<version>3.7.2</version>
<version>3.8.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
130 changes: 76 additions & 54 deletions src/main/java/net/silverstonemc/entityclearer/ClearTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import io.lumine.mythic.core.mobs.ActiveMob;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.silverstonemc.entityclearer.utils.*;
import net.kyori.adventure.title.Title;
import net.silverstonemc.entityclearer.utils.ConfigUtils;
import net.silverstonemc.entityclearer.utils.EntityData;
import net.silverstonemc.entityclearer.utils.LogDebug;
import net.silverstonemc.entityclearer.utils.OnlinePlayers;
import org.bukkit.Bukkit;
import org.bukkit.SoundCategory;
import org.bukkit.World;
Expand Down Expand Up @@ -72,7 +76,8 @@ private void removeEntities(Iterable<World> worlds, boolean useTpsList, boolean
Object[] notEnoughPlayers = new OnlinePlayers().isNotEnough(world, worldConfigName);
// Skip the world if there aren't enough players online
if ((boolean) notEnoughPlayers[0]) {
debug.debug(Level.WARNING,
debug.debug(
Level.WARNING,
worldName,
"Not enough players in the " + notEnoughPlayers[1] + "! Skipping...");
continue;
Expand Down Expand Up @@ -115,6 +120,7 @@ private void removeEntities(Iterable<World> worlds, boolean useTpsList, boolean
for (Player player : world.getPlayers()) {
sendActionBar(world, player, tpsLow);
sendChat(world, player, tpsLow);
sendTitle(world, player, tpsLow);
playSound(world, player);
}
sendLog(world, tpsLow);
Expand Down Expand Up @@ -143,7 +149,8 @@ private EntityData matchEntityFromConfig(Entity entity, String worldName) {
}).findFirst().orElse(null);

if (mythicEntityData != null) {
debug.debug(Level.INFO, worldName,
debug.debug(
Level.INFO, worldName,
"Entity " + mythicMob.getMobType() + " is a MythicMob that matches the config's!");
return mythicEntityData;
}
Expand All @@ -162,7 +169,8 @@ private EntityData matchEntityFromConfig(Entity entity, String worldName) {
.orElse(null);

if (mythicMob != null) {
debug.debug(Level.WARNING, worldName,
debug.debug(
Level.WARNING, worldName,
"Entity " + mythicMob.getMobType() + " is a MythicMob not in the config! Skipping...");
return null;
}
Expand All @@ -172,16 +180,16 @@ private EntityData matchEntityFromConfig(Entity entity, String worldName) {
return entityData;
}

debug.debug(Level.WARNING, worldName,
"Entity " + entity.getType() + " is not a valid type from the config!");
debug.debug(Level.WARNING, worldName, "Entity " + entity.getType() + " is not listed in the config!");
return null;
}

private void checkOccupied(Entity entity, EntityData entityData, String path, String worldName) {
// Skip entity if it is occupied and the config doesn't allow it
if (!entityData.includeOccupied()) for (Entity passenger : entity.getPassengers())
if (passenger.getType() == EntityType.PLAYER) {
new LogDebug().debug(Level.INFO, worldName,
new LogDebug().debug(
Level.INFO, worldName,
"Skipping entity " + entity.getType() + " because it is occupied!");
return;
}
Expand All @@ -205,13 +213,15 @@ private void checkNamed(Entity entity, EntityData entityData, String path, Strin
debug.debug(Level.INFO, worldName, "Removing " + entityType + " without a name only...");
// And it doesn't have a name
if (entity.getCustomName() == null) {
debug.debug(Level.INFO, worldName,
debug.debug(
Level.INFO, worldName,
"The " + entityType + " " + entity.getType() + " doesn't have a custom name!");
checkSpawnReason(entity, path, worldName);
}
// And it does have a name
else {
debug.debug(Level.INFO, worldName,
debug.debug(
Level.INFO, worldName,
entity.getType() + " was skipped becuase it has a name: " + entity.getCustomName());
debug.debug(Level.INFO, "", "");
}
Expand Down Expand Up @@ -243,7 +253,8 @@ private void checkSpawnReason(Entity entity, String path, String worldName) {
entity.getType() + "'s spawn reason " + entity.getEntitySpawnReason() + " matches the config's!");
checkNearby(entity, worldName);

} else debug.debug(Level.INFO, worldName,
} else debug.debug(
Level.INFO, worldName,
entity.getType() + "'s spawn reason " + entity.getEntitySpawnReason()
.name() + " doesn't match the config's! (" + spawnReasons + ")");

Expand Down Expand Up @@ -303,11 +314,13 @@ private void checkNearby(Entity entity, String worldName) {
}
}

debug.debug(Level.INFO, worldName,
debug.debug(
Level.INFO, worldName,
"Found " + nearbyEntities.size() + " nearby entities that were on the list.");
}

if (nearbyEntities.size() > plugin.getConfig().getInt("nearby-entities.count")) removeEntity(entity,
if (nearbyEntities.size() > plugin.getConfig().getInt("nearby-entities.count")) removeEntity(
entity,
worldName);
else {
debug.debug(Level.INFO, worldName, "Not enough entities nearby! Skipping...");
Expand All @@ -320,7 +333,8 @@ private void removeEntity(Entity entity, String worldName) {
removedEntities++;

LogDebug debug = new LogDebug();
debug.debug(Level.INFO, worldName,
debug.debug(
Level.INFO, worldName,
entity.getType() + " removed! Total removed is " + removedEntities + ".");
debug.debug(Level.INFO, "", "");
}
Expand Down Expand Up @@ -353,52 +367,59 @@ private void removeEntitiesPostTask() {
}

private void sendActionBar(World world, Player player, boolean tpsLow) {
if (tpsLow) {
if (plugin.getConfig().getString("messages.actionbar-completed-low-tps-message").isBlank())
return;
if (!player.hasPermission("entityclearer.removalnotifs.actionbar")) return;
if (!player.hasPermission("entityclearer.removalnotifs.actionbar")) return;

bukkitAudiences.player(player).sendActionBar(MiniMessage.miniMessage()
.deserialize(new ParseMessage().parse(plugin.getConfig()
.getString("messages.actionbar-completed-low-tps-message")
.replace("{ENTITIES}", String.valueOf(removedEntities)))));
String path = tpsLow ? "messages.actionbar-completed-low-tps-message" : "messages.actionbar-completed-message";

} else if (!plugin.getConfig().getString("messages.actionbar-completed-message").isBlank()) {
if (!player.hasPermission("entityclearer.removalnotifs.actionbar")) return;
if (plugin.getConfig().getString(path).isBlank()) return;

new LogDebug().debug(Level.INFO,
world.getName(),
"Sending action bar to player " + player.getName() + " about " + removedEntities + " entities");
new LogDebug().debug(
Level.INFO,
world.getName(),
"Sending action bar to player " + player.getName() + " about " + removedEntities + " entities");

bukkitAudiences.player(player).sendActionBar(MiniMessage.miniMessage()
.deserialize(new ParseMessage().parse(plugin.getConfig()
.getString("messages.actionbar-completed-message")
.replace("{ENTITIES}", String.valueOf(removedEntities)))));
}
bukkitAudiences.player(player).sendActionBar(MiniMessage.miniMessage()
.deserialize(plugin.getConfig().getString(path)
.replace("{ENTITIES}", String.valueOf(removedEntities))));
}

private void sendChat(World world, Player player, boolean tpsLow) {
if (tpsLow) {
if (plugin.getConfig().getString("messages.chat-completed-low-tps-message").isBlank()) return;
if (!player.hasPermission("entityclearer.removalnotifs.chat")) return;
if (!player.hasPermission("entityclearer.removalnotifs.chat")) return;

bukkitAudiences.player(player).sendMessage(MiniMessage.miniMessage()
.deserialize(new ParseMessage()
.parse(plugin.getConfig().getString("messages.chat-completed-low-tps-message"))
.replace("{ENTITIES}", String.valueOf(removedEntities))));
String path = tpsLow ? "messages.chat-completed-low-tps-message" : "messages.chat-completed-message";

} else if (!plugin.getConfig().getString("messages.chat-completed-message").isBlank()) {
if (!player.hasPermission("entityclearer.removalnotifs.chat")) return;
if (plugin.getConfig().getString(path).isBlank()) return;

new LogDebug().debug(Level.INFO,
world.getName(),
"Sending message to player " + player.getName() + " about " + removedEntities + " entities");
new LogDebug().debug(
Level.INFO,
world.getName(),
"Sending message to player " + player.getName() + " about " + removedEntities + " entities");

bukkitAudiences.player(player).sendMessage(MiniMessage.miniMessage()
.deserialize(new ParseMessage()
.parse(plugin.getConfig().getString("messages.chat-completed-message"))
.replace("{ENTITIES}", String.valueOf(removedEntities))));
}
bukkitAudiences.player(player).sendMessage(MiniMessage.miniMessage()
.deserialize(plugin.getConfig().getString(path)
.replace("{ENTITIES}", String.valueOf(removedEntities))));
}

private void sendTitle(World world, Player player, boolean tpsLow) {
if (!player.hasPermission("entityclearer.removalnotifs.title")) return;

String titlePath = tpsLow ? "messages.title-completed-low-tps-message" : "messages.title-completed-message";
String subtitlePath = tpsLow ? "messages.subtitle-completed-low-tps-message" : "messages.subtitle-completed-message";

if (plugin.getConfig().getString(titlePath).isBlank() && plugin.getConfig().getString(subtitlePath)
.isBlank()) return;

new LogDebug().debug(
Level.INFO,
world.getName(),
"Sending action bar to player " + player.getName() + " about " + removedEntities + " entities");

Title title = Title.title(
MiniMessage.miniMessage().deserialize(plugin.getConfig().getString(titlePath)
.replace("{ENTITIES}", String.valueOf(removedEntities))),
MiniMessage.miniMessage().deserialize(plugin.getConfig().getString(subtitlePath)
.replace("{ENTITIES}", String.valueOf(removedEntities))));
bukkitAudiences.player(player).showTitle(title);
}

private void playSound(World world, Player player) {
Expand Down Expand Up @@ -439,14 +460,15 @@ private void sendLog(World world, boolean tpsLow) {
if (tpsLow) {
if (plugin.getConfig().getString("messages.log-completed-low-tps-message").isBlank()) return;

bukkitAudiences.console().sendMessage(MiniMessage.miniMessage().deserialize(new ParseMessage()
.parse(worldName + plugin.getConfig().getString("messages.log-completed-low-tps-message"))
.replace("{ENTITIES}", String.valueOf(removedEntities))));
bukkitAudiences.console().sendMessage(MiniMessage.miniMessage()
.deserialize(worldName + plugin.getConfig()
.getString("messages.log-completed-low-tps-message")
.replace("{ENTITIES}", String.valueOf(removedEntities))));

} else if (!plugin.getConfig().getString("messages.log-completed-message").isBlank())

bukkitAudiences.console().sendMessage(MiniMessage.miniMessage().deserialize(new ParseMessage()
.parse(worldName + plugin.getConfig().getString("messages.log-completed-message"))
.replace("{ENTITIES}", String.valueOf(removedEntities))));
bukkitAudiences.console().sendMessage(MiniMessage.miniMessage()
.deserialize(worldName + plugin.getConfig().getString("messages.log-completed-message")
.replace("{ENTITIES}", String.valueOf(removedEntities))));
}
}
Loading

0 comments on commit fc65f5b

Please # to comment.