Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
crumble
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplicitee committed Sep 7, 2019
1 parent 5a1b868 commit 67c1f0e
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/me/simplicitee/projectaddons/MainListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import me.simplicitee.projectaddons.ability.chi.NinjaStance;
import me.simplicitee.projectaddons.ability.chi.WeakeningJab;
import me.simplicitee.projectaddons.ability.earth.Accretion;
import me.simplicitee.projectaddons.ability.earth.Crumble;
import me.simplicitee.projectaddons.ability.earth.Dig;
import me.simplicitee.projectaddons.ability.earth.EarthKick;
import me.simplicitee.projectaddons.ability.earth.LavaSurge;
Expand Down Expand Up @@ -138,6 +139,8 @@ public void onLeftClick(final PlayerInteractEvent event) {
if (CoreAbility.hasAbility(player, Accretion.class)) {
CoreAbility.getAbility(player, Accretion.class).shoot();
}
} else if (canBend(player, "Crumble")) {
new Crumble(player, ClickType.LEFT_CLICK);
}
}

Expand Down Expand Up @@ -199,6 +202,8 @@ public void onSneak(PlayerToggleSneakEvent event) {
new Dig(player);
} else if (canBend(player, "Accretion")) {
new Accretion(player);
} else if (canBend(player, "Crumble")) {
new Crumble(player, ClickType.SHIFT_UP);
}
}

Expand Down Expand Up @@ -299,7 +304,7 @@ public void onHitDamage(EntityDamageByEntityEvent event) {
ActionBar.sendActionBar(ChatColor.LIGHT_PURPLE + "!> " + Element.CHI.getColor() + "Dodged" + ChatColor.LIGHT_PURPLE + " <!", player);

if (damagerE instanceof Player) {
ActionBar.sendActionBar(ChatColor.LIGHT_PURPLE + "!> " + ChatColor.WHITE + player.getName() + Element.CHI.getColor() + "dodged" + ChatColor.LIGHT_PURPLE + " <!", (Player) damagerE);
ActionBar.sendActionBar(ChatColor.LIGHT_PURPLE + "!> " + ChatColor.WHITE + player.getName() + Element.CHI.getColor() + " dodged" + ChatColor.LIGHT_PURPLE + " <!", (Player) damagerE);
}

return;
Expand Down
15 changes: 15 additions & 0 deletions src/me/simplicitee/projectaddons/ProjectAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -13,6 +14,7 @@
import com.projectkorra.projectkorra.configuration.Config;

import me.simplicitee.projectaddons.ability.air.GaleGust;
import me.simplicitee.projectaddons.ability.earth.Crumble;
import me.simplicitee.projectaddons.ability.fire.FireDisc;
import me.simplicitee.projectaddons.ability.water.RazorLeaf;

Expand Down Expand Up @@ -50,6 +52,12 @@ public void onDisable() {
if (boards != null) {
boards.disable();
}

if (CoreAbility.getAbility(Crumble.class) != null) {
for (Crumble c : CoreAbility.getAbilities(Crumble.class)) {
c.revert();
}
}
}

public String prefix() {
Expand Down Expand Up @@ -306,6 +314,13 @@ private void setupConfig() {
c.addDefault("Abilities.Accretion.SelectRange", 7);
c.addDefault("Abilities.Accretion.RevertTime", 20000);

// Crumble
c.addDefault("Abilities.Crumble.Enabled", true);
c.addDefault("Abilities.Crumble.Cooldown", 2000);
c.addDefault("Abilities.Crumble.Radius", 6);
c.addDefault("Abilities.Crumble.SelectRange", 9);
c.addDefault("Abilities.Crumble.RevertTime", 60);

config.save();
}

Expand Down
181 changes: 181 additions & 0 deletions src/me/simplicitee/projectaddons/ability/earth/Crumble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package me.simplicitee.projectaddons.ability.earth;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AddonAbility;
import com.projectkorra.projectkorra.ability.SandAbility;
import com.projectkorra.projectkorra.util.ClickType;
import com.projectkorra.projectkorra.util.TempBlock;

import me.simplicitee.projectaddons.ProjectAddons;

public class Crumble extends SandAbility implements AddonAbility {

private int radius, maxRadius, counter, revertTime;
private long cooldown;
private Block center;
private Map<Block, BlockData> revert;

public Crumble(Player player, ClickType click) {
super(player);

if (bPlayer.isOnCooldown(this)) {
return;
}

if (click == ClickType.LEFT_CLICK) {
int selectRange = ProjectAddons.instance.getConfig().getInt("Abilities.Crumble.SelectRange");
this.center = player.getTargetBlock(null, selectRange);
} else {
this.center = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
}

this.revert = new HashMap<>();
this.revertTime = ProjectAddons.instance.getConfig().getInt("Abilities.Crumble.RevertTime");
this.counter = 0;
this.radius = 0;
this.cooldown = ProjectAddons.instance.getConfig().getLong("Abilities.Crumble.Cooldown");
this.maxRadius = ProjectAddons.instance.getConfig().getInt("Abilities.Crumble.Radius");

start();
}

@Override
public long getCooldown() {
return cooldown;
}

@Override
public Location getLocation() {
return null;
}

@Override
public String getName() {
return "Crumble";
}

@Override
public boolean isHarmlessAbility() {
return true;
}

@Override
public boolean isSneakAbility() {
return true;
}

@Override
public void progress() {
if (!player.isOnline() || player.isDead()) {
remove();
return;
} else if (radius > maxRadius) {
remove();
return;
}

counter++;
if (counter % 2 != 0) {
return;
}

for (int theta = 0; theta < 360; theta += 5) {
double x = Math.cos(Math.toRadians(theta)) * radius;
double z = Math.sin(Math.toRadians(theta)) * radius;

Block block = center.getRelative((int)x, 0, (int)z);
block = GeneralMethods.getTopBlock(block.getLocation(), 2);

if (block.isPassable() && !block.isLiquid()) {
block.breakNaturally();
block = block.getRelative(BlockFace.DOWN);
}

if (TempBlock.isTempBlock(block)) {
continue;
} else if (!isEarthbendable(block)) {
continue;
} else if (isSand(block)) {
continue;
}

Material m = Material.SAND;
if (isAir(block.getRelative(BlockFace.DOWN).getType())) {
m = Material.SANDSTONE;
}

revert.put(block, block.getBlockData());
final Block b = block;

new BukkitRunnable() {

@Override
public void run() {
b.setBlockData(revert.get(b));
}

}.runTaskLater(ProjectKorra.plugin, 20 * revertTime);

block.setType(m);
}

radius++;
}

@Override
public void remove() {
super.remove();
bPlayer.addCooldown(this);
}

@Override
public String getAuthor() {
return "Simplicitee";
}

@Override
public String getVersion() {
return ProjectAddons.instance.version();
}

@Override
public void load() {
}

@Override
public void stop() {
}

public void revert() {
for (Block b : revert.keySet()) {
b.setBlockData(revert.get(b));
}
}

@Override
public boolean isEnabled() {
return ProjectAddons.instance.getConfig().getBoolean("Abilities.Crumble.Enabled");
}

@Override
public String getDescription() {
return "Crumble the earth into sand!";
}

@Override
public String getInstructions() {
return "Left click or sneak";
}
}
3 changes: 3 additions & 0 deletions src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ permissions:
bending.ability.galegust: true
bending.ability.zephyr: true
bending.ability.dig: true
bending.ability.dodging: true
bending.ability.accretion: true
bending.ability.crumble: true
bending.ability.tailwind: true
bending.ability.plantarmor:
children:
Expand Down

0 comments on commit 67c1f0e

Please sign in to comment.