Merge branch 'development'

This commit is contained in:
Brianna 2020-09-24 14:40:04 -05:00
commit 6ded055ed6
22 changed files with 105 additions and 85 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicHeads</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>3.2.12</version>
<version>3.2.13</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicHeads-${project.version}</finalName>
@ -83,11 +83,11 @@
<repositories>
<repository>
<id>private</id>
<url>https://repo.songoda.com/artifactory/private/</url>
<url>https://repo.songoda.com/repository/private/</url>
</repository>
<repository>
<id>public</id>
<url>https://repo.songoda.com/artifactory/public/</url>
<url>https://repo.songoda.com/repository/public/</url>
</repository>
<repository>
<id>spigot-repo</id>

View File

@ -29,7 +29,13 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;
@ -118,18 +124,12 @@ public class EpicHeads extends SongodaPlugin {
// Load Heads
loadHeads();
// Load Favorites
loadData();
int timeout = Settings.AUTOSAVE.getInt() * 60 * 20;
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, timeout, timeout);
}
private void saveToFile() {
storage.doSave();
}
private void loadData() {
@Override
public void onDataLoad() {
// Adding in favorites.
if (storage.containsGroup("players")) {
for (StorageRow row : storage.getRowsByGroup("players")) {
@ -148,6 +148,9 @@ public class EpicHeads extends SongodaPlugin {
this.saveToFile();
}
private void saveToFile() {
storage.doSave();
}
private void downloadHeads() {
try {

View File

@ -12,11 +12,11 @@ import java.util.stream.Collectors;
public class CommandAdd extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandAdd(EpicHeads instance) {
super(false, "add");
this.instance = instance;
public CommandAdd(EpicHeads plugin) {
super(CommandType.CONSOLE_OK, "add");
this.plugin = plugin;
}
@Override
@ -27,10 +27,10 @@ public class CommandAdd extends AbstractCommand {
String name = args[1].replace("_", " ");
String categoryStr = args[2].replace("_", " ");
HeadManager headManager = instance.getHeadManager();
HeadManager headManager = plugin.getHeadManager();
if (headManager.getLocalHeads().stream().anyMatch(head -> head.getURL().equals(url))) {
instance.getLocale().getMessage("command.add.exists").sendPrefixedMessage(sender);
plugin.getLocale().getMessage("command.add.exists").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -40,10 +40,10 @@ public class CommandAdd extends AbstractCommand {
headManager.addLocalHead(new Head(headManager.getNextLocalId(), name, url, category, true, null, (byte) 0));
instance.getLocale().getMessage("command.add.success")
plugin.getLocale().getMessage("command.add.success")
.processPlaceholder("name", name).sendPrefixedMessage(sender);
if (categories.isEmpty()) {
instance.reloadConfig();
plugin.reloadConfig();
}
return ReturnType.SUCCESS;
}

View File

@ -3,7 +3,6 @@ package com.songoda.epicheads.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.ItemUtils;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.utils.Methods;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -13,11 +12,11 @@ import java.util.List;
public class CommandBase64 extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandBase64(EpicHeads instance) {
super(true, "base64");
this.instance = instance;
public CommandBase64(EpicHeads plugin) {
super(CommandType.PLAYER_ONLY, "base64");
this.plugin = plugin;
}
@Override
@ -33,7 +32,7 @@ public class CommandBase64 extends AbstractCommand {
if (encodededStr == null) return ReturnType.FAILURE;
instance.getLocale().newMessage(encodededStr).sendPrefixedMessage(player);
plugin.getLocale().newMessage(encodededStr).sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}

View File

@ -2,7 +2,6 @@ package com.songoda.epicheads.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.gui.GUIOverview;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,10 +10,10 @@ import java.util.List;
public class CommandEpicHeads extends AbstractCommand {
final GuiManager guiManager;
private final GuiManager guiManager;
public CommandEpicHeads(GuiManager guiManager) {
super(false, "EpicHeads");
super(CommandType.PLAYER_ONLY, "EpicHeads");
this.guiManager = guiManager;
}

View File

@ -15,11 +15,11 @@ import java.util.Optional;
public class CommandGive extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandGive(EpicHeads instance) {
super(false, "give");
this.instance = instance;
public CommandGive(EpicHeads plugin) {
super(CommandType.CONSOLE_OK, "give");
this.plugin = plugin;
}
@Override
@ -32,7 +32,7 @@ public class CommandGive extends AbstractCommand {
int headId = Integer.parseInt(args[2]);
if (player == null && !playerStr.equals("all")) {
instance.getLocale().getMessage("command.give.notonline")
plugin.getLocale().getMessage("command.give.notonline")
.processPlaceholder("name", args[1]).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -40,9 +40,9 @@ public class CommandGive extends AbstractCommand {
List<Head> heads;
if (archive.equalsIgnoreCase("global"))
heads = instance.getHeadManager().getGlobalHeads();
heads = plugin.getHeadManager().getGlobalHeads();
else if (archive.equalsIgnoreCase("local"))
heads = instance.getHeadManager().getLocalHeads();
heads = plugin.getHeadManager().getLocalHeads();
else {
return ReturnType.SYNTAX_ERROR;
}
@ -61,18 +61,18 @@ public class CommandGive extends AbstractCommand {
if (pl == sender) continue;
pl.getInventory().addItem(item);
instance.getLocale().getMessage("command.give.receive")
plugin.getLocale().getMessage("command.give.receive")
.processPlaceholder("name", head.get().getName()).sendPrefixedMessage(pl);
}
instance.getLocale().getMessage("command.give.success")
.processPlaceholder("player", instance.getLocale().getMessage("general.word.everyone").getMessage())
plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("player", plugin.getLocale().getMessage("general.word.everyone").getMessage())
.processPlaceholder("name", head.get().getName())
.sendPrefixedMessage(sender);
} else {
player.getInventory().addItem(item);
instance.getLocale().getMessage("command.give.receive")
plugin.getLocale().getMessage("command.give.receive")
.processPlaceholder("name", head.get().getName()).sendPrefixedMessage(player);
instance.getLocale().getMessage("command.give.success")
plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("player", player.getName())
.processPlaceholder("name", head.get().getName())
.sendPrefixedMessage(sender);
@ -80,7 +80,7 @@ public class CommandGive extends AbstractCommand {
return ReturnType.SUCCESS;
} else {
instance.getLocale().getMessage("command.give.notfound")
plugin.getLocale().getMessage("command.give.notfound")
.processPlaceholder("name", head.get().getName()).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

View File

@ -11,11 +11,11 @@ import java.util.List;
public class CommandGiveToken extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandGiveToken(EpicHeads instance) {
super(false, "givetoken");
this.instance = instance;
public CommandGiveToken(EpicHeads plugin) {
super(CommandType.CONSOLE_OK, "givetoken");
this.plugin = plugin;
}
@Override
@ -26,18 +26,18 @@ public class CommandGiveToken extends AbstractCommand {
int amount = Integer.parseInt(args[1]);
if (player == null) {
instance.getLocale().getMessage("command.give.notonline")
plugin.getLocale().getMessage("command.give.notonline")
.processPlaceholder("name", args[1]).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
player.getInventory().addItem(Methods.createToken(amount));
instance.getLocale().getMessage("command.givetoken.receive")
plugin.getLocale().getMessage("command.givetoken.receive")
.processPlaceholder("amount", amount).sendPrefixedMessage(player);
if (player != sender)
instance.getLocale().getMessage("command.givetoken.success")
plugin.getLocale().getMessage("command.givetoken.success")
.processPlaceholder("player", player.getName())
.processPlaceholder("amount", amount).sendPrefixedMessage(sender);

View File

@ -11,24 +11,24 @@ import java.util.List;
public class CommandHelp extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandHelp(EpicHeads instance) {
super(false, "help");
this.instance = instance;
public CommandHelp(EpicHeads plugin) {
super(CommandType.CONSOLE_OK, "help");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage("");
new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa",
instance.getDescription().getName(), instance.getDescription().getVersion()))
plugin.getDescription().getName(), plugin.getDescription().getVersion()))
.sendTo(sender);
sender.sendMessage("");
sender.sendMessage(Methods.formatText("&7Welcome to EpicHeads! To get started try using the command /heads to access the heads panel."));
sender.sendMessage("");
sender.sendMessage(Methods.formatText("&6Commands:"));
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
for (AbstractCommand command : plugin.getCommandManager().getAllCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + command.getSyntax() + ChatColor.GRAY + " - " + command.getDescription());
}

View File

@ -8,17 +8,17 @@ import java.util.List;
public class CommandReload extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandReload(EpicHeads instance) {
super(false, "reload");
this.instance = instance;
public CommandReload(EpicHeads plugin) {
super(CommandType.CONSOLE_OK, "reload");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reloadConfig();
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
plugin.reloadConfig();
plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -11,10 +11,10 @@ import java.util.List;
public class CommandSearch extends AbstractCommand {
final GuiManager guiManager;
private final GuiManager guiManager;
public CommandSearch(GuiManager guiManager) {
super(true, "search");
super(CommandType.PLAYER_ONLY, "search");
this.guiManager = guiManager;
}

View File

@ -11,10 +11,10 @@ import java.util.List;
public class CommandSettings extends AbstractCommand {
final GuiManager guiManager;
private final GuiManager guiManager;
public CommandSettings(GuiManager guiManager) {
super(true, "settings");
super(CommandType.PLAYER_ONLY, "settings");
this.guiManager = guiManager;
}

View File

@ -3,7 +3,6 @@ package com.songoda.epicheads.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.ItemUtils;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.utils.Methods;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -13,11 +12,11 @@ import java.util.List;
public class CommandUrl extends AbstractCommand {
final EpicHeads instance;
private final EpicHeads plugin;
public CommandUrl(EpicHeads instance) {
super(true, "url");
this.instance = instance;
public CommandUrl(EpicHeads plugin) {
super(CommandType.PLAYER_ONLY, "url");
this.plugin = plugin;
}
@Override
@ -34,7 +33,7 @@ public class CommandUrl extends AbstractCommand {
String url = ItemUtils.getDecodedTexture(encodededStr);
instance.getLocale().newMessage("http://textures.minecraft.net/texture/" + url).sendPrefixedMessage(player);
plugin.getLocale().newMessage("http://textures.minecraft.net/texture/" + url).sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}

View File

@ -81,7 +81,7 @@ public class GUIHeads extends Gui {
this.setTitle(name + " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page").getMessage() + " " + (page) + "/" + (pages));
}
void showPage() {
private void showPage() {
updateTitle();
List<Head> pageHeads = this.heads.stream().skip((page - 1) * (rows - 1) * 9).limit((rows - 1) * 9)
.collect(Collectors.toList());

View File

@ -37,7 +37,7 @@ public class GUIOverview extends Gui {
showPage();
}
void showPage() {
private void showPage() {
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.GOLDEN_APPLE,
plugin.getLocale().getMessage("gui.overview.viewfavorites").getMessage(),
plugin.getLocale().getMessage("gui.overview.favoriteslore").getMessage().split("\\|")),

View File

@ -1,6 +1,5 @@
package com.songoda.epicheads.head;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.utils.ItemUtils;
import com.songoda.epicheads.EpicHeads;
@ -81,7 +80,7 @@ public class Head {
ItemStack item = ItemUtils.getCustomHead(this.URL);
ItemMeta meta = item.getItemMeta();
if(meta != null) {
if (meta != null) {
meta.setDisplayName(getHeadItemName(favorite));
meta.setLore(getHeadItemLore(free));
item.setItemMeta(meta);

View File

@ -1,6 +1,13 @@
package com.songoda.epicheads.head;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

View File

@ -33,7 +33,7 @@ public class DeathListeners implements Listener {
double rand = Math.random() * 100;
if (rand - ch < 0 || ch == 100) {
ItemStack itemNew;
ItemStack itemNew = null;
if (event.getEntity() instanceof Player) {
if (!Settings.DROP_PLAYER_HEADS.getBoolean()) return;
@ -52,7 +52,8 @@ public class DeathListeners implements Listener {
Optional<Head> optional = plugin.getHeadManager().getHeads().stream()
.filter(head -> url.equals(head.getURL())).findFirst();
itemNew = optional.get().asItemStack();
if (optional.isPresent())
itemNew = optional.get().asItemStack();
}
} else {
if (!Settings.DROP_MOB_HEADS.getBoolean() || event.getEntity() instanceof ArmorStand) return;
@ -63,6 +64,7 @@ public class DeathListeners implements Listener {
null, true, null, (byte) 0);
itemNew = head.asItemStack();
}
if (itemNew == null) return;
ItemMeta meta = itemNew.getItemMeta();
meta.setLore(new ArrayList<>());

View File

@ -53,7 +53,7 @@ public class LoginListeners implements Listener {
headManager.removeLocalHead(head);
}
headManager.addLocalHeads(new Head(id, player.getName(), url, tag, true,null, (byte) 0));
headManager.addLocalHeads(new Head(id, player.getName(), url, tag, true, null, (byte) 0));
}

View File

@ -2,7 +2,11 @@ package com.songoda.epicheads.players;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class PlayerManager {

View File

@ -5,7 +5,6 @@ import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.head.Head;
import java.util.Arrays;
import java.util.stream.Collectors;

View File

@ -1,7 +1,5 @@
package com.songoda.epicheads.utils;
import org.bukkit.entity.EntityType;
/**
* Created by songoda on 3/20/2017.
*/

View File

@ -7,8 +7,19 @@ import com.songoda.epicheads.utils.storage.StorageRow;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class StorageYaml extends Storage {