Skip to content

Commit

Permalink
Modificado sistema de update, para maior velocidade
Browse files Browse the repository at this point in the history
Adicionado sistema StackMobs ( desabilitado por padrão)
Adcionado comando novo /vip remover
  • Loading branch information
GilbertoKPL committed Dec 24, 2023
1 parent 5bf4b8f commit 407f638
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 89 deletions.
9 changes: 1 addition & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dependencies {
}

//Mysql with MariaDB driver database
compileOnly("org.mariadb.jdbc:mariadb-java-client:3.1.4") {
compileOnly("org.mariadb.jdbc:mariadb-java-client:3.3.2") {
exclude("org.slf4j", "slf4j-api")
exclude("org.slf4j", "jcl-over-slf4j")
}
Expand Down Expand Up @@ -98,18 +98,11 @@ dependencies {
exclude("org.slf4j", "jcl-over-slf4j")
}

compileOnly("commons-io:commons-io:2.15.1") {
exclude("org.slf4j", "slf4j-api")
exclude("org.slf4j", "jcl-over-slf4j")
}

compileOnly("org.json:json:20231013") {
exclude("org.slf4j", "slf4j-api")
exclude("org.slf4j", "jcl-over-slf4j")
}

compileOnly("com.google.code.gson:gson:2.10.1")

}

