forked from HelpChat/DeluxeMenus
-
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.
Merge branch 'HelpChat:main' into main
- Loading branch information
Showing
21 changed files
with
700 additions
and
213 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
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
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
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
124 changes: 68 additions & 56 deletions
124
src/main/java/com/extendedclip/deluxemenus/hooks/NamedHeadHook.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 |
---|---|---|
@@ -1,56 +1,68 @@ | ||
package com.extendedclip.deluxemenus.hooks; | ||
|
||
import com.extendedclip.deluxemenus.DeluxeMenus; | ||
import com.extendedclip.deluxemenus.cache.SimpleCache; | ||
import com.extendedclip.deluxemenus.utils.SkullUtils; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class NamedHeadHook implements ItemHook, Listener, SimpleCache { | ||
|
||
private final Map<String, ItemStack> cache = new ConcurrentHashMap<>(); | ||
|
||
public NamedHeadHook(@NotNull final DeluxeMenus plugin) { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public ItemStack getItem(@NotNull final String... arguments) { | ||
if (arguments.length == 0) { | ||
return DeluxeMenus.getInstance().getHead().clone(); | ||
} | ||
|
||
try { | ||
return cache.computeIfAbsent(arguments[0], SkullUtils::getSkullByName).clone(); | ||
} catch (Exception exception) { | ||
DeluxeMenus.printStacktrace( | ||
"Something went wrong while trying to get a head by name" + | ||
": " + arguments[0], | ||
exception | ||
); | ||
} | ||
|
||
return DeluxeMenus.getInstance().getHead().clone(); | ||
} | ||
|
||
@EventHandler(ignoreCancelled = true) | ||
public void onPlayerQuit(final PlayerQuitEvent event) { | ||
cache.remove(event.getPlayer().getName()); | ||
} | ||
|
||
@Override | ||
public String getPrefix() { | ||
return "head-"; | ||
} | ||
|
||
@Override | ||
public void clearCache() { | ||
cache.clear(); | ||
} | ||
} | ||
package com.extendedclip.deluxemenus.hooks; | ||
|
||
import com.extendedclip.deluxemenus.DeluxeMenus; | ||
import com.extendedclip.deluxemenus.cache.SimpleCache; | ||
import com.extendedclip.deluxemenus.utils.SkullUtils; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import com.extendedclip.deluxemenus.utils.VersionHelper; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.SkullMeta; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class NamedHeadHook implements ItemHook, Listener, SimpleCache { | ||
|
||
private final Map<String, ItemStack> cache = new ConcurrentHashMap<>(); | ||
|
||
public NamedHeadHook(@NotNull final DeluxeMenus plugin) { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public ItemStack getItem(@NotNull final String... arguments) { | ||
if (arguments.length == 0) { | ||
return DeluxeMenus.getInstance().getHead().clone(); | ||
} | ||
|
||
try { | ||
return cache.computeIfAbsent(arguments[0], SkullUtils::getSkullByName).clone(); | ||
} catch (Exception exception) { | ||
DeluxeMenus.printStacktrace( | ||
"Something went wrong while trying to get a head by name" + | ||
": " + arguments[0], | ||
exception | ||
); | ||
} | ||
|
||
return DeluxeMenus.getInstance().getHead().clone(); | ||
} | ||
|
||
@Override | ||
public boolean itemMatchesIdentifiers(@NotNull ItemStack item, @NotNull String... arguments) { | ||
if (arguments.length == 0) { | ||
return false; | ||
} | ||
return arguments[0].equalsIgnoreCase(SkullUtils.getSkullOwner(item)); | ||
} | ||
|
||
@EventHandler(ignoreCancelled = true) | ||
public void onPlayerQuit(final PlayerQuitEvent event) { | ||
cache.remove(event.getPlayer().getName()); | ||
} | ||
|
||
@Override | ||
public String getPrefix() { | ||
return "head-"; | ||
} | ||
|
||
@Override | ||
public void clearCache() { | ||
cache.clear(); | ||
} | ||
} |
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.