This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a1b868
commit 67c1f0e
Showing
4 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
src/me/simplicitee/projectaddons/ability/earth/Crumble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters