Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item lore fix #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.leaderos.plugin.helpers;

import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.SimpleCommandMap;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

/**
* Unload mechanism for commands
* @author WaterArchery, hyperion
* @since 1.0.0
*/
public class CommandHelper {

/**
* Unload all cached commands
*
* @since 1.0
* @author WaterArchery
*/
public static void unregisterCommands(List<String> commands) {
commands.forEach(command -> getBukkitCommands(getCommandMap()).remove(command));
}

/**
* Get command map from server
*
* @since 1.0
* @author hyperion
*/
@NotNull
private static CommandMap getCommandMap() {
try {
final Server server = Bukkit.getServer();
final Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap");
getCommandMap.setAccessible(true);

return (CommandMap) getCommandMap.invoke(server);
} catch (final Exception ignored) {
throw new CommandRegistrationException("Unable get Command Map. Commands will not be registered!");
}
}

// copied from triumph-cmd, credit goes to triumph-team
@NotNull
private static Map<String, Command> getBukkitCommands(@NotNull final CommandMap commandMap) {
try {
final Field bukkitCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
bukkitCommands.setAccessible(true);
//noinspection unchecked
return (Map<String, org.bukkit.command.Command>) bukkitCommands.get(commandMap);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new CommandRegistrationException("Unable get Bukkit commands. Commands might not be registered correctly!");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public static int getDurability(ItemStack item, int maxDurability) {
ItemMeta meta = result.getItemMeta();
meta.setLore(lore);
meta.setDisplayName(name);
meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
if (XMaterial.supports(14) && modelId > 0) {
meta.setCustomModelData(modelId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package net.leaderos.plugin.modules.auth;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.auth.commands.AuthCommand;
import net.leaderos.shared.modules.LeaderOSModule;

import java.util.Arrays;
import java.util.Collections;

/**
* Auth module of leaderos-plugin
*
Expand All @@ -23,7 +27,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new AuthCommand());
CommandHelper.unregisterCommands(Collections.singletonList("auth"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import lombok.Getter;
import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.bazaar.commands.BazaarCommand;
import net.leaderos.shared.modules.LeaderOSModule;

import java.util.Arrays;

/**
* Bazaar module of leaderos-plugin
*
Expand All @@ -31,7 +34,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new BazaarCommand());
CommandHelper.unregisterCommands(Arrays.asList("bazaar", "webbazaar", "pazar"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.leaderos.plugin.modules.cache;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.cache.commands.CacheCommand;
import net.leaderos.plugin.modules.cache.listeners.CacheUpdateEvent;
import net.leaderos.plugin.modules.cache.listeners.LoginListener;
Expand All @@ -9,6 +10,9 @@
import net.leaderos.shared.modules.LeaderOSModule;
import org.bukkit.event.HandlerList;

import java.util.Arrays;
import java.util.Collections;

/**
* Cache module of leaderos-plugin
*
Expand Down Expand Up @@ -61,7 +65,7 @@ public void onDisable() {
// Removes cache
User.getUserList().clear();
// Unregister Command
Bukkit.getCommandManager().unregisterCommand(new CacheCommand());
CommandHelper.unregisterCommands(Collections.singletonList("leaderos-cache"));
// Placeholder unloader
if( org.bukkit.Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public String onPlaceholderRequest(Player p, String identifier) {
return user.getEmail();
else if (identifier.equals("credit"))
return String.valueOf(user.getCredit());
else if (identifier.equals("credit_integer"))
return String.valueOf((int) user.getCredit());
else if (identifier.equals("creation_ip"))
return user.getCreationIp();
else if (identifier.equals("creation_date"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.leaderos.plugin.modules.credit;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.credit.commands.CreditCommand;
import net.leaderos.shared.modules.LeaderOSModule;

import java.util.Arrays;

/**
* Credit module of leaderos-plugin
*
Expand All @@ -23,7 +26,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new CreditCommand());
CommandHelper.unregisterCommands(Arrays.asList("credit", "credits", "kredi"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.leaderos.plugin.modules.discord;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.discord.commands.SyncCommand;
import net.leaderos.shared.modules.LeaderOSModule;

import java.util.Arrays;

/**
* Discord module of leaderos-plugin
*
Expand All @@ -23,7 +26,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new SyncCommand());
CommandHelper.unregisterCommands(Arrays.asList("discord-sync", "discord-link"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cryptomorin.xseries.profiles.objects.Profileable;
import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.helpers.ItemUtil;
import net.leaderos.plugin.modules.donations.commands.DonationsCommand;
import net.leaderos.plugin.modules.donations.model.Donation;
Expand All @@ -16,8 +17,8 @@
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;

/**
* Donations module main class
Expand All @@ -40,7 +41,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new DonationsCommand());
CommandHelper.unregisterCommands(Arrays.asList("donations", "recentdonations", "krediyukleyenler"));
Timer.taskid.cancel();
if( org.bukkit.Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import lombok.Getter;
import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.voucher.commands.VoucherCommand;
import net.leaderos.plugin.modules.voucher.listeners.VoucherListener;
import net.leaderos.plugin.modules.voucher.data.Data;
import net.leaderos.shared.modules.LeaderOSModule;
import org.bukkit.event.HandlerList;

import java.util.Arrays;

/**
* Voucher module of leaderos plugin
* @author poyrazinan
Expand Down Expand Up @@ -41,7 +44,7 @@ public void onEnable() {
*/
public void onDisable() {
HandlerList.unregisterAll(voucherListener);
Bukkit.getCommandManager().unregisterCommand(new VoucherCommand());
CommandHelper.unregisterCommands(Arrays.asList("creditvoucher", "creditsvoucher", "creditsvouchers", "kredikagidi"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.leaderos.plugin.modules.webstore;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.helpers.CommandHelper;
import net.leaderos.plugin.modules.webstore.commands.WebStoreCommand;
import net.leaderos.plugin.modules.webstore.model.Category;
import net.leaderos.shared.exceptions.RequestException;
import net.leaderos.shared.modules.LeaderOSModule;

import java.io.IOException;
import java.util.Arrays;

/**
* Web-store module of leaderos-plugin
Expand All @@ -27,7 +29,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
Bukkit.getCommandManager().unregisterCommand(new WebStoreCommand());
CommandHelper.unregisterCommands(Arrays.asList("webstore", "webshop", "sitemarket", "webmarket"));
}

/**
Expand Down