Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
<artifactId>Elytra</artifactId>
<!-- Output to jar format -->
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>0.1.3-SNAPSHOT</version>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>DrkMatr1984 Repo</id>
<url>https://minevolt.net/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/me/fromgate/elytra/Elytra.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ public void onEnable() {
task.runTaskTimer(plugin, 20, 13);
}
if(cfg.boostEnable){
new BoostCheckTask().runTaskTimer(getPlugin(), 20, 8);
BoostCheckTask task = new BoostCheckTask();
task.runTaskTimer(getPlugin(), 20, 8);
}
if(cfg.shiftActivation){
new ShiftActivationCheckTask().runTaskTimer(plugin, 20, 10);
ShiftActivationCheckTask task = new ShiftActivationCheckTask();
task.runTaskTimer(plugin, 20, 10);
}
if(cfg.autoElytra){
new AutoGlideCheckTask().runTaskTimer(plugin, 20, 8);
AutoGlideCheckTask task = new AutoGlideCheckTask();
task.runTaskTimer(plugin, 20, 8);
}
if (cfg.runUpEnable){
new RunUpCheckTask().runTaskTimer(plugin, 20, 6);
RunUpCheckTask task = new RunUpCheckTask();
task.runTaskTimer(plugin, 20, 6);
}
}
}
55 changes: 12 additions & 43 deletions src/main/java/me/fromgate/elytra/tasks/AutoGlideCheckTask.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
package me.fromgate.elytra.tasks;

import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.util.Util;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.util.Util;

