9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-26 18:39:07 +00:00

Compare commits

...

45 Commits

Author SHA1 Message Date
LoJoSho
17abd0c8cc feat: Improvements to emote block checking 2023-03-11 20:48:09 -06:00
LoJoSho
a907cd51b9 feat: Add CMI vanish support 2023-03-11 20:07:01 -06:00
LoJoSho
9f6c7db8fd fix: kicking while interacting in emote/wardrobe #76 2023-03-11 19:20:35 -06:00
LoJoSho
2ba83d8cc5 fix: default color being white 2023-03-10 16:06:51 -06:00
LoJoSho
40bf0e173e version bump (2.2.5-DEV) 2023-03-10 16:06:46 -06:00
LoJoSho
a757292b4b version bump (2.2.4) 2023-03-09 19:14:33 -06:00
LoJoSho
b41d466546 fix: action menu not using debug method 2023-03-09 19:09:42 -06:00
LoJoSho
135fdc94d4 fix: sound debug was wrong level 2023-03-09 19:08:21 -06:00
LoJoSho
d0092a2ffe clean: refactor spelling mistake in isBackpackSpawned 2023-03-02 19:19:45 -06:00
LoJoSho
acf31009d5 feat: backpack improvements 2023-03-02 19:19:08 -06:00
LoJoSho
981c6155e7 feat: add all to unapply command 2023-03-01 10:45:06 -06:00
LoJoSho
2ecc86fc7b fix: same issue as before but with cosmetic wardrobe flag 2023-03-01 10:27:27 -06:00
LoJoSho
2682428354 fix: worldguard flag hiding cosmetics when on allow 2023-03-01 10:21:40 -06:00
LoJoSho
df8ad26684 fix: Flying with elytra and teleporting with backpack causing NPE 2023-03-01 10:14:05 -06:00
LoJoSho
1f714c0153 -1 in wardrobe static radius now returns true 2023-03-01 10:09:18 -06:00
LoJoSho
0bfadad222 Reload IA on change option (Legacy IA hook option) 2023-03-01 10:02:27 -06:00
LoJoSho
a1c719fc50 version bump (2.2.4-DEV) 2023-03-01 10:02:05 -06:00
Craftinators
fe9812cd69 clean: suppress warnings 2023-03-01 08:56:49 -05:00
Craftinators
b9699b27c7 fix: spelling errors 2023-03-01 00:52:13 -05:00
Craftinators
2c5ddb542e clean: remove unused import 2023-03-01 00:44:27 -05:00
Craftinators
461642d64b clean: make Type abstract 2023-03-01 00:44:00 -05:00
Craftinators
37a8a2379d clean: add @NotNull & remove import 2023-02-28 22:25:13 -05:00
LoJoSho
e698392e40 Merge pull request #74 from Craftinators/remapped
`Action` Abstraction
2023-02-28 18:54:02 -06:00
Craftinators
e1357b265f clean: use final 2023-02-28 14:50:16 -05:00
Craftinators
a5475b0268 clean: prefer not to use var 2023-02-28 14:50:03 -05:00
Craftinators
60dba9efa6 fix: use parseFloat instead of valueOf 2023-02-28 14:41:46 -05:00
Craftinators
e2d3391070 clean: reduce nesting 2023-02-28 14:40:58 -05:00
Craftinators
aed34ec28d clean: reduce nesting 2023-02-28 14:35:08 -05:00
Craftinators
ae6d88ab56 clean: make Action abstract 2023-02-28 14:34:03 -05:00
LoJoSho
35be7283e9 Merge pull request #72 from Craftinators/remapped
`CosmeticType` Abstraction
2023-02-28 09:32:30 -06:00
Craftinators
224fcb83d9 clean: config to local 2023-02-28 01:03:11 -05:00
Craftinators
98934536be clean: make Cosmetic abstract 2023-02-28 01:02:52 -05:00
LoJoSho
5ac3712e56 Merge pull request #71 from Craftinators/remapped
Database structure changes
2023-02-27 21:57:40 -06:00
Craftinators
2d2d4e6d44 clean: remove TODO 2023-02-27 22:55:33 -05:00
Craftinators
4b1921b754 clean: try-with-resource to SuppressWarnings 2023-02-27 22:55:12 -05:00
Craftinators
8ca1d44375 clean: add error message 2023-02-27 15:36:50 -05:00
Craftinators
23c82cc6ed fix: additional null checks 2023-02-27 15:34:42 -05:00
Craftinators
2bf5280827 fix: reorder null checks 2023-02-27 15:29:50 -05:00
Craftinators
475a1e0ef1 fix: add Class.forName(...) back 2023-02-27 13:06:23 -05:00
Craftinators
ef4d53eb85 fix: throw error if file isn't created 2023-02-27 12:57:12 -05:00
Craftinators
97da4f7809 feat: add SQLData class 2023-02-27 12:53:51 -05:00
Craftinators
1622dac67f clean: cleanup openConnection() 2023-02-27 12:26:43 -05:00
Craftinators
fce1ec5042 refactor: use try-with-resources 2023-02-27 12:23:30 -05:00
Craftinators
060bcc95e1 clean: reorganize MySQLData 2023-02-27 12:20:26 -05:00
Craftinators
5aca80609a feat: make Data abstract 2023-02-27 12:11:09 -05:00
40 changed files with 407 additions and 297 deletions

