Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fromgate committed Oct 25, 2013
0 parents commit f33554b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: PlayEffectRailgun
main: me.fromgate.playeffectrailgun.Railgun
version: 0.1.0
author: fromgate, [email protected]
depend: [PlayEffect]
74 changes: 74 additions & 0 deletions src/me/fromgate/playeffectrailgun/Railgun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.fromgate.playeffectrailgun;

import java.util.List;

import me.fromgate.playeffect.PlayEffect;
import me.fromgate.playeffect.Util;
import me.fromgate.playeffect.VisualEffect;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.java.JavaPlugin;

public class Railgun extends JavaPlugin implements Listener {


@Override
public void onEnable(){
if (getServer().getPluginManager().getPlugin("PlayEffect")==null){
getLogger().info("[PlayEffectRailgun] PlayEffect plugin required!");
return;
}

getServer().getPluginManager().registerEvents(this, this);
}

@EventHandler
public void railShot(PlayerInteractEvent event){
if (event.getAction() != Action.RIGHT_CLICK_AIR) return;
Player p = event.getPlayer();
if (p.getItemInHand()==null) return;
if (p.getItemInHand().getType()!= Material.BLAZE_ROD) return;
Location loc1 = p.getEyeLocation();
@SuppressWarnings("deprecation")
Location loc2 = p.getTargetBlock(null, 100).getLocation();
if (loc1 == null) return;
if (loc2 == null) return;
List<Location> line = Util.buildLine(loc1, loc2); // provided by PlayEffect
if (line.size()<=2) return;
line.remove(0);

if (p.hasMetadata("railgun")&&((System.currentTimeMillis()-p.getMetadata("railgun").get(0).asLong())<=15000)){
PlayEffect.play(VisualEffect.CLOUD, line.get(1), "num:5");
PlayEffect.play(VisualEffect.SOUND, line.get(1),"type:FUSE");
return;
}

p.setMetadata("railgun", new FixedMetadataValue (this, System.currentTimeMillis()));

for (Location l : line){
// PlayEffect: play firework effect to simulate railgun trails
String param = "loc:"+Util.locationToStrLoc(loc1)+" loc2:"+Util.locationToStrLoc(loc2)+" draw:line color:aqua type:ball";
PlayEffect.play(VisualEffect.FIREWORK, param);

for (Entity e : l.getChunk().getEntities()){
if (!(e instanceof LivingEntity)) continue;
LivingEntity le = (LivingEntity) e;
if (le.getLocation().distance(l)<=1.5) le.damage(le.getMaxHealth()*0.55);
}
}


}



}

0 comments on commit f33554b

Please sign in to comment.