Arconix is no longer required.

This commit is contained in:
Brianna O'Keefe 2019-02-19 13:31:20 -05:00
parent 6041cdcba6
commit 6074445bbe
18 changed files with 416 additions and 149 deletions

View File

@ -1,10 +1,10 @@
Hey loves,
Thanks for downloading our plugin ^_^ In order to
run it you will need a plugin called arconix. It
basically takes a bunch of methods that we use all
over the place throughout our plugin lineup and
stores it in one place so we don't have to write
use holograms with it you will need a plugin called
arconix. It basically takes a bunch of methods that
we use all over the place throughout our plugin lineup
and stores it in one place so we don't have to write
new code every time we need to get something simple
done. So make sure to stay up to date with the latest
updates for it.

View File

@ -1,7 +1,5 @@
package com.songoda.ultimaterepairing;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.anvil.AnvilManager;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.command.CommandManager;
@ -10,16 +8,20 @@ import com.songoda.ultimaterepairing.events.BlockListeners;
import com.songoda.ultimaterepairing.events.InteractListeners;
import com.songoda.ultimaterepairing.events.InventoryListeners;
import com.songoda.ultimaterepairing.events.PlayerListeners;
import com.songoda.ultimaterepairing.handlers.HologramHandler;
import com.songoda.ultimaterepairing.handlers.ParticleHandler;
import com.songoda.ultimaterepairing.handlers.RepairHandler;
import com.songoda.ultimaterepairing.hologram.Hologram;
import com.songoda.ultimaterepairing.hologram.HologramArconix;
import com.songoda.ultimaterepairing.utils.ConfigWrapper;
import com.songoda.ultimaterepairing.utils.Debugger;
import com.songoda.ultimaterepairing.utils.Methods;
import com.songoda.ultimaterepairing.utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@ -42,11 +44,12 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
private Locale locale;
private RepairHandler repairHandler;
private HologramHandler hologramHandler;
private SettingsManager settingsManager;
private CommandManager commandManager;
private AnvilManager anvilManager;
private Hologram hologram;
private Editor editor;
public static UltimateRepairing getInstance() {
@ -76,11 +79,9 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
// Check to make sure the Bukkit version is compatible.
if (!checkVersion()) return;
Arconix.pl().hook(this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
Bukkit.getPluginManager().registerEvents(this, this);
settingsManager = new SettingsManager(this);
@ -102,16 +103,21 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
references = new References();
this.repairHandler = new RepairHandler(this);
this.hologramHandler = new HologramHandler(this);
this.commandManager = new CommandManager(this);
new ParticleHandler(this);
PluginManager pluginManager = getServer().getPluginManager();
// Register Hologram Plugin
if (pluginManager.isPluginEnabled("Arconix"))
hologram = new HologramArconix(this);
/*
* Register anvils into AnvilManager from Configuration.
*/
if (dataFile.getConfig().contains("data")) {
for (String key : dataFile.getConfig().getConfigurationSection("data").getKeys(false)) {
Location location = Arconix.pl().getApi().serialize().unserializeLocation(key);
Location location = Methods.unserializeLocation(key);
UAnvil anvil = anvilManager.getAnvil(location);
anvil.setHologram(dataFile.getConfig().getBoolean("data." + key + ".hologram"));
anvil.setInfinity(dataFile.getConfig().getBoolean("data." + key + ".infinity"));
@ -126,14 +132,14 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Methods.formatText("&a============================="));
}
public void onDisable() {
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Methods.formatText("&a============================="));
saveConfig();
saveToFile();
}
@ -183,7 +189,7 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
*/
for (UAnvil anvil : anvilManager.getAnvils()) {
if (!anvil.shouldSave())continue;
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(anvil.getLocation());
String locationStr = Methods.serializeLocation(anvil.getLocation());
dataFile.getConfig().set("data." + locationStr + ".hologram", anvil.isHologram());
dataFile.getConfig().set("data." + locationStr + ".particles", anvil.isParticles());
dataFile.getConfig().set("data." + locationStr + ".infinity", anvil.isInfinity());
@ -210,7 +216,6 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
references = new References();
reloadConfig();
saveConfig();
hologramHandler.updateHolograms();
} catch (Exception ex) {
Debugger.runReport(ex);
}
@ -228,8 +233,8 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
return repairHandler;
}
public HologramHandler getHologramHandler() {
return hologramHandler;
public Hologram getHologram() {
return hologram;
}
public SettingsManager getSettingsManager() {

View File

@ -27,7 +27,7 @@ public class UAnvil {
public void setHologram(boolean hologram) {
this.hologram = hologram;
UltimateRepairing.getInstance().getHologramHandler().updateHolograms();
UltimateRepairing.getInstance().getHologram().update(this);
}
public boolean isParticles() {

View File

@ -1,7 +1,5 @@
package com.songoda.ultimaterepairing.anvil.editor;
import com.songoda.arconix.api.ArconixAPI;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Methods;
@ -31,7 +29,7 @@ public class Editor {
}
private void open(Player player, UAnvil anvil) {
Inventory inventory = Bukkit.createInventory(null, 27, TextComponent.formatTitle("Anvil Settings"));
Inventory inventory = Bukkit.createInventory(null, 27, Methods.formatText("Anvil Settings"));
int nu = 0;
while (nu != 27) {

View File

@ -1,11 +1,11 @@
package com.songoda.ultimaterepairing.command;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.command.commands.CommandURAnvil;
import com.songoda.ultimaterepairing.command.commands.CommandReload;
import com.songoda.ultimaterepairing.command.commands.CommandSettings;
import com.songoda.ultimaterepairing.command.commands.CommandUltimateRepairing;
import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -55,7 +55,7 @@ public class CommandManager implements CommandExecutor {
}
}
}
commandSender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&7The command you entered does not exist or is spelt incorrectly."));
commandSender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
return true;
}
@ -67,8 +67,8 @@ public class CommandManager implements CommandExecutor {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cInvalid Syntax!"));
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cInvalid Syntax!"));
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
}
return;
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimaterepairing.command.commands;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.command.AbstractCommand;
import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.command.CommandSender;
public class CommandReload extends AbstractCommand {
@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand {
@Override
protected ReturnType runCommand(UltimateRepairing instance, CommandSender sender, String... args) {
instance.reload();
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7Configuration and Language files reloaded."));
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Configuration and Language files reloaded."));
return ReturnType.SUCCESS;
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimaterepairing.command.commands;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.command.AbstractCommand;
import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.command.CommandSender;
public class CommandUltimateRepairing extends AbstractCommand {
@ -14,11 +14,11 @@ public class CommandUltimateRepairing extends AbstractCommand {
@Override
protected ReturnType runCommand(UltimateRepairing instance, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(TextComponent.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
}
}
sender.sendMessage("");

View File

@ -1,9 +1,9 @@
package com.songoda.ultimaterepairing.events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Debugger;
import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -39,7 +39,7 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
try {
String loc = Arconix.pl().getApi().serialize().serializeLocation(event.getBlock());
String loc = Methods.serializeLocation(event.getBlock());
if (!event.getBlock().getType().equals(Material.ANVIL) && !instance.getConfig().contains("data.anvil." + loc)) {
return;

View File

@ -1,6 +1,5 @@
package com.songoda.ultimaterepairing.events;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Debugger;

View File

@ -1,72 +0,0 @@
package com.songoda.ultimaterepairing.handlers;
import com.songoda.arconix.api.packets.Hologram;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.ArrayList;
import java.util.List;
/**
* Created by songoda on 2/24/2017.
*/
public class HologramHandler {
private final UltimateRepairing instance;
public HologramHandler(UltimateRepairing plugin) {
this.instance = plugin;
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::updateHolograms, 0L, 5000L);
}
public void updateHolograms() {
try {
FileConfiguration config = instance.getConfig();
if (instance.getAnvilManager().getAnvils().isEmpty()) return;
for (UAnvil anvil : instance.getAnvilManager().getAnvils()) {
if (anvil.getWorld() == null) continue;
Location location = anvil.getLocation();
location.add(.5, 1.10, .5);
this.remove(location);
if (!anvil.isHologram()) continue;
List<String> lines = new ArrayList<>();
if (!config.getBoolean("Main.Enable Default Anvil Function"))
lines.add(Arconix.pl().getApi().format().formatText(instance.getLocale().getMessage("general.hologram.oneclick")));
else if (config.getBoolean("Main.Swap Right And Left Click Options"))
lines.add(Arconix.pl().getApi().format().formatText(instance.getLocale().getMessage("general.hologram.swapclick")));
else
lines.add(Arconix.pl().getApi().format().formatText(instance.getLocale().getMessage("general.hologram.click")));
lines.add(Arconix.pl().getApi().format().formatText(instance.getLocale().getMessage("general.hologram.torepair")));
Arconix.pl().getApi().packetLibrary.getHologramManager().spawnHolograms(location, lines);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
private void remove(Location location) {
try {
Location loco = location.clone();
Hologram hologramManager = Arconix.pl().getApi().packetLibrary.getHologramManager();
hologramManager.despawnHologram(loco);
hologramManager.despawnHologram(loco.subtract(0, .25, 0));
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -1,12 +1,10 @@
package com.songoda.ultimaterepairing.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.Listener;

View File

@ -1,7 +1,5 @@
package com.songoda.ultimaterepairing.handlers;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
@ -136,7 +134,7 @@ public class RepairHandler {
p.setItemInHand(null);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
if (i.isValid() && !playerData.isBeingRepaired()) {
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.timeout")));
p.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.timeout")));
removeItem(playerData, p);
p.closeInventory();
@ -195,7 +193,7 @@ public class RepairHandler {
String cost = "0";
Material mat = new Methods().getType(item);
String name = Arconix.pl().getApi().format().formatText(mat.name(), true);
String name = Methods.formatText(mat.name(), true);
if (type == RepairType.XP)
cost = price + " XP";
@ -259,7 +257,7 @@ public class RepairHandler {
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
if (!answer) {
removeItem(playerData, player);
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.cancelled")));
player.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.cancelled")));
return;
}
RepairType type = playerData.getType();
@ -282,8 +280,8 @@ public class RepairHandler {
int cost = Methods.getCost(type, players);
ItemStack item2 = new ItemStack(Methods.getType(players), cost);
String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " ");
if (type == RepairType.ITEM && Arconix.pl().getApi().getGUI().inventoryContains(player.getInventory(), item2)) {
Arconix.pl().getApi().getGUI().removeFromInventory(player.getInventory(), item2);
if (type == RepairType.ITEM && Methods.inventoryContains(player.getInventory(), item2)) {
Methods.removeFromInventory(player.getInventory(), item2);
sold = true;
}
@ -316,15 +314,15 @@ public class RepairHandler {
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
player.getWorld().playEffect(location, effect, blockTypeFinal);
player.getWorld().playEffect(location, effect, Material.STONE);
Arconix.pl().getApi().getPlayer(player).playSound(Sound.valueOf("BLOCK_ANVIL_LAND"));
player.playSound(location, Sound.valueOf("BLOCK_ANVIL_LAND"), 1L, 1L);
}, 10L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.getWorld().playEffect(location, effect, blockTypeFinal), 15L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.getWorld().playEffect(location, effect, blockTypeFinal), 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
Arconix.pl().getApi().getPlayer(player).playSound(Sound.valueOf("BLOCK_ANVIL_LAND"));
player.playSound(location, Sound.valueOf("BLOCK_ANVIL_LAND"), 1L, 1L);
player.getWorld().playEffect(location, effect, blockTypeFinal);
player.getWorld().playEffect(location, effect, Material.ANVIL);
player.sendMessage(TextComponent.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.success")));
player.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.success")));
ItemStack repairedi = playerData.getToBeRepaired();
repairedi.setDurability((short) 0);
Item repaired = player.getWorld().dropItemNaturally(player.getLocation(), repairedi);
@ -345,11 +343,11 @@ public class RepairHandler {
if (!economy)
player.sendMessage("Vault is not installed.");
else
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", instance.getLocale().getMessage("interface.repair.eco"))));
player.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", instance.getLocale().getMessage("interface.repair.eco"))));
} else if (type == RepairType.XP)
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", instance.getLocale().getMessage("interface.repair.xp"))));
player.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", instance.getLocale().getMessage("interface.repair.xp"))));
else
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", name)));
player.sendMessage(Methods.formatText(instance.references.getPrefix() + instance.getLocale().getMessage("event.repair.notenough", name)));
} catch (Exception ex) {

View File

@ -0,0 +1,98 @@
package com.songoda.ultimaterepairing.hologram;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class Hologram {
protected final UltimateRepairing instance;
Hologram(UltimateRepairing instance) {
this.instance = instance;
}
public void loadHolograms() {
Collection<UAnvil> uAnvils = instance.getAnvilManager().getAnvils();
if (uAnvils.size() == 0) return;
for (UAnvil anvil : uAnvils) {
if (anvil.getWorld() == null) continue;
add(anvil);
}
}
public void unloadHolograms() {
Collection<UAnvil> uAnvils = instance.getAnvilManager().getAnvils();
if (uAnvils.size() == 0) return;
for (UAnvil anvil : uAnvils) {
if (anvil.getWorld() == null) continue;
remove(anvil);
}
}
public void add(UAnvil anvil) {
format(anvil, Action.ADD);
}
public void remove(UAnvil anvil) {
format(anvil, Action.REMOVE);
}
public void update(UAnvil anvil) {
format(anvil, Action.UPDATE);
}
private void format(UAnvil anvil, Action action) {
ArrayList<String> lines = new ArrayList<>();
if (!instance.getConfig().getBoolean("Main.Enable Default Anvil Function"))
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.oneclick")));
else if (instance.getConfig().getBoolean("Main.Swap Right And Left Click Options"))
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.swapclick")));
else
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.click")));
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.torepair")));
Location location = anvil.getLocation();
if (!anvil.isHologram()) {
remove(location);
return;
}
switch (action) {
case UPDATE:
update(location, lines);
break;
case ADD:
add(location, lines);
break;
case REMOVE:
remove(location);
break;
}
}
protected abstract void add(Location location, ArrayList<String> lines);
protected abstract void remove(Location location);
protected abstract void update(Location location, ArrayList<String> lines);
public enum Action {
UPDATE, ADD, REMOVE
}
}

View File

@ -0,0 +1,47 @@
package com.songoda.ultimaterepairing.hologram;
import com.songoda.arconix.api.hologram.HologramObject;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.ArrayList;
public class HologramArconix extends Hologram {
private com.songoda.arconix.api.packets.Hologram hologramManager;
public HologramArconix(UltimateRepairing instance) {
super(instance);
this.hologramManager = Arconix.pl().getApi().packetLibrary.getHologramManager();
}
@Override
public void add(Location location, ArrayList<String> lines) {
fixLocation(location);
HologramObject hologram = new HologramObject(null, location, lines);
hologramManager.addHologram(hologram);
}
@Override
public void remove(Location location) {
fixLocation(location);
location.add(0, 0.25, 0);
hologramManager.removeHologram(location, 5);
}
@Override
public void update(Location location, ArrayList<String> lines) {
remove(location.clone());
fixLocation(location);
HologramObject hologram = new HologramObject(null, location, lines);
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateRepairing.getInstance(), () -> {
hologramManager.addHologram(hologram);
}, 1L);
}
private void fixLocation(Location location) {
location.add(0.5, 1.10, 0.5);
}
}

View File

@ -0,0 +1,67 @@
package com.songoda.ultimaterepairing.utils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
/**
* ConfigWrapper made by @clip
*/
public class ConfigWrapper {
private final JavaPlugin plugin;
private final String folderName, fileName;
private FileConfiguration config;
private File configFile;
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
this.plugin = instance;
this.folderName = folderName;
this.fileName = fileName;
}
public void createNewFile(final String message, final String header) {
reloadConfig();
saveConfig();
loadConfig(header);
if (message != null) {
plugin.getLogger().info(message);
}
}
public FileConfiguration getConfig() {
if (config == null) {
reloadConfig();
}
return config;
}
public void loadConfig(final String header) {
config.options().header(header);
config.options().copyDefaults(true);
saveConfig();
}
public void reloadConfig() {
if (configFile == null) {
configFile = new File(plugin.getDataFolder() + folderName, fileName);
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public void saveConfig() {
if (config == null || configFile == null) {
return;
}
try {
getConfig().save(configFile);
} catch (final IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}

View File

@ -1,18 +1,17 @@
package com.songoda.ultimaterepairing.utils;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* Created by songoda on 2/25/2017.
@ -21,7 +20,8 @@ public class Methods {
public static ItemStack getGlass() {
try {
return Arconix.pl().getApi().getGUI().getGlass(UltimateRepairing.getInstance().getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), UltimateRepairing.getInstance().getConfig().getInt("Interfaces.Glass Type 1"));
UltimateRepairing instance = UltimateRepairing.getInstance();
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception e) {
Debugger.runReport(e);
}
@ -30,16 +30,31 @@ public class Methods {
public static ItemStack getBackgroundGlass(boolean type) {
try {
UltimateRepairing instance = UltimateRepairing.getInstance();
if (type)
return Arconix.pl().getApi().getGUI().getGlass(false, UltimateRepairing.getInstance().getConfig().getInt("Interfaces.Glass Type 2"));
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return Arconix.pl().getApi().getGUI().getGlass(false, UltimateRepairing.getInstance().getConfig().getInt("Interfaces.Glass Type 3"));
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
private static ItemStack getGlass(Boolean rainbow, int type) {
int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass;
if (rainbow) {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
} else {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
}
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l");
glass.setItemMeta(glassmeta);
return glass;
}
public static int getCost(RepairType type, ItemStack item) {
try {
@ -106,10 +121,10 @@ public class Methods {
public static ItemStack createButton(ItemStack item, String name, String... lore) {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextComponent.formatText(name));
meta.setDisplayName(formatText(name));
if (lore != null && lore.length != 0) {
List<String> newLore = new ArrayList<>();
for (String line : lore) newLore.add(TextComponent.formatText(line));
for (String line : lore) newLore.add(formatText(line));
meta.setLore(newLore);
}
item.setItemMeta(meta);
@ -126,4 +141,120 @@ public class Methods {
public static boolean isAnvil(Material material){
return material.equals(Material.ANVIL) || material.equals(Material.CHIPPED_ANVIL) || material.equals(Material.DAMAGED_ANVIL);
}
/**
* Checks if the inventory contains the specified item.
*
* @param inventory The inventory to check
* @param item The item to check for.
* @return Whether or not the inventory contains the item.
*/
public static boolean inventoryContains(Inventory inventory, ItemStack item) {
int count = 0;
ItemStack[] items = inventory.getContents();
for (ItemStack item1 : items) {
if (item1 != null && item1.getType() == item.getType() && item1.getDurability() == item.getDurability()) {
count += item1.getAmount();
}
if (count >= item.getAmount()) {
return true;
}
}
return false;
}
/**
* Removes the specified item from the inventory
*
* @param inventory The inventory to remove from.
* @param item The item to remove.
*/
public static void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
ItemStack[] items = inventory.getContents();
for (int i = 0; i < items.length; i++) {
if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
if (items[i].getAmount() > amt) {
items[i].setAmount(items[i].getAmount() - amt);
break;
} else if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
}
}
inventory.setContents(items);
}
/**
* Serializes the location of the block specified.
*
* @param b The block whose location is to be saved.
* @return The serialized data.
*/
public static String serializeLocation(Block b) {
if (b == null)
return "";
return serializeLocation(b.getLocation());
}
/**
* Serializes the location specified.
*
* @param location The location that is to be saved.
* @return The serialized data.
*/
public static String serializeLocation(Location location) {
if (location == null)
return "";
String w = location.getWorld().getName();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String str = w + ":" + x + ":" + y + ":" + z;
str = str.replace(".0", "").replace("/", "");
return str;
}
private static Map<String, Location> serializeCache = new HashMap<>();
/**
* Deserializes a location from the string.
*
* @param str The string to parse.
* @return The location that was serialized in the string.
*/
public static Location unserializeLocation(String str) {
if (str == null || str.equals(""))
return null;
if (serializeCache.containsKey(str)) {
return serializeCache.get(str).clone();
}
String cacheKey = str;
str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", ".");
List<String> args = Arrays.asList(str.split("\\s*:\\s*"));
World world = Bukkit.getWorld(args.get(0));
double x = Double.parseDouble(args.get(1)), y = Double.parseDouble(args.get(2)), z = Double.parseDouble(args.get(3));
Location location = new Location(world, x, y, z, 0, 0);
serializeCache.put(cacheKey, location.clone());
return location;
}
public static String formatText(String text) {
if (text == null || text.equals(""))
return "";
return formatText(text, false);
}
public static String formatText(String text, boolean cap) {
if (text == null || text.equals(""))
return "";
if (cap)
text = text.substring(0, 1).toUpperCase() + text.substring(1);
return ChatColor.translateAlternateColorCodes('&', text);
}
}

View File

@ -1,7 +1,5 @@
package com.songoda.ultimaterepairing.utils;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.ultimaterepairing.UltimateRepairing;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -106,9 +104,9 @@ public class SettingsManager implements Listener {
player.closeInventory();
player.sendMessage("");
player.sendMessage(TextComponent.formatText("&7Please enter a value for &6" + current + "&7."));
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
player.sendMessage(TextComponent.formatText("&cUse only numbers."));
player.sendMessage(Methods.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
@ -124,8 +122,8 @@ public class SettingsManager implements Listener {
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(TextComponent.formatText("&f&l" + key));
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Methods.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
@ -143,18 +141,18 @@ public class SettingsManager implements Listener {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextComponent.formatText("&6" + key));
meta.setDisplayName(Methods.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(TextComponent.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(TextComponent.formatText("&9" + config.getString(fKey)));
lore.add(Methods.formatText("&9" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(Material.CLOCK);
lore.add(TextComponent.formatText("&5" + config.getInt(fKey)));
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
}
if (defs.getConfig().contains(fKey)) {
@ -163,7 +161,7 @@ public class SettingsManager implements Listener {
Matcher m = SETTINGS_PATTERN.matcher(text);
while (m.find()) {
if (m.end() != text.length() || m.group().length() != 0)
lore.add(TextComponent.formatText("&7" + m.group()));
lore.add(Methods.formatText("&7" + m.group()));
}
}

View File

@ -1,4 +1,4 @@
#General Messages
1`q #General Messages
general.nametag.prefix = "&8[&6UltimateRepairing&8]"
general.hologram.click = "Left-Click with an item"