-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.3.0 MoneyNotes and Money managing after death!
Fixed: - Removed @testonly from ColorUtils.java - Changed "Best" code length from 12 to 10 - Changed onPlayerJoin event to joinEvent Added: - Auto-Updating config file WITH old values Created: - Entire new class ClickEvent.java which tracks for Player Interact Event and checks if player "deposited" clicked money note - New class that is allowing to manipulate deaths' economy settings - /moneynote class (/withdraw as alias) that can generate a note - New class file that generate Moneynote Itemstack
- Loading branch information
1 parent
7ac2fcf
commit 8a41a90
Showing
12 changed files
with
438 additions
and
13 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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/me/opkarol/opeconomy/commands/NoteExecutor.java
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,48 @@ | ||
package me.opkarol.opeconomy.commands; | ||
|
||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import me.opkarol.opeconomy.Economy; | ||
import me.opkarol.opeconomy.economy.Database; | ||
import me.opkarol.opeconomy.notes.NoteItem; | ||
import org.bukkit.Sound; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static me.opkarol.opeconomy.utils.Utils.isntValidInteger; | ||
import static me.opkarol.opeconomy.utils.Utils.returnMessageToSender; | ||
|
||
public class NoteExecutor extends NoteItem implements CommandExecutor { | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!sender.hasPermission("opeconomy.command.moneynote") && !sender.isOp()) return returnMessageToSender(sender, getDontHavePermission()); | ||
|
||
if (!(sender instanceof Player)) return returnMessageToSender(sender, getNotAvailableToConsole()); | ||
|
||
if (args.length == 0) return returnMessageToSender(sender, getBadUsage()); | ||
|
||
String moneyToWithdrawString = args[0]; | ||
if(isntValidInteger(moneyToWithdrawString)) return returnMessageToSender(sender, getLastArgumentNotNumber()); | ||
|
||
int amount; | ||
try {amount = Integer.parseInt(moneyToWithdrawString);} catch (NumberFormatException e) { return returnMessageToSender(sender, getLastArgumentNotNumber()); } | ||
|
||
if (amount < 0) return returnMessageToSender(sender, getLastArgumentNotNumber()); | ||
Player player = (Player) sender; | ||
if (amount > getMaximumNote() || amount < getMinimumNote()) return returnMessageToSender(sender, getLastArgumentNotNumber()); | ||
|
||
if (Database.getMoneyFromUUID(player.getUniqueId()) >= amount){ | ||
player.getInventory().addItem(NoteItem.getNote(amount, player)); | ||
Database.removePlayerMoney(player.getUniqueId(), amount); | ||
playSound(player, Sound.valueOf(getWithdrawSound())); | ||
return returnMessageToSender(sender, PlaceholderAPI.setPlaceholders(player, getWithdrawnMoney().replace("%money_withdrawn%", String.valueOf(amount)))); | ||
} | ||
|
||
return returnMessageToSender(sender, getBadUsage()); | ||
} | ||
|
||
|
||
} |
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,46 @@ | ||
package me.opkarol.opeconomy.events; | ||
|
||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import me.opkarol.opeconomy.economy.Database; | ||
import me.opkarol.opeconomy.notes.NoteItem; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.persistence.PersistentDataType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
public class ClickEvent extends NoteItem implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.HIGH) | ||
public void clickEvent(@NotNull PlayerInteractEvent event){ | ||
ItemStack item = event.getPlayer().getInventory().getItemInHand(); | ||
if (!item.isSimilar(itemStack)) return; | ||
|
||
int value; | ||
try { | ||
value = Objects.requireNonNull(item.getItemMeta()).getPersistentDataContainer().get(Objects.requireNonNull(NamespacedKey.fromString("opeconomy-money-note-key-dont-leak-pls")), PersistentDataType.INTEGER); | ||
} catch (Exception e) { | ||
return; | ||
} | ||
|
||
Player player = event.getPlayer(); | ||
|
||
int slot = player.getInventory().getHeldItemSlot(); | ||
ItemStack amount = player.getInventory().getItem(slot); | ||
|
||
assert amount != null; | ||
if (amount.getAmount() == 1) player.getInventory().remove(item); | ||
else amount.setAmount(amount.getAmount() - 1); | ||
|
||
Database.addPlayerMoney(player.getUniqueId(), value); | ||
playSound(player, Sound.valueOf(getDepositSound())); | ||
player.sendMessage(PlaceholderAPI.setPlaceholders(player, getDepositedMoney().replace("%money_deposited%", String.valueOf(value)))); | ||
} | ||
} |
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,52 @@ | ||
package me.opkarol.opeconomy.events; | ||
|
||
import me.opkarol.opeconomy.Economy; | ||
import me.opkarol.opeconomy.economy.Database; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.PlayerDeathEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DeathEvent implements Listener { | ||
static double lostMoneyOnDeath; | ||
static double lostPercentageOfMoneyOnDeath; | ||
static boolean killerGetsMoney; | ||
|
||
@EventHandler(priority = EventPriority.HIGH) | ||
public void deathEvent(@NotNull PlayerDeathEvent event){ | ||
Player died = event.getEntity(); | ||
Player killer = event.getEntity().getKiller(); | ||
|
||
if (died == killer){ | ||
return; | ||
} | ||
|
||
if (killer == null) return; | ||
|
||
if (lostPercentageOfMoneyOnDeath != 0 && lostMoneyOnDeath != 0) return; //Both can't be turned on in the same time | ||
else if (lostPercentageOfMoneyOnDeath == 0 && lostMoneyOnDeath == 0) return; //Nothing happens, both turned off | ||
|
||
if (!killerGetsMoney) return; | ||
|
||
double money; | ||
if (lostMoneyOnDeath != 0) money = lostMoneyOnDeath; | ||
else money = Database.getMoneyFromPlayer(died) * lostPercentageOfMoneyOnDeath; | ||
|
||
Economy.getAPI().removeMoney(died.getUniqueId(), (int) money); | ||
Economy.getAPI().addMoney(killer.getUniqueId(), (int) money); | ||
} | ||
|
||
public static void setKillerGetsMoney(boolean killerGetsMoney) { | ||
DeathEvent.killerGetsMoney = killerGetsMoney; | ||
} | ||
|
||
public static void setLostMoneyOnDeath(double lostMoneyOnDeath) { | ||
DeathEvent.lostMoneyOnDeath = lostMoneyOnDeath; | ||
} | ||
|
||
public static void setLostPercentageOfMoneyOnDeath(double lostPercentageOfMoneyOnDeath) { | ||
DeathEvent.lostPercentageOfMoneyOnDeath = lostPercentageOfMoneyOnDeath; | ||
} | ||
} |
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
Oops, something went wrong.