Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Develop #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.idea/

# CMake
cmake-build-*/

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Gradle ###
.gradle
gradle/
build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Gradle Patch ###
**/build/

# End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<br>
<p>
<a href="https://discord.gg/9vedhPD"><img src="https://discordapp.com/api/guilds/623254930848874511/embed.png" alt="Discord server" ></a>
<a href="/../../"><img src="https://img.shields.io/github/last-commit/onRuntime/berrygames-bungee-plugin" alt="GitHub last-commit" /></a>
<a href="/../../"><img src="https://img.shields.io/github/last-commit/onRuntime/berrygames-gooseberry" alt="GitHub last-commit" /></a>
<a href="https://www.patreon.com/onruntime"><img src="https://img.shields.io/badge/donate-patreon-F96854" alt="Patreon" /></a>
</p>
</div>
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
group 'net.berrygames'
version '0.0.1'

dependencies {
compile project(':CloudBerry')
}
48 changes: 48 additions & 0 deletions src/main/java/net/berrygames/bungee/GooseBerry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.berrygames.bungee;

import net.berrygames.bungee.listener.PlayerConnect;
import net.berrygames.bungee.listener.ProxyPing;
import net.berrygames.cloudberry.proxy.BerryProxy;
import net.berrygames.translation.ITranslatable;
import net.berrygames.translation.Translatable;
import net.md_5.bungee.api.ProxyServer;

public class GooseBerry extends BerryProxy {

// - General Managers
private RedisService redisService;
private ITranslatable translatable;

@Override
public void onLoad() {
super.onLoad();
}

@Override
public void onEnable() {
super.onEnable();

// - Initialize General managers
this.redisService = new RedisServiceImpl("127.0.0.1", 6379, "Sunntitane2", 0);
this.translatable = new Translatable();

// - Register listeners
ProxyServer.getInstance().getPluginManager().registerListener(this, new PlayerConnect());
ProxyServer.getInstance().getPluginManager().registerListener(this, new ProxyPing());
}

@Override
public void onDisable() {
super.onDisable();
}

@Override
public RedisService getRedis() {
return redisService;
}

@Override
public ITranslatable getTranslatable() {
return translatable;
}
}
30 changes: 30 additions & 0 deletions src/main/java/net/berrygames/bungee/listener/PlayerConnect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.berrygames.bungee.listener;

import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

public class PlayerConnect implements Listener {

@EventHandler
public void onConnect(ServerConnectEvent event) {
final var player = event.getPlayer();
if(player.getServer() != null) return;

// - Detect player client version and disconnect him if it's lower than 47 (v1.9).
if(player.getPendingConnection().getVersion() <= 47) {
event.setCancelled(true);
player.disconnect(new TextComponent("player.disconnect.badVersion"));
return;
}

// - Send player to Hub.
//event.setTarget(null);
//redis.sendPlayer(player.getName(), ServerType.HUB);

// - Set tab header for player.
player.setTabHeader(new TextComponent(""), new TextComponent(("")));
// TODO: Until 30 seconds, disconnect player with no server message.
}
}
44 changes: 44 additions & 0 deletions src/main/java/net/berrygames/bungee/listener/ProxyPing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.berrygames.bungee.listener;

import net.berrygames.bungee.utilities.CenteredMessage;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

