Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Modularización del plugin
Browse files Browse the repository at this point in the history
para hacerlo compatible con diversas plataformas
  • Loading branch information
Cadiducho committed Mar 2, 2021
1 parent 580eac7 commit 399033b
Show file tree
Hide file tree
Showing 36 changed files with 597 additions and 679 deletions.
18 changes: 8 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#Antiguo stuff de NB
/nbproject/private/
nbproject/
/build/
/dist/
.gradle
.idea
*.iml

#Maven
/target/
target/
\.idea/
/build/
/bukkit/build
/common/build
/sponge/build
/bungee/build

*.iml
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
subprojects {
apply plugin: 'java'

group = 'com.cadiducho'
version = '3.0'
description = '40ServidoresMC'
java.sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenCentral()
}
}
29 changes: 29 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id 'java'
id "com.github.johnrengelman.shadow" version "6.1.0"
id "io.freefair.lombok" version "5.3.0"
}

repositories {
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
}

dependencies {
implementation project(':common')
implementation 'org.bstats:bstats-bukkit:2.2.1'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.10.9'
}

shadowJar {
archiveBaseName.set(rootProject.name)
archiveClassifier.set('Bukkit')
archiveVersion.set(version)

relocate 'org.bstats', 'com.cadiducho.cservidoresmc.lib.bstats'
}

artifacts {
archives shadowJar
}
2 changes: 2 additions & 0 deletions bukkit/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.cadiducho.cservidoresmc.bukkit;

