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();
|
||||
|
||||
|
35
src/net/sothatsit/heads/cache/CacheFile.java
vendored
35
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;
|
||||
@ -194,8 +209,7 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -235,8 +249,7 @@ public final class CacheFile implements Mod {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -286,4 +299,6 @@ public final class CacheFile implements Mod {
|
||||
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 {
|
||||
|
||||
@ -67,7 +68,9 @@ public class ItemEcoCommand extends AbstractCommand {
|
||||
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) {
|
||||
Lang.Command.ItemEco.Set.noItem().send(player);
|
||||
|
@ -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