Skip to content

Commit cbfb089

Browse files
authored
1.0 source
1 parent 08ae74c commit cbfb089

6 files changed

Lines changed: 184 additions & 0 deletions

File tree

src/HungerHealth/HungerHealth.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>SPIGOT</platformType>
8+
</autoDetectTypes>
9+
<projectReimportVersion>1</projectReimportVersion>
10+
</configuration>
11+
</facet>
12+
</component>
13+
</module>

src/HungerHealth/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>me.sintaxlabs</groupId>
8+
<artifactId>HungerHealth</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>HungerHealth</name>
13+
14+
<properties>
15+
<java.version>1.8</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>3.8.1</version>
25+
<configuration>
26+
<source>${java.version}</source>
27+
<target>${java.version}</target>
28+
</configuration>
29+
</plugin>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-shade-plugin</artifactId>
33+
<version>3.2.4</version>
34+
<executions>
35+
<execution>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>shade</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
</plugins>
44+
<resources>
45+
<resource>
46+
<directory>src/main/resources</directory>
47+
<filtering>true</filtering>
48+
</resource>
49+
</resources>
50+
</build>
51+
52+
<repositories>
53+
<repository>
54+
<id>spigotmc-repo</id>
55+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
56+
</repository>
57+
<repository>
58+
<id>sonatype</id>
59+
<url>https://oss.sonatype.org/content/groups/public/</url>
60+
</repository>
61+
</repositories>
62+
63+
<dependencies>
64+
<dependency>
65+
<groupId>io.papermc.paper</groupId>
66+
<artifactId>paper-api</artifactId>
67+
<version>1.21-R0.1-SNAPSHOT</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
</dependencies>
71+
</project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package me.sintaxlabs.hungerhealth;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.entity.Entity;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.EventPriority;
8+
import org.bukkit.event.Listener;
9+
import org.bukkit.event.entity.*;
10+
import org.bukkit.event.player.PlayerItemConsumeEvent;
11+
import org.bukkit.plugin.java.JavaPlugin;
12+
13+
public final class main extends JavaPlugin implements Listener
14+
{
15+
16+
@Override
17+
public void onEnable()
18+
{
19+
getServer().getPluginManager().registerEvents(this, this);
20+
}
21+
22+
// Get exhausted? Set health to hunger.
23+
@EventHandler(priority = EventPriority.HIGHEST)
24+
public void hungerEvent(EntityExhaustionEvent e)
25+
{
26+
Entity entity = e.getEntity();
27+
if (entity instanceof Player)
28+
{
29+
Bukkit.getScheduler().runTaskLater(JavaPlugin.getProvidingPlugin(getClass()), () -> ConvertHealthToHunger1(e), 1L);
30+
}
31+
}
32+
33+
// Eating? Set health to hunger.
34+
@EventHandler(priority = EventPriority.HIGHEST)
35+
public void painEvent(PlayerItemConsumeEvent e)
36+
{
37+
Bukkit.getScheduler().runTaskLater(JavaPlugin.getProvidingPlugin(getClass()), () -> ConvertHealthToHunger2(e), 1L);
38+
}
39+
40+
41+
42+
// Get hurt by mob? Set hunger to health.
43+
@EventHandler(priority = EventPriority.HIGHEST)
44+
public void painEvent(EntityDamageEvent e)
45+
{
46+
Entity entity = e.getEntity();
47+
if (entity instanceof Player)
48+
{
49+
Bukkit.getScheduler().runTaskLater(JavaPlugin.getProvidingPlugin(getClass()), () -> ConvertHungerToHealth(e.getEntity()), 1L);
50+
}
51+
}
52+
53+
//Healing? Set hunger to health.
54+
@EventHandler(priority = EventPriority.HIGHEST)
55+
public void painEvent(EntityRegainHealthEvent e)
56+
{
57+
Entity entity = e.getEntity();
58+
if (entity instanceof Player)
59+
{
60+
Bukkit.getScheduler().runTaskLater(JavaPlugin.getProvidingPlugin(getClass()), () -> ConvertHungerToHealth(e.getEntity()), 1L);
61+
}
62+
}
63+
64+
private static void ConvertHealthToHunger1(EntityExhaustionEvent e)
65+
{
66+
Player player = (Player) e.getEntity();
67+
float hunger = player.getFoodLevel();
68+
player.setHealth(hunger);
69+
player.setSaturation(0);
70+
}
71+
private static void ConvertHealthToHunger2(PlayerItemConsumeEvent e)
72+
{
73+
Player player = e.getPlayer();
74+
float hunger = player.getFoodLevel();
75+
player.setHealth(hunger);
76+
player.setSaturation(0);
77+
}
78+
79+
private static void ConvertHungerToHealth(Entity e)
80+
{
81+
Player player = (Player) e;
82+
//player.setSaturatedRegenRate(0);
83+
float health = (float) player.getHealth();
84+
player.setFoodLevel((int) health);
85+
player.setSaturation(0);
86+
}
87+
88+
@Override
89+
public void onDisable() {
90+
// Plugin shutdown logic
91+
}
92+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: HungerHealth
2+
version: '${project.version}'
3+
main: me.sintaxlabs.hungerhealth.main
4+
api-version: '1.21'
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: HungerHealth
2+
version: '1.0'
3+
main: me.sintaxlabs.hungerhealth.main
4+
api-version: '1.21'

0 commit comments

Comments
 (0)