1
.gitignore vendored
View File

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

View File

@@ -8,7 +8,7 @@ plugins {
} }
group = "com.hibiscusmc" group = "com.hibiscusmc"
version = "2.2.3" version = "2.2.5-DEV"
allprojects { allprojects {
apply(plugin = "java") apply(plugin = "java")
@@ -62,7 +62,7 @@ allprojects {
} }
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 +77,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")
} }
} }

View File

@@ -28,6 +28,9 @@ 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.List;
import java.util.Set;
public class CosmeticCommand implements CommandExecutor { public class CosmeticCommand implements CommandExecutor {
// cosmetics apply cosmetics playerName // cosmetics apply cosmetics playerName
@@ -92,7 +95,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")) {
@@ -148,19 +151,11 @@ public class CosmeticCommand implements CommandExecutor {
return true; return true;
} }
CosmeticSlot cosmeticSlot;
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;
@@ -168,20 +163,34 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player); CosmeticUser user = CosmeticUsers.getUser(player);
if (user.getCosmetic(cosmeticSlot) == null) { Set<CosmeticSlot> cosmeticSlots;
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
return true; if (args[1].equalsIgnoreCase("all")) {
cosmeticSlots = user.getSlotsWithCosmetics();
} else {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
return true;
}
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
} }
TagResolver placeholders = for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()), if (user.getCosmetic(cosmeticSlot) == null) {
TagResolver.resolver(Placeholder.parsed("player", player.getName())), if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name()))); continue;
}
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders); TagResolver placeholders =
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
user.removeCosmeticSlot(cosmeticSlot); if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
user.updateCosmetic(cosmeticSlot);
user.removeCosmeticSlot(cosmeticSlot);
user.updateCosmetic(cosmeticSlot);
}
return true; return true;
} }
case ("wardrobe") -> { case ("wardrobe") -> {

View File

@@ -59,6 +59,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
for (Cosmetic cosmetic : user.getCosmetic()) { for (Cosmetic cosmetic : user.getCosmetic()) {
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()) {

View File

@@ -32,6 +32,10 @@ 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 COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static String defaultMenu; private static String defaultMenu;
private static String dyeMenuName; private static String dyeMenuName;
@@ -46,6 +50,8 @@ 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 cosmeticEmoteBlockCheck;
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 +83,7 @@ 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);
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 +98,10 @@ 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);
} }
private static Vector loadVector(final ConfigurationNode config) { private static Vector loadVector(final ConfigurationNode config) {
@@ -190,6 +201,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 +222,11 @@ public class Settings {
public static double getEmoteDistance() { public static double getEmoteDistance() {
return emoteDistance; return emoteDistance;
} }
public static boolean getCosmeticEmoteBlockCheck() {
return cosmeticEmoteBlockCheck;
}
public static void setDebugMode(boolean newSetting) { public static void setDebugMode(boolean newSetting) {
debugMode = newSetting; debugMode = newSetting;

View File

@@ -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;
} }

View File

@@ -12,7 +12,7 @@ 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;
@@ -22,6 +22,7 @@ public class Cosmetic {
protected Cosmetic(String id, @NotNull 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 {
@@ -31,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() {
@@ -54,6 +55,11 @@ 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;
} }
@@ -62,10 +68,6 @@ public class Cosmetic {
return permission != null; return permission != null;
} }
public void setId(String id) {
this.id = id;
}
public void setDyable(boolean dyable) { public void setDyable(boolean dyable) {
this.dyable = dyable; this.dyable = 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() {

View File

@@ -33,6 +33,4 @@ public class CosmeticArmorType extends Cosmetic {
public EquipmentSlot getEquipSlot() { public EquipmentSlot getEquipSlot() {
return this.equipSlot; return this.equipSlot;
} }
} }

View File

@@ -2,6 +2,7 @@ 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.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;
@@ -12,13 +13,13 @@ import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticBackpackType extends Cosmetic { public class CosmeticBackpackType extends Cosmetic {
private final 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
@@ -28,14 +29,20 @@ public class CosmeticBackpackType extends Cosmetic {
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 (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) {
user.getUserBackpackManager().getArmorStand().teleport(loc); 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();
@@ -44,4 +51,8 @@ public class CosmeticBackpackType extends Cosmetic {
public String getModelName() { public String getModelName() {
return modelName; return modelName;
} }
public UserBackpackManager.BackpackType getBackpackType() {
return backpackType;
}
} }

View File

@@ -19,7 +19,6 @@ public class CosmeticBalloonType extends Cosmetic {
private final 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);
@@ -27,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);
@@ -89,10 +80,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);
}
*/
} }

View File

@@ -17,27 +17,20 @@ 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 serializeData(@NotNull 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())) {
@@ -57,7 +50,8 @@ public class Data {
return data; return data;
} }
public Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull 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();

View File

@@ -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, serializeData(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 = 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
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()) { // Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
return; // ...
// });
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
// Connection isn't null AND Connection isn't closed :: return
try {
if (isConnectionOpen()) {
return;
} else if (connection != null) close(); // Close connection if still active
} catch (RuntimeException e) {
e.printStackTrace(); // If isConnectionOpen() throws error
} }
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
//close Connection if still active // Connect to database host
if (connection != null) { try {
close(); Class.forName("com.mysql.jdbc.Driver");
} connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
} catch (SQLException e) {
//connect to database host System.out.println(e.getMessage());
try { } catch (ClassNotFoundException e) {
Class.forName("com.mysql.jdbc.Driver"); throw new RuntimeException(e);
}
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
//});
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
} }
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,7 +111,7 @@ public class MySQLData extends Data {
return props; return props;
} }
private boolean isConnectionOpen() { private boolean isConnectionOpen() throws RuntimeException {
try { try {
return connection != null && !connection.isClosed(); return connection != null && !connection.isClosed();
} catch (SQLException e) { } catch (SQLException e) {
@@ -166,16 +119,21 @@ public class MySQLData extends Data {
} }
} }
@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;
} }
} }

