Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
Add #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiaskirchmaier authored Oct 1, 2022
1 parent 7d43ce0 commit 03e2a03
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: ClearLag
version: 2.0.0
version: 2.1.0
main: tobias14\clearlag\ClearLag
src-namespace-prefix: tobias14\clearlag
api: 4.0.0
Expand Down
7 changes: 6 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# \_____ |_|\___|\__,_|_| |______\__,_|\__, |
# __/ |
# |___/
metadata/version: 2.0.0
metadata/version: 2.1.0
# metadata/autor: tobias14
# metadata/website: https://github.com/Tobias-2006/ClearLag
#
Expand Down Expand Up @@ -67,6 +67,11 @@ clearlag/preferences:
# True by default.
logging/console: true

# Set here when ClearLag sends alert messages.
# E.g. ["15m", "10m", "5m", "1m", "3s", "2s", "1s"]
# Empty array, for the default times.
logging/alert-times: []

# Specify here which entities are to be removed and which are not.
# All entities that inherit from Human are automatically excluded.
entities:
Expand Down
9 changes: 9 additions & 0 deletions src/preferences/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,18 @@ public function __construct(Config $config)
$clearDelay = 0x384; // 15 minutes
}

try {
$alertTimes = array_map(function(string $timeString): int {
return TimeUtils::parseTimeString($timeString);
}, $config->getNested('clearlag/preferences.logging/alert-times', []));
} catch(Exception) {
$alertTimes = [];
}

$this->removalPreferences = new RemovalPreferences(
$clearDelay,
$config->getNested('clearlag/preferences.logging/console', true),
$alertTimes,
$entityPreferences,
$config->getNested('clearlag/preferences.entities.entity/blacklist', [])
);
Expand Down
17 changes: 16 additions & 1 deletion src/preferences/types/RemovalPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ final class RemovalPreferences
/**
* @param int $delay Time span between each entity removal.
* @param bool $consoleLogging
* @param int[] $alertTimes
* @param EntityPreferences $entityPreferences
* @param string[] $blacklist List of entity-/item-names that should not be removed.
*/
public function __construct(private int $delay, private bool $consoleLogging, private EntityPreferences $entityPreferences, private array $blacklist) {}
public function __construct(
private int $delay,
private bool $consoleLogging,
private array $alertTimes,
private EntityPreferences $entityPreferences,
private array $blacklist
) {}

/**
* @return int
Expand All @@ -30,6 +37,14 @@ public function getConsoleLogging(): bool
return $this->consoleLogging;
}

/**
* @return int[]
*/
public function getAlertTimes(): array
{
return $this->alertTimes;
}

/**
* @return EntityPreferences
*/
Expand Down
3 changes: 2 additions & 1 deletion src/task/ClearTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function __construct(private Preferences $preferences)

public function onRun(): void
{
if(in_array($this->timer, self::HARDCODED_ALERT_TIMES)) {
$alertTimes = $this->preferences->getRemovalPreferences()->getAlertTimes();
if(in_array($this->timer, $alertTimes !== [] ? $alertTimes : self::HARDCODED_ALERT_TIMES)) {
$message = Messages::ALERT_MESSAGE();
$unit = $this->preferences->getTranslations()->get(TimeUtils::getHighestUnit($this->timer))?->getText();
$message->replace(['{TIME}' => (string) TimeUtils::toHighestUnit($this->timer), '{UNIT}' => $unit]);
Expand Down

0 comments on commit 03e2a03

Please sign in to comment.