Skip to content

Commit

Permalink
Versão 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Clayderson Ferreira committed Mar 31, 2019
1 parent 6f67df1 commit f7593b0
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 147 deletions.
14 changes: 11 additions & 3 deletions mineshop.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../../../Java Librarys/spigot-1.7.2.jar!/" />
<root url="jar://$MODULE_DIR$/../../../../Java Librarys/spigot-1.5.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../../../Java Librarys/spigot-1.7.2.jar!/" />
<root url="jar://$MODULE_DIR$/../../../../Java Librarys/spigot-1.5.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module" module-name="msdk" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../../../Java Librarys/msdk-1.1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
47 changes: 47 additions & 0 deletions src/br/com/mineshop/plugin/spigot/Commands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package br.com.mineshop.plugin.spigot;

import br.com.mineshop.msdk.MSDK;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

public class Commands implements Listener, CommandExecutor {
private MSDK msdk;
private JavaPlugin plugin;

String cmd1 = "mineshop";

Commands(MSDK msdk, JavaPlugin plugin) {
this.msdk = msdk;
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (sender instanceof Player) {
sender.sendMessage(ChatColor.RED + "Este comando não pode ser executado fora do console do servidor");
} else if (command.getName().equalsIgnoreCase(this.cmd1)) {
if (args.length > 0) {
String token = args[0].trim().toLowerCase();

this.msdk.setCredentials(token);
this.plugin.getConfig().set("token", token);
this.plugin.saveConfig();

sender.sendMessage(String.format(
"%sPronto! Se o token informado estiver correto, este servidor irá sincronizar com sua loja em " +
"alguns instantes.",
ChatColor.GREEN
));
} else {
sender.sendMessage(String.format("%s <token>", this.cmd1));
}
}

return true;
}
}
107 changes: 107 additions & 0 deletions src/br/com/mineshop/plugin/spigot/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package br.com.mineshop.plugin.spigot;

import br.com.mineshop.msdk.exceptions.MsdkException;
import br.com.mineshop.msdk.webservice.endpoints.v1.QueueItem;
import br.com.mineshop.msdk.exceptions.WebServiceException;
import br.com.mineshop.msdk.MSDK;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class Main extends JavaPlugin {
private MSDK msdk = new MSDK();
private JavaPlugin plugin;
private Commands commands = new Commands(this.msdk, this);

@Override
public void onEnable() {
this.saveDefaultConfig();

this.plugin = this;
this.msdk.setCredentials(this.getConfig().getString("token"));
this.getCommand(this.commands.cmd1).setExecutor(this.commands);

int timerAfterRestart = this.getConfig().getInt("eventLoop.timer.afterRestart");
int timerDelay = this.getConfig().getInt("eventLoop.timer.delay");

if (timerAfterRestart < 20) {
Bukkit.getLogger().warning(String.format(
"[%s] O event loop está configurado para ser executado em %s segundo(s) logo após a " +
"reinicialização do servidor ou do plugin! Recomendamos um delay entre 20 e 300 segundos neste campo.",
this.getDescription().getName(),
Integer.toString(timerAfterRestart)
));
}

if (timerDelay < 10) {
Bukkit.getLogger().warning(String.format(
"[%s] O event loop está configurado para ser executado a cada %s segundo(s)! Recomendamos um " +
"delay entre 10 e 60 segundos neste campo.",
this.getDescription().getName(),
Integer.toString(timerDelay)
));
}

new BukkitRunnable() {
@Override
public void run() {
QueueItem[] queueItems = null;

try {
queueItems = msdk.getQueueItems();
} catch (WebServiceException | MsdkException e) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), e.getMessage()));
}

if (queueItems == null) {
return;
}

for (QueueItem queueItem : queueItems) {
new BukkitRunnable() {
@Override
public void run() {
if (queueItem.getType().equalsIgnoreCase("online")) {
Player player = getServer().getPlayerExact(queueItem.getNickname());

if (player == null) {
return;
}

int emptySlots = 0;

for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
emptySlots++;
}
}

if (queueItem.getSlotsNeeded() > emptySlots) {
player.sendMessage(String.format(
"%sNão pudemos entregar todos os itens que você comprou em nossa loja porque seu " +
"inventário não tem espaço suficiente. O restante dos itens serão entregues em %s segundo(s). " +
"Para recebê-los, por favor, esvazie seu inventário.",
ChatColor.LIGHT_PURPLE,
Integer.toString(timerDelay)
));

return;
}
}

try {
msdk.hasBeenDelivered(queueItem.getNickname(), queueItem.getUuid());
getServer().dispatchCommand(getServer().getConsoleSender(), queueItem.getCommand());
} catch (WebServiceException | MsdkException e) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), e.getMessage()));
}
}
}.runTask(plugin);
}
}
}.runTaskTimerAsynchronously(this, timerAfterRestart * 20, timerDelay * 20);
}
}
46 changes: 0 additions & 46 deletions src/br/com/mineshop/spigot/mineshop/Commands.java

This file was deleted.

88 changes: 0 additions & 88 deletions src/br/com/mineshop/spigot/mineshop/Main.java

This file was deleted.

9 changes: 5 additions & 4 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
authorization:
scheduler:
firstExecution: 300
repeat: 90
eventLoop:
timer:
afterRestart: 60
delay: 20
token:
9 changes: 3 additions & 6 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: mineshop
description: plugin oficial de integração entre loja e servidor para automatização da entrega de produtos vendidos
version: 1.0.0
main: br.com.mineshop.spigot.mineshop.Main
description: plugin oficial de integração entre loja e servidor para automatizar a entrega de produtos vendidos
version: 2.0.1
main: br.com.mineshop.plugin.spigot.Main
load: POSTWORLD
author: Sapiente <contato@clayderson.com.br>
website: https://github.com/clayderson/mineshop-spigot
depend: [msdk]
softdepend: [msdk]

commands:
mineshop:
usage: /<command> <token>
Expand Down

0 comments on commit f7593b0

Please sign in to comment.