tasks.shadowJar {
Expand Down
124 changes: 69 additions & 55 deletions src/main/java/github/gilbertokpl/total/TotalEssentialsJava.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package github.gilbertokpl.total;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import github.gilbertokpl.core.external.CorePlugin;
import github.gilbertokpl.total.cache.internal.InternalLoader;
import github.gilbertokpl.total.cache.local.PlayerData;
Expand All @@ -14,26 +12,20 @@
import github.gilbertokpl.total.util.*;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.io.IOUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.CodeSource;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Objects;
import java.util.jar.*;

Expand All @@ -43,9 +35,6 @@ public class TotalEssentialsJava extends JavaPlugin {
public static CorePlugin basePlugin;
public static Permission permission;
public static boolean lowVersion = false;
private final List<String> dependency = Collections.singletonList(
"https://github.com/GilbertoKPL/TotalEssentials/releases/download/1.1.1/TotalEssentials-lib-1.1.1.jar"
);

public static TotalEssentialsJava getInstance() {
return instance;
Expand All @@ -63,61 +52,70 @@ public static boolean isLowVersion() {
return lowVersion;
}

public static Boolean start = false;
public static Boolean update = false;
public static Boolean libModify = false;

public static String jarPath = null;

@Override
public void onLoad() {

//lib Checker
String version;

//update

try {
version = getLatestVersion("GilbertoKPL", "TotalEssentials");

if (!Objects.equals(version, this.getDescription().getVersion())) {
System.out.println("Existe uma nova versão disponivel = " + version + " baixando...");
jarPath = "plugins/TotalEssentials-" + version +".jar";
boolean archive = downloadArchive("https://github.com/GilbertoKPL/TotalEssentials/releases/download/"+ version +"/TotalEssentials-" + version +".jar", jarPath);
if (archive) {
new File("plugins/TotalEssentials-" + this.getDescription().getVersion() +".jar").deleteOnExit();
update = true;
}
}

StringBuilder classPath = new StringBuilder();
} catch (IOException ignored) {
version = this.getDescription().getVersion();
}

for (String depend : dependency) {
String[] split = depend.split("/");
String name = split[split.length - 1];
String path = "plugins/TotalEssentials/lib/";
String newPath = path + name;
//lib Checker

File file = new File(newPath);
String classPath;

classPath.append(newPath.replace("plugins/", "")).append(" ");
String depend = "https://github.com/GilbertoKPL/TotalEssentials/releases/download/"+version+"/TotalEssentials-lib-"+version+".jar";
String[] split = depend.split("/");
String name = split[split.length - 1];
String pathLib = "plugins/TotalEssentials/lib/";
String newPath = pathLib + name;

if (!file.exists()) {
Bukkit.getServer().getConsoleSender().sendMessage("Baixando dependencia = %dependency%.".replace("%dependency%", name));
downloadArchive(depend, newPath);
}
File file = new File(newPath);

classPath = newPath.replace("plugins/", "");

if (!file.exists()) {
Bukkit.getServer().getConsoleSender().sendMessage("Baixando dependencia = %dependency%.".replace("%dependency%", name));
downloadArchive(depend, newPath);
libModify = true;
}

try {
if (!Objects.equals(getManifest(), classPath.toString().toString())) {
modifyManifest(classPath.toString().toString());
Bukkit.getServer().getConsoleSender().sendMessage("Reninciando para aplicar modificações");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart");
start = true;
if (update || !Objects.equals(getManifest(), classPath)) {
modifyManifest(classPath);
update = true;
}
} catch (IOException e) {
throw new RuntimeException(e);
}

//update

try {
String version = getLatestVersion("GilbertoKPL", "TotalEssentials");

if (!Objects.equals(version, this.getDescription().getVersion())) {
System.out.println("Existe uma nova versão disponivel = " + version + " baixando...");
boolean archive = downloadArchive("https://github.com/GilbertoKPL/TotalEssentials/releases/download/"+ version +"/TotalEssentials-" + version +".jar", "plugins/TotalEssentials-" + version +".jar");

if (archive) {
new File("plugins/TotalEssentials-" + this.getDescription().getVersion() +".jar").deleteOnExit();
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart");
start = true;
System.out.println("Reninciando para aplicar configurações!");
}
}

} catch (IOException ignored) {}
if (update || libModify) {
update = true;
Bukkit.getServer().getConsoleSender().sendMessage("Reninciando para aplicar modificações");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart");
return;
}


instance = this;
Expand All @@ -135,7 +133,7 @@ public void onLoad() {
@Override
public void onEnable() {

if (start) return;
if (update) return;

basePlugin.start(
"github.gilbertokpl.total.commands",
Expand Down Expand Up @@ -183,7 +181,7 @@ public void onEnable() {
@Override
public void onDisable() {

if (start) return;
if (update) return;

for (Player p : basePlugin.getReflection().getPlayers()) {
if (MainConfig.playtimeActivated) {
Expand Down Expand Up @@ -304,6 +302,16 @@ private static void createJarWithNewManifest(String jarFilePath, Manifest newMan
}

public static String JarPath() {

if (jarPath != null) {
File file = new File(jarPath);
try {
return file.getCanonicalPath();
} catch (Exception e) {
e.fillInStackTrace();
}
}

Class<?> currentClass = TotalEssentialsJava.class;
CodeSource codeSource = currentClass.getProtectionDomain().getCodeSource();

Expand All @@ -326,12 +334,18 @@ public static String getLatestVersion(String owner, String repo) throws IOExcept
String apiUrl = "https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest";
URL url = new URL(apiUrl);

try (InputStream inputStream = url.openConnection().getInputStream()) {
String jsonContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
try (InputStream inputStream = url.openStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
StringBuilder jsonContent = new StringBuilder();

JsonObject json = JsonParser.parseString(jsonContent).getAsJsonObject();
String line;
while ((line = reader.readLine()) != null) {
jsonContent.append(line);
}

return json.get("tag_name").getAsString();
int startIndex = jsonContent.indexOf("\"tag_name\":\"") + 12;
int endIndex = jsonContent.indexOf("\"", startIndex);
return jsonContent.substring(startIndex, endIndex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,67 @@ public class MainConfig implements DefaultConfig {
public static String databaseSqlPassword = "!essentialsk123";


//stackMobs

@PrimaryComments(
{
@PrimaryComment(primaryAnnotations = "Configurações do StackMobs", lang = LangTypes.PT_BR),
@PrimaryComment(primaryAnnotations = "", lang = LangTypes.EN_US)
}
)
@Comments(
{
@Comment(annotations = "Se estiver ativado (true), O Stackamobs será ativado.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static Boolean stackmobsActivated = false;
@Comments(
{
@Comment(annotations = "Lista de mobs que irão estocar.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static List<Integer> stackmobsStackList = Collections.singletonList(54);
@Comments(
{
@Comment(annotations = "dar replace no nome do mob.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static List<String> stackmobsNameReplacer = Collections.singletonList("54:Zumbi");

@Comments(
{
@Comment(annotations = "Raio que ira estocar.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static Integer stackmobsRadius = 10;

@Comments(
{
@Comment(annotations = "Quantidade máxima.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static Integer stackmobsMax = 200;
@Comments(
{
@Comment(annotations = "Lista de mobs que irão estocar.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static String stackmobsNameTag = "&6&l%name% %quantity%X";
@Comments(
{
@Comment(annotations = "Lista de mobs que irão estocar.", lang = LangTypes.PT_BR),
@Comment(annotations = "", lang = LangTypes.EN_US)
}
)
public static List<String> stackmobsBlockedWorlds = Collections.singletonList("Spawn");


//Commands

@PrimaryComments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class CommandVip : github.gilbertokpl.core.external.command.CommandCreator("vip"
cache.remove(args[2])

VipUtil.updateCargo(args[1])
TotalEssentialsJava.permission.playerRemoveGroup(VipUtil.world, args[1], VipData.vipGroup[args[2]])
VipData.vipQuantity[args[2]] = (VipData.vipQuantity[args[2]] ?: 0) - 1
PlayerData.discordCache[args[1]]?.let { VipData.vipDiscord[args[2]]?.let { it1 ->
Discord.removeUserRole(it,
it1
)
} }

s.sendMessage(LangConfig.VipsRemove)

return false
Expand Down
Loading

0 comments on commit 407f638

Please sign in to comment.