public class AutoGlideCheckTask extends BukkitRunnable {
private Map<Player, Location> oldLocale = new HashMap<>();
private HashMap<Player, Location> oldLocale = new HashMap<Player, Location>();
@Override
public void run() {
if(Bukkit.getServer().getOnlinePlayers()!=null && !Bukkit.getServer().getOnlinePlayers().isEmpty()){
for(Player player : Bukkit.getServer().getOnlinePlayers())
{
if (player.hasPermission("elytra.auto")){
if(!player.hasMetadata("swimming") && !player.hasMetadata("falling")){
if(Elytra.getCfg().cancelIfSlowFall && player.hasPotionEffect(PotionEffectType.SLOW_FALLING))
return;
Location l = player.getLocation();
if(oldLocale.containsKey(player)){
if(!Util.isSameBlocks(l, oldLocale.get(player))){
Expand All @@ -33,9 +28,11 @@ public void run() {
if(Elytra.getCfg().autoElytraEquip)
{
if(player.hasPermission("elytra.auto-equip")){
if(Util.hasElytraStorage(player)){
autoEquip(player);
}
if(Util.hasElytraStorage(player)) {
Util.autoEquip(player);
}else {
//no elytra to autoequip (maybe a message)
}
}
}
}
Expand All @@ -57,32 +54,4 @@ public void run() {
}
}

private void autoEquip(Player player){
PlayerInventory inv = player.getInventory();
List<ItemStack> storage = new ArrayList<ItemStack>();
ItemStack chestplate = new ItemStack(Material.AIR);
ItemStack elytra = new ItemStack(Material.AIR);
if(inv.getChestplate()!=null && inv.getChestplate().getType()!=Material.AIR){
chestplate = inv.getChestplate();
inv.setChestplate(new ItemStack(Material.AIR));
}
for(ItemStack item : inv.getStorageContents()){
storage.add(item);
}
for(ItemStack item : storage){
if(item!=null){
if(item.getType().equals(Material.ELYTRA)){
elytra = item;
break;
}
}
}
storage.remove(elytra);
if(chestplate.getType()!=Material.AIR){
storage.add(chestplate);
}
player.getInventory().setStorageContents(Util.listToArray(storage));
inv.setChestplate(elytra);
player.sendMessage(ChatColor.GREEN + "Elytra Auto-Equipped");
}
}
25 changes: 19 additions & 6 deletions src/main/java/me/fromgate/elytra/tasks/BoostCheckTask.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package me.fromgate.elytra.tasks;

import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.ElytraCooldown;
import me.fromgate.elytra.util.Util;
import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.Map;
import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.ElytraCooldown;
import me.fromgate.elytra.util.Util;

public class BoostCheckTask extends BukkitRunnable {

private Map<Player, Location> oldLocale = new HashMap<>();
private HashMap<Player, Location> oldLocale = new HashMap<Player, Location>();

@Override
public void run() {
Expand Down Expand Up @@ -54,6 +55,18 @@ public void run() {
oldLocale.put(player, l);
return;
}
if(Elytra.getCfg().chargeFirework>0) {
if(Util.containsFireworks(player)) {
Util.removeFirework(player, Elytra.getCfg().chargeFirework);
player.setVelocity(vector.multiply(Elytra.getCfg().speedUpMult));
Util.playParticles(player);
Util.playSound(player);
Util.processGForce(player);
return;
}
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNot Enough Fireworks to Boost"));
return;
}
player.setVelocity(vector.multiply(Elytra.getCfg().speedUpMult));
Util.playParticles(player);
Util.playSound(player);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/me/fromgate/elytra/tasks/RunUpCheckTask.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package me.fromgate.elytra.tasks;

import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.ElytraCooldown;
import me.fromgate.elytra.util.ElytraConfig;
import me.fromgate.elytra.util.Util;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.Map;
import me.fromgate.elytra.Elytra;
import me.fromgate.elytra.ElytraCooldown;
import me.fromgate.elytra.util.ElytraConfig;
import me.fromgate.elytra.util.Util;

public class RunUpCheckTask extends BukkitRunnable {

private Map<Player, Location> oldLocale = new HashMap<>();
private HashMap<Player, Location> oldLocale = new HashMap<Player, Location>();
private Map<String, Integer> runners = new HashMap<>();
private ElytraConfig cfg;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.fromgate.elytra.tasks;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
Expand All @@ -17,12 +18,24 @@ public void run() {
{
if (!player.hasPermission("elytra.shift-activation")) return;
if(player.hasMetadata("swimming") || player.hasMetadata("falling")) return;
if (!player.isSneaking()) return;
if (!player.isGliding()) return;
if (!Util.isElytraWeared(player)) return;
if (!player.isGliding()) return;
if (!player.isSneaking()) return;
Vector vector = player.getVelocity();
if (vector.length() > Elytra.getCfg().shiftActSpeed) return;
if (!ElytraCooldown.checkAndUpdate(player, ElytraCooldown.Type.SHIFT)) return;
if(Elytra.getCfg().chargeFirework>0) {
if(Util.containsFireworks(player)) {
Util.removeFirework(player, Elytra.getCfg().chargeFirework);
player.setVelocity(vector.multiply(Elytra.getCfg().shiftMult));
Util.playParticles(player);
Util.playSound(player);
Util.processGForce(player);
return;
}
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNot Enough Fireworks to Boost"));
return;
}
player.setVelocity(vector.multiply(Elytra.getCfg().shiftMult));
Util.playParticles(player);
Util.playSound(player);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/me/fromgate/elytra/util/ElytraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public ElytraConfig(JavaPlugin plugin) {

@Path(value = "auto-glide.required-air-under-player")
public int autoElytraEmpty = 3;


@Path(value = "auto-glide.cancel-if-slow-fall")
public boolean cancelIfSlowFall = true;

// Constant-flight
@Path(value = "constant-flight.enable")
public boolean constSpeedEnable = false;
Expand Down Expand Up @@ -95,7 +98,9 @@ public ElytraConfig(JavaPlugin plugin) {

@Path(value = "g-force.damage-player")
public double gforceDamagePlayer = 2;


@Path(value = "g-force.charge-firework")
public int chargeFirework = 1;

// Visual effects
@Path(value = "particles.enable")
Expand Down
80 changes: 67 additions & 13 deletions src/main/java/me/fromgate/elytra/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import me.fromgate.elytra.Elytra;

import java.util.List;

import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -115,8 +113,8 @@ public static boolean isElytraWeared(Player player) {

public static boolean hasElytraStorage(Player player) {
PlayerInventory inv = player.getInventory();
if(inv.getStorageContents()!=null){
for(ItemStack item : inv.getStorageContents()){
if(inv.getContents()!=null){
for(ItemStack item : inv.getContents()){
if(item!=null){
if(!item.getType().equals(Material.AIR)){
if(item.getType().equals(Material.ELYTRA)){
Expand All @@ -130,17 +128,72 @@ public static boolean hasElytraStorage(Player player) {
return false;
}

public static ItemStack[] listToArray(List<ItemStack> list){
ItemStack[] array = new ItemStack[list.size()];
int i = 0;
for (ItemStack is : list){
array[i] = is;
i += 1;
}
return array;
public static boolean containsFireworks(Player player) {
if(player.getInventory().getContents()!=null){
if(player.getInventory().contains(Material.FIREWORK_ROCKET)) {
for(ItemStack item : player.getInventory().getContents()){
if(item!=null && !item.getType().equals(Material.AIR)){
if(item.getType().equals(Material.FIREWORK_ROCKET)){
if(item.getAmount()>=Elytra.getCfg().chargeFirework) {
return true;
}
}
}
}
}
}
return false;
}


public static void removeFirework(Player player, int amount) {
PlayerInventory inv = player.getInventory();
for(ItemStack item : inv.getContents()){
if(item!=null){
if(!item.getType().equals(Material.AIR)){
if(item.getType().equals(Material.FIREWORK_ROCKET)){
if(item.getAmount()>=amount) {
inv.remove(item);
if(item.getAmount()-amount > 0) {
item.setAmount(item.getAmount()-amount);
inv.addItem(item);
}
return;
}
}
}
}
}
}

public static void autoEquip(Player player){
PlayerInventory inv = player.getInventory();
ItemStack chestplate = new ItemStack(Material.AIR);
ItemStack elytra = new ItemStack(Material.AIR);
if(inv.getChestplate()!=null && inv.getChestplate().getType()!=Material.AIR){
chestplate = inv.getChestplate();
inv.setChestplate(new ItemStack(Material.AIR));
}
for(ItemStack item : inv.getContents()){
if(item!=null){
if(item.getType().equals(Material.ELYTRA)){
elytra = item;
break;
}
}
}
inv.remove(elytra);
if((elytra.getAmount()-1)>0) {
elytra.setAmount(elytra.getAmount() -1);
inv.addItem(elytra);
}
if(chestplate.getType()!=Material.AIR){
inv.addItem(chestplate);
}
elytra.setAmount(1);
inv.setChestplate(elytra);
player.sendMessage(ChatColor.GREEN + "Elytra Auto-Equipped");
}

public static boolean checkEmptyBlocks(Location from, Location to) {
if (from.getBlockY() - to.getBlockY() < 1) return false;
Block bf = from.getBlock();
Expand All @@ -158,6 +211,7 @@ public static boolean isSameBlocks(Location loc1, Location loc2) {
if (loc1.getBlockX() != loc2.getBlockX()) return false;
if (loc1.getBlockZ() != loc2.getBlockZ()) return false;
if (loc1.getBlockY() != loc2.getBlockY()) return false;
if (loc1.getWorld() != loc2.getWorld()) return false;
return true;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ auto-glide:
enable: true # Enable auto-glide feature
auto-equip: false # Enable auto-equip feature (If a player has an elytra in his inventory, it is auto-equipped when auto-glide engages)
required-air-under-player: 3 # Amount of empty block under player feet required to start gliding
cancel-if-slow-fall: true # Cancels AutoGlide and AutoEquip if player have a slow fall potion activated.

# Constant flight
# Determines minimum glding speed, allows to flight constantly
Expand Down Expand Up @@ -55,6 +56,7 @@ run-up:
g-force:
damage-elytra: 10 # Break elytra
damage-player: 2.0 # Deal damage to player
charge-firework: 2

# Particles effects
particles:
Expand Down
Loading