Skip to content

Commit

Permalink
New Addons : /is chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Dec 24, 2024
1 parent f1531bf commit 78e738f
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions addons/SkylliaChat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id("java")
}

group = "fr.euphyllia.skyllia";
version = "1.1";

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
compileOnly(project(":api"))
compileOnly(project(":plugin"))
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks {
compileJava {
options.encoding = "UTF-8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fr.euphyllia.skylliachat;

import fr.euphyllia.skyllia.api.SkylliaAPI;
import fr.euphyllia.skyllia.api.skyblock.Island;
import fr.euphyllia.skyllia.api.skyblock.Players;
import fr.euphyllia.skyllia.configuration.LanguageToml;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

public class ChatListeners implements Listener {

private final Main plugin;

public ChatListeners(Main plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent event) {
Player player = event.getPlayer();

if (Main.getPlugin(Main.class).getIslandChatEnabled().getOrDefault(player, false)) {
event.setCancelled(true);

Bukkit.getAsyncScheduler().runNow(Main.getPlugin(Main.class), scheduledTask -> {
Island island = SkylliaAPI.getCacheIslandByPlayerId(player.getUniqueId());
if (island == null) {
LanguageToml.sendMessage(player, LanguageToml.messagePlayerHasNotIsland);
return;
}

String message = event.getMessage();
String format = this.plugin.getConfig().getString("chat.format", "<red>[Messaging Island] %player_name%: <gray>%message%")
.replace("%player_name%", player.getName())
.replace("%message%", message);
for (Players islandMember : island.getMembersCached()) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(islandMember.getMojangId());
if (offlinePlayer.isOnline() && offlinePlayer.getPlayer() != null) {
LanguageToml.sendMessage(offlinePlayer.getPlayer(), format);
}
}
});
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.euphyllia.skylliachat;

import fr.euphyllia.skyllia.api.SkylliaAPI;
import fr.euphyllia.skyllia.api.commands.SubCommandRegistry;
import fr.euphyllia.skylliachat.commands.IslandChatCommand;
import fr.euphyllia.skylliachat.commands.IslandChatReloadCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.concurrent.ConcurrentHashMap;

public final class Main extends JavaPlugin {

private final ConcurrentHashMap<Player, Boolean> islandChatEnabled = new ConcurrentHashMap<>();

@Override
public void onEnable() {
saveDefaultConfig();
// Plugin startup logic
SkylliaAPI.registerCommands(new IslandChatCommand(this), "chat");
SkylliaAPI.registerAdminCommands(new IslandChatReloadCommand(this), "chat_reload");

getServer().getPluginManager().registerEvents(new ChatListeners(this), this);
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

public ConcurrentHashMap<Player, Boolean> getIslandChatEnabled() {
return islandChatEnabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.euphyllia.skylliachat.commands;

import fr.euphyllia.skyllia.api.commands.SubCommandInterface;
import fr.euphyllia.skyllia.configuration.LanguageToml;
import fr.euphyllia.skylliachat.Main;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

public class IslandChatCommand implements SubCommandInterface {

private final Main plugin;

public IslandChatCommand(Main main) {
plugin = main;
}

@Override
public boolean onCommand(@NotNull Plugin plugin, @NotNull CommandSender sender, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
LanguageToml.sendMessage(sender, LanguageToml.messageCommandPlayerOnly);
return true;
}
if (!sender.hasPermission("skylliachat.use")) {
LanguageToml.sendMessage(sender, "<red>You are not a permission to execute this commands.");
return true;
}

// Toggle island chat mode
boolean isEnabled = this.plugin.getIslandChatEnabled().getOrDefault(player, false);
this.plugin.getIslandChatEnabled().put(player, !isEnabled);

String msg;
if (isEnabled) {
msg = this.plugin.getConfig().getString("message.chat.disabled", "<red>Island messaging Disabled.");
} else {
msg = this.plugin.getConfig().getString("message.chat.enabled", "<green>Island Messaging Enabled.");
}
LanguageToml.sendMessage(sender, msg);
return true;
}

@Override
public @NotNull List<String> onTabComplete(@NotNull Plugin plugin, @NotNull CommandSender sender, @NotNull String[] args) {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.euphyllia.skylliachat.commands;

import fr.euphyllia.skyllia.api.commands.SubCommandInterface;
import fr.euphyllia.skyllia.configuration.LanguageToml;
import fr.euphyllia.skylliachat.Main;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

public class IslandChatReloadCommand implements SubCommandInterface {

private final Main plugin;

public IslandChatReloadCommand(Main plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(@NotNull Plugin plugin, @NotNull CommandSender sender, @NotNull String[] args) {
if (!sender.hasPermission("skylliachat.reload")) {
LanguageToml.sendMessage(sender, "<red>You are not a permission to execute this commands.");
return true;
}

// Recharge la configuration
this.plugin.reloadConfig();

String msg = this.plugin.getConfig().getString("message.config.reloaded", "<green>Configuration successfully reloaded!");
LanguageToml.sendMessage(sender, msg);
return true;
}

@Override
public @NotNull List<String> onTabComplete(@NotNull Plugin plugin, @NotNull CommandSender sender, @NotNull String[] args) {
return Collections.emptyList();
}
}
9 changes: 9 additions & 0 deletions addons/SkylliaChat/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
chat:
format: "<red>[Messaging Island] %player_name%: <gray>%message%"

message:
config:
reloaded: "<green>Configuration successfully reloaded!"
chat:
enabled: "<green>Island Messaging Enabled."
disabled: "<red>Island messaging Disabled."
12 changes: 12 additions & 0 deletions addons/SkylliaChat/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: SkylliaChat
version: '1.1'
main: fr.euphyllia.skylliachat.Main
api-version: '1.20'
folia-supported: true

dependencies:
server:
Skyllia:
load: OMIT
required: true
join-classpath: true
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ include("nms:v1_21_R3")
// Addons
include("addons:OreGenerator")
include("addons:PapiSkyllia")
include("addons:InsightsSkyllia")
include("addons:InsightsSkyllia")
include("addons:SkylliaChat")

0 comments on commit 78e738f

Please sign in to comment.