9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-22 16:39:21 +00:00

Compare commits

..

71 Commits

Author SHA1 Message Date
LoJoSho
17abd0c8cc feat: Improvements to emote block checking 2023-03-11 20:48:09 -06:00
LoJoSho
a907cd51b9 feat: Add CMI vanish support 2023-03-11 20:07:01 -06:00
LoJoSho
9f6c7db8fd fix: kicking while interacting in emote/wardrobe #76 2023-03-11 19:20:35 -06:00
LoJoSho
2ba83d8cc5 fix: default color being white 2023-03-10 16:06:51 -06:00
LoJoSho
40bf0e173e version bump (2.2.5-DEV) 2023-03-10 16:06:46 -06:00
LoJoSho
a757292b4b version bump (2.2.4) 2023-03-09 19:14:33 -06:00
LoJoSho
b41d466546 fix: action menu not using debug method 2023-03-09 19:09:42 -06:00
LoJoSho
135fdc94d4 fix: sound debug was wrong level 2023-03-09 19:08:21 -06:00
LoJoSho
d0092a2ffe clean: refactor spelling mistake in isBackpackSpawned 2023-03-02 19:19:45 -06:00
LoJoSho
acf31009d5 feat: backpack improvements 2023-03-02 19:19:08 -06:00
LoJoSho
981c6155e7 feat: add all to unapply command 2023-03-01 10:45:06 -06:00
LoJoSho
2ecc86fc7b fix: same issue as before but with cosmetic wardrobe flag 2023-03-01 10:27:27 -06:00
LoJoSho
2682428354 fix: worldguard flag hiding cosmetics when on allow 2023-03-01 10:21:40 -06:00
LoJoSho
df8ad26684 fix: Flying with elytra and teleporting with backpack causing NPE 2023-03-01 10:14:05 -06:00
LoJoSho
1f714c0153 -1 in wardrobe static radius now returns true 2023-03-01 10:09:18 -06:00
LoJoSho
0bfadad222 Reload IA on change option (Legacy IA hook option) 2023-03-01 10:02:27 -06:00
LoJoSho
a1c719fc50 version bump (2.2.4-DEV) 2023-03-01 10:02:05 -06:00
Craftinators
fe9812cd69 clean: suppress warnings 2023-03-01 08:56:49 -05:00
Craftinators
b9699b27c7 fix: spelling errors 2023-03-01 00:52:13 -05:00
Craftinators
2c5ddb542e clean: remove unused import 2023-03-01 00:44:27 -05:00
Craftinators
461642d64b clean: make Type abstract 2023-03-01 00:44:00 -05:00
Craftinators
37a8a2379d clean: add @NotNull & remove import 2023-02-28 22:25:13 -05:00
LoJoSho
e698392e40 Merge pull request #74 from Craftinators/remapped
`Action` Abstraction
2023-02-28 18:54:02 -06:00
Craftinators
e1357b265f clean: use final 2023-02-28 14:50:16 -05:00
Craftinators
a5475b0268 clean: prefer not to use var 2023-02-28 14:50:03 -05:00
Craftinators
60dba9efa6 fix: use parseFloat instead of valueOf 2023-02-28 14:41:46 -05:00
Craftinators
e2d3391070 clean: reduce nesting 2023-02-28 14:40:58 -05:00
Craftinators
aed34ec28d clean: reduce nesting 2023-02-28 14:35:08 -05:00
Craftinators
ae6d88ab56 clean: make Action abstract 2023-02-28 14:34:03 -05:00
LoJoSho
35be7283e9 Merge pull request #72 from Craftinators/remapped
`CosmeticType` Abstraction
2023-02-28 09:32:30 -06:00
Craftinators
224fcb83d9 clean: config to local 2023-02-28 01:03:11 -05:00
Craftinators
98934536be clean: make Cosmetic abstract 2023-02-28 01:02:52 -05:00
LoJoSho
5ac3712e56 Merge pull request #71 from Craftinators/remapped
Database structure changes
2023-02-27 21:57:40 -06:00
Craftinators
2d2d4e6d44 clean: remove TODO 2023-02-27 22:55:33 -05:00
Craftinators
4b1921b754 clean: try-with-resource to SuppressWarnings 2023-02-27 22:55:12 -05:00
Craftinators
8ca1d44375 clean: add error message 2023-02-27 15:36:50 -05:00
Craftinators
23c82cc6ed fix: additional null checks 2023-02-27 15:34:42 -05:00
Craftinators
2bf5280827 fix: reorder null checks 2023-02-27 15:29:50 -05:00
Craftinators
475a1e0ef1 fix: add Class.forName(...) back 2023-02-27 13:06:23 -05:00
Craftinators
ef4d53eb85 fix: throw error if file isn't created 2023-02-27 12:57:12 -05:00
Craftinators
97da4f7809 feat: add SQLData class 2023-02-27 12:53:51 -05:00
Craftinators
1622dac67f clean: cleanup openConnection() 2023-02-27 12:26:43 -05:00
Craftinators
fce1ec5042 refactor: use try-with-resources 2023-02-27 12:23:30 -05:00
Craftinators
060bcc95e1 clean: reorganize MySQLData 2023-02-27 12:20:26 -05:00
Craftinators
5aca80609a feat: make Data abstract 2023-02-27 12:11:09 -05:00
LoJoSho
7c1da21026 Refactoring and Misc changes in UserWardrobeManager 2023-02-25 10:48:39 -06:00
LoJoSho
52329a6de5 Move wardrobe lists to singleton list 2023-02-25 10:34:23 -06:00
LoJoSho
8cdef228e3 Add HMCColor to the internal hook system 2023-02-25 10:27:31 -06:00
LoJoSho
432d6d837a check if user has cosmetic permissions on wardrobe leave 2023-02-25 09:43:19 -06:00
LoJoSho
f42e8b2298 Refactor custom Armorstands and add HMcParticleCloud Entity 2023-02-25 09:39:27 -06:00
LoJoSho
107f5b9215 Merge remote-tracking branch 'origin/remapped' into remapped 2023-02-24 20:31:50 -06:00
LoJoSho
d303fcc45b Merge pull request #70 from Craftinators/remapped
clean: use preferred method
2023-02-24 20:31:31 -06:00
Craftinators
147be9ab7c clean: use preferred method 2023-02-24 21:22:25 -05:00
LoJoSho
7f91f9dbad set default database to SQLite 2023-02-24 20:09:07 -06:00
LoJoSho
63e538511b Merge pull request #69 from Craftinators/remapped
Major consistency changes
2023-02-24 19:48:40 -06:00
Craftinators
d0c8abc38c clean: add annotations 2023-02-24 17:51:48 -05:00
Craftinators
97a28b9e0c clean: remove unused imports 2023-02-24 17:47:21 -05:00
Craftinators
b5ae6e65a1 clean: annotation & variable modifier changes 2023-02-24 17:46:39 -05:00
Craftinators
0c7e740d7a clean: annotation & variable modifier changes 2023-02-24 16:46:23 -05:00
Craftinators
1b7462becc clean: several annotation & naming changes 2023-02-24 13:33:45 -05:00
Craftinators
d508ecd4c0 clean: cosmetic annotation changes 2023-02-24 12:21:53 -05:00
Craftinators
601d6f8a53 fix: break once "-s" flag found 2023-02-24 12:11:22 -05:00
Craftinators
44be4eceb8 clean: comment delete 2023-02-24 12:02:28 -05:00
Craftinators
8bebd57169 fix: event annotation changes 2023-02-24 12:00:14 -05:00
LoJoSho
8f426cef31 version bump (2.2.3) 2023-02-24 10:19:52 -06:00
LoJoSho
abce477f0d add cosmetic playEmote command 2023-02-24 10:19:39 -06:00
LoJoSho
985e797f83 remove annoying space 2023-02-24 09:03:20 -06:00
LoJoSho
8bc84cbdd2 Fix balloon teleport fix not checking if player has balloon 2023-02-24 09:02:16 -06:00
LoJoSho
894e4eef26 update default with correct dye menu name 2023-02-21 17:08:27 -06:00
LoJoSho
5995dabf6f Fix clicking in emote kicking players 2023-02-21 17:05:02 -06:00
LoJoSho
ed647b7e5d Fix for invalid player on emote command 2023-02-21 10:20:42 -06:00
98 changed files with 1016 additions and 616 deletions

1
.gitignore vendored
View File

@@ -23,7 +23,6 @@ atlassian-ide-plugin.xml
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear

View File

