-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for BungeeCord plugins
Took 1 hour 0 minutes
- Loading branch information
Showing
8 changed files
with
261 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cc.synkdev.synkLibs.bungee; | ||
|
||
import net.md_5.bungee.config.Configuration; | ||
import net.md_5.bungee.config.ConfigurationProvider; | ||
import net.md_5.bungee.config.YamlConfiguration; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
|
||
public class LangBungee { | ||
public File file; | ||
SynkLibsBungee core = SynkLibsBungee.getInstance(); | ||
public LangBungee(File dataFolder) { | ||
file = new File(dataFolder.getParent(), "SynkLibs"); | ||
init(); | ||
} | ||
|
||
public Configuration config; | ||
|
||
public void init() { | ||
if (!file.exists()) { | ||
file.mkdirs(); | ||
} | ||
file = new File(file, "lang.yml"); | ||
if (!file.exists()) { | ||
try { | ||
file.createNewFile(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
try { | ||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); | ||
load(); | ||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void load() { | ||
File tempFile = new File(file.getParent(), "temp-"+System.currentTimeMillis()+".yml"); | ||
try { | ||
URL url = new URL("https://synkdev.cc/storage/lang-libs-bungee.php"); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); | ||
|
||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
for (String s : line.split("<br>")) { | ||
String id = s.split(":")[0]; | ||
if (config.contains(id)) { | ||
writer.write(id + ": " + config.getString(id)); | ||
writer.newLine(); | ||
} else { | ||
writer.write(s); | ||
writer.newLine(); | ||
} | ||
} | ||
} | ||
reader.close(); | ||
writer.close(); | ||
tempFile.renameTo(file); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public String translate(String s) { | ||
return removeEnds(config.getString(s)); | ||
} | ||
|
||
public String translate(String s, String s1) { | ||
return translate(s).replace("%s1%", s1); | ||
} | ||
|
||
public String translate(String s, String s1, String s2) { | ||
return translate(s, s1).replace("%s2%", s2); | ||
} | ||
|
||
public String translate(String s, String s1, String s2, String s3) { | ||
return translate(s, s1, s2).replace("%s3%", s3); | ||
} | ||
|
||
public String removeEnds(String s) { | ||
return s.split("\"")[0]; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/cc/synkdev/synkLibs/bungee/SynkLibsBungee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cc.synkdev.synkLibs.bungee; | ||
|
||
import cc.synkdev.synkLibs.components.SynkPlugin; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.md_5.bungee.api.ChatColor; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import org.bstats.bungeecord.Metrics; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SynkLibsBungee extends Plugin implements SynkPlugin { | ||
@Getter private static SynkLibsBungee instance; | ||
@Getter String prefix = ChatColor.translateAlternateColorCodes('&', "&8[&6SynkLibs&8] » &r"); | ||
@Setter @Getter static SynkPlugin spl = null; | ||
static public Map<SynkPlugin, String> availableUpdates = new HashMap<>(); | ||
|
||
@Override | ||
public void onEnable() { | ||
instance = this; | ||
setSpl(this); | ||
new Metrics(this, 23042); | ||
getProxy().getPluginManager().registerListener(this, new UtilsBungee(this)); | ||
UtilsBungee.checkUpdate(this, this); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
|
||
} | ||
|
||
@Override | ||
public String name() { | ||
return "SynkLibs"; | ||
} | ||
|
||
@Override | ||
public String ver() { | ||
return "1.3"; | ||
} | ||
|
||
@Override | ||
public String dlLink() { | ||
return "https://modrinth.com/plugin/synklibs"; | ||
} | ||
|
||
@Override | ||
public String prefix() { | ||
return getPrefix(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cc.synkdev.synkLibs.bungee; | ||
|
||
import cc.synkdev.synkLibs.Lang; | ||
import cc.synkdev.synkLibs.components.SynkPlugin; | ||
import net.md_5.bungee.api.ChatColor; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.event.PostLoginEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.event.EventHandler; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
|
||
public class UtilsBungee implements Listener { | ||
private SynkLibsBungee bcore = SynkLibsBungee.getInstance(); | ||
private static SynkLibsBungee score = SynkLibsBungee.getInstance(); | ||
SynkPlugin spl; | ||
static LangBungee slang; | ||
public UtilsBungee(SynkPlugin spl) { | ||
this.spl = spl; | ||
} | ||
Lang lang; | ||
public static void log(String s) { | ||
score.getProxy().getConsole().sendMessage(score.getSpl().prefix()+" "+s); | ||
} | ||
|
||
public static void checkUpdate(SynkPlugin spl, Plugin plugin) { | ||
checkUpdate(spl, plugin.getDataFolder()); | ||
} | ||
|
||
private static void checkUpdate(SynkPlugin spl, File dataFolder) { | ||
slang = new LangBungee(dataFolder); | ||
try { | ||
URL url = new URL("https://synkdev.cc/ver/"+spl.name()); | ||
BufferedReader in = new BufferedReader( | ||
new InputStreamReader(url.openStream())); | ||
|
||
String inputLine; | ||
while ((inputLine = in.readLine()) != null) { | ||
if (inputLine.equals(spl.ver())) { | ||
log(ChatColor.GREEN + spl.name() + " " + slang.translate("upToDate")); | ||
} else { | ||
log(ChatColor.GREEN + slang.translate("updateAvailable") + " " + spl.name() + ": v" + inputLine); | ||
log(ChatColor.GREEN + slang.translate("downloadHere") + ": "+spl.dlLink()); | ||
if (SynkLibsBungee.availableUpdates.containsKey(spl)) SynkLibsBungee.availableUpdates.replace(spl, inputLine); | ||
else SynkLibsBungee.availableUpdates.put(spl, inputLine); | ||
} | ||
break; | ||
} | ||
in.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
@EventHandler | ||
public void joinBungee (PostLoginEvent event) { | ||
lang = new Lang(bcore.getDataFolder()); | ||
if (event.getPlayer().hasPermission("synklibs.bungee.updatenotifier")) bcore.availableUpdates.forEach((s, s2) -> { | ||
ProxiedPlayer p = event.getPlayer(); | ||
p.sendMessage(lang.translate("updateAvailable") + " "+s+"!"); | ||
p.sendMessage(lang.translate("downloadHere")+": "+s.dlLink()); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: SynkLibs | ||
version: '${project.version}' | ||
main: cc.synkdev.synkLibs.bungee.SynkLibsBungee | ||
author: Synk |