Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PieTw3lve committed Mar 8, 2024
0 parents commit e55a6e2
Show file tree
Hide file tree
Showing 7 changed files with 884 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore
.vscode/
target/
src/test/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h1 align="center">DateCalculator</h1>
<p align="center">
<img src="https://github.com/PieTw3lve/DateCalculator/actions/workflows/maven.yml/badge.svg" alt="Build and Publish"></a>
<img src="https://img.shields.io/github/v/release/PieTw3lve/DateCalculator" alt="GitHub release (latest by date)">
<img src="https://img.shields.io/badge/Minecraft-1.20--1.20.4-orange.svg" alt="Supported versions">
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
</p>

## Information

- DateCalculator is a straightforward and lightweight plugin that enables you to calculate dates.
- This plugin is designed to be user-friendly and easy to use, with plans to develop it into a comprehensive date calculator.

## Features

- Calculate the amount of days between a date and the current date.

## Placeholders

| Placeholder | Description |
| ------------------------------------------------ | ------------------------------------------------------------------------------ |
| `%datecalculator_daysbetweentoday_<yyyy-MM-dd>%` | Calculates the number of days between the specified date and the current date. |

## Dependencies

- [PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.6245/) (Required)

## Reporting Issues

- If you encounter any issues with the plugin, please report them [here](https://github.com/PieTw3lve/DateCalculator/issues).
88 changes: 88 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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>com.github.pietw3lve</groupId>
<artifactId>PAPI-DateCalculator</artifactId>
<version>1.0.0</version>

<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>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- This adds the PlaceholderAPI Maven repository to the build -->
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--This adds the PlaceholderAPI artifact to the build -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.pietw3lve.datecalculator;

import org.bukkit.OfflinePlayer;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;

public class DateCalculatorExpansion extends PlaceholderExpansion {

private final DateCalculatorPlugin plugin;

public DateCalculatorExpansion(DateCalculatorPlugin plugin) {
this.plugin = plugin;
}

@Override
public String getAuthor() {
return "PieTw3lve";
}

@Override
public String getIdentifier() {
return "datecalculator";
}

@Override
public String getVersion() {
return "1.0.0";
}

@Override
public boolean persist() {
return true;
}

@Override
public String onRequest(OfflinePlayer player, String identifier) {
// %datecalculator_daysbetweentoday_<yyyy-MM-dd>%
if (identifier.startsWith("daysbetweentoday_")) {
String targetDate = identifier.substring(17);
plugin.getLogger().info(targetDate);
return plugin.getDaysBetweenToday(targetDate);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.pietw3lve.datecalculator;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

public class DateCalculatorPlugin extends JavaPlugin
{

public void onEnable()
{
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
getLogger().info("PlaceholderAPI found! Registering placeholders...");
new DateCalculatorExpansion(this).register();
} else {
getLogger().info("Could not find PlaceholderAPI! This plugin is required.");
Bukkit.getPluginManager().disablePlugin(this);
}
}

public String getDaysBetweenToday(String targetDate) {
try {
LocalDate today = LocalDate.now();
LocalDate target = LocalDate.parse(targetDate);
long days = ChronoUnit.DAYS.between(target, today);
return String.valueOf(days);
} catch (Exception e) {
return "Invalid date format!";
}
}
}
10 changes: 10 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: DateCalculator
main: com.github.pietw3lve.datecalculator.DateCalculatorPlugin
version: 1.0.0
api-version: 1.15
author: PieTw3lve
website: https://github.com/PieTw3lve/DateCalculator
description: A simple plugin to calculate the difference between two dates.

# This sets PlaceholderAPI as a dependency for your plugin.
depend: [PlaceholderAPI]

0 comments on commit e55a6e2

Please sign in to comment.