diff options
author | Genny <gen@nyble.dev> | 2020-02-03 14:21:42 -0600 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2020-02-03 14:21:42 -0600 |
commit | 8c79ab0d5a96f89e74a070968f8787f9ba94a8c8 (patch) | |
tree | 93d0bc26f68c802860d2e8cabc2d4381eeffeb44 | |
download | sunfright-8c79ab0d5a96f89e74a070968f8787f9ba94a8c8.tar.gz sunfright-8c79ab0d5a96f89e74a070968f8787f9ba94a8c8.zip |
Initial commit
-rw-r--r-- | .classpath | 49 | ||||
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | .project | 23 | ||||
-rw-r--r-- | pom.xml | 69 | ||||
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/Damager.java | 48 | ||||
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/Sunfright.java | 30 | ||||
-rw-r--r-- | src/main/resources/plugin.yml | 7 |
7 files changed, 235 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..9c4312a --- /dev/null +++ b/.classpath @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + <attribute name="test" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" path="target/generated-sources/annotations"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + <attribute name="ignore_optional_problems" value="true"/> + <attribute name="m2e-apt" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + <attribute name="ignore_optional_problems" value="true"/> + <attribute name="m2e-apt" value="true"/> + <attribute name="test" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..344b319 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# VSCode things +.vscode +.settings + +# Maven things +target/ + +# Genuinebyte things +cptotest.sh \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..5f0a208 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>sunfright</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + </natures> +</projectDescription> diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fe464f3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,69 @@ +<!-- based on https://github.com/sgrayme/SpigotPlugin/blob/master/pom.xml --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>dev.genbyte.sunfright</groupId> + <artifactId>sunfright</artifactId> + <packaging>jar</packaging> + <version>0.1.0</version> + + <name>sunfright</name> + <description>Burn me to a cript, large glowing orb!</description> + <url>https://genbyte.dev</url><!-- TODO: add URL --> + + <developers> + <developer> + <name>Genuinebyte</name> + <url>https://genbyte.dev</url> + </developer> + </developers> + + <properties> + <author>Genuinebyte</author> + <mainClass>dev.genbyte.sunfright.Sunfright</mainClass> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + </properties> + + <repositories> + <!-- Spigot Maven repository --> + <repository> + <id>spigot-repo</id> + <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> + </repository> + </repositories> + + <dependencies> + <!--Spigot API --> + <dependency> + <groupId>org.spigotmc</groupId> + <artifactId>spigot-api</artifactId> + <version>1.15.1-R0.1-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <sourceDirectory>src/main/java</sourceDirectory> + <defaultGoal>clean install</defaultGoal> + + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>plugin.yml</include> + </includes> + </resource> + + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + <excludes> + <exclude>plugin.yml</exclude> + </excludes> + </resource> + </resources> + </build> +</project> diff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java new file mode 100644 index 0000000..c592647 --- /dev/null +++ b/src/main/java/dev/genbyte/sunfright/Damager.java @@ -0,0 +1,48 @@ +package dev.genbyte.sunfright; + +import java.util.Collection; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.scheduler.BukkitRunnable; + +public class Damager extends BukkitRunnable { + private final Sunfright sf; + + public Damager(Sunfright sf) { + this.sf = sf; + } + + public void run() { + Collection<? extends Player> players = sf.getServer().getOnlinePlayers(); + players.forEach((player) -> { + byte skylight = player.getLocation().getBlock().getLightFromSky(); + if (skylight > 3 && skylight < 13) { + new DoDamage(player, (byte) 1).runTask(sf); + } else if (skylight >= 13) { + new DoDamage(player, (byte) 2).runTask(sf); + } + }); + } + + private class DoDamage extends BukkitRunnable { + private final Player player; + private final byte damage; + + public DoDamage(Player player, byte damage) { + this.player = player; + this.damage = damage; + } + + public void run() { + ItemStack helmet = player.getInventory().getHelmet(); + if (helmet != null && helmet instanceof Damageable) { + Damageable damageable = (Damageable) helmet; + damageable.setDamage(damageable.getDamage() - damage); + } else { + player.damage(damage); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/dev/genbyte/sunfright/Sunfright.java b/src/main/java/dev/genbyte/sunfright/Sunfright.java new file mode 100644 index 0000000..d05774f --- /dev/null +++ b/src/main/java/dev/genbyte/sunfright/Sunfright.java @@ -0,0 +1,30 @@ +package dev.genbyte.sunfright; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; + +public class Sunfright extends JavaPlugin { + private Logger logger; + private BukkitTask damager; + + @Override + public void onLoad() { + logger = this.getLogger(); + } + + @Override + public void onEnable() { + int time = 20; + damager = new Damager(this).runTaskTimerAsynchronously(this, time, time); + logger.log(Level.INFO, "Damager task started. and will run every " + (time / 20) + " seconds"); + } + + @Override + public void onDisable() { + damager.cancel(); + logger.log(Level.INFO, "Damager task stopped."); + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..991a8e4 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: ${name} +version: ${version} +description: ${description} +author: ${author} +website: ${url} + +main: ${mainClass} \ No newline at end of file |