mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-08 11:41:28 +01:00
Redid time system & Fixed holograms on start
This commit is contained in:
parent
2ac6b8e2d6
commit
c89bb9ad98
@ -2,34 +2,29 @@ package com.songoda.ultimatekits;
|
||||
|
||||
import com.songoda.ultimatekits.command.CommandManager;
|
||||
import com.songoda.ultimatekits.conversion.Convert;
|
||||
import com.songoda.ultimatekits.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimatekits.listeners.*;
|
||||
import com.songoda.ultimatekits.handlers.DisplayItemHandler;
|
||||
import com.songoda.ultimatekits.handlers.ParticleHandler;
|
||||
import com.songoda.ultimatekits.hologram.Hologram;
|
||||
import com.songoda.ultimatekits.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.key.KeyManager;
|
||||
import com.songoda.ultimatekits.kit.*;
|
||||
import com.songoda.ultimatekits.listeners.BlockListeners;
|
||||
import com.songoda.ultimatekits.listeners.ChatListeners;
|
||||
import com.songoda.ultimatekits.listeners.EntityListeners;
|
||||
import com.songoda.ultimatekits.listeners.InteractListeners;
|
||||
import com.songoda.ultimatekits.utils.*;
|
||||
import com.songoda.ultimatekits.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -54,7 +49,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
private KeyManager keyManager;
|
||||
private DisplayItemHandler displayItemHandler;
|
||||
private Hologram hologram;
|
||||
|
||||
|
||||
private ItemSerializer itemSerializer;
|
||||
|
||||
/**
|
||||
@ -111,7 +106,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
|
||||
// Register Hologram Plugin
|
||||
if (pluginManager.isPluginEnabled("HolographicDisplays"))
|
||||
hologram = new HologramHolographicDisplays(this);
|
||||
@ -121,14 +116,14 @@ public class UltimateKits extends JavaPlugin {
|
||||
pluginManager.registerEvents(new ChatListeners(this), this);
|
||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
|
||||
|
||||
this.loadFromFile();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
// Starting Metrics
|
||||
new Metrics(this);
|
||||
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
|
||||
}
|
||||
@ -217,6 +212,10 @@ public class UltimateKits extends JavaPlugin {
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (hologram != null)
|
||||
hologram.loadHolograms();
|
||||
|
||||
}
|
||||
|
||||
public ServerVersion getServerVersion() {
|
||||
@ -226,6 +225,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
public boolean isServerVersion(ServerVersion version) {
|
||||
return serverVersion == version;
|
||||
}
|
||||
|
||||
public boolean isServerVersion(ServerVersion... versions) {
|
||||
return ArrayUtils.contains(versions, serverVersion);
|
||||
}
|
||||
@ -305,6 +305,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload plugin yaml files.
|
||||
*/
|
||||
@ -358,7 +359,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
public ConfigWrapper getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
@ -374,11 +375,11 @@ public class UltimateKits extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Grab instance of the item serializer
|
||||
*
|
||||
*
|
||||
* @return instance of ItemSerializer
|
||||
*/
|
||||
public ItemSerializer getItemSerializer() {
|
||||
return this.itemSerializer;
|
||||
return this.itemSerializer;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
|
@ -138,8 +138,10 @@ public class Kit {
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.crate.wrongkey")));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < key.getKitAmount(); i++)
|
||||
givePartKit(player, key);
|
||||
for (int i = 0; i < key.getKitAmount(); i++) {
|
||||
if (givePartKit(player, key))
|
||||
return;
|
||||
}
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.key.success", showableName));
|
||||
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
||||
ItemStack is = player.getItemInHand();
|
||||
@ -270,7 +272,7 @@ public class Kit {
|
||||
}
|
||||
}
|
||||
|
||||
private void givePartKit(Player player, Key key) {
|
||||
private boolean givePartKit(Player player, Key key) {
|
||||
try {
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
int amt = innerContents.size();
|
||||
@ -279,8 +281,7 @@ public class Kit {
|
||||
if (amt != amtToGive || kitAnimation != KitAnimation.NONE)
|
||||
Collections.shuffle(innerContents);
|
||||
|
||||
for (int i = 0; i < innerContents.size(); i ++) {
|
||||
KitItem item = innerContents.get(i);
|
||||
for (KitItem item : innerContents) {
|
||||
if (amtToGive == 0) continue;
|
||||
int ch = item.getChance() == 0 ? 100 : item.getChance();
|
||||
double rand = Math.random() * 100;
|
||||
@ -309,7 +310,7 @@ public class Kit {
|
||||
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
new CrateAnimateTask(plugin, player, this, item.getItem());
|
||||
return;
|
||||
return true;
|
||||
} else {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
@ -320,9 +321,11 @@ public class Kit {
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateDelay(Player player) {
|
||||
|
@ -20,28 +20,24 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public InteractListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
public InteractListeners(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent event) {
|
||||
try {
|
||||
boolean chand = true; // This needs to be out of my code.
|
||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9)
|
||||
&& event.getHand() != EquipmentSlot.HAND) {
|
||||
chand = false;
|
||||
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (!chand) return;
|
||||
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(block.getLocation());
|
||||
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData == null) return;
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
@ -59,7 +55,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (kitBlockData.getType() != KitType.PREVIEW) {
|
||||
if (!kit.hasPermission(player)) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.general.noperms"));
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.general.noperms"));
|
||||
return;
|
||||
}
|
||||
if (kit.getNextUse(player) <= 0) {
|
||||
@ -67,8 +63,8 @@ public class InteractListeners implements Listener {
|
||||
kit.updateDelay(player);
|
||||
} else {
|
||||
long time = kit.getNextUse(player);
|
||||
player.sendMessage(Methods.formatText(instance.getReferences().getPrefix()
|
||||
+ instance.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time))));
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time))));
|
||||
}
|
||||
} else if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
kit.buy(player);
|
||||
@ -80,7 +76,7 @@ public class InteractListeners implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (player.isSneaking() && player.hasPermission("ultimatekits.admin")) {
|
||||
new GUIBlockEditor(instance, player, block.getLocation());
|
||||
new GUIBlockEditor(plugin, player, block.getLocation());
|
||||
return;
|
||||
}
|
||||
if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
|
||||
|
@ -171,18 +171,59 @@ public class Methods {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the specified Unix Epoch time human readable as per the format settings in the Arconix config.
|
||||
*
|
||||
* @param time The time to convert.
|
||||
* @return A human readable string representing to specified time.
|
||||
*/
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "";
|
||||
return String.format("%d hour(s), %d min(s), %d sec(s)", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
|
||||
|
||||
if (days != 0L)
|
||||
sb.append(" ").append(days).append("d");
|
||||
if (hours != 0L)
|
||||
sb.append(" ").append(hours).append("h");
|
||||
if (minutes != 0L)
|
||||
sb.append(" ").append(minutes).append("m");
|
||||
if (seconds != 0L)
|
||||
sb.append(" ").append(seconds).append("s");
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
StringBuilder number = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
number.append(c);
|
||||
} else if (Character.isLetter(c) && (number.length() > 0)) {
|
||||
result += convert(Integer.parseInt(number.toString()), c);
|
||||
number = new StringBuilder();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long convert(long value, char unit) {
|
||||
switch (unit) {
|
||||
case 'd':
|
||||
return value * 1000 * 60 * 60 * 24;
|
||||
case 'h':
|
||||
return value * 1000 * 60 * 60;
|
||||
case 'm':
|
||||
return value * 1000 * 60;
|
||||
case 's':
|
||||
return value * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats the specified double into the Economy format specified in the Arconix config.
|
||||
*
|
||||
|
@ -54,7 +54,7 @@ event.claim.cannotafford = "&9You cannot afford to buy kit &7%kit%&9."
|
||||
event.claim.nottwice = "&9You can only receive this kit once."
|
||||
event.claim.purchasesuccess = "&9You have purchased kit &7%kit%&9."
|
||||
event.claim.givesuccess = "&9You have received kit &7%kit%&9."
|
||||
event.claim.delay = "&9Please wait %time%"
|
||||
event.claim.delay = "&cYou need to wait &4%time% &cbefore you can use this."
|
||||
event.claim.eco = "&7You received &a%amt%&7."
|
||||
event.claim.once = "&7Cooldown: &6You already claimed this kit!"
|
||||
event.claim.ready = "&7Cooldown: &6Ready for use!"
|
||||
|
Loading…
Reference in New Issue
Block a user