Added CowSpawnLoop

Spawns cows every few nights if there are no cows near the player in
question
This commit is contained in:
alisolarflare 2016-12-08 21:01:04 -05:00
parent 213fa33d10
commit ba8ad22889
11 changed files with 93 additions and 52 deletions

View file

@ -1,4 +1,3 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
encoding/metrics=UTF-8
encoding/src=UTF-8

View file

@ -21,9 +21,6 @@
<include>*.yml</include>
</includes>
</resource>
<resource>
<directory>metrics</directory>
</resource>
</resources>
<plugins>
<plugin>

View file

@ -13,6 +13,7 @@ import alisolarflare.components.flaircolouring.FlairColouringComponent;
import alisolarflare.components.gpowers.GPowerComponent;
import alisolarflare.components.insurance.InsuranceComponent;
import alisolarflare.components.magic.MagicComponent;
import alisolarflare.components.spawn.SpawnComponent;
public class AliPresents extends JavaPlugin{
public void onEnable(){
@ -30,6 +31,7 @@ public class AliPresents extends JavaPlugin{
new InsuranceComponent().register(this);
new MagicComponent().register(this);
//new MetricsComponent().register(this);
new SpawnComponent().register(this);
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");

View file

@ -23,6 +23,11 @@ public class CreativeBoundariesAPI {
cbCreatives.remove(player);
}
public static boolean toCreative(Player player){
if (player.getWorld().getName().equalsIgnoreCase("World")){
player.sendMessage("Creative Boundaries is disabled on the New Map!");
return true;
}
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
if (tb == null) {

View file

@ -24,8 +24,10 @@ public class LetterDyeListener implements Listener{
try{
if((event.getAction() != Action.RIGHT_CLICK_AIR)) return;
ItemStack item = event.getItem();
if(item.getType() != Material.INK_SACK) return;
if(item.getItemMeta().hasEnchant(Enchantment.LUCK) && (item.getItemMeta().getEnchantLevel(Enchantment.LUCK) == 10)) return;
if(item.getItemMeta().hasEnchant(Enchantment.LUCK)) return;
if(item.getItemMeta().getEnchantLevel(Enchantment.LUCK) == 10) return;
if(item.getItemMeta().getDisplayName() == "LetterDye") return;
Dye dye = (Dye) event.getItem().getData();

View file

@ -11,7 +11,7 @@ import alisolarflare.components.metrics.files.MetricsFile;
import alisolarflare.components.metrics.output.GetLoginMetrics;
public class MetricsComponent extends Component{
String defaultPath = "metrics";
String defaultPath = "src/alisolarflare/resources";
String defaultFilePath = (defaultPath + "/metrics.txt");
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");

View file

@ -13,37 +13,12 @@ import java.util.List;
import buttondevteam.lib.TBMCCoreAPI;
public class MetricsFile {
private String fileName = "AliPresents/metrics/playerLogins.txt";
public MetricsFile(String directory){
this.fileName = directory;
private String fileName = "src/alisolarflare/resources/metrics/playerLogins.txt";
public MetricsFile(String filePath){
this.fileName = filePath;
}
public void AddLine(String string){
BufferedWriter inputStream = null;
String[] fileNames = {
"/AliPresents/metrics/playerLogins.txt",
"AliPresents/metrics/playerLogins.txt",
"/metrics/playerLogins.txt",
"metrics/playerLogins.txt",
"/playerLogins.txt",
"playerLogins.txt",
"/AliPresents/metrics/playerLogins",
"AliPresents/metrics/playerLogins",
"/metrics/playerLogins",
"metrics/playerLogins",
"/playerLogins",
"playerLogins",
".AliPresents.metrics.playerLogins.txt",
"AliPresents.metrics.playerLogins.txt",
".metrics.playerLogins.txt",
"metrics.playerLogins.txt",
".playerLogins.txt",
"playerLogins.txt",
};
for(String fileName: fileNames){
try {
TBMCCoreAPI.sendDebugMessage("Trying to Open File: "+fileName+"...");
File file = new File(fileName);
@ -62,7 +37,6 @@ public class MetricsFile {
TBMCCoreAPI.sendDebugMessage(e.toString());
}
}
}
public List<String> toArrayList(){
BufferedReader outputStream = null;
try {

View file

@ -0,0 +1,15 @@
package alisolarflare.components.spawn;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.components.spawn.cows.CowSpawnLoop;
public class SpawnComponent extends Component {
@Override
public void register(JavaPlugin plugin) {
registerListener(plugin, new CowSpawnLoop(plugin));
}
}

View file

@ -0,0 +1,47 @@
package alisolarflare.components.spawn.cows;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
public class CowSpawnLoop extends BukkitRunnable implements Listener{
private JavaPlugin plugin;
public CowSpawnLoop(JavaPlugin plugin) {
this.plugin = plugin;
this.runTaskTimer(plugin, 30200, 30200);
}
@Override
public void run() {
boolean foodTrue;
for (Player player : plugin.getServer().getOnlinePlayers()){
foodTrue = false;
for (Entity entity : player.getNearbyEntities(128, 128, 128)){
if (entity instanceof Cow){
foodTrue = true;
}
}
if (foodTrue){
Location location = player.getLocation().add(new Vector(Math.random()*20, 0, Math.random()*20).normalize().multiply(30));
Block attemptedCowSpawn = player.getWorld().getHighestBlockAt(location);
if (attemptedCowSpawn.getType().equals(Material.GRASS)){
player.getWorld().spawnEntity(attemptedCowSpawn.getLocation().add(new Vector (0,1,0)), EntityType.COW);
player.getWorld().spawnEntity(attemptedCowSpawn.getLocation().add(new Vector (0,1,0)), EntityType.COW);
player.getWorld().spawnEntity(attemptedCowSpawn.getLocation().add(new Vector (0,1,0)), EntityType.COW);
}
}
}
}
}