Skip to content
Open
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
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
<name>LightMaker</name>

<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -42,8 +43,8 @@
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

Expand Down
83 changes: 58 additions & 25 deletions src/main/java/mov/naspen/lightmaker/LightMaker.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,89 @@
package mov.naspen.lightmaker;

import mov.naspen.lightmaker.events.*;
import mov.naspen.lightmaker.util.Lights;
import mov.naspen.lightmaker.util.HandWatcher;
import mov.naspen.lightmaker.util.LightManager;
import mov.naspen.lightmaker.util.Highlighter;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

import static mov.naspen.lightmaker.Recipe.*;
import static mov.naspen.lightmaker.util.HandWatcher.startWatching;

public final class LightMaker extends JavaPlugin {

public static Highlighter projector;

public static List<NamespacedKey> recipeList = new ArrayList<>();
private Highlighter projector;
private Recipe lightRecipe;
private HandWatcher handWatcher;
private LightManager lightManager;

public static int watchPeriod;
private final List<NamespacedKey> recipeList = new ArrayList<>();
public int watchPeriod;

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerInteraction(), this);
getServer().getPluginManager().registerEvents(new BlockReplacement(), this);
getServer().getPluginManager().registerEvents(new BlockPlacement(), this);
Lights.makeLights();

lightRecipe = new Recipe(this);
projector = new Highlighter(this);
handWatcher = new HandWatcher(this);
lightManager = new LightManager();

getServer().getPluginManager().registerEvents(new PlayerInteraction(this), this);
getServer().getPluginManager().registerEvents(new BlockReplacement(this), this);
getServer().getPluginManager().registerEvents(new BlockPlacement(this), this);

lightManager.makeLights();
this.saveDefaultConfig();

//If setting is true, register player log-in event.
if (this.getConfig().getBoolean("grant_recipes_on_login")) {
getServer().getPluginManager().registerEvents(new PlayerLogin(), this);
}
if (this.getConfig().getBoolean("grant_recipes_on_login"))
getServer().getPluginManager().registerEvents(new PlayerLogin(this), this);

//allows for the creation of custom recipes by disabling the default base ones entirely
if(this.getConfig().getBoolean("enable_base_recipes")) {
addRecipes(this);
}
if(this.getConfig().getBoolean("enable_level_recipes")){
addLevelRecipe(this);
}
if(this.getConfig().getBoolean("stop-entity-spawns-at-0")){getServer().getPluginManager().registerEvents(new CreatureSpawnEventListener(), this);}
watchPeriod = this.getConfig().getInt("watch-period-in-ticks") != 0 ? this.getConfig().getInt("watch-period-in-ticks") : 10;
startWatching(this);
if(this.getConfig().getBoolean("enable_base_recipes"))
lightRecipe.addRecipes();

if(this.getConfig().getBoolean("enable_level_recipes"))
lightRecipe.addLevelRecipe();

if(this.getConfig().getBoolean("stop-entity-spawns-at-0"))
getServer().getPluginManager().registerEvents(new CreatureSpawnEventListener(this), this);


watchPeriod = this.getConfig().getInt("watch-period-in-ticks") != 0
? this.getConfig().getInt("watch-period-in-ticks")
: 10
;

handWatcher.startWatching();

this.getLogger().log(Level.INFO,"Lights can now be MADE by *your* hands!");
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

@NotNull
public List<NamespacedKey> getRecipeList() {
return recipeList;
}

public Highlighter getProjector() {
return projector;
}

public Recipe getLightRecipe() {
return lightRecipe;
}

public LightManager getLightManager() {
return lightManager;
}

public HandWatcher getHandWatcher() {
return handWatcher;
}
}
54 changes: 29 additions & 25 deletions src/main/java/mov/naspen/lightmaker/Recipe.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
package mov.naspen.lightmaker;

import mov.naspen.lightmaker.util.Lights;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.StonecuttingRecipe;
import org.bukkit.plugin.Plugin;

import java.util.List;
import java.util.Objects;
import java.util.logging.Level;

