refactor & thread-safe cooldowns

This commit is contained in:
Govindas 2021-04-09 12:50:14 +03:00
parent bca1fab175
commit b18fc1f8cf
9 changed files with 115 additions and 20 deletions

94
pom.xml Normal file
View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>net.govindas</groupId>
<artifactId>Skooldown</artifactId>
<version>1.2.0</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.basedir}/compile</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/org/spigotmc/spigot-api/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>commons-pool2</id>
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
</repository>
<repository>
<id>PaperMC</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q</id>
<url>http://maven.sk89q.com/repo</url>
</repository>
</repositories>''
<dependencies>
<dependency>
<groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,19 +1,19 @@
package lt.govindas.skooldown; package net.govindas.skooldown;
import ch.njol.skript.Skript; import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.util.Timespan; import ch.njol.skript.util.Timespan;
import lt.govindas.skooldown.conditions.CondIsCooldownOver; import net.govindas.skooldown.conditions.CondIsCooldownOver;
import lt.govindas.skooldown.effects.EffEndCooldown; import net.govindas.skooldown.effects.EffEndCooldown;
import lt.govindas.skooldown.effects.EffStartCooldown; import net.govindas.skooldown.effects.EffStartCooldown;
import lt.govindas.skooldown.expressions.ExprCooldown; import net.govindas.skooldown.expressions.ExprCooldown;
import lt.govindas.skooldown.utilities.CleanupTimer; import net.govindas.skooldown.utilities.CleanupTimer;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap;
public final class Skooldown extends JavaPlugin { public final class Skooldown extends JavaPlugin {
public static HashMap<String, Long> cooldowns = new HashMap<String, Long>(); public static ConcurrentHashMap<String, Long> cooldowns = new ConcurrentHashMap<String, Long>();
@Override @Override
public void onEnable() { public void onEnable() {
@ -32,6 +32,7 @@ public final class Skooldown extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
cooldowns = null;
getLogger().info("Skript addon disabled!"); getLogger().info("Skript addon disabled!");
} }
} }

View File

@ -1,10 +1,10 @@
package lt.govindas.skooldown.conditions; package net.govindas.skooldown.conditions;
import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import lt.govindas.skooldown.Skooldown; import net.govindas.skooldown.Skooldown;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class CondIsCooldownOver extends Condition { public class CondIsCooldownOver extends Condition {

View File

@ -1,10 +1,10 @@
package lt.govindas.skooldown.effects; package net.govindas.skooldown.effects;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import lt.govindas.skooldown.Skooldown; import net.govindas.skooldown.Skooldown;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class EffEndCooldown extends Effect { public class EffEndCooldown extends Effect {

View File

@ -1,11 +1,11 @@
package lt.govindas.skooldown.effects; package net.govindas.skooldown.effects;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timespan; import ch.njol.skript.util.Timespan;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import lt.govindas.skooldown.Skooldown; import net.govindas.skooldown.Skooldown;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class EffStartCooldown extends Effect { public class EffStartCooldown extends Effect {

View File

@ -1,4 +1,4 @@
package lt.govindas.skooldown.expressions; package net.govindas.skooldown.expressions;
public class ExprAllCooldowns { public class ExprAllCooldowns {
//TODO //TODO

View File

@ -1,4 +1,4 @@
package lt.govindas.skooldown.expressions; package net.govindas.skooldown.expressions;
import ch.njol.skript.classes.Changer; import ch.njol.skript.classes.Changer;
@ -9,7 +9,7 @@ import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.util.Timespan; import ch.njol.skript.util.Timespan;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import lt.govindas.skooldown.Skooldown; import net.govindas.skooldown.Skooldown;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class ExprCooldown extends SimpleExpression<Timespan> { public class ExprCooldown extends SimpleExpression<Timespan> {

View File

@ -1,6 +1,6 @@
package lt.govindas.skooldown.utilities; package net.govindas.skooldown.utilities;
import lt.govindas.skooldown.Skooldown; import net.govindas.skooldown.Skooldown;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.Iterator; import java.util.Iterator;

View File

@ -1,5 +1,5 @@
name: Skooldown name: Skooldown
main: lt.govindas.skooldown.Skooldown main: lt.govindas.skooldown.Skooldown
version: 1.1.0 version: 1.2.0
author: Govindas author: Govindas
depend: [Skript] depend: [Skript]