Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "discord_comissions/OdysseyBot"]
path = discord_comissions/OdysseyBot
url = [email protected]:GyllieGyllie/OdysseyBot.git
83 changes: 83 additions & 0 deletions comissions/wildestbreeding/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.gylliegyllie</groupId>
<artifactId>wildestbreeding</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<finalName>WildestBreeding</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>json-simple</artifactId>
<groupId>com.googlecode.json-simple</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

78 changes: 78 additions & 0 deletions comissions/wildestbreeding/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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>net.gylliegyllie</groupId>
<artifactId>wildestbreeding</artifactId>
<version>1.0</version>

<build>
<defaultGoal>clean install</defaultGoal>
<finalName>WildestBreeding</finalName>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>

<!-- Spigot -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- GSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.gylliegyllie.wildestbreeding;

import net.gylliegyllie.wildestbreeding.commands.AnimalFeedPacket;
import net.gylliegyllie.wildestbreeding.configuration.Configuration;
import net.gylliegyllie.wildestbreeding.listeners.BreedListener;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
import org.bukkit.inventory.meta.tags.ItemTagType;
import org.bukkit.plugin.java.JavaPlugin;

public class Plugin extends JavaPlugin {

private Configuration configuration;

private NamespacedKey key = new NamespacedKey(this, "feed-type");

@Override
public void onEnable() {

try {
this.configuration = new Configuration(this);
} catch (Exception e) {
e.printStackTrace();
this.getServer().getLogger().severe("Failed to load configuration!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}

this.getServer().getPluginManager().registerEvents(new BreedListener(this), this);

this.getCommand("animalfeed").setExecutor(new AnimalFeedPacket(this));

this.getLogger().info("Wildest Breeding enabled!");
}

@Override
public void onDisable() {

this.getLogger().info("Wildest Breeding disabled!");
}

public Configuration getConfiguration() {
return this.configuration;
}

public void addCustomFlag(ItemStack item, String value) {
ItemMeta itemMeta = item.getItemMeta();

if (itemMeta != null) {
itemMeta.getCustomTagContainer().setCustomTag(this.key, ItemTagType.STRING, value);
item.setItemMeta(itemMeta);
}
}

public String getCustomFlag(ItemStack item) {
ItemMeta itemMeta = item.getItemMeta();

if (itemMeta != null) {
CustomItemTagContainer container = itemMeta.getCustomTagContainer();

if (container.hasCustomTag(this.key, ItemTagType.STRING)) {
return container.getCustomTag(this.key, ItemTagType.STRING);
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package net.gylliegyllie.wildestbreeding.commands;

import net.gylliegyllie.wildestbreeding.Plugin;
import net.gylliegyllie.wildestbreeding.configuration.FeedConfig;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class AnimalFeedPacket implements CommandExecutor {

private final Plugin plugin;

public AnimalFeedPacket(Plugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (args.length != 3) {
sender.sendMessage(ChatColor.BLUE + "Usage: /seedpacket <player> <mob> <quantity>");
return true;
}

Player player = this.plugin.getServer().getPlayer(args[0]);

if (player == null) {
sender.sendMessage(ChatColor.RED + "Player not found!");
return true;
}

EntityType mob;

try {
mob = EntityType.valueOf(args[1].toUpperCase());
} catch (Exception ignore) {
sender.sendMessage(ChatColor.RED + "Invalid mob entered!");
return true;
}

if (!sender.hasPermission("animalfeed." + mob.name().toLowerCase())) {
sender.sendMessage(ChatColor.RED + "No permissions!");
return true;
}

FeedConfig config = this.plugin.getConfiguration().getForMob(mob);

if (config == null) {
sender.sendMessage(ChatColor.RED + "No config found for given mob?");
return true;
}

int amount;

try {
amount = Integer.valueOf(args[2]);
} catch (Exception ignore) {
sender.sendMessage(ChatColor.RED + "Invalid quantity entered!");
return true;
}

ItemStack itemStack = new ItemStack(config.packet, amount);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.AQUA + config.packetName);
itemStack.setItemMeta(itemMeta);

this.plugin.addCustomFlag(itemStack, config.mob.name());

player.getInventory().addItem(itemStack);

sender.sendMessage(ChatColor.GREEN + "Successfully given packets!");
player.sendMessage(ChatColor.GREEN + "You have received " + amount + " " + config.packetName);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package net.gylliegyllie.wildestbreeding.configuration;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.gylliegyllie.wildestbreeding.Plugin;
import org.bukkit.entity.EntityType;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Configuration {

private final Gson GSON = (new GsonBuilder()).setPrettyPrinting().enableComplexMapKeySerialization().create();

private final Plugin plugin;

private List<FeedConfig> configs;

private Map<EntityType, FeedConfig> mobMapping = new HashMap<>();

public Configuration(Plugin plugin) throws Exception {
this.plugin = plugin;

File file = new File(plugin.getDataFolder(), "config.json");

if (!file.exists()) {

file.getParentFile().mkdir();

try (InputStream in = plugin.getResource("config.json");
OutputStream out = new FileOutputStream(file)) {

byte[] buf = new byte[1024];
int len;

while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}

}
}

try (FileReader fileReader = new FileReader(file)) {

Type listType = new TypeToken<ArrayList<FeedConfig>>(){}.getType();
this.configs = GSON.fromJson(fileReader, listType);

}

for (FeedConfig config : this.configs) {
this.mobMapping.put(config.mob, config);
}
}

public List<FeedConfig> getConfigs() {
return this.configs;
}

public FeedConfig getForMob(EntityType mob) {
return this.mobMapping.get(mob);
}
}
Loading