public class Recipe {

public static void addRecipes(Plugin plugin){
String recipe_type = plugin.getConfig().getString("recipe_type");
assert recipe_type != null;
private final LightMaker plugin;

if(recipe_type.equals("bottled-light")){
addBottlingRecipe(plugin);
}else if(recipe_type.equals("shapeless")){
addShapelessRecipe(plugin);
}
public Recipe(LightMaker plugin) {
this.plugin = plugin;
}

public void addRecipes(){
String recipe_type = plugin.getConfig().getString("recipe_type", "shapeless"); // Default value if getString == null

switch (recipe_type) {
case "bottled-light":
addBottlingRecipe();
break;
case "shapeless":
addShapelessRecipe();
break;
}
}

public static void addShapelessRecipe(Plugin plugin){
public void addShapelessRecipe(){
plugin.getLogger().log(Level.INFO,"Adding Shapeless Light Block recipe!");
//create a new unique key
NamespacedKey key = new NamespacedKey(plugin, "light_block_shapeless");
LightMaker.recipeList.add(key);
plugin.getRecipeList().add(key);
//creates a new recipe with the default light quantity as the output quantity
ShapelessRecipe recipe = new ShapelessRecipe(key, Lights.lights.get(15).asQuantity(plugin.getConfig().getInt("default_light_quantity")));
ShapelessRecipe recipe = new ShapelessRecipe(
key, plugin.getLightManager().getLightsList().get(15).asQuantity(plugin.getConfig().getInt("default_light_quantity"))
);
//places the light_ingredients configuration list into a String List
List<String> light_ingredients = plugin.getConfig().getStringList("light_ingredients");
//ensures that the list can fit into a crafting grid
Expand All @@ -53,20 +60,20 @@ public static void addShapelessRecipe(Plugin plugin){
Bukkit.addRecipe(recipe);
}

public static void addBottlingRecipe(Plugin plugin){
public void addBottlingRecipe(){
plugin.getLogger().log(Level.INFO,"Adding Light Block bottling recipe!");
//the name/key of the group used for collecting the recipes in the recipe book.
String bottlingGroup = "light_block_bottling";
//loops through each item in the 'lights_to_bottle' section and creates a recipe with the defined quantity in a group.
for(String ingredient : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("light_ingredients_to_bottle")).getKeys(false)){
//if the quantity for the current entry is zero or doesn't exist, use the default quantity.
int q = plugin.getConfig().getInt("light_ingredients_to_bottle." + ingredient + ".quantity") != 0 ?
plugin.getConfig().getInt("light_ingredients_to_bottle." + ingredient + ".quantity") :
plugin.getConfig().getInt("default_light_quantity");
int q = plugin.getConfig().getInt("light_ingredients_to_bottle." + ingredient + ".quantity") != 0
? plugin.getConfig().getInt("light_ingredients_to_bottle." + ingredient + ".quantity")
: plugin.getConfig().getInt("default_light_quantity");
//create a new unique key with the ingredient name.
NamespacedKey key = new NamespacedKey(plugin, "light_block_bottling_" + ingredient);
//add new key to recipe list for on player login unlocking
LightMaker.recipeList.add(key);
plugin.getRecipeList().add(key);
Material itemToBottle;

try {
Expand All @@ -79,7 +86,8 @@ public static void addBottlingRecipe(Plugin plugin){
}
//create a shapeless recipe with the defined quantity as the output quantity.
ShapelessRecipe bottleRecipe = new ShapelessRecipe(key,
Lights.lights.get(15).asQuantity(q));
plugin.getLightManager().getLightsList().get(15).asQuantity(q)
);

//add a glass bottle to the recipe
bottleRecipe.addIngredient(Material.GLASS_BOTTLE);
Expand All @@ -94,15 +102,11 @@ public static void addBottlingRecipe(Plugin plugin){
plugin.getLogger().log(Level.INFO,"Light Block bottling recipes have been added!");
}

public static void addLevelRecipe(Plugin plugin){
public void addLevelRecipe(){
for (int i = 15; i >= 0; i--){
NamespacedKey key = new NamespacedKey(plugin, "light_count_" + i);
StonecuttingRecipe recipe = new StonecuttingRecipe(key, Lights.lights.get(i), Material.LIGHT);
StonecuttingRecipe recipe = new StonecuttingRecipe(key, plugin.getLightManager().getLightsList().get(i), Material.LIGHT);
Bukkit.getServer().addRecipe(recipe);
}
}




}
12 changes: 9 additions & 3 deletions src/main/java/mov/naspen/lightmaker/events/BlockPlacement.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package mov.naspen.lightmaker.events;

import mov.naspen.lightmaker.LightMaker;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;

import static mov.naspen.lightmaker.util.ParticleRender.summonMarker;

public class BlockPlacement implements Listener {

private final LightMaker plugin;

public BlockPlacement(LightMaker plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.NORMAL)
public void BlockPlaceEvent(BlockPlaceEvent e) {
if(e.getBlock().getType() == Material.LIGHT && !e.isCancelled()){
summonMarker(e.getPlayer(),e.getBlock());
e.getPlayer().spawnParticle(Particle.BLOCK_MARKER, e.getBlock().getLocation().toCenterLocation(), 1, e.getBlock().getBlockData());
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/main/java/mov/naspen/lightmaker/events/BlockReplacement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mov.naspen.lightmaker.events;

import mov.naspen.lightmaker.util.Lights;
import mov.naspen.lightmaker.LightMaker;
import org.bukkit.Material;
import org.bukkit.block.data.type.Light;
import org.bukkit.event.EventHandler;
Expand All @@ -10,12 +10,21 @@

public class BlockReplacement implements Listener {

private final LightMaker plugin;

public BlockReplacement(LightMaker plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.NORMAL)
public void BlockPlaceEvent(BlockPlaceEvent e) {
if(e.isCancelled()){return;}
if(e.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE){return;}
if(e.isCancelled()) return;
if(e.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE) return;
if(e.getBlockReplacedState().getType() == Material.LIGHT){
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), Lights.makeLight(((Light) e.getBlockReplacedState().getBlockData()).getLevel()));
e.getBlock().getWorld().dropItemNaturally(
e.getBlock().getLocation(),
plugin.getLightManager().makeLight(((Light) e.getBlockReplacedState().getBlockData()).getLevel())
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package mov.naspen.lightmaker.events;

import mov.naspen.lightmaker.LightMaker;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.Light;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class CreatureSpawnEventListener implements Listener {

private final LightMaker plugin;

public CreatureSpawnEventListener(LightMaker plugin) {
this.plugin = plugin;
}

@EventHandler
public void onCreatureSpawnEvent(CreatureSpawnEvent e) {
if(
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/mov/naspen/lightmaker/events/PlayerInteraction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mov.naspen.lightmaker.events;

import mov.naspen.lightmaker.LightMaker;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
Expand All @@ -16,14 +17,18 @@

import java.util.*;

import static mov.naspen.lightmaker.util.Lights.*;

public class PlayerInteraction implements Listener {

private final LightMaker plugin;

public PlayerInteraction(LightMaker plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerInteractEvent(PlayerInteractEvent e) {
if (e.useInteractedBlock() == Event.Result.DENY){ return;}
if (e.getItem() != null && e.getClickedBlock() != null && isLight(e.getItem())) {
if (e.getItem() != null && e.getClickedBlock() != null && plugin.getLightManager().isLight(e.getItem())) {
//get Block
Block b = e.getClickedBlock();
//check block type
Expand All @@ -38,7 +43,7 @@ public void PlayerInteractEvent(PlayerInteractEvent e) {
if(!be.isCancelled()){
b.breakNaturally();
List<Item> items = new ArrayList<>();
items.add(b.getWorld().dropItemNaturally(b.getLocation(), lights.get(l)));
items.add(b.getWorld().dropItemNaturally(b.getLocation(), plugin.getLightManager().getLightsList().get(l)));
if(!(new BlockDropItemEvent(b, b.getState(), e.getPlayer(), items).callEvent())){
for(Item i : items){
i.remove();
Expand All @@ -49,7 +54,7 @@ public void PlayerInteractEvent(PlayerInteractEvent e) {
} else if (e.getAction() == Action.RIGHT_CLICK_BLOCK && !e.getPlayer().isSneaking()) {
//if Player is sneaking don't match the light level. If they are use the vanilla level
//get hand level
int handLevel = getLightLevel(e.getItem().asOne());
int handLevel = plugin.getLightManager().getLightLevel(e.getItem().asOne());
e.setCancelled(true);
BlockData data = b.getBlockData();
((Levelled) data).setLevel(handLevel);
Expand Down
Loading