Last active
August 29, 2015 13:56
-
-
Save 97WaterPolo/9319085 to your computer and use it in GitHub Desktop.
FisherMan Class
This file contains hidden or 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
//TODO Change the instances for the teams with scoreboard stuff. | |
/**Hallo Saunders! I really appreciate you giving me the chance to help with anni, I went onto the forums and saw your | |
* sticky of future classes, the first one was a Fisherman class that CoastinJosh posted. Hopefully this works for you! | |
* | |
* I have the teams and board registered in my main class, so if you use this change it to where your scoreboard stuff is. | |
* | |
* Most of it is commented, so you can kind of see my train of thought. | |
* | |
* | |
* Basically this does - If a player is fishing, and the item is a fish, there is a 75% chance of them getting 2 of it. | |
* It goes directly into their inventory when the reel in if something is on it. | |
* | |
* Thinking that if the player hooks a player, they can pull them one or two blocks just like SMASH grapple, I assume you would just reverse | |
* the scout grapple, so instead of pulling them towards the player, it pulls player towards them. This would make the class unique as if a player is shooting a bow, | |
* or PvPing, this one slight adjustment to their location, will throw them off a little. Possible add a cooldown in which a player can't pull a player for | |
* 10sec after pulling a player. They could still cast it, but when they try to reel the player in the event is cancelled. | |
* | |
* I also added a velocity so if a player is underwater, they move close to normal speed. Problem is its a little glitchy, not sure if you have a better | |
* way to do it, but you can always say you act like a fish with the fast jerky movements. | |
* | |
* Added water breathing potion effect on the respawn, its infinite just like scout's speed | |
* | |
* I added a random drop chance when dealing with items, you can get stuff as low as a "Sunken Boat" to something as rare as a diamond. | |
* | |
* Also, if you catch a fish, it heals you one food bar and its counterpart if you catch an item it heals you half a heart. | |
* | |
* Also added sharking, basically it checks to see if player is underwater, and then checks the state of the rod, if the | |
* state is cancelled, it shoots the player forward with a velocity of .5. Its actuallly pretty effective and works well in my opinion, as | |
* well as imitates the jerky movements fish make. | |
* | |
* Another featured I "tried" to add was increasing the bite chance. Was pretty simple as it worked in older versions, unfortunetly it | |
* doesn't work 1.7+ due to the new fishing system. Hopefully if bukkit updated the fishing system or someone makes a PR it will be fixed. | |
* | |
* Also added it so if a player hits an enemy with the hook it does knock them back a little like normal, but when the reel it in, it pulls the player | |
* towards them at a velocity of -.5. Its not alot, but it would be a cool feature to overthrow a player's balance by a little. Also I added a 10sec cooldown | |
* so you can't spam it, once a player is pulled by the hook, the caught player is added to a list, and while on that list all damage fishing hook related | |
* is cancelled. I am guessing this is similiar to the scorpio fall damage negation stuff. | |
*/ | |
package com.AnniStuff.sigler; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Random; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Color; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.Sound; | |
import org.bukkit.World; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.EntityType; | |
import org.bukkit.entity.Fish; | |
import org.bukkit.entity.Item; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.EventPriority; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.EntityDamageByEntityEvent; | |
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; | |
import org.bukkit.event.entity.ProjectileLaunchEvent; | |
import org.bukkit.event.player.PlayerFishEvent; | |
import org.bukkit.event.player.PlayerFishEvent.State; | |
import org.bukkit.event.player.PlayerJoinEvent; | |
import org.bukkit.event.player.PlayerMoveEvent; | |
import org.bukkit.event.player.PlayerRespawnEvent; | |
import org.bukkit.inventory.Inventory; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
import org.bukkit.inventory.meta.LeatherArmorMeta; | |
import org.bukkit.potion.PotionEffect; | |
import org.bukkit.potion.PotionEffectType; | |
import org.bukkit.scheduler.BukkitScheduler; | |
import org.bukkit.scoreboard.Team; | |
import org.bukkit.util.Vector; | |
@SuppressWarnings("unused") | |
public class Fisherman implements Listener | |
{ | |
public Main plugin;//The variable to refer to the class that extends JP, needed it for scheduler | |
public Fisherman(Main plugin) { | |
this.plugin = plugin; | |
} | |
//Checks if a player is underwater | |
public boolean isUnderWater(Player p) | |
{ | |
World w = p.getWorld(); | |
Location l = p.getLocation(); | |
l.setY(l.getY() + 1); | |
if(w.getBlockAt(l).getType() == Material.WATER || w.getBlockAt(l).getType() == Material.STATIONARY_WATER){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//Sets the color for the leather armor | |
public ItemStack setColor(ItemStack item, Color color) | |
{ | |
LeatherArmorMeta lam = (LeatherArmorMeta)item.getItemMeta(); | |
lam.setColor(color); | |
item.setItemMeta(lam); | |
return item; | |
} | |
//Changes the display name of the fishing rod | |
public static ItemStack newItem(Material material, String itemname) | |
{ | |
ItemStack item = new ItemStack(material); | |
ItemMeta meta = item.getItemMeta(); | |
meta.setDisplayName(itemname); | |
item.setItemMeta(meta); | |
return item; | |
} | |
ItemStack FishingRod = newItem(Material.FISHING_ROD, ChatColor.ITALIC + "Fishing Rod"); | |
public Inventory playerArmor(Player player,ItemStack helm, ItemStack chest, ItemStack leg, ItemStack boot) | |
{ | |
player.getInventory().setArmorContents(null); //clear armor contetns | |
player.getInventory().setHelmet(helm); //set helm | |
player.getInventory().setChestplate(chest); //set chests | |
player.getInventory().setLeggings(leg); //set leggings | |
player.getInventory().setBoots(boot); //set boots | |
player.getInventory().addItem(new ItemStack(Material.COMPASS,1)); //starter kit | |
player.getInventory().addItem(new ItemStack(Material.WOOD_AXE,1)); //starter kit | |
player.getInventory().addItem(new ItemStack(Material.WOOD_PICKAXE,1)); //starter kit | |
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD,1)); //starter kit | |
player.getInventory().addItem(FishingRod); //starter kit special item | |
return null; | |
} | |
//Not sure how you do the team armor, or if there is a more efficient way, I just create a new item per team and set the color. Pretty sure | |
// your respawn event has a better way. | |
ItemStack helm = new ItemStack(Material.LEATHER_HELMET, 1); | |
ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1); | |
ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS, 1); | |
ItemStack boot = new ItemStack(Material.LEATHER_BOOTS, 1); | |
Random rand = new Random(); | |
ArrayList<String> cooldown = new ArrayList<String>(); | |
@SuppressWarnings({ "deprecation", "static-access" }) | |
@EventHandler(priority=EventPriority.HIGH) | |
public void PlayerFishing(PlayerFishEvent event) | |
{ | |
final Player player = event.getPlayer(); | |
player.getItemInHand().setDurability((short) 0); | |
event.getHook().setBiteChance(0.5); //Sets the bite chance, currently broken | |
if((event.getCaught() != null) && event.getCaught() instanceof Item) | |
{ | |
Item item = (Item) event.getCaught(); | |
ItemStack drop = item.getItemStack(); | |
item.remove(); | |
if ((item.getItemStack().getType().equals(Material.RAW_FISH))) //From testing, since rest of fish come from RAW_FISH, this works for the rest like puffer, clown, etc. | |
{ | |
if (player.getFoodLevel() <= 20) | |
{ | |
player.setFoodLevel(player.getFoodLevel() + 2); //If its a fish, give them a food bar | |
}else{return;} | |
if (!(player.getInventory().firstEmpty() == -1)) //If their inventory is not full, add it | |
{ | |
player.playSound(player.getLocation(), Sound.WATER, 1.0F, 1.0F); //plays a sound, no idea what to put | |
player.getInventory().addItem(drop); // Adds the original item straight to their inventory | |
int odd = rand.nextInt(4); //Next integer | |
if (odd != 0) //as a 75% chance of getting double drops | |
{ | |
player.getInventory().addItem(drop);//adding second drop | |
} | |
item.remove(); //removing the item | |
player.updateInventory(); | |
}else | |
{ | |
player.getWorld().dropItemNaturally(player.getLocation(), drop); //if their inventory is full, drop it naturally where they are | |
} | |
}else | |
{ | |
if (player.getHealth() <= player.getMaxHealth()) | |
{ | |
player.setHealth(player.getHealth() + 1); | |
}else{return;} | |
int oddOG = rand.nextInt(2); // To determine if there should be a extra drop | |
if (!(player.getInventory().firstEmpty() == -1)) | |
{ | |
if (oddOG == 0) | |
{ | |
int odd = rand.nextInt(50); //determine what the extra drop should be | |
player.getInventory().addItem(drop); //Adds the original drop | |
if (odd <= 5) | |
{ | |
player.getInventory().addItem(new ItemStack(Material.IRON_INGOT, 1)); | |
}else if (odd >= 6 && odd <= 10) | |
{ | |
player.getInventory().addItem(new ItemStack(Material.GOLD_INGOT, 1)); | |
}else if (odd >= 11 && odd <= 14) | |
{ | |
player.getInventory().addItem(new ItemStack(Material.GOLD_ORE, 1)); | |
} | |
else if (odd >= 15 && odd <= 18) | |
{ | |
player.getInventory().addItem(new ItemStack(Material.APPLE, 1)); | |
} | |
else if (odd == 19) | |
{ | |
player.getInventory().addItem(new ItemStack(Material.DIAMOND, 1)); | |
}else if (odd > 20 && odd < 30) | |
{ | |
player.getInventory().addItem(new ItemStack(this.newItem(Material.BOAT, ChatColor.ITALIC + "Sunken Boat"))); | |
}else | |
{ | |
return; | |
} | |
}else | |
{ | |
player.getInventory().addItem(drop); | |
} | |
}else | |
{ | |
player.getWorld().dropItemNaturally(player.getLocation(), drop); //if their inventory is full, drop it naturally where they are | |
} | |
player.playSound(player.getLocation(), Sound.CAT_PURR, 1.0F, 1.0F); //Not sure what sound to place. | |
item.remove(); //removing the item | |
event.setCancelled(true); | |
player.updateInventory(); | |
} | |
} | |
if (this.isUnderWater(player)) // The sharking method | |
{ | |
if (event.getState() == State.FAILED_ATTEMPT || event.getState() == State.IN_GROUND) | |
{ | |
Vector velocity = new Vector(); | |
velocity = player.getLocation().getDirection().multiply(.5); | |
player.setVelocity(velocity); | |
} | |
} | |
if (event.getCaught() instanceof Player) | |
{ | |
final Player caught = (Player) event.getCaught(); | |
Vector velocity = new Vector(); | |
velocity = player.getLocation().getDirection().multiply(-0.5); | |
caught.setVelocity(velocity); | |
cooldown.add(caught.getName());//adds them to a cooldown - the person who was hooked | |
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() //Removes them from player cooldown | |
{ | |
@Override | |
public void run() | |
{cooldown.remove(caught.getName());} | |
}, 100L); | |
} | |
} | |
@EventHandler | |
public void fishHook(EntityDamageByEntityEvent event) | |
{ | |
if (event.getDamager() instanceof Fish && event.getEntity() instanceof Player) | |
{ | |
Player player = (Player) event.getEntity(); | |
if (cooldown.contains(player.getName())) | |
{ | |
event.setCancelled(true); | |
}else | |
{ | |
return; | |
} | |
} | |
} | |
//Not sure what method you use to check for teams, so I just made a team variable at the start | |
ArrayList<String> fisherman = new ArrayList<String>(); | |
@EventHandler | |
public void playerRespawn(PlayerRespawnEvent event) | |
{ | |
final Player player = event.getPlayer(); | |
//For some reason it needs to be delayed or it won't give the effect? o_O Should be the same thing you do for scout but change potion effect. | |
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){@Override public void run(){player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 999999, 1));}}, 5L); | |
if (plugin.red.hasPlayer(player) && fisherman.contains(player.getName())) //The fisherman List is how you tell if a player has that class selected. Not sure how you do it. | |
{ | |
this.setColor(helm, Color.RED); | |
this.setColor(chest, Color.RED); | |
this.setColor(leg, Color.RED); | |
this.setColor(boot, Color.RED); | |
this.playerArmor(player, helm, chest, leg, boot); | |
} | |
else if (plugin.blue.hasPlayer(player) && fisherman.contains(player.getName())) | |
{ | |
this.setColor(helm, Color.BLUE); | |
this.setColor(chest, Color.BLUE); | |
this.setColor(leg, Color.BLUE); | |
this.setColor(boot, Color.BLUE); | |
this.playerArmor(player, helm, chest, leg, boot); | |
} | |
else if (plugin.green.hasPlayer(player) && fisherman.contains(player.getName())) | |
{ | |
this.setColor(helm, Color.GREEN); | |
this.setColor(chest, Color.GREEN); | |
this.setColor(leg, Color.GREEN); | |
this.setColor(boot, Color.GREEN); | |
this.playerArmor(player, helm, chest, leg, boot); | |
} | |
else if (plugin.yellow.hasPlayer(player) && fisherman.contains(player.getName())) | |
{ | |
this.setColor(helm, Color.YELLOW); | |
this.setColor(chest, Color.YELLOW); | |
this.setColor(leg, Color.YELLOW); | |
this.setColor(boot, Color.YELLOW); | |
this.playerArmor(player, helm, chest, leg, boot); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment