Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit e026f63

Browse files
author
Giacomello Nathan
committed
Merge branch 'release/0.0.1b' into develop
2 parents 191e7f7 + 77d692f commit e026f63

5 files changed

Lines changed: 399 additions & 16 deletions

File tree

pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@
6262
<scope>provided</scope>
6363
</dependency>
6464

65-
<!-- Network -->
66-
<dependency>
67-
<groupId>com.github.froxynetwork</groupId>
68-
<artifactId>froxynetwork</artifactId>
69-
<version>0.1.2</version>
70-
</dependency>
71-
72-
<!-- Game -->
73-
<dependency>
74-
<groupId>com.github.froxynetwork</groupId>
75-
<artifactId>froxygame</artifactId>
76-
<version>0.0.1</version>
77-
</dependency>
78-
7965
<!--Spigot API -->
8066
<dependency>
8167
<groupId>org.spigotmc</groupId>

src/main/java/com/froxynetwork/froxyapi/API.java

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.froxynetwork.froxyapi;
22

3+
import java.io.File;
4+
5+
import org.bukkit.Server;
36
import org.bukkit.plugin.java.JavaPlugin;
7+
import org.slf4j.Logger;
8+
9+
import com.froxynetwork.froxyapi.language.LanguageManager;
10+
import com.froxynetwork.froxyapi.language.Languages;
411

