Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Smudgge committed Jul 16, 2024
1 parent 4f1955c commit bcdf1c8
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cozyplugins</groupId>
<artifactId>CozyTreasureHunt</artifactId>
<version>1.2.0</version>
<version>1.3.1</version>
<packaging>jar</packaging>
<name>CozyTreasureHunt</name>

Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>com.github.Cozy-Plugins</groupId>
<artifactId>CozyLibrary</artifactId>
<version>1.0.2</version>
<version>1.12.2</version>
</dependency>

<!-- HeadDatabase -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

import com.github.cozyplugins.cozylibrary.ConsoleManager;
import com.github.cozyplugins.cozylibrary.datatype.ratio.Ratio;
import com.github.cozyplugins.cozylibrary.indicator.ConfigurationConvertable;
import com.github.cozyplugins.cozylibrary.indicator.Replicable;
import com.github.cozyplugins.cozylibrary.item.CozyItem;
import com.github.cozyplugins.cozylibrary.reward.RewardBundle;
import com.github.cozyplugins.cozylibrary.user.PlayerUser;
import com.github.cozyplugins.cozytreasurehunt.dependency.HeadDatabaseDependency;
import com.github.cozyplugins.cozytreasurehunt.storage.TreasureStorage;
import com.github.cozyplugins.cozytreasurehunt.storage.indicator.Savable;
import com.github.smuddgge.squishyconfiguration.indicator.ConfigurationConvertable;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import com.github.smuddgge.squishyconfiguration.memory.MemoryConfigurationSection;
import org.bukkit.*;
import org.bukkit.block.Skull;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
Expand All @@ -55,6 +56,7 @@ public class Treasure implements ConfigurationConvertable<Treasure>, Savable, Re

private @NotNull Material material;
private @Nullable String hdb;
private @Nullable UUID skullOwner;

private @Nullable String publicBroadcastMessage;
private @Nullable String privateBroadcastMessage;
Expand Down Expand Up @@ -154,12 +156,20 @@ public Treasure(@NotNull UUID identifier) {
* @return The treasure as an item.
*/
public @NotNull CozyItem getItem() {

// Check if the head database is enabled and there is a hdb value.
if (HeadDatabaseDependency.isEnabled() && this.hdb != null && !this.hdb.equals("")) {
ItemStack item = HeadDatabaseDependency.get().getItemHead(this.hdb);
return new CozyItem(item);
}

// Check if there is a skull owner.
if (this.skullOwner != null) {
return new CozyItem(this.material)
.setMaterial(Material.PLAYER_HEAD)
.setSkull(this.skullOwner);
}

return new CozyItem(this.material);
}

Expand Down Expand Up @@ -368,6 +378,17 @@ public int getRespawnTime() {
return this;
}

/**
* Used to set the skull owner.
*
* @param skullOwner The skull owner.
* @return This instance.
*/
public @NotNull Treasure setSkullOwner(UUID skullOwner) {
this.skullOwner = skullOwner;
return this;
}

/**
* Used to set the public broadcast message.
* Setting this value to null will not show a
Expand Down Expand Up @@ -640,6 +661,13 @@ public int getRespawnTime() {
HeadDatabaseDependency.get().setBlockSkin(location.getBlock(), this.hdb);
}

if (this.skullOwner != null) {
location.getBlock().setType(Material.PLAYER_HEAD);
Skull skull = (Skull) location.getBlock().getState();
skull.setOwningPlayer(Bukkit.getOfflinePlayer(this.skullOwner));
skull.update();
}

return this;
}

Expand Down Expand Up @@ -715,6 +743,7 @@ public void spawnParticlesPlayerRight(@NotNull PlayerUser playerUser) {

section.set("material", this.material.toString());
section.set("hdb", this.hdb);
if (this.skullOwner != null) section.set("skull_owner", this.skullOwner.toString());

section.set("public_broadcast_message", this.publicBroadcastMessage);
section.set("private_broadcast_message", this.privateBroadcastMessage);
Expand Down Expand Up @@ -755,6 +784,7 @@ public Treasure convert(ConfigurationSection section) {

this.material = Material.getMaterial(materialName);
this.hdb = section.getString("hdb");
if (section.getKeys().contains("skull_owner")) this.skullOwner = UUID.fromString(section.getString("skull_owner"));

this.publicBroadcastMessage = section.getString("public_broadcast_message");
this.privateBroadcastMessage = section.getString("private_broadcast_message");
Expand All @@ -781,6 +811,7 @@ public Treasure convert(ConfigurationSection section) {
return this;
}


@Override
public void save() {
TreasureStorage.insert(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package com.github.cozyplugins.cozytreasurehunt;

import com.github.cozyplugins.cozylibrary.indicator.ConfigurationConvertable;
import com.github.cozyplugins.cozylibrary.indicator.Replicable;
import com.github.cozyplugins.cozytreasurehunt.event.TreasurePostSpawnEvent;
import com.github.cozyplugins.cozytreasurehunt.event.TreasurePreSpawnEvent;
import com.github.cozyplugins.cozytreasurehunt.storage.LocationStorage;
import com.github.cozyplugins.cozytreasurehunt.storage.TreasureStorage;
import com.github.cozyplugins.cozytreasurehunt.storage.indicator.Savable;
import com.github.smuddgge.squishyconfiguration.indicator.ConfigurationConvertable;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import com.github.smuddgge.squishyconfiguration.memory.MemoryConfigurationSection;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -212,7 +212,7 @@ public String toString() {
}

@Override
public TreasureLocation convert(ConfigurationSection section) {
public @NotNull TreasureLocation convert(@NotNull ConfigurationSection section) {
this.isSpawned = section.getBoolean("is_spawned");
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class SetCommand implements CommandType {
@Override
public @Nullable CommandStatus onPlayer(@NotNull PlayerUser user, @NotNull ConfigurationSection section, @NotNull CommandArguments arguments) {
// Check if there is no treasure specified.
if (arguments.getArguments().isEmpty() || Objects.equals(arguments.getArguments().get(1), "")) {
if (arguments.getArguments().isEmpty() || Objects.equals(arguments.getArguments().get(0), "")) {
user.sendMessage(section.getString("invalid_treasure", "&7Treasure type does not exist."));
return new CommandStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.github.cozyplugins.cozytreasurehunt.inventory.editor;

import com.github.cozyplugins.cozylibrary.datatype.ratio.Ratio;
import com.github.cozyplugins.cozylibrary.inventory.InventoryInterface;
import com.github.cozyplugins.cozylibrary.inventory.CozyInventory;
import com.github.cozyplugins.cozylibrary.inventory.InventoryItem;
import com.github.cozyplugins.cozylibrary.inventory.action.action.AnvilValueAction;
import com.github.cozyplugins.cozylibrary.inventory.action.action.ClickAction;
Expand All @@ -42,7 +42,7 @@
/**
* An inventory used to edit a type of treasure.
*/
public class TreasureEditor extends InventoryInterface {
public class TreasureEditor extends CozyInventory {

private final @NotNull Treasure treasure;
private final TreasureListEditor listEditor;
Expand Down Expand Up @@ -207,6 +207,22 @@ protected void onGenerate(PlayerUser player) {
if (hdb != null) this.treasure.setHdb(hdb);
}

if (this.treasure.getMaterial() == Material.PLAYER_HEAD) {

if (HeadDatabaseDependency.isEnabled()) {
HeadDatabaseAPI api = HeadDatabaseDependency.get();
String hdb = api.getItemID(item.create());

if (hdb != null) {
this.treasure.setHdb(hdb);
}
}

if (this.treasure.getHdb() == null) {
this.treasure.setSkullOwner(item.getSkullOwner());
}
}

this.treasure.save();

// Replace the item type.
Expand Down Expand Up @@ -738,7 +754,7 @@ private void setPage1() {
"&7will be given when this treasure is found.")
.addSlot(31)
.addAction((ClickAction) (user, type, inventory) -> {
InventoryInterface back = this;
CozyInventory back = this;

// Create editor inventory.
RewardBundleEditorInventory editorInventory = new RewardBundleEditorInventory(this.treasure.getRewardBundle()) {
Expand All @@ -749,7 +765,7 @@ protected void onBundleUpdate(@NotNull RewardBundle bundle) {
}

@Override
protected @Nullable InventoryInterface onBackButton(@NotNull PlayerUser user) {
protected @Nullable CozyInventory onBackButton(@NotNull PlayerUser user) {
return back;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

package com.github.cozyplugins.cozytreasurehunt.inventory.editor;

import com.github.cozyplugins.cozylibrary.inventory.InventoryInterface;
import com.github.cozyplugins.cozylibrary.inventory.CozyInventory;
import com.github.cozyplugins.cozylibrary.inventory.InventoryItem;
import com.github.cozyplugins.cozylibrary.inventory.action.action.ClickAction;
import com.github.cozyplugins.cozylibrary.item.CozyItem;
import com.github.cozyplugins.cozylibrary.user.PlayerUser;
import com.github.cozyplugins.cozytreasurehunt.Treasure;
import com.github.cozyplugins.cozytreasurehunt.storage.TreasureStorage;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
Expand All @@ -40,7 +40,7 @@
* An inventory that displays the list of types of
* treasure that the player can edit.
*/
public class TreasureListEditor extends InventoryInterface {
public class TreasureListEditor extends CozyInventory {

private @NotNull List<Treasure> treasureList;
private int page;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.cozyplugins.cozytreasurehunt.storage;

import com.github.cozyplugins.cozylibrary.CozyPlugin;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import org.jetbrains.annotations.NotNull;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.cozyplugins.cozytreasurehunt.Leaderboard;
import com.github.cozyplugins.cozytreasurehunt.TreasureLocation;
import com.github.cozyplugins.cozytreasurehunt.storage.configuration.DataConfigurationDirectory;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.cozyplugins.cozylibrary.location.Region3D;
import com.github.cozyplugins.cozytreasurehunt.TreasureLocation;
import com.github.cozyplugins.cozytreasurehunt.storage.configuration.LocationConfigurationDirectory;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.cozyplugins.cozytreasurehunt.storage;

import com.github.cozyplugins.cozylibrary.indicator.ConfigurationConvertable;
import com.github.cozyplugins.cozytreasurehunt.TreasureLocation;
import com.github.cozyplugins.cozytreasurehunt.storage.indicator.Savable;
import com.github.smuddgge.squishyconfiguration.indicator.ConfigurationConvertable;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import com.github.smuddgge.squishyconfiguration.memory.MemoryConfigurationSection;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.cozyplugins.cozylibrary.ConsoleManager;
import com.github.cozyplugins.cozylibrary.configuration.ConfigurationDirectory;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.cozyplugins.cozylibrary.configuration.ConfigurationDirectory;
import com.github.cozyplugins.cozytreasurehunt.Treasure;
import com.github.cozyplugins.cozytreasurehunt.storage.configuration.TreasureConfigurationDirectory;
import com.github.smuddgge.squishyconfiguration.implementation.yaml.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.implementation.YamlConfiguration;
import com.github.smuddgge.squishyconfiguration.interfaces.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down

0 comments on commit bcdf1c8

Please sign in to comment.