Skip to content

Commit

Permalink
New Language System, so I don't have to manually add them.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Oct 9, 2024
1 parent 3766fb9 commit f98b1d6
Show file tree
Hide file tree
Showing 17 changed files with 858 additions and 1,166 deletions.
5 changes: 2 additions & 3 deletions src/main/java/de/presti/trollv4/api/PlayMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;

import de.presti.trollv4.logging.Logger;
import de.presti.trollv4.main.Main;
import org.bukkit.entity.Player;

import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
Expand Down Expand Up @@ -34,15 +33,15 @@ public static void play(Player p, String PATH) {
} else {
if (!new File("plugins/TrollV4/rick.nbs").exists()) {
Logger.info("Downloading Rick.nbs!");
Main.download("https://cdn.azura.best/download/trollv4/uni/rick.nbs", "plugins/TrollV4/rick.nbs");
RequestUtility.download("https://cdn.azura.best/download/trollv4/uni/rick.nbs", "plugins/TrollV4/rick.nbs");
if (new File("plugins/TrollV4/rick.nbs").exists()) {
Logger.info("Downloaded Rick.nbs!");
} else {
Logger.info("Couldnt download Rick.nbs!");
}
} else if (!new File("plugins/TrollV4/giorno.nbs").exists()) {
Logger.info("Downloading Giorno.nbs!");
Main.download("https://cdn.azura.best/download/trollv4/uni/giorno.nbs", "plugins/TrollV4/giorno.nbs");
RequestUtility.download("https://cdn.azura.best/download/trollv4/uni/giorno.nbs", "plugins/TrollV4/giorno.nbs");
if (new File("plugins/TrollV4/giorno.nbs").exists()) {
Logger.info("Downloaded Giorno.nbs!");
} else {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/de/presti/trollv4/api/RequestUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

public class RequestUtility {

Expand Down Expand Up @@ -58,4 +60,44 @@ public static byte[] getBytes(String url) {

return new byte[0];
}

public static boolean download(String url, String fileName) {
if (url == null || fileName == null) {
return false;
}

if (url.toLowerCase().startsWith("https://github.com")) {
return downloadGithub(url, fileName);
} else {
return downloadDirect(url, fileName);
}
}

public static boolean downloadGithub(String url, String fileName) {
String cleaned = url.replaceAll("https://github.com/", "")
.replace("releases/tag/", "releases/tags/");

JsonObject jsonObject = RequestUtility.getJSON("https://api.github.com/repos/" + cleaned).getAsJsonObject();
if (jsonObject.has("assets")) {
JsonArray assets = jsonObject.getAsJsonArray("assets");
for (JsonElement jsonElement : assets) {
JsonObject jsonObject1 = jsonElement.getAsJsonObject();

if (jsonObject1.has("name") && jsonObject1.get("name").getAsString().endsWith(".jar")) {
return downloadDirect(assets.get(0).getAsJsonObject().get("browser_download_url").getAsString(), fileName);
}
}
}

return false;
}

public static boolean downloadDirect(String url, String fileName) {
try {
Files.write(Paths.get(fileName), RequestUtility.getBytes(url));
return true;
} catch (Exception e) {
return false;
}
}
}
54 changes: 27 additions & 27 deletions src/main/java/de/presti/trollv4/api/TrollV4API.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.github.juliarn.npclib.api.Position;
import com.github.juliarn.npclib.bukkit.util.BukkitPlatformUtil;
import de.presti.trollv4.config.Config;
import de.presti.trollv4.config.Language;
import de.presti.trollv4.config.language.LanguageService;
import de.presti.trollv4.logging.Logger;
import de.presti.trollv4.main.Main;
import de.presti.trollv4.utils.crossversion.HS;
Expand Down Expand Up @@ -187,7 +187,7 @@ public void run() {
}
}, 0, 20);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -203,7 +203,7 @@ public static void Explode(Player victim) {
victim.getWorld().createExplosion(victim.getLocation(), 3.0F);
victim.setHealth(0.0D);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -225,7 +225,7 @@ public static void FakeHack(Player victim) {

}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -239,7 +239,7 @@ public static void Strike(Player victim) {
if (victim != null) {
victim.getLocation().getWorld().strikeLightning(victim.getLocation());
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -257,7 +257,7 @@ public static void Rocket(Player victim) {
victim.playSound(victim.getLocation(), XSound.ENTITY_ENDER_DRAGON_GROWL.parseSound(), 100.0F, 25.0F);
victim.setAllowFlight(false);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -273,7 +273,7 @@ public static void Spam(Player victim) {
victim.sendMessage("§cDont Cheat!");
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -285,9 +285,9 @@ public static void Spam(Player victim) {
*/
public static void FakeOP(Player victim) {
if (victim != null) {
victim.sendMessage(Language.getMessage("gui.fakeop.opm", victim));
victim.sendMessage(LanguageService.getDefault("gui.fakeop.opm", victim));
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -299,9 +299,9 @@ public static void FakeOP(Player victim) {
*/
public static void Crash(Player victim) {
if (victim != null) {
victim.kickPlayer(Language.getMessage("gui.crash.message"));
victim.kickPlayer(LanguageService.getDefault("gui.crash.message"));
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -324,7 +324,7 @@ public static void Freeze(Player victim) {
ArrayUtils.freeze.add(victim);
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -337,11 +337,11 @@ public static void Freeze(Player victim) {
*/
public static void AntiCheat(Player victim) {
if (victim != null) {
victim.sendMessage(Language.getMessage("gui.anticheat.detected"));
victim.sendMessage(LanguageService.getDefault("gui.anticheat.detected"));
victim.teleport(new Location(victim.getWorld(), victim.getLocation().getX(),
victim.getLocation().getY() + 2, victim.getLocation().getZ()));
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -360,7 +360,7 @@ public static void Lagging(Player victim) {
ArrayUtils.lagging.remove(victim);
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ public static void Arrest(Player victim) {
.setType(XMaterial.BEDROCK.parseMaterial());

} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -423,7 +423,7 @@ public static void Rotate(Player victim) {
ArrayUtils.rotateplayer.add(victim);
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -443,7 +443,7 @@ public static void RandomTP(Player victim) {
ArrayUtils.randomtp.add(victim);
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -463,7 +463,7 @@ public static void TnTTrace(Player victim) {
ArrayUtils.tntp.add(victim);
}
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand Down Expand Up @@ -654,7 +654,7 @@ public void run() {
});
ArrayUtils.wtf.get(victim).runTaskTimer(Main.getInstance(), 0L, 20L);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand Down Expand Up @@ -789,7 +789,7 @@ public static void WebTrap(Player victim) {
.setType(XMaterial.COBWEB.parseMaterial());

} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
}

Expand All @@ -816,7 +816,7 @@ public static void MLG(Player victim, String mlg) {
Titles.send(victim, 1, 10, 1, "§2MAKE A §cMLG", "");
victim.setAllowFlight(false);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
} else if (mlg.equalsIgnoreCase("lava")) {
if (victim != null) {
Expand All @@ -832,7 +832,7 @@ public static void MLG(Player victim, String mlg) {
Titles.send(victim, 1, 10, 1, "§2MAKE A §cMLG", "");
victim.setAllowFlight(false);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
} else if (mlg.equalsIgnoreCase("cobweb")) {
if (victim != null) {
Expand All @@ -848,7 +848,7 @@ public static void MLG(Player victim, String mlg) {
Titles.send(victim, 1, 10, 1, "§2MAKE A §cMLG", "");
victim.setAllowFlight(false);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
} else if (mlg.equalsIgnoreCase("water")) {
if (victim != null) {
Expand All @@ -864,7 +864,7 @@ public static void MLG(Player victim, String mlg) {
Titles.send(victim, 1, 10, 1, "§2MAKE A §cMLG", "");
victim.setAllowFlight(false);
} else {
Main.getInstance().getLogger().info(Language.getMessage("noonline"));
Main.getInstance().getLogger().info(LanguageService.getDefault("noonline"));
}
} else {
Main.getInstance().getLogger().info(mlg + " does not exist!");
Expand Down Expand Up @@ -976,7 +976,7 @@ public static void SpookyWorld(Player victim) {

@Override
public void run() {
String spookyWorldName = Config.getconfig().getString("trolls.spookyWorld.name");
String spookyWorldName = Config.getConfig().getString("trolls.spookyWorld.name");
if (Bukkit.getWorld(spookyWorldName) != null) {
victim.teleport(Bukkit.getWorld(spookyWorldName).getSpawnLocation());

Expand Down Expand Up @@ -1020,7 +1020,7 @@ public void run() {
victim.addPotionEffect(XPotion.BLINDNESS.buildPotionEffect(1000000, 3));
victim.addPotionEffect(XPotion.SLOWNESS.buildPotionEffect(1000000, 3));
} else {
Logger.info(Language.getMessage("gui.spooky.world"));
Logger.info(LanguageService.getDefault("gui.spooky.world"));
}
}
}.runTaskLater(Main.getInstance(), 40L);
Expand Down
Loading

0 comments on commit f98b1d6

Please sign in to comment.