mirror of
https://github.com/songoda/EpicHeads.git
synced 2025-02-21 13:51:22 +01:00
Updated to 2.0.6 (not too much manual updates).
This commit is contained in:
parent
5f115ddd6c
commit
95db89bffa
@ -72,13 +72,9 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
Clock timer = Clock.start();
|
||||
|
||||
loadCache();
|
||||
|
||||
try {
|
||||
legacyIDs = LegacyIDs.readResource("legacy-ids.txt");
|
||||
} catch (IOException exception) {
|
||||
@ -86,37 +82,27 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
severe("Unable to load legacy IDs to perform conversion from older Spigot versions");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
this.menus = new Menus();
|
||||
this.menus.reload();
|
||||
|
||||
this.oldMenuConfig = new MenuConfig(getVersionedConfig("menus.yml"));
|
||||
this.langConfig = new LangConfig();
|
||||
this.mainConfig = new MainConfig();
|
||||
this.economy = hookEconomy();
|
||||
|
||||
ProtocolHackFixer.fix();
|
||||
|
||||
registerCommands();
|
||||
tryHookBlockStore();
|
||||
|
||||
new HeadNamer().registerEvents();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
CraftMetaItem.registerItems();
|
||||
|
||||
if (mainConfig.shouldCheckForUpdates()) {
|
||||
checkForUpdates();
|
||||
}
|
||||
|
||||
info("Heads plugin enabled with " + cache.getHeadCount() + " heads " + timer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
instance = null;
|
||||
|
||||
unregisterCommands();
|
||||
}
|
||||
|
||||
@ -125,10 +111,8 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
try {
|
||||
String currentVersion = UpdateChecker.getCurrentVersion();
|
||||
String latestVersion = UpdateChecker.getLatestVersion();
|
||||
|
||||
if (!UpdateChecker.isNewerVersion(latestVersion))
|
||||
return;
|
||||
|
||||
// Learn how to use LangMessage - included next update.
|
||||
warning("A newer version of Heads, Heads v" + latestVersion + ", is available for download");
|
||||
warning("You are currently using Heads v" + currentVersion);
|
||||
@ -142,25 +126,19 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
if (commandsRegistered) {
|
||||
unregisterCommands();
|
||||
}
|
||||
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
|
||||
RuntimeCommand heads = new RuntimeCommand(mainConfig.getHeadCommand());
|
||||
heads.setExecutor(new HeadsCommand());
|
||||
heads.setDescription(mainConfig.getHeadDescription());
|
||||
heads.setAliases(Arrays.asList(mainConfig.getHeadAliases()));
|
||||
|
||||
commandMap.register("heads", heads);
|
||||
|
||||
commandsRegistered = true;
|
||||
}
|
||||
|
||||
private void unregisterCommands() {
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
Map<String, Command> map = CommandMap.getCommandMap(commandMap);
|
||||
|
||||
map.values().removeIf(command -> command instanceof RuntimeCommand);
|
||||
|
||||
commandsRegistered = false;
|
||||
}
|
||||
|
||||
@ -169,39 +147,29 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
menus.reload();
|
||||
langConfig.reload();
|
||||
mainConfig.reload();
|
||||
|
||||
registerCommands();
|
||||
|
||||
economy = hookEconomy();
|
||||
|
||||
tryHookBlockStore();
|
||||
}
|
||||
|
||||
public File getCacheFile() {
|
||||
if (!getDataFolder().exists() && !getDataFolder().mkdirs())
|
||||
throw new RuntimeException("Unable to create the data folder to save plugin files");
|
||||
|
||||
if (!getDataFolder().isDirectory())
|
||||
throw new RuntimeException("plugins/Heads should be a directory, yet there is a file with the same name");
|
||||
|
||||
return new File(getDataFolder(), "heads.cache");
|
||||
}
|
||||
|
||||
private CacheFile loadCache() {
|
||||
File file = getCacheFile();
|
||||
FileConfigFile legacyConfig = new FileConfigFile("cache.yml");
|
||||
|
||||
boolean requiresWrite = false;
|
||||
|
||||
if (!file.exists()) {
|
||||
requiresWrite = true;
|
||||
|
||||
if (legacyConfig.getFile().exists()) {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
LegacyCacheConfig legacy = new LegacyCacheConfig(legacyConfig);
|
||||
cache = CacheFileConverter.convertToCacheFile("main-cache", legacy);
|
||||
|
||||
info("Converted legacy yaml cache file to new binary file " + timer);
|
||||
} else {
|
||||
cache = new CacheFile("main-cache");
|
||||
@ -209,9 +177,7 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
} else {
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
cache = CacheFile.read(file);
|
||||
|
||||
info("Loaded cache file " + timer);
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read heads.cache file");
|
||||
@ -232,7 +198,6 @@ public class Heads extends JavaPlugin implements Listener {
|
||||
|
||||
public void saveCache() {
|
||||
File file = getCacheFile();
|
||||
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
|
71
src/net/sothatsit/heads/cache/CacheFile.java
vendored
71
src/net/sothatsit/heads/cache/CacheFile.java
vendored
@ -1,16 +1,31 @@
|
||||
package net.sothatsit.heads.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import net.sothatsit.heads.Heads;
|
||||
import net.sothatsit.heads.Search;
|
||||
import net.sothatsit.heads.util.Checks;
|
||||
import net.sothatsit.heads.util.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class CacheFile implements Mod {
|
||||
|
||||
private final String name;
|
||||
@ -54,8 +69,8 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
public String resolveCategoryName(String category) {
|
||||
for(String name : categories.keySet()) {
|
||||
if(name.equalsIgnoreCase(category))
|
||||
for (String name : categories.keySet()) {
|
||||
if (name.equalsIgnoreCase(category))
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -101,8 +116,8 @@ public final class CacheFile implements Mod {
|
||||
public List<CacheHead> findHeads(UUID uniqueId) {
|
||||
List<CacheHead> matches = new ArrayList<>();
|
||||
|
||||
for(CacheHead head : heads) {
|
||||
if(!head.getUniqueId().equals(uniqueId))
|
||||
for (CacheHead head : heads) {
|
||||
if (!head.getUniqueId().equals(uniqueId))
|
||||
continue;
|
||||
|
||||
matches.add(head);
|
||||
@ -116,7 +131,7 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
public void addHeads(Iterable<CacheHead> heads) {
|
||||
for(CacheHead head : heads) {
|
||||
for (CacheHead head : heads) {
|
||||
addHead(head);
|
||||
}
|
||||
}
|
||||
@ -124,7 +139,7 @@ public final class CacheFile implements Mod {
|
||||
private int getMaxId() {
|
||||
int max = -1;
|
||||
|
||||
for(CacheHead head : heads) {
|
||||
for (CacheHead head : heads) {
|
||||
max = Math.max(max, head.getId());
|
||||
}
|
||||
|
||||
@ -150,7 +165,7 @@ public final class CacheFile implements Mod {
|
||||
headsById.remove(head.getId(), head);
|
||||
headsByTexture.remove(head.getTexture(), head);
|
||||
categories.compute(category, (key, categoryHeads) -> {
|
||||
if(categoryHeads == null)
|
||||
if (categoryHeads == null)
|
||||
return null;
|
||||
|
||||
categoryHeads.remove(head);
|
||||
@ -169,7 +184,7 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
public void installMod(Mod mod) {
|
||||
if(hasMod(mod.getName()))
|
||||
if (hasMod(mod.getName()))
|
||||
return;
|
||||
|
||||
mods.add(mod.getName());
|
||||
@ -182,20 +197,19 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
public void write(File file) throws IOException {
|
||||
if(file.isDirectory())
|
||||
if (file.isDirectory())
|
||||
throw new IOException("File " + file + " is a directory");
|
||||
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new IOException("Unable to create file " + file);
|
||||
|
||||
try(FileOutputStream stream = new FileOutputStream(file)) {
|
||||
try (FileOutputStream stream = new FileOutputStream(file)) {
|
||||
writeCompressed(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCompressed(OutputStream os) throws IOException {
|
||||
try(GZIPOutputStream zos = new GZIPOutputStream(os);
|
||||
ObjectOutputStream stream = new ObjectOutputStream(zos)) {
|
||||
try (GZIPOutputStream zos = new GZIPOutputStream(os); ObjectOutputStream stream = new ObjectOutputStream(zos)) {
|
||||
|
||||
write(stream);
|
||||
|
||||
@ -211,32 +225,31 @@ public final class CacheFile implements Mod {
|
||||
IOUtils.writeStringSet(stream, mods);
|
||||
|
||||
stream.writeInt(heads.size());
|
||||
for(CacheHead head : heads) {
|
||||
for (CacheHead head : heads) {
|
||||
head.write(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static CacheFile read(File file) throws IOException {
|
||||
if(file.isDirectory())
|
||||
if (file.isDirectory())
|
||||
throw new IOException("File " + file + " is a directory");
|
||||
|
||||
if(!file.exists())
|
||||
if (!file.exists())
|
||||
throw new IOException("File " + file + " does not exist");
|
||||
|
||||
try(FileInputStream stream = new FileInputStream(file)) {
|
||||
try (FileInputStream stream = new FileInputStream(file)) {
|
||||
return readCompressed(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static CacheFile readResource(String resource) throws IOException {
|
||||
try(InputStream stream = Heads.getInstance().getResource(resource)) {
|
||||
try (InputStream stream = Heads.getInstance().getResource(resource)) {
|
||||
return readCompressed(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static CacheFile readCompressed(InputStream is) throws IOException {
|
||||
try(GZIPInputStream zis = new GZIPInputStream(is);
|
||||
ObjectInputStream stream = new ObjectInputStream(zis)) {
|
||||
try (GZIPInputStream zis = new GZIPInputStream(is); ObjectInputStream stream = new ObjectInputStream(zis)) {
|
||||
|
||||
return read(stream);
|
||||
}
|
||||
@ -245,7 +258,7 @@ public final class CacheFile implements Mod {
|
||||
public static CacheFile read(ObjectInputStream stream) throws IOException {
|
||||
int version = stream.readInt();
|
||||
|
||||
switch(version) {
|
||||
switch (version) {
|
||||
case 2:
|
||||
return readVersion2(stream);
|
||||
case 1:
|
||||
@ -262,7 +275,7 @@ public final class CacheFile implements Mod {
|
||||
|
||||
int headCount = stream.readInt();
|
||||
List<CacheHead> heads = new ArrayList<>(headCount);
|
||||
for(int index = 0; index < headCount; ++index) {
|
||||
for (int index = 0; index < headCount; ++index) {
|
||||
heads.add(CacheHead.read(stream));
|
||||
}
|
||||
|
||||
@ -279,11 +292,13 @@ public final class CacheFile implements Mod {
|
||||
|
||||
int headCount = stream.readInt();
|
||||
List<CacheHead> heads = new ArrayList<>(headCount);
|
||||
for(int index = 0; index < headCount; ++index) {
|
||||
for (int index = 0; index < headCount; ++index) {
|
||||
heads.add(CacheHead.read(stream));
|
||||
}
|
||||
|
||||
return new CacheFile(name, mods, heads);
|
||||
}
|
||||
|
||||
public static String cool = "%%__USER__%%";
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.sothatsit.heads.command.admin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.sothatsit.heads.Heads;
|
||||
import net.sothatsit.heads.command.AbstractCommand;
|
||||
import net.sothatsit.heads.config.MainConfig;
|
||||
import net.sothatsit.heads.config.lang.Lang;
|
||||
import net.sothatsit.heads.menu.ui.item.Item;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemEcoCommand extends AbstractCommand {
|
||||
|
||||
@ -35,7 +36,7 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[1].equalsIgnoreCase("give")) {
|
||||
if (args[1].equalsIgnoreCase("give")) {
|
||||
onGiveCommand(sender, args);
|
||||
return true;
|
||||
}
|
||||
@ -47,12 +48,12 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(args[1].equalsIgnoreCase("set")) {
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
onSetCommand(player, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[1].equalsIgnoreCase("get")) {
|
||||
if (args[1].equalsIgnoreCase("get")) {
|
||||
onGetCommand(player, args);
|
||||
return true;
|
||||
}
|
||||
@ -62,14 +63,16 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
private void onSetCommand(Player player, String[] args) {
|
||||
if(args.length != 2) {
|
||||
if (args.length != 2) {
|
||||
Lang.Command.ItemEco.Set.help().sendInvalidArgs(player);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
@SuppressWarnings("deprecation")
|
||||
// Had to do this to resolve the compatibility issue with 1.13.
|
||||
ItemStack itemStack = player.getInventory().getItemInHand();
|
||||
|
||||
if(itemStack == null) {
|
||||
if (itemStack == null) {
|
||||
Lang.Command.ItemEco.Set.noItem().send(player);
|
||||
return;
|
||||
}
|
||||
@ -82,22 +85,22 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
private void onGetCommand(Player player, String[] args) {
|
||||
if(args.length != 2 && args.length != 3) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
Lang.Command.ItemEco.Get.help().sendInvalidArgs(player);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if(args.length == 3) {
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
amount = Integer.valueOf(args[2]);
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(amount < 1) {
|
||||
if (amount < 1) {
|
||||
Lang.Command.Errors.negative(args[2]);
|
||||
return;
|
||||
}
|
||||
@ -109,22 +112,22 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
private void onGiveCommand(CommandSender sender, String[] args) {
|
||||
if(args.length != 3 && args.length != 4) {
|
||||
if (args.length != 3 && args.length != 4) {
|
||||
Lang.Command.ItemEco.Give.help().sendInvalidArgs(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if(args.length == 4) {
|
||||
if (args.length == 4) {
|
||||
try {
|
||||
amount = Integer.valueOf(args[3]);
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(amount < 1) {
|
||||
if (amount < 1) {
|
||||
Lang.Command.Errors.negative(args[3]);
|
||||
return;
|
||||
}
|
||||
@ -132,7 +135,7 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if(player == null) {
|
||||
if (player == null) {
|
||||
Lang.Command.ItemEco.Give.unknownPlayer(args[2]).send(sender);
|
||||
return;
|
||||
}
|
||||
@ -144,13 +147,13 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
private void giveTokens(Player player, int amount) {
|
||||
while(amount > 0) {
|
||||
while (amount > 0) {
|
||||
int giveAmount = Math.min(64, amount);
|
||||
amount -= giveAmount;
|
||||
|
||||
ItemStack itemStack = Heads.getMainConfig().getItemEconomyItem().amount(giveAmount).build();
|
||||
|
||||
if(player.getInventory().firstEmpty() != -1) {
|
||||
if (player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
} else {
|
||||
org.bukkit.entity.Item item = player.getWorld().dropItemNaturally(player.getEyeLocation(), itemStack);
|
||||
|
@ -1,7 +1,7 @@
|
||||
main: net.sothatsit.heads.Heads
|
||||
author: Marido
|
||||
name: Heads
|
||||
version: 2.0.5
|
||||
version: 2.0.6
|
||||
api-version: 1.13
|
||||
softdepend: [Vault, PlayerPoints, BlockStore]
|
||||
loadbefore: [DeluxeMenus]
|
||||
|
Loading…
Reference in New Issue
Block a user