Skip to content

Commit

Permalink
Merge branch 'main' into localization
Browse files Browse the repository at this point in the history
  • Loading branch information
jonagamerpro1234 authored Sep 2, 2023
2 parents 429f068 + b385e1e commit 3488f3e
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 52 deletions.
4 changes: 2 additions & 2 deletions CustomJoinAndQuitMessagesOld/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ Welcome:

# |Text| here you can set your own welcome message when entering
Text:
- '<GRADIENT:8200FC>&m=========================================</GRADIENT:00FC95>&r'
- '<gradient:8200FC:00FC95>&m=========================================</gradient>&r'
- '<0>'
- '&e> &7Welcome To The Server &b<name>'
- '<0>'
- '&e> &cShop: shop-example.com'
- '&e> &7Use &b/skin to put on a skin'
- '<0>'
- '<GRADIENT:8200FC>&m=========================================</GRADIENT:00FC95>&r'
- '<gradient:8200FC:00FC95>&m=========================================</gradient>&r'
#
# |File-Version| I would not change anything
File-Version: 4
Expand Down
6 changes: 6 additions & 0 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>jss.customjoinandquitmessage.libs.bstats</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package jss.customjoinandquitmessage;

import jss.customjoinandquitmessage.commands.CommandHandler;
import jss.customjoinandquitmessage.files.GroupFile;
import jss.customjoinandquitmessage.files.utils.PreConfigLoader;
import jss.customjoinandquitmessage.listeners.chat.JoinListener;
import jss.customjoinandquitmessage.listeners.chat.QuitListener;
import jss.customjoinandquitmessage.managers.JoinQuitMessageHandlerFactory;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
Expand All @@ -24,22 +26,31 @@ public final class CustomJoinAndQuitMessage extends JavaPlugin {
private final PreConfigLoader preConfigLoader = new PreConfigLoader(this);
private BukkitAudiences adventure;
private Metrics metrics;
public GroupFile groupFile;

public void onLoad() {
instance = this;

}

public void onEnable() {
this.adventure = BukkitAudiences.create(this);
metrics = new Metrics(this,6318);
saveDefaultConfig();

metrics.addCustomChart( new SimplePie("using_the_group_function", () -> getConfig().getString("ChatFormat.Type","group")));
metrics = new Metrics(this,6318);

saveDefaultConfig();
preConfigLoader.loadConfigs();
if(!preConfigLoader.loadLangs()){
Bukkit.getPluginManager().disablePlugins();
}

groupFile = new GroupFile();
groupFile.saveDefaultConfig();

metrics.addCustomChart( new SimplePie("using_the_group_function", () -> getConfig().getString("ChatFormat.Type","group")));

new JoinQuitMessageHandlerFactory();

registerListener(
new JoinListener(),
new QuitListener()
Expand Down Expand Up @@ -81,8 +92,8 @@ public PreConfigLoader getPreConfigLoader() {
return preConfigLoader;
}


public static CustomJoinAndQuitMessage get(){
return instance;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if(args[0].equalsIgnoreCase("reload")){
listOptions.add("config");
listOptions.add("lang");
listOptions.add("handlers");
}
break;
}

return Utils.setLimitTab(listOptions, lastArgs);
}


public ArrayList<SubCommand> getSubCommands() {
return subCommands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import jss.commandapi.SubCommand;
import jss.customjoinandquitmessage.files.utils.Settings;
import jss.customjoinandquitmessage.utils.MessageUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@SuppressWarnings("unused")

public class DisplayCommand extends SubCommand {

public String name() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package jss.customjoinandquitmessage.commands.subcommands;

import jss.commandapi.SubCommand;
import jss.customjoinandquitmessage.CustomJoinAndQuitMessage;
import jss.customjoinandquitmessage.files.utils.Settings;
import jss.customjoinandquitmessage.utils.MessageUtils;
import org.bukkit.command.CommandSender;

public class HelpCommand extends SubCommand {

private final CustomJoinAndQuitMessage plugin = CustomJoinAndQuitMessage.get();

public String name() {
return "help";
}
Expand All @@ -20,9 +23,13 @@ public boolean requiresPermission() {
}

public boolean onCommand(CommandSender sender, String[] args) {
MessageUtils.sendColorMessage(sender, " ");
MessageUtils.sendColorMessage(sender, "&5-=-=-=-=-=-=-=-=-=&6[&d" + plugin.name + "&6]&5=-=-=-=-=-=-=-=-=-");
for (String s : Settings.lang_helpCommand) {
MessageUtils.sendColorMessage(sender, s);
}
MessageUtils.sendColorMessage(sender, "&5-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
MessageUtils.sendColorMessage(sender, " ");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import jss.commandapi.SubCommand;
import jss.customjoinandquitmessage.CustomJoinAndQuitMessage;
import jss.customjoinandquitmessage.files.utils.Settings;
import jss.customjoinandquitmessage.managers.JoinQuitMessageHandlerFactory;
import jss.customjoinandquitmessage.utils.Utils;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class ReloadCommand extends SubCommand {

private static final CustomJoinAndQuitMessage plugin = CustomJoinAndQuitMessage.get();
private final JoinQuitMessageHandlerFactory handlerFactory = JoinQuitMessageHandlerFactory.getInstance();

public String name() {
return "reload";
Expand All @@ -26,6 +28,12 @@ public boolean requiresPermission() {
public boolean onCommand(CommandSender sender, String @NotNull [] args) {
if (args.length >= 2){

if(args[1].equalsIgnoreCase("handlers")){
handlerFactory.updateActiveHandler();
Utils.sendColorMessage(sender, Settings.lang_reloadCommand);
return true;
}

if(args[1].equalsIgnoreCase("config")){
plugin.getPreConfigLoader().loadConfigs();
Utils.sendColorMessage(sender, Settings.lang_reloadCommand);
Expand All @@ -42,6 +50,7 @@ public boolean onCommand(CommandSender sender, String @NotNull [] args) {
return true;
}

handlerFactory.updateActiveHandler();
plugin.reloadAllFiles();
Utils.sendColorMessage(sender, Settings.lang_reloadCommand);
return true;
Expand All @@ -52,10 +61,10 @@ public boolean allowConsole() {
}

public boolean isEnabled() {
return false;
return true;
}

public String disabledMessage() {
return null;
return Settings.lang_disableCommand;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,60 @@

import jss.customjoinandquitmessage.CustomJoinAndQuitMessage;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

public class GroupFile {

private final CustomJoinAndQuitMessage plugin = CustomJoinAndQuitMessage.get();
private File file;
private FileConfiguration config;

//create groups.yml file
public void createFile() throws IOException {
this.file = new File(plugin.getDataFolder(), "groups.yml");

if(!file.exists()){
file.createNewFile();
public FileConfiguration getConfig() {
if (this.config == null) {
reloadConfig();
}
return this.config;
}

//get config for groups.yml
public FileConfiguration get(){
return config;
public void saveConfig() {
try {
this.config.save(this.file);
} catch (IOException ex) {
ex.printStackTrace();
}
}

//reload groups.yml file
public void reload(){
public void reloadConfig() {
if (this.config == null) {
this.file = new File(plugin.getDataFolder(), "groups.yml");
}
this.config = YamlConfiguration.loadConfiguration(this.file);
Reader defaultConfigStream;
try {
defaultConfigStream = new InputStreamReader(Objects.requireNonNull(plugin.getResource("groups.yml")), StandardCharsets.UTF_8);
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigStream);
config.setDefaults(defaultConfig);
} catch (NullPointerException ex) {
ex.printStackTrace();


}
}

public void saveDefaultConfig() {
if (this.file == null) {
this.file = new File(plugin.getDataFolder(), "groups.yml");
}
if (!this.file.exists()) {
plugin.saveResource("groups.yml", false);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void loadMessages(){
Settings.lang_reloadCommand = config.getString("ReloadCommand");
Settings.lang_usageDisplayCommand = config.getString("UsageDisplayCommand");
Settings.lang_unknownSound = config.getString("UnknownSound");
Settings.lang_disableCommand = config.getString("DisableCommand");
Settings.lang_disableCommand = config.getString("DisabledCommand");
Settings.lang_updateAlert_console = config.getStringList("UpdateAlert.Console");
Settings.lang_updateAlert_player = config.getStringList("UpdateAlert.Player");
Settings.lang_helpCommand = config.getStringList("HelpCommand");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public PreConfigLoader(CustomJoinAndQuitMessage plugin) {
this.plugin = plugin;
}

@SuppressWarnings("unused")
public void loadConfigs(){
FileConfiguration config = plugin.getConfig();
Settings.config_Lang = config.getString("Settings.Lang");
Expand Down Expand Up @@ -98,7 +97,7 @@ public boolean loadLangs(){
}

if(!availableLangs.containsKey(Settings.config_Lang)){
Settings.config_Lang = "en_US";
//Settings.config_Lang = "en_US";
availableLangs.put(Settings.config_Lang, new LangFile(plugin, Settings.config_Lang,0));
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jss.customjoinandquitmessage.CustomJoinAndQuitMessage;
import jss.customjoinandquitmessage.files.utils.Settings;
import jss.customjoinandquitmessage.managers.JoinQuitMessageHandlerFactory;
import jss.customjoinandquitmessage.utils.MessageUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -11,7 +13,7 @@

public class JoinListener implements Listener {

private static final CustomJoinAndQuitMessage plugin = CustomJoinAndQuitMessage.get();
private final JoinQuitMessageHandlerFactory handlerFactory = JoinQuitMessageHandlerFactory.getInstance();

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onJoin(@NotNull PlayerJoinEvent e){
Expand All @@ -20,12 +22,16 @@ public void onJoin(@NotNull PlayerJoinEvent e){
boolean isNormal = Settings.chatformat_type.equalsIgnoreCase("normal");
boolean isGroup = Settings.chatformat_type.equalsIgnoreCase("group");

if(isNormal){


handlerFactory.getActiveHandler().welcome(p);

if(isNormal){
e.setJoinMessage(null);
handlerFactory.getActiveHandler().handlerJoinAndQuitMessages(p,true);
handlerFactory.getActiveHandler().handlerJoinAndQuitTitle(p,true);
handlerFactory.getActiveHandler().handlerJoinAndQuitActionbar(p,true);
}else if (isGroup) {

e.setJoinMessage(null);
MessageUtils.sendColorMessage(p,"Test group");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
package jss.customjoinandquitmessage.listeners.chat;

import jss.customjoinandquitmessage.files.utils.Settings;
import jss.customjoinandquitmessage.managers.JoinQuitMessageHandlerFactory;
import jss.customjoinandquitmessage.utils.MessageUtils;
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.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;

public class QuitListener implements Listener {

@EventHandler
public void onQuit(PlayerQuitEvent e){
private final JoinQuitMessageHandlerFactory handlerFactory = JoinQuitMessageHandlerFactory.getInstance();

}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onQuit(@NotNull PlayerQuitEvent e){
Player p = e.getPlayer();
boolean isNormal = Settings.chatformat_type.equalsIgnoreCase("normal");
boolean isGroup = Settings.chatformat_type.equalsIgnoreCase("group");

handlerFactory.getActiveHandler().welcome(p);

if(isNormal){
e.setQuitMessage(null);
handlerFactory.getActiveHandler().handlerJoinAndQuitMessages(p,false);
handlerFactory.getActiveHandler().handlerJoinAndQuitTitle(p,false);
handlerFactory.getActiveHandler().handlerJoinAndQuitActionbar(p,false );
}else if (isGroup) {
e.setQuitMessage(null);
MessageUtils.sendColorMessage(p,"Test group");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import org.bukkit.entity.Player;

// This is an abstract class that defines the methods for handling join and quit messages.
public abstract class AbstractJoinQuitMessageHandler {

// This method handles join and quit messages for a player.
public abstract void handlerJoinAndQuitMessages(Player player, boolean isJoin);

// This method sends a welcome message to a player.
public abstract void welcome(Player player);

// This method handles join and quit titles for a player.
public abstract void handlerJoinAndQuitTitle(Player player, boolean isJoin);

// This method handles join and quit actionbar messages for a player.
public abstract void handlerJoinAndQuitActionbar(Player player, boolean isJoin);

// This method handles join and quit sounds for a player.
public abstract void handlerJoinAndQuitSound(Player player, boolean isJoin);

}
Loading

0 comments on commit 3488f3e

Please sign in to comment.