Skip to content

Commit f63fb7c

Browse files
Commands for setting new parameters
1 parent 10215bc commit f63fb7c

File tree

11 files changed

+348
-264
lines changed

11 files changed

+348
-264
lines changed

src/main/java/me/general_breddok/blockdisplaycreator/command/capi/BlockDisplayCreatorCAPICommand.java

Lines changed: 104 additions & 7 deletions
Large diffs are not rendered by default.

src/main/java/me/general_breddok/blockdisplaycreator/custom/ConfiguredCollisionDta.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
@EqualsAndHashCode
2222
@FieldDefaults(level = AccessLevel.PRIVATE)
2323
public class ConfiguredCollisionDta implements ConfiguredCollision {
24-
final String identifier;
2524
@NotNull
2625
Summoner<Shulker> summoner;
26+
@NotNull
27+
final String identifier;
2728
@Nullable
2829
Vector offset;
2930
double size;
@@ -42,19 +43,6 @@ public ConfiguredCollisionDta(Summoner<Shulker> summoner, String identifier) {
4243
this(summoner, identifier, null, 1, false);
4344
}
4445

45-
public static void setScale(Shulker shulker, double size) {
46-
if (size <= 0 || size == 1) {
47-
return;
48-
}
49-
50-
Attribute scaleAttribute = VersionCompat.getScaleAttribute();
51-
52-
if (scaleAttribute == null)
53-
return;
54-
55-
shulker.getAttribute(scaleAttribute).setBaseValue(size);
56-
}
57-
5846
@Override
5947
public Shulker summon(@NotNull Location location) {
6048
VersionManager versionManager = BlockDisplayCreator.getInstance().getVersionManager();
@@ -87,6 +75,19 @@ public Shulker summon(@NotNull Location location) {
8775
return shulker;
8876
}
8977

78+
private static void setScale(Shulker shulker, double size) {
79+
if (size <= 0 || size == 1) {
80+
return;
81+
}
82+
83+
Attribute scaleAttribute = VersionCompat.getScaleAttribute();
84+
85+
if (scaleAttribute == null)
86+
return;
87+
88+
shulker.getAttribute(scaleAttribute).setBaseValue(size);
89+
}
90+
9091
@Override
9192
public ConfiguredCollisionDta clone() {
9293
Summoner<Shulker> clonedSummoner = DeepCloneable.tryClone(this.summoner);

src/main/java/me/general_breddok/blockdisplaycreator/custom/ConfiguredInteractionDta.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
@EqualsAndHashCode
1717
@FieldDefaults(level = AccessLevel.PRIVATE)
1818
public class ConfiguredInteractionDta implements ConfiguredInteraction {
19-
final String identifier;
19+
@NotNull
2020
Summoner<Interaction> summoner;
21+
@NotNull
22+
final String identifier;
2123
@Nullable
2224
Vector offset;
2325
@Nullable

src/main/java/me/general_breddok/blockdisplaycreator/custom/block/BDCCustomBlockService.java

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -63,95 +63,6 @@ public BDCCustomBlockService(CustomBlockStorage storage) {
6363
this.storage = storage;
6464
}
6565

66-
public static void applyDisplayTranslationRotation(@NotNull GroupSummoner<Display> displaySummoner, Display display) {
67-
if (displaySummoner instanceof TranslationVectorAdjustable translationVectorAdjustable) {
68-
DirectedVector translation = translationVectorAdjustable.getTranslation();
69-
if (translation != null) {
70-
EntityRotation displayRotation = new EntityRotation(display);
71-
displayRotation.addRotation(translation.getYaw(), translation.getPitch());
72-
displayRotation.applyToEntity(display);
73-
}
74-
}
75-
}
76-
77-
/**
78-
* Creates a {@link CustomBlockData} from its location and stores all block data there
79-
*
80-
* @param customBlock the custom block to create data for
81-
* @param displayVehicleUuids list of UUIDs of display vehicles associated with the custom block
82-
* @return a {@link CustomBlockData} instance containing the custom block's data
83-
*/
84-
public static CustomBlockData createCustomBlockData(CustomBlock customBlock, List<UUID> displayVehicleUuids) {
85-
CustomBlockData customBlockData = new CustomBlockData(customBlock.getLocation().getBlock(), BlockDisplayCreator.getInstance());
86-
customBlockData.set(CustomBlockKey.NAME, PersistentDataType.STRING, customBlock.getName());
87-
customBlockData.set(CustomBlockKey.SERVICE_CLASS, PersistentDataType.STRING, BDCCustomBlockService.class.getName());
88-
customBlockData.set(CustomBlockKey.DISPLAY_UUID, PersistentDataTypes.UUID_ARRAY, displayVehicleUuids.toArray(UUID[]::new));
89-
customBlockData.set(CustomBlockKey.INTERACTION_UUID, PersistentDataTypes.UUID_ARRAY, customBlock.getInteractions().stream().map(Entity::getUniqueId).toList().toArray(UUID[]::new));
90-
customBlockData.set(CustomBlockKey.COLLISION_UUID, PersistentDataTypes.UUID_ARRAY, customBlock.getCollisions().stream().map(Entity::getUniqueId).toList().toArray(UUID[]::new));
91-
customBlockData.set(CustomBlockKey.BLOCK_ROTATION, PersistentDataTypes.CUSTOM_BLOCK_ROTATION, customBlock.getRotation());
92-
customBlockData.set(CustomBlockKey.CUSTOM_BLOCK_UUID, PersistentDataTypes.UUID, customBlock.getUuid());
93-
if (customBlock.getSaveSystem().equals("item")) {
94-
GroupSummoner<Display> displaySummoner = customBlock.getDisplaySummoner();
95-
if (displaySummoner instanceof AutomaticCommandDisplaySummoner automaticCommandDisplaySummoner) {
96-
customBlockData.set(CustomBlockKey.DISPLAY_SPAWN_COMMAND, PersistentDataTypes.COMMAND_ARRAY, automaticCommandDisplaySummoner.getCommands().toArray(CommandLine[]::new));
97-
}
98-
}
99-
return customBlockData;
100-
}
101-
102-
/**
103-
* Triggers the {@link CustomBlockPlaceEvent} and handles cancellation
104-
*
105-
* @param customBlock the custom block that was placed
106-
* @param player the player who placed the block (nullable)
107-
* @param customBlockData the custom block data associated with the block's location
108-
* @return true if the event was not cancelled, false if it was
109-
*/
110-
private static boolean triggerCustomBlockPlaceEvent(CustomBlock customBlock, Player player, CustomBlockData customBlockData) {
111-
CustomBlockPlaceEvent customBlockPlaceEvent = new CustomBlockPlaceEvent(customBlock, player);
112-
// If the event is canceled, remove all entities and clear the block data
113-
if (!EventUtil.call(customBlockPlaceEvent)) {
114-
customBlock.getDisplays().forEach(Entity::remove);
115-
customBlock.getInteractions().forEach(Entity::remove);
116-
customBlock.getCollisions().forEach(Entity::remove);
117-
clearCustomBlockData(customBlockData);
118-
customBlock.getLocation().getBlock().setType(Material.AIR);
119-
return false;
120-
}
121-
return true;
122-
}
123-
124-
/**
125-
* Triggers the {@link CustomBlockBreakEvent} and handles cancellation
126-
*
127-
* @param customBlock the custom block that is being broken
128-
* @param player the player who is breaking the block (nullable)
129-
* @return true if the event was not cancelled, false if it was
130-
*/
131-
private static boolean triggerCustomBlockBreakEvent(CustomBlock customBlock, Player player) {
132-
CustomBlockBreakEvent customBlockBreakEvent = new CustomBlockBreakEvent(customBlock, player);
133-
return EventUtil.call(customBlockBreakEvent);
134-
}
135-
136-
/**
137-
* Clears all custom block data from the provided {@link CustomBlockData} instance
138-
*
139-
* @param customBlockData the custom block data to clear
140-
*/
141-
public static void clearCustomBlockData(CustomBlockData customBlockData) {
142-
customBlockData.remove(CustomBlockKey.NAME);
143-
customBlockData.remove(CustomBlockKey.SERVICE_CLASS);
144-
customBlockData.remove(CustomBlockKey.DISPLAY_UUID);
145-
customBlockData.remove(CustomBlockKey.INTERACTION_UUID);
146-
customBlockData.remove(CustomBlockKey.COLLISION_UUID);
147-
customBlockData.remove(CustomBlockKey.BLOCK_ROTATION);
148-
customBlockData.remove(CustomBlockKey.CUSTOM_BLOCK_UUID);
149-
customBlockData.remove(CustomBlockKey.DISPLAY_SPAWN_COMMAND);
150-
151-
customBlockData.remove(CustomBlockKey.ITEM);
152-
customBlockData.remove(CustomBlockKey.DISPLAY_SPAWN_COMMAND);
153-
}
154-
15566
/**
15667
* {@inheritDoc}
15768
*/
@@ -617,4 +528,93 @@ public boolean breakBlock(@NotNull CustomBlock customBlock, @Nullable Player pla
617528

618529
return true;
619530
}
531+
532+
public static void applyDisplayTranslationRotation(@NotNull GroupSummoner<Display> displaySummoner, Display display) {
533+
if (displaySummoner instanceof TranslationVectorAdjustable translationVectorAdjustable) {
534+
DirectedVector translation = translationVectorAdjustable.getTranslation();
535+
if (translation != null) {
536+
EntityRotation displayRotation = new EntityRotation(display);
537+
displayRotation.addRotation(translation.getYaw(), translation.getPitch());
538+
displayRotation.applyToEntity(display);
539+
}
540+
}
541+
}
542+
543+
/**
544+
* Creates a {@link CustomBlockData} from its location and stores all block data there
545+
*
546+
* @param customBlock the custom block to create data for
547+
* @param displayVehicleUuids list of UUIDs of display vehicles associated with the custom block
548+
* @return a {@link CustomBlockData} instance containing the custom block's data
549+
*/
550+
public static CustomBlockData createCustomBlockData(CustomBlock customBlock, List<UUID> displayVehicleUuids) {
551+
CustomBlockData customBlockData = new CustomBlockData(customBlock.getLocation().getBlock(), BlockDisplayCreator.getInstance());
552+
customBlockData.set(CustomBlockKey.NAME, PersistentDataType.STRING, customBlock.getName());
553+
customBlockData.set(CustomBlockKey.SERVICE_CLASS, PersistentDataType.STRING, BDCCustomBlockService.class.getName());
554+
customBlockData.set(CustomBlockKey.DISPLAY_UUID, PersistentDataTypes.UUID_ARRAY, displayVehicleUuids.toArray(UUID[]::new));
555+
customBlockData.set(CustomBlockKey.INTERACTION_UUID, PersistentDataTypes.UUID_ARRAY, customBlock.getInteractions().stream().map(Entity::getUniqueId).toList().toArray(UUID[]::new));
556+
customBlockData.set(CustomBlockKey.COLLISION_UUID, PersistentDataTypes.UUID_ARRAY, customBlock.getCollisions().stream().map(Entity::getUniqueId).toList().toArray(UUID[]::new));
557+
customBlockData.set(CustomBlockKey.BLOCK_ROTATION, PersistentDataTypes.CUSTOM_BLOCK_ROTATION, customBlock.getRotation());
558+
customBlockData.set(CustomBlockKey.CUSTOM_BLOCK_UUID, PersistentDataTypes.UUID, customBlock.getUuid());
559+
if (customBlock.getSaveSystem().equals("item")) {
560+
GroupSummoner<Display> displaySummoner = customBlock.getDisplaySummoner();
561+
if (displaySummoner instanceof AutomaticCommandDisplaySummoner automaticCommandDisplaySummoner) {
562+
customBlockData.set(CustomBlockKey.DISPLAY_SPAWN_COMMAND, PersistentDataTypes.COMMAND_ARRAY, automaticCommandDisplaySummoner.getCommands().toArray(CommandLine[]::new));
563+
}
564+
}
565+
return customBlockData;
566+
}
567+
568+
/**
569+
* Triggers the {@link CustomBlockPlaceEvent} and handles cancellation
570+
*
571+
* @param customBlock the custom block that was placed
572+
* @param player the player who placed the block (nullable)
573+
* @param customBlockData the custom block data associated with the block's location
574+
* @return true if the event was not cancelled, false if it was
575+
*/
576+
private static boolean triggerCustomBlockPlaceEvent(CustomBlock customBlock, Player player, CustomBlockData customBlockData) {
577+
CustomBlockPlaceEvent customBlockPlaceEvent = new CustomBlockPlaceEvent(customBlock, player);
578+
// If the event is canceled, remove all entities and clear the block data
579+
if (!EventUtil.call(customBlockPlaceEvent)) {
580+
customBlock.getDisplays().forEach(Entity::remove);
581+
customBlock.getInteractions().forEach(Entity::remove);
582+
customBlock.getCollisions().forEach(Entity::remove);
583+
clearCustomBlockData(customBlockData);
584+
customBlock.getLocation().getBlock().setType(Material.AIR);
585+
return false;
586+
}
587+
return true;
588+
}
589+
590+
/**
591+
* Triggers the {@link CustomBlockBreakEvent} and handles cancellation
592+
*
593+
* @param customBlock the custom block that is being broken
594+
* @param player the player who is breaking the block (nullable)
595+
* @return true if the event was not cancelled, false if it was
596+
*/
597+
private static boolean triggerCustomBlockBreakEvent(CustomBlock customBlock, Player player) {
598+
CustomBlockBreakEvent customBlockBreakEvent = new CustomBlockBreakEvent(customBlock, player);
599+
return EventUtil.call(customBlockBreakEvent);
600+
}
601+
602+
/**
603+
* Clears all custom block data from the provided {@link CustomBlockData} instance
604+
*
605+
* @param customBlockData the custom block data to clear
606+
*/
607+
public static void clearCustomBlockData(CustomBlockData customBlockData) {
608+
customBlockData.remove(CustomBlockKey.NAME);
609+
customBlockData.remove(CustomBlockKey.SERVICE_CLASS);
610+
customBlockData.remove(CustomBlockKey.DISPLAY_UUID);
611+
customBlockData.remove(CustomBlockKey.INTERACTION_UUID);
612+
customBlockData.remove(CustomBlockKey.COLLISION_UUID);
613+
customBlockData.remove(CustomBlockKey.BLOCK_ROTATION);
614+
customBlockData.remove(CustomBlockKey.CUSTOM_BLOCK_UUID);
615+
customBlockData.remove(CustomBlockKey.DISPLAY_SPAWN_COMMAND);
616+
617+
customBlockData.remove(CustomBlockKey.ITEM);
618+
customBlockData.remove(CustomBlockKey.DISPLAY_SPAWN_COMMAND);
619+
}
620620
}

src/main/java/me/general_breddok/blockdisplaycreator/data/yaml/YamlConfigFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.AccessLevel;
44
import lombok.experimental.FieldDefaults;
5+
import me.general_breddok.blockdisplaycreator.BlockDisplayCreator;
56
import me.general_breddok.blockdisplaycreator.data.locator.ConfigLocator;
67
import me.general_breddok.blockdisplaycreator.file.CachedFile;
78
import me.general_breddok.blockdisplaycreator.file.exception.InvalidFileFormatException;
@@ -195,7 +196,7 @@ public void reload() {
195196
public void reload(boolean createNewIfNotExist) {
196197
if (!this.configFile.exists()) {
197198
if (createNewIfNotExist) {
198-
load(this.configFile.toPath(), true);
199+
loadFromStream(BlockDisplayCreator.getInstance().getResource("messages.yml"));
199200
} else {
200201
throw new IllegalArgumentException("Configuration file does not exist: " + configFile.getAbsolutePath());
201202
}

src/main/java/me/general_breddok/blockdisplaycreator/file/CachedFile.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public CachedFile(@NotNull Path path, boolean createNew) {
4747

4848
/**
4949
* Reloads the file with an option to create and load a new file if the file does not exist.
50-
* Must be implemented by subclasses.
5150
*
5251
* @param loadNew whether to load a new file if the file does not exist
5352
*/

src/main/java/me/general_breddok/blockdisplaycreator/listener/block/BlockBreakListener.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,6 @@ public BlockBreakListener(ServiceManager<String, CustomBlockService> serviceMana
3636
this.serviceManager = serviceManager;
3737
}
3838

39-
private static boolean checkAccess(Player player, CustomBlock customBlock) {
40-
BDCDependentPluginsManager dependentPluginManager = BlockDisplayCreator.getInstance().getDependentPluginsManager();
41-
Location customBlockLocation = customBlock.getLocation();
42-
43-
if (dependentPluginManager.isWorldGuardAvailable()) {
44-
if (!WGRegionAccessChecker.checkRegionAccess(customBlockLocation, WGRegionFlags.BREAK_CB, player)) {
45-
ChatUtil.sendMessage(player, StringMessagesValue.REGION_DENIED_BREAK);
46-
return false;
47-
}
48-
}
49-
50-
if (dependentPluginManager.isSuperiorSkyblockAvailable()) {
51-
if (!SSBIslandAccessChecker.checkIslandAccess(customBlockLocation, SSBIslandPrivileges.BREAK_CB, player)) {
52-
ChatUtil.sendMessage(player, StringMessagesValue.ISLAND_DENIED_BREAK);
53-
return false;
54-
}
55-
}
56-
57-
CustomBlockPermissions permissions = customBlock.getPermissions();
58-
59-
if (permissions != null) {
60-
if (!permissions.hasPermissions(player, CustomBlockPermissions.Type.BREAK)) {
61-
ChatUtil.sendMessage(player, StringMessagesValue.PERMISSION_DENIED_BREAK);
62-
return false;
63-
}
64-
}
65-
return true;
66-
}
67-
6839
@EventHandler(ignoreCancelled = true)
6940
public void onBlockBreak(BlockBreakEvent event) {
7041
Player player = event.getPlayer();
@@ -116,4 +87,33 @@ public void onBlockBreak(BlockBreakEvent event) {
11687
} catch (IllegalArgumentException ignore) {
11788
}
11889
}
90+
91+
private static boolean checkAccess(Player player, CustomBlock customBlock) {
92+
BDCDependentPluginsManager dependentPluginManager = BlockDisplayCreator.getInstance().getDependentPluginsManager();
93+
Location customBlockLocation = customBlock.getLocation();
94+
95+
if (dependentPluginManager.isWorldGuardAvailable()) {
96+
if (!WGRegionAccessChecker.checkRegionAccess(customBlockLocation, WGRegionFlags.BREAK_CB, player)) {
97+
ChatUtil.sendMessage(player, StringMessagesValue.REGION_DENIED_BREAK);
98+
return false;
99+
}
100+
}
101+
102+
if (dependentPluginManager.isSuperiorSkyblockAvailable()) {
103+
if (!SSBIslandAccessChecker.checkIslandAccess(customBlockLocation, SSBIslandPrivileges.BREAK_CB, player)) {
104+
ChatUtil.sendMessage(player, StringMessagesValue.ISLAND_DENIED_BREAK);
105+
return false;
106+
}
107+
}
108+
109+
CustomBlockPermissions permissions = customBlock.getPermissions();
110+
111+
if (permissions != null) {
112+
if (!permissions.hasPermissions(player, CustomBlockPermissions.Type.BREAK)) {
113+
ChatUtil.sendMessage(player, StringMessagesValue.PERMISSION_DENIED_BREAK);
114+
return false;
115+
}
116+
}
117+
return true;
118+
}
119119
}

0 commit comments

Comments
 (0)