Skip to content

Commit

Permalink
add money reward
Browse files Browse the repository at this point in the history
  • Loading branch information
assada committed Jun 20, 2022
1 parent 6d85202 commit f5d78f4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dead.guru</groupId>
<artifactId>ItemDatabaseLink</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.6-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand All @@ -21,6 +21,10 @@
</pluginRepositories>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
Expand Down Expand Up @@ -57,16 +61,22 @@
</build>

<dependencies>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.0</version>
<version>5.0.1</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/idl/AbstractItemNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AbstractItemNotifier(ItemChecker checker, FileConfiguration config) {
public void handle(Player player) {
int newItems = this.checker.check(player);
if (newItems > 0) {
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Got " + ChatColor.WHITE + newItems + ChatColor.GREEN + " new items for you. Use " + ChatColor.YELLOW + "/claim" + ChatColor.GREEN + " command to claim it!");
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " " + ChatColor.WHITE + ChatColor.BOLD + newItems + ChatColor.RESET + ChatColor.GREEN + " new rewards waiting for you. Use " + ChatColor.BOLD + ChatColor.YELLOW + "/claim" + ChatColor.RESET + ChatColor.GREEN + " command to claim it!");
}
}
}
21 changes: 18 additions & 3 deletions src/main/java/idl/ClaimCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import idl.Data.IDLItemStack;
import idl.Data.Item;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand All @@ -21,10 +23,12 @@
public class ClaimCommand implements CommandExecutor {
private final FileConfiguration config;
private final ItemChecker checker;
private Economy econ;

public ClaimCommand(FileConfiguration config, ItemChecker checker) {
public ClaimCommand(FileConfiguration config, ItemChecker checker, Economy economy) {
this.config = config;
this.checker = checker;
this.econ = economy;
}

@Override
Expand Down Expand Up @@ -56,6 +60,17 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
gotIds.add(idlItem.getId());
player.sendMessage(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + " Done! You are completely healed and completely full!");
}
if(idlItem.getType().equals("Money") && null != econ) {
int qty = idlItem.getQty();
EconomyResponse r = econ.depositPlayer(player, qty);
if(r.transactionSuccess()) {
gotIds.add(idlItem.getId());
player.sendMessage(String.format(ChatColor.DARK_GREEN + "[" + config.getString("general.chatPrefix") + ChatColor.DARK_GREEN + "]" + ChatColor.GREEN + "You were given " + ChatColor.YELLOW + "%s" + ChatColor.GREEN + " and now have "+ChatColor.YELLOW+"%s", econ.format(r.amount), econ.format(r.balance)));
} else {
Bukkit.getLogger().warning("[ItemDatabaseLink] Vault disabled!");
player.sendMessage(String.format("An error occured: %s", r.errorMessage));
}
}
if (idlItem.getType().equals("PotionEffect")) {
PotionEffectType effectType = PotionEffectType.getByName(idlItem.getValue().toUpperCase());
if (effectType != null) {
Expand Down Expand Up @@ -83,12 +98,12 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}
if (freeSlots) {
transferred = player.getInventory().addItem(value).isEmpty();
message = ChatColor.GREEN + "Done! Check your inventory!";
message = ChatColor.GREEN + "Done! Check your inventory!"; //TODO: messages
} else if (dropIfInventoryIsFull) {
Location loc = player.getLocation();
player.getWorld().dropItem(loc, value);
transferred = true;
message = ChatColor.GREEN + "Done! Items on ground near you!";
message = ChatColor.GREEN + "Done! Items on ground near you!"; //TODO: messages
}
if (transferred) {
gotIds.add(item.getItem().getId());
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/idl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,43 @@

import idl.DataSource.ItemDataSource;
import idl.DataSource.ItemMysqlDataSource;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
FileConfiguration config = getConfig();
MysqlDataSource dataSource = new MysqlDataSource(config);
private static Economy econ;

private boolean setupEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}

public static Economy getEconomy() {
return econ;
}

@Override
public void onEnable() {
Bukkit.getLogger().info(ChatColor.GREEN + "[" + this.getName() + "] Enabled " + this.getName());
if (!setupEconomy() ) {
Bukkit.getLogger().severe(String.format("[%s] - No Vault soft-dependency found!", getDescription().getName()));
getServer().getPluginManager().disablePlugin(this);
return;
}
if (config.getInt("general.configVersion", 1) < 5) { //config migration
if (config.getInt("general.configVersion", 1) < 4) {
config.set("general.configVersion", 4);
Expand Down Expand Up @@ -55,7 +79,7 @@ public void onEnable() {
}

getServer().getPluginManager().registerEvents(listener, this);
this.getCommand("claim").setExecutor(new ClaimCommand(config, itemChecker));
this.getCommand("claim").setExecutor(new ClaimCommand(config, itemChecker, this.getEconomy()));
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ItemCheckTask(itemChecker, config), 0L, config.getLong("general.checkTicks", 3600L));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ commands:
description: Claim all items
usage: /<command>
permission: idl.command.claim
softdepend: [AuthMe]
softdepend: [AuthMe, Vault]
permissions:
idl.*:
description: Gives access to all commands
Expand Down

0 comments on commit f5d78f4

Please sign in to comment.