import com.cadiducho.cservidoresmc.bukkit.util.MetricsLite;
import com.cadiducho.cservidoresmc.ApiClient;
import com.cadiducho.cservidoresmc.bukkit.util.Updater;
import com.cadiducho.cservidoresmc.bukkit.util.Util;
import com.google.gson.Gson;
import lombok.Getter;
import org.bstats.bukkit.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -18,9 +20,9 @@
* @author Cadiducho
*/
public class BukkitPlugin extends JavaPlugin {
private final Util met = new Util(this);
private Updater updater;

@Getter private ApiClient apiClient;
@Getter private Updater updater;

private final String tag = "&8[&b40ServidoresMC&8]";
private int configVer = 0;
Expand All @@ -38,7 +40,9 @@ public static BukkitPlugin get() {
public void onEnable() {
instance = this;
debugLog("Modo Debug activado en el plugin");


apiClient = new ApiClient(new Gson());

/*
* Generar y cargar Config.yml
*/
Expand All @@ -53,7 +57,7 @@ public void onEnable() {

installPlaceholderAPI();

MetricsLite metrics = new MetricsLite(instance);
Metrics metrics = new Metrics(instance, 3909);
/*
* Finalizar...
*/
Expand Down Expand Up @@ -142,19 +146,8 @@ public void sendMessage(String str, CommandSender sender) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', tag + " " + str));
}

public Util getMetodos() {
return this.met;
}

public String getPluginVersion(){
return this.getDescription().getVersion();
}

public String getTag() {
return this.tag;
}

public Updater getUpdater() {
return this.updater;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

public class PlaceholderHook extends PlaceholderExpansion {

Expand All @@ -18,17 +17,17 @@ public boolean canRegister() {
}

@Override
public @NotNull String getAuthor() {
public String getAuthor() {
return "Cadiducho";
}

@Override
public @NotNull String getIdentifier() {
public String getIdentifier() {
return "40servidoresmc";
}

@Override
public @NotNull String getVersion() {
public String getVersion() {
return "1.0.0";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.cadiducho.cservidoresmc.bukkit.cmd;

import com.cadiducho.cservidoresmc.bukkit.BukkitPlugin;
import com.cadiducho.cservidoresmc.bukkit.util.Util;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
Expand All @@ -20,7 +19,6 @@ public abstract class CommandBase {
private final transient String perm;
private final transient List<String> aliases;
protected static final transient BukkitPlugin plugin = BukkitPlugin.get();
protected static final transient Util metodos = BukkitPlugin.get().getMetodos();

protected CommandBase(final String name, final String perm, final List<String> aliases) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.cadiducho.cservidoresmc.bukkit.cmd;

import com.cadiducho.cservidoresmc.model.ServerStats;
import com.cadiducho.cservidoresmc.model.ServerVote;
import org.bukkit.command.CommandSender;

import java.util.Collections;
import java.util.logging.Level;

/**
* Comando para obtener las estadísticas de tu servidor en 40ServidoresMC
* @author Cadiducho
*/
public class StatsCMD extends CommandBase {

public StatsCMD() {
super("stats40", "40servidores.stats", Collections.emptyList());
}

@Override
public void run(CommandSender sender, String label, String[] args) {
if (!perm(sender, getPermission(), true)) return;

plugin.getApiClient().fetchServerStats().thenAccept((ServerStats serverStats) -> {
if (serverStats.getServerName() == null) { //clave mal configurada
plugin.sendMessage("&cClave incorrecta. Entra en &bhttps://40servidoresmc.es/miservidor.php &cy cambia esta.", sender);
return;
}

plugin.sendMessage("&9==> &7" + serverStats.getServerName() + " &festá en el TOP &a" + serverStats.getPosition(), sender);
plugin.sendMessage("&bVotos hoy: &6" + serverStats.getDayVotes(), sender);
plugin.sendMessage("&bVotos premiados hoy: &6" + serverStats.getRewardedDayVotes(), sender);
plugin.sendMessage("&bVotos semanales: &6" + serverStats.getWeekVotes(), sender);
plugin.sendMessage("&bVotos premiados semanales: &6" + serverStats.getRewardedWeekVotes(), sender);

if (serverStats.getLastVotes() != null) {
StringBuilder usuarios = new StringBuilder();
for (ServerVote vote : serverStats.getLastVotes()) {
String strellita = vote.isRewarded() ? "&a" : "&c";
usuarios.append(strellita).append(vote.getName()).append("&6, ");
}
usuarios = new StringBuilder(usuarios.substring(0, usuarios.length() - 2) + ".");
plugin.sendMessage("&bÚltimos 20 votos: " + usuarios, sender);
}
}).exceptionally(ex -> {
plugin.sendMessage("&cHa ocurrido una excepción. Revisa la consola o avisa a un administrador", sender);
plugin.log(Level.SEVERE, "Excepción obteniendo estadisticas: " + ex.getMessage());
return null;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.cadiducho.cservidoresmc.bukkit.cmd;

import com.cadiducho.cservidoresmc.bukkit.util.ApiResponse;
import com.cadiducho.cservidoresmc.bukkit.util.Cooldown;
import com.cadiducho.cservidoresmc.bukkit.util.Util;
import com.cadiducho.cservidoresmc.Cooldown;
import com.cadiducho.cservidoresmc.model.VoteResponse;
import com.cadiducho.cservidoresmc.model.VoteStatus;
import com.google.gson.Gson;
import org.bukkit.command.CommandSender;
import org.json.simple.JSONObject;

import java.util.Arrays;
import java.util.logging.Level;
Expand All @@ -31,50 +31,50 @@ public void run(CommandSender sender, String label, String[] args) {
return;
}

if (cooldown.isCoolingDown(sender)) {
if (cooldown.isCoolingDown(sender.getName())) {
plugin.sendMessage("&6No puedes ejecutar este comando tantas veces seguidas!", sender);
return;
}

cooldown.setOnCooldown(sender);
cooldown.setOnCooldown(sender.getName());

plugin.sendMessage("&7Obteniendo voto...", sender);
Util.readUrl("https://40servidoresmc.es/api2.php?nombre=" + sender.getName() + "&clave=" + plugin.getConfig().getString("clave"), (ApiResponse response) -> {
if (response.getException().isPresent()) {
plugin.sendMessage("&cHa ocurrido una excepción. Avisa a un administrador", sender);
plugin.log(Level.SEVERE, "Excepción intentando votar: " + response.getException().get());
return;
}
plugin.getApiClient().validateVote(sender.getName()).thenAccept((VoteResponse voteResponse) -> {
System.out.println(new Gson().toJson(voteResponse));
String web = voteResponse.getWeb();
VoteStatus status = voteResponse.getStatus();

JSONObject jsonData = response.getResult();
String web = (String) jsonData.get("web");
int status = (int) ((long) jsonData.get("status"));

switch (status) {
case 0:
case NOT_VOTED:
plugin.sendMessage("&6No has votado hoy! Puedes hacerlo en &a" + web, sender);
break;
case 1:
case SUCCESS:
plugin.sendMessage(plugin.getConfig().getString("mensaje"), sender);
plugin.listaComandos.stream()
.map(cmds -> cmds.replace("{0}", sender.getName()))
.forEach(comando -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), comando));
plugin.getServer().getScheduler().runTask(plugin, () -> {
plugin.listaComandos.stream()
.map(cmds -> cmds.replace("{0}", sender.getName()))
.forEach(comando -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), comando));

if (plugin.getConfig().getBoolean("broadcast.activado")) {
plugin.getServer().getOnlinePlayers()
.forEach(p -> plugin.sendMessage(plugin.getConfig().getString("broadcast.mensajeBroadcast").replace("{0}", sender.getName()), p));
}
if (plugin.getConfig().getBoolean("broadcast.activado")) {
plugin.getServer().getOnlinePlayers()
.forEach(p -> plugin.sendMessage(plugin.getConfig().getString("broadcast.mensajeBroadcast").replace("{0}", sender.getName()), p));
}
});
break;
case 2:
case ALREADY_VOTED:
plugin.sendMessage("&aGracias por votar, pero ya has obtenido tu premio!", sender);
break;
case 3:
case INVALID_kEY:
plugin.sendMessage("&cClave incorrecta. Entra en &bhttps://40servidoresmc.es/miservidor.php &cy cambia esta.", sender);
break;
default:
plugin.sendMessage("&7Ha ocurrido un error. Prueba más tarde o avisa a un adminsitrador", sender);
break;
}
}).exceptionally(e -> {
plugin.sendMessage("&cHa ocurrido una excepción. Avisa a un administrador", sender);
plugin.log(Level.SEVERE, "Excepción intentando votar: " + e.getMessage());
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.cadiducho.cservidoresmc.bukkit.BukkitPlugin;
import org.bukkit.command.CommandSender;
import org.json.simple.JSONObject;

import java.util.Optional;

/**
Expand Down Expand Up @@ -36,7 +34,8 @@ public Updater(BukkitPlugin instance, String vInstalada, String vMinecraft) {
public void checkearVersion(CommandSender send, boolean boot) {
plugin.debugLog("Buscando nueva versión...");
Optional<CommandSender> sender = Optional.ofNullable(send);
Util.readUrl(readurl, (ApiResponse response) -> {
// ToDo: fixme
/*Util.readUrl(readurl, (ApiResponse response) -> {
if (response.getException().isPresent()) {
plugin.log(ERROR);
sender.ifPresent(s -> plugin.sendMessage(ERROR, s));
Expand Down Expand Up @@ -67,7 +66,7 @@ public void checkearVersion(CommandSender send, boolean boot) {
sender.ifPresent(s -> plugin.sendMessage(NOVERSION, s));
}
}
});
});*/
}

}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/plugin.yml → bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 40ServidoresMC
main: com.cadiducho.cservidoresmc.bukkit.BukkitPlugin
version: 2.6
version: 3.0
author: Cadiducho
api-version: 1.13
description: Enlace para servidores de la web 40ServidoresMC!
Expand Down
7 changes: 7 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id "io.freefair.lombok" version "5.3.0"
}

dependencies {
compileOnly 'com.google.code.gson:gson:2.8.6'
}
2 changes: 2 additions & 0 deletions common/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
Loading

0 comments on commit 399033b

Please sign in to comment.