mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-22 16:39:21 +00:00
Compare commits
148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1eb592137 | ||
|
|
3f951263b9 | ||
|
|
744fc87491 | ||
|
|
ca01a94502 | ||
|
|
879a58d1f4 | ||
|
|
aab40b68a7 | ||
|
|
9533e2ec46 | ||
|
|
7b2e767cac | ||
|
|
4bdd000917 | ||
|
|
b397ae52f9 | ||
|
|
40620f1daa | ||
|
|
4d8d43ee2a | ||
|
|
4f8a32c3e8 | ||
|
|
1d303dee71 | ||
|
|
e9659ab1e8 | ||
|
|
ee917dbf32 | ||
|
|
2a275fe503 | ||
|
|
a5631cd2e4 | ||
|
|
1ed1a2c41d | ||
|
|
c2bf0322a7 | ||
|
|
3f8f84735f | ||
|
|
2fb28dda32 | ||
|
|
6192515550 | ||
|
|
6fcf893bac | ||
|
|
d0dfa19f2d | ||
|
|
c3b4abea40 | ||
|
|
a030d1272b | ||
|
|
d6c4b51b98 | ||
|
|
a306d76c19 | ||
|
|
1d51ee0711 | ||
|
|
e340874270 | ||
|
|
093b01d7ff | ||
|
|
5b129cc254 | ||
|
|
7a32697906 | ||
|
|
2ea272ee4a | ||
|
|
9ebfc9748d | ||
|
|
d1a2b6a016 | ||
|
|
af78424b07 | ||
|
|
c35546e536 | ||
|
|
7db03a2f8a | ||
|
|
99f3765e6e | ||
|
|
fae001a48f | ||
|
|
1ccb35ad62 | ||
|
|
2b4e570172 | ||
|
|
965b6cc740 | ||
|
|
ffda4ba6f5 | ||
|
|
df2da4fc89 | ||
|
|
cea40033f9 | ||
|
|
42a01a44aa | ||
|
|
17c07d0e01 | ||
|
|
ea4d088b04 | ||
|
|
591198175a | ||
|
|
be93369a8b | ||
|
|
fd6553a52a | ||
|
|
961f460ffb | ||
|
|
eb925d9022 | ||
|
|
d05072eb2c | ||
|
|
f456ddf8a4 | ||
|
|
c395b68d6a | ||
|
|
fddd5d0311 | ||
|
|
f08c38ff1a | ||
|
|
a4bd9108b1 | ||
|
|
de1377dc8f | ||
|
|
00ce32c528 | ||
|
|
0ddcb12b31 | ||
|
|
adadecfa19 | ||
|
|
ac35ef8b5d | ||
|
|
65f1c72b8e | ||
|
|
178bff37f5 | ||
|
|
48b9d4fb41 | ||
|
|
81d6583430 | ||
|
|
0304c9ff44 | ||
|
|
bf591e708d | ||
|
|
14bbd111f9 | ||
|
|
2185c27be5 | ||
|
|
aef9e24d28 | ||
|
|
d1a35b721e | ||
|
|
17abd0c8cc | ||
|
|
a907cd51b9 | ||
|
|
9f6c7db8fd | ||
|
|
2ba83d8cc5 | ||
|
|
40bf0e173e | ||
|
|
a757292b4b | ||
|
|
b41d466546 | ||
|
|
135fdc94d4 | ||
|
|
d0092a2ffe | ||
|
|
acf31009d5 | ||
|
|
981c6155e7 | ||
|
|
2ecc86fc7b | ||
|
|
2682428354 | ||
|
|
df8ad26684 | ||
|
|
1f714c0153 | ||
|
|
0bfadad222 | ||
|
|
a1c719fc50 | ||
|
|
fe9812cd69 | ||
|
|
b9699b27c7 | ||
|
|
2c5ddb542e | ||
|
|
461642d64b | ||
|
|
37a8a2379d | ||
|
|
e698392e40 | ||
|
|
e1357b265f | ||
|
|
a5475b0268 | ||
|
|
60dba9efa6 | ||
|
|
e2d3391070 | ||
|
|
aed34ec28d | ||
|
|
ae6d88ab56 | ||
|
|
35be7283e9 | ||
|
|
224fcb83d9 | ||
|
|
98934536be | ||
|
|
5ac3712e56 | ||
|
|
2d2d4e6d44 | ||
|
|
4b1921b754 | ||
|
|
8ca1d44375 | ||
|
|
23c82cc6ed | ||
|
|
2bf5280827 | ||
|
|
475a1e0ef1 | ||
|
|
ef4d53eb85 | ||
|
|
97da4f7809 | ||
|
|
1622dac67f | ||
|
|
fce1ec5042 | ||
|
|
060bcc95e1 | ||
|
|
5aca80609a | ||
|
|
7c1da21026 | ||
|
|
52329a6de5 | ||
|
|
8cdef228e3 | ||
|
|
432d6d837a | ||
|
|
f42e8b2298 | ||
|
|
107f5b9215 | ||
|
|
d303fcc45b | ||
|
|
147be9ab7c | ||
|
|
7f91f9dbad | ||
|
|
63e538511b | ||
|
|
d0c8abc38c | ||
|
|
97a28b9e0c | ||
|
|
b5ae6e65a1 | ||
|
|
0c7e740d7a | ||
|
|
1b7462becc | ||
|
|
d508ecd4c0 | ||
|
|
601d6f8a53 | ||
|
|
44be4eceb8 | ||
|
|
8bebd57169 | ||
|
|
8f426cef31 | ||
|
|
abce477f0d | ||
|
|
985e797f83 | ||
|
|
8bc84cbdd2 | ||
|
|
894e4eef26 | ||
|
|
5995dabf6f | ||
|
|
ed647b7e5d |
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#### Select the option(s) that best describes this PR:
|
||||||
|
- [ ] Major breaking change
|
||||||
|
- [ ] Minor change
|
||||||
|
- [ ] Bug fix
|
||||||
|
- [ ] Feature implementation
|
||||||
|
- [ ] Documentation
|
||||||
|
- [ ] Cleaning
|
||||||
|
- [ ] Refactoring
|
||||||
|
|
||||||
|
#### Please describe the changes this PR makes and why it should be merged:
|
||||||
|
|
||||||
|
#### Check that:
|
||||||
|
- [ ] *Any* new classes, public methods and/or properties are properly documented with `JavaDocs`
|
||||||
|
- [ ] Syntax and style are consistent with existing code
|
||||||
|
- [ ] *Any* replaced method isn't deleted, but rather labeled as deprecated
|
||||||
|
> **Note** In the case where the new method has the exact same signature as the method it's replacing, mention above that the old method *was* deleted.
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,7 +23,6 @@ atlassian-ide-plugin.xml
|
|||||||
*.ctxt
|
*.ctxt
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
|
||||||
*.war
|
*.war
|
||||||
*.nar
|
*.nar
|
||||||
*.ear
|
*.ear
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.hibiscusmc"
|
group = "com.hibiscusmc"
|
||||||
version = "2.2.2"
|
version = "2.2.6"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
@@ -59,10 +59,13 @@ allprojects {
|
|||||||
|
|
||||||
// PlayerAnimator
|
// PlayerAnimator
|
||||||
maven("https://mvn.lumine.io/repository/maven/")
|
maven("https://mvn.lumine.io/repository/maven/")
|
||||||
|
|
||||||
|
// md-5 Repo
|
||||||
|
maven("https://repo.md-5.net/content/groups/public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||||
compileOnly("com.mojang:authlib:1.5.25")
|
compileOnly("com.mojang:authlib:1.5.25")
|
||||||
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
@@ -77,7 +80,6 @@ allprojects {
|
|||||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
|
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +89,7 @@ dependencies {
|
|||||||
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
|
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
|
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
||||||
|
implementation(project(path = ":v1_19_R3", configuration = "reobf"))
|
||||||
|
|
||||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||||
implementation("net.kyori:adventure-api:4.11.0")
|
implementation("net.kyori:adventure-api:4.11.0")
|
||||||
@@ -117,7 +120,7 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runServer {
|
runServer {
|
||||||
minecraftVersion("1.19.2")
|
minecraftVersion("1.19.4")
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
@@ -125,6 +128,7 @@ tasks {
|
|||||||
dependsOn(":v1_18_R2:reobfJar")
|
dependsOn(":v1_18_R2:reobfJar")
|
||||||
dependsOn(":v1_19_R1:reobfJar")
|
dependsOn(":v1_19_R1:reobfJar")
|
||||||
dependsOn(":v1_19_R2:reobfJar")
|
dependsOn(":v1_19_R2:reobfJar")
|
||||||
|
dependsOn(":v1_19_R3:reobfJar")
|
||||||
mergeServiceFiles()
|
mergeServiceFiles()
|
||||||
|
|
||||||
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
||||||
@@ -197,6 +201,12 @@ bukkit {
|
|||||||
register("hmccosmetics.cmd.emote") {
|
register("hmccosmetics.cmd.emote") {
|
||||||
default = BukkitPluginDescription.Permission.Default.TRUE
|
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") {
|
register("hmccosmetics.cmd.emote.other") {
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
|
|||||||
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
||||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||||
import com.jeff_media.updatechecker.UpdateCheckSource;
|
import com.jeff_media.updatechecker.UpdateCheckSource;
|
||||||
@@ -42,8 +45,6 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorldGuard
|
// WorldGuard
|
||||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheckEnabled()) {
|
||||||
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,11 +138,16 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
disable = true;
|
disable = true;
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
Database.save(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) continue;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
player.setInvisible(false);
|
||||||
|
}
|
||||||
|
Database.save(user);
|
||||||
}
|
}
|
||||||
// Plugin shutdown logic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HMCCosmeticsPlugin getInstance() {
|
public static HMCCosmeticsPlugin getInstance() {
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the plugin is set up and/or reloaded
|
||||||
|
*/
|
||||||
public class HMCCosmeticSetupEvent extends Event {
|
public class HMCCosmeticSetupEvent extends Event {
|
||||||
|
|
||||||
public HMCCosmeticSetupEvent() {
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,51 +3,68 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticEquipEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player equips a cosmetic
|
||||||
private CosmeticUser user;
|
*/
|
||||||
private Cosmetic cosmetic;
|
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerCosmeticEquipEvent(CosmeticUser user, Cosmetic cosmetic) {
|
|
||||||
this.user = user;
|
|
||||||
this.cosmetic = cosmetic;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return isCancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
isCancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private Cosmetic cosmetic;
|
||||||
|
|
||||||
@Override
|
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
public HandlerList getHandlers() {
|
super(who);
|
||||||
return handlers;
|
this.cosmetic = cosmetic;
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Cosmetic} being equipped in this event
|
||||||
|
*
|
||||||
|
* @return The {@link Cosmetic} which is being equipped in this event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
public Cosmetic getCosmetic() {
|
public Cosmetic getCosmetic() {
|
||||||
return cosmetic;
|
return cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCosmetic() {
|
/**
|
||||||
|
* Sets the {@link Cosmetic} that the player will equip
|
||||||
|
*
|
||||||
|
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||||
|
*/
|
||||||
|
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from equipping the cosmetic
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a cosmetic user related event
|
||||||
|
*/
|
||||||
|
public abstract class PlayerCosmeticEvent extends Event {
|
||||||
|
protected CosmeticUser user;
|
||||||
|
|
||||||
|
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
|
||||||
|
user = who;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user involved in this event
|
||||||
|
*
|
||||||
|
* @return User who is involved in this event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final CosmeticUser getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,46 +2,59 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticHideEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when cosmetics are hidden from a player
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final CosmeticUser.HiddenReason reason;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
||||||
private CosmeticUser.HiddenReason reason;
|
super(who);
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerCosmeticHideEvent(CosmeticUser user, CosmeticUser.HiddenReason reason) {
|
|
||||||
this.user = user;
|
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.isCancelled = false;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player
|
||||||
|
*
|
||||||
|
* @return The {@link CosmeticUser.HiddenReason} why cosmetics are being hidden for the player
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public CosmeticUser.HiddenReason getReason() {
|
||||||
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from hiding cosmetics
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
public CosmeticUser.HiddenReason getReason() {
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,52 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player removes a cosmetic
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final Cosmetic cosmetic;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
private Cosmetic cosmetic;
|
super(who);
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerCosmeticRemoveEvent(CosmeticUser user, Cosmetic cosmetic) {
|
|
||||||
this.user = user;
|
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
this.isCancelled = false;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Cosmetic} being removed in this event
|
||||||
|
*
|
||||||
|
* @return The {@link Cosmetic} which is being removed in this event
|
||||||
|
*/
|
||||||
|
public Cosmetic getCosmetic() {
|
||||||
|
return cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from removing the cosmetic
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
@@ -38,12 +56,4 @@ public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
|
|||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cosmetic getCosmetic() {
|
|
||||||
return cosmetic;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticShowEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when cosmetics are shown from a player
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerCosmeticShowEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from showing cosmetics
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player starts playing an emote
|
||||||
|
*/
|
||||||
|
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final String animationId;
|
||||||
|
|
||||||
|
public PlayerEmoteStartEvent(@NotNull CosmeticUser who, @NotNull String animationId) {
|
||||||
|
super(who);
|
||||||
|
this.animationId = animationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the animation id of the emote the player started playing
|
||||||
|
* @implNote The returned string of this method may be an invalid animation id. Make sure to validate it before use
|
||||||
|
*
|
||||||
|
* @return The animation id of the emote which the player started playing
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getAnimationId() {
|
||||||
|
return animationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from playing the emote
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player stops playing an emote
|
||||||
|
*/
|
||||||
|
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final UserEmoteManager.StopEmoteReason reason;
|
||||||
|
|
||||||
|
public PlayerEmoteStopEvent(@NotNull CosmeticUser who, @NotNull UserEmoteManager.StopEmoteReason reason) {
|
||||||
|
super(who);
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||||
|
*
|
||||||
|
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||||
|
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@NotNull
|
||||||
|
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||||
|
*
|
||||||
|
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||||
|
* @since 2.2.5
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public UserEmoteManager.StopEmoteReason getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from stopping the emote
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a menu is closed by a player
|
||||||
|
*/
|
||||||
|
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
|
super(who, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a menu related event
|
||||||
|
*/
|
||||||
|
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||||
|
protected Menu menu;
|
||||||
|
|
||||||
|
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
|
super(who);
|
||||||
|
this.menu = menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Menu} involved with this event
|
||||||
|
*
|
||||||
|
* @return The {@link Menu} which is involved with the event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final Menu getMenu() {
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,47 +3,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerMenuOpenEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a menu is opened by a player
|
||||||
|
*/
|
||||||
|
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
private Menu menu;
|
super(who, menu);
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerMenuOpenEvent(CosmeticUser user, Menu menu) {
|
|
||||||
this.user = user;
|
|
||||||
this.menu = menu;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from opening a {@link Menu}
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Menu getMenu() {
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerWardrobeEnterEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player enters their wardrobe
|
||||||
|
*/
|
||||||
|
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerWardrobeEnterEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from entering their wardrobe
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerWardrobeLeaveEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player leaves their wardrobe
|
||||||
|
*/
|
||||||
|
public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerWardrobeLeaveEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from leaving their wardrobe
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
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.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
@@ -27,13 +28,15 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class CosmeticCommand implements CommandExecutor {
|
public class CosmeticCommand implements CommandExecutor {
|
||||||
|
|
||||||
// cosmetics apply cosmetics playerName
|
// cosmetics apply cosmetics playerName
|
||||||
// 0 1 2
|
// 0 1 2
|
||||||
|
|
||||||
@Override
|
@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;
|
boolean silent = false;
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
@@ -68,7 +71,10 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
|
|
||||||
if (sender.hasPermission("HMCCosmetics.cmd.silent") || sender.isOp()) {
|
if (sender.hasPermission("HMCCosmetics.cmd.silent") || sender.isOp()) {
|
||||||
for (String singleArg : args) {
|
for (String singleArg : args) {
|
||||||
if (singleArg.equalsIgnoreCase("-s")) silent = true;
|
if (singleArg.equalsIgnoreCase("-s")) {
|
||||||
|
silent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +94,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Cosmetic cosmetic;
|
Cosmetic cosmetic;
|
||||||
Color color = Color.WHITE;
|
Color color = null;
|
||||||
|
|
||||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.apply.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.apply.other")) {
|
||||||
@@ -144,19 +150,11 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CosmeticSlot cosmeticSlot = null;
|
|
||||||
|
|
||||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) {
|
||||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
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 (player == null) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
return true;
|
return true;
|
||||||
@@ -164,9 +162,22 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
||||||
if (user.getCosmetic(cosmeticSlot) == null) {
|
if (user.getCosmetic(cosmeticSlot) == null) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
|
||||||
return true;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TagResolver placeholders =
|
TagResolver placeholders =
|
||||||
@@ -178,6 +189,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
|
|
||||||
user.removeCosmeticSlot(cosmeticSlot);
|
user.removeCosmeticSlot(cosmeticSlot);
|
||||||
user.updateCosmetic(cosmeticSlot);
|
user.updateCosmetic(cosmeticSlot);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("wardrobe") -> {
|
case ("wardrobe") -> {
|
||||||
@@ -318,9 +330,9 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
player.sendMessage("Passengers -> " + player.getPassengers());
|
player.sendMessage("Passengers -> " + player.getPassengers());
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
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("Cosmetics -> " + user.getCosmetics());
|
||||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -389,6 +401,10 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
||||||
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
|
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);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
|
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
|
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
|
||||||
@@ -399,6 +415,38 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
cosmeticEmoteType.run(user);
|
cosmeticEmoteType.run(user);
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import java.util.List;
|
|||||||
public class CosmeticCommandTabComplete implements TabCompleter {
|
public class CosmeticCommandTabComplete implements TabCompleter {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@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> completions = new ArrayList<>();
|
||||||
List<String> finalCompletitons = new ArrayList<>();
|
List<String> finalCompletions = new ArrayList<>();
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.apply")) completions.add("apply");
|
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.show")) completions.add("show");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
|
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;
|
if (!(sender instanceof Player)) return completions;
|
||||||
@@ -55,9 +56,10 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.addAll(applyCommandComplete(user, args));
|
completions.addAll(applyCommandComplete(user, args));
|
||||||
}
|
}
|
||||||
case "unapply" -> {
|
case "unapply" -> {
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
completions.add(cosmetic.getSlot().toString().toUpperCase());
|
completions.add(cosmetic.getSlot().toString().toUpperCase());
|
||||||
}
|
}
|
||||||
|
completions.add("ALL");
|
||||||
}
|
}
|
||||||
case "menu" -> {
|
case "menu" -> {
|
||||||
for (Menu menu : Menus.getMenu()) {
|
for (Menu menu : Menus.getMenu()) {
|
||||||
@@ -79,8 +81,11 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.add("viewerlocation");
|
completions.add("viewerlocation");
|
||||||
completions.add("leavelocation");
|
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) {
|
if (args.length == 3) {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
@@ -88,13 +93,13 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
case "dye" -> {
|
case "dye" -> {
|
||||||
completions.add("#FFFFFF");
|
completions.add("#FFFFFF");
|
||||||
}
|
}
|
||||||
case "menu", "apply", "unapply" -> {
|
case "menu", "apply", "unapply", "playemote" -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
completions.add(player.getName());
|
completions.add(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[2], completions, finalCompletitons);
|
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 4) {
|
if (args.length == 4) {
|
||||||
@@ -104,14 +109,15 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.add("#FFFFFF");
|
completions.add("#FFFFFF");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[3], completions, finalCompletitons);
|
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(finalCompletitons);
|
Collections.sort(finalCompletions);
|
||||||
return finalCompletitons;
|
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<>();
|
List<String> completitions = new ArrayList<>();
|
||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
@@ -130,7 +136,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
return completitions;
|
return completitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPermission(CommandSender sender, String permission) {
|
private boolean hasPermission(@NotNull CommandSender sender, String permission) {
|
||||||
if (sender.isOp()) return true;
|
if (sender.isOp()) return true;
|
||||||
if (sender.hasPermission(permission)) return true;
|
if (sender.hasPermission(permission)) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -32,6 +32,18 @@ public class Settings {
|
|||||||
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
|
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 FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
|
||||||
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
|
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 HOOK_WORLDGUARD_PATH = "worldguard";
|
||||||
|
private static final String HOOK_WG_MOVE_CHECK_PATH = "player_move_check";
|
||||||
|
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
|
||||||
|
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
|
||||||
|
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||||
|
private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
|
||||||
|
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
|
||||||
|
private static final String COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH = "leggings-add-enchantments";
|
||||||
|
private static final String COSMETIC_ADD_ENCHANTS_BOOTS_PATH = "boots-add-enchantments";
|
||||||
|
|
||||||
private static String defaultMenu;
|
private static String defaultMenu;
|
||||||
private static String dyeMenuName;
|
private static String dyeMenuName;
|
||||||
@@ -46,6 +58,15 @@ public class Settings {
|
|||||||
private static boolean debugMode;
|
private static boolean debugMode;
|
||||||
private static boolean unapplyOnDeath;
|
private static boolean unapplyOnDeath;
|
||||||
private static boolean forcePermissionJoin;
|
private static boolean forcePermissionJoin;
|
||||||
|
private static boolean itemsAdderChangeReload;
|
||||||
|
private static boolean worldGuardMoveCheck;
|
||||||
|
private static boolean cosmeticEmoteBlockCheck;
|
||||||
|
private static boolean addHelmetEnchants;
|
||||||
|
private static boolean addChestplateEnchants;
|
||||||
|
private static boolean addLeggingEnchants;
|
||||||
|
private static boolean addBootsEnchants;
|
||||||
|
private static boolean emoteDamageLeave;
|
||||||
|
private static boolean emoteInvincible;
|
||||||
private static int lookDownPitch;
|
private static int lookDownPitch;
|
||||||
private static int viewDistance;
|
private static int viewDistance;
|
||||||
private static int tickPeriod;
|
private static int tickPeriod;
|
||||||
@@ -77,6 +98,13 @@ public class Settings {
|
|||||||
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
||||||
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
||||||
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
||||||
|
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
|
||||||
|
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
|
||||||
|
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
|
||||||
|
addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false);
|
||||||
|
addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false);
|
||||||
|
addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false);
|
||||||
|
addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false);
|
||||||
|
|
||||||
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
||||||
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
|
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
|
||||||
@@ -91,6 +119,13 @@ public class Settings {
|
|||||||
dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu");
|
dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu");
|
||||||
dyeMenuInputSlot = dyeMenuSettings.node(DYE_MENU_INPUT_SLOT).getInt(19);
|
dyeMenuInputSlot = dyeMenuSettings.node(DYE_MENU_INPUT_SLOT).getInt(19);
|
||||||
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
|
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);
|
||||||
|
|
||||||
|
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
|
||||||
|
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector loadVector(final ConfigurationNode config) {
|
private static Vector loadVector(final ConfigurationNode config) {
|
||||||
@@ -190,6 +225,9 @@ public class Settings {
|
|||||||
public static boolean isDebugEnabled() {
|
public static boolean isDebugEnabled() {
|
||||||
return debugMode;
|
return debugMode;
|
||||||
}
|
}
|
||||||
|
public static boolean getItemsAdderReloadChange() {
|
||||||
|
return itemsAdderChangeReload;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getTickPeriod() {
|
public static int getTickPeriod() {
|
||||||
return tickPeriod;
|
return tickPeriod;
|
||||||
@@ -208,6 +246,43 @@ public class Settings {
|
|||||||
public static double getEmoteDistance() {
|
public static double getEmoteDistance() {
|
||||||
return emoteDistance;
|
return emoteDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getCosmeticEmoteBlockCheck() {
|
||||||
|
return cosmeticEmoteBlockCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmoteDamageLeave() {
|
||||||
|
return emoteDamageLeave;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmoteInvincible() {
|
||||||
|
return emoteInvincible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWorldGuardMoveCheckEnabled() {
|
||||||
|
return worldGuardMoveCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
|
||||||
|
switch (slot) {
|
||||||
|
case HEAD -> {
|
||||||
|
return addHelmetEnchants;
|
||||||
|
}
|
||||||
|
case CHEST -> {
|
||||||
|
return addChestplateEnchants;
|
||||||
|
}
|
||||||
|
case LEGS -> {
|
||||||
|
return addLeggingEnchants;
|
||||||
|
}
|
||||||
|
case FEET -> {
|
||||||
|
return addBootsEnchants;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setDebugMode(boolean newSetting) {
|
public static void setDebugMode(boolean newSetting) {
|
||||||
debugMode = newSetting;
|
debugMode = newSetting;
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class WardrobeSettings {
|
|||||||
|
|
||||||
public static boolean inDistanceOfStatic(final Location location) {
|
public static boolean inDistanceOfStatic(final Location location) {
|
||||||
if (wardrobeLocation == null) return false;
|
if (wardrobeLocation == null) return false;
|
||||||
if (staticRadius == -1) return false;
|
if (staticRadius == -1) return true;
|
||||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||||
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Cosmetic {
|
public abstract class Cosmetic {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String permission;
|
private String permission;
|
||||||
@@ -19,8 +20,9 @@ public class Cosmetic {
|
|||||||
private CosmeticSlot slot;
|
private CosmeticSlot slot;
|
||||||
private boolean dyable;
|
private boolean dyable;
|
||||||
|
|
||||||
protected Cosmetic(String id, ConfigurationNode config) {
|
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (!config.node("permission").virtual()) {
|
if (!config.node("permission").virtual()) {
|
||||||
this.permission = config.node("permission").getString();
|
this.permission = config.node("permission").getString();
|
||||||
} else {
|
} else {
|
||||||
@@ -30,20 +32,20 @@ public class Cosmetic {
|
|||||||
if (!config.node("item").virtual()) this.item = generateItemStack(config.node("item"));
|
if (!config.node("item").virtual()) this.item = generateItemStack(config.node("item"));
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
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));
|
setDyable(config.node("dyeable").getBoolean(false));
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
||||||
|
|
||||||
Cosmetics.addCosmetic(this);
|
Cosmetics.addCosmetic(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
public String getPermission() {
|
|
||||||
return this.permission;
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticSlot getSlot() {
|
public CosmeticSlot getSlot() {
|
||||||
@@ -53,17 +55,17 @@ public class Cosmetic {
|
|||||||
public void setSlot(CosmeticSlot slot) {
|
public void setSlot(CosmeticSlot slot) {
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return this.permission;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPermission(String permission) {
|
public void setPermission(String permission) {
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresPermission() {
|
public boolean requiresPermission() {
|
||||||
if (permission == null) return false;
|
return permission != null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDyable(boolean dyable) {
|
public void setDyable(boolean dyable) {
|
||||||
@@ -74,10 +76,7 @@ public class Cosmetic {
|
|||||||
return this.dyable;
|
return this.dyable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void update(CosmeticUser user);
|
||||||
public void update(CosmeticUser user) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
@@ -17,7 +20,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class Cosmetics {
|
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) {
|
public static void addCosmetic(Cosmetic cosmetic) {
|
||||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||||
@@ -31,14 +34,19 @@ public class Cosmetics {
|
|||||||
COSMETICS.remove(cosmetic);
|
COSMETICS.remove(cosmetic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Cosmetic getCosmetic(String id) {
|
public static Cosmetic getCosmetic(String id) {
|
||||||
return COSMETICS.get(id);
|
return COSMETICS.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Set<Cosmetic> values() {
|
public static Set<Cosmetic> values() {
|
||||||
return COSMETICS.values();
|
return COSMETICS.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Set<String> keys() {
|
public static Set<String> keys() {
|
||||||
return COSMETICS.keySet();
|
return COSMETICS.keySet();
|
||||||
}
|
}
|
||||||
@@ -76,7 +84,7 @@ public class Cosmetics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupCosmetics(CommentedConfigurationNode config) {
|
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
|
||||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
||||||
try {
|
try {
|
||||||
String id = cosmeticConfig.key().toString();
|
String id = cosmeticConfig.key().toString();
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class CosmeticArmorType extends Cosmetic {
|
public class CosmeticArmorType extends Cosmetic {
|
||||||
|
|
||||||
private EquipmentSlot equipSlot;
|
private final EquipmentSlot equipSlot;
|
||||||
|
|
||||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
@@ -20,18 +25,23 @@ public class CosmeticArmorType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
|
||||||
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
|
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
|
||||||
if (!player.getInventory().getItemInOffHand().getType().isAir()) return;
|
if (!player.getInventory().getItemInOffHand().getType().isAir()) return;
|
||||||
}
|
}
|
||||||
PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation()));
|
ItemStack equippedItem = player.getInventory().getItem(equipSlot);
|
||||||
|
if (Settings.getShouldAddEnchants(equipSlot)) {
|
||||||
|
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||||
|
}
|
||||||
|
|
||||||
|
NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(player.getLocation()));
|
||||||
|
//PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method
|
||||||
}
|
}
|
||||||
|
|
||||||
public EquipmentSlot getEquipSlot() {
|
public EquipmentSlot getEquipSlot() {
|
||||||
return this.equipSlot;
|
return this.equipSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,43 +2,65 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CosmeticBackpackType extends Cosmetic {
|
public class CosmeticBackpackType extends Cosmetic {
|
||||||
|
|
||||||
private String modelName;
|
private final String modelName;
|
||||||
private ConfigurationNode config;
|
private UserBackpackManager.BackpackType backpackType;
|
||||||
|
|
||||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
|
|
||||||
this.config = config;
|
|
||||||
modelName = config.node("model").getString();
|
modelName = config.node("model").getString();
|
||||||
|
backpackType = UserBackpackManager.BackpackType.valueOf(config.node("type").getString("NORMAL").toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
Location loc = player.getLocation().clone().add(0, 2, 0);
|
Location loc = player.getLocation().clone().add(0, 2, 0);
|
||||||
|
|
||||||
if (user.isInWardrobe() || !user.isBackupSpawned()) return;
|
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||||
if (loc.getWorld() != user.getUserBackpackManager().getArmorstand().getWorld()) {
|
if (!user.getUserBackpackManager().getArmorStand().isValid()) {
|
||||||
user.getUserBackpackManager().getArmorstand().teleport(loc);
|
MessagesUtil.sendDebugMessages("Invalid Backpack detected! Respawning backpack, report this on the discord if this happens often!", Level.WARNING);
|
||||||
|
user.respawnBackpack();
|
||||||
|
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();
|
user.getUserBackpackManager().showBackpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModelName() {
|
public String getModelName() {
|
||||||
return modelName;
|
return modelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserBackpackManager.BackpackType getBackpackType() {
|
||||||
|
return backpackType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -16,9 +17,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CosmeticBalloonType extends Cosmetic {
|
public class CosmeticBalloonType extends Cosmetic {
|
||||||
|
|
||||||
private String modelName;
|
private final String modelName;
|
||||||
private List<String> dyableParts;
|
private List<String> dyableParts;
|
||||||
//private HashMap<Animations, String> animationBalloons;
|
|
||||||
|
|
||||||
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
@@ -26,17 +26,9 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
String modelId = config.node("model").getString();
|
String modelId = config.node("model").getString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!config.node("dyable-parts").virtual()) dyableParts = config.node("dyable-parts").getList(String.class);
|
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());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
// Seriously?
|
// Seriously?
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -46,12 +38,19 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
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;
|
if (user.isInWardrobe()) return;
|
||||||
|
|
||||||
|
if (!userBalloonManager.getModelEntity().isValid()) {
|
||||||
|
user.respawnBalloon();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location newLocation = player.getLocation();
|
||||||
Location currentLocation = user.getBalloonManager().getLocation();
|
Location currentLocation = user.getBalloonManager().getLocation();
|
||||||
newLocation = newLocation.clone().add(Settings.getBalloonOffset());
|
newLocation = newLocation.clone().add(Settings.getBalloonOffset());
|
||||||
|
|
||||||
@@ -86,10 +85,4 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
if (dyableParts.isEmpty()) return true;
|
if (dyableParts.isEmpty()) return true;
|
||||||
return dyableParts.contains(name);
|
return dyableParts.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public String getAnimation(Animations animation) {
|
|
||||||
return animationBalloons.get(animation);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class CosmeticEmoteType extends Cosmetic {
|
public class CosmeticEmoteType extends Cosmetic {
|
||||||
|
|
||||||
private String animationId;
|
private final String animationId;
|
||||||
|
|
||||||
public CosmeticEmoteType(String id, ConfigurationNode config) {
|
public CosmeticEmoteType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
@@ -21,7 +22,7 @@ public class CosmeticEmoteType extends Cosmetic {
|
|||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(CosmeticUser user) {
|
public void run(@NotNull CosmeticUser user) {
|
||||||
user.getUserEmoteManager().playEmote(this);
|
user.getUserEmoteManager().playEmote(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class CosmeticMainhandType extends Cosmetic {
|
public class CosmeticMainhandType extends Cosmetic {
|
||||||
@@ -14,10 +15,9 @@ public class CosmeticMainhandType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,23 +16,23 @@ public class Database {
|
|||||||
|
|
||||||
private static Data data;
|
private static Data data;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static InternalData INTERNAL_DATA = new InternalData();
|
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() {
|
public Database() {
|
||||||
String databaseType = DatabaseSettings.getDatabaseType();
|
String databaseType = DatabaseSettings.getDatabaseType();
|
||||||
data = INTERNAL_DATA; // default
|
data = SQLITE_DATA; // default
|
||||||
if (databaseType.equalsIgnoreCase("INTERNAL")) {
|
|
||||||
data = INTERNAL_DATA;
|
|
||||||
}
|
|
||||||
if (databaseType.equalsIgnoreCase("MySQL")) {
|
if (databaseType.equalsIgnoreCase("MySQL")) {
|
||||||
data = MYSQL_DATA;
|
data = MYSQL_DATA;
|
||||||
}
|
}
|
||||||
|
/* SQLite is the default database. Might change in the future, so keep code here in case.
|
||||||
if (databaseType.equalsIgnoreCase("sqlite")) {
|
if (databaseType.equalsIgnoreCase("sqlite")) {
|
||||||
data = SQLITE_DATA;
|
data = SQLITE_DATA;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
MessagesUtil.sendDebugMessages("Database is " + data);
|
MessagesUtil.sendDebugMessages("Database is " + data);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
@@ -10,40 +10,34 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Data {
|
public abstract class Data {
|
||||||
|
|
||||||
public void setup() {
|
public abstract void setup();
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(CosmeticUser user) {
|
public abstract void save(CosmeticUser user);
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public abstract CosmeticUser get(UUID uniqueId);
|
||||||
// Override
|
|
||||||
return null;
|
public abstract void clear(UUID uniqueId);
|
||||||
}
|
|
||||||
|
|
||||||
public void clear(UUID uniqueId) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
|
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
|
||||||
public String steralizeData(CosmeticUser user) {
|
@NotNull
|
||||||
|
public final String serializeData(@NotNull CosmeticUser user) {
|
||||||
String data = "";
|
String data = "";
|
||||||
if (user.getHidden()) {
|
if (user.getHidden()) {
|
||||||
if (shouldHiddenSave(user.getHiddenReason())) {
|
if (shouldHiddenSave(user.getHiddenReason())) {
|
||||||
data = "HIDDEN=" + user.getHiddenReason();
|
data = "HIDDEN=" + user.getHiddenReason();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
Color color = user.getCosmeticColor(cosmetic.getSlot());
|
Color color = user.getCosmeticColor(cosmetic.getSlot());
|
||||||
String input = cosmetic.getSlot() + "=" + cosmetic.getId();
|
String input = cosmetic.getSlot() + "=" + cosmetic.getId();
|
||||||
if (color != null) input = input + "&" + color.asRGB();
|
if (color != null) input = input + "&" + color.asRGB();
|
||||||
@@ -56,7 +50,8 @@ public class Data {
|
|||||||
return 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<>();
|
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
|
||||||
boolean checkPermission = Settings.getForcePermissionJoin();
|
boolean checkPermission = Settings.getForcePermissionJoin();
|
||||||
|
|
||||||
@@ -102,7 +97,7 @@ public class Data {
|
|||||||
return cosmetics;
|
return cosmetics;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
|
private boolean shouldHiddenSave(CosmeticUser.@NotNull HiddenReason reason) {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case EMOTE, NONE -> {
|
case EMOTE, NONE -> {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.bukkit.persistence.PersistentDataType;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class InternalData extends Data {
|
public class InternalData extends Data {
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
|
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
|
||||||
@@ -27,7 +28,7 @@ public class InternalData extends Data {
|
|||||||
public void save(CosmeticUser user) {
|
public void save(CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
|
|
||||||
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, steralizeData(user));
|
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, serializeData(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +39,7 @@ public class InternalData extends Data {
|
|||||||
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
|
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
|
||||||
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
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 (Map<Cosmetic, Color> cosmeticColors : a.values()) {
|
||||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
|||||||
@@ -2,18 +2,15 @@ package com.hibiscusmc.hmccosmetics.database.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
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.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MySQLData extends Data {
|
public class MySQLData extends SQLData {
|
||||||
|
|
||||||
// Connection Information
|
// Connection Information
|
||||||
private String host;
|
private String host;
|
||||||
@@ -22,6 +19,7 @@ public class MySQLData extends Data {
|
|||||||
private String password;
|
private String password;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,11 +33,12 @@ public class MySQLData extends Data {
|
|||||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||||
"(UUID varchar(36) PRIMARY KEY, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");").execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
|
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
|
||||||
@@ -52,104 +51,58 @@ public class MySQLData extends Data {
|
|||||||
throw new RuntimeException(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
|
@Override
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public void clear(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) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||||
preparedSt.setString(1, unqiueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
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
|
// Connection isn't null AND Connection isn't closed :: return
|
||||||
if (connection != null) {
|
try {
|
||||||
close();
|
if (isConnectionOpen()) {
|
||||||
|
return;
|
||||||
|
} else if (connection != null) close(); // Close connection if still active
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace(); // If isConnectionOpen() throws error
|
||||||
}
|
}
|
||||||
|
|
||||||
//connect to database host
|
// Connect to database host
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//});
|
|
||||||
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private Properties setupProperties() {
|
private Properties setupProperties() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("user", user);
|
props.put("user", user);
|
||||||
@@ -158,28 +111,29 @@ public class MySQLData extends Data {
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectionOpen() {
|
private boolean isConnectionOpen() throws RuntimeException {
|
||||||
try {
|
try {
|
||||||
if (connection == null || connection.isClosed()) {
|
return connection != null && !connection.isClosed();
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
|
||||||
if (!isConnectionOpen()) {
|
if (!isConnectionOpen()) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -1,31 +1,28 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.database.types;
|
package com.hibiscusmc.hmccosmetics.database.types;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
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 com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SQLiteData extends Data {
|
public class SQLiteData extends SQLData {
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
||||||
|
boolean exists = dataFolder.exists();
|
||||||
|
|
||||||
if (!dataFolder.exists()){
|
if (!exists) {
|
||||||
try {
|
try {
|
||||||
dataFolder.createNewFile();
|
boolean created = dataFolder.createNewFile();
|
||||||
|
if (!created) throw new IOException("File didn't exist but now does");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
MessagesUtil.sendDebugMessages("File write error. Database will not work properly", Level.SEVERE);
|
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, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");").execute();
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(CosmeticUser user) {
|
@SuppressWarnings("resource")
|
||||||
Runnable run = () -> {
|
public void clear(UUID uniqueId) {
|
||||||
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) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||||
preparedSt.setString(1, unqiueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -106,56 +55,47 @@ public class SQLiteData extends Data {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
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 && !connection.isClosed()) return;
|
||||||
if (connection != null) {
|
|
||||||
//close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Close Connection if still active
|
||||||
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
||||||
|
|
||||||
//connect to database host
|
// Connect to database host
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
|
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//});
|
|
||||||
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
if (!isConnectionOpen()) {
|
if (!isConnectionOpen()) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectionOpen() {
|
private boolean isConnectionOpen() {
|
||||||
try {
|
try {
|
||||||
if (connection == null || connection.isClosed()) {
|
return connection != null && !connection.isClosed();
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -25,13 +27,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Menu {
|
public class Menu {
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
private String title;
|
private final String title;
|
||||||
private int rows;
|
private final int rows;
|
||||||
private ConfigurationNode config;
|
private final ConfigurationNode config;
|
||||||
private String permissionNode;
|
private final String permissionNode;
|
||||||
|
|
||||||
public Menu(String id, ConfigurationNode config) {
|
public Menu(String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
@@ -58,7 +60,7 @@ public class Menu {
|
|||||||
openMenu(user, false);
|
openMenu(user, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openMenu(CosmeticUser user, boolean ignorePermission) {
|
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
if (!ignorePermission && !permissionNode.isEmpty()) {
|
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();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
||||||
@@ -164,7 +167,8 @@ public class Menu {
|
|||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getSlots(List<String> slotString) {
|
@NotNull
|
||||||
|
private List<Integer> getSlots(@NotNull List<String> slotString) {
|
||||||
List<Integer> slots = new ArrayList<>();
|
List<Integer> slots = new ArrayList<>();
|
||||||
|
|
||||||
for (String a : slotString) {
|
for (String a : slotString) {
|
||||||
@@ -181,6 +185,7 @@ public class Menu {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private List<Integer> getSlots(int small, int max) {
|
private List<Integer> getSlots(int small, int max) {
|
||||||
List<Integer> slots = new ArrayList<>();
|
List<Integer> slots = new ArrayList<>();
|
||||||
|
|
||||||
@@ -188,7 +193,9 @@ public class Menu {
|
|||||||
return slots;
|
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()) {
|
if (itemStack.hasItemMeta()) {
|
||||||
itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
|
itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
|
||||||
}
|
}
|
||||||
@@ -201,7 +208,6 @@ public class Menu {
|
|||||||
|
|
||||||
public boolean canOpen(Player player) {
|
public boolean canOpen(Player player) {
|
||||||
if (permissionNode.isEmpty()) return true;
|
if (permissionNode.isEmpty()) return true;
|
||||||
if (player.isOp() || player.hasPermission(permissionNode)) return true;
|
return player.isOp() || player.hasPermission(permissionNode);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
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.CommentedConfigurationNode;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
@@ -17,21 +19,23 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class Menus {
|
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) {
|
public static void addMenu(Menu menu) {
|
||||||
MENUS.put(menu.getId().toUpperCase(), 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());
|
return MENUS.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Collection<Menu> getMenu() {
|
public static Collection<Menu> getMenu() {
|
||||||
return MENUS.values();
|
return MENUS.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMenu(String id) {
|
public static boolean hasMenu(@NotNull String id) {
|
||||||
return MENUS.containsKey(id.toUpperCase());
|
return MENUS.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ public class Menus {
|
|||||||
|
|
||||||
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static List<String> getMenuNames() {
|
public static List<String> getMenuNames() {
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
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();
|
this.id = id.toUpperCase();
|
||||||
Actions.addAction(this);
|
Actions.addAction(this);
|
||||||
}
|
}
|
||||||
@@ -15,7 +16,5 @@ public class Action {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(CosmeticUser user, String raw) {
|
public abstract void run(CosmeticUser user, String raw);
|
||||||
// Override
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,34 +4,36 @@ import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
|
|||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Actions {
|
public class Actions {
|
||||||
|
|
||||||
private static HashMap<String, Action> actions = new HashMap<>();
|
private static final HashMap<String, Action> actions = new HashMap<>();
|
||||||
|
|
||||||
// [ID]
|
// [ID]
|
||||||
private static ActionMessage ACTION_MESSAGE = new ActionMessage();
|
private static final ActionMessage ACTION_MESSAGE = new ActionMessage();
|
||||||
private static ActionMenu ACTION_MENU = new ActionMenu();
|
private static final ActionMenu ACTION_MENU = new ActionMenu();
|
||||||
private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
|
private static final ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
|
||||||
private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
|
private static final ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
|
||||||
private static ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
|
private static final ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
|
||||||
private static ActionSound ACTION_SOUND = new ActionSound();
|
private static final ActionSound ACTION_SOUND = new ActionSound();
|
||||||
private static ActionEquip ACTION_EQUIP = new ActionEquip();
|
private static final ActionEquip ACTION_EQUIP = new ActionEquip();
|
||||||
private static ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
|
private static final ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
|
||||||
private static ActionParticle ACTION_PARTICLE = new ActionParticle();
|
private static final ActionParticle ACTION_PARTICLE = new ActionParticle();
|
||||||
private static ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
|
private static final ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
|
||||||
private static ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
||||||
private static ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
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());
|
return actions.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAction(String id) {
|
public static boolean isAction(@NotNull String id) {
|
||||||
return actions.containsKey(id.toUpperCase());
|
return actions.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ public class Actions {
|
|||||||
actions.put(action.getId().toUpperCase(), action);
|
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) {
|
for (String a : raw) {
|
||||||
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
||||||
String message = StringUtils.substringAfter(a, "] ");
|
String message = StringUtils.substringAfter(a, "] ");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCloseMenu extends Action {
|
public class ActionCloseMenu extends Action {
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ public class ActionCloseMenu extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
user.getPlayer().closeInventory();
|
user.getPlayer().closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionConsoleCommand extends Action {
|
public class ActionConsoleCommand extends Action {
|
||||||
|
|
||||||
@@ -11,8 +12,7 @@ public class ActionConsoleCommand extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
|
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticHide extends Action {
|
public class ActionCosmeticHide extends Action {
|
||||||
|
|
||||||
@@ -10,10 +11,8 @@ public class ActionCosmeticHide extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
if (!user.getHidden()) {
|
if (user.getHidden()) return;
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticShow extends Action {
|
public class ActionCosmeticShow extends Action {
|
||||||
|
|
||||||
@@ -10,10 +11,11 @@ public class ActionCosmeticShow extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
if (user.getHidden()) {
|
if (!user.getHidden()) return;
|
||||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return; // Do not hide if its already off for WG
|
|
||||||
|
// Do not hide if it's already off for WG
|
||||||
|
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||||
user.showCosmetics();
|
user.showCosmetics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticToggle extends Action {
|
public class ActionCosmeticToggle extends Action {
|
||||||
|
|
||||||
@@ -10,13 +11,13 @@ public class ActionCosmeticToggle extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
if (user.getHidden()) {
|
if (user.getHidden()) {
|
||||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||||
user.showCosmetics();
|
user.showCosmetics();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ public class ActionEquip extends Action {
|
|||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(CosmeticUser user, String raw) {
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
||||||
if (cosmetic == null) {
|
if (cosmetic == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
user.addPlayerCosmetic(cosmetic);
|
user.addPlayerCosmetic(cosmetic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import com.hibiscusmc.hmccosmetics.gui.Menu;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ActionMenu extends Action {
|
public class ActionMenu extends Action {
|
||||||
|
|
||||||
@@ -22,12 +25,14 @@ public class ActionMenu extends Action {
|
|||||||
raw = raw.replaceAll("-o", "");
|
raw = raw.replaceAll("-o", "");
|
||||||
ignorePermission = true;
|
ignorePermission = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Menus.hasMenu(raw)) {
|
if (!Menus.hasMenu(raw)) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Invalid Action Menu -> " + raw);
|
MessagesUtil.sendDebugMessages("Invalid Action Menu -> " + raw, Level.WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu = Menus.getMenu(raw);
|
Menu menu = Menus.getMenu(raw);
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info(raw + " | " + ignorePermission);
|
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
|
||||||
menu.openMenu(user, ignorePermission);
|
menu.openMenu(user, ignorePermission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionMessage extends Action {
|
public class ActionMessage extends Action {
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class ActionMessage extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
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.BlockDataParticle;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
|
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.type.ParticleType;
|
||||||
import com.owen1212055.particlehelper.api.type.Particles;
|
import com.owen1212055.particlehelper.api.type.Particles;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionParticle extends Action {
|
public class ActionParticle extends Action {
|
||||||
|
|
||||||
@@ -22,17 +23,17 @@ public class ActionParticle extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
public void run(CosmeticUser user, @NotNull String raw) {
|
||||||
String[] rawString = raw.split(" ");
|
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) {
|
if (particleType == null) {
|
||||||
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
|
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean multi = false;
|
|
||||||
if (particleType.multi() != null) {
|
// particleType.multi() should never be null, but particleType can be.
|
||||||
multi = true; // Should work?
|
boolean multi = particleType.multi() != null;
|
||||||
}
|
|
||||||
|
|
||||||
var particle = multi ? particleType.multi() : particleType.single();
|
var particle = multi ? particleType.multi() : particleType.single();
|
||||||
if (particle instanceof DestinationParticle || particle instanceof BlockDataParticle
|
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!");
|
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " is not supported by this action!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
particle = ServerUtils.addParticleValues(particle, rawString);
|
particle = ServerUtils.addParticleValues(particle, rawString);
|
||||||
Location location = user.getPlayer().getLocation();
|
Location location = user.getPlayer().getLocation();
|
||||||
for (Player player : PacketManager.getViewers(location)) {
|
for (Player player : PacketManager.getViewers(location)) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionPlayerCommand extends Action {
|
public class ActionPlayerCommand extends Action {
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class ActionPlayerCommand extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
|
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
|||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ public class ActionSound extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
String[] processedString = raw.split(" ");
|
String[] processedString = raw.split(" ");
|
||||||
|
|
||||||
@@ -24,11 +25,11 @@ public class ActionSound extends Action {
|
|||||||
float pitch = 1;
|
float pitch = 1;
|
||||||
|
|
||||||
if (processedString.length > 2) {
|
if (processedString.length > 2) {
|
||||||
volume = Float.valueOf(processedString[1]);
|
volume = Float.parseFloat(processedString[1]);
|
||||||
pitch = Float.valueOf(processedString[2]);
|
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);
|
player.playSound(player.getLocation(), soundName, volume, pitch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ public class ActionUnequip extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(CosmeticUser user, String raw) {
|
||||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) {
|
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||||
user.removeCosmeticSlot(slot);
|
user.removeCosmeticSlot(slot);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccolor.gui.guis.GuiItem;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
||||||
import org.bukkit.Bukkit;
|
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.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class DyeMenu {
|
public class DyeMenu {
|
||||||
|
|
||||||
// Yes, I do know how tacted on this feels.
|
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
if (player == null) return;
|
||||||
public static void openMenu(CosmeticUser user, Cosmetic cosmetic) {
|
if (!Hooks.isActiveHook("HMCColor")) {
|
||||||
|
addCosmetic(user, cosmetic, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
||||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
if (originalItem == null || !cosmetic.isDyable()) return;
|
||||||
|
|
||||||
Player player = user.getPlayer();
|
|
||||||
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
||||||
gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName()));
|
gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName()));
|
||||||
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
||||||
@@ -43,13 +47,7 @@ public class DyeMenu {
|
|||||||
meta instanceof MapMeta mapMeta ? mapMeta.getColor() : null;
|
meta instanceof MapMeta mapMeta ? mapMeta.getColor() : null;
|
||||||
if (color == null) return;
|
if (color == null) return;
|
||||||
|
|
||||||
//user.removeCosmeticSlot(cosmetic);
|
addCosmetic(user, cosmetic, color);
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
|
||||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
player.closeInventory();
|
|
||||||
user.updateCosmetic(cosmetic.getSlot());
|
|
||||||
}, 2);
|
|
||||||
} else event.setCancelled(true);
|
} else event.setCancelled(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -57,4 +55,14 @@ public class DyeMenu {
|
|||||||
gui.setCloseGuiAction(event -> {});
|
gui.setCloseGuiAction(event -> {});
|
||||||
gui.open(player);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class Type {
|
public abstract class Type {
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
|
|
||||||
public Type(String id) {
|
public Type(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -21,12 +21,8 @@ public class Type {
|
|||||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||||
run(user, config, null);
|
run(user, config, null);
|
||||||
}
|
}
|
||||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
|
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
|
||||||
//TODO: Finish this
|
|
||||||
return null; // Override
|
public abstract ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.TypeCosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeEmpty;
|
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeEmpty;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Types {
|
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 TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||||
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
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());
|
return types.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isType(String id) {
|
public static boolean isType(@NotNull String id) {
|
||||||
return types.containsKey(id.toUpperCase());
|
return types.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
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.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -31,17 +34,18 @@ public class TypeCosmetic extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
if (config.node("cosmetic").virtual()) return;
|
||||||
String cosmeticName = config.node("cosmetic").getString();
|
String cosmeticName = config.node("cosmetic").getString();
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||||
|
Player player = user.getPlayer();
|
||||||
if (cosmetic == null) {
|
if (cosmetic == null) {
|
||||||
MessagesUtil.sendMessage(user.getPlayer(), "invalid-cosmetic");
|
MessagesUtil.sendMessage(player, "invalid-cosmetic");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.canEquipCosmetic(cosmetic)) {
|
if (!user.canEquipCosmetic(cosmetic)) {
|
||||||
MessagesUtil.sendMessage(user.getPlayer(), "no-cosmetic-permission");
|
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +96,7 @@ public class TypeCosmetic extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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<>();
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
if (config.node("cosmetic").virtual()) return processLoreLines(user, itemMeta);;
|
if (config.node("cosmetic").virtual()) return processLoreLines(user, itemMeta);;
|
||||||
@@ -143,7 +147,10 @@ public class TypeCosmetic extends Type {
|
|||||||
return itemMeta;
|
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<>();
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
if (itemMeta.hasLore()) {
|
if (itemMeta.hasLore()) {
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -17,7 +17,6 @@ import java.util.List;
|
|||||||
public class TypeEmpty extends Type {
|
public class TypeEmpty extends Type {
|
||||||
|
|
||||||
// This can be used as an example for making your own types.
|
// This can be used as an example for making your own types.
|
||||||
|
|
||||||
public TypeEmpty() {
|
public TypeEmpty() {
|
||||||
super("empty");
|
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.
|
// 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.
|
// This is the code that's run when the item is clicked.
|
||||||
@Override
|
@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.
|
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.
|
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
|
||||||
|
|
||||||
@@ -33,7 +32,7 @@ public class TypeEmpty extends Type {
|
|||||||
try {
|
try {
|
||||||
// This gets the actions with the item. We can add more, such as with the Cosmetic type, an equip and unequip action set.
|
// 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
|
// 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 (!actionConfig.node("any").virtual()) actionStrings.addAll(actionConfig.node("any").getList(String.class));
|
||||||
|
|
||||||
if (clickType != null) {
|
if (clickType != null) {
|
||||||
@@ -53,7 +52,8 @@ public class TypeEmpty extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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<>();
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
if (itemMeta.hasLore()) {
|
if (itemMeta.hasLore()) {
|
||||||
|
|||||||
@@ -2,45 +2,92 @@ package com.hibiscusmc.hmccosmetics.hooks;
|
|||||||
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class Hook implements Listener {
|
/**
|
||||||
|
* Represents a hook into other minecraft plugins
|
||||||
|
*/
|
||||||
|
public abstract class Hook implements Listener {
|
||||||
|
private final String id;
|
||||||
|
private boolean active = false;
|
||||||
|
private boolean itemHook = false;
|
||||||
|
|
||||||
private String id;
|
public Hook(@NotNull String id) {
|
||||||
private boolean active;
|
|
||||||
private boolean itemHook;
|
|
||||||
|
|
||||||
public Hook(String id) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
active = false;
|
|
||||||
Hooks.addHook(this);
|
Hooks.addHook(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
/**
|
||||||
// Override
|
* Loads this hook
|
||||||
}
|
*
|
||||||
|
* @implNote By default, this method does nothing. It should be overridden by child classes to implement any necessary loading logic
|
||||||
|
*/
|
||||||
|
public void load() { }
|
||||||
|
|
||||||
public ItemStack getItem(String itemid) {
|
/**
|
||||||
|
* Gets an {@link ItemStack} that is associated with the provided id from the hooked plugin
|
||||||
|
* @param itemId The id of the {@link ItemStack}
|
||||||
|
* @return The {@link ItemStack} with the id provided. If an invalid id was provided or if the hook doesn't have any related {@link ItemStack}s then this will return null
|
||||||
|
* @implNote By default, this method returns null. It should be overridden by child classes if you will to have your hook return a related {@link ItemStack}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
return null;
|
return null;
|
||||||
// Override
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
/**
|
||||||
|
* Gets the id of this hook
|
||||||
|
*
|
||||||
|
* @return The unique id for this hook
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActive(boolean active) {
|
/**
|
||||||
this.active = active;
|
* Gets whether this hook has been activated
|
||||||
}
|
* @return true if this hook is active, false otherwise
|
||||||
|
* @deprecated As of release 2.2.5+, replaced by {@link #isActive()}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public boolean getActive() {
|
public boolean getActive() {
|
||||||
return this.active;
|
return this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabledItemHook(boolean enabled) {
|
/**
|
||||||
itemHook = enabled;
|
* Gets whether this hook has been activated
|
||||||
|
* @return true if this hook is active, false otherwise
|
||||||
|
* @since 2.2.5
|
||||||
|
*/
|
||||||
|
public final boolean isActive() {
|
||||||
|
return this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEnabledItemHook() {
|
/**
|
||||||
|
* Sets whether this hook is active
|
||||||
|
* @param active true to activate the hook, false otherwise
|
||||||
|
*/
|
||||||
|
public final void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the method {@link #getItem(String)} should return a non-null value
|
||||||
|
* @return true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||||
|
*
|
||||||
|
* @apiNote Even though this method returns true does not mean that {@link #getItem(String)} won't return null, rather if this returns false then {@link #getItem(String)} should return false everytime
|
||||||
|
*/
|
||||||
|
public final boolean hasEnabledItemHook() {
|
||||||
return itemHook;
|
return itemHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the method {@link #getItem(String)} should return a non-null value
|
||||||
|
* @param enabled true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||||
|
*/
|
||||||
|
public final void setEnabledItemHook(boolean enabled) {
|
||||||
|
itemHook = enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,22 @@ package com.hibiscusmc.hmccosmetics.hooks;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.items.*;
|
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.HookPremiumVanish;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.misc.HookSuperVanish;
|
import com.hibiscusmc.hmccosmetics.hooks.misc.HookSuperVanish;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
|
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Hooks {
|
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 HookOraxen ORAXEN_HOOK = new HookOraxen();
|
||||||
private static HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
|
private static HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
|
||||||
private static HookLooty LOOTY_HOOK = new HookLooty();
|
private static HookLooty LOOTY_HOOK = new HookLooty();
|
||||||
@@ -22,12 +26,14 @@ public class Hooks {
|
|||||||
private static HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
|
private static HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
|
||||||
private static HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
private static HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||||
private static HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
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());
|
return hooks.get(id.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isItemHook(String id) {
|
public static boolean isItemHook(@NotNull String id) {
|
||||||
return hooks.containsKey(id.toLowerCase());
|
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(":")) {
|
if (!raw.contains(":")) {
|
||||||
Material mat = Material.getMaterial(raw.toUpperCase());
|
Material mat = Material.getMaterial(raw.toUpperCase());
|
||||||
if (mat == null) return null;
|
if (mat == null) return null;
|
||||||
@@ -60,14 +67,13 @@ public class Hooks {
|
|||||||
if (!isItemHook(split[0])) return null;
|
if (!isItemHook(split[0])) return null;
|
||||||
Hook hook = getHook(split[0]);
|
Hook hook = getHook(split[0]);
|
||||||
if (!hook.hasEnabledItemHook()) return null;
|
if (!hook.hasEnabledItemHook()) return null;
|
||||||
if (!hook.getActive()) return null;
|
if (!hook.isActive()) return null;
|
||||||
ItemStack item = hook.getItem(split[1]);
|
return hook.getItem(split[1]);
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isActiveHook(String id) {
|
public static boolean isActiveHook(String id) {
|
||||||
Hook hook = getHook(id);
|
Hook hook = getHook(id);
|
||||||
if (hook == null) return false;
|
if (hook == null) return false;
|
||||||
return hook.getActive();
|
return hook.isActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,24 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookHMCCosmetics extends Hook implements Listener {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin HMCCosmetics} to provide cosmetic items
|
||||||
|
*/
|
||||||
|
public class HookHMCCosmetics extends Hook {
|
||||||
public HookHMCCosmetics() {
|
public HookHMCCosmetics() {
|
||||||
super("HMCCosmetics");
|
super("HMCCosmetics");
|
||||||
setEnabledItemHook(true);
|
setEnabledItemHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin HMCCosmetics}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(String itemid) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(itemid);
|
Cosmetic cosmetic = Cosmetics.getCosmetic(itemId);
|
||||||
if (cosmetic == null) return null;
|
if (cosmetic == null) return null;
|
||||||
return cosmetic.getItem();
|
return cosmetic.getItem();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
import dev.lone.itemsadder.api.CustomStack;
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookItemAdder extends Hook implements Listener {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder} to provide custom items
|
||||||
// I hate IA, this overcomplicate stuff is so unneeded if it just did its stuff when its needed.
|
*/
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class HookItemAdder extends Hook {
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
public HookItemAdder() {
|
public HookItemAdder() {
|
||||||
@@ -20,10 +22,13 @@ public class HookItemAdder extends Hook implements Listener {
|
|||||||
setEnabledItemHook(true);
|
setEnabledItemHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(String itemid) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
CustomStack stack = CustomStack.getInstance(itemid);
|
CustomStack stack = CustomStack.getInstance(itemId);
|
||||||
if (stack == null) return null;
|
if (stack == null) return null;
|
||||||
return stack.getItemStack();
|
return stack.getItemStack();
|
||||||
} else {
|
} else {
|
||||||
@@ -33,7 +38,8 @@ public class HookItemAdder extends Hook implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
||||||
if (enabled) return; // Only run on the first event fired; ignore all rest
|
// By default, it will only run once at startup, if hook setting is enabled
|
||||||
|
if (enabled && !Settings.getItemsAdderReloadChange()) return;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
HMCCosmeticsPlugin.setup();
|
HMCCosmeticsPlugin.setup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,25 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
|||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
import com.mineinabyss.geary.prefabs.PrefabKey;
|
import com.mineinabyss.geary.prefabs.PrefabKey;
|
||||||
import com.mineinabyss.looty.LootyFactory;
|
import com.mineinabyss.looty.LootyFactory;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookLooty extends Hook implements Listener {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.mineinabyss.looty.LootyPlugin Looty} to provide custom items
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class HookLooty extends Hook {
|
||||||
public HookLooty() {
|
public HookLooty() {
|
||||||
super("looty");
|
super("looty");
|
||||||
setEnabledItemHook(true);
|
setEnabledItemHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.looty.LootyPlugin Looty}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(String itemid) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemid);
|
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||||
if (prefabKey == null) return null;
|
if (prefabKey == null) return null;
|
||||||
return LootyFactory.INSTANCE.createFromPrefab(prefabKey);
|
return LootyFactory.INSTANCE.createFromPrefab(prefabKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,24 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookMythic extends Hook implements Listener {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit} to provide custom items
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class HookMythic extends Hook {
|
||||||
public HookMythic() {
|
public HookMythic() {
|
||||||
super("mythicmobs");
|
super("mythicmobs");
|
||||||
setEnabledItemHook(true);
|
setEnabledItemHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(String itemid) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
return MythicBukkit.inst().getItemManager().getItemStack(itemid);
|
return MythicBukkit.inst().getItemManager().getItemStack(itemId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,25 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
|||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
import io.th0rgal.oraxen.api.OraxenItems;
|
import io.th0rgal.oraxen.api.OraxenItems;
|
||||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookOraxen extends Hook implements Listener {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin} to provide custom items
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class HookOraxen extends Hook {
|
||||||
public HookOraxen() {
|
public HookOraxen() {
|
||||||
super("oraxen");
|
super("oraxen");
|
||||||
setEnabledItemHook(true);
|
setEnabledItemHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(String itemid) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
ItemBuilder builder = OraxenItems.getItemById(itemid);
|
ItemBuilder builder = OraxenItems.getItemById(itemId);
|
||||||
if (builder == null) return null;
|
if (builder == null) return null;
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.Zrips.CMI.CMI CMI}
|
||||||
|
*/
|
||||||
|
public class HookCMI extends Hook {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.hibiscusmc.hmccolor.HMCColor HMCColor}
|
||||||
|
*/
|
||||||
|
public class HookHMCColor extends Hook {
|
||||||
|
public HookHMCColor() {
|
||||||
|
super("HMCColor");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,18 +7,20 @@ import de.myzelyam.api.vanish.PlayerHideEvent;
|
|||||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookPremiumVanish extends Hook implements Listener {
|
|
||||||
|
|
||||||
// NOTE: Supervanish and Premium Vanish both use the same api
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||||
|
*
|
||||||
|
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||||
|
*/
|
||||||
|
public class HookPremiumVanish extends Hook {
|
||||||
public HookPremiumVanish() {
|
public HookPremiumVanish() {
|
||||||
super("PremiumVanish");
|
super("PremiumVanish");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerVanish(PlayerHideEvent event) {
|
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
@@ -26,11 +28,10 @@ public class HookPremiumVanish extends Hook implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerShow(PlayerShowEvent event) {
|
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
user.showCosmetics();
|
user.showCosmetics();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,20 @@ import de.myzelyam.api.vanish.PlayerHideEvent;
|
|||||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookSuperVanish extends Hook implements Listener {
|
|
||||||
|
|
||||||
// NOTE: Supervanish and Premium Vanish both use the same api
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||||
|
*
|
||||||
|
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||||
|
*/
|
||||||
|
public class HookSuperVanish extends Hook {
|
||||||
public HookSuperVanish() {
|
public HookSuperVanish() {
|
||||||
super("SuperVanish");
|
super("SuperVanish");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerVanish(PlayerHideEvent event) {
|
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
@@ -26,7 +28,7 @@ public class HookSuperVanish extends Hook implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerShow(PlayerShowEvent event) {
|
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
|||||||
@@ -12,12 +12,15 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link me.clip.placeholderapi.PlaceholderAPIPlugin PlaceholderAPIPlugin}
|
||||||
|
*/
|
||||||
public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||||
|
|
||||||
private static boolean papiEnabled = false;
|
private static boolean papiEnabled = false;
|
||||||
|
|
||||||
public HMCPlaceholderExpansion() {
|
public HMCPlaceholderExpansion() {
|
||||||
@@ -25,22 +28,25 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getIdentifier() {
|
@NotNull
|
||||||
|
public String getIdentifier() {
|
||||||
return "HMCCosmetics";
|
return "HMCCosmetics";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getAuthor() {
|
@NotNull
|
||||||
|
public String getAuthor() {
|
||||||
return "HibiscusMC";
|
return "HibiscusMC";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
@NotNull
|
||||||
|
public String getVersion() {
|
||||||
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, String params) {
|
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
|
||||||
if (!player.isOnline()) return null;
|
if (!player.isOnline()) return null;
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
@@ -70,7 +76,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||||
case "material" -> {
|
case "material" -> {
|
||||||
return getMaterial(user.getCosmetic(slot));
|
return getMaterialName(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "custommodeldata" -> {
|
case "custommodeldata" -> {
|
||||||
return getModelData(user.getCosmetic(slot));
|
return getModelData(user.getCosmetic(slot));
|
||||||
@@ -132,33 +138,76 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaterial(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @param cosmetic The cosmetic to get its {@link org.bukkit.Material Material}s name
|
||||||
|
* @return The name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @deprecated As of release 2.2.5+, use {@link #getMaterialName(Cosmetic)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@Nullable
|
||||||
|
public String getMaterial(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
return cosmetic.getItem().getType().toString();
|
return item.getType().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModelData(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @param cosmetic The cosmetic to get its {@link org.bukkit.Material Material}s name
|
||||||
|
* @return The name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @since 2.2.5
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getMaterialName(@NotNull Cosmetic cosmetic) {
|
||||||
|
ItemStack item = cosmetic.getItem();
|
||||||
|
if (item == null) return null;
|
||||||
|
return item.getType().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic items custom model data
|
||||||
|
* @param cosmetic The cosmetic to get its custom model data
|
||||||
|
* @return The cosmetic items custom model data
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getModelData(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
if (!item.hasItemMeta()) return null;
|
if (!item.hasItemMeta()) return null;
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
return String.valueOf(itemMeta.getCustomModelData());
|
return String.valueOf(itemMeta.getCustomModelData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItemName(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the cosmetic items display name
|
||||||
|
* @param cosmetic The cosmetic to get its items display name
|
||||||
|
* @return The cosmetic items display name
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemName(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
if (!item.hasItemMeta()) return null;
|
if (!item.hasItemMeta()) return null;
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
return itemMeta.getDisplayName();
|
return itemMeta.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItemLore(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the cosmetic items lore
|
||||||
|
* @param cosmetic The cosmetic to get its items lore
|
||||||
|
* @return The cosmetic items lore
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemLore(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
return String.valueOf(item.getItemMeta().getLore());
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
|
return String.valueOf(itemMeta.getLore());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,17 @@ package com.hibiscusmc.hmccosmetics.hooks.placeholders;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link me.clip.placeholderapi.PlaceholderAPI PlaceholderAPI}
|
||||||
|
*/
|
||||||
public class HookPlaceholderAPI extends Hook {
|
public class HookPlaceholderAPI extends Hook {
|
||||||
|
|
||||||
public HookPlaceholderAPI() {
|
public HookPlaceholderAPI() {
|
||||||
super("PlaceholderAPI");
|
super("PlaceholderAPI");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers HMCCosmetics Placeholder Expansion
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
new HMCPlaceholderExpansion().register();
|
new HMCPlaceholderExpansion().register();
|
||||||
|
|||||||
@@ -9,9 +9,18 @@ import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
|||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.sk89q.worldguard.WorldGuard WorldGuard}
|
||||||
|
*/
|
||||||
public class WGHook {
|
public class WGHook {
|
||||||
|
/**
|
||||||
|
* @implNote Please use {@link #getCosmeticEnableFlag()} instead
|
||||||
|
*/
|
||||||
public static StateFlag COSMETIC_ENABLE_FLAG;
|
public static StateFlag COSMETIC_ENABLE_FLAG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implNote Please use {@link #getCosmeticWardrobeFlag()} instead
|
||||||
|
*/
|
||||||
public static StateFlag COSMETIC_WARDROBE_FLAG;
|
public static StateFlag COSMETIC_WARDROBE_FLAG;
|
||||||
|
|
||||||
public WGHook() {
|
public WGHook() {
|
||||||
@@ -35,10 +44,18 @@ public class WGHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic enable {@link StateFlag}
|
||||||
|
* @return The cosmetic enable {@link StateFlag}
|
||||||
|
*/
|
||||||
public static StateFlag getCosmeticEnableFlag() {
|
public static StateFlag getCosmeticEnableFlag() {
|
||||||
return COSMETIC_ENABLE_FLAG;
|
return COSMETIC_ENABLE_FLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic wardrobe {@link StateFlag}
|
||||||
|
* @return The cosmetic wardrobe {@link StateFlag}
|
||||||
|
*/
|
||||||
public static StateFlag getCosmeticWardrobeFlag() {
|
public static StateFlag getCosmeticWardrobeFlag() {
|
||||||
return COSMETIC_WARDROBE_FLAG;
|
return COSMETIC_WARDROBE_FLAG;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
||||||
|
*/
|
||||||
public class WGListener implements Listener {
|
public class WGListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
Location location = event.getPlayer().getLocation();
|
Location location = event.getPlayer().getLocation();
|
||||||
@@ -31,10 +34,12 @@ public class WGListener implements Listener {
|
|||||||
}
|
}
|
||||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||||
|
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) return;
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||||
|
if (!protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString().equalsIgnoreCase("ALLOW")) return;
|
||||||
user.enterWardrobe();
|
user.enterWardrobe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
|||||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@@ -13,11 +14,12 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerConnectionListener implements Listener {
|
public class PlayerConnectionListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
||||||
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
||||||
if (!HMCCosmeticsPlugin.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion() != null)
|
if (!HMCCosmeticsPlugin.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion() != null)
|
||||||
MessagesUtil.sendMessageNoKey(
|
MessagesUtil.sendMessageNoKey(
|
||||||
@@ -46,7 +48,7 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
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 (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
|
||||||
if (!event.getPlayer().getPassengers().isEmpty()) {
|
if (!event.getPlayer().getPassengers().isEmpty()) {
|
||||||
@@ -59,7 +61,7 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
user.getUserEmoteManager().stopEmote();
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
||||||
event.getPlayer().setInvisible(false);
|
event.getPlayer().setInvisible(false);
|
||||||
}
|
}
|
||||||
Database.save(user);
|
Database.save(user);
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ import com.hibiscusmc.hmccosmetics.gui.Menu;
|
|||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -52,6 +53,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
registerMenuChangeListener();
|
registerMenuChangeListener();
|
||||||
registerPlayerEquipmentListener();
|
registerPlayerEquipmentListener();
|
||||||
registerPlayerArmListener();
|
registerPlayerArmListener();
|
||||||
|
registerEntityUseListener();
|
||||||
|
|
||||||
//registerLookMovement();
|
//registerLookMovement();
|
||||||
//registerMoveListener();
|
//registerMoveListener();
|
||||||
@@ -83,7 +85,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
|
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
if (event.isSneaking()) {
|
if (event.isSneaking()) {
|
||||||
user.getUserEmoteManager().stopEmote();
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.isSneaking()) return;
|
if (!event.isSneaking()) return;
|
||||||
@@ -102,10 +104,10 @@ public class PlayerGameListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||||
user.getUserBackpackManager().hideBackpack();
|
user.getUserBackpackManager().hideBackpack();
|
||||||
|
|
||||||
user.getUserBackpackManager().getArmorstand().teleport(event.getTo());
|
user.getUserBackpackManager().getArmorStand().teleport(event.getTo());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.updateCosmetic();
|
user.updateCosmetic();
|
||||||
@@ -133,15 +135,15 @@ public class PlayerGameListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cosmetic cosmetic = user.getCosmetic(CosmeticSlot.BALLOON);
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
final Color color = user.getCosmeticColor(CosmeticSlot.BALLOON);
|
user.despawnBalloon();
|
||||||
user.removeCosmeticSlot(CosmeticSlot.BALLOON);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
user.spawnBalloon((CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON));
|
||||||
user.updateCosmetic();
|
user.updateCosmetic();
|
||||||
}, 4);
|
}, 4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerHit(EntityDamageByEntityEvent event) {
|
public void onPlayerHit(EntityDamageByEntityEvent event) {
|
||||||
@@ -153,6 +155,26 @@ public class PlayerGameListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDamaged(EntityDamageEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
|
Player player = ((Player) event.getEntity()).getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
if (Settings.isEmoteInvincible()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (Settings.isEmoteDamageLeave()) {
|
||||||
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (user.isInWardrobe()) {
|
||||||
|
user.leaveWardrobe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLook(PlayerMoveEvent event) {
|
public void onPlayerLook(PlayerMoveEvent event) {
|
||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
@@ -174,12 +196,20 @@ public class PlayerGameListener implements Listener {
|
|||||||
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||||
Pose pose = event.getPose();
|
Pose pose = event.getPose();
|
||||||
if (pose.equals(Pose.STANDING)) {
|
if (pose.equals(Pose.STANDING)) {
|
||||||
if (!user.isBackupSpawned()) {
|
// #84, Riptides mess with backpacks
|
||||||
|
ItemStack currentItem = player.getInventory().getItemInMainHand();
|
||||||
|
if (currentItem == null) return;
|
||||||
|
if (!currentItem.hasItemMeta()) return;
|
||||||
|
if (currentItem.containsEnchantment(Enchantment.RIPTIDE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.isBackpackSpawned()) {
|
||||||
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
|
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pose.equals(Pose.SLEEPING) || pose.equals(Pose.SWIMMING) || pose.equals(Pose.FALL_FLYING)) {
|
if (pose.equals(Pose.SLEEPING) || pose.equals(Pose.SWIMMING) || pose.equals(Pose.FALL_FLYING) || pose.equals(Pose.SPIN_ATTACK)) {
|
||||||
user.despawnBackpack();
|
user.despawnBackpack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,6 +301,14 @@ public class PlayerGameListener implements Listener {
|
|||||||
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
||||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||||
}, 2);
|
}, 2);
|
||||||
|
|
||||||
|
// #84, Riptides mess with backpacks
|
||||||
|
ItemStack currentItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||||
|
if (currentItem == null) return;
|
||||||
|
if (!currentItem.hasItemMeta()) return;
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && currentItem.containsEnchantment(Enchantment.RIPTIDE)) {
|
||||||
|
user.despawnBackpack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -326,7 +364,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
|
|
||||||
HashMap<Integer, ItemStack> items = new HashMap<>();
|
HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
||||||
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
||||||
}
|
}
|
||||||
@@ -394,6 +432,10 @@ public class PlayerGameListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!user.isInWardrobe()) return;
|
if (!user.isInWardrobe()) return;
|
||||||
Menu menu = Menus.getDefaultMenu();
|
Menu menu = Menus.getDefaultMenu();
|
||||||
if (menu == null) return;
|
if (menu == null) return;
|
||||||
@@ -403,6 +445,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() {
|
private void registerLookMovement() {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ public interface NMSHandler {
|
|||||||
|
|
||||||
Entity getEntity(int entityId);
|
Entity getEntity(int entityId);
|
||||||
|
|
||||||
Entity getInvisibleArmorstand(Location loc);
|
Entity getHMCArmorStand(Location loc);
|
||||||
|
|
||||||
ArmorStand getMEGEntity(Location loc);
|
ArmorStand getMEGEntity(Location loc);
|
||||||
|
|
||||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||||
|
|
||||||
|
Entity spawnHMCParticleCloud(Location location);
|
||||||
|
|
||||||
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||||
|
|
||||||
void equipmentSlotUpdate(
|
void equipmentSlotUpdate(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class NMSHandlers {
|
public class NMSHandlers {
|
||||||
|
|
||||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_17_R1", "v1_18_R2", "v1_19_R1", "v1_19_R2"};
|
private static final String[] SUPPORTED_VERSION = new String[]{"v1_17_R1", "v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3"};
|
||||||
private static NMSHandler handler;
|
private static NMSHandler handler;
|
||||||
private static String version;
|
private static String version;
|
||||||
|
|
||||||
@@ -37,7 +37,6 @@ public class NMSHandlers {
|
|||||||
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
||||||
version = packageVersion;
|
version = packageVersion;
|
||||||
try {
|
try {
|
||||||
//Class.forName("org.bukkit.craftbukkit." + version + ".block.CraftBlock").getName();
|
|
||||||
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||||
return;
|
return;
|
||||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.user;
|
package com.hibiscusmc.hmccosmetics.user;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableCollection;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.api.*;
|
import com.hibiscusmc.hmccosmetics.api.*;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
@@ -77,10 +79,15 @@ public class CosmeticUser {
|
|||||||
return playerCosmetics.get(slot);
|
return playerCosmetics.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Collection<Cosmetic> getCosmetic() {
|
public Collection<Cosmetic> getCosmetic() {
|
||||||
return playerCosmetics.values();
|
return playerCosmetics.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImmutableCollection<Cosmetic> getCosmetics() {
|
||||||
|
return ImmutableList.copyOf(playerCosmetics.values());
|
||||||
|
}
|
||||||
|
|
||||||
public void addPlayerCosmetic(Cosmetic cosmetic) {
|
public void addPlayerCosmetic(Cosmetic cosmetic) {
|
||||||
addPlayerCosmetic(cosmetic, null);
|
addPlayerCosmetic(cosmetic, null);
|
||||||
}
|
}
|
||||||
@@ -151,6 +158,10 @@ public class CosmeticUser {
|
|||||||
return playerCosmetics.containsKey(slot);
|
return playerCosmetics.containsKey(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<CosmeticSlot> getSlotsWithCosmetics() {
|
||||||
|
return Set.copyOf(playerCosmetics.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
public void updateCosmetic(CosmeticSlot slot) {
|
public void updateCosmetic(CosmeticSlot slot) {
|
||||||
if (getCosmetic(slot) == null) {
|
if (getCosmetic(slot) == null) {
|
||||||
return;
|
return;
|
||||||
@@ -287,7 +298,7 @@ public class CosmeticUser {
|
|||||||
|
|
||||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
if (this.userBackpackManager != null) return;
|
if (this.userBackpackManager != null) return;
|
||||||
this.userBackpackManager = new UserBackpackManager(this);
|
this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType());
|
||||||
userBackpackManager.spawnBackpack(cosmeticBackpackType);
|
userBackpackManager.spawnBackpack(cosmeticBackpackType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +308,7 @@ public class CosmeticUser {
|
|||||||
userBackpackManager = null;
|
userBackpackManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBackupSpawned() {
|
public boolean isBackpackSpawned() {
|
||||||
if (this.userBackpackManager == null) return false;
|
if (this.userBackpackManager == null) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -354,7 +365,7 @@ public class CosmeticUser {
|
|||||||
public List<CosmeticSlot> getDyeableSlots() {
|
public List<CosmeticSlot> getDyeableSlots() {
|
||||||
ArrayList<CosmeticSlot> dyableSlots = new ArrayList();
|
ArrayList<CosmeticSlot> dyableSlots = new ArrayList();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : getCosmetic()) {
|
for (Cosmetic cosmetic : getCosmetics()) {
|
||||||
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +412,7 @@ public class CosmeticUser {
|
|||||||
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
|
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
|
||||||
}
|
}
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
userBackpackManager.getArmorstand().getEquipment().clear();
|
userBackpackManager.clearItems();
|
||||||
}
|
}
|
||||||
updateCosmetic();
|
updateCosmetic();
|
||||||
MessagesUtil.sendDebugMessages("HideCosmetics");
|
MessagesUtil.sendDebugMessages("HideCosmetics");
|
||||||
@@ -427,7 +438,7 @@ public class CosmeticUser {
|
|||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
||||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
||||||
userBackpackManager.getArmorstand().getEquipment().setHelmet(item);
|
userBackpackManager.setItem(item);
|
||||||
}
|
}
|
||||||
updateCosmetic();
|
updateCosmetic();
|
||||||
MessagesUtil.sendDebugMessages("ShowCosmetics");
|
MessagesUtil.sendDebugMessages("ShowCosmetics");
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|||||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
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.entity.ArmorStand;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@@ -17,37 +20,69 @@ import java.util.logging.Level;
|
|||||||
public class UserBackpackManager {
|
public class UserBackpackManager {
|
||||||
|
|
||||||
private boolean hideBackpack;
|
private boolean hideBackpack;
|
||||||
private ArmorStand invisibleArmorstand;
|
private ArmorStand invisibleArmorStand;
|
||||||
private CosmeticUser user;
|
private AreaEffectCloud particleCloud;
|
||||||
|
private final CosmeticUser user;
|
||||||
private BackpackType backpackType;
|
private BackpackType backpackType;
|
||||||
|
|
||||||
public UserBackpackManager(CosmeticUser user) {
|
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
hideBackpack = false;
|
hideBackpack = false;
|
||||||
backpackType = BackpackType.NORMAL;
|
this.backpackType = backpackType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFirstArmorstandId() {
|
public int getFirstArmorStandId() {
|
||||||
return invisibleArmorstand.getEntityId();
|
return invisibleArmorStand.getEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArmorStand getArmorstand() {
|
public ArmorStand getArmorStand() {
|
||||||
return invisibleArmorstand;
|
return invisibleArmorStand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
|
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 (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||||
return;
|
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()));
|
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
|
||||||
model.setCanHurt(false);
|
model.setCanHurt(false);
|
||||||
modeledEntity.addModel(model, false);
|
modeledEntity.addModel(model, false);
|
||||||
@@ -57,23 +92,28 @@ public class UserBackpackManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void despawnBackpack() {
|
public void despawnBackpack() {
|
||||||
if (invisibleArmorstand == null) return;
|
if (invisibleArmorStand != null) {
|
||||||
invisibleArmorstand.setHealth(0);
|
invisibleArmorStand.setHealth(0);
|
||||||
invisibleArmorstand.remove();
|
invisibleArmorStand.remove();
|
||||||
this.invisibleArmorstand = null;
|
this.invisibleArmorStand = null;
|
||||||
|
}
|
||||||
|
if (particleCloud != null) {
|
||||||
|
particleCloud.remove();
|
||||||
|
this.particleCloud = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideBackpack() {
|
public void hideBackpack() {
|
||||||
if (user.getHidden() == true) return;
|
if (user.getHidden()) return;
|
||||||
getArmorstand().getEquipment().clear();
|
getArmorStand().getEquipment().clear();
|
||||||
hideBackpack = true;
|
hideBackpack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showBackpack() {
|
public void showBackpack() {
|
||||||
if (hideBackpack == false) return;
|
if (!hideBackpack) return;
|
||||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
|
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
|
||||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||||
getArmorstand().getEquipment().setHelmet(item);
|
getArmorStand().getEquipment().setHelmet(item);
|
||||||
hideBackpack = false;
|
hideBackpack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +121,27 @@ public class UserBackpackManager {
|
|||||||
hideBackpack = shown;
|
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 {
|
public enum BackpackType {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
FIRST_PERSON // First person not yet implemented
|
FIRST_PERSON // First person not yet implemented
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.bukkit.entity.ArmorStand;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -26,13 +27,13 @@ public class UserBalloonManager {
|
|||||||
private final UUID uniqueID;
|
private final UUID uniqueID;
|
||||||
private final ArmorStand modelEntity;
|
private final ArmorStand modelEntity;
|
||||||
|
|
||||||
public UserBalloonManager(Location location) {
|
public UserBalloonManager(@NotNull Location location) {
|
||||||
this.uniqueID = UUID.randomUUID();
|
this.uniqueID = UUID.randomUUID();
|
||||||
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
|
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
|
// redo this
|
||||||
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||||
balloonType = BalloonType.MODELENGINE;
|
balloonType = BalloonType.MODELENGINE;
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStartEvent;
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStopEvent;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class UserEmoteManager {
|
public class UserEmoteManager {
|
||||||
|
|
||||||
@@ -13,13 +17,24 @@ public class UserEmoteManager {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playEmote(CosmeticEmoteType cosmeticEmoteType) {
|
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
|
||||||
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
|
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
|
||||||
|
playEmote(cosmeticEmoteType.getAnimationId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playEmote(String animationId) {
|
||||||
if (isPlayingEmote()) return;
|
if (isPlayingEmote()) return;
|
||||||
if (user.isInWardrobe()) return;
|
if (user.isInWardrobe()) return;
|
||||||
|
// API
|
||||||
|
PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, animationId);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Internal
|
||||||
try {
|
try {
|
||||||
model = new UserEmoteModel(user);
|
model = new UserEmoteModel(user);
|
||||||
model.playAnimation(cosmeticEmoteType.getAnimationId());
|
model.playAnimation(animationId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -30,8 +45,21 @@ public class UserEmoteManager {
|
|||||||
return model.isPlayingAnimation();
|
return model.isPlayingAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopEmote() {
|
public void stopEmote(StopEmoteReason emoteReason) {
|
||||||
if (!isPlayingEmote()) return;
|
if (!isPlayingEmote()) return;
|
||||||
|
// API
|
||||||
|
PlayerEmoteStopEvent event = new PlayerEmoteStopEvent(user, emoteReason);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Internal
|
||||||
model.stopAnimation();
|
model.stopAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum StopEmoteReason {
|
||||||
|
SNEAK,
|
||||||
|
DAMAGE,
|
||||||
|
CONNECTION
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,35 +14,38 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UserEmoteModel extends PlayerModel {
|
public class UserEmoteModel extends PlayerModel {
|
||||||
|
|
||||||
private CosmeticUser user;
|
private final CosmeticUser user;
|
||||||
private String emotePlaying;
|
private String emotePlaying;
|
||||||
private int armorstandId;
|
private final int armorStandId;
|
||||||
private GameMode originalGamemode;
|
private GameMode originalGamemode;
|
||||||
|
|
||||||
public UserEmoteModel(CosmeticUser user) {
|
public UserEmoteModel(@NotNull CosmeticUser user) {
|
||||||
super(user.getPlayer());
|
super(user.getPlayer());
|
||||||
this.user = user;
|
this.user = user;
|
||||||
armorstandId = NMSHandlers.getHandler().getNextEntityId();
|
armorStandId = NMSHandlers.getHandler().getNextEntityId();
|
||||||
getRangeManager().setRenderDistance(Settings.getViewDistance());
|
getRangeManager().setRenderDistance(Settings.getViewDistance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playAnimation(String id) {
|
public void playAnimation(@NotNull String id) {
|
||||||
id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits.
|
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);
|
super.playAnimation(id);
|
||||||
|
|
||||||
emotePlaying = id;
|
emotePlaying = id;
|
||||||
|
|
||||||
// Add config option that either allows player to move or forces them into a spot.
|
// Add config option that either allows player to move or forces them into a spot.
|
||||||
Player player = user.getPlayer();
|
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());
|
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
|
||||||
outsideViewers.remove(player);
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
@@ -50,24 +53,27 @@ public class UserEmoteModel extends PlayerModel {
|
|||||||
|
|
||||||
Location newLocation = player.getLocation().clone();
|
Location newLocation = player.getLocation().clone();
|
||||||
newLocation.setPitch(0);
|
newLocation.setPitch(0);
|
||||||
|
|
||||||
double DISTANCE = Settings.getEmoteDistance();
|
double DISTANCE = Settings.getEmoteDistance();
|
||||||
|
|
||||||
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
|
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
|
||||||
if (thirdPersonLocation.getBlock().getType() != Material.AIR) {
|
if (Settings.getCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
|
||||||
stopAnimation();
|
stopAnimation();
|
||||||
MessagesUtil.sendMessage(player, "emote-blocked");
|
MessagesUtil.sendMessage(player, "emote-blocked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getPlayer().setInvisible(true);
|
user.getPlayer().setInvisible(true);
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||||
|
|
||||||
originalGamemode = player.getGameMode();
|
originalGamemode = player.getGameMode();
|
||||||
|
|
||||||
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorstandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||||
PacketManager.sendInvisibilityPacket(armorstandId, viewer);
|
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
|
||||||
PacketManager.sendLookPacket(armorstandId, player.getLocation(), viewer);
|
PacketManager.sendLookPacket(armorStandId, player.getLocation(), viewer);
|
||||||
|
|
||||||
PacketManager.gamemodeChangePacket(player, 3);
|
PacketManager.gamemodeChangePacket(player, 3);
|
||||||
PacketManager.sendCameraPacket(armorstandId, viewer);
|
PacketManager.sendCameraPacket(armorStandId, viewer);
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("playAnimation run");
|
MessagesUtil.sendDebugMessages("playAnimation run");
|
||||||
}
|
}
|
||||||
@@ -89,16 +95,16 @@ public class UserEmoteModel extends PlayerModel {
|
|||||||
emotePlaying = null;
|
emotePlaying = null;
|
||||||
despawn();
|
despawn();
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
if (user.getPlayer() == null) return;
|
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
List<Player> viewer = List.of(user.getPlayer());
|
if (player == null) return;
|
||||||
if (viewer == null) return;
|
|
||||||
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
|
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
|
||||||
outsideViewers.remove(player);
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
int entityId = player.getEntityId();
|
int entityId = player.getEntityId();
|
||||||
PacketManager.sendCameraPacket(entityId, viewer);
|
PacketManager.sendCameraPacket(entityId, viewer);
|
||||||
PacketManager.sendEntityDestroyPacket(armorstandId, viewer);
|
PacketManager.sendEntityDestroyPacket(armorStandId, viewer);
|
||||||
if (this.originalGamemode != null) {
|
if (this.originalGamemode != null) {
|
||||||
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
|
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
|
||||||
player.setGameMode(this.originalGamemode);
|
player.setGameMode(this.originalGamemode);
|
||||||
@@ -112,7 +118,6 @@ public class UserEmoteModel extends PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayingAnimation() {
|
public boolean isPlayingAnimation() {
|
||||||
if (emotePlaying == null) return false;
|
return emotePlaying != null;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
@@ -23,38 +24,27 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class UserWardrobeManager {
|
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 String npcName;
|
||||||
private UUID WARDROBE_UUID;
|
|
||||||
private int ARMORSTAND_ID;
|
|
||||||
private GameMode originalGamemode;
|
private GameMode originalGamemode;
|
||||||
private CosmeticUser user;
|
private final CosmeticUser user;
|
||||||
private Location viewingLocation;
|
private final Location viewingLocation;
|
||||||
private Location npcLocation;
|
private final Location npcLocation;
|
||||||
private Location exitLocation;
|
private Location exitLocation;
|
||||||
private BossBar bossBar;
|
private BossBar bossBar;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private WardrobeStatus wardrobeStatus;
|
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) {
|
public UserWardrobeManager(CosmeticUser user, Location exitLocation, Location viewingLocation, Location npcLocation) {
|
||||||
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
@@ -78,7 +68,7 @@ public class UserWardrobeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.hidePlayer();
|
user.hidePlayer();
|
||||||
List<Player> viewer = List.of(player);
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
outsideViewers.remove(player);
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
@@ -114,8 +104,8 @@ public class UserWardrobeManager {
|
|||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
user.getUserBackpackManager().getArmorstand().teleport(npcLocation.clone().add(0, 2, 0));
|
user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0));
|
||||||
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
|
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
@@ -162,11 +152,11 @@ public class UserWardrobeManager {
|
|||||||
setWardrobeStatus(WardrobeStatus.STOPPING);
|
setWardrobeStatus(WardrobeStatus.STOPPING);
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
List<Player> viewer = List.of(player);
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
outsideViewers.remove(player);
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
MessagesUtil.sendMessage(player, "closed-wardrobe");
|
if (player != null) MessagesUtil.sendMessage(player, "closed-wardrobe");
|
||||||
|
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
this.active = false;
|
this.active = false;
|
||||||
@@ -197,11 +187,7 @@ public class UserWardrobeManager {
|
|||||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exitLocation == null) {
|
player.teleport(Objects.requireNonNullElseGet(exitLocation, () -> player.getWorld().getSpawnLocation()));
|
||||||
player.teleport(player.getWorld().getSpawnLocation());
|
|
||||||
} else {
|
|
||||||
player.teleport(exitLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WardrobeSettings.isEquipPumpkin()) {
|
if (WardrobeSettings.isEquipPumpkin()) {
|
||||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
|
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
|
||||||
@@ -213,6 +199,13 @@ public class UserWardrobeManager {
|
|||||||
target.hideBossBar(bossBar);
|
target.hideBossBar(bossBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Wardrobe Temp Cosmetics
|
||||||
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
|
if (cosmetic.requiresPermission()) {
|
||||||
|
if (!player.hasPermission(cosmetic.getPermission())) user.removeCosmeticSlot(cosmetic.getSlot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user.updateCosmetic();
|
user.updateCosmetic();
|
||||||
};
|
};
|
||||||
run.run();
|
run.run();
|
||||||
@@ -224,15 +217,16 @@ public class UserWardrobeManager {
|
|||||||
BukkitRunnable runnable = new BukkitRunnable() {
|
BukkitRunnable runnable = new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (active == false || user.getPlayer() == null) {
|
Player player = user.getPlayer();
|
||||||
|
if (!active || player == null) {
|
||||||
MessagesUtil.sendDebugMessages("Active is false");
|
MessagesUtil.sendDebugMessages("Active is false");
|
||||||
this.cancel();
|
this.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MessagesUtil.sendDebugMessages("Update ");
|
MessagesUtil.sendDebugMessages("Update ");
|
||||||
List<Player> viewer = List.of(user.getPlayer());
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
outsideViewers.remove(user.getPlayer());
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
||||||
int yaw = data.get();
|
int yaw = data.get();
|
||||||
@@ -251,10 +245,10 @@ public class UserWardrobeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorstandId(), location, false, viewer);
|
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
|
||||||
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
|
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||||
user.getUserBackpackManager().getArmorstand().setRotation(nextyaw, 0);
|
user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0);
|
||||||
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorstandId(), outsideViewers);
|
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
@@ -274,7 +268,7 @@ public class UserWardrobeManager {
|
|||||||
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArmorstandId() {
|
public int getCameraId() {
|
||||||
return ARMORSTAND_ID;
|
return ARMORSTAND_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.util;
|
|||||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class InventoryUtils {
|
public class InventoryUtils {
|
||||||
@@ -58,6 +60,8 @@ public class InventoryUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@Nullable
|
||||||
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
|
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case 36 -> {
|
case 36 -> {
|
||||||
@@ -81,6 +85,8 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@Nullable
|
||||||
public static CosmeticSlot NMSCosmeticSlot(int slot) {
|
public static CosmeticSlot NMSCosmeticSlot(int slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case 5 -> {
|
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) {
|
switch (slot) {
|
||||||
case HELMET -> {
|
case HELMET -> {
|
||||||
return EquipmentSlot.HEAD;
|
return EquipmentSlot.HEAD;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -24,9 +26,9 @@ import java.util.logging.Level;
|
|||||||
public class MessagesUtil {
|
public class MessagesUtil {
|
||||||
|
|
||||||
private static String prefix;
|
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("");
|
prefix = config.node("prefix").getString("");
|
||||||
for (ConfigurationNode node : config.childrenMap().values()) {
|
for (ConfigurationNode node : config.childrenMap().values()) {
|
||||||
if (node.virtual()) continue;
|
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);
|
sendMessage(user.getPlayer(), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +94,7 @@ public class MessagesUtil {
|
|||||||
return processString(player, key, null);
|
return processString(player, key, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Component processString(Player player, String key, TagResolver placeholders) {
|
public static Component processString(Player player, String key, TagResolver placeholders) {
|
||||||
if (!messages.containsKey(key)) return null;
|
if (!messages.containsKey(key)) return null;
|
||||||
if (messages.get(key) == null) return null;
|
if (messages.get(key) == null) return null;
|
||||||
@@ -104,14 +107,17 @@ public class MessagesUtil {
|
|||||||
return Adventure.MINI_MESSAGE.deserialize(message);
|
return Adventure.MINI_MESSAGE.deserialize(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(String message) {
|
public static Component processStringNoKey(String message) {
|
||||||
return processStringNoKey(null, message, null);
|
return processStringNoKey(null, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(Player player, String message) {
|
public static Component processStringNoKey(Player player, String message) {
|
||||||
return processStringNoKey(player, message, null);
|
return processStringNoKey(player, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
|
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
|
||||||
message = message.replaceAll("%prefix%", prefix);
|
message = message.replaceAll("%prefix%", prefix);
|
||||||
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlayerUtils {
|
public class PlayerUtils {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static WrappedSignedProperty getSkin(Player player) {
|
public static WrappedSignedProperty getSkin(Player player) {
|
||||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||||
.get("textures").stream().findAny().orElse(null);
|
.get("textures").stream().findAny().orElse(null);
|
||||||
@@ -22,11 +25,13 @@ public class PlayerUtils {
|
|||||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
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());
|
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<>();
|
List<Player> players = new ArrayList<>();
|
||||||
int viewDistance = Settings.getViewDistance();
|
int viewDistance = Settings.getViewDistance();
|
||||||
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {
|
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ColorBuilder {
|
public class ColorBuilder {
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ public class ColorBuilder {
|
|||||||
return canBeColored(new ItemStack(material));
|
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();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
return (itemMeta instanceof LeatherArmorMeta ||
|
return (itemMeta instanceof LeatherArmorMeta ||
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,7 +35,7 @@ public class ItemBuilder {
|
|||||||
* @param itemStack builder ItemStack
|
* @param itemStack builder ItemStack
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ItemBuilder(final ItemStack itemStack) {
|
ItemBuilder(final @NotNull ItemStack itemStack) {
|
||||||
this.material = itemStack.getType();
|
this.material = itemStack.getType();
|
||||||
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
||||||
: Bukkit.getItemFactory().getItemMeta(this.material);
|
: Bukkit.getItemFactory().getItemMeta(this.material);
|
||||||
@@ -44,6 +46,8 @@ public class ItemBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
@NotNull
|
||||||
public static ItemBuilder from(final Material material) {
|
public static ItemBuilder from(final Material material) {
|
||||||
return new ItemBuilder(material);
|
return new ItemBuilder(material);
|
||||||
}
|
}
|
||||||
@@ -52,7 +56,8 @@ public class ItemBuilder {
|
|||||||
* @param itemStack builder ItemStack
|
* @param itemStack builder ItemStack
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Contract("_ -> new")
|
||||||
|
@NotNull
|
||||||
public static ItemBuilder from(final ItemStack itemStack) {
|
public static ItemBuilder from(final ItemStack itemStack) {
|
||||||
return new ItemBuilder(itemStack);
|
return new ItemBuilder(itemStack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Keys {
|
public class Keys {
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ public class Keys {
|
|||||||
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
|
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
|
||||||
public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key");
|
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();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if (itemMeta == null) {
|
if (itemMeta == null) {
|
||||||
@@ -26,7 +27,7 @@ public class Keys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, Z> void setKey(
|
public static <T, Z> void setKey(
|
||||||
final ItemStack itemStack,
|
final @NotNull ItemStack itemStack,
|
||||||
final NamespacedKey key,
|
final NamespacedKey key,
|
||||||
final PersistentDataType<T, Z> type,
|
final PersistentDataType<T, Z> type,
|
||||||
final Z value) {
|
final Z value) {
|
||||||
@@ -41,7 +42,7 @@ public class Keys {
|
|||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasKey(final ItemStack itemStack) {
|
public static boolean hasKey(final @NotNull ItemStack itemStack) {
|
||||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if (itemMeta == null) {
|
if (itemMeta == null) {
|
||||||
@@ -51,7 +52,7 @@ public class Keys {
|
|||||||
return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE);
|
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();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if (itemMeta == null) {
|
if (itemMeta == null) {
|
||||||
@@ -62,7 +63,7 @@ public class Keys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if (itemMeta == null) {
|
if (itemMeta == null) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
@@ -8,15 +9,17 @@ public class StringUtils {
|
|||||||
* @param parsed message to be parsed
|
* @param parsed message to be parsed
|
||||||
* @return MiniMessage parsed string
|
* @return MiniMessage parsed string
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public static Component parse(final String parsed) {
|
public static Component parse(final String parsed) {
|
||||||
return Adventure.MINI_MESSAGE.deserialize(parsed);
|
return Adventure.MINI_MESSAGE.deserialize(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static String parseStringToString(final String parsed) {
|
public static String parseStringToString(final String parsed) {
|
||||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
|
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static String formatArmorItemType(String type) {
|
public static String formatArmorItemType(String type) {
|
||||||
type = type.toLowerCase();
|
type = type.toLowerCase();
|
||||||
final String[] parts = type.split(" ");
|
final String[] parts = type.split(" ");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class Utils {
|
|||||||
return original;
|
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;
|
if (predicate.test(original)) return replacement;
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class BasePacket {
|
public class BasePacket {
|
||||||
|
|
||||||
public static void sendPacket(Player player, PacketContainer packet) {
|
public static void sendPacket(Player player, PacketContainer packet) {
|
||||||
|
if (player == null) return;
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -31,11 +32,11 @@ import java.util.UUID;
|
|||||||
public class PacketManager extends BasePacket {
|
public class PacketManager extends BasePacket {
|
||||||
|
|
||||||
public static void sendEntitySpawnPacket(
|
public static void sendEntitySpawnPacket(
|
||||||
final Location location,
|
final @NotNull Location location,
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final EntityType entityType,
|
final EntityType entityType,
|
||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||||
packet.getModifier().writeDefaults();
|
packet.getModifier().writeDefaults();
|
||||||
@@ -64,7 +65,7 @@ public class PacketManager extends BasePacket {
|
|||||||
public static void ridingMountPacket(
|
public static void ridingMountPacket(
|
||||||
int mountId,
|
int mountId,
|
||||||
int passengerId,
|
int passengerId,
|
||||||
List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||||
packet.getIntegers().write(0, mountId);
|
packet.getIntegers().write(0, mountId);
|
||||||
@@ -84,7 +85,7 @@ public class PacketManager extends BasePacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void equipmentSlotUpdate(
|
public static void equipmentSlotUpdate(
|
||||||
Player player,
|
@NotNull Player player,
|
||||||
CosmeticSlot cosmetic,
|
CosmeticSlot cosmetic,
|
||||||
List<Player> sendTo
|
List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
@@ -111,7 +112,7 @@ public class PacketManager extends BasePacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void armorStandMetaPacket(
|
public static void armorStandMetaPacket(
|
||||||
Entity entity,
|
@NotNull Entity entity,
|
||||||
List<Player> sendTo
|
List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
@@ -134,7 +135,8 @@ public class PacketManager extends BasePacket {
|
|||||||
packet.getModifier().writeDefaults();
|
packet.getModifier().writeDefaults();
|
||||||
packet.getIntegers().write(0, entityId);
|
packet.getIntegers().write(0, entityId);
|
||||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||||
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
|
|
||||||
|
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||||
} else {
|
} else {
|
||||||
@@ -148,8 +150,8 @@ public class PacketManager extends BasePacket {
|
|||||||
|
|
||||||
public static void sendLookPacket(
|
public static void sendLookPacket(
|
||||||
int entityId,
|
int entityId,
|
||||||
Location location,
|
@NotNull Location location,
|
||||||
List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||||
packet.getIntegers().write(0, entityId);
|
packet.getIntegers().write(0, entityId);
|
||||||
@@ -167,9 +169,9 @@ public class PacketManager extends BasePacket {
|
|||||||
|
|
||||||
public static void sendRotationPacket(
|
public static void sendRotationPacket(
|
||||||
int entityId,
|
int entityId,
|
||||||
Location location,
|
@NotNull Location location,
|
||||||
boolean onGround,
|
boolean onGround,
|
||||||
List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
float yaw = location.getYaw() * ROTATION_FACTOR;
|
float yaw = location.getYaw() * ROTATION_FACTOR;
|
||||||
@@ -188,7 +190,7 @@ public class PacketManager extends BasePacket {
|
|||||||
int entityId,
|
int entityId,
|
||||||
int yaw,
|
int yaw,
|
||||||
boolean onGround,
|
boolean onGround,
|
||||||
List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
float yaw2 = yaw * ROTATION_FACTOR;
|
float yaw2 = yaw * ROTATION_FACTOR;
|
||||||
@@ -225,7 +227,7 @@ public class PacketManager extends BasePacket {
|
|||||||
public static void sendRidingPacket(
|
public static void sendRidingPacket(
|
||||||
final int mountId,
|
final int mountId,
|
||||||
final int passengerId,
|
final int passengerId,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||||
packet.getIntegers().write(0, mountId);
|
packet.getIntegers().write(0, mountId);
|
||||||
@@ -240,7 +242,7 @@ public class PacketManager extends BasePacket {
|
|||||||
* @param entityId The entity to delete for a player
|
* @param entityId The entity to delete for a player
|
||||||
* @param sendTo The players the packet should be sent to
|
* @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);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||||
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
||||||
for (final Player p : sendTo) sendPacket(p, packet);
|
for (final Player p : sendTo) sendPacket(p, packet);
|
||||||
@@ -251,7 +253,7 @@ public class PacketManager extends BasePacket {
|
|||||||
* @param entityId The Entity ID that camera will go towards
|
* @param entityId The Entity ID that camera will go towards
|
||||||
* @param sendTo The players that will be sent this packet
|
* @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);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
|
||||||
packet.getIntegers().write(0, entityId);
|
packet.getIntegers().write(0, entityId);
|
||||||
for (final Player p : sendTo) sendPacket(p, packet);
|
for (final Player p : sendTo) sendPacket(p, packet);
|
||||||
@@ -266,10 +268,10 @@ public class PacketManager extends BasePacket {
|
|||||||
* @param sendTo Who should it send the packet to?
|
* @param sendTo Who should it send the packet to?
|
||||||
*/
|
*/
|
||||||
public static void sendFakePlayerSpawnPacket(
|
public static void sendFakePlayerSpawnPacket(
|
||||||
final Location location,
|
final @NotNull Location location,
|
||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||||
wrapper.setEntityID(entityId);
|
wrapper.setEntityID(entityId);
|
||||||
@@ -304,19 +306,17 @@ public class PacketManager extends BasePacket {
|
|||||||
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
||||||
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
|
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
|
||||||
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
||||||
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
|
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1") || NMSHandlers.getVersion().contains("v1_19_R3")) {
|
||||||
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
|
|
||||||
} else {
|
|
||||||
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
|
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
|
||||||
wrappedGameProfile,
|
wrappedGameProfile,
|
||||||
0,
|
0,
|
||||||
EnumWrappers.NativeGameMode.CREATIVE,
|
EnumWrappers.NativeGameMode.CREATIVE,
|
||||||
WrappedChatComponent.fromText(name)
|
WrappedChatComponent.fromText(name)
|
||||||
)));
|
)));
|
||||||
|
} else {
|
||||||
|
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
|
||||||
}
|
}
|
||||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,7 +326,7 @@ public class PacketManager extends BasePacket {
|
|||||||
*/
|
*/
|
||||||
public static void sendPlayerOverlayPacket(
|
public static void sendPlayerOverlayPacket(
|
||||||
final int playerId,
|
final int playerId,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
0x01 = Is on fire
|
0x01 = Is on fire
|
||||||
@@ -363,7 +363,7 @@ public class PacketManager extends BasePacket {
|
|||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final List<Player> sendTo
|
final List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
|
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||||
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
||||||
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||||
|
|
||||||
@@ -376,6 +376,7 @@ public class PacketManager extends BasePacket {
|
|||||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
|
||||||
packet.getUUIDLists().write(0, List.of(uuid));
|
packet.getUUIDLists().write(0, List.of(uuid));
|
||||||
for (final Player p : sendTo) sendPacket(p, packet);
|
for (final Player p : sendTo) sendPacket(p, packet);
|
||||||
@@ -398,7 +399,7 @@ public class PacketManager extends BasePacket {
|
|||||||
public static void sendLeashPacket(
|
public static void sendLeashPacket(
|
||||||
final int leashedEntity,
|
final int leashedEntity,
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
|
||||||
packet.getIntegers().write(0, leashedEntity);
|
packet.getIntegers().write(0, leashedEntity);
|
||||||
@@ -417,9 +418,9 @@ public class PacketManager extends BasePacket {
|
|||||||
*/
|
*/
|
||||||
public static void sendTeleportPacket(
|
public static void sendTeleportPacket(
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final Location location,
|
final @NotNull Location location,
|
||||||
boolean onGround,
|
boolean onGround,
|
||||||
final List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||||
packet.getIntegers().write(0, entityId);
|
packet.getIntegers().write(0, entityId);
|
||||||
@@ -444,10 +445,10 @@ public class PacketManager extends BasePacket {
|
|||||||
*/
|
*/
|
||||||
public static void sendMovePacket(
|
public static void sendMovePacket(
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final Location from,
|
final @NotNull Location from,
|
||||||
final Location to,
|
final @NotNull Location to,
|
||||||
final boolean onGround,
|
final boolean onGround,
|
||||||
List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||||
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
|
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
|
||||||
@@ -470,6 +471,7 @@ public class PacketManager extends BasePacket {
|
|||||||
sendMovePacket(entityId, from, to, onGround, getViewers(to));
|
sendMovePacket(entityId, from, to, onGround, getViewers(to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static List<Player> getViewers(Location location) {
|
public static List<Player> getViewers(Location location) {
|
||||||
ArrayList<Player> viewers = new ArrayList();
|
ArrayList<Player> viewers = new ArrayList();
|
||||||
if (Settings.getViewDistance() <= 0) {
|
if (Settings.getViewDistance() <= 0) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketEvent;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
|
|||||||
* @param event - the packet event.
|
* @param event - the packet event.
|
||||||
* @return The spawned entity.
|
* @return The spawned entity.
|
||||||
*/
|
*/
|
||||||
public Entity getEntity(PacketEvent event) {
|
public Entity getEntity(@NotNull PacketEvent event) {
|
||||||
return getEntity(event.getPlayer().getWorld());
|
return getEntity(event.getPlayer().getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
|
|||||||
*
|
*
|
||||||
* @param position - the new position.
|
* @param position - the new position.
|
||||||
*/
|
*/
|
||||||
public void setPosition(Vector position) {
|
public void setPosition(@NotNull Vector position) {
|
||||||
setX(position.getX());
|
setX(position.getX());
|
||||||
setY(position.getY());
|
setY(position.getY());
|
||||||
setZ(position.getZ());
|
setZ(position.getZ());
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ public class WrapperPlayServerPlayerInfo extends AbstractPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAction(PlayerInfoAction value) {
|
public void setAction(PlayerInfoAction value) {
|
||||||
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
|
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||||
handle.getPlayerInfoAction().write(0, value);
|
handle.getPlayerInfoAction().write(0, value);
|
||||||
} else {
|
return;
|
||||||
handle.getPlayerInfoActions().write(0, Set.of(value));
|
|
||||||
}
|
}
|
||||||
|
// New way of handling it 1.19.3+
|
||||||
|
handle.getPlayerInfoActions().write(0, Set.of(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PlayerInfoData> getData() {
|
public List<PlayerInfoData> getData() {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
||||||
public static final PacketType TYPE =
|
public static final PacketType TYPE =
|
||||||
@@ -55,7 +56,7 @@ public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
|||||||
* @param event - the packet event.
|
* @param event - the packet event.
|
||||||
* @return The spawned entity.
|
* @return The spawned entity.
|
||||||
*/
|
*/
|
||||||
public Entity getEntity(PacketEvent event) {
|
public Entity getEntity(@NotNull PacketEvent event) {
|
||||||
return getEntity(event.getPlayer().getWorld());
|
return getEntity(event.getPlayer().getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ cosmetic-settings:
|
|||||||
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
|
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-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 where the camera is placed (prevents players viewing through blocks)
|
||||||
|
emote-damage-leave: true # If the player should leave the emote when they take damage
|
||||||
|
emote-invincible: false # If the player should not take damage while doing an emote
|
||||||
|
|
||||||
|
helmet-add-enchantments: false # If the plugin should keep enchants on helmets. This is useful as some enchantments are client side only.
|
||||||
|
chest-add-enchantments: false # If the plugin should keep enchants on chestplate. This is useful as some enchantments are client side only.
|
||||||
|
leggings-add-enchantments: false # If the plugin should keep enchants on leggings. This is useful as some enchantments are client side only.
|
||||||
|
boots-add-enchantments: false # If the plugin should keep enchants on boots. This is useful as some enchantments are client side only.
|
||||||
|
|
||||||
# view distance in blocks that other players will see the backpack cosmetic
|
# 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
|
# setting this to lower than the server player view distance should fix the
|
||||||
@@ -35,11 +43,20 @@ cosmetic-settings:
|
|||||||
y: 3
|
y: 3
|
||||||
z: 0.5
|
z: 0.5
|
||||||
dye-menu:
|
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>"
|
# If you use Oraxen, set this to "<glyph:neg_shift_8><glyph:dye_menu>"
|
||||||
title: "§f"
|
title: "§f"
|
||||||
input-slot: 19
|
input-slot: 19
|
||||||
output-slot: 25
|
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
|
||||||
|
worldguard:
|
||||||
|
# Checks worldguard regions for HMCC flags. If set to false, flags will not work properly.
|
||||||
|
# Requires restart to apply changes.
|
||||||
|
player_move_check: true
|
||||||
wardrobe:
|
wardrobe:
|
||||||
# spawn static wardrobe if in this radius of wardrobe-location
|
# spawn static wardrobe if in this radius of wardrobe-location
|
||||||
static-radius: 10
|
static-radius: 10
|
||||||
@@ -58,6 +75,8 @@ wardrobe:
|
|||||||
color: BLUE
|
color: BLUE
|
||||||
transition:
|
transition:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
# If you use ItemsAdder, set this to "<black>%img_title%
|
||||||
|
# If you use Oraxen, set this to "<black><glyph:title>"
|
||||||
text: "<black>"
|
text: "<black>"
|
||||||
delay: 40
|
delay: 40
|
||||||
title-fade-in: 1000 # milliseconds
|
title-fade-in: 1000 # milliseconds
|
||||||
|
|||||||
BIN
lib/CMI-API9.3.1.5.jar
Normal file
BIN
lib/CMI-API9.3.1.5.jar
Normal file
Binary file not shown.
BIN
lib/CMILib1.2.4.6.jar
Normal file
BIN
lib/CMILib1.2.4.6.jar
Normal file
Binary file not shown.
@@ -11,5 +11,6 @@ include(
|
|||||||
"v1_17_R1",
|
"v1_17_R1",
|
||||||
"v1_18_R2",
|
"v1_18_R2",
|
||||||
"v1_19_R1",
|
"v1_19_R1",
|
||||||
"v1_19_R2"
|
"v1_19_R2",
|
||||||
|
"v1_19_R3",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import net.minecraft.world.level.Level;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
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);
|
super(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvisibleArmorstand(Location loc) {
|
public HMCArmorStand(Location loc) {
|
||||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||||
setInvisible(true);
|
setInvisible(true);
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user