Skip to content

Commit

Permalink
v1.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
byteful committed Apr 3, 2024
1 parent dd63c29 commit 0690ebc
Show file tree
Hide file tree
Showing 21 changed files with 1,642 additions and 1,346 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,27 @@ dependencies {

ItemStack hand = player.getInventory().getItemInMainHand();
LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(hand);
tool.setLevel(69);
tool.setXp(420);
player.getInventory().setItemInMainHand(tool.getItemStack());
tool.

setLevel(69);
tool.

setXp(420);
player.

getInventory().

setItemInMainHand(tool.getItemStack());

// Events

@EventHandler
public void onLevelEvent(LevelToolsLevelIncreaseEvent event) {
event.setNewLevel(69);
event.setNewLevel(69);
}

@EventHandler
public void onXPEvent(LevelToolsXPIncreaseEvent event) {
event.setNewXp(420);
event.setNewXp(420);
}
```
18 changes: 8 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,28 @@ repositories {
maven {
url = uri('https://redempt.dev')
}
maven {
url = uri('https://repo.aikar.co/content/groups/aikar/')
}
maven {
url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/')
}
}

dependencies {
implementation 'de.tr7zw:item-nbt-api:2.12.2'
implementation 'com.github.Redempt:RedLib:6.5.9'
implementation 'de.tr7zw:item-nbt-api:2.12.3'
implementation 'com.github.Redempt:RedLib:6.6.1'
implementation 'com.github.Redempt:Crunch:2.0.3'
implementation 'com.github.cryptomorin:XSeries:9.9.0'
implementation 'com.github.Revxrsal.Lamp:common:3.1.9'
implementation 'com.github.Revxrsal.Lamp:bukkit:3.1.9'
implementation 'com.github.Revxrsal.Lamp:common:3.2.0'
implementation 'com.github.Revxrsal.Lamp:bukkit:3.2.0'
implementation 'com.github.Sven65:Item-Names:1.0.2'
implementation 'org.bstats:bstats-bukkit:3.0.2'

compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:24.1.0'
compileOnly 'me.clip:placeholderapi:2.11.5'
}

group = 'me.byteful.plugin'
version = '1.3.6.1'
version = '1.3.7'
description = 'LevelTools'
java.sourceCompatibility = JavaVersion.VERSION_1_8

Expand All @@ -69,8 +67,8 @@ shadowJar {
relocate "de.tr7zw.changeme.nbtapi", "me.byteful.plugin.leveltools.libs.nbtapi"
relocate "com.cryptomorin.xseries", "me.byteful.plugin.leveltools.libs.xseries"
relocate "redempt.redlib", "me.byteful.plugin.leveltools.libs.redlib"
relocate 'co.aikar.commands', 'me.byteful.plugin.leveltools.libs.aikar.acf'
relocate 'co.aikar.locales', 'me.byteful.plugin.leveltools.libs.aikar.locales'
relocate 'revxrsal.commands', 'me.byteful.plugin.leveltools.libs.lamp'
relocate 'org.bstats', 'me.byteful.plugin.leveltools.libs.bstats'
}

def targetJavaVersion = 8
Expand Down
266 changes: 145 additions & 121 deletions src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.byteful.plugin.leveltools;

import static me.byteful.plugin.leveltools.util.Text.colorize;

import java.util.Objects;
import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
import me.byteful.plugin.leveltools.util.LevelToolsUtil;
import org.bukkit.command.CommandSender;
Expand All @@ -9,142 +12,163 @@
import revxrsal.commands.annotation.*;
import revxrsal.commands.help.CommandHelp;

import java.util.Objects;

import static me.byteful.plugin.leveltools.util.Text.colorize;

@Command("leveltools")
public class LevelToolsCommand {
@Dependency
private LevelToolsPlugin plugin;

@DefaultFor("leveltools")
@Subcommand("help")
@Description("Shows the list of LevelTools commands.")
public void onHelp(CommandSender sender, CommandHelp<String> help, @Default("1") int page) {
sender.sendMessage(colorize("&6&lLevelTools Command Help:"));
for (String entry : help.paginate(page, 7)) {
sender.sendMessage(colorize(entry));
}
@Dependency private LevelToolsPlugin plugin;

@DefaultFor("leveltools")
@Subcommand("help")
@Description("Shows the list of LevelTools commands.")
public void onHelp(CommandSender sender, CommandHelp<String> help, @Default("1") int page) {
sender.sendMessage(colorize("&6&lLevelTools Command Help:"));
for (String entry : help.paginate(page, 7)) {
sender.sendMessage(colorize(entry));
}
}

@Subcommand("reload")
@Description("Reloads LevelTools' plugin configuration.")
public void onReload(CommandSender sender) {
if (!checkPerm(sender)) {
return;
}

plugin.reloadConfig();
plugin.setAnvilCombineMode();
plugin.setLevelXpFormula();
sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successful_reload"))));
@Subcommand("reload")
@Description("Reloads LevelTools' plugin configuration.")
public void onReload(CommandSender sender) {
if (!checkPerm(sender)) {
return;
}

@Subcommand("reset")
@Description("Resets all XP/Levels for all the items in the target player.")
public void onReset(CommandSender sender, Player target, @Switch("all") boolean all) {
final ItemStack hand = LevelToolsUtil.getHand(target);
if (!all) {
if (!LevelToolsUtil.isSupportedTool(hand.getType())) {
sender.sendMessage(colorize(plugin.getConfig().getString("messages.item_not_tool")));

return;
}

final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(hand);
tool.setLevel(0);
tool.setXp(0);
LevelToolsUtil.setHand(target, tool.getItemStack());
sender.sendMessage(colorize(plugin.getConfig().getString("messages.successfully_reset_hand_tool", "&aSuccessfully reset tool in hand's XP/Levels for {player}.").replace("{player}", target.getName())));

return;
}

final PlayerInventory inv = target.getInventory();
final ItemStack[] contents = inv.getContents();
for (int i = 0; i < contents.length; i++) {
final ItemStack item = contents[i];
if (item == null || !LevelToolsUtil.isSupportedTool(item.getType())) {
continue;
}
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setLevel(0);
tool.setXp(0);
inv.setItem(i, tool.getItemStack());
}
sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_reset_tools")).replace("{player}", target.getName())));
plugin.reloadConfig();
plugin.setAnvilCombineMode();
plugin.setLevelXpFormula();
sender.sendMessage(
colorize(
Objects.requireNonNull(plugin.getConfig().getString("messages.successful_reload"))));
}

@Subcommand("reset")
@Description("Resets all XP/Levels for all the items in the target player.")
public void onReset(CommandSender sender, Player target, @Switch("all") boolean all) {
final ItemStack hand = LevelToolsUtil.getHand(target);
if (!all) {
if (!LevelToolsUtil.isSupportedTool(hand.getType())) {
sender.sendMessage(colorize(plugin.getConfig().getString("messages.item_not_tool")));

return;
}

final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(hand);
tool.setLevel(0);
tool.setXp(0);
LevelToolsUtil.setHand(target, tool.getItemStack());
sender.sendMessage(
colorize(
plugin
.getConfig()
.getString(
"messages.successfully_reset_hand_tool",
"&aSuccessfully reset tool in hand's XP/Levels for {player}.")
.replace("{player}", target.getName())));

return;
}

@Subcommand("xp")
@Description("Sets the item in hand's XP to provided XP.")
public void onXP(Player player, double xp) {
if (!checkPerm(player)) {
return;
}

final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setXp(xp);
LevelToolsUtil.setHand(player, tool.getItemStack());
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
final PlayerInventory inv = target.getInventory();
final ItemStack[] contents = inv.getContents();
for (int i = 0; i < contents.length; i++) {
final ItemStack item = contents[i];
if (item == null || !LevelToolsUtil.isSupportedTool(item.getType())) {
continue;
}
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setLevel(0);
tool.setXp(0);
inv.setItem(i, tool.getItemStack());
}
sender.sendMessage(
colorize(
Objects.requireNonNull(
plugin.getConfig().getString("messages.successfully_reset_tools"))
.replace("{player}", target.getName())));
}

@Subcommand("xp")
@Description("Sets the item in hand's XP to provided XP.")
public void onXP(Player player, double xp) {
if (!checkPerm(player)) {
return;
}

@Subcommand("level")
@Description("Sets the item in hand's level to provided level.")
public void onLevel(Player player, int level) {
if (!checkPerm(player)) {
return;
}

final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
final int initial = tool.getLevel();
tool.setLevel(level);
LevelToolsUtil.setHand(player, tool.getItemStack());
if (initial != tool.getLevel()) {
LevelToolsUtil.handleReward(tool, player);
}
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setXp(xp);
LevelToolsUtil.setHand(player, tool.getItemStack());
player.sendMessage(
colorize(
Objects.requireNonNull(
plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(
colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
}

@Subcommand("levelup")
@Description("Increases the item in hand's level to next level.")
public void onLevelUp(Player player) {
if (!checkPerm(player)) {
return;
}

final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setLevel(tool.getLevel() + 1);
LevelToolsUtil.setHand(player, tool.getItemStack());
LevelToolsUtil.handleReward(tool, player);
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
@Subcommand("level")
@Description("Sets the item in hand's level to provided level.")
public void onLevel(Player player, int level) {
if (!checkPerm(player)) {
return;
}

private boolean checkPerm(CommandSender sender) {
if (!sender.hasPermission("leveltools.admin")) {
sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.no_permission"))));
final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
final int initial = tool.getLevel();
tool.setLevel(level);
LevelToolsUtil.setHand(player, tool.getItemStack());
if (initial != tool.getLevel()) {
LevelToolsUtil.handleReward(tool, player);
}
player.sendMessage(
colorize(
Objects.requireNonNull(
plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(
colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
}

return false;
}
@Subcommand("levelup")
@Description("Increases the item in hand's level to next level.")
public void onLevelUp(Player player) {
if (!checkPerm(player)) {
return;
}

return true;
final ItemStack item = LevelToolsUtil.getHand(player);

if (LevelToolsUtil.isSupportedTool(item.getType())) {
final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
tool.setLevel(tool.getLevel() + 1);
LevelToolsUtil.setHand(player, tool.getItemStack());
LevelToolsUtil.handleReward(tool, player);
player.sendMessage(
colorize(
Objects.requireNonNull(
plugin.getConfig().getString("messages.successfully_executed_action"))));
} else {
player.sendMessage(
colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
}
}

private boolean checkPerm(CommandSender sender) {
if (!sender.hasPermission("leveltools.admin")) {
sender.sendMessage(
colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.no_permission"))));

return false;
}

return true;
}
}
Loading

0 comments on commit 0690ebc

Please sign in to comment.