11package ca .q0r .mchannels .channels ;
22
3- import ca .q0r .mchannels .configs .ChannelUtil ;
43import ca .q0r .mchannels .types .ChannelEditType ;
54import ca .q0r .mchannels .types .ChannelType ;
65
76import java .util .HashSet ;
87import java .util .Set ;
98
109public class ChannelManager {
11- private static Set <Channel > channels = new HashSet <Channel >();
10+ private static Set <Channel > channels ;
11+ private static ChannelYml yml ;
1212
1313 public static void initialize () {
1414 channels = new HashSet <Channel >();
15+ yml = new ChannelYml ();
1516
1617 loadChannels ();
1718 }
@@ -23,17 +24,17 @@ public static Set<Channel> getChannels() {
2324 }
2425
2526 /**
26- * Loads Channels from ChannelUtil to Memory.
27+ * Loads Channels from yml to Memory.
2728 */
2829 public static void loadChannels () {
29- for (String key : ChannelUtil .getConfig ().getKeys (false )) {
30- ChannelType type = ChannelType .fromName (ChannelUtil .getConfig ().getString (key + ".type" ));
31- String prefix = ChannelUtil .getConfig ().getString (key + ".prefix" , "[" );
32- String suffix = ChannelUtil .getConfig ().getString (key + ".suffix" , "]" );
33- Boolean passworded = ChannelUtil .getConfig ().getBoolean (key + ".passworded" , false );
34- String password = ChannelUtil .getConfig ().getString (key + ".password" , "" );
35- Integer distance = ChannelUtil .getConfig ().getInt (key + ".distance" , -1 );
36- Boolean defaulted = ChannelUtil .getConfig ().getBoolean (key + ".default" , false );
30+ for (String key : yml .getConfig ().getKeys (false )) {
31+ ChannelType type = ChannelType .fromName (yml .getConfig ().getString (key + ".type" ));
32+ String prefix = yml .getConfig ().getString (key + ".prefix" , "[" );
33+ String suffix = yml .getConfig ().getString (key + ".suffix" , "]" );
34+ Boolean passworded = yml .getConfig ().getBoolean (key + ".passworded" , false );
35+ String password = yml .getConfig ().getString (key + ".password" , "" );
36+ Integer distance = yml .getConfig ().getInt (key + ".distance" , -1 );
37+ Boolean defaulted = yml .getConfig ().getBoolean (key + ".default" , false );
3738
3839 if (type == null ) {
3940 type = ChannelType .GLOBAL ;
@@ -47,41 +48,43 @@ public static void loadChannels() {
4748 * Loads a Channel from the config.
4849 */
4950 public static void loadChannel (String name ) {
50- ChannelType type = ChannelType .fromName (ChannelUtil .getConfig ().getString (name + ".type" ));
51- String prefix = ChannelUtil .getConfig ().getString (name + ".prefix" , "[" );
52- String suffix = ChannelUtil .getConfig ().getString (name + ".suffix" , "]" );
53- Boolean passworded = ChannelUtil .getConfig ().getBoolean (name + ".passworded" , false );
54- String password = ChannelUtil .getConfig ().getString (name + ".password" , "" );
55- Integer distance = ChannelUtil .getConfig ().getInt (name + ".distance" , -1 );
56- Boolean defaulted = ChannelUtil .getConfig ().getBoolean (name + ".default" , false );
51+ ChannelType type = ChannelType .fromName (yml .getConfig ().getString (name + ".type" ));
52+ String prefix = yml .getConfig ().getString (name + ".prefix" , "[" );
53+ String suffix = yml .getConfig ().getString (name + ".suffix" , "]" );
54+ Boolean passworded = yml .getConfig ().getBoolean (name + ".passworded" , false );
55+ String password = yml .getConfig ().getString (name + ".password" , "" );
56+ Integer distance = yml .getConfig ().getInt (name + ".distance" , -1 );
57+ Boolean defaulted = yml .getConfig ().getBoolean (name + ".default" , false );
5758
5859 channels .add (new Channel (name .toLowerCase (), type , prefix , suffix , passworded , password , distance , defaulted ));
5960 }
6061
6162
6263 /**
63- * Reloads Channels from ChannelUtil to Memory.
64+ * Reloads Channels from yml to Memory.
6465 */
6566 public static void reloadChannels () {
66- for (String key : ChannelUtil .getConfig ().getKeys (false )) {
67+ yml = new ChannelYml ();
68+
69+ for (String key : yml .getConfig ().getKeys (false )) {
6770 if (getChannel (key ) != null ) {
6871 Channel channel = getChannel (key );
6972
70- channel .setType (ChannelType .fromName (ChannelUtil .getConfig ().getString (key + ".type" )));
71- channel .setPrefix (ChannelUtil .getConfig ().getString (key + ".prefix" , "[" ));
72- channel .setSuffix (ChannelUtil .getConfig ().getString (key + ".suffix" , "]" ));
73- channel .setPassword (ChannelUtil .getConfig ().getString (key + ".password" , "" ));
74- channel .setPassworded (ChannelUtil .getConfig ().getBoolean (key + ".passworded" , false ), channel .getPassword ());
75- channel .setDistance (ChannelUtil .getConfig ().getInt (key + ".distance" , -1 ));
76- channel .setDefault (ChannelUtil .getConfig ().getBoolean (key + ".default" , false ));
73+ channel .setType (ChannelType .fromName (yml .getConfig ().getString (key + ".type" )));
74+ channel .setPrefix (yml .getConfig ().getString (key + ".prefix" , "[" ));
75+ channel .setSuffix (yml .getConfig ().getString (key + ".suffix" , "]" ));
76+ channel .setPassword (yml .getConfig ().getString (key + ".password" , "" ));
77+ channel .setPassworded (yml .getConfig ().getBoolean (key + ".passworded" , false ), channel .getPassword ());
78+ channel .setDistance (yml .getConfig ().getInt (key + ".distance" , -1 ));
79+ channel .setDefault (yml .getConfig ().getBoolean (key + ".default" , false ));
7780 } else {
7881 loadChannel (key );
7982 }
8083 }
8184 }
8285
8386 /**
84- * Loads Channels from ChannelUtil to Memory.
87+ * Loads Channels from yml to Memory.
8588 * @param name Name of Channel being created.
8689 * @param type Type of Channel being created.
8790 * @param prefix Prefix of Channel being created.
@@ -94,23 +97,23 @@ public static void reloadChannels() {
9497 public static void createChannel (String name , ChannelType type , String prefix , String suffix , Boolean passworded , String password , Integer distance , Boolean defaulted ) {
9598 channels .add (new Channel (name .toLowerCase (), type , prefix , suffix , passworded , password , distance , defaulted ));
9699
97- ChannelUtil .getConfig ().set (name .toLowerCase () + ".type" , type .getName ());
98- ChannelUtil .getConfig ().set (name .toLowerCase () + ".prefix" , prefix );
99- ChannelUtil .getConfig ().set (name .toLowerCase () + ".suffix" , suffix );
100- ChannelUtil .getConfig ().set (name .toLowerCase () + ".passworded" , passworded );
101- ChannelUtil .getConfig ().set (name .toLowerCase () + ".password" , password );
102- ChannelUtil .getConfig ().set (name .toLowerCase () + ".distance" , distance );
103- ChannelUtil .getConfig ().set (name .toLowerCase () + ".default" , defaulted );
100+ yml .getConfig ().set (name .toLowerCase () + ".type" , type .getName ());
101+ yml .getConfig ().set (name .toLowerCase () + ".prefix" , prefix );
102+ yml .getConfig ().set (name .toLowerCase () + ".suffix" , suffix );
103+ yml .getConfig ().set (name .toLowerCase () + ".passworded" , passworded );
104+ yml .getConfig ().set (name .toLowerCase () + ".password" , password );
105+ yml .getConfig ().set (name .toLowerCase () + ".distance" , distance );
106+ yml .getConfig ().set (name .toLowerCase () + ".default" , defaulted );
104107
105108 if (defaulted ) {
106109 setDefaultChannel (name );
107110 }
108111
109- ChannelUtil .save ();
112+ yml .save ();
110113 }
111114
112115 /**
113- * Removes a Channel from ChannelUtil /Memory.
116+ * Removes a Channel from yml /Memory.
114117 * @param name Name of Channel being removed.
115118 */
116119 public static void removeChannel (String name ) {
@@ -126,9 +129,9 @@ public static void removeChannel(String name) {
126129 if (isReal ) {
127130 channels .remove (getChannel (name ));
128131
129- ChannelUtil .getConfig ().set (name , null );
132+ yml .getConfig ().set (name , null );
130133
131- ChannelUtil .save ();
134+ yml .save ();
132135 }
133136 }
134137
@@ -148,7 +151,7 @@ public static Channel getChannel(String name) {
148151 }
149152
150153 /**
151- * Saves all Channels in Memory to ChannelUtil .
154+ * Saves all Channels in Memory to yml .
152155 */
153156 public static void saveChannels () {
154157 for (Channel channel : channels ) {
@@ -161,15 +164,15 @@ public static void saveChannels() {
161164 * @param channel Channel being saved.
162165 */
163166 public static void saveChannel (Channel channel ) {
164- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".type" , channel .getType ().getName ().toLowerCase ());
165- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".prefix" , channel .getPrefix ());
166- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".suffix" , channel .getSuffix ());
167- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".passworded" , channel .isPassworded ());
168- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".password" , channel .getPassword ());
169- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".distance" , channel .getDistance ());
170- ChannelUtil .getConfig ().set (channel .getName ().toLowerCase () + ".default" , channel .isDefault ());
171-
172- ChannelUtil .save ();
167+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".type" , channel .getType ().getName ().toLowerCase ());
168+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".prefix" , channel .getPrefix ());
169+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".suffix" , channel .getSuffix ());
170+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".passworded" , channel .isPassworded ());
171+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".password" , channel .getPassword ());
172+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".distance" , channel .getDistance ());
173+ yml .getConfig ().set (channel .getName ().toLowerCase () + ".default" , channel .isDefault ());
174+
175+ yml .save ();
173176 }
174177
175178 /**
@@ -240,15 +243,15 @@ public static Set<Channel> getPlayersChannels(String player) {
240243 }
241244
242245 /**
243- * Loads Channels from ChannelUtil to Memory.
246+ * Loads Channels from yml to Memory.
244247 * @param channel Name of Channel being edited.
245248 * @param type EditType being used.
246249 * @param option Option being used.
247250 */
248251 public static void editChannel (Channel channel , ChannelEditType type , Object option ) {
249252 if (option .getClass () == type .getOptionClass ()) {
250253 if (type .getName ().equalsIgnoreCase ("name" )) {
251- ChannelUtil .getConfig ().set (channel .getName (), null );
254+ yml .getConfig ().set (channel .getName (), null );
252255
253256 channel .setName ((String ) option );
254257 } else if (type .getName ().equalsIgnoreCase ("default" )) {
0 commit comments