512
/**
613
* MIT License
@@ -28,9 +35,100 @@
2835
* @author 0ddlyoko
2936
*/
3037
/**
31-
* All methods are here
38+
* Interface for all methods (like {@link Server} for Spigot)
3239
*/
3340
public interface API {
3441

35-
public JavaPlugin getPlugin();
42+
/**
43+
* @return The JavaPlugin implementation of the Core plugin
44+
*/
45+
public JavaPlugin getCorePlugin();
46+
47+
/**
48+
* @return The JavaPlugin implementation of the Game plugin
49+
*/
50+
public JavaPlugin getGamePlugin();
51+
52+
/**
53+
* @return The version of the actual Core
54+
*/
55+
public String getVersion();
56+
57+
/**
58+
* @return The logger
59+
*/
60+
public Logger getLogger();
61+
62+
// -----------------------------------------
63+
// | |
64+
// | Language Manager |
65+
// | |
66+
// -----------------------------------------
67+
68+
/**
69+
* @return The LanguageManager
70+
*/
71+
public LanguageManager getLanguageManager();
72+
73+
/**
74+
* @return The default language
75+
*/
76+
public default Languages getDefaultLanguage() {
77+
return getLanguageManager().getDefaultLanguage();
78+
}
79+
80+
/**
81+
* Register a path as a language directory.<br />
82+
* All language files MUST have the correct name to be loaded.<br />
83+
* Files name MUST be of this form: "{name}.lang".<br />
84+
* Example: <code>fr_FR.lang or en_US.lang</code>
85+
*
86+
* @param path The directory
87+
*/
88+
public default void register(File path) {
89+
getLanguageManager().register(path);
90+
}
91+
92+
/**
93+
* Get the default translate of specific message id.<br />
94+
* Same as <code>$(id, getDefaultLanguage(), params)</code>
95+
*
96+
* @param id The id of the message
97+
* @param params The parameters
98+
* @return The message translated by default language, or the id if message id doesn't exist
99+
*/
100+
public default String $(String id, String... params) {
101+
return getLanguageManager().$(id, params);
102+
}
103+
104+
/**
105+
* Get the translation of specific message id with specific language. If message id not found, return the translation with DEFAULT language
106+
*
107+
* @param id The id of the message
108+
* @param lang The specific language
109+
* @param params The parameters
110+
* @return The message translated by specific language, or the message translated by default language, or the id if message id doesn't exist
111+
*/
112+
public default String $(String id, Languages lang, String... params) {
113+
return getLanguageManager().$(id, lang, params);
114+
}
115+
116+
/**
117+
* Get the translate of specific id with specific language
118+
*
119+
* @param id The id of the message
120+
* @param lang The specific language
121+
* @param params The parameters
122+
* @return The message translated by specific language, or the id if message id doesn't exist
123+
*/
124+
public default String $_(String id, Languages lang, String... params) {
125+
return getLanguageManager().$_(id, lang, params);
126+
}
127+
128+
// -----------------------------------------
129+
// | |
130+
// | Other |
131+
// | |
132+
// -----------------------------------------
133+
36134
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package com.froxynetwork.froxyapi;
2+
3+
import java.io.File;
4+
5+
import org.bukkit.plugin.java.JavaPlugin;
6+
import org.slf4j.Logger;
7+
8+
import com.froxynetwork.froxyapi.language.LanguageManager;
9+
import com.froxynetwork.froxyapi.language.Languages;
10+
11+
/**
12+
* MIT License
13+
*
14+
* Copyright (c) 2019 FroxyNetwork
15+
*
16+
* Permission is hereby granted, free of charge, to any person obtaining a copy
17+
* of this software and associated documentation files (the "Software"), to deal
18+
* in the Software without restriction, including without limitation the rights
19+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20+
* copies of the Software, and to permit persons to whom the Software is
21+
* furnished to do so, subject to the following conditions:
22+
*
23+
* The above copyright notice and this permission notice shall be included in
24+
* all copies or substantial portions of the Software.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32+
* SOFTWARE.
33+
*
34+
* @author 0ddlyoko
35+
*/
36+
/**
37+
* Represents the API core, for version and API singleton handling
38+
*/
39+
public final class Froxy {
40+
41+
private static API api;
42+
43+
private Froxy() {
44+
}
45+
46+
/**
47+
* Gets the current {@link API} singleton
48+
*
49+
* @return API instance being ran
50+
*/
51+
public static API getAPI() {
52+
return api;
53+
}
54+
55+
/**
56+
* Attempts to set the {@link API} singleton.
57+
* <p>
58+
* This cannot be done if the API is already set.
59+
*
60+
* @param api API instance
61+
*/
62+
public static void setAPI(API api) {
63+
if (Froxy.api != null)
64+
throw new UnsupportedOperationException("Cannot redefine singleton API");
65+
Froxy.api = api;
66+
api.getLogger().info("");
67+
}
68+
69+
/**
70+
* @return The JavaPlugin implementation of the Core plugin
71+
*/
72+
public static JavaPlugin getCorePlugin() {
73+
return api.getCorePlugin();
74+
}
75+
76+
/**
77+
* @return The JavaPlugin implementation of the Game plugin
78+
*/
79+
public static JavaPlugin getGamePlugin() {
80+
return api.getGamePlugin();
81+
}
82+
83+
/**
84+
* @return The version of the actual Core
85+
*/
86+
public static String getVersion() {
87+
return api.getVersion();
88+
}
89+
90+
/**
91+
* @return The logger
92+
*/
93+
public static Logger getLogger() {
94+
return api.getLogger();
95+
}
96+
97+
// -----------------------------------------
98+
// | |
99+
// | Language Manager |
100+
// | |
101+
// -----------------------------------------
102+
103+
public static LanguageManager getLanguageManager() {
104+
return api.getLanguageManager();
105+
}
106+
107+
public static Languages getDefaultLanguage() {
108+
return api.getDefaultLanguage();
109+
}
110+
111+
/**
112+
* Register a path as a language directory.<br />
113+
* All language files MUST have the correct name to be loaded.<br />
114+
* Files name MUST be of this form: "{name}.lang".<br />
115+
* Example: <code>fr_FR.lang or en_US.lang</code>
116+
*
117+
* @param path The directory
118+
*/
119+
public static void register(File path) {
120+
api.register(path);
121+
}
122+
123+
/**
124+
* Get the default translate of specific message id.<br />
125+
* Same as <code>$(id, getDefaultLanguage(), params)</code>
126+
*
127+
* @param id The id of the message
128+
* @param params The parameters
129+
* @return The message translated by default language, or the id if message id doesn't exist
130+
*/
131+
public static String $(String id, String... params) {
132+
return api.$(id, params);
133+
}
134+
135+
/**
136+
* Get the translation of specific message id with specific language. If message id not found, return the translation with DEFAULT language
137+
*
138+
* @param id The id of the message
139+
* @param lang The specific language
140+
* @param params The parameters
141+
* @return The message translated by specific language, or the message translated by default language, or the id if message id doesn't exist
142+
*/
143+
public static String $(String id, Languages lang, String... params) {
144+
return api.$(id, lang, params);
145+
}
146+
147+
/**
148+
* Get the translate of specific id with specific language
149+
*
150+
* @param id The id of the message
151+
* @param lang The specific language
152+
* @param params The parameters
153+
* @return The message translated by specific language, or the id if message id doesn't exist
154+
*/
155+
public static String $_(String id, Languages lang, String... params) {
156+
return api.$_(id, lang, params);
157+
}
158+
159+
// -----------------------------------------
160+
// | |
161+
// | Other |
162+
// | |
163+
// -----------------------------------------
164+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.froxynetwork.froxyapi.language;
2+
3+
import java.io.File;
4+
5+
/**
6+
* MIT License
7+
*
8+
* Copyright (c) 2019 FroxyNetwork
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*
28+
* @author 0ddlyoko
29+
*/
30+
/**
31+
* Interface for the Language Manager.<br />
32+
* With this interface, you can manage language
33+
*/
34+
public interface LanguageManager {
35+
36+
/**
37+
* @return The default language of the server
38+
*/
39+
public Languages getDefaultLanguage();
40+
41+
/**
42+
* Register a path as a language directory.<br />
43+
* All language files MUST have the correct name to be loaded.<br />
44+
* Files name MUST be of this form: "{name}.lang".<br />
45+
* Example: <code>fr_FR.lang or en_US.lang</code>
46+
*
47+
* @param path The directory
48+
*/
49+
public void register(File path);
50+
51+
/**
52+
* Get the default translate of specific message id.<br />
53+
* Same as <code>$(id, getDefaultLanguage(), params)</code>
54+
*
55+
* @param id The id of the message
56+
* @param params The parameters
57+
* @return The message translated by default language, or the id if message id doesn't exist
58+
*/
59+
public default String $(String id, String... params) {
60+
return $(id, getDefaultLanguage(), params);
61+
}
62+
63+
/**
64+
* Get the translation of specific message id with specific language. If message id not found, return the translation with DEFAULT language
65+
*
66+
* @param id The id of the message
67+
* @param lang The specific language
68+
* @param params The parameters
69+
* @return The message translated by specific language, or the message translated by default language, or the id if message id doesn't exist
70+
*/
71+
public String $(String id, Languages lang, String... params);
72+
73+
/**
74+
* Get the translate of specific id with specific language
75+
*
76+
* @param id The id of the message
77+
* @param lang The specific language
78+
* @param params The parameters
79+
* @return The message translated by specific language, or the id if message id doesn't exist
80+
*/
81+
public String $_(String id, Languages lang, String... params);
82+
}

0 commit comments

Comments
 (0)