@@ -8,7 +8,7 @@ plugins {
}
group = "com.hibiscusmc"
version = "2.2.2"
version = "2.2.5-DEV"
allprojects {
apply(plugin = "java")
@@ -62,7 +62,7 @@ allprojects {
}
dependencies {
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
@@ -77,7 +77,6 @@ allprojects {
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
}
}
@@ -90,7 +89,7 @@ dependencies {
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
implementation("net.kyori:adventure-api:4.11.0")
implementation ("net.kyori:adventure-text-minimessage:4.11.0")
implementation("net.kyori:adventure-text-minimessage:4.11.0")
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
implementation("dev.triumphteam:triumph-gui:3.1.3")
implementation("org.spongepowered:configurate-yaml:4.1.2")
@@ -197,6 +196,12 @@ bukkit {
register("hmccosmetics.cmd.emote") {
default = BukkitPluginDescription.Permission.Default.TRUE
}
register("hmccosmetics.cmd.playemote") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.playemote.other") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.emote.other") {
default = BukkitPluginDescription.Permission.Default.OP
}

View File

@@ -42,8 +42,6 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public final class HMCCosmeticsPlugin extends JavaPlugin {

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.api;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class HMCCosmeticSetupEvent extends Event {
@@ -12,6 +13,7 @@ public class HMCCosmeticSetupEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -5,10 +5,11 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerCosmeticEquipEvent extends Event implements Cancellable {
private CosmeticUser user;
private final CosmeticUser user;
private Cosmetic cosmetic;
private boolean isCancelled;
@@ -31,6 +32,7 @@ public class PlayerCosmeticEquipEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}
@@ -47,7 +49,7 @@ public class PlayerCosmeticEquipEvent extends Event implements Cancellable {
return cosmetic;
}
public void setCosmetic() {
public void setCosmetic(Cosmetic cosmetic) {
this.cosmetic = cosmetic;
}
}

View File

@@ -4,11 +4,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerCosmeticHideEvent extends Event implements Cancellable {
private CosmeticUser user;
private CosmeticUser.HiddenReason reason;
private final CosmeticUser user;
private final CosmeticUser.HiddenReason reason;
private boolean isCancelled;
public PlayerCosmeticHideEvent(CosmeticUser user, CosmeticUser.HiddenReason reason) {
@@ -30,6 +31,7 @@ public class PlayerCosmeticHideEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -5,11 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
private CosmeticUser user;
private Cosmetic cosmetic;
private final CosmeticUser user;
private final Cosmetic cosmetic;
private boolean isCancelled;
public PlayerCosmeticRemoveEvent(CosmeticUser user, Cosmetic cosmetic) {
@@ -31,6 +32,7 @@ public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -4,10 +4,11 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerCosmeticShowEvent extends Event implements Cancellable {
private CosmeticUser user;
private final CosmeticUser user;
private boolean isCancelled;
public PlayerCosmeticShowEvent(CosmeticUser user) {
@@ -28,6 +29,7 @@ public class PlayerCosmeticShowEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -5,11 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerMenuOpenEvent extends Event implements Cancellable {
private CosmeticUser user;
private Menu menu;
private final CosmeticUser user;
private final Menu menu;
private boolean isCancelled;
public PlayerMenuOpenEvent(CosmeticUser user, Menu menu) {
@@ -31,6 +32,7 @@ public class PlayerMenuOpenEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -4,10 +4,11 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerWardrobeEnterEvent extends Event implements Cancellable {
private CosmeticUser user;
private final CosmeticUser user;
private boolean isCancelled;
public PlayerWardrobeEnterEvent(CosmeticUser user) {
@@ -28,6 +29,7 @@ public class PlayerWardrobeEnterEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -4,10 +4,11 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerWardrobeLeaveEvent extends Event implements Cancellable {
private CosmeticUser user;
private final CosmeticUser user;
private boolean isCancelled;
public PlayerWardrobeLeaveEvent(CosmeticUser user) {
@@ -28,6 +29,7 @@ public class PlayerWardrobeLeaveEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}

View File

@@ -15,6 +15,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.ticxo.playeranimator.api.PlayerAnimator;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.EnumUtils;
@@ -27,13 +28,16 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
public class CosmeticCommand implements CommandExecutor {
// cosmetics apply cosmetics playerName
// 0 1 2
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
boolean silent = false;
if (args.length == 0) {
@@ -68,7 +72,10 @@ public class CosmeticCommand implements CommandExecutor {
if (sender.hasPermission("HMCCosmetics.cmd.silent") || sender.isOp()) {
for (String singleArg : args) {
if (singleArg.equalsIgnoreCase("-s")) silent = true;
if (singleArg.equalsIgnoreCase("-s")) {
silent = true;
break;
}
}
}
@@ -88,7 +95,7 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
Cosmetic cosmetic;
Color color = Color.WHITE;
Color color = null;
if (sender instanceof Player) player = ((Player) sender).getPlayer();
if (sender.hasPermission("hmccosmetics.cmd.apply.other")) {
@@ -144,19 +151,11 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
CosmeticSlot cosmeticSlot = null;
if (sender instanceof Player) player = ((Player) sender).getPlayer();
if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) {
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
}
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
return true;
}
cosmeticSlot = CosmeticSlot.valueOf(args[1].toUpperCase());
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
@@ -164,20 +163,34 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user.getCosmetic(cosmeticSlot) == null) {
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
return true;
Set<CosmeticSlot> cosmeticSlots;
if (args[1].equalsIgnoreCase("all")) {
cosmeticSlots = user.getSlotsWithCosmetics();
} else {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
return true;
}
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
}
TagResolver placeholders =
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
if (user.getCosmetic(cosmeticSlot) == null) {
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
continue;
}
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
TagResolver placeholders =
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
user.removeCosmeticSlot(cosmeticSlot);
user.updateCosmetic(cosmeticSlot);
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
user.removeCosmeticSlot(cosmeticSlot);
user.updateCosmetic(cosmeticSlot);
}
return true;
}
case ("wardrobe") -> {
@@ -318,7 +331,7 @@ public class CosmeticCommand implements CommandExecutor {
}
player.sendMessage("Passengers -> " + player.getPassengers());
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorstand().getLocation());
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorStand().getLocation());
}
player.sendMessage("Cosmetics -> " + user.getCosmetic());
player.sendMessage("EntityId -> " + player.getEntityId());
@@ -389,6 +402,10 @@ public class CosmeticCommand implements CommandExecutor {
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
@@ -399,6 +416,38 @@ public class CosmeticCommand implements CommandExecutor {
cosmeticEmoteType.run(user);
return true;
}
case ("playemote") -> {
// /cosmetic playEmote <emoteId> [playerName]
if (!sender.hasPermission("hmccosmetics.cmd.playemote")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (args.length < 2) {
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
return true;
}
if (args.length >= 2) {
if (!PlayerAnimator.api.getAnimationManager().getRegistry().keySet().contains(args[1])) {
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
return true;
}
}
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
user.getUserEmoteManager().playEmote(args[1]);
return true;
}
}
return true;
}

View File

@@ -24,9 +24,9 @@ import java.util.List;
public class CosmeticCommandTabComplete implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String @NotNull [] args) {
List<String> completions = new ArrayList<>();
List<String> finalCompletitons = new ArrayList<>();
List<String> finalCompletions = new ArrayList<>();
if (args.length == 1) {
if (hasPermission(sender, "hmccosmetics.cmd.apply")) completions.add("apply");
@@ -41,8 +41,9 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
StringUtil.copyPartialMatches(args[0], completions, finalCompletitons);
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
}
if (!(sender instanceof Player)) return completions;
@@ -58,6 +59,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
for (Cosmetic cosmetic : user.getCosmetic()) {
completions.add(cosmetic.getSlot().toString().toUpperCase());
}
completions.add("ALL");
}
case "menu" -> {
for (Menu menu : Menus.getMenu()) {
@@ -79,8 +81,11 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add("viewerlocation");
completions.add("leavelocation");
}
case "playemote" -> {
completions.addAll(PlayerAnimator.api.getAnimationManager().getRegistry().keySet());
}
}
StringUtil.copyPartialMatches(args[1], completions, finalCompletitons);
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
}
if (args.length == 3) {
String subcommand = args[0].toLowerCase();
@@ -88,13 +93,13 @@ public class CosmeticCommandTabComplete implements TabCompleter {
case "dye" -> {
completions.add("#FFFFFF");
}
case "menu", "apply", "unapply" -> {
case "menu", "apply", "unapply", "playemote" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
}
}
StringUtil.copyPartialMatches(args[2], completions, finalCompletitons);
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
}
if (args.length == 4) {
@@ -104,14 +109,15 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add("#FFFFFF");
}
}
StringUtil.copyPartialMatches(args[3], completions, finalCompletitons);
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
}
Collections.sort(finalCompletitons);
return finalCompletitons;
Collections.sort(finalCompletions);
return finalCompletions;
}
private static List<String> applyCommandComplete(CosmeticUser user, String[] args) {
@NotNull
private static List<String> applyCommandComplete(CosmeticUser user, String @NotNull [] args) {
List<String> completitions = new ArrayList<>();
if (args.length == 2) {
@@ -130,7 +136,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
return completitions;
}
private boolean hasPermission(CommandSender sender, String permission) {
private boolean hasPermission(@NotNull CommandSender sender, String permission) {
if (sender.isOp()) return true;
if (sender.hasPermission(permission)) return true;
return false;

View File

@@ -32,6 +32,10 @@ public class Settings {
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
private static final String HOOK_SETTING_PATH = "hook-settings";
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change";
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static String defaultMenu;
private static String dyeMenuName;
@@ -46,6 +50,8 @@ public class Settings {
private static boolean debugMode;
private static boolean unapplyOnDeath;
private static boolean forcePermissionJoin;
private static boolean itemsAdderChangeReload;
private static boolean cosmeticEmoteBlockCheck;
private static int lookDownPitch;
private static int viewDistance;
private static int tickPeriod;
@@ -77,6 +83,7 @@ public class Settings {
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
@@ -91,6 +98,10 @@ public class Settings {
dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu");
dyeMenuInputSlot = dyeMenuSettings.node(DYE_MENU_INPUT_SLOT).getInt(19);
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
}
private static Vector loadVector(final ConfigurationNode config) {
@@ -190,6 +201,9 @@ public class Settings {
public static boolean isDebugEnabled() {
return debugMode;
}
public static boolean getItemsAdderReloadChange() {
return itemsAdderChangeReload;
}
public static int getTickPeriod() {
return tickPeriod;
@@ -208,6 +222,11 @@ public class Settings {
public static double getEmoteDistance() {
return emoteDistance;
}
public static boolean getCosmeticEmoteBlockCheck() {
return cosmeticEmoteBlockCheck;
}
public static void setDebugMode(boolean newSetting) {
debugMode = newSetting;

View File

@@ -182,7 +182,7 @@ public class WardrobeSettings {
public static boolean inDistanceOfStatic(final Location location) {
if (wardrobeLocation == null) return false;
if (staticRadius == -1) return false;
if (staticRadius == -1) return true;
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
}

View File

@@ -5,13 +5,14 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.logging.Level;
public class Cosmetic {
public abstract class Cosmetic {
private String id;
private String permission;
@@ -19,8 +20,9 @@ public class Cosmetic {
private CosmeticSlot slot;
private boolean dyable;
protected Cosmetic(String id, ConfigurationNode config) {
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
this.id = id;
if (!config.node("permission").virtual()) {
this.permission = config.node("permission").getString();
} else {
@@ -30,20 +32,20 @@ public class Cosmetic {
if (!config.node("item").virtual()) this.item = generateItemStack(config.node("item"));
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
setDyable(config.node("dyeable").getBoolean(false));
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
Cosmetics.addCosmetic(this);
}
public String getId() {
return this.id;
}
public String getPermission() {
return this.permission;
public void setId(String id) {
this.id = id;
}
public CosmeticSlot getSlot() {
@@ -53,17 +55,17 @@ public class Cosmetic {
public void setSlot(CosmeticSlot slot) {
this.slot = slot;
}
public String getPermission() {
return this.permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public boolean requiresPermission() {
if (permission == null) return false;
return true;
}
public void setId(String id) {
this.id = id;
return permission != null;
}
public void setDyable(boolean dyable) {
@@ -74,10 +76,7 @@ public class Cosmetic {
return this.dyable;
}
public void update(CosmeticUser user) {
// Override
}
public abstract void update(CosmeticUser user);
@Nullable
public ItemStack getItem() {

View File

@@ -6,6 +6,8 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
@@ -17,7 +19,7 @@ import java.util.logging.Level;
public class Cosmetics {
private static HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
public static void addCosmetic(Cosmetic cosmetic) {
COSMETICS.put(cosmetic.getId(), cosmetic);
@@ -35,10 +37,14 @@ public class Cosmetics {
return COSMETICS.get(id);
}
@Contract(pure = true)
@NotNull
public static Set<Cosmetic> values() {
return COSMETICS.values();
}
@Contract(pure = true)
@NotNull
public static Set<String> keys() {
return COSMETICS.keySet();
}
@@ -76,7 +82,7 @@ public class Cosmetics {
}
}
private static void setupCosmetics(CommentedConfigurationNode config) {
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
try {
String id = cosmeticConfig.key().toString();

View File

@@ -7,11 +7,12 @@ import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticArmorType extends Cosmetic {
private EquipmentSlot equipSlot;
private final EquipmentSlot equipSlot;
public CosmeticArmorType(String id, ConfigurationNode config) {
super(id, config);
@@ -20,7 +21,7 @@ public class CosmeticArmorType extends Cosmetic {
}
@Override
public void update(CosmeticUser user) {
public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
if (player == null) return;
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
@@ -32,6 +33,4 @@ public class CosmeticArmorType extends Cosmetic {
public EquipmentSlot getEquipSlot() {
return this.equipSlot;
}
}

View File

@@ -2,43 +2,57 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticBackpackType extends Cosmetic {
private String modelName;
private ConfigurationNode config;
private final String modelName;
private UserBackpackManager.BackpackType backpackType;
public CosmeticBackpackType(String id, ConfigurationNode config) {
super(id, config);
this.config = config;
modelName = config.node("model").getString();
backpackType = UserBackpackManager.BackpackType.valueOf(config.node("type").getString("NORMAL").toUpperCase());
}
@Override
public void update(CosmeticUser user) {
public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
if (player == null) return;
Location loc = player.getLocation().clone().add(0, 2, 0);
if (user.isInWardrobe() || !user.isBackupSpawned()) return;
if (loc.getWorld() != user.getUserBackpackManager().getArmorstand().getWorld()) {
user.getUserBackpackManager().getArmorstand().teleport(loc);
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
if (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) {
user.getUserBackpackManager().getArmorStand().teleport(loc);
}
user.getUserBackpackManager().getArmorstand().teleport(loc);
user.getUserBackpackManager().getArmorStand().teleport(loc);
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorstandId(), loc);
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
user.getUserBackpackManager().teleportEffectEntity(loc);
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
} else {
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
}
user.getUserBackpackManager().getArmorstand().setRotation(loc.getYaw(), loc.getPitch());
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());
user.getUserBackpackManager().showBackpack();
}
public String getModelName() {
return modelName;
}
public UserBackpackManager.BackpackType getBackpackType() {
return backpackType;
}
}

View File

@@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
@@ -16,9 +17,8 @@ import java.util.List;
public class CosmeticBalloonType extends Cosmetic {
private String modelName;
private final String modelName;
private List<String> dyableParts;
//private HashMap<Animations, String> animationBalloons;
public CosmeticBalloonType(String id, ConfigurationNode config) {
super(id, config);
@@ -26,17 +26,9 @@ public class CosmeticBalloonType extends Cosmetic {
String modelId = config.node("model").getString();
try {
if (!config.node("dyable-parts").virtual()) dyableParts = config.node("dyable-parts").getList(String.class);
/*
if (!config.node("animations").virtual()) {
for (ConfigurationNode animationNode : config.node("animations").childrenMap().values()) {
if (EnumUtils.isValidEnum(Animations.class, animationNode.key().toString().toUpperCase())) continue;
animationBalloons.put(Animations.valueOf(animationNode.key().toString().toUpperCase()), animationNode.getString());
}
if (!config.node("dyable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class);
}
*/
} catch (SerializationException e) {
// Seriously?
throw new RuntimeException(e);
@@ -46,12 +38,14 @@ public class CosmeticBalloonType extends Cosmetic {
}
@Override
public void update(CosmeticUser user) {
public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
UserBalloonManager userBalloonManager = user.getBalloonManager();
Location newLocation = player.getLocation();
if (player == null || userBalloonManager == null || newLocation == null) return;
if (player == null || userBalloonManager == null) return;
if (user.isInWardrobe()) return;
Location newLocation = player.getLocation();
Location currentLocation = user.getBalloonManager().getLocation();
newLocation = newLocation.clone().add(Settings.getBalloonOffset());
@@ -86,10 +80,4 @@ public class CosmeticBalloonType extends Cosmetic {
if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name);
}
/*
public String getAnimation(Animations animation) {
return animationBalloons.get(animation);
}
*/
}

View File

@@ -3,11 +3,12 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticEmoteType extends Cosmetic {
private String animationId;
private final String animationId;
public CosmeticEmoteType(String id, ConfigurationNode config) {
super(id, config);
@@ -21,7 +22,7 @@ public class CosmeticEmoteType extends Cosmetic {
// Nothing
}
public void run(CosmeticUser user) {
public void run(@NotNull CosmeticUser user) {
user.getUserEmoteManager().playEmote(this);
}

View File

@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticMainhandType extends Cosmetic {
@@ -14,10 +15,9 @@ public class CosmeticMainhandType extends Cosmetic {
}
@Override
public void update(CosmeticUser user) {
public void update(@NotNull CosmeticUser user) {
Player player = user.getPlayer();
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
}
}

View File

@@ -16,23 +16,23 @@ public class Database {
private static Data data;
@Deprecated
private static InternalData INTERNAL_DATA = new InternalData();
private static MySQLData MYSQL_DATA = new MySQLData();
private static SQLiteData SQLITE_DATA = new SQLiteData();
private static final MySQLData MYSQL_DATA = new MySQLData();
private static final SQLiteData SQLITE_DATA = new SQLiteData();
public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
data = INTERNAL_DATA; // default
if (databaseType.equalsIgnoreCase("INTERNAL")) {
data = INTERNAL_DATA;
}
data = SQLITE_DATA; // default
if (databaseType.equalsIgnoreCase("MySQL")) {
data = MYSQL_DATA;
}
/* SQLite is the default database. Might change in the future, so keep code here in case.
if (databaseType.equalsIgnoreCase("sqlite")) {
data = SQLITE_DATA;
}
*/
MessagesUtil.sendDebugMessages("Database is " + data);
setup();

View File

@@ -10,33 +10,27 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class Data {
public abstract class Data {
public void setup() {
// Override
}
public abstract void setup();
public void save(CosmeticUser user) {
// Override
}
public abstract void save(CosmeticUser user);
@Nullable
public CosmeticUser get(UUID uniqueId) {
// Override
return null;
}
public abstract CosmeticUser get(UUID uniqueId);
public abstract void clear(UUID uniqueId);
public void clear(UUID uniqueId) {
// Override
}
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
public String steralizeData(CosmeticUser user) {
@NotNull
public final String serializeData(@NotNull CosmeticUser user) {
String data = "";
if (user.getHidden()) {
if (shouldHiddenSave(user.getHiddenReason())) {
@@ -56,7 +50,8 @@ public class Data {
return data;
}
public Map<CosmeticSlot, Map<Cosmetic, Color>> desteralizedata(CosmeticUser user, String raw) {
@NotNull
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
boolean checkPermission = Settings.getForcePermissionJoin();
@@ -102,7 +97,7 @@ public class Data {
return cosmetics;
}
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
private boolean shouldHiddenSave(CosmeticUser.@NotNull HiddenReason reason) {
switch (reason) {
case EMOTE, NONE -> {
return false;

View File

@@ -14,6 +14,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.Map;
import java.util.UUID;
@Deprecated
public class InternalData extends Data {
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
@@ -27,7 +28,7 @@ public class InternalData extends Data {
public void save(CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, steralizeData(user));
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, serializeData(user));
}
@Override
@@ -38,7 +39,7 @@ public class InternalData extends Data {
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
Map<CosmeticSlot, Map<Cosmetic, Color>> a = desteralizedata(user, rawData);
Map<CosmeticSlot, Map<Cosmetic, Color>> a = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : a.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {

View File

@@ -2,18 +2,15 @@ package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.*;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
public class MySQLData extends Data {
public class MySQLData extends SQLData {
// Connection Information
private String host;
@@ -22,6 +19,7 @@ public class MySQLData extends Data {
private String password;
private int port;
@Nullable
private Connection connection;
@Override
@@ -35,11 +33,12 @@ public class MySQLData extends Data {
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
try {
openConnection();
if (connection == null) throw new NullPointerException("Connection is null");
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
} catch (SQLException e) {
} catch (SQLException | NullPointerException e) {
plugin.getLogger().severe("");
plugin.getLogger().severe("");
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
@@ -52,104 +51,58 @@ public class MySQLData extends Data {
throw new RuntimeException(e);
}
}
@Override
public void save(CosmeticUser user) {
Runnable run = () -> {
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, steralizeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
};
if (!HMCCosmeticsPlugin.isDisable()) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
} else {
run.run();
}
}
@Override
public CosmeticUser get(UUID uniqueId) {
CosmeticUser user = new CosmeticUser(uniqueId);
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
});
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
});
return user;
}
@Override
public void clear(UUID unqiueId) {
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
preparedSt.setString(1, unqiueId.toString());
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
});
// TODO
}
private void openConnection() throws SQLException {
if (connection != null && !connection.isClosed()) {
return;
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
// ...
// });
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
// Connection isn't null AND Connection isn't closed :: return
try {
if (isConnectionOpen()) {
return;
} else if (connection != null) close(); // Close connection if still active
} catch (RuntimeException e) {
e.printStackTrace(); // If isConnectionOpen() throws error
}
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
//close Connection if still active
if (connection != null) {
close();
}
//connect to database host
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
//});
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
// Connect to database host
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public void close() {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
if (connection == null) throw new NullPointerException("Connection is null");
connection.close();
} catch (SQLException e) {
} catch (SQLException | NullPointerException e) {
System.out.println(e.getMessage());
}
});
}
@NotNull
private Properties setupProperties() {
Properties props = new Properties();
props.put("user", user);
@@ -158,28 +111,29 @@ public class MySQLData extends Data {
return props;
}
private boolean isConnectionOpen() {
private boolean isConnectionOpen() throws RuntimeException {
try {
if (connection == null || connection.isClosed()) {
return false;
} else {
return true;
}
return connection != null && !connection.isClosed();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public PreparedStatement preparedStatement(String query) {
PreparedStatement ps = null;
if (!isConnectionOpen()) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
}
try {
if (connection == null) throw new NullPointerException("Connection is null");
ps = connection.prepareStatement(query);
} catch (SQLException e) {
} catch (SQLException | NullPointerException e) {
e.printStackTrace();
}
return ps;
}
}

View File

@@ -0,0 +1,68 @@
package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
public abstract class SQLData extends Data {
@Override
@SuppressWarnings({"Duplicates", "resource"}) // Duplicate is from deprecated InternalData
public CosmeticUser get(UUID uniqueId) {
CosmeticUser user = new CosmeticUser(uniqueId);
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
});
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
});
return user;
}
@Override
@SuppressWarnings("resource")
public void save(CosmeticUser user) {
Runnable run = () -> {
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
};
if (!HMCCosmeticsPlugin.isDisable()) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
} else {
run.run();
}
}
public abstract PreparedStatement preparedStatement(String query);
}

View File

@@ -1,31 +1,28 @@
package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
public class SQLiteData extends Data {
public class SQLiteData extends SQLData {
private Connection connection;
@Override
public void setup() {
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
boolean exists = dataFolder.exists();
if (!dataFolder.exists()){
if (!exists) {
try {
dataFolder.createNewFile();
boolean created = dataFolder.createNewFile();
if (!created) throw new IOException("File didn't exist but now does");
} catch (IOException e) {
MessagesUtil.sendDebugMessages("File write error. Database will not work properly", Level.SEVERE);
}
@@ -39,66 +36,18 @@ public class SQLiteData extends Data {
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void save(CosmeticUser user) {
Runnable run = () -> {
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, steralizeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
};
if (!HMCCosmeticsPlugin.isDisable()) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
} else {
run.run();
}
}
@Override
public CosmeticUser get(UUID uniqueId) {
CosmeticUser user = new CosmeticUser(uniqueId);
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
});
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
});
return user;
}
@Override
public void clear(UUID unqiueId) {
@SuppressWarnings("resource")
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
preparedSt.setString(1, unqiueId.toString());
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@@ -106,56 +55,47 @@ public class SQLiteData extends Data {
});
}
private void openConnection() throws SQLException {
if (connection != null && !connection.isClosed()) {
return;
}
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
// ...
// });
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
//close Connection if still active
if (connection != null) {
//close();
}
if (connection != null && !connection.isClosed()) return;
// Close Connection if still active
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
//connect to database host
// Connect to database host
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
//});
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
}
@Override
public PreparedStatement preparedStatement(String query) {
PreparedStatement ps = null;
if (!isConnectionOpen()) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
}
try {
ps = connection.prepareStatement(query);
} catch (SQLException e) {
e.printStackTrace();
}
return ps;
}
private boolean isConnectionOpen() {
try {
if (connection == null || connection.isClosed()) {
return false;
} else {
return true;
}
return connection != null && !connection.isClosed();
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@@ -17,6 +17,8 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
@@ -25,13 +27,13 @@ import java.util.List;
public class Menu {
private String id;
private String title;
private int rows;
private ConfigurationNode config;
private String permissionNode;
private final String id;
private final String title;
private final int rows;
private final ConfigurationNode config;
private final String permissionNode;
public Menu(String id, ConfigurationNode config) {
public Menu(String id, @NotNull ConfigurationNode config) {
this.id = id;
this.config = config;
@@ -58,7 +60,7 @@ public class Menu {
openMenu(user, false);
}
public void openMenu(CosmeticUser user, boolean ignorePermission) {
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
Player player = user.getPlayer();
if (player == null) return;
if (!ignorePermission && !permissionNode.isEmpty()) {
@@ -97,7 +99,8 @@ public class Menu {
}
private Gui getItems(CosmeticUser user, Gui gui) {
@Contract("_, _ -> param2")
private Gui getItems(@NotNull CosmeticUser user, Gui gui) {
Player player = user.getPlayer();
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
@@ -164,7 +167,8 @@ public class Menu {
return gui;
}
private List<Integer> getSlots(List<String> slotString) {
@NotNull
private List<Integer> getSlots(@NotNull List<String> slotString) {
List<Integer> slots = new ArrayList<>();
for (String a : slotString) {
@@ -181,6 +185,7 @@ public class Menu {
return slots;
}
@NotNull
private List<Integer> getSlots(int small, int max) {
List<Integer> slots = new ArrayList<>();
@@ -188,7 +193,9 @@ public class Menu {
return slots;
}
private ItemStack updateLore(CosmeticUser user, ItemStack itemStack, Type type, ConfigurationNode config) {
@Contract("_, _, _, _ -> param2")
@NotNull
private ItemStack updateLore(CosmeticUser user, @NotNull ItemStack itemStack, Type type, ConfigurationNode config) {
if (itemStack.hasItemMeta()) {
itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
}
@@ -201,7 +208,6 @@ public class Menu {
public boolean canOpen(Player player) {
if (permissionNode.isEmpty()) return true;
if (player.isOp() || player.hasPermission(permissionNode)) return true;
return false;
return player.isOp() || player.hasPermission(permissionNode);
}
}

View File

@@ -4,6 +4,8 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
@@ -17,21 +19,23 @@ import java.util.logging.Level;
public class Menus {
private static HashMap<String, Menu> MENUS = new HashMap<>();
private static final HashMap<String, Menu> MENUS = new HashMap<>();
public static void addMenu(Menu menu) {
MENUS.put(menu.getId().toUpperCase(), menu);
}
public static Menu getMenu(String id) {
public static Menu getMenu(@NotNull String id) {
return MENUS.get(id.toUpperCase());
}
@Contract(pure = true)
@NotNull
public static Collection<Menu> getMenu() {
return MENUS.values();
}
public static boolean hasMenu(String id) {
public static boolean hasMenu(@NotNull String id) {
return MENUS.containsKey(id.toUpperCase());
}
@@ -41,6 +45,7 @@ public class Menus {
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
@NotNull
public static List<String> getMenuNames() {
List<String> names = new ArrayList<>();

View File

@@ -1,12 +1,13 @@
package com.hibiscusmc.hmccosmetics.gui.action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class Action {
public abstract class Action {
private String id;
private final String id;
public Action(String id) {
public Action(@NotNull String id) {
this.id = id.toUpperCase();
Actions.addAction(this);
}
@@ -15,7 +16,5 @@ public class Action {
return this.id;
}
public void run(CosmeticUser user, String raw) {
// Override
}
public abstract void run(CosmeticUser user, String raw);
}

View File

@@ -4,34 +4,36 @@ import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
@SuppressWarnings("unused")
public class Actions {
private static HashMap<String, Action> actions = new HashMap<>();
private static final HashMap<String, Action> actions = new HashMap<>();
// [ID]
private static ActionMessage ACTION_MESSAGE = new ActionMessage();
private static ActionMenu ACTION_MENU = new ActionMenu();
private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
private static ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
private static ActionSound ACTION_SOUND = new ActionSound();
private static ActionEquip ACTION_EQUIP = new ActionEquip();
private static ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
private static ActionParticle ACTION_PARTICLE = new ActionParticle();
private static ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
private static ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
private static ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
private static final ActionMessage ACTION_MESSAGE = new ActionMessage();
private static final ActionMenu ACTION_MENU = new ActionMenu();
private static final ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
private static final ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
private static final ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
private static final ActionSound ACTION_SOUND = new ActionSound();
private static final ActionEquip ACTION_EQUIP = new ActionEquip();
private static final ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
private static final ActionParticle ACTION_PARTICLE = new ActionParticle();
private static final ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
public static Action getAction(String id) {
public static Action getAction(@NotNull String id) {
return actions.get(id.toUpperCase());
}
public static boolean isAction(String id) {
public static boolean isAction(@NotNull String id) {
return actions.containsKey(id.toUpperCase());
}
@@ -39,7 +41,7 @@ public class Actions {
actions.put(action.getId().toUpperCase(), action);
}
public static void runActions(CosmeticUser user, List<String> raw) {
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
for (String a : raw) {
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
String message = StringUtils.substringAfter(a, "] ");

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class ActionCloseMenu extends Action {
@@ -10,7 +11,7 @@ public class ActionCloseMenu extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, String raw) {
user.getPlayer().closeInventory();
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class ActionConsoleCommand extends Action {
@@ -11,8 +12,7 @@ public class ActionConsoleCommand extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, String raw) {
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
}
}

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticHide extends Action {
@@ -10,10 +11,8 @@ public class ActionCosmeticHide extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
if (!user.getHidden()) {
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
return;
}
public void run(@NotNull CosmeticUser user, String raw) {
if (user.getHidden()) return;
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
}
}

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticShow extends Action {
@@ -10,10 +11,11 @@ public class ActionCosmeticShow extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
if (user.getHidden()) {
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return; // Do not hide if its already off for WG
user.showCosmetics();
}
public void run(@NotNull CosmeticUser user, String raw) {
if (!user.getHidden()) return;
// Do not hide if it's already off for WG
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
}
}

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticToggle extends Action {
@@ -10,13 +11,13 @@ public class ActionCosmeticToggle extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, String raw) {
if (user.getHidden()) {
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
return;
}
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
return;
}
}

View File

@@ -14,9 +14,8 @@ public class ActionEquip extends Action {
@Override
public void run(CosmeticUser user, String raw) {
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
if (cosmetic == null) {
return;
}
if (cosmetic == null) return;
user.addPlayerCosmetic(cosmetic);
}
}

View File

@@ -5,6 +5,9 @@ import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import java.util.logging.Level;
public class ActionMenu extends Action {
@@ -22,12 +25,14 @@ public class ActionMenu extends Action {
raw = raw.replaceAll("-o", "");
ignorePermission = true;
}
if (!Menus.hasMenu(raw)) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Invalid Action Menu -> " + raw);
MessagesUtil.sendDebugMessages("Invalid Action Menu -> " + raw, Level.WARNING);
return;
}
Menu menu = Menus.getMenu(raw);
HMCCosmeticsPlugin.getInstance().getLogger().info(raw + " | " + ignorePermission);
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
menu.openMenu(user, ignorePermission);
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.jetbrains.annotations.NotNull;
public class ActionMessage extends Action {
@@ -11,7 +12,7 @@ public class ActionMessage extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, String raw) {
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
}
}

View File

@@ -5,15 +5,16 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
import com.owen1212055.particlehelper.api.type.ParticleType;
import com.owen1212055.particlehelper.api.type.Particles;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionParticle extends Action {
@@ -22,17 +23,17 @@ public class ActionParticle extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
@SuppressWarnings("ConstantConditions")
public void run(CosmeticUser user, @NotNull String raw) {
String[] rawString = raw.split(" ");
var particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
if (particleType == null) {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
return;
}
boolean multi = false;
if (particleType.multi() != null) {
multi = true; // Should work?
}
// particleType.multi() should never be null, but particleType can be.
boolean multi = particleType.multi() != null;
var particle = multi ? particleType.multi() : particleType.single();
if (particle instanceof DestinationParticle || particle instanceof BlockDataParticle
@@ -40,6 +41,7 @@ public class ActionParticle extends Action {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " is not supported by this action!");
return;
}
particle = ServerUtils.addParticleValues(particle, rawString);
Location location = user.getPlayer().getLocation();
for (Player player : PacketManager.getViewers(location)) {

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.jetbrains.annotations.NotNull;
public class ActionPlayerCommand extends Action {
@@ -11,7 +12,7 @@ public class ActionPlayerCommand extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, String raw) {
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
}
}

View File

@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.logging.Level;
@@ -15,7 +16,7 @@ public class ActionSound extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
Player player = user.getPlayer();
String[] processedString = raw.split(" ");
@@ -24,11 +25,11 @@ public class ActionSound extends Action {
float pitch = 1;
if (processedString.length > 2) {
volume = Float.valueOf(processedString[1]);
pitch = Float.valueOf(processedString[2]);
volume = Float.parseFloat(processedString[1]);
pitch = Float.parseFloat(processedString[2]);
}
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.WARNING);
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
player.playSound(player.getLocation(), soundName, volume, pitch);
}

View File

@@ -13,9 +13,8 @@ public class ActionUnequip extends Action {
@Override
public void run(CosmeticUser user, String raw) {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) {
return;
}
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
user.removeCosmeticSlot(slot);
}

View File

@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccolor.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
import org.bukkit.Bukkit;
@@ -17,17 +18,20 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
public class DyeMenu {
// Yes, I do know how tacted on this feels.
public static void openMenu(CosmeticUser user, Cosmetic cosmetic) {
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
Player player = user.getPlayer();
if (player == null) return;
if (!Hooks.isActiveHook("HMCColor")) {
addCosmetic(user, cosmetic, null);
return;
}
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
if (originalItem == null || !cosmetic.isDyable()) return;
Player player = user.getPlayer();
Gui gui = HMCColorApi.INSTANCE.colorMenu();
gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName()));
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
@@ -43,13 +47,7 @@ public class DyeMenu {
meta instanceof MapMeta mapMeta ? mapMeta.getColor() : null;
if (color == null) return;
//user.removeCosmeticSlot(cosmetic);
user.addPlayerCosmetic(cosmetic, color);
player.setItemOnCursor(new ItemStack(Material.AIR));
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
player.closeInventory();
user.updateCosmetic(cosmetic.getSlot());
}, 2);
addCosmetic(user, cosmetic, color);
} else event.setCancelled(true);
});
@@ -57,4 +55,14 @@ public class DyeMenu {
gui.setCloseGuiAction(event -> {});
gui.open(player);
}
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
Player player = user.getPlayer();
user.addPlayerCosmetic(cosmetic, color);
player.setItemOnCursor(new ItemStack(Material.AIR));
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
player.closeInventory();
user.updateCosmetic(cosmetic.getSlot());
}, 2);
}
}

View File

@@ -5,9 +5,9 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.meta.ItemMeta;
import org.spongepowered.configurate.ConfigurationNode;
public class Type {
public abstract class Type {
private String id;
private final String id;
public Type(String id) {
this.id = id;
@@ -21,12 +21,8 @@ public class Type {
public void run(CosmeticUser user, ConfigurationNode config) {
run(user, config, null);
}
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
// Override
}
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
//TODO: Finish this
return null; // Override
}
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
public abstract ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta);
}

View File

@@ -2,21 +2,22 @@ package com.hibiscusmc.hmccosmetics.gui.type;
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeEmpty;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
public class Types {
private static HashMap<String, Type> types = new HashMap<>();
private static final HashMap<String, Type> types = new HashMap<>();
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
public static Type getType(String id) {
public static Type getType(@NotNull String id) {
return types.get(id.toUpperCase());
}
public static boolean isType(String id) {
public static boolean isType(@NotNull String id) {
return types.containsKey(id.toUpperCase());
}

View File

@@ -14,9 +14,12 @@ import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
@@ -31,17 +34,18 @@ public class TypeCosmetic extends Type {
}
@Override
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
if (config.node("cosmetic").virtual()) return;
String cosmeticName = config.node("cosmetic").getString();
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
Player player = user.getPlayer();
if (cosmetic == null) {
MessagesUtil.sendMessage(user.getPlayer(), "invalid-cosmetic");
MessagesUtil.sendMessage(player, "invalid-cosmetic");
return;
}
if (!user.canEquipCosmetic(cosmetic)) {
MessagesUtil.sendMessage(user.getPlayer(), "no-cosmetic-permission");
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
return;
}
@@ -92,7 +96,7 @@ public class TypeCosmetic extends Type {
}
@Override
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
public ItemMeta setLore(CosmeticUser user, @NotNull ConfigurationNode config, ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (config.node("cosmetic").virtual()) return processLoreLines(user, itemMeta);;
@@ -143,7 +147,10 @@ public class TypeCosmetic extends Type {
return itemMeta;
}
private ItemMeta processLoreLines(CosmeticUser user, ItemMeta itemMeta) {
@Contract("_, _ -> param2")
@NotNull
@SuppressWarnings("Duplicates")
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasLore()) {

View File

@@ -3,11 +3,11 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
@@ -17,7 +17,6 @@ import java.util.List;
public class TypeEmpty extends Type {
// This can be used as an example for making your own types.
public TypeEmpty() {
super("empty");
// This is an empty type, meaning, when a menu item has a type of "empty" it will run the code in the method run.
@@ -25,7 +24,7 @@ public class TypeEmpty extends Type {
// This is the code that's run when the item is clicked.
@Override
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
List<String> actionStrings = new ArrayList<>(); // List where we keep the actions the server will execute.
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
@@ -33,7 +32,7 @@ public class TypeEmpty extends Type {
try {
// This gets the actions with the item. We can add more, such as with the Cosmetic type, an equip and unequip action set.
// We add that to a List of Strings, before running those actions through the server. This is not the area where we deal
// with actions, mearly what should be done for each item.
// with actions, merely what should be done for each item.
if (!actionConfig.node("any").virtual()) actionStrings.addAll(actionConfig.node("any").getList(String.class));
if (clickType != null) {
@@ -53,7 +52,8 @@ public class TypeEmpty extends Type {
}
@Override
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
@SuppressWarnings("Duplicates")
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasLore()) {

View File

@@ -5,7 +5,7 @@ import org.bukkit.inventory.ItemStack;
public class Hook implements Listener {
private String id;
private final String id;
private boolean active;
private boolean itemHook;
@@ -19,7 +19,7 @@ public class Hook implements Listener {
// Override
}
public ItemStack getItem(String itemid) {
public ItemStack getItem(String itemId) {
return null;
// Override
}

View File

@@ -2,18 +2,22 @@ package com.hibiscusmc.hmccosmetics.hooks;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.hooks.items.*;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookCMI;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookHMCColor;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookPremiumVanish;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookSuperVanish;
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
public class Hooks {
private static HashMap<String, Hook> hooks = new HashMap<>();
private static final HashMap<String, Hook> hooks = new HashMap<>();
private static HookOraxen ORAXEN_HOOK = new HookOraxen();
private static HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
private static HookLooty LOOTY_HOOK = new HookLooty();
@@ -22,12 +26,14 @@ public class Hooks {
private static HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
private static HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
private static HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
private static HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
private static HookCMI CMI_HOOK = new HookCMI();
public static Hook getHook(String id) {
public static Hook getHook(@NotNull String id) {
return hooks.get(id.toLowerCase());
}
public static boolean isItemHook(String id) {
public static boolean isItemHook(@NotNull String id) {
return hooks.containsKey(id.toLowerCase());
}
@@ -46,7 +52,8 @@ public class Hooks {
}
}
public static ItemStack getItem(String raw) {
@Nullable
public static ItemStack getItem(@NotNull String raw) {
if (!raw.contains(":")) {
Material mat = Material.getMaterial(raw.toUpperCase());
if (mat == null) return null;
@@ -61,8 +68,7 @@ public class Hooks {
Hook hook = getHook(split[0]);
if (!hook.hasEnabledItemHook()) return null;
if (!hook.getActive()) return null;
ItemStack item = hook.getItem(split[1]);
return item;
return hook.getItem(split[1]);
}
public static boolean isActiveHook(String id) {

View File

@@ -14,8 +14,8 @@ public class HookHMCCosmetics extends Hook implements Listener {
}
@Override
public ItemStack getItem(String itemid) {
Cosmetic cosmetic = Cosmetics.getCosmetic(itemid);
public ItemStack getItem(String itemId) {
Cosmetic cosmetic = Cosmetics.getCosmetic(itemId);
if (cosmetic == null) return null;
return cosmetic.getItem();
}

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
@@ -11,8 +12,6 @@ import org.bukkit.inventory.ItemStack;
public class HookItemAdder extends Hook implements Listener {
// I hate IA, this overcomplicate stuff is so unneeded if it just did its stuff when its needed.
private boolean enabled = false;
public HookItemAdder() {
@@ -21,9 +20,9 @@ public class HookItemAdder extends Hook implements Listener {
}
@Override
public ItemStack getItem(String itemid) {
public ItemStack getItem(String itemId) {
if (enabled) {
CustomStack stack = CustomStack.getInstance(itemid);
CustomStack stack = CustomStack.getInstance(itemId);
if (stack == null) return null;
return stack.getItemStack();
} else {
@@ -33,7 +32,7 @@ public class HookItemAdder extends Hook implements Listener {
@EventHandler
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
if (enabled) return; // Only run on the first event fired; ignore all rest
if (enabled && !Settings.getItemsAdderReloadChange()) return; // Defaultly it will only run once at startup. If hook setting is enable
this.enabled = true;
HMCCosmeticsPlugin.setup();
}

View File

@@ -14,8 +14,8 @@ public class HookLooty extends Hook implements Listener {
}
@Override
public ItemStack getItem(String itemid) {
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemid);
public ItemStack getItem(String itemId) {
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
if (prefabKey == null) return null;
return LootyFactory.INSTANCE.createFromPrefab(prefabKey);
}

View File

@@ -12,7 +12,7 @@ public class HookMythic extends Hook implements Listener {
}
@Override
public ItemStack getItem(String itemid) {
return MythicBukkit.inst().getItemManager().getItemStack(itemid);
public ItemStack getItem(String itemId) {
return MythicBukkit.inst().getItemManager().getItemStack(itemId);
}
}

View File

@@ -14,8 +14,8 @@ public class HookOraxen extends Hook implements Listener {
}
@Override
public ItemStack getItem(String itemid) {
ItemBuilder builder = OraxenItems.getItemById(itemid);
public ItemStack getItem(String itemId) {
ItemBuilder builder = OraxenItems.getItemById(itemId);
if (builder == null) return null;
return builder.build();
}

View File

@@ -0,0 +1,34 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.Zrips.CMI.events.CMIPlayerUnVanishEvent;
import com.Zrips.CMI.events.CMIPlayerVanishEvent;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class HookCMI extends Hook implements Listener {
public HookCMI() {
super("CMI");
}
@EventHandler
public void onPlayerVanish(@NotNull CMIPlayerVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -0,0 +1,11 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import org.bukkit.event.Listener;
public class HookHMCColor extends Hook implements Listener {
public HookHMCColor() {
super("HMCColor");
}
}

View File

@@ -8,6 +8,7 @@ import de.myzelyam.api.vanish.PlayerShowEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class HookPremiumVanish extends Hook implements Listener {
@@ -18,7 +19,7 @@ public class HookPremiumVanish extends Hook implements Listener {
}
@EventHandler
public void onPlayerVanish(PlayerHideEvent event) {
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
@@ -26,7 +27,7 @@ public class HookPremiumVanish extends Hook implements Listener {
}
@EventHandler
public void onPlayerShow(PlayerShowEvent event) {
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;

View File

@@ -8,6 +8,7 @@ import de.myzelyam.api.vanish.PlayerShowEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class HookSuperVanish extends Hook implements Listener {
@@ -18,7 +19,7 @@ public class HookSuperVanish extends Hook implements Listener {
}
@EventHandler
public void onPlayerVanish(PlayerHideEvent event) {
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
@@ -26,7 +27,7 @@ public class HookSuperVanish extends Hook implements Listener {
}
@EventHandler
public void onPlayerShow(PlayerShowEvent event) {
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;

View File

@@ -25,22 +25,25 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
}
@Override
public @NotNull String getIdentifier() {
@NotNull
public String getIdentifier() {
return "HMCCosmetics";
}
@Override
public @NotNull String getAuthor() {
@NotNull
public String getAuthor() {
return "HibiscusMC";
}
@Override
public @NotNull String getVersion() {
@NotNull
public String getVersion() {
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
}
@Override
public String onRequest(OfflinePlayer player, String params) {
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
if (!player.isOnline()) return null;
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
if (user == null) return null;
@@ -132,13 +135,13 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return null;
}
public String getMaterial(Cosmetic cosmetic) {
public String getMaterial(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
return cosmetic.getItem().getType().toString();
}
public String getModelData(Cosmetic cosmetic) {
public String getModelData(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
@@ -146,7 +149,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return String.valueOf(itemMeta.getCustomModelData());
}
public String getItemName(Cosmetic cosmetic) {
public String getItemName(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
@@ -154,7 +157,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return itemMeta.getDisplayName();
}
public String getItemLore(Cosmetic cosmetic) {
public String getItemLore(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (item.hasItemMeta()) {

View File

@@ -12,11 +12,12 @@ import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
public class WGListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
Location location = event.getPlayer().getLocation();
@@ -31,10 +32,12 @@ public class WGListener implements Listener {
}
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) return;
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
return;
}
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString().equalsIgnoreCase("ALLOW")) return;
user.enterWardrobe();
}
}

View File

@@ -13,11 +13,12 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;
public class PlayerConnectionListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
if (!HMCCosmeticsPlugin.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion() != null)
MessagesUtil.sendMessageNoKey(
@@ -46,7 +47,7 @@ public class PlayerConnectionListener implements Listener {
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
if (!event.getPlayer().getPassengers().isEmpty()) {

View File

@@ -23,7 +23,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
@@ -52,6 +51,7 @@ public class PlayerGameListener implements Listener {
registerMenuChangeListener();
registerPlayerEquipmentListener();
registerPlayerArmListener();
registerEntityUseListener();
//registerLookMovement();
//registerMoveListener();
@@ -102,10 +102,10 @@ public class PlayerGameListener implements Listener {
return;
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
user.getUserBackpackManager().hideBackpack();
user.getUserBackpackManager().getArmorstand().teleport(event.getTo());
user.getUserBackpackManager().getArmorStand().teleport(event.getTo());
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic();
@@ -133,14 +133,14 @@ public class PlayerGameListener implements Listener {
return;
}
final Cosmetic cosmetic = user.getCosmetic(CosmeticSlot.BALLOON);
final Color color = user.getCosmeticColor(CosmeticSlot.BALLOON);
user.removeCosmeticSlot(CosmeticSlot.BALLOON);
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.despawnBalloon();
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.addPlayerCosmetic(cosmetic, color);
user.updateCosmetic();
}, 4);
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.spawnBalloon((CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON));
user.updateCosmetic();
}, 4);
}
}
@EventHandler
@@ -174,7 +174,7 @@ public class PlayerGameListener implements Listener {
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
Pose pose = event.getPose();
if (pose.equals(Pose.STANDING)) {
if (!user.isBackupSpawned()) {
if (!user.isBackpackSpawned()) {
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
}
return;
@@ -394,6 +394,10 @@ public class PlayerGameListener implements Listener {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
if (!user.isInWardrobe()) return;
Menu menu = Menus.getDefaultMenu();
if (menu == null) return;
@@ -403,6 +407,21 @@ public class PlayerGameListener implements Listener {
});
}
private void registerEntityUseListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
event.setCancelled(true);
}
}
});
}
private void registerLookMovement() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
@Override

View File

@@ -19,12 +19,14 @@ public interface NMSHandler {
Entity getEntity(int entityId);
Entity getInvisibleArmorstand(Location loc);
Entity getHMCArmorStand(Location loc);
ArmorStand getMEGEntity(Location loc);
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
Entity spawnHMCParticleCloud(Location location);
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
void equipmentSlotUpdate(

View File

@@ -37,7 +37,6 @@ public class NMSHandlers {
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
version = packageVersion;
try {
//Class.forName("org.bukkit.craftbukkit." + version + ".block.CraftBlock").getName();
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
return;
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |

View File

@@ -151,6 +151,10 @@ public class CosmeticUser {
return playerCosmetics.containsKey(slot);
}
public Set<CosmeticSlot> getSlotsWithCosmetics() {
return Set.copyOf(playerCosmetics.keySet());
}
public void updateCosmetic(CosmeticSlot slot) {
if (getCosmetic(slot) == null) {
return;
@@ -287,7 +291,7 @@ public class CosmeticUser {
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.userBackpackManager != null) return;
this.userBackpackManager = new UserBackpackManager(this);
this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType());
userBackpackManager.spawnBackpack(cosmeticBackpackType);
}
@@ -297,7 +301,7 @@ public class CosmeticUser {
userBackpackManager = null;
}
public boolean isBackupSpawned() {
public boolean isBackpackSpawned() {
if (this.userBackpackManager == null) return false;
return true;
}
@@ -401,7 +405,7 @@ public class CosmeticUser {
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
userBackpackManager.getArmorstand().getEquipment().clear();
userBackpackManager.clearItems();
}
updateCosmetic();
MessagesUtil.sendDebugMessages("HideCosmetics");
@@ -427,7 +431,7 @@ public class CosmeticUser {
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
userBackpackManager.getArmorstand().getEquipment().setHelmet(item);
userBackpackManager.setItem(item);
}
updateCosmetic();
MessagesUtil.sendDebugMessages("ShowCosmetics");

View File

@@ -9,6 +9,9 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.ArmorStand;
import org.bukkit.inventory.ItemStack;
@@ -17,37 +20,69 @@ import java.util.logging.Level;
public class UserBackpackManager {
private boolean hideBackpack;
private ArmorStand invisibleArmorstand;
private CosmeticUser user;
private ArmorStand invisibleArmorStand;
private AreaEffectCloud particleCloud;
private final CosmeticUser user;
private BackpackType backpackType;
public UserBackpackManager(CosmeticUser user) {
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
this.user = user;
hideBackpack = false;
backpackType = BackpackType.NORMAL;
this.backpackType = backpackType;
}
public int getFirstArmorstandId() {
return invisibleArmorstand.getEntityId();
public int getFirstArmorStandId() {
return invisibleArmorStand.getEntityId();
}
public ArmorStand getArmorstand() {
return invisibleArmorstand;
public ArmorStand getArmorStand() {
return invisibleArmorStand;
}
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
if (this.invisibleArmorstand != null) return;
if (getBackpackType().equals(BackpackType.NORMAL)) {
spawnNormalBackpack(cosmeticBackpackType);
}
if (getBackpackType().equals(BackpackType.FIRST_PERSON)) {
spawnFirstPersonBackpack(cosmeticBackpackType);
}
}
this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
private void spawnNormalBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.invisibleArmorStand != null) return;
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorstand);
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
}
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
}
public void spawnFirstPersonBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.invisibleArmorStand != null) return;
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
@@ -57,23 +92,28 @@ public class UserBackpackManager {
}
public void despawnBackpack() {
if (invisibleArmorstand == null) return;
invisibleArmorstand.setHealth(0);
invisibleArmorstand.remove();
this.invisibleArmorstand = null;
if (invisibleArmorStand != null) {
invisibleArmorStand.setHealth(0);
invisibleArmorStand.remove();
this.invisibleArmorStand = null;
}
if (particleCloud != null) {
particleCloud.remove();
this.particleCloud = null;
}
}
public void hideBackpack() {
if (user.getHidden() == true) return;
getArmorstand().getEquipment().clear();
if (user.getHidden()) return;
getArmorStand().getEquipment().clear();
hideBackpack = true;
}
public void showBackpack() {
if (hideBackpack == false) return;
if (!hideBackpack) return;
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
getArmorstand().getEquipment().setHelmet(item);
getArmorStand().getEquipment().setHelmet(item);
hideBackpack = false;
}
@@ -81,6 +121,27 @@ public class UserBackpackManager {
hideBackpack = shown;
}
public BackpackType getBackpackType() {
return backpackType;
}
public int getAreaEffectEntityId() {
return particleCloud.getEntityId();
}
public void teleportEffectEntity(Location location) {
particleCloud.teleport(location);
}
public void setItem(ItemStack item) {
getArmorStand().getEquipment().setHelmet(item);
}
public void clearItems() {
ItemStack item = new ItemStack(Material.AIR);
getArmorStand().getEquipment().setHelmet(item);
}
public enum BackpackType {
NORMAL,
FIRST_PERSON // First person not yet implemented

View File

@@ -15,6 +15,7 @@ import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import java.util.logging.Level;
@@ -26,13 +27,13 @@ public class UserBalloonManager {
private final UUID uniqueID;
private final ArmorStand modelEntity;
public UserBalloonManager(Location location) {
public UserBalloonManager(@NotNull Location location) {
this.uniqueID = UUID.randomUUID();
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
}
public void spawnModel(CosmeticBalloonType cosmeticBalloonType, Color color) {
public void spawnModel(@NotNull CosmeticBalloonType cosmeticBalloonType, Color color) {
// redo this
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
balloonType = BalloonType.MODELENGINE;

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.jetbrains.annotations.NotNull;
public class UserEmoteManager {
@@ -13,13 +14,17 @@ public class UserEmoteManager {
this.user = user;
}
public void playEmote(CosmeticEmoteType cosmeticEmoteType) {
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
playEmote(cosmeticEmoteType.getAnimationId());
}
public void playEmote(String animationId) {
if (isPlayingEmote()) return;
if (user.isInWardrobe()) return;
try {
model = new UserEmoteModel(user);
model.playAnimation(cosmeticEmoteType.getAnimationId());
model.playAnimation(animationId);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -14,35 +14,38 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class UserEmoteModel extends PlayerModel {
private CosmeticUser user;
private final CosmeticUser user;
private String emotePlaying;
private int armorstandId;
private final int armorStandId;
private GameMode originalGamemode;
public UserEmoteModel(CosmeticUser user) {
public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer());
this.user = user;
armorstandId = NMSHandlers.getHandler().getNextEntityId();
armorStandId = NMSHandlers.getHandler().getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@Override
public void playAnimation(String id) {
id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits.
public void playAnimation(@NotNull String id) {
if (id.contains(":")) id = id.split(":", 2)[1]; // A:B -> B -> B.B.B
if (!id.contains(".")) id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits.
super.playAnimation(id);
emotePlaying = id;
// Add config option that either allows player to move or forces them into a spot.
Player player = user.getPlayer();
List<Player> viewer = List.of(user.getPlayer());
List<Player> viewer = Collections.singletonList(user.getPlayer());
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
outsideViewers.remove(player);
@@ -50,24 +53,27 @@ public class UserEmoteModel extends PlayerModel {
Location newLocation = player.getLocation().clone();
newLocation.setPitch(0);
double DISTANCE = Settings.getEmoteDistance();
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
if (thirdPersonLocation.getBlock().getType() != Material.AIR) {
if (Settings.getCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
return;
}
user.getPlayer().setInvisible(true);
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
originalGamemode = player.getGameMode();
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorstandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorstandId, viewer);
PacketManager.sendLookPacket(armorstandId, player.getLocation(), viewer);
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
PacketManager.sendLookPacket(armorStandId, player.getLocation(), viewer);
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(armorstandId, viewer);
PacketManager.sendCameraPacket(armorStandId, viewer);
MessagesUtil.sendDebugMessages("playAnimation run");
}
@@ -89,16 +95,16 @@ public class UserEmoteModel extends PlayerModel {
emotePlaying = null;
despawn();
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getPlayer() == null) return;
Player player = user.getPlayer();
List<Player> viewer = List.of(user.getPlayer());
if (viewer == null) return;
if (player == null) return;
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
outsideViewers.remove(player);
int entityId = player.getEntityId();
PacketManager.sendCameraPacket(entityId, viewer);
PacketManager.sendEntityDestroyPacket(armorstandId, viewer);
PacketManager.sendEntityDestroyPacket(armorStandId, viewer);
if (this.originalGamemode != null) {
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
player.setGameMode(this.originalGamemode);
@@ -112,7 +118,6 @@ public class UserEmoteModel extends PlayerModel {
}
public boolean isPlayingAnimation() {
if (emotePlaying == null) return false;
return true;
return emotePlaying != null;
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -23,38 +24,27 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class UserWardrobeManager {
private int NPC_ID;
private final int NPC_ID;
private final int ARMORSTAND_ID;
private final UUID WARDROBE_UUID;
private String npcName;
private UUID WARDROBE_UUID;
private int ARMORSTAND_ID;
private GameMode originalGamemode;
private CosmeticUser user;
private Location viewingLocation;
private Location npcLocation;
private final CosmeticUser user;
private final Location viewingLocation;
private final Location npcLocation;
private Location exitLocation;
private BossBar bossBar;
private boolean active;
private WardrobeStatus wardrobeStatus;
public UserWardrobeManager(CosmeticUser user) {
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
WARDROBE_UUID = UUID.randomUUID();
this.user = user;
exitLocation = WardrobeSettings.getLeaveLocation();
viewingLocation = WardrobeSettings.getViewerLocation();
npcLocation = WardrobeSettings.getWardrobeLocation();
wardrobeStatus = WardrobeStatus.SETUP;
}
public UserWardrobeManager(CosmeticUser user, Location exitLocation, Location viewingLocation, Location npcLocation) {
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
@@ -78,7 +68,7 @@ public class UserWardrobeManager {
}
user.hidePlayer();
List<Player> viewer = List.of(player);
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
@@ -114,8 +104,8 @@ public class UserWardrobeManager {
// Misc
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
user.getUserBackpackManager().getArmorstand().teleport(npcLocation.clone().add(0, 2, 0));
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0));
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
@@ -162,7 +152,7 @@ public class UserWardrobeManager {
setWardrobeStatus(WardrobeStatus.STOPPING);
Player player = user.getPlayer();
List<Player> viewer = List.of(player);
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
@@ -197,11 +187,7 @@ public class UserWardrobeManager {
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
}
if (exitLocation == null) {
player.teleport(player.getWorld().getSpawnLocation());
} else {
player.teleport(exitLocation);
}
player.teleport(Objects.requireNonNullElseGet(exitLocation, () -> player.getWorld().getSpawnLocation()));
if (WardrobeSettings.isEquipPumpkin()) {
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
@@ -213,6 +199,13 @@ public class UserWardrobeManager {
target.hideBossBar(bossBar);
}
// For Wardrobe Temp Cosmetics
for (Cosmetic cosmetic : user.getCosmetic()) {
if (cosmetic.requiresPermission()) {
if (!player.hasPermission(cosmetic.getPermission())) user.removeCosmeticSlot(cosmetic.getSlot());
}
}
user.updateCosmetic();
};
run.run();
@@ -224,15 +217,16 @@ public class UserWardrobeManager {
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (active == false || user.getPlayer() == null) {
Player player = user.getPlayer();
if (!active || player == null) {
MessagesUtil.sendDebugMessages("Active is false");
this.cancel();
return;
}
MessagesUtil.sendDebugMessages("Update ");
List<Player> viewer = List.of(user.getPlayer());
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(user.getPlayer());
outsideViewers.remove(player);
Location location = WardrobeSettings.getWardrobeLocation().clone();
int yaw = data.get();
@@ -251,10 +245,10 @@ public class UserWardrobeManager {
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorstandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
user.getUserBackpackManager().getArmorstand().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorstandId(), outsideViewers);
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
@@ -274,7 +268,7 @@ public class UserWardrobeManager {
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
}
public int getArmorstandId() {
public int getCameraId() {
return ARMORSTAND_ID;
}

View File

@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.util;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class InventoryUtils {
@@ -58,6 +60,8 @@ public class InventoryUtils {
};
}
@Contract(pure = true)
@Nullable
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
switch (slot) {
case 36 -> {
@@ -81,6 +85,8 @@ public class InventoryUtils {
}
}
@Contract(pure = true)
@Nullable
public static CosmeticSlot NMSCosmeticSlot(int slot) {
switch (slot) {
case 5 -> {
@@ -104,7 +110,9 @@ public class InventoryUtils {
}
}
public static EquipmentSlot getEquipmentSlot(CosmeticSlot slot) {
@Contract(pure = true)
@Nullable
public static EquipmentSlot getEquipmentSlot(@NotNull CosmeticSlot slot) {
switch (slot) {
case HELMET -> {
return EquipmentSlot.HEAD;

View File

@@ -15,6 +15,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import java.time.Duration;
@@ -24,9 +26,9 @@ import java.util.logging.Level;
public class MessagesUtil {
private static String prefix;
private static HashMap<String, String> messages = new HashMap<>();
private static final HashMap<String, String> messages = new HashMap<>();
public static void setup(ConfigurationNode config) {
public static void setup(@NotNull ConfigurationNode config) {
prefix = config.node("prefix").getString("");
for (ConfigurationNode node : config.childrenMap().values()) {
if (node.virtual()) continue;
@@ -35,7 +37,7 @@ public class MessagesUtil {
}
}
public static void sendMessage(CosmeticUser user, String key) {
public static void sendMessage(@NotNull CosmeticUser user, String key) {
sendMessage(user.getPlayer(), key);
}
@@ -92,6 +94,7 @@ public class MessagesUtil {
return processString(player, key, null);
}
@Nullable
public static Component processString(Player player, String key, TagResolver placeholders) {
if (!messages.containsKey(key)) return null;
if (messages.get(key) == null) return null;
@@ -104,14 +107,17 @@ public class MessagesUtil {
return Adventure.MINI_MESSAGE.deserialize(message);
}
@NotNull
public static Component processStringNoKey(String message) {
return processStringNoKey(null, message, null);
}
@NotNull
public static Component processStringNoKey(Player player, String message) {
return processStringNoKey(player, message, null);
}
@NotNull
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
message = message.replaceAll("%prefix%", prefix);
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);

View File

@@ -6,12 +6,15 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PlayerUtils {
@Nullable
public static WrappedSignedProperty getSkin(Player player) {
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
.get("textures").stream().findAny().orElse(null);
@@ -22,11 +25,13 @@ public class PlayerUtils {
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
}
public static List<Player> getNearbyPlayers(Player player) {
@NotNull
public static List<Player> getNearbyPlayers(@NotNull Player player) {
return getNearbyPlayers(player.getLocation());
}
public static List<Player> getNearbyPlayers(Location location) {
@NotNull
public static List<Player> getNearbyPlayers(@NotNull Location location) {
List<Player> players = new ArrayList<>();
int viewDistance = Settings.getViewDistance();
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {

View File

@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
public class ColorBuilder {
@@ -13,7 +14,7 @@ public class ColorBuilder {
return canBeColored(new ItemStack(material));
}
public static boolean canBeColored(final ItemStack itemStack) {
public static boolean canBeColored(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
return (itemMeta instanceof LeatherArmorMeta ||

View File

@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +35,7 @@ public class ItemBuilder {
* @param itemStack builder ItemStack
*/
ItemBuilder(final ItemStack itemStack) {
ItemBuilder(final @NotNull ItemStack itemStack) {
this.material = itemStack.getType();
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
: Bukkit.getItemFactory().getItemMeta(this.material);
@@ -44,6 +46,8 @@ public class ItemBuilder {
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final Material material) {
return new ItemBuilder(material);
}
@@ -52,7 +56,8 @@ public class ItemBuilder {
* @param itemStack builder ItemStack
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final ItemStack itemStack) {
return new ItemBuilder(itemStack);
}

View File

@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
public class Keys {
@@ -13,7 +14,7 @@ public class Keys {
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key");
public static void setKey(final ItemStack itemStack) {
public static void setKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -26,7 +27,7 @@ public class Keys {
}
public static <T, Z> void setKey(
final ItemStack itemStack,
final @NotNull ItemStack itemStack,
final NamespacedKey key,
final PersistentDataType<T, Z> type,
final Z value) {
@@ -41,7 +42,7 @@ public class Keys {
itemStack.setItemMeta(itemMeta);
}
public static boolean hasKey(final ItemStack itemStack) {
public static boolean hasKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -51,7 +52,7 @@ public class Keys {
return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE);
}
public static <T, Z> boolean hasKey(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
public static <T, Z> boolean hasKey(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -62,7 +63,7 @@ public class Keys {
}
@Nullable
public static <T, Z> Z getValue(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
public static <T, Z> Z getValue(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public class StringUtils {
@@ -8,15 +9,17 @@ public class StringUtils {
* @param parsed message to be parsed
* @return MiniMessage parsed string
*/
@NotNull
public static Component parse(final String parsed) {
return Adventure.MINI_MESSAGE.deserialize(parsed);
}
@NotNull
public static String parseStringToString(final String parsed) {
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
}
@NotNull
public static String formatArmorItemType(String type) {
type = type.toLowerCase();
final String[] parts = type.split(" ");

View File

@@ -29,7 +29,7 @@ public class Utils {
return original;
}
public static <T> T replaceIf(final @Nullable T original, final T replacement, final Predicate<T> predicate) {
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @NotNull Predicate<T> predicate) {
if (predicate.test(original)) return replacement;
return original;
}

View File

@@ -22,6 +22,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,11 +32,11 @@ import java.util.UUID;
public class PacketManager extends BasePacket {
public static void sendEntitySpawnPacket(
final Location location,
final @NotNull Location location,
final int entityId,
final EntityType entityType,
final UUID uuid,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getModifier().writeDefaults();
@@ -64,7 +65,7 @@ public class PacketManager extends BasePacket {
public static void ridingMountPacket(
int mountId,
int passengerId,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
@@ -84,7 +85,7 @@ public class PacketManager extends BasePacket {
}
}
public static void equipmentSlotUpdate(
Player player,
@NotNull Player player,
CosmeticSlot cosmetic,
List<Player> sendTo
) {
@@ -111,7 +112,7 @@ public class PacketManager extends BasePacket {
}
public static void armorStandMetaPacket(
Entity entity,
@NotNull Entity entity,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
@@ -147,9 +148,9 @@ public class PacketManager extends BasePacket {
}
public static void sendLookPacket(
int entityId,
Location location,
List<Player> sendTo
int entityId,
@NotNull Location location,
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
packet.getIntegers().write(0, entityId);
@@ -166,10 +167,10 @@ public class PacketManager extends BasePacket {
}
public static void sendRotationPacket(
int entityId,
Location location,
boolean onGround,
List<Player> sendTo
int entityId,
@NotNull Location location,
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw = location.getYaw() * ROTATION_FACTOR;
@@ -188,7 +189,7 @@ public class PacketManager extends BasePacket {
int entityId,
int yaw,
boolean onGround,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw2 = yaw * ROTATION_FACTOR;
@@ -225,7 +226,7 @@ public class PacketManager extends BasePacket {
public static void sendRidingPacket(
final int mountId,
final int passengerId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
@@ -240,7 +241,7 @@ public class PacketManager extends BasePacket {
* @param entityId The entity to delete for a player
* @param sendTo The players the packet should be sent to
*/
public static void sendEntityDestroyPacket(final int entityId, List<Player> sendTo) {
public static void sendEntityDestroyPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
for (final Player p : sendTo) sendPacket(p, packet);
@@ -251,7 +252,7 @@ public class PacketManager extends BasePacket {
* @param entityId The Entity ID that camera will go towards
* @param sendTo The players that will be sent this packet
*/
public static void sendCameraPacket(final int entityId, List<Player> sendTo) {
public static void sendCameraPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
packet.getIntegers().write(0, entityId);
for (final Player p : sendTo) sendPacket(p, packet);
@@ -266,10 +267,10 @@ public class PacketManager extends BasePacket {
* @param sendTo Who should it send the packet to?
*/
public static void sendFakePlayerSpawnPacket(
final Location location,
final @NotNull Location location,
final UUID uuid,
final int entityId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
@@ -326,7 +327,7 @@ public class PacketManager extends BasePacket {
*/
public static void sendPlayerOverlayPacket(
final int playerId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
/*
0x01 = Is on fire
@@ -398,7 +399,7 @@ public class PacketManager extends BasePacket {
public static void sendLeashPacket(
final int leashedEntity,
final int entityId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
packet.getIntegers().write(0, leashedEntity);
@@ -417,9 +418,9 @@ public class PacketManager extends BasePacket {
*/
public static void sendTeleportPacket(
final int entityId,
final Location location,
final @NotNull Location location,
boolean onGround,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getIntegers().write(0, entityId);
@@ -444,10 +445,10 @@ public class PacketManager extends BasePacket {
*/
public static void sendMovePacket(
final int entityId,
final Location from,
final Location to,
final @NotNull Location from,
final @NotNull Location to,
final boolean onGround,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
@@ -470,6 +471,7 @@ public class PacketManager extends BasePacket {
sendMovePacket(entityId, from, to, onGround, getViewers(to));
}
@NotNull
public static List<Player> getViewers(Location location) {
ArrayList<Player> viewers = new ArrayList();
if (Settings.getViewDistance() <= 0) {

View File

@@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -58,7 +59,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
@@ -96,7 +97,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
*
* @param position - the new position.
*/
public void setPosition(Vector position) {
public void setPosition(@NotNull Vector position) {
setX(position.getX());
setY(position.getY());
setZ(position.getZ());

View File

@@ -5,6 +5,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
public static final PacketType TYPE =
@@ -55,7 +56,7 @@ public class WrapperPlayServerRelEntityMove extends AbstractPacket {
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}

View File

@@ -24,6 +24,7 @@ cosmetic-settings:
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player.
emote-block-check: true # If the server should check if the block is open (prevents players viewing through blocks)
# view distance in blocks that other players will see the backpack cosmetic
# setting this to lower than the server player view distance should fix the
@@ -35,11 +36,16 @@ cosmetic-settings:
y: 3
z: 0.5
dye-menu:
# If you use ItemsAdder, set this to "§f:offset_-8::cosmetics_gui:"
# If you use ItemsAdder, set this to "§f:offset_-8::dye_menu:"
# If you use Oraxen, set this to "<glyph:neg_shift_8><glyph:dye_menu>"
title: "§f"
input-slot: 19
output-slot: 25
hook-settings:
itemsadder:
# This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but
# could cause console spam as HMCCosmetics has to reload itself as well.
reload-on-change: false
wardrobe:
# spawn static wardrobe if in this radius of wardrobe-location
static-radius: 10

BIN
lib/CMI-API9.3.1.5.jar Normal file

Binary file not shown.

BIN
lib/CMILib1.2.4.6.jar Normal file

Binary file not shown.

View File

@@ -5,13 +5,13 @@ import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
public class InvisibleArmorstand extends ArmorStand {
public class HMCArmorStand extends ArmorStand {
public InvisibleArmorstand(Level world, double x, double y, double z) {
public HMCArmorStand(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public InvisibleArmorstand(Location loc) {
public HMCArmorStand(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_17_R1;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
public class HMCParticleCloud extends AreaEffectCloud {
public HMCParticleCloud(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public HMCParticleCloud(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);
setInvulnerable(true);
setSilent(true);
setNoGravity(true);
persist = false;
}
}

View File

@@ -64,9 +64,15 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
return hmcArmorStand.getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnHMCParticleCloud(Location location) {
HMCParticleCloud hmcParticleCloud = new HMCParticleCloud(location);
return hmcParticleCloud.getBukkitEntity();
}
@Override
@@ -76,7 +82,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);

View File

@@ -5,13 +5,13 @@ import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
public class InvisibleArmorstand extends ArmorStand {
public class HMCArmorStand extends ArmorStand {
public InvisibleArmorstand(Level world, double x, double y, double z) {
public HMCArmorStand(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public InvisibleArmorstand(Location loc) {
public HMCArmorStand(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
public class HMCParticleCloud extends AreaEffectCloud {
public HMCParticleCloud(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public HMCParticleCloud(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);
setInvulnerable(true);
setSilent(true);
setNoGravity(true);
persist = false;
}
}

View File

@@ -66,9 +66,15 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
return hmcArmorStand.getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnHMCParticleCloud(Location location) {
HMCParticleCloud hmcParticleCloud = new HMCParticleCloud(location);
return hmcParticleCloud.getBukkitEntity();
}
@Override
@@ -78,7 +84,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);

View File

@@ -5,13 +5,13 @@ import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
public class InvisibleArmorstand extends ArmorStand {
public class HMCArmorStand extends ArmorStand {
public InvisibleArmorstand(Level world, double x, double y, double z) {
public HMCArmorStand(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public InvisibleArmorstand(Location loc) {
public HMCArmorStand(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
public class HMCParticleCloud extends AreaEffectCloud {
public HMCParticleCloud(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public HMCParticleCloud(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);
setInvulnerable(true);
setSilent(true);
setNoGravity(true);
persist = false;
}
}

View File

@@ -66,9 +66,15 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
return hmcArmorStand.getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnHMCParticleCloud(Location location) {
HMCParticleCloud hmcParticleCloud = new HMCParticleCloud(location);
return hmcParticleCloud.getBukkitEntity();
}
@Override
@@ -78,16 +84,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
HMCArmorStand HMCArmorStand = new HMCArmorStand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
HMCArmorStand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(HMCArmorStand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity();
return HMCArmorStand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);

View File

@@ -5,13 +5,13 @@ import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
public class InvisibleArmorstand extends ArmorStand {
public class HMCArmorStand extends ArmorStand {
public InvisibleArmorstand(Level world, double x, double y, double z) {
public HMCArmorStand(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public InvisibleArmorstand(Location loc) {
public HMCArmorStand(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_19_R2;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
public class HMCParticleCloud extends AreaEffectCloud {
public HMCParticleCloud(Level world, double x, double y, double z) {
super(world, x, y, z);
}
public HMCParticleCloud(Location loc) {
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);
setInvulnerable(true);
setSilent(true);
setNoGravity(true);
persist = false;
}
}

View File

@@ -66,9 +66,15 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
return hmcArmorStand.getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnHMCParticleCloud(Location location) {
HMCParticleCloud hmcParticleCloud = new HMCParticleCloud(location);
return hmcParticleCloud.getBukkitEntity();
}
@Override
@@ -78,7 +84,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);