View File

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

View File

@@ -1,31 +1,28 @@
package com.hibiscusmc.hmccosmetics.database.types; 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, serializeData(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 = 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
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,43 +55,41 @@ public class SQLiteData extends Data {
}); });
} }
private void openConnection() throws SQLException { private void openConnection() throws SQLException {
if (connection != null && !connection.isClosed()) { // Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
return; // ...
} // });
//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;
// 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;
} }

View File

@@ -3,7 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class Action { public abstract class Action {
private final String id; private final String id;
@@ -16,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
}
} }

View File

@@ -9,23 +9,24 @@ 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 final 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(@NotNull String id) { public static Action getAction(@NotNull String id) {

View File

@@ -15,5 +15,4 @@ public class ActionConsoleCommand extends Action {
public void run(@NotNull 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);
} }
} }

View File

@@ -12,8 +12,7 @@ public class ActionCosmeticHide extends Action {
@Override @Override
public void run(@NotNull 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);
}
} }
} }

View File

@@ -12,9 +12,10 @@ public class ActionCosmeticShow extends Action {
@Override @Override
public void run(@NotNull 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
user.showCosmetics(); // Do not hide if it's already off for WG
} if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
} }
} }

View File

@@ -17,6 +17,7 @@ public class ActionCosmeticToggle extends Action {
user.showCosmetics(); user.showCosmetics();
return; return;
} }
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION); user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
} }
} }

View File

@@ -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);
} }
} }

View File

@@ -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);
} }
} }

View File

@@ -9,6 +9,7 @@ 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;
@@ -22,17 +23,17 @@ public class ActionParticle extends Action {
} }
@Override @Override
@SuppressWarnings("ConstantConditions")
public void run(CosmeticUser user, @NotNull String raw) { 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)) {

View File

@@ -25,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);
} }

View File

@@ -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);
} }

View File

@@ -8,7 +8,6 @@ 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.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
@@ -57,7 +56,7 @@ public class DyeMenu {
gui.open(player); gui.open(player);
} }
private static void addCosmetic(CosmeticUser user, Cosmetic cosmetic, Color color) { private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
Player player = user.getPlayer(); Player player = user.getPlayer();
user.addPlayerCosmetic(cosmetic, color); user.addPlayerCosmetic(cosmetic, color);
player.setItemOnCursor(new ItemStack(Material.AIR)); player.setItemOnCursor(new ItemStack(Material.AIR));

View File

@@ -5,7 +5,7 @@ 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 final String id; private final String 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);
}
} }

