Skip to content

Commit 3b9fe21

Browse files
author
TheProgramSrc
committed
Changelog:
* Code Improvements
1 parent 0819f39 commit 3b9fe21

28 files changed

+138
-198
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>4.1.4</version>
9+
<version>4.2.0-BETA0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/SuperPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ default void registerLogFilter(LogsFilter logsFilter){
166166

167167
/**
168168
* Gets the plugin data storage
169-
* @return
169+
* @return the plugin data storage
170170
*/
171171
PluginDataStorage getPluginDataStorage();
172172
}

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/BungeeModule.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,44 @@ public class BungeeModule extends SuperModule<Listener> implements Listener {
1010

1111
protected BungeePlugin bungeePlugin;
1212

13-
public BungeeModule(BungeePlugin plugin, boolean registerListener){
14-
super(plugin);
15-
this.bungeePlugin = plugin;
13+
public BungeeModule(boolean registerListener){
14+
super(BungeePlugin.i);
15+
this.bungeePlugin = BungeePlugin.i;
1616
if(registerListener) this.listener(this);
1717
this.onLoad();
1818
}
1919

20-
public BungeeModule(BungeePlugin plugin){
21-
this(plugin, true);
20+
public BungeeModule(){
21+
this(true);
2222
}
2323

2424
@Override
2525
protected void listener(Listener... listeners) {
26-
((BungeePlugin)this.plugin).listener(listeners);
26+
this.bungeePlugin.listener(listeners);
2727
}
2828

2929
/**
3030
* Gets the BungeeCord Plugin Settings
3131
* @return The Plugin Settings
3232
*/
3333
protected Settings getSettings(){
34-
return ((BungeePlugin)this.plugin).getSettings();
34+
return this.bungeePlugin.getSettings();
3535
}
3636

3737
/**
3838
* Gets the proxy
3939
* @return The proxy
4040
*/
4141
protected ProxyServer getProxy(){
42-
return ((BungeePlugin)this.plugin).getProxy();
42+
return this.bungeePlugin.getProxy();
4343
}
4444

4545
/**
4646
* Gets the BungeeTasks util
4747
* @return the BungeeTasks util
4848
*/
4949
protected BungeeTasks getBungeeTasks(){
50-
return ((BungeePlugin)this.plugin).getBungeeTasks();
50+
return this.bungeePlugin.getBungeeTasks();
5151
}
5252

5353
}

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/BungeePlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public void onLoad() {
5959
public void onEnable() {
6060
if(this.emergencyStop) return;
6161
this.log("Enabling plugin &3v" + this.getPluginVersion());
62-
this.bungeeTasks = new BungeeTasks(this);
63-
this.settings = new Settings(this);
62+
this.bungeeTasks = new BungeeTasks();
63+
this.settings = new Settings();
6464
this.translationsFolder = Utils.folder(new File(this.getDataFolder(), "translations/"));
6565
this.translationManager = new TranslationManager(this);
6666
this.getTranslationManager().registerTranslation(Base.class);
67-
new BungeeEventManager(this);
67+
new BungeeEventManager();
6868
PluginClassLoader classLoader = new ReflectionClassLoader(this);
6969
this.dependencyManager = new DependencyManager(this, classLoader);
7070
this.dependencyManager.loadDependencies(Dependencies.get());

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/commands/BungeeCommand.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.md_5.bungee.api.connection.ProxiedPlayer;
66
import net.md_5.bungee.api.plugin.Command;
77
import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
8-
import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin;
98
import xyz.theprogramsrc.supercoreapi.bungee.utils.BungeeConsole;
109
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
1110

@@ -17,20 +16,17 @@ public abstract class BungeeCommand extends BungeeModule {
1716

1817
/**
1918
* Create a new {@link BungeeCommand BungeeCommand}
20-
*
21-
* @param plugin The {@link BungeePlugin BungeeCord Plugin}
2219
*/
23-
public BungeeCommand(final BungeePlugin plugin){
24-
super(plugin);
25-
getProxy().getPluginManager().registerCommand(plugin, new Command(this.getCommand(), this.getPermission(), this.getAliases()) {
20+
public BungeeCommand(){
21+
getProxy().getPluginManager().registerCommand(this.bungeePlugin, new Command(this.getCommand(), this.getPermission(), this.getAliases()) {
2622
@Override
2723
public void execute(CommandSender sender, String[] args) {
2824
CommandResult result;
2925
if(sender instanceof ProxiedPlayer){
3026
ProxiedPlayer player = ((ProxiedPlayer)sender);
3127
result = BungeeCommand.this.onPlayerExecute(player, args);
3228
}else{
33-
result = BungeeCommand.this.onConsoleExecute(new BungeeConsole(plugin), args);
29+
result = BungeeCommand.this.onConsoleExecute(new BungeeConsole(), args);
3430
}
3531
BungeeCommand.this.onResult(sender, result);
3632
}
@@ -39,17 +35,17 @@ public void execute(CommandSender sender, String[] args) {
3935

4036
private void onResult(CommandSender sender, CommandResult result){
4137
if(result == CommandResult.NO_PERMISSION){
42-
sender.sendMessage(new TextComponent(this.plugin.getSuperUtils().color(Base.NO_PERMISSION.toString())));
38+
sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_PERMISSION.toString())));
4339
}else if(result == CommandResult.NO_ACCESS){
44-
sender.sendMessage(new TextComponent(this.plugin.getSuperUtils().color(Base.NO_ACCESS.toString())));
40+
sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_ACCESS.toString())));
4541
}else if(result == CommandResult.NOT_SUPPORTED){
4642
if(sender instanceof ProxiedPlayer){
47-
sender.sendMessage(new TextComponent(this.plugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.CONSOLE.toString()).toString())));
43+
sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.CONSOLE.toString()).toString())));
4844
}else{
49-
sender.sendMessage(new TextComponent(this.plugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.PLAYERS.toString()).toString())));
45+
sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.PLAYERS.toString()).toString())));
5046
}
5147
}else if(result == CommandResult.INVALID_ARGS){
52-
sender.sendMessage(new TextComponent(this.plugin.getSuperUtils().color(Base.INVALID_ARGUMENTS.toString())));
48+
sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.INVALID_ARGUMENTS.toString())));
5349
}
5450
}
5551

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package xyz.theprogramsrc.supercoreapi.bungee.events;
22

