Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlayerJoin, PlayerQuit and AsyncPlayerChat listeners #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="src" path="bin/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/default"/>
</classpath>
34 changes: 34 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>folia-survival</name>
<comment>Project folia-survival created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1700065081804</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=--init-script /home/jijon/.vscode-server/data/User/globalStorage/redhat.java/1.24.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle --init-script /home/jijon/.vscode-server/data/User/globalStorage/redhat.java/1.24.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/protobuf/init.gradle
auto.sync=true
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-17-openjdk-amd64
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
4 changes: 4 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=bin/generated-sources/annotations
org.eclipse.jdt.apt.genTestSrcDir=bin/generated-test-sources/annotations
10 changes: 10 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.nonnull=javax.annotation.Nonnull
org.eclipse.jdt.core.compiler.annotation.nullable=javax.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
org.eclipse.jdt.core.compiler.processAnnotations=enabled
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic",
"editor.wordWrap": "off"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ buildscript {
}

plugins {
id 'com.github.spotless-java' version '6.22.0'
//id 'com.github.spotless-java' version '6.22.0'
id 'java'
}

group 'fr.thegreensuits'
sourceCompatibility = '17'
version '1.0'

apply plugin: 'com.github.johnrengelman.shadow'
Expand Down Expand Up @@ -55,7 +54,7 @@ dependencies {
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.22'
}

spotless {
/* spotless {
format 'misc', {
target '*.gradle', '*.md', '.gitignore'

Expand All @@ -78,4 +77,4 @@ spotless {
endWithNewline()
setEncoding('utf-8')
}
}
} */
17 changes: 17 additions & 0 deletions src/main/java/fr/thegreensuits/folia_survival/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@

import org.bukkit.plugin.java.JavaPlugin;

import fr.thegreensuits.folia_survival.listener.AsyncPlayerChatListener;
import fr.thegreensuits.folia_survival.listener.PlayerJoinListener;
import fr.thegreensuits.folia_survival.listener.PlayerQuitListener;

public class Main extends JavaPlugin {
public static Main INSTANCE;

public Main() {
INSTANCE = this;
}

@Override
public void onEnable() {
super.onEnable();

getServer().getPluginManager().registerEvents(new PlayerJoinListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new AsyncPlayerChatListener(), INSTANCE);

getLogger().info("Folia Survival plugin enabled");
}

@Override
public void onDisable() {
super.onLoad();
getLogger().info("Folia Survival plugin disabled");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fr.thegreensuits.folia_survival.listener;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

public class AsyncPlayerChatListener implements Listener {
@EventHandler()
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
List<Player> mentionnedPlayers = Bukkit.getOnlinePlayers()
.stream()
.filter(player -> event.getMessage().contains(player.getDisplayName()) && event.getPlayer() != player)
.collect(
java.util.stream.Collectors.toList());

for (Player player : mentionnedPlayers) {
event.setMessage(event.getMessage().replace(player.getDisplayName(),
"§5§l" + player.getDisplayName() + "§7"));
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1f, 1f);
}

event.setFormat(
"§7" + event.getPlayer().getDisplayName() + " §8»§7 " + event.getMessage().replaceAll("%", "%%"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.thegreensuits.folia_survival.listener;

import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public class PlayerJoinListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage("§8[§b+§8] §b" + event.getPlayer().getDisplayName() + "§7 a rejoint le serveur !");

event.getPlayer().setDisplayName(ChatColor.GRAY + event.getPlayer().getName());
event.getPlayer().setPlayerListName("§7" + event.getPlayer().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.thegreensuits.folia_survival.listener;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerQuitListener implements Listener {
@EventHandler()
public void onPlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage("§8[§d-§8] §d" + event.getPlayer().getDisplayName() + "§7 a quitté le serveur !");
}
}