Skip to content

Commit

Permalink
First public revision
Browse files Browse the repository at this point in the history
  • Loading branch information
horgeon committed Mar 30, 2020
1 parent 7000143 commit 7db98c1
Show file tree
Hide file tree
Showing 30 changed files with 2,806 additions and 0 deletions.
198 changes: 198 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.prodrivers.bukkit</groupId>
<artifactId>parkour-addon</artifactId>
<version>2.0</version>
<name>Prodrivers Parkour Addon</name>
<description></description>
<url>https://prodrivers.fr/</url>

<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>prodrivers-repo</id>
<url>https://repo.prodrivers.fr/</url>
</repository>
<repository>
<id>horgeon-repo</id>
<url>https://repo.horgeon.fr/repository/maven-all/</url>
</repository>
</repositories>

<dependencies>
<!--Lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Vault API-->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<!--InventoryGUIAPI-->
<dependency>
<groupId>me.eddie</groupId>
<artifactId>inventoryguiapi</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/libs/InventoryGUIAPI-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<!--Parkour plugin-->
<dependency>
<groupId>me.A5H73Y</groupId>
<artifactId>Parkour</artifactId>
<version>5.3</version>
<scope>system</scope>
<systemPath>${basedir}/libs/Parkour.jar</systemPath>
</dependency>
<!--Prodrivers Commons API-->
<dependency>
<groupId>fr.prodrivers.bukkit</groupId>
<artifactId>prodrivers-commons-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<!--Prodrivers Players-->
<!--<dependency>
<groupId>fr.prodrivers.bukkit</groupId>
<artifactId>players</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>-->
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>clean compile process-classes resources:resources assembly:single</defaultGoal>

<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}</directory>
<includes>
<include>README.md</include>
<include>LICENSE.md</include>
</includes>
</resource>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>*.java</exclude>
</excludes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.8</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:11.39.1</tile>
</tiles>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>fr.prodrivers.bukkit.parkouraddon.ParkourAddonPlugin</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<version>1.1</version>
<configuration>
<checkoutDirectory>${project.build.directory}/scmpublish</checkoutDirectory>
<checkinComment>Publishing documentation for ${project.artifactId}:${project.version}</checkinComment>
<content>${project.reporting.outputDirectory}/apidocs</content>
<skipDeletedFiles>true</skipDeletedFiles>
<pubScmUrl>scm:git:[email protected]:Prodrivers/bukkit-commons.git</pubScmUrl>
<scmBranch>gh-pages</scmBranch>
</configuration>
</plugin>
</plugins>
</build>

<distributionManagement>
<repository>
<id>prodrivers-repo</id>
<name>prodrivers-commons-releases</name>
<url>https://gitlab.com/api/v4/projects/12871610/packages/maven</url>
</repository>
<snapshotRepository>
<id>prodrivers-repo</id>
<name>prodrivers-commons-snapshots</name>
<url>https://gitlab.com/api/v4/projects/12871610/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
80 changes: 80 additions & 0 deletions src/main/java/fr/prodrivers/bukkit/parkouraddon/Categories.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package fr.prodrivers.bukkit.parkouraddon;

import io.ebean.SqlRow;
import fr.prodrivers.bukkit.parkouraddon.models.ParkourCategory;
import fr.prodrivers.bukkit.parkouraddon.models.ParkourCourse;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

class Categories {
private static HashMap<Integer, ParkourCategory> categories = new HashMap<>();
private static HashMap<Integer, Integer> numberOfCategories = new HashMap<>();

public static int getNumberOfCompletedCoursesInCategory( UUID playerUniqueId, ParkourCategory category ) {
SqlRow row = ParkourAddonPlugin.database
.createSqlQuery( "SELECT COUNT( courseId ) FROM parkourplayercompletion NATURAL JOIN course GROUP BY playeruuid, categoryId HAVING playeruuid = :playeruuid AND categoryId = :categoryid;" )
.setParameter( "playeruuid", Utils.getBytesFromUniqueId( playerUniqueId ) )
.setParameter( "categoryid", category.getCategoryId() )
.findOne();
return row.getInteger( "count( courseid )" );

/*// Retrieve player's completed courses
ParkourPlayerCompletion present = ParkourPlayerCompletion.retrieve( ParkourAddonPlugin.database, Utils.getBytesFromUniqueId( playerUniqueId ), category );
if( present != null ) { // If the player has already completed courses in this category
// Return the number of completed courses
return present.getNumber();
} else {
// Return 0 as the player hasn't completed any courses in this category
return 0;
}*/
}

static int getNumberOfCoursesInCategory( ParkourCategory category ) {
// Get the Category ID
int cid = category.getCategoryId();

if( numberOfCategories.containsKey( cid ) ) { // If the number of courses for this category is already cached
// Return the cached number
return numberOfCategories.get( cid );
} else {
// Retrieve the number from the database
int nb = ParkourAddonPlugin.database.createQuery( ParkourCourse.class ).setUseQueryCache( true ).where().eq( "categoryId", cid ).findCount();

// Store it inthe cache
numberOfCategories.put( cid, nb );

//Return it
return nb;
}
}

static void reload() {
// Clear the cache on configuration reload
numberOfCategories.clear();
categories.clear();
}

private static void generateCategories() {
categories.clear();
for( ParkourCategory category : ParkourAddonPlugin.database.find( ParkourCategory.class ).select( "*" ).findList() ) {
categories.put( category.getCategoryId(), category );
}
}

public static Collection<ParkourCategory> retrieveAll() {
if( categories.isEmpty() ) {
generateCategories();
}
return categories.values();
}

public static ParkourCategory retrieve( int id ) {
if( categories.isEmpty() ) {
generateCategories();
}
return categories.get( id );
}
}
Loading

0 comments on commit 7db98c1

Please sign in to comment.