Skip to content

Commit

Permalink
Fixes ConfigDecorator not allowing to reload config.yml
Browse files Browse the repository at this point in the history
Structrador should now be able to place more than 20 entities 🪰
ElasticEconomy is backwards compatible with original Vault
  • Loading branch information
anjoismysign committed Nov 29, 2023
1 parent fb43712 commit fd8628b
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 106 deletions.
2 changes: 1 addition & 1 deletion ci-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.27</version>
<version>1.697.28</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.27</version>
<version>1.697.28</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down Expand Up @@ -76,8 +76,8 @@
<shadedPattern>global.warming.commons</shadedPattern>
</relocation>
<relocation>
<pattern>fr.skytasul.guardianbeam</pattern>
<shadedPattern>nuclear.winter.guardianbeam</shadedPattern>
<pattern>net.milkbowl.vault</pattern>
<shadedPattern>nuclear.winter.vault</shadedPattern>
</relocation>
<!-- doomsday.clock.NNNEEEXXXTTT -->
</relocations>
Expand Down
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.27</version>
<version>1.697.28</version>
<packaging>pom</packaging>

<properties>
Expand Down Expand Up @@ -92,12 +92,6 @@
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.skytasul</groupId>
<artifactId>guardianbeam</artifactId>
<version>2.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
Expand All @@ -120,7 +114,8 @@
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>vaultapi</artifactId>
<version>1.7.4</version>
<version>1.7.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/us/mytheria/bloblib/entities/ConfigDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import us.mytheria.bloblib.utilities.ResourceUtil;

import java.io.File;

public class ConfigDecorator {
private final JavaPlugin plugin;
private final ListenersSection listenersSection;

public ConfigDecorator(JavaPlugin plugin) {
this.plugin = plugin;
File file = new File(plugin.getDataFolder(), "config.yml");
ResourceUtil.updateYml(file, plugin);
plugin.reloadConfig();
this.listenersSection = ListenersSection.of(plugin);
}

private FileConfiguration getRoot() {
return plugin.getConfig();
}

/**
Expand All @@ -19,14 +31,12 @@ public ConfigDecorator(JavaPlugin plugin) {
* @return the section
*/
public ConfigurationSection reloadAndGetSection(String path) {
FileConfiguration root = plugin.getConfig();
root.options().copyDefaults(true);
FileConfiguration root = getRoot();
ConfigurationSection section;
if (!root.isConfigurationSection(path))
section = root.createSection(path);
else
section = root.getConfigurationSection(path);
plugin.saveConfig();
return section;
}

Expand All @@ -37,6 +47,6 @@ public ConfigurationSection reloadAndGetSection(String path) {
*/
@NotNull
public ListenersSection reloadAndGetListeners() {
return ListenersSection.of(plugin);
return listenersSection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ public void reload() {
listeners.forEach(BlobListener::reload);
}

@SuppressWarnings("ManualArrayToCollectionCopy")
public void add(BlobListener... listeners) {
for (BlobListener listener : listeners) {
add(listener);
this.listeners.add(listener);
}
}

public void remove(BlobListener... listeners) {
for (BlobListener listener : listeners) {
remove(listener);
this.listeners.remove(listener);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public record ListenersSection(ConfigurationSection tinyListeners,
@NotNull
public static ListenersSection of(JavaPlugin plugin) {
FileConfiguration configuration = plugin.getConfig();
configuration.options().copyDefaults(true);
ConfigurationSection listeners = configuration.getConfigurationSection("Listeners");
if (!listeners.isConfigurationSection("TinyListeners"))
listeners.createSection("TinyListeners");
Expand All @@ -43,7 +42,6 @@ public static ListenersSection of(JavaPlugin plugin) {
ConfigurationSection tinyListeners = listeners.getConfigurationSection("TinyListeners");
ConfigurationSection complexListeners = listeners.getConfigurationSection("ComplexListeners");
ConfigurationSection simpleListeners = listeners.getConfigurationSection("SimpleListeners");
plugin.saveConfig();
return new ListenersSection(tinyListeners, complexListeners, simpleListeners, configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public boolean supportsOfflineOperations() {
return false;
}

@Override
public boolean supportsUUIDOperations() {
return false;
}

@Override
public boolean createAccount(UUID uuid, String s) {
return true;
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/us/mytheria/bloblib/utilities/BeamUtil.java

This file was deleted.

44 changes: 40 additions & 4 deletions src/main/java/us/mytheria/bloblib/utilities/BlockFaceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class BlockFaceUtil {

@NotNull
public static BlockFace rotate(BlockFace face, StructureRotation rotation) {
public static BlockFace rotateCardinalDirection(BlockFace face, StructureRotation rotation) {
switch (rotation) {
case NONE -> {
return face;
Expand All @@ -26,8 +26,20 @@ public static BlockFace rotate(BlockFace face, StructureRotation rotation) {
case WEST -> {
return BlockFace.NORTH;
}
case NORTH_EAST -> {
return BlockFace.SOUTH_EAST;
}
case SOUTH_EAST -> {
return BlockFace.SOUTH_WEST;
}
case SOUTH_WEST -> {
return BlockFace.NORTH_WEST;
}
case NORTH_WEST -> {
return BlockFace.NORTH_EAST;
}
default -> {
throw new IllegalArgumentException("Invalid BlockFace: " + face);
return face;
}
}
}
Expand All @@ -45,8 +57,20 @@ public static BlockFace rotate(BlockFace face, StructureRotation rotation) {
case WEST -> {
return BlockFace.EAST;
}
case NORTH_EAST -> {
return BlockFace.SOUTH_WEST;
}
case SOUTH_EAST -> {
return BlockFace.NORTH_WEST;
}
case SOUTH_WEST -> {
return BlockFace.NORTH_EAST;
}
case NORTH_WEST -> {
return BlockFace.SOUTH_EAST;
}
default -> {
throw new IllegalArgumentException("Invalid BlockFace: " + face);
return face;
}
}
}
Expand All @@ -64,8 +88,20 @@ public static BlockFace rotate(BlockFace face, StructureRotation rotation) {
case WEST -> {
return BlockFace.SOUTH;
}
case NORTH_EAST -> {
return BlockFace.NORTH_WEST;
}
case SOUTH_EAST -> {
return BlockFace.NORTH_EAST;
}
case SOUTH_WEST -> {
return BlockFace.SOUTH_EAST;
}
case NORTH_WEST -> {
return BlockFace.SOUTH_WEST;
}
default -> {
throw new IllegalArgumentException("Invalid BlockFace: " + face);
return face;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/us/mytheria/bloblib/utilities/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public static void inputStreamToFile(File file, InputStream inputStream) {
}
}

/**
* Will update the existing file with the new values
*
* @param existingFile the file to update
* @param main the plugin
*/
public static void updateYml(File existingFile, Plugin main) {
String name = existingFile.getName();
File path = existingFile.getParentFile();
updateYml(path, "/temp" + name, name, existingFile, main);
}

public static void updateYml(File path, String tempFileName, String fileName, File existingFile, Plugin main) {
File tempFile = new File(path.getPath() + tempFileName);
ResourceUtil.inputStreamToFile(tempFile, main.getResource(fileName)); // writes defaults to temp file
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/us/mytheria/bloblib/utilities/Structrador.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.structure.Mirror;
import org.bukkit.block.structure.StructureRotation;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -233,7 +235,7 @@ public ChainedTask chainedPlace(Location location, boolean includeEntities,
ChainedTask chainedTask = new ChainedTask(future, null,
(totalSize / maxPlacedPerPeriod) * period);
ChainedTaskProgress progress = new ChainedTaskProgress(totalSize, chainedTask);
Iterator<BlockState> iterator = blocks.iterator();
Iterator<BlockState> blockIterator = blocks.iterator();
World world = location.getWorld();
if (world == null)
throw new IllegalArgumentException("Location must have a world.");
Expand Down Expand Up @@ -278,8 +280,8 @@ public ChainedTask chainedPlace(Location location, boolean includeEntities,
@Override
public void run() {
Uber<Integer> placed = Uber.drive(0);
while (iterator.hasNext() && placed.thanks() < maxPlacedPerPeriod) {
BlockState next = iterator.next();
while (blockIterator.hasNext() && placed.thanks() < maxPlacedPerPeriod) {
BlockState next = blockIterator.next();
Vector nextVector = next.getLocation().toVector();
Vector result = VectorUtil.rotateVector(nextVector, degree);
Location blockLocation = location.clone()
Expand All @@ -289,11 +291,19 @@ public void run() {
ManoBlockState state = MANORATOR_FACTORY.of(next);
state.update(true, false, blockLocation);
BlockState current = blockLocation.getBlock().getState();
BlockData data = current.getBlockData();
if (data instanceof Directional directional) {
directional.setFacing(BlockFaceUtil
.rotateCardinalDirection(directional.getFacing(),
structureRotation));
current.setBlockData(directional);
current.update(true, false);
}
placedBlockConsumer.accept(current);
placed.talk(placed.thanks() + 1);
progress.run();
}
if (!iterator.hasNext()) {
if (!blockIterator.hasNext()) {
paletteFuture.complete(null);
this.cancel();
}
Expand All @@ -310,8 +320,8 @@ public void run() {
BukkitRunnable entityTask = new BukkitRunnable() {
@Override
public void run() {
Uber<Integer> maxPlaced = Uber.drive(0);
while (entityIterator.hasNext() && maxPlaced.thanks() < maxPlacedPerPeriod) {
Uber<Integer> placed = Uber.drive(0);
while (entityIterator.hasNext() && placed.thanks() < maxPlacedPerPeriod) {
Entity next = entityIterator.next();
Location nextLocation = next.getLocation();
Vector nextVector = nextLocation.toVector();
Expand All @@ -334,15 +344,15 @@ public void run() {
if (next instanceof Hanging hanging) {
BlockFace facing = hanging.getFacing();
hanging.setFacingDirection(
BlockFaceUtil.rotate(facing, structureRotation),
BlockFaceUtil.rotateCardinalDirection(facing, structureRotation),
true);
}
next.setSilent(isSilent);
placedEntityConsumer.accept(next);
maxPlaced.talk(maxPlaced.thanks() + 1);
placed.talk(placed.thanks() + 1);
progress.run();
}
if (!iterator.hasNext()) {
if (!entityIterator.hasNext()) {
future.complete(null);
this.cancel();
}
Expand Down
Loading

0 comments on commit fd8628b

Please sign in to comment.