-
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.
- Loading branch information
0 parents
commit c0047d9
Showing
3 changed files
with
261 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.doodcraft.cozmyc</groupId> | ||
<artifactId>imagetest</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>ImageTest</name> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>16</source> | ||
<target>16</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigotmc-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.20.4-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.projectkorra</groupId> | ||
<artifactId>projectkorra</artifactId> | ||
<version>1.11.3</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
182 changes: 182 additions & 0 deletions
182
src/main/java/net/doodcraft/cozmyc/imagetest/ImageTest.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,182 @@ | ||
package net.doodcraft.cozmyc.imagetest; | ||
|
||
import com.projectkorra.projectkorra.Element; | ||
import com.projectkorra.projectkorra.ProjectKorra; | ||
import com.projectkorra.projectkorra.ability.AddonAbility; | ||
import com.projectkorra.projectkorra.ability.FireAbility; | ||
import org.bukkit.Location; | ||
|
||
import org.bukkit.Particle; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
public class ImageTest extends FireAbility implements AddonAbility { | ||
|
||
private long cooldown; | ||
private long duration; | ||
private long startTime; | ||
|
||
private BufferedImage image; | ||
private int currentRow; | ||
|
||
private int rowsPerTick; | ||
|
||
public ImageTest(Player player) { | ||
super(player); | ||
|
||
if (!bPlayer.canBend(this) || !bPlayer.canBendIgnoreCooldowns(this)) { | ||
return; | ||
} | ||
|
||
setFields(); | ||
start(); | ||
} | ||
|
||
private void setFields() { | ||
this.cooldown = 1000; | ||
this.duration = 60000; | ||
this.startTime = System.currentTimeMillis(); | ||
|
||
File file = new File(ProjectKorra.plugin.getDataFolder() + File.separator + "Abilities" + File.separator + "image.png"); | ||
try { | ||
this.image = ImageIO.read(file); | ||
this.image = resizeImage(image, 80, 80); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
this.currentRow = 0; | ||
this.rowsPerTick = 16; | ||
} | ||
|
||
@Override | ||
public void progress() { | ||
if (System.currentTimeMillis() - startTime > duration || !bPlayer.getBoundAbilityName().equalsIgnoreCase("ImageTest")) { | ||
remove(); | ||
return; | ||
} | ||
|
||
if (image == null) { | ||
return; | ||
} | ||
|
||
displayImageParticles(image, player.getLocation()); | ||
} | ||
|
||
private BufferedImage resizeImage(BufferedImage image, int maxWidth, int maxHeight) { | ||
int width = image.getWidth(); | ||
int height = image.getHeight(); | ||
double aspectRatio = (double) width / height; | ||
|
||
if (width > maxWidth || height > maxHeight) { | ||
if (width > height) { | ||
width = maxWidth; | ||
height = (int) (width / aspectRatio); | ||
} else { | ||
height = maxHeight; | ||
width = (int) (height * aspectRatio); | ||
} | ||
} | ||
|
||
Image tempImage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); | ||
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | ||
Graphics2D g2d = resizedImage.createGraphics(); | ||
g2d.drawImage(tempImage, 0, 0, null); | ||
g2d.dispose(); | ||
return resizedImage; | ||
} | ||
|
||
private void displayImageParticles(BufferedImage image, Location location) { | ||
World world = location.getWorld(); | ||
|
||
double centerXOffset = (image.getWidth() / 2.0) / 10.0; | ||
double centerZOffset = (image.getHeight() / 2.0) / 10.0; | ||
|
||
for (int y = 0; y < rowsPerTick; y++) { | ||
int row = currentRow + y; | ||
if (row >= image.getHeight()) { | ||
currentRow = 0; | ||
return; | ||
} | ||
for (int x = 0; x < image.getWidth(); x++) { | ||
int rgba = image.getRGB(x, row); | ||
Color color = new Color(rgba, true); | ||
if (color.getAlpha() > 0) { | ||
double xPos = location.getX() - centerXOffset + (x / 10.0); | ||
double yPos = location.getY(); | ||
double zPos = location.getZ() - centerZOffset + (row / 10.0); | ||
|
||
Particle.DustOptions dustOptions = new Particle.DustOptions(org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 0.66F); | ||
world.spawnParticle(Particle.REDSTONE, new Location(world, xPos, yPos, zPos), 1, dustOptions); | ||
} | ||
} | ||
} | ||
currentRow += rowsPerTick; | ||
} | ||
|
||
@Override | ||
public long getCooldown() { | ||
return cooldown; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ImageTest"; | ||
} | ||
|
||
@Override | ||
public Element getElement() { | ||
return Element.FIRE; | ||
} | ||
|
||
@Override | ||
public Location getLocation() { | ||
return player != null ? player.getLocation() : null; | ||
} | ||
|
||
@Override | ||
public boolean isHarmlessAbility() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isIgniteAbility() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isExplosiveAbility() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isSneakAbility() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void load() { | ||
ProjectKorra.plugin.getServer().getPluginManager().registerEvents(new ImageTestListener(), ProjectKorra.plugin); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
|
||
} | ||
|
||
@Override | ||
public String getAuthor() { | ||
return "Cozmyc"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return "1.0.0"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/net/doodcraft/cozmyc/imagetest/ImageTestListener.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,26 @@ | ||
package net.doodcraft.cozmyc.imagetest; | ||
|
||
import com.projectkorra.projectkorra.BendingPlayer; | ||
import com.projectkorra.projectkorra.ability.CoreAbility; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerToggleSneakEvent; | ||
|
||
public class ImageTestListener implements Listener { | ||
@EventHandler | ||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { | ||
Player player = event.getPlayer(); | ||
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); | ||
|
||
if (bPlayer == null || !bPlayer.canBendIgnoreCooldowns(CoreAbility.getAbility(ImageTest.class))) { | ||
return; | ||
} | ||
|
||
if (player.isSneaking() && bPlayer.getBoundAbilityName().equalsIgnoreCase("ImageTest")) { | ||
if (!CoreAbility.hasAbility(player, ImageTest.class)) { | ||
new ImageTest(player); | ||
} | ||
} | ||
} | ||
} |