View File

@@ -149,6 +149,7 @@ public class TypeCosmetic extends Type {
@Contract("_, _ -> param2") @Contract("_, _ -> param2")
@NotNull @NotNull
@SuppressWarnings("Duplicates")
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) { private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>(); List<String> processedLore = new ArrayList<>();

View File

@@ -3,7 +3,6 @@ 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;
@@ -18,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.
@@ -34,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) {
@@ -54,6 +52,7 @@ public class TypeEmpty extends Type {
} }
@Override @Override
@SuppressWarnings("Duplicates")
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, @NotNull ItemMeta itemMeta) { public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>(); List<String> processedLore = new ArrayList<>();

View File

@@ -2,6 +2,7 @@ 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.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;
@@ -26,6 +27,7 @@ public class Hooks {
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 HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
private static HookCMI CMI_HOOK = new HookCMI();
public static Hook getHook(@NotNull String id) { public static Hook getHook(@NotNull String id) {
return hooks.get(id.toLowerCase()); return hooks.get(id.toLowerCase());

View File

@@ -1,6 +1,7 @@
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;
@@ -11,8 +12,6 @@ import org.bukkit.inventory.ItemStack;
public class HookItemAdder extends Hook implements Listener { public class HookItemAdder extends Hook implements Listener {
// I hate IA, this overcomplicate stuff is so unneeded if it just did its stuff when its needed.
private boolean enabled = false; private boolean enabled = false;
public HookItemAdder() { public HookItemAdder() {
@@ -33,7 +32,7 @@ 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 if (enabled && !Settings.getItemsAdderReloadChange()) return; // Defaultly it will only run once at startup. If hook setting is enable
this.enabled = true; this.enabled = true;
HMCCosmeticsPlugin.setup(); HMCCosmeticsPlugin.setup();
} }

View File

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

View File

@@ -32,10 +32,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();
} }
} }

View File

@@ -51,6 +51,7 @@ public class PlayerGameListener implements Listener {
registerMenuChangeListener(); registerMenuChangeListener();
registerPlayerEquipmentListener(); registerPlayerEquipmentListener();
registerPlayerArmListener(); registerPlayerArmListener();
registerEntityUseListener();
//registerLookMovement(); //registerLookMovement();
//registerMoveListener(); //registerMoveListener();
@@ -101,7 +102,7 @@ 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());
@@ -173,7 +174,7 @@ 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()) { if (!user.isBackpackSpawned()) {
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK)); user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
} }
return; return;
@@ -406,6 +407,21 @@ public class PlayerGameListener implements Listener {
}); });
} }
private void registerEntityUseListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
event.setCancelled(true);
}
}
});
}
private void registerLookMovement() { 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

View File

@@ -151,6 +151,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 +291,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 +301,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;
} }
@@ -401,7 +405,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 +431,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");

View File

@@ -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;
@@ -18,13 +21,14 @@ public class UserBackpackManager {
private boolean hideBackpack; private boolean hideBackpack;
private ArmorStand invisibleArmorStand; private ArmorStand invisibleArmorStand;
private AreaEffectCloud particleCloud;
private final CosmeticUser user; 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() {
@@ -38,6 +42,16 @@ public class UserBackpackManager {
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start"); MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
if (getBackpackType().equals(BackpackType.NORMAL)) {
spawnNormalBackpack(cosmeticBackpackType);
}
if (getBackpackType().equals(BackpackType.FIRST_PERSON)) {
spawnFirstPersonBackpack(cosmeticBackpackType);
}
}
private void spawnNormalBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.invisibleArmorStand != null) return; if (this.invisibleArmorStand != null) return;
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType); this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
@@ -56,11 +70,37 @@ public class UserBackpackManager {
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish"); MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
} }
public void spawnFirstPersonBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.invisibleArmorStand != null) return;
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
}
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
}
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() {
@@ -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

View File

@@ -57,7 +57,7 @@ public class UserEmoteModel extends PlayerModel {
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;

View File

@@ -24,6 +24,7 @@ cosmetic-settings:
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server. 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 (prevents players viewing through blocks)
# 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
@@ -40,6 +41,11 @@ 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
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

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

Binary file not shown.

BIN
lib/CMILib1.2.4.6.jar Normal file

Binary file not shown.