Last active
February 11, 2018 18:57
-
-
Save Densyakun/d04ee51bba115fefc31f9810127520d5 to your computer and use it in GitHub Desktop.
[BukkitPlugin]左クリックで矢を跳ね返すプラグイン。
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
package org.densyakun.arrowreturn; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.bukkit.Material; | |
import org.bukkit.entity.EntityType; | |
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.entity.EntityDamageByEntityEvent; | |
import org.bukkit.event.player.PlayerInteractEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import net.minecraft.server.v1_8_R3.EntityArrow; | |
public class ArrowReturn extends JavaPlugin implements Listener { | |
static List<Player> a = new ArrayList<Player>(); | |
@Override | |
public void onEnable() { | |
getServer().getPluginManager().registerEvents(this, this); | |
} | |
@EventHandler | |
public void a(PlayerInteractEvent a) { | |
if ((a.getAction() == Action.LEFT_CLICK_AIR || a.getAction() == Action.LEFT_CLICK_BLOCK) | |
&& a.getPlayer().getItemInHand() != null | |
&& a.getPlayer().getItemInHand().getType() == Material.GOLD_SWORD) | |
new a(a.getPlayer()); | |
} | |
@EventHandler | |
public void ArrowAttack(EntityDamageByEntityEvent evt) { | |
if (evt.getDamager().getType() == EntityType.ARROW && evt.getEntityType() == EntityType.PLAYER | |
&& c((Player) evt.getEntity()) | |
&& ((Player) evt.getEntity()).getItemInHand().getType() == Material.GOLD_SWORD) { | |
evt.setCancelled(true); | |
EntityArrow arrow = (EntityArrow) evt.getEntity(); | |
float yaw; | |
float pitch; | |
if ((arrow.yaw + 180) >= 360) | |
yaw = arrow.yaw + 180; | |
else | |
yaw = arrow.yaw - 180; | |
if ((arrow.pitch + 180) >= 360) | |
pitch = arrow.pitch + 180; | |
else | |
pitch = arrow.pitch - 180; | |
arrow.shoot(arrow.lastX, arrow.lastY, arrow.lastZ, yaw, pitch); | |
} | |
} | |
public boolean c(Player b) { | |
for (int c = 0; c < a.size(); c++) | |
if (b.getName().equals(a.get(c).b) && c) | |
return true; | |
return false; | |
} | |
private static class a implements Runnable { | |
boolean c = true; | |
public a(Player b) { | |
Start.a.add(b); | |
new Thread(this).start(); | |
} | |
@Override | |
public void run() { | |
try { | |
Thread.sleep(125); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
c = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment