From 54263855a3a7100f7d27e77ef1e52c3fda0438be Mon Sep 17 00:00:00 2001 From: jerembdn Date: Wed, 15 Nov 2023 17:34:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20base=20listeners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 17 +++++++++ .project | 34 ++++++++++++++++++ .settings/org.eclipse.buildship.core.prefs | 13 +++++++ .settings/org.eclipse.jdt.apt.core.prefs | 4 +++ .settings/org.eclipse.jdt.core.prefs | 10 ++++++ .vscode/settings.json | 4 ++- .../thegreensuits/folia_survival/Main.class | Bin 0 -> 1320 bytes .../listener/AsyncPlayerChatListener.class | Bin 0 -> 3419 bytes .../listener/PlayerJoinListener.class | Bin 0 -> 1454 bytes .../listener/PlayerQuitListener.class | Bin 0 -> 1096 bytes build.gradle | 7 ++-- .../fr/thegreensuits/folia_survival/Main.java | 17 +++++++++ .../listener/AsyncPlayerChatListener.java | 30 ++++++++++++++++ .../listener/PlayerJoinListener.java | 17 +++++++++ .../listener/PlayerQuitListener.java | 12 +++++++ 15 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.buildship.core.prefs create mode 100644 .settings/org.eclipse.jdt.apt.core.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/main/fr/thegreensuits/folia_survival/Main.class create mode 100644 bin/main/fr/thegreensuits/folia_survival/listener/AsyncPlayerChatListener.class create mode 100644 bin/main/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.class create mode 100644 bin/main/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.class create mode 100644 src/main/java/fr/thegreensuits/folia_survival/listener/AsyncPlayerChatListener.java create mode 100644 src/main/java/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.java create mode 100644 src/main/java/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8404c28 --- /dev/null +++ b/.classpath @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..31b19c3 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + folia-survival + Project folia-survival created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + + + 1700065081804 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..8fe5149 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..faa4735 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..162fb05 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 1133129..7daa38d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,5 @@ { - "java.configuration.updateBuildConfiguration": "automatic" + "java.configuration.updateBuildConfiguration": "automatic", + "java.compile.nullAnalysis.mode": "automatic", + "editor.wordWrap": "off" } \ No newline at end of file diff --git a/bin/main/fr/thegreensuits/folia_survival/Main.class b/bin/main/fr/thegreensuits/folia_survival/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..bb8e2ac4f9976980350c99caf67ab9b616bdb95e GIT binary patch literal 1320 zcmb7D|4!3T7(JIwx^-p11Vn^w2*Ngn`dhT15QIch2xhp%zf575a;4syu3N%;_#$co zK@%UqhcbR`$LJzP{HN_b_x60}eD{1me|`G_U5Uxw#T__G=<;L_gzO= z?;1_7C0drFZ(2esNHR>io~`dT4-bW}e{`C*kotS8W$7FA*bdhWsaIRoot3TCHHI1U zGRy`;@1l^xf6kC7m1_*iRkzMnB#_adAe9C~pN1>wW#~7BZo^9BNbW_wSUs>}R25``o1NF7<8E}brfY|{F;2G;rnKn`M|TJn z($=G0BZd166YD|Vi`91Ci;>kL52I68@eq#{JYpFA8;yo1SfJbrx$g#1it0HQ)v5X( zm7{)d{|y2DR!oy*<7zg5;-zxttF)VUoNj zXru`Y=7hcy^i8u9B7i|}MrgWn0=4oL+GkqyAWP3|_@jm-`sjET{e)@JVGM*+6#fp; zr;r$^5mBykjGn zA9Az)h#YpMw7s(Fd)Xn!GL2(i*_|*a3@dAyo-b|bX7_lLcJZKPOiDLDV)%tfuAx$3 z#R+4=$XbRyoINmjLKb}u)dF>nJDeRXkB*vtR!&IU&(3WUsNQATroUUDqPb;2pfc~2 zWCj&jszXCsV0po`Wp8i7N8$g5krP^6x8FtB%ZZ3n> zSfimf%D!o3^NwYa0v?!Kigj48p4qVJ0bY;mb z8os2nO}JXaRRU|~olQ8QqZuvqcgVDS=?dJ?d~u6$R1$`Wa~n2m*uS#dch; zV<&D9NSh4a@ErnBn{cQ*lGBkKZql%emuB9~+^UY8R!0QHcJQ7mjXoXy zxSgAf@o{OF1U8>fHO#Tt?&!Q+8h5aM%}!mfY#r8dM0uR{ozSZcj^Z8-cPFZ2xTND4 zjx$GG$-s)lVQ>6gR#&%Ao-9kdD08vH6Y_Z8M7Swl26Yrw%o*<-$_h@YV+g|nO9`hc zqpCO%NOB)zaBd;D1SUo`oS^5iXU&bvX`tqKzugLPVJoih1_jO;~@djl*S_hsir1H+haN&#}m|w2-;&= z0z2azMUcnXi6j@`CC zQW!B?z=~KUR0V_mtU9zJa9QGj_*JG>ZL+OSj?cB$O$#jUy0Deqv~x+HZxly+jPa;5 zr!8Y_uw-o9DzHDn_CH5>;e!RNeAgK7k^YEN@-lcIA8PnO;EJG_28F=1C!A54Ed()A(HJs{ ztjLo(KElVmXJhjsfj{ETMLR>|VcYjM793}^JRZO7ixVudv7bD})&Kosc;v(pO+7!9#b5@!}1|Ax_jkGj7B;3>?O literal 0 HcmV?d00001 diff --git a/bin/main/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.class b/bin/main/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.class new file mode 100644 index 0000000000000000000000000000000000000000..6664193967210d67170ff45f272f4712659d2528 GIT binary patch literal 1454 zcmbtUTTc@~7(G)iTgn1bfdZlwZO%>d z_`st-%J@yUK%tVD_^@-^GvAzZzWL_Y@9#eWjAPkAh#|QnEw#(Dl5^M33FTWmo+Iqf zeop2^-gYcU_=>w+S}Try#N~n~+;nNlKsCdyJv(n(j_qcx<;))6QU+=nIy{-RGP(VI zp)8)~uCmTIG1QI;SE#oPRf)b0hUzJAn@3QEdJ_i13{7d_@}=BChRbz3<8X#(+S{_7 z4Op%k7J>WCqJ19+u`AheO1pG(cGts7`(h+W#grlfGQ zlR4pRa~Vb_<>c&m^yAraW`O!naT-JrLzlMqE<{TMxQHP5sTdS?JV8m80zaViZ=#c6YVmcQ@ggB@*Gc^NMej`{oLxr zCPQ1fUl*994)j)Qdv{GzP-4kSJI*C(mnTe2YRU%rs14L>(VHh6}pCFLB#U+V_4@DJs<}3)zGUH zqMqIWYU^lbQO~Ha=|4f_Yw@>9ZEbO}4h=Lm0{|M)L^HbiXr>@h8aL4FHhnD|t!OL8 z`+{ov3G5F1Kx{MGae_Mo1>8HuLxuwSqr=n`@T7p}dRb#m@ah{z3K$P??~6EsoMI}3 vb5L~lB2XD16~ZOuD4ndy_7KroqM9Y5ntofrr$nEa;RDh{nqiUthOqPpP5y<1 literal 0 HcmV?d00001 diff --git a/bin/main/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.class b/bin/main/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.class new file mode 100644 index 0000000000000000000000000000000000000000..f0659785e3827647cc7ff94a7e84bd694295e67c GIT binary patch literal 1096 zcmbtTTTc@~6#fPZTb32Hau;Qb7s_?LV^T5k8XqcNFiq4LGo?crSY~l{wh6z8_~=WC zn)rZk{wU*_Z4Je0V&cQ@nKL`*obUVgo9{n9e+96DWd~gh#SI;pO;OWAs5p@(4mP4t z@^^8f>$1+nAe6BYO6cHO$oGVPPG?H3Ee9EflUuybgOICQ@U*fe){TQ+hVe+(f=aTz zElnWmLYd%K5kv27sie8X&|R1`-83s#IiPdDMBJ@jM2?ay06s_~H z%(b+6YcpduWz4Wr`VR(01}{=a%or95r4H!3Df2b~9$H343x51XqKw=TWf@C?c2}v$ za3do{$fi0wrG<~Vs)j-r9Sk#!9?7?6v{bcwi43bkXE93J9`4_IbGTn!r1;jSg^MAK zTbU*ph6|Wm)n8h4fgYWJNRb^QG6SLh)?!wKVNU$eL literal 0 HcmV?d00001 diff --git a/build.gradle b/build.gradle index c77ada1..9981f24 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -55,7 +54,7 @@ dependencies { testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.22' } -spotless { +/* spotless { format 'misc', { target '*.gradle', '*.md', '.gitignore' @@ -78,4 +77,4 @@ spotless { endWithNewline() setEncoding('utf-8') } -} \ No newline at end of file +} */ \ No newline at end of file diff --git a/src/main/java/fr/thegreensuits/folia_survival/Main.java b/src/main/java/fr/thegreensuits/folia_survival/Main.java index 27351ba..e7db23a 100644 --- a/src/main/java/fr/thegreensuits/folia_survival/Main.java +++ b/src/main/java/fr/thegreensuits/folia_survival/Main.java @@ -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"); } } diff --git a/src/main/java/fr/thegreensuits/folia_survival/listener/AsyncPlayerChatListener.java b/src/main/java/fr/thegreensuits/folia_survival/listener/AsyncPlayerChatListener.java new file mode 100644 index 0000000..1de396c --- /dev/null +++ b/src/main/java/fr/thegreensuits/folia_survival/listener/AsyncPlayerChatListener.java @@ -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 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("%", "%%")); + } +} diff --git a/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.java b/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.java new file mode 100644 index 0000000..d96d2e9 --- /dev/null +++ b/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerJoinListener.java @@ -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()); + } +} diff --git a/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.java b/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.java new file mode 100644 index 0000000..766f9fa --- /dev/null +++ b/src/main/java/fr/thegreensuits/folia_survival/listener/PlayerQuitListener.java @@ -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 !"); + } +}