Skip to content

Commit

Permalink
Initial commit and code
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykCholewa committed Nov 11, 2024
1 parent 0f3d123 commit 2d0f31e
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.PatrykCholewa</groupId>
<artifactId>FoxKiller</artifactId>
<version>1.0.0-1.21.3-SNAPSHOT</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>spigot-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.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.PatrykCholewa.FoxKiller;

import com.github.PatrykCholewa.FoxKiller.listeners.FoxKillListener;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;

import java.io.File;

public class FoxKillerPlugin extends JavaPlugin {

private static Plugin instance;

public static Plugin getInstance() {
return instance;
}

public FoxKillerPlugin() {

}

public FoxKillerPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
super(loader, description, dataFolder, file);
}

@Override
public void onEnable() {
super.onEnable();
instance = this;

PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new FoxKillListener(), instance);
}

@Override
public void onDisable() {
super.onDisable();
instance = null;
HandlerList.unregisterAll(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.PatrykCholewa.FoxKiller.listeners;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.WeatherType;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.WeatherEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class FoxKillListener implements Listener {

@EventHandler
public static void onEvent(EntityDeathEvent event) {
if (event.getEntity().getType() != EntityType.FOX) {
return;
}

if (event.getDamageSource().getDamageType() != DamageType.PLAYER_ATTACK) {
return;
}

event.getDrops().addAll(createRandomDrop());
event.setDroppedExp(7);
}

private static List<ItemStack> createRandomDrop() {
List<ItemStack> list = new ArrayList<>();
ItemStack is;

int rand = new Random().nextInt();
if ((rand % 3) == 0) {
is = new ItemStack(Material.CAKE);
list.add(is);
}
if ((rand % 7) == 0) {
is = new ItemStack(Material.INFESTED_STONE_BRICKS);
list.add(is);
}

if ((rand % 31) == 0) {
is = new ItemStack(Material.OMINOUS_BOTTLE);
list.add(is);
}

if ((rand % 47) == 0) {
is = new ItemStack(Material.PLAYER_HEAD);
SkullMeta skullMeta = (SkullMeta) is.getItemMeta();
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer("Zirekall"));
is.setItemMeta(skullMeta);
list.add(is);
}

return list;
}

}
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: FoxKiller
version: 1.0.0
main: com.github.PatrykCholewa.FoxKiller.FoxKillerPlugin
api-version: 1.21

0 comments on commit 2d0f31e

Please sign in to comment.