Skip to content

Commit

Permalink
Added HeadsDatabase for custom heads.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chazza committed Dec 24, 2019
1 parent 18397ba commit f898dae
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 84 deletions.
Binary file added libs/HeadDatabaseAPI.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<artifactId>blockparticles-plugin</artifactId>

<dependencies>
<dependency>
<groupId>me.arcaniax</groupId>
<artifactId>hdb</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/../libs/HeadDatabaseAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>me.badbones69</groupId>
<artifactId>blockparticles-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.badbones69.blockparticles;

import me.badbones69.blockparticles.api.BlockParticles;
import me.badbones69.blockparticles.api.ParticleManager;
import me.badbones69.blockparticles.api.FileManager;
import me.badbones69.blockparticles.api.FileManager.Files;
import me.badbones69.blockparticles.api.enums.ParticleType;
Expand All @@ -19,11 +19,11 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class Main extends JavaPlugin {
public class BlockParticles extends JavaPlugin {

private Boolean updateChecker = false;
private FileManager fileManager = FileManager.getInstance();
private BlockParticles bp = BlockParticles.getInstance();
private ParticleManager bp = ParticleManager.getInstance();

@Override
public void onDisable() {
Expand Down
26 changes: 18 additions & 8 deletions plugin/src/main/java/me/badbones69/blockparticles/Methods.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package me.badbones69.blockparticles;

import me.badbones69.blockparticles.api.BlockParticles;
import me.badbones69.blockparticles.api.FileManager;
import me.badbones69.blockparticles.api.FileManager.Files;
import me.badbones69.blockparticles.api.ParticleManager;
import me.badbones69.blockparticles.api.enums.Particles;
import me.badbones69.blockparticles.api.objects.ItemBuilder;
import me.badbones69.blockparticles.controllers.Fountains;
Expand All @@ -21,7 +22,7 @@
public class Methods implements Listener {

public static HashMap<Location, Location> Locations = new HashMap<>();
private static BlockParticles bp = BlockParticles.getInstance();
private static ParticleManager bp = ParticleManager.getInstance();

public static String color(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
Expand Down Expand Up @@ -63,7 +64,7 @@ public static boolean noPlayers(Location loc, int range) {
}

public static ArrayList<String> getLocations() {
return new ArrayList<>(Files.DATA.getFile().getConfigurationSection("Locations").getKeys(false));
return new ArrayList<>(Files.DATA.getFile().getConfigurationSection("locations").getKeys(false));
}

public static void kill() {
Expand All @@ -79,7 +80,7 @@ public static void kill() {
}
}
bp.getFountainItem().clear();
Bukkit.getScheduler().cancelTasks(BlockParticles.getInstance().getPlugin());
Bukkit.getScheduler().cancelTasks(ParticleManager.getInstance().getPlugin());
}

public static void startParticles() {
Expand All @@ -90,10 +91,13 @@ public static void startParticles() {
for (final String id : Files.DATA.getFile().getConfigurationSection("locations").getKeys(false)) {
World world = Bukkit.getServer().getWorld(Files.DATA.getFile().getString("locations." + id + ".world"));
String particle = Files.DATA.getFile().getString("locations." + id + ".particle");
int X = Integer.parseInt(Files.DATA.getFile().getString("locations." + id + ".x"));
int Y = Integer.parseInt(Files.DATA.getFile().getString("locations." + id + ".y"));
int Z = Integer.parseInt(Files.DATA.getFile().getString("locations." + id + ".z"));
final Location loc = new Location(world, X, Y, Z);
int x = Files.DATA.getFile().getInt("locations." + id + ".x");
int y = Files.DATA.getFile().getInt("locations." + id + ".y");
int z = Files.DATA.getFile().getInt("locations." + id + ".z");
final Location loc = new Location(world, x, y, z);

if (FileManager.Files.CONFIG.getFile().get("settings.heads." + particle) != null)
Fountains.startCustomFountain(loc, id, particle);

if (particle.equalsIgnoreCase("LoveWell")) bp.getParticleControl().playLoveWell(loc, id);
if (particle.equalsIgnoreCase("BigLoveWell")) bp.getParticleControl().playBigLoveWell(loc, id);
Expand Down Expand Up @@ -333,10 +337,16 @@ public static void setLoc(CommandSender player, String name, String particle) {
break;
}
}

if(FileManager.Files.CONFIG.getFile().get("settings.heads." + particle) != null) {
c = true;
}

if (!c) {
player.sendMessage(color(Prefix + "&6" + particle + " &cis not a particle. Please do /bp help for more information."));
return;
}

for (String loc : Files.DATA.getFile().getConfigurationSection("locations").getKeys(false)) {
if (loc.equalsIgnoreCase(name)) {
Files.DATA.getFile().set("locations." + loc + ".particle", particle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void saveFile(String name) {
if(file != null) {
try {
file.getFile().save(new File(plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName()));
if(log) System.out.println(prefix + "Successfuly saved the " + file.getFileName() + ".");
if(log) System.out.println(prefix + "Successfully saved the " + file.getFileName() + ".");
}catch(Exception e) {
System.out.println(prefix + "Could not save " + file.getFileName() + "!");
e.printStackTrace();
Expand Down Expand Up @@ -235,7 +235,7 @@ public void reloadFile(String name) {
if(file != null) {
try {
file.file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName()));
if(log) System.out.println(prefix + "Successfuly reload the " + file.getFileName() + ".");
if(log) System.out.println(prefix + "Successfully reload the " + file.getFileName() + ".");
}catch(Exception e) {
System.out.println(prefix + "Could not reload the " + file.getFileName() + "!");
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import java.util.HashMap;
import java.util.List;

public class BlockParticles {
public class ParticleManager {

private static BlockParticles instance = new BlockParticles();
private static ParticleManager instance = new ParticleManager();
private Plugin plugin;
private List<Entity> fountainItems = new ArrayList<>();
private HashMap<Player, String> setCommandPlayers = new HashMap<>();
private ParticleControl particleControl;

public static BlockParticles getInstance() {
public static ParticleManager getInstance() {
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.badbones69.blockparticles.api.objects;

import me.badbones69.blockparticles.api.BlockParticles;
import me.badbones69.blockparticles.api.ParticleManager;
import me.badbones69.blockparticles.multisupport.SkullCreator;
import me.badbones69.blockparticles.multisupport.Version;
import me.badbones69.blockparticles.multisupport.itemnbtapi.NBTItem;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class ItemBuilder {
private EntityType entityType;
private HashMap<String, String> namePlaceholders;
private HashMap<String, String> lorePlaceholders;
private BlockParticles bp = BlockParticles.getInstance();
private ParticleManager bp = ParticleManager.getInstance();

/**
* The initial starting point for making an item.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.badbones69.blockparticles.api.objects;

public class Particle {
private String id;
public Particle(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package me.badbones69.blockparticles.controllers;

import me.arcaniax.hdb.api.HeadDatabaseAPI;
import me.badbones69.blockparticles.BlockParticles;
import me.badbones69.blockparticles.Methods;
import me.badbones69.blockparticles.api.BlockParticles;
import me.badbones69.blockparticles.api.FileManager;
import me.badbones69.blockparticles.api.ParticleManager;
import me.badbones69.blockparticles.multisupport.Version;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -15,6 +18,7 @@
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.ArrayList;
Expand All @@ -25,7 +29,7 @@
public class Fountains implements Listener {

private static Random random = new Random();
private static BlockParticles bp = BlockParticles.getInstance();
private static ParticleManager bp = ParticleManager.getInstance();
private static List<String> pokemonHeads = Arrays.asList(
"4a786e4e35b59d91eb6454ef26b7b0683761d6b11f1d63c7740af17aa3f",
"f4a224d1753fddd25f5bd6b4b6ac879efdb4e978c046e7fa8120a07a8e4ab4d8",
Expand Down Expand Up @@ -170,6 +174,34 @@ private static float randomVector() {
return (float) -.1 + (float) (Math.random() * ((.1 - -.1)));
}


private static final HeadDatabaseAPI HEAD_DATABASE_API = new HeadDatabaseAPI();
public static void startCustomFountain(Location loc, String id, String fountainId) {
bp.getParticleControl().getLocations().put(id, Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(bp.getPlugin(), () -> {
for (String head : getRandomHeads(FileManager.Files.CONFIG.getFile().getStringList("settings.heads." + fountainId))) {

final ItemStack headStack = HEAD_DATABASE_API.getItemHead(head);

if(headStack == null) {
JavaPlugin.getPlugin(BlockParticles.class).getLogger().warning("Head item '" + head + "' for id " + fountainId + " is invalid!");
return;
}

final Item headItem = Bukkit.getWorld(loc.getWorld().getName()).dropItem(loc.clone().add(.8, .10, .8), headStack);
if (Version.getCurrentVersion().isNewer(Version.v1_8_R3)) {
headItem.setVelocity(new Vector(randomVector(), .01, randomVector()));
} else {
headItem.setVelocity(new Vector(randomVector(), .3, randomVector()));
}
bp.addFountainItem(headItem);
Bukkit.getScheduler().scheduleSyncDelayedTask(bp.getPlugin(), () -> {
bp.removeFountainItem(headItem);
headItem.remove();
}, 2 * 20);
}
}, 0, 3));
}

public static void startHalloween(final Location loc, String id) {
bp.getParticleControl().getLocations().put(id, Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(bp.getPlugin(), () -> {
ItemStack flesh = new ItemStack(Material.ROTTEN_FLESH);
Expand Down
Loading

0 comments on commit f898dae

Please sign in to comment.