Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

ConditionalEvents runs actions when Minecraft events meet configured conditions:
commands, item use, joins, deaths, regions and more. Events can run once only or
on a cooldown. This copy tracks upstream 4.80.3 and builds for Paper 1.21.10. It
has no update checker or bStats reporting.
on a cooldown. Once-only and cooldown data belong to the roleplay character in
play, so such events run only while a character is in play; `data_scope: account`
keeps an event's data per account instead. Events without that data run as
upstream. This copy tracks upstream 4.80.3, builds for
Paper 1.21.10 and needs TLibs 2.6.1 with RPCharacters. It has no update checker or
bStats reporting.

## Documentation

Expand All @@ -18,6 +22,9 @@ covers event types, conditions, actions and variables.

With Java 21 and the private build inputs prepared by
`.github/scripts/prepare-release.sh`, run `mvn clean verify`.
JUnit and Mockito cover the per-character data, which must keep 100% line
coverage in `net.tfminecraft.conditionalevents.character`. Upstream
ConditionalEvents has no tests.

## License

Expand Down
92 changes: 92 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<argLine></argLine>
<tlibs.version>2.6.1</tlibs.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -83,6 +85,31 @@
<version>2.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.plugins</groupId>
<artifactId>tlibs</artifactId>
<version>${tlibs.version}</version>
<scope>provided</scope>
<exclusions>
<!-- The server supplies TLibs and its integrations. -->
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.20.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down Expand Up @@ -158,6 +185,71 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
<configuration>
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar} -Xshare:off</argLine>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.15</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>coverage-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>coverage-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<!-- TFMC's character code is fully covered; upstream ConditionalEvents has no tests. -->
<rules>
<rule>
<element>PACKAGE</element>
<includes>
<include>net.tfminecraft.conditionalevents.character</include>
</includes>
<limits>
<limit>
<counter>LINE</counter>
<value>MISSEDCOUNT</value>
<maximum>0</maximum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.tfminecraft.conditionalevents;


import net.tfminecraft.conditionalevents.character.CharacterTracker;
import net.tfminecraft.conditionalevents.api.ConditionalEventsAPI;
import net.tfminecraft.conditionalevents.api.ExpansionCE;
import net.tfminecraft.conditionalevents.configs.ConfigsManager;
Expand Down Expand Up @@ -35,6 +35,7 @@ public class ConditionalEvents extends JavaPlugin {
private EventsManager eventsManager;
private DependencyManager dependencyManager;
private PlayerManager playerManager;
private CharacterTracker characterTracker;
private ConfigsManager configsManager;
private DebugManager debugManager;
private BungeeMessagingManager bungeeMessagingManager;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void onEnable(){
this.interruptEventManager = new InterruptEventManager(this);
this.configsManager = new ConfigsManager(this);
this.configsManager.configure();
this.characterTracker = new CharacterTracker();

registerEvents();
registerCommands();
Expand All @@ -74,6 +76,7 @@ public void onEnable(){



characterTracker.start();
reloadPlayerDataSaveTask();

ConditionalEventsAPI api = new ConditionalEventsAPI(this);
Expand All @@ -97,6 +100,7 @@ public void onDisable(){
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerEventsListener(this), this);
pm.registerEvents(characterTracker, this);
pm.registerEvents(new ItemEventsListener(this), this);
pm.registerEvents(new ArmorListener(new ArrayList<>()), this);
pm.registerEvents(new ItemSelectListener(this), this);
Expand Down Expand Up @@ -223,6 +227,10 @@ public BungeeMessagingManager getBungeeMessagingManager() {
return bungeeMessagingManager;
}

public CharacterTracker getCharacterTracker() {
return characterTracker;
}

public PlayerManager getPlayerManager() {
return playerManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.tfminecraft.conditionalevents.character;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

import net.tfminecraft.tlibs.character.CharacterRef;
import net.tfminecraft.tlibs.character.CharacterSessionEndEvent;
import net.tfminecraft.tlibs.character.CharacterSessionStartEvent;
import net.tfminecraft.tlibs.character.Characters;

/**
* Which character each player is playing, readable from any thread, since events such as chat run
* off the main thread.
*/
public final class CharacterTracker implements Listener {
private final Map<UUID, UUID> current = new ConcurrentHashMap<>();

/** The character the player is playing, or empty between characters. */
public Optional<UUID> character(UUID account) {
return Optional.ofNullable(current.get(account));
}

/** Picks up characters already in play when the plugin enables. Main thread only. */
public void start() {
for (Player player : Bukkit.getOnlinePlayers()) {
Characters.currentSession(player).ifPresent(session -> begin(session.ref()));
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onStart(CharacterSessionStartEvent event) {
begin(event.getSession().ref());
}

@EventHandler(priority = EventPriority.MONITOR)
public void onEnd(CharacterSessionEndEvent event) {
CharacterRef ref = event.getSession().ref();
current.remove(ref.ownerId(), ref.characterId());
}

@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent event) {
current.remove(event.getPlayer().getUniqueId());
}

private void begin(CharacterRef ref) {
current.put(ref.ownerId(), ref.characterId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void configureEvents(){
List<String> conditions = new ArrayList<String>();
List<ActionGroup> actionGroups = new ArrayList<ActionGroup>();
boolean oneTime = false;
boolean characterScoped = true;
String ignoreWithPermission = null;
long cooldown = 0;
boolean enabled = true;
Expand Down Expand Up @@ -167,6 +168,13 @@ public void configureEvents(){
if(config.contains(path+".one_time")) {
oneTime = Boolean.valueOf(config.getString(path+".one_time"));
}
if(config.contains(path+".data_scope")) {
String scope = config.getString(path+".data_scope");
characterScoped = !"account".equalsIgnoreCase(scope);
if(characterScoped && !"character".equalsIgnoreCase(scope)){
plugin.getLogger().warning("Event "+key+" has data_scope "+scope+"; use character or account. Using character.");
}
}
if(config.contains(path+".enabled")) {
enabled = Boolean.valueOf(config.getString(path+".enabled"));
}
Expand All @@ -190,6 +198,7 @@ public void configureEvents(){
event.setCooldown(cooldown);
event.setIgnoreWithPermission(ignoreWithPermission);
event.setOneTime(oneTime);
event.setCharacterScoped(characterScoped);
event.setEnabled(enabled);
event.setIgnoreIfCancelled(ignoreIfCancelled);
event.setPreventCooldownActivationActionGroups(preventCooldownActivationActionGroups);
Expand Down
Loading
Loading