mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Finish mcMMO addon
This commit is contained in:
1 parent
f54a71a25b
commit
0bb3c5b232
5 files changed
+75
-51
No files matched your search
@@ -5,14 +5,15 @@ import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.impls.SimpleChatChannel;
|
||||
import net.draycia.simplechat.storage.ChatUser;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PartyChatChannel extends SimpleChatChannel implements Listener {
|
||||
|
||||
public PartyChatChannel(String name, SimpleChat simpleChat) {
|
||||
super(name, simpleChat);
|
||||
public PartyChatChannel(String name, SimpleChat simpleChat, ConfigurationSection config) {
|
||||
super(name, simpleChat, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,25 +1,44 @@
|
||||
package net.draycia.simplechatmcmmo;
|
||||
|
||||
import net.draycia.simplechat.events.ChannelRegisterEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class SimpleChatMCMMO extends JavaPlugin {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||
|
||||
for (String key : getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ConfigurationSection section = getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
ChatChannel channel = loadChannel(key, section);
|
||||
|
||||
if (channel != null) {
|
||||
if (simpleChat.getChannelManager().registerChannel(channel)) {
|
||||
getLogger().info("Registering channel: " + channel.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
||||
ChatChannel channel = new PartyChatChannel(key, simpleChat, section);
|
||||
|
||||
@EventHandler
|
||||
public void onChannelRegister(ChannelRegisterEvent event) {
|
||||
String name = section.getString("name");
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
getLogger().warning("Skipping channel, please check your settings!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
channels:
|
||||
+10
-19
@@ -22,12 +22,14 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
private String key;
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
private ConfigurationSection config;
|
||||
|
||||
private SimpleChatChannel() { }
|
||||
|
||||
public SimpleChatChannel(String key, SimpleChat simpleChat) {
|
||||
public SimpleChatChannel(String key, SimpleChat simpleChat, ConfigurationSection config) {
|
||||
this.key = key;
|
||||
this.simpleChat = simpleChat;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public SimpleChat getSimpleChat() {
|
||||
@@ -244,9 +246,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
public Map<String, String> getFormats() {
|
||||
HashMap<String, String> formats = new HashMap<>();
|
||||
|
||||
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||
ConfigurationSection formatSection = section.getConfigurationSection("formats");
|
||||
ConfigurationSection formatSection = config.getConfigurationSection("formats");
|
||||
|
||||
if (formatSection == null) {
|
||||
formatSection = simpleChat.getConfig().getConfigurationSection("default").getConfigurationSection("formats");
|
||||
@@ -353,11 +353,8 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
private String getString(String key) {
|
||||
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||
|
||||
if (section != null && section.contains(key)) {
|
||||
return section.getString(key);
|
||||
if (config != null && config.contains(key)) {
|
||||
return config.getString(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||
@@ -370,11 +367,8 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
private boolean getBoolean(String key) {
|
||||
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||
|
||||
if (section != null && section.contains(key)) {
|
||||
return section.getBoolean(key);
|
||||
if (config != null && config.contains(key)) {
|
||||
return config.getBoolean(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||
@@ -387,11 +381,8 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
private double getDouble(String key) {
|
||||
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
|
||||
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
|
||||
|
||||
if (section != null && section.contains(key)) {
|
||||
return section.getDouble(key);
|
||||
if (config != null && config.contains(key)) {
|
||||
return config.getDouble(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
+33
-21
@@ -9,46 +9,58 @@ import net.draycia.simplechat.util.Registry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ChannelManager {
|
||||
|
||||
private ChannelRegistry registry;
|
||||
private String defaultChannelKey = null;
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
public ChannelManager(SimpleChat simpleChat) {
|
||||
registry = new ChannelRegistry(simpleChat);
|
||||
List<ChatChannel> channels = new ArrayList<>();
|
||||
this.simpleChat = simpleChat;
|
||||
this.registry = new ChannelRegistry(simpleChat);
|
||||
|
||||
for (String key : simpleChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ChatChannel channel = new SimpleChatChannel(key, simpleChat);
|
||||
|
||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
String name = section.getString("name");
|
||||
ChatChannel channel = loadChannel(key, section);
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
simpleChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
simpleChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
continue;
|
||||
if (channel != null) {
|
||||
if (registerChannel(channel)) {
|
||||
simpleChat.getLogger().info("Registering channel: " + channel.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
channels.add(channel);
|
||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
||||
ChatChannel channel = new SimpleChatChannel(key, simpleChat, section);
|
||||
|
||||
if (channel.isDefault()) {
|
||||
simpleChat.getLogger().info("Default channel found: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
}
|
||||
String name = section.getString("name");
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
simpleChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
simpleChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ChatChannel channel : channels) {
|
||||
simpleChat.getLogger().info("Registering channel: " + channel.getName());
|
||||
getRegistry().register(channel.getKey(), channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(channels, getRegistry()));
|
||||
public boolean registerChannel(ChatChannel channel) {
|
||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||
|
||||
if (success) {
|
||||
if (channel.isDefault() && defaultChannelKey == null) {
|
||||
simpleChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public Registry<ChatChannel> getRegistry() {
|
||||
|
||||
Reference in new issue
Block a user