public class ProxyPing implements Listener {

@EventHandler
public void onPing(ProxyPingEvent event){
ServerPing serverPing;
int maxSlot = 500;
int online = getOnlinePlayers();
// String line1 = "&2&l▪&a&l▪&e&l▪ &a&lBerryGames &7Game Server &2[1.9 »&2 1.13] &e&l▪&a&l▪&2&l▪";
//String line1 = "&5&lBerry&d&lGames &f❙ &b&lMINI GAMES &f❙ &91.9 ➟ 1.12.2";
//String line2 = "&a☆ &6The server is currently under development &a☆ ";
//String line2 = "&b☆ &aThe server is currently in development &b☆ ";
String line1 = "§6§lBerryGames &f❙ §a1.9 §8➟ §a1.12.2";
String line2 = "§b§lTwitter §f» §9@BerryGamesMC";

if (event.getConnection().getVersion() <= 47) {
serverPing = new ServerPing(
new ServerPing.Protocol("§4Use 1.9 ➟ 1.12.2 §f- §7" + online + "§8/§7" + maxSlot, 48),
new ServerPing.Players(maxSlot, online, null),
CenteredMessage.getCenteredMotd(line1) + "\n" + CenteredMessage.getCenteredMotd("§cUse 1.9 ➟ 1.12.2"),
ProxyServer.getInstance().getConfig().getFaviconObject());
} else {
serverPing = new ServerPing(
new ServerPing.Protocol("§7" + online + "§8/§7" + maxSlot, event.getConnection().getVersion()),
new ServerPing.Players(maxSlot, online, null),
CenteredMessage.getCenteredMotd(line1) + "\n" + CenteredMessage.getCenteredMotd(line2),
ProxyServer.getInstance().getConfig().getFaviconObject()
);
}
event.setResponse(serverPing);
}

private int getOnlinePlayers(){
return 0;
}
}
21 changes: 21 additions & 0 deletions src/main/java/net/berrygames/bungee/task/PingTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.berrygames.bungee.task;

import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;

/**
* This file is a part of BerryGames, located on net.berrygames.bungee.task
*
* @author SweetKebab_
* Created the 10/12/19 at 9:02 PM.
*/
public class PingTask implements Runnable {
@Override
public void run() {
ProxyServer.getInstance().getServers().forEach((ip, sese) -> sese.ping((result, error) -> {
if(result.getDescriptionComponent() == null)
ProxyServer.getInstance().getServers().remove(sese.getName());
}));
}
}
87 changes: 87 additions & 0 deletions src/main/java/net/berrygames/bungee/utilities/CenteredMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package net.berrygames.bungee.utilities;

import net.md_5.bungee.api.ChatColor;

public class CenteredMessage {
private final static int CENTER_PX_MSG = 154;
private final static int CENTER_PX_MOTD = 128;

public static String getCenteredMessage(String message){
if(message == null || message.equals("")) return "";

message = ChatColor.translateAlternateColorCodes('&', message);

int messagePxSize = 0;
boolean previousCode = false;
boolean isBold = false;

for(char c : message.toCharArray()){
if(c == '§'){
previousCode = true;
continue;
}else if(previousCode == true){
previousCode = false;
if(c == 'l' || c == 'L'){
isBold = true;
continue;
}else isBold = false;
}else{
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
messagePxSize++;
}
}

int halvedMessageSize = messagePxSize / 2;
int toCompensate = CENTER_PX_MSG - halvedMessageSize;
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
int compensated = 0;
StringBuilder sb = new StringBuilder();
while(compensated < toCompensate){
sb.append(" ");
compensated += spaceLength;
}

return sb.toString() + message;
}

public static String getCenteredMotd(String message){
if(message == null || message.equals("")) return "";

message = ChatColor.translateAlternateColorCodes('&', message);

int messagePxSize = 0;
boolean previousCode = false;
boolean isBold = false;

for(char c : message.toCharArray()){
if(c == '§'){
previousCode = true;
continue;
}else if(previousCode == true){
previousCode = false;
if(c == 'l' || c == 'L'){
isBold = true;
continue;
}else isBold = false;
}else{
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
messagePxSize++;
}
}

int halvedMessageSize = messagePxSize / 2;
int toCompensate = CENTER_PX_MOTD - halvedMessageSize;
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
int compensated = 0;
StringBuilder sb = new StringBuilder();
while(compensated < toCompensate){
sb.append(" ");
compensated += spaceLength;
}

return sb.toString() + message;
}

}
Loading