-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clayderson Ferreira
committed
Mar 31, 2019
1 parent
6f67df1
commit f7593b0
Showing
7 changed files
with
173 additions
and
147 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
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; | ||
} | ||
} |
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,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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
authorization: | ||
scheduler: | ||
firstExecution: 300 | ||
repeat: 90 | ||
eventLoop: | ||
timer: | ||
afterRestart: 60 | ||
delay: 20 | ||
token: |
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