33
import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
4-
import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin;
54

65
/**
76
* This manages the customized events
87
*/
98
public class BungeeEventManager extends BungeeModule {
109

11-
public BungeeEventManager(BungeePlugin plugin) {
12-
super(plugin);
13-
}
14-
1510
}

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/storage/Settings.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package xyz.theprogramsrc.supercoreapi.bungee.storage;
22

33
import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
4-
import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin;
54
import xyz.theprogramsrc.supercoreapi.bungee.utils.storage.BungeeYMLConfig;
65

76
/**
@@ -13,10 +12,6 @@ public class Settings extends BungeeModule {
1312

1413
private String defaultPrefix;
1514

16-
public Settings(BungeePlugin plugin) {
17-
super(plugin);
18-
}
19-
2015
@Override
2116
public void onLoad() {
2217
this.config = new BungeeYMLConfig(this.getPluginFolder(), "Settings.yml");

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/BungeeConsole.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@
33
import net.md_5.bungee.api.CommandSender;
44
import net.md_5.bungee.api.plugin.Listener;
55
import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
6-
import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin;
76

87
/**
98
* Representation of a BungeeCord Console
109
*/
1110
public class BungeeConsole extends BungeeModule {
1211

13-
public BungeeConsole(BungeePlugin plugin) {
14-
super(plugin);
15-
}
16-
1712
/**
1813
* Registers the specified listeners
1914
* @param listeners The listeners to register
2015
*/
2116
public void listeners(Listener... listeners){
22-
((BungeePlugin)this.plugin).listener(listeners);
17+
this.bungeePlugin.listener(listeners);
2318
}
2419

2520
/**

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/tasks/BungeeTasks.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import net.md_5.bungee.api.scheduler.ScheduledTask;
44
import net.md_5.bungee.api.scheduler.TaskScheduler;
55
import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
6-
import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin;
76
import xyz.theprogramsrc.supercoreapi.global.objects.RecurringTask;
87

98
import java.util.concurrent.TimeUnit;
@@ -12,9 +11,8 @@ public class BungeeTasks extends BungeeModule {
1211

1312
private final TaskScheduler scheduler;
1413

15-
public BungeeTasks(BungeePlugin plugin) {
16-
super(plugin);
17-
this.scheduler = plugin.getProxy().getScheduler();
14+
public BungeeTasks() {
15+
this.scheduler = this.getProxy().getScheduler();
1816
}
1917

2018
/**
@@ -25,7 +23,7 @@ public BungeeTasks(BungeePlugin plugin) {
2523
* @return the scheduled task
2624
*/
2725
public ScheduledTask runAsync(Runnable task){
28-
return this.scheduler.runAsync(((BungeePlugin)this.plugin), task);
26+
return this.scheduler.runAsync(this.bungeePlugin, task);
2927
}
3028

3129
/**
@@ -37,7 +35,7 @@ public ScheduledTask runAsync(Runnable task){
3735
* @return the scheduled task
3836
*/
3937
public ScheduledTask runAsyncLater(Runnable task, long delay){
40-
return this.scheduler.schedule(((BungeePlugin)this.plugin), task, delay*50L, TimeUnit.MILLISECONDS);
38+
return this.scheduler.schedule(this.bungeePlugin, task, delay*50L, TimeUnit.MILLISECONDS);
4139
}
4240

4341
/**
@@ -52,7 +50,7 @@ public ScheduledTask runAsyncLater(Runnable task, long delay){
5250
* @return the scheduled task
5351
*/
5452
public RecurringTask runAsyncTimer(Runnable task, long delay, long period){
55-
ScheduledTask scheduledTask = this.scheduler.schedule(((BungeePlugin)this.plugin), task, delay*50L, period*50L, TimeUnit.MILLISECONDS);
53+
ScheduledTask scheduledTask = this.scheduler.schedule(this.bungeePlugin, task, delay*50L, period*50L, TimeUnit.MILLISECONDS);
5654
return new RecurringTask() {
5755
private boolean cancelled;
5856
@Override
Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,17 @@
11
package xyz.theprogramsrc.supercoreapi.global.utils;
22

3-
import xyz.theprogramsrc.supercoreapi.SuperPlugin;
4-
5-
import java.io.ByteArrayOutputStream;
6-
import java.io.DataOutputStream;
3+
import xyz.theprogramsrc.supercoreapi.global.utils.serverutils.BungeeServerUtils;
4+
import xyz.theprogramsrc.supercoreapi.global.utils.serverutils.SpigotServerUtils;
75

86
public class ServerUtils {
9-
10-
protected SuperPlugin<?> plugin;
11-
12-
public ServerUtils(SuperPlugin<?> plugin){
13-
this.plugin = plugin;
14-
}
15-
16-
/**
17-
* Send a player to another server
18-
* @param player the player
19-
* @param server the server
20-
*/
21-
public void sendToServer(Object player, String server){
22-
boolean canBungee = false;
23-
try{
24-
Class.forName("net.md_5.bungee.api.connection.ProxiedPlayer");
25-
canBungee = true;
26-
}catch (ClassNotFoundException ignored){ }
27-
28-
if(canBungee){
29-
if(player instanceof net.md_5.bungee.api.connection.ProxiedPlayer){
30-
this.sendToServerBungee(((net.md_5.bungee.api.connection.ProxiedPlayer)player), server);
31-
}else{
32-
this.sendToServerBukkit(((org.bukkit.entity.Player)player), server);
33-
}
34-
}else{
35-
if(player instanceof org.bukkit.entity.Player){
36-
this.sendToServerBukkit(((org.bukkit.entity.Player)player), server);
37-
}else{
38-
throw new IllegalArgumentException("The argument 'player' must be org.bukkit.entity.Player or net.md_5.bungee.api.connection.ProxiedPlayer");
39-
}
40-
}
7+
8+
public SpigotServerUtils spigot(){
9+
return new SpigotServerUtils();
4110
}
4211

43-
private void sendToServerBukkit(org.bukkit.entity.Player player, String server){
44-
if(!((org.bukkit.plugin.java.JavaPlugin)this.plugin.getPlugin()).getServer().getMessenger().isOutgoingChannelRegistered(((org.bukkit.plugin.java.JavaPlugin)this.plugin.getPlugin()), "BungeeCord")){
45-
((org.bukkit.plugin.java.JavaPlugin)this.plugin.getPlugin()).getServer().getMessenger().registerOutgoingPluginChannel(((org.bukkit.plugin.java.JavaPlugin)this.plugin.getPlugin()), "BungeeCord");
46-
}
47-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
48-
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
49-
50-
try{
51-
dataOutputStream.writeUTF("Connect");
52-
dataOutputStream.writeUTF(server);
53-
}catch (Exception ex){
54-
ex.printStackTrace();
55-
}
56-
57-
player.sendPluginMessage(((org.bukkit.plugin.java.JavaPlugin)this.plugin.getPlugin()), "BungeeCord", byteArrayOutputStream.toByteArray());
58-
}
59-
60-
private void sendToServerBungee(net.md_5.bungee.api.connection.ProxiedPlayer player, String server){
61-
((net.md_5.bungee.api.plugin.Plugin)this.plugin).getProxy().registerChannel("BungeeCord");
62-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
63-
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
64-
65-
try{
66-
dataOutputStream.writeUTF("Connect");
67-
dataOutputStream.writeUTF(server);
68-
}catch (Exception ex){
69-
ex.printStackTrace();
70-
}
71-
player.sendData("BungeeCord", byteArrayOutputStream.toByteArray());
12+
public BungeeServerUtils bungee(){
13+
return new BungeeServerUtils();
7214
}
7315

74-
7516
}
7617

0 commit comments

Comments
 (0)