Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create custom heads without username field #31

Closed
wants to merge 1 commit into from
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
292 changes: 146 additions & 146 deletions src/main/java/me/rayzr522/decoheads/data/Head.java
Original file line number Diff line number Diff line change
@@ -1,146 +1,146 @@
/**
*
*/
package me.rayzr522.decoheads.data;

import me.rayzr522.decoheads.Category;
import me.rayzr522.decoheads.DecoHeads;
import me.rayzr522.decoheads.util.CustomHead;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* @author Rayzr
*/
public class Head {
private String name;
private Category category;

private String texture;
private String uuid;
private double cost;

private boolean enabled;

private Head(String name, Category category, ConfigurationSection config) {
if (!config.isString("texture")) {
throw new IllegalArgumentException("config for head '" + name + "' is missing 'texture' key!");
}

this.name = name;
this.category = category;

this.texture = config.getString("texture");
this.uuid = config.getString("uuid", UUID.randomUUID().toString());
this.cost = config.getDouble("cost", -1);
this.enabled = config.getBoolean("enabled", true);
}

public Head(String name, Category category, String texture, UUID uuid, double cost) {
this.name = name;
this.category = category;
this.texture = texture;
this.uuid = uuid.toString();
this.cost = cost;
this.enabled = true;
}

public static Head load(String name, Category category, ConfigurationSection config) {
try {
return new Head(name, category, config);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public Map<String, Object> serialize() {
HashMap<String, Object> map = new HashMap<>();
map.put("texture", texture);
map.put("uuid", uuid);
map.put("cost", cost);
return map;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

public String getTexture() {
return texture;
}

public String getUUID() {
return uuid;
}

public double getCost() {
return cost;
}

public void setCost(double cost) {
this.cost = cost;
}

public double computeCostFor(Player player) {
if (DecoHeads.getInstance().checkPermission(String.format("free.%s", getInternalName()), player, false)) {
return 0.0;
}

return cost != -1 ? cost : DecoHeads.getInstance().getSettings().getDefaultHeadCost();
}

public boolean hasCostFor(Player player) {
return computeCostFor(player) > 0.0;
}

public boolean isUseableBy(CommandSender sender) {
return isEnabled() && DecoHeads.getInstance().checkPermission(String.format("head.%s", getInternalName()), sender, false);
}

private String getInternalName() {
return name.toLowerCase().replaceAll("[^a-z0-9-]", "-");
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public String toString() {
return "Head{" +
"name='" + name + '\'' +
", category=" + category +
", texture='" + texture + '\'' +
", uuid='" + uuid + '\'' +
", cost=" + cost +
", enabled=" + enabled +
'}';
}

public ItemStack getItem() {
return CustomHead.getHead(texture, uuid, name);
}
}
/**
*
*/
package me.rayzr522.decoheads.data;
import me.rayzr522.decoheads.Category;
import me.rayzr522.decoheads.DecoHeads;
import me.rayzr522.decoheads.util.CustomHead;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author Rayzr
*/
public class Head {
private String name;
private Category category;
private String texture;
private String uuid;
private double cost;
private boolean enabled;
private Head(String name, Category category, ConfigurationSection config) {
if (!config.isString("texture")) {
throw new IllegalArgumentException("config for head '" + name + "' is missing 'texture' key!");
}
this.name = name;
this.category = category;
this.texture = config.getString("texture");
this.uuid = config.getString("uuid", UUID.randomUUID().toString());
this.cost = config.getDouble("cost", -1);
this.enabled = config.getBoolean("enabled", true);
}
public Head(String name, Category category, String texture, UUID uuid, double cost) {
this.name = name;
this.category = category;
this.texture = texture;
this.uuid = uuid.toString();
this.cost = cost;
this.enabled = true;
}
public static Head load(String name, Category category, ConfigurationSection config) {
try {
return new Head(name, category, config);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public Map<String, Object> serialize() {
HashMap<String, Object> map = new HashMap<>();
map.put("texture", texture);
map.put("uuid", uuid);
map.put("cost", cost);
return map;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public String getTexture() {
return texture;
}
public String getUUID() {
return uuid;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
public double computeCostFor(Player player) {
if (DecoHeads.getInstance().checkPermission(String.format("free.%s", getInternalName()), player, false)) {
return 0.0;
}
return cost != -1 ? cost : DecoHeads.getInstance().getSettings().getDefaultHeadCost();
}
public boolean hasCostFor(Player player) {
return computeCostFor(player) > 0.0;
}
public boolean isUseableBy(CommandSender sender) {
return isEnabled() && DecoHeads.getInstance().checkPermission(String.format("head.%s", getInternalName()), sender, false);
}
private String getInternalName() {
return name.toLowerCase().replaceAll("[^a-z0-9-]", "-");
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public String toString() {
return "Head{" +
"name='" + name + '\'' +
", category=" + category +
", texture='" + texture + '\'' +
", uuid='" + uuid + '\'' +
", cost=" + cost +
", enabled=" + enabled +
'}';
}
public ItemStack getItem() {
return CustomHead.getHead(texture, uuid);
}
}
Loading