Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
- Recoded entire codebase
- Reworked every kit from the ground up
  • Loading branch information
Foulest committed Oct 30, 2024
1 parent fb294ec commit e7ec7c0
Show file tree
Hide file tree
Showing 72 changed files with 1,883 additions and 3,428 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'net.foulest'
version = '1.4.0'
version = '1.4.1'
description = 'KitPvP'

// Set the project's language level
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/net/foulest/kitpvp/KitPvP.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.foulest.kitpvp.kits.type.*;
import net.foulest.kitpvp.listeners.DeathListener;
import net.foulest.kitpvp.listeners.EventListener;
import net.foulest.kitpvp.listeners.FlaskListener;
import net.foulest.kitpvp.listeners.KitListener;
import net.foulest.kitpvp.region.Spawn;
import net.foulest.kitpvp.util.DatabaseUtil;
Expand All @@ -42,7 +43,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Objects;
import java.util.logging.Level;

/**
Expand Down Expand Up @@ -72,6 +72,7 @@ public void onLoad() {

@Override
@SneakyThrows
@SuppressWarnings("NestedMethodCall")
public void onEnable() {
// Kicks all online players.
Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer("Disconnected"));
Expand All @@ -96,7 +97,7 @@ public void onEnable() {

// Loads the plugin's listeners.
MessageUtil.log(Level.INFO, "Loading Listeners...");
loadListeners(new DeathListener(), new EventListener(), new KitListener());
loadListeners(new DeathListener(), new EventListener(), new KitListener(), new FlaskListener());

// Loads the plugin's commands.
MessageUtil.log(Level.INFO, "Loading Commands...");
Expand All @@ -107,10 +108,8 @@ public void onEnable() {

// Loads the plugin's kits.
MessageUtil.log(Level.INFO, "Loading Kits...");
loadKits(new Archer(), new Burrower(), new Cactus(), new Dragon(), new Fisherman(), new Ghost(), new Tamer(),
new Hulk(), new Imprisoner(), new Kangaroo(), new Knight(), new Mage(), new Monk(), new Ninja(),
new Pyro(), new Spiderman(), new Summoner(), new Tank(), new Thor(), new Timelord(), new Vampire(),
new Zen());
loadKits(new Archer(), new Fisherman(), new Kangaroo(), new Knight(), new Mage(),
new Ninja(), new Pyro(), new Tank(), new Vampire());

// Loads the spawn.
MessageUtil.log(Level.INFO, "Loading Spawn...");
Expand All @@ -125,7 +124,12 @@ public void onEnable() {
// Loads online players' user data.
MessageUtil.log(Level.INFO, "Loading Player Data...");
for (Player player : Bukkit.getOnlinePlayers()) {
Objects.requireNonNull(PlayerDataManager.getPlayerData(player)).load();
PlayerData playerData = PlayerDataManager.getPlayerData(player);

if (playerData != null) {
playerData.load();
}

Spawn.teleport(player);
player.getInventory().setHeldItemSlot(0);
}
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/net/foulest/kitpvp/cmds/ArmorColorCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package net.foulest.kitpvp.cmds;

import net.foulest.kitpvp.util.ConstantUtil;
import lombok.Data;
import net.foulest.kitpvp.util.MessageUtil;
import net.foulest.kitpvp.util.command.Command;
import net.foulest.kitpvp.util.command.CommandArgs;
Expand All @@ -27,6 +27,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -35,42 +36,42 @@
*
* @author Foulest
*/
@Data
public class ArmorColorCmd {

@SuppressWarnings("MethodMayBeStatic")
@Command(name = "armorcolor", description = "Colors your chestplate with an RGB hex.",
permission = "kitpvp.armorcolor", usage = "/armorcolor [hex]", inGameOnly = true)
public void onCommand(@NotNull CommandArgs args) {
Player player = args.getPlayer();
public static void onCommand(@NotNull CommandArgs args) {
CommandSender sender = args.getSender();

if (player == null) {
MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY);
return;
}
Player player = args.getPlayer();

// Prints the usage message.
if (args.length() != 1) {
MessageUtil.messagePlayer(sender, "&cUsage: /armorcolor [hex]");
return;
}

if (args.getArgs(0).length() != 6) {
String hex = args.getArgs(0);

if (hex.length() != 6) {
MessageUtil.messagePlayer(sender, "&cInvalid hex.");
return;
}

if (player.getInventory().getChestplate().getType() != Material.LEATHER_CHESTPLATE) {
PlayerInventory inventory = player.getInventory();
ItemStack invChestplate = inventory.getChestplate();

if (invChestplate.getType() != Material.LEATHER_CHESTPLATE) {
MessageUtil.messagePlayer(sender, "&cYou can't color that chestplate.");
return;
}

ItemStack chestplate = new ItemBuilder(player.getInventory().getChestplate())
.color(Color.fromRGB(Integer.parseInt(args.getArgs(0), 16))).getItem();
ItemStack chestplate = new ItemBuilder(invChestplate)
.color(Color.fromRGB(Integer.parseInt(hex, 16))).getItem();

player.getInventory().setChestplate(chestplate);
inventory.setChestplate(chestplate);
player.updateInventory();

MessageUtil.messagePlayer(sender, "&aColor 0x" + args.getArgs(0) + " has been applied.");
MessageUtil.messagePlayer(sender, "&aColor 0x" + hex + " has been applied.");
}
}
16 changes: 11 additions & 5 deletions src/main/java/net/foulest/kitpvp/cmds/BalanceCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package net.foulest.kitpvp.cmds;

import lombok.Data;
import net.foulest.kitpvp.data.PlayerData;
import net.foulest.kitpvp.data.PlayerDataManager;
import net.foulest.kitpvp.util.ConstantUtil;
Expand All @@ -33,13 +34,13 @@
*
* @author Foulest
*/
@Data
public class BalanceCmd {

@SuppressWarnings("MethodMayBeStatic")
@Command(name = "balance", aliases = {"bal", "money", "coins"},
description = "Shows your current balance.",
permission = "kitpvp.balance", usage = "/balance [player]", inGameOnly = true)
public void onCommand(@NotNull CommandArgs args) {
public static void onCommand(@NotNull CommandArgs args) {
CommandSender sender = args.getSender();
Player player = args.getPlayer();

Expand All @@ -53,18 +54,23 @@ public void onCommand(@NotNull CommandArgs args) {

// Prints the usage message.
if (args.length() != 1) {
MessageUtil.messagePlayer(sender, "&fCoins: &6" + playerData.getCoins());
int coins = playerData.getCoins();
MessageUtil.messagePlayer(sender, "&fCoins: &6" + coins);
return;
}

Player target = Bukkit.getPlayer(args.getArgs(0));
String targetName = args.getArgs(0);
Player target = Bukkit.getPlayer(targetName);
PlayerData targetData = PlayerDataManager.getPlayerData(target);

if (!target.isOnline()) {
MessageUtil.messagePlayer(sender, ConstantUtil.PLAYER_NOT_FOUND);
return;
}

MessageUtil.messagePlayer(args.getSender(), "&f" + target.getName() + "'s Coins: &6" + targetData.getCoins());
targetName = target.getName();
int targetCoins = targetData.getCoins();

MessageUtil.messagePlayer(sender, "&f" + targetName + "'s Coins: &6" + targetCoins);
}
}
66 changes: 43 additions & 23 deletions src/main/java/net/foulest/kitpvp/cmds/BountyCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package net.foulest.kitpvp.cmds;

import lombok.Data;
import net.foulest.kitpvp.data.PlayerData;
import net.foulest.kitpvp.data.PlayerDataManager;
import net.foulest.kitpvp.util.ConstantUtil;
Expand All @@ -30,18 +31,20 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* Command for placing bounties on other players.
*
* @author Foulest
*/
@Data
public class BountyCmd {

@SuppressWarnings("MethodMayBeStatic")
@Command(name = "bounty", aliases = "bounties",
description = "Allows players to place bounties on each other.",
permission = "kitpvp.bounties", usage = "/bounty [player]", inGameOnly = true)
public void onCommand(@NotNull CommandArgs args) {
public static void onCommand(@NotNull CommandArgs args) {
CommandSender sender = args.getSender();
Player player = args.getPlayer();

Expand All @@ -52,7 +55,12 @@ public void onCommand(@NotNull CommandArgs args) {
}

PlayerData playerData = PlayerDataManager.getPlayerData(player);
Player benefactor = Bukkit.getPlayer(playerData.getBenefactor());
UUID playerUUID = player.getUniqueId();
String playerName = player.getName();

UUID benefactorUUID = playerData.getBenefactor();
Player benefactor = Bukkit.getPlayer(benefactorUUID);
String benefactorName = benefactor.getName();

// Checks if the bounties feature is enabled.
if (!Settings.bountiesEnabled) {
Expand All @@ -62,13 +70,14 @@ public void onCommand(@NotNull CommandArgs args) {

if (args.length() == 0) {
MessageUtil.messagePlayer(player, "");
int activeBounty = playerData.getBounty();

if (playerData.getBounty() == 0 || playerData.getBenefactor() == null || !benefactor.isOnline()) {
if (activeBounty == 0 || benefactorUUID == null || !benefactor.isOnline()) {
MessageUtil.messagePlayer(player, " &aYou currently don't have a");
MessageUtil.messagePlayer(player, " &abounty on your head.");
} else {
MessageUtil.messagePlayer(player, " &cYou currently have a &e$" + playerData.getBounty() + " &cbounty");
MessageUtil.messagePlayer(player, " &con your head set by &e" + benefactor.getName() + "&c.");
MessageUtil.messagePlayer(player, " &cYou currently have a &e$" + activeBounty + " &cbounty");
MessageUtil.messagePlayer(player, " &con your head set by &e" + benefactorName + "&c.");
}

MessageUtil.messagePlayer(player, "");
Expand All @@ -86,22 +95,29 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

Player target = Bukkit.getPlayer(args.getArgs(1));
String targetName = args.getArgs(1);
Player target = Bukkit.getPlayer(targetName);
PlayerData targetData = PlayerDataManager.getPlayerData(target);

if (target.equals(player)) {
MessageUtil.messagePlayer(player, "&cYou can't set a bounty on yourself.");
return;
}

// TODO: Implement cooldown in between placing bounties.
if (!target.isOnline()) {
MessageUtil.messagePlayer(player, ConstantUtil.PLAYER_NOT_FOUND);
return;
}

if (!StringUtils.isNumeric(args.getArgs(2))) {
MessageUtil.messagePlayer(player, "&c'" + args.getArgs(3) + "' is not a valid amount.");
targetName = target.getName();
String bountyAmount = args.getArgs(2);

if (!StringUtils.isNumeric(bountyAmount)) {
MessageUtil.messagePlayer(player, "&c'" + bountyAmount + "' is not a valid amount.");
return;
}

int amount = Integer.parseInt(args.getArgs(2));
int amount = Integer.parseInt(bountyAmount);
int minCoins = Settings.bountiesMinAmount;
int maxCoins = Settings.bountiesMaxAmount;

Expand All @@ -120,38 +136,42 @@ public void onCommand(@NotNull CommandArgs args) {
return;
}

if (targetData.getBounty() > amount) {
MessageUtil.messagePlayer(player, "&c" + target.getName() + " already has a higher bounty.");
int targetBounty = targetData.getBounty();

if (targetBounty > amount) {
MessageUtil.messagePlayer(player, "&c" + targetName + " already has a higher bounty.");
return;
}

MessageUtil.messagePlayer(player, "&aYou set a $" + amount + " bounty on " + target.getName() + "'s head.");
MessageUtil.messagePlayer(player, "&aYou set a $" + amount + " bounty on " + targetName + "'s head.");

MessageUtil.messagePlayer(target, "");
MessageUtil.messagePlayer(target, " &c" + player.getName() + " &eset a &c$" + amount + " &ebounty on your head.");
MessageUtil.messagePlayer(target, " &c" + playerName + " &eset a &c$" + amount + " &ebounty on your head.");
MessageUtil.messagePlayer(target, "");

for (Player online : Bukkit.getOnlinePlayers()) {
if (!online.equals(target) && !online.equals(player)) {
MessageUtil.messagePlayer(online, "&c" + player.getName() + " &eset a &c$" + amount + " &ebounty on &c" + target.getName() + "&e's head.");
MessageUtil.messagePlayer(online, "&c" + playerName + " &eset a &c$" + amount + " &ebounty on &c" + targetName + "&e's head.");
}
}

targetData.addBounty(amount, player.getUniqueId());
targetData.addBounty(amount, playerUUID);
playerData.removeCoins(amount);

UUID targetBenefactor = targetData.getBenefactor();

// Refund the original benefactor if they set a new bounty on the same player.
if (targetData.getBenefactor() != null) {
Player targetBenefactor = Bukkit.getPlayer(targetData.getBenefactor());
PlayerData targetBenefactorData = PlayerDataManager.getPlayerData(targetBenefactor);
if (targetBenefactor != null) {
Player targetBenefactorPlayer = Bukkit.getPlayer(targetBenefactor);
PlayerData targetBenefactorData = PlayerDataManager.getPlayerData(targetBenefactorPlayer);

if (targetBenefactor.isOnline()) {
MessageUtil.messagePlayer(targetBenefactor, "&aYour bounty on " + target.getName() + "'s head has been refunded.");
if (targetBenefactorPlayer.isOnline()) {
MessageUtil.messagePlayer(targetBenefactorPlayer, "&aYour bounty on " + targetName + "'s head has been refunded.");
} else {
targetBenefactorData.load();
}

targetBenefactorData.addCoins(targetData.getBounty());
targetBenefactorData.addCoins(targetBounty);
}
}
}
Loading

0 comments on commit e7ec7c0

Please sign in to comment.