Skip to content

Commit

Permalink
Modify punishments; extend time (#115)
Browse files Browse the repository at this point in the history
* Create and implement API to modify punishment reason, scope
  and end time, with possibility to modify end time (#162)
* Add command-extend addon to extend a punishment by specified
  duration (#115)
* Guarantee end > start in database, increment database revision
  accordingly
* Update Github workflow
  • Loading branch information
A248 committed Feb 12, 2023
1 parent 9fc7335 commit b5b4aa8
Show file tree
Hide file tree
Showing 49 changed files with 1,178 additions and 147 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
cache: 'maven'
- name: Build with Maven
run: mvn clean -B -U verify
deploy:
Expand All @@ -29,17 +24,12 @@ jobs:
needs: build
steps:
- uses: actions/checkout@v2
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
cache: 'maven'
server-id: cloudsmith-deploy
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2022 Anand Beh
* Copyright © 2023 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -41,20 +41,6 @@ public interface ExpunctionOrder extends EnforcementOptionsFactory {
*
* @return a future which yields true if the punishment existed and was expunged
*/
default ReactionStage<Boolean> expunge() {
return expunge(enforcementOptionsBuilder().build());
}

/**
* Expunges the punishment. <br>
* <br>
* An expunged punishment is not "undone" and therefore does not trigger undo notifications.
* As such, the {@link EnforcementOptions#broadcasting()} setting has no meaning here.
*
* @param enforcementOptions the enforcement options. Can be used to disable unenforcement entirely.
* The "broadcasting" setting has no effect.
* @return a future which yields true if the punishment existed and was expunged
*/
ReactionStage<Boolean> expunge(EnforcementOptions enforcementOptions);
ReactionStage<Boolean> expunge();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

package space.arim.libertybans.api.punish;

import space.arim.omnibus.util.concurrent.ReactionStage;

import java.time.Clock;
import java.time.Instant;

import space.arim.omnibus.util.concurrent.ReactionStage;
import java.util.Optional;
import java.util.function.Consumer;

/**
* A full punishment, identifiable by its ID. <br>
Expand Down Expand Up @@ -225,6 +227,19 @@ default ReactionStage<?> unenforcePunishment() {
*/
ReactionStage<?> unenforcePunishment(EnforcementOptions enforcementOptions);

/**
* Modifies this punishment and yields the new instance. <br>
* <br>
* This punishment instance is invalidated by use of this method. The new punishment
* returned should be used as soon as it becomes available.
*
* @param editorConsumer the actions applied to modify this punishment. Note that the editor
* is made invalid as soon as the consumer exits scope.
* @return the new punishment after changes have been propagated to the database, or
* an empty optional if the punishment has since been expunged
*/
ReactionStage<Optional<Punishment>> modifyPunishment(Consumer<PunishmentEditor> editorConsumer);

/**
* Whether this punishment is equal to another. The other punishment must
* represent the same punishment stored in the database. <br>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* LibertyBans is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/>
* and navigate to version 3 of the GNU Affero General Public License.
*/

package space.arim.libertybans.api.punish;

import space.arim.libertybans.api.scope.ServerScope;

import java.time.Duration;
import java.time.Instant;

/**
* Assistant interface for modifying a punishment
*
*/
public interface PunishmentEditor {

/**
* Sets the new reason
*
* @param reason the new reason
*/
void setReason(String reason);

/**
* Sets the new scope
*
* @param scope the new scope
*/
void setScope(ServerScope scope);

/**
* Sets the new end date. {@link Punishment#PERMANENT_END_DATE} is used for a
* permanent punishment
*
* @param endDate the new end date
* @throws IllegalStateException if {@link #extendEndDate(Duration)} was used
*/
void setEndDate(Instant endDate);

/**
* Modifies the end date by adding the given duration. <br>
* <br>
* It is possible to reduce the end date by using a negative duration. Note that if
* the subtraction operation would otherwise cause the punishment to have an end date less
* than or equal to the start date, then 1 second plus the start date is used as the new
* end date.
*
* @param endDateDelta the amount by which to change the end date, may be negative
* @throws IllegalStateException if {@link #setEndDate(Instant)} was used
*/
void extendEndDate(Duration endDateDelta);

}
5 changes: 5 additions & 0 deletions bans-core-addons/addon-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<artifactId>addon-command-expunge</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>space.arim.libertybans</groupId>
<artifactId>addon-command-extend</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>space.arim.libertybans</groupId>
<artifactId>addon-command-staffrollback</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import space.arim.libertybans.core.addon.exempt.luckperms.ExemptionLuckPermsModule;
import space.arim.libertybans.core.addon.exempt.vault.ExemptionVaultModule;
import space.arim.libertybans.core.addon.expunge.ExpungeModule;
import space.arim.libertybans.core.addon.extend.ExtendModule;
import space.arim.libertybans.core.addon.staffrollback.StaffRollbackModule;
import space.arim.libertybans.core.addon.warnactions.WarnActionsModule;

Expand All @@ -40,8 +41,9 @@ public class ServiceLoadingIT {
public void loadAddons() {
assertEquals(
Set.of(
new CheckPunishModule(), new CheckUserModule(), new ExpungeModule(), new StaffRollbackModule(),
new ExemptionLuckPermsModule(), new ExemptionVaultModule(), new WarnActionsModule()
new CheckPunishModule(), new CheckUserModule(), new ExpungeModule(), new ExtendModule(),
new StaffRollbackModule(), new ExemptionLuckPermsModule(), new ExemptionVaultModule(),
new WarnActionsModule()
),
assertDoesNotThrow(AddonLoader::loadAddonBindModules)
);
Expand Down
14 changes: 14 additions & 0 deletions bans-core-addons/command-extend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>space.arim.libertybans</groupId>
<artifactId>bans-core-addons</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>

<name>command-extend</name>
<artifactId>addon-command-extend</artifactId>
</project>
16 changes: 16 additions & 0 deletions bans-core-addons/command-extend/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import space.arim.libertybans.core.addon.AddonProvider;
import space.arim.libertybans.core.addon.extend.ExtendProvider;

module space.arim.libertybans.core.addon.extend {
requires jakarta.inject;
requires net.kyori.adventure;
requires net.kyori.examination.api;
requires static org.checkerframework.checker.qual;
requires static org.jetbrains.annotations;
requires space.arim.api.jsonchat;
requires space.arim.dazzleconf;
requires space.arim.injector;
requires space.arim.libertybans.core;
exports space.arim.libertybans.core.addon.extend;
provides AddonProvider with ExtendProvider;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* LibertyBans is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/>
* and navigate to version 3 of the GNU Affero General Public License.
*/

package space.arim.libertybans.core.addon.extend;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import space.arim.libertybans.core.addon.AbstractAddon;
import space.arim.libertybans.core.addon.AddonCenter;

@Singleton
public final class ExtendAddon extends AbstractAddon<ExtendConfig> {

@Inject
public ExtendAddon(AddonCenter addonCenter) {
super(addonCenter);
}

@Override
public void startup() {

}

@Override
public void shutdown() {

}

@Override
public Class<ExtendConfig> configInterface() {
return ExtendConfig.class;
}

@Override
public String identifier() {
return "command-extend";
}
}
Loading

0 comments on commit b5b4aa8

Please sign in to comment.