Skip to content

Commit

Permalink
Merge pull request #1 from GilbertoKPL/main
Browse files Browse the repository at this point in the history
insert pom build and simple refactor
  • Loading branch information
MrDrawn authored May 14, 2022
2 parents f09e63c + 63c4c6e commit 81dfae1
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 73 deletions.
63 changes: 60 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pay2ply.spigot</groupId>
<artifactId>Pay2Ply [SPIGOT]</artifactId>
<artifactId>Pay2Ply</artifactId>
<version>1.0-SNAPSHOT</version>

<repositories>
<repository>
<id>bukkit</id>
<name>bukkit repo</name>
<url>https://repo.mikeprimm.com/</url>
</repository>
<repository>
<id>jitpack</id>
<name>io</name>
<url>https://jitpack.io/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.GilbertoKPL</groupId>
<artifactId>pay2ply-sdk</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>

<build>
<finalName>pay2ply-spigot</finalName>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>

<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
Expand Down
102 changes: 50 additions & 52 deletions src/main/java/com/pay2ply/spigot/Pay2Ply.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,73 @@
import com.pay2ply.sdk.dispense.Dispense;
import com.pay2ply.spigot.command.Pay2PlyCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class Pay2Ply extends JavaPlugin {
private static Pay2Ply instance;
private static Pay2Ply instance;
private final SDK sdk = new SDK();

public Pay2Ply() {
Pay2Ply.instance = this;
}
public Pay2Ply() {
Pay2Ply.instance = this;
}

public static Pay2Ply getInstance() {
return Pay2Ply.instance;
}
public static Pay2Ply getInstance() {
return Pay2Ply.instance;
}

private final SDK sdk = new SDK();
public SDK getSdk() {
return sdk;
}

public SDK getSdk() {
return sdk;
}
@Override
public void onEnable() {
this.saveDefaultConfig();

@Override
public void onEnable() {
this.saveDefaultConfig();
this.sdk.setToken(this.getConfig().getString("settings.token"));

this.sdk.setToken(this.getConfig().getString("settings.token"));
getCommand("pay2ply").setExecutor(new Pay2PlyCommand());

getCommand("pay2ply").setExecutor(new Pay2PlyCommand());

new BukkitRunnable() {
@Override
public void run() {
Dispense[] dispenses = null;

try {
dispenses = sdk.getDispenses();
} catch (Exception exception) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), exception.getMessage()));
}

if (dispenses == null) {
return;
}

for (Dispense dispense : dispenses) {
new BukkitRunnable() {
new BukkitRunnable() {
@Override
public void run() {
Player player = getServer().getPlayerExact(dispense.getUsername());
Dispense[] dispenses = null;

if (player == null) {
return;
}
try {
dispenses = sdk.getDispenses();
} catch (Exception exception) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), exception.getMessage()));
}

try {
sdk.update(dispense.getUsername(), dispense.getId());
getServer().dispatchCommand(getServer().getConsoleSender(), dispense.getCommand());
if (dispenses == null) {
return;
}

if (getConfig().getBoolean("settings.messages")) {
Bukkit.getLogger().info(String.format("[%s] O produto de %s foi ativo.", getDescription().getName(), dispense.getUsername()));
for (Dispense dispense : dispenses) {
new BukkitRunnable() {
@Override
public void run() {
Player player = getServer().getPlayerExact(dispense.getUsername());

if (player == null) {
return;
}

try {
sdk.update(dispense.getUsername(), dispense.getId());
getServer().dispatchCommand(getServer().getConsoleSender(), dispense.getCommand());

if (getConfig().getBoolean("settings.messages")) {
Bukkit.getLogger().info(String.format("[%s] O produto de %s foi ativo.", getDescription().getName(), dispense.getUsername()));
}
} catch (Exception exception) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), exception.getMessage()));
}
}
}.runTask(getInstance());
}
} catch (Exception exception) {
Bukkit.getLogger().warning(String.format("[%s] %s", getDescription().getName(), exception.getMessage()));
}
}
}.runTask(getInstance());
}
}
}.runTaskTimerAsynchronously(this, 60 * 20, 20 * 20);
}
}.runTaskTimerAsynchronously(this, 60 * 20, 20 * 20);
}
}
36 changes: 18 additions & 18 deletions src/main/java/com/pay2ply/spigot/command/Pay2PlyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
import org.bukkit.command.CommandSender;

public class Pay2PlyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
if (!commandSender.hasPermission("pay2ply.command")) {
commandSender.sendMessage(String.format("%sVocê não possui permissão para executar este comando.", ChatColor.RED));
return true;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
if (!commandSender.hasPermission("pay2ply.command")) {
commandSender.sendMessage(String.format("%sVocê não possui permissão para executar este comando.", ChatColor.RED));
return true;
}

if (args.length > 0) {
String token = args[0].trim().toLowerCase();
if (args.length > 0) {
String token = args[0].trim().toLowerCase();

Pay2Ply.getInstance().getSdk().setToken(token);
Pay2Ply.getInstance().getConfig().set("settings.token", token);
Pay2Ply.getInstance().saveConfig();
Pay2Ply.getInstance().getSdk().setToken(token);
Pay2Ply.getInstance().getConfig().set("settings.token", token);
Pay2Ply.getInstance().saveConfig();

commandSender.sendMessage(String.format("%sSe o token do servidor estiver correto, a loja será vinculada em alguns instantes.", ChatColor.GREEN));
commandSender.sendMessage(String.format("%sSe o token do servidor estiver correto, a loja será vinculada em alguns instantes.", ChatColor.GREEN));

return true;
} else {
commandSender.sendMessage(String.format("%s/%s <token do servidor>.", ChatColor.RED, "pay2ply"));
}
return true;
} else {
commandSender.sendMessage(String.format("%s/%s <token do servidor>.", ChatColor.RED, "pay2ply"));
}

return false;
}
return false;
}
}

0 comments on commit 81dfae1

Please sign in to comment.