-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves DisplayOperator and DisplayOperatorReader from BlobDesign to Bl…
…obLib ObjectManager now implements CommandTarget for their asset
- Loading branch information
1 parent
e5885c0
commit 0d1d0ea
Showing
4 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/us/mytheria/bloblib/entities/display/DisplayOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package us.mytheria.bloblib.entities.display; | ||
|
||
import org.bukkit.entity.Display; | ||
import org.bukkit.util.Transformation; | ||
import org.jetbrains.annotations.NotNull; | ||
import us.mytheria.bloblib.entities.BukkitPluginOperator; | ||
|
||
/** | ||
* Represents an object that can hold Display entities | ||
* using initial displayData and a transformation. | ||
*/ | ||
public interface DisplayOperator extends BukkitPluginOperator { | ||
|
||
/** | ||
* The initial DisplayData held by this DisplayOperator. | ||
* | ||
* @return The initial DisplayData held by this DisplayOperator. | ||
*/ | ||
DisplayData getDisplayData(); | ||
|
||
/** | ||
* The initial transformation held by this DisplayOperator. | ||
* | ||
* @return The initial transformation held by this DisplayOperator. | ||
*/ | ||
Transformation getTransformation(); | ||
|
||
/** | ||
* Applies the DisplayData and Transformation to the given Display. | ||
* | ||
* @param display the Display to apply the DisplayData and Transformation to | ||
*/ | ||
default void apply(@NotNull Display display) { | ||
if (getDisplayData() != null) | ||
getDisplayData().apply(display); | ||
if (getTransformation() != null) | ||
display.setTransformation(getTransformation()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/us/mytheria/bloblib/entities/display/DisplayOperatorReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package us.mytheria.bloblib.entities.display; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.util.Transformation; | ||
|
||
public class DisplayOperatorReader { | ||
|
||
public static DisplayOperator READ(ConfigurationSection section, String path, JavaPlugin plugin) { | ||
DisplayData displayData; | ||
try { | ||
displayData = DisplayData.of(section); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException(e.getMessage() + " in file " + path); | ||
} | ||
Transformation transformation; | ||
try { | ||
transformation = DisplayReader.TRANSFORMATION_FAIL_FAST(section); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException(e.getMessage() + " in file " + path); | ||
} | ||
return new DisplayOperator() { | ||
@Override | ||
public DisplayData getDisplayData() { | ||
return displayData; | ||
} | ||
|
||
@Override | ||
public Transformation getTransformation() { | ||
return transformation; | ||
} | ||
|
||
@Override | ||
public Plugin getPlugin() { | ||
return plugin; | ||
} | ||
}; | ||
} | ||
} |