Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AceKiron committed Jan 24, 2025
0 parents commit f15022d
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and upload artifact
on:
push:
pull_request:
workflow_dispatch:

jobs:
build-jar:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Maven Action
uses: s4u/setup-maven-action@v1.18.0
with:
java-version: 21

- run: mvn package

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: pmc-base
path: target/pmc-chat-addon-*.jar
23 changes: 23 additions & 0 deletions .github/workflows/update-license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Update copyright year(s) in license file

on:
workflow_dispatch:
schedule:
- cron: '0 3 1 1 *'

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: FantasticFiasco/action-update-license-year@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: |
LICENSE
commitTitle: "docs: update copyright years"
prTitle: "docs: update copyright years"
prBody: "It's that time of the year, let's update the license"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
target/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 AceKiron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions chataddon.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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.PronounMC</groupId>
<artifactId>pmc-chat-addon</artifactId>
<version>2025.1</version>
<packaging>jar</packaging>

<name>PronounMC-ChatAddon</name>

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>pronounmc</id>
<url>https://maven.pkg.github.com/PronounMC/pmc-base</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.PronounMC</groupId>
<artifactId>pmc-base</artifactId>
<version>2025.1</version>
</dependency>
</dependencies>
</project>
41 changes: 41 additions & 0 deletions src/main/java/dev/mxace/pronounmc/addons/chataddon/ChatAddon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.mxace.pronounmc.addons.chataddon;

import dev.mxace.pronounmc.addons.chataddon.listeners.ChatListener;
import dev.mxace.pronounmc.addons.chataddon.listeners.PlaceholderAPIChatListener;

import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;

public final class ChatAddon extends JavaPlugin {

@Override
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
// PlaceholderAPI found
File file = new File(getDataFolder(), "config.yml");

if (!file.exists()) {
saveResource("config.yml", false);
}

YamlConfiguration yaml = new YamlConfiguration();
yaml.options().parseComments(true);

try {
yaml.load(file);
} catch (IOException | InvalidConfigurationException ex) {
Bukkit.getLogger().severe("Could not load config from '" + file.getPath() + "'.");
}

getServer().getPluginManager().registerEvents(new PlaceholderAPIChatListener(yaml.getString("placeholderapi-chat-format", "<%player_name%>[%pronounmc_identifier%]")), this);
} else {
// PlaceholderAPI not found
getServer().getPluginManager().registerEvents(new ChatListener(), this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.mxace.pronounmc.addons.chataddon;

public class ChatAddonConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.mxace.pronounmc.addons.chataddon.listeners;

import dev.mxace.pronounmc.manager.PronounsManager;

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.AsyncPlayerChatEvent;

public class ChatListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
event.setCancelled(true);

String msg = "<" + event.getPlayer().getDisplayName() + ">[" + PronounsManager.getPronouns(event.getPlayer()).getIdentifier() + "] " + event.getMessage();

Bukkit.getLogger().info(msg);

for (Player recipient : event.getRecipients()) {
recipient.sendMessage(msg);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.mxace.pronounmc.addons.chataddon.listeners;

import me.clip.placeholderapi.PlaceholderAPI;
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.AsyncPlayerChatEvent;

public class PlaceholderAPIChatListener implements Listener {
private final String format;

public PlaceholderAPIChatListener(String format) {
this.format = format;
}

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
event.setCancelled(true);

String msg = PlaceholderAPI.setPlaceholders(event.getPlayer(), format) + " " + event.getMessage();

Bukkit.getLogger().info(msg);

for (Player recipient : event.getRecipients()) {
recipient.sendMessage(msg);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholderapi-chat-format: "<%player_name%>[%pronounmc_identifier%]"
8 changes: 8 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: PronounMC-ChatAddon
version: '2025.1'
main: dev.mxace.pronounmc.addons.chataddon.ChatAddon
api-version: '1.21'
depend:
- PronounMC
softdepend:
- PlaceholderAPI

0 comments on commit f15022d

Please sign in to comment.