Added CowSpawnLoop
Spawns cows every few nights if there are no cows near the player in question
This commit is contained in:
parent
213fa33d10
commit
ba8ad22889
11 changed files with 93 additions and 52 deletions
|
@ -1,4 +1,3 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
encoding/metrics=UTF-8
|
|
||||||
encoding/src=UTF-8
|
encoding/src=UTF-8
|
||||||
|
|
3
pom.xml
3
pom.xml
|
@ -21,9 +21,6 @@
|
||||||
<include>*.yml</include>
|
<include>*.yml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
<resource>
|
|
||||||
<directory>metrics</directory>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import alisolarflare.components.flaircolouring.FlairColouringComponent;
|
||||||
import alisolarflare.components.gpowers.GPowerComponent;
|
import alisolarflare.components.gpowers.GPowerComponent;
|
||||||
import alisolarflare.components.insurance.InsuranceComponent;
|
import alisolarflare.components.insurance.InsuranceComponent;
|
||||||
import alisolarflare.components.magic.MagicComponent;
|
import alisolarflare.components.magic.MagicComponent;
|
||||||
|
import alisolarflare.components.spawn.SpawnComponent;
|
||||||
|
|
||||||
public class AliPresents extends JavaPlugin{
|
public class AliPresents extends JavaPlugin{
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
|
@ -30,6 +31,7 @@ public class AliPresents extends JavaPlugin{
|
||||||
new InsuranceComponent().register(this);
|
new InsuranceComponent().register(this);
|
||||||
new MagicComponent().register(this);
|
new MagicComponent().register(this);
|
||||||
//new MetricsComponent().register(this);
|
//new MetricsComponent().register(this);
|
||||||
|
new SpawnComponent().register(this);
|
||||||
|
|
||||||
|
|
||||||
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");
|
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");
|
||||||
|
|
|
@ -23,6 +23,11 @@ public class CreativeBoundariesAPI {
|
||||||
cbCreatives.remove(player);
|
cbCreatives.remove(player);
|
||||||
}
|
}
|
||||||
public static boolean toCreative(Player 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());
|
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
|
||||||
|
|
||||||
if (tb == null) {
|
if (tb == null) {
|
||||||
|
|
|
@ -24,10 +24,12 @@ public class LetterDyeListener implements Listener{
|
||||||
try{
|
try{
|
||||||
if((event.getAction() != Action.RIGHT_CLICK_AIR)) return;
|
if((event.getAction() != Action.RIGHT_CLICK_AIR)) return;
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
|
|
||||||
if(item.getType() != Material.INK_SACK) return;
|
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;
|
if(item.getItemMeta().getDisplayName() == "LetterDye") return;
|
||||||
|
|
||||||
Dye dye = (Dye) event.getItem().getData();
|
Dye dye = (Dye) event.getItem().getData();
|
||||||
User user = essentials.getUser(event.getPlayer());
|
User user = essentials.getUser(event.getPlayer());
|
||||||
user.setNickname(FlairColouringAPI.colourShiftRight(user._getNickname(), dye.getColor()));
|
user.setNickname(FlairColouringAPI.colourShiftRight(user._getNickname(), dye.getColor()));
|
||||||
|
|
|
@ -11,7 +11,7 @@ import alisolarflare.components.metrics.files.MetricsFile;
|
||||||
import alisolarflare.components.metrics.output.GetLoginMetrics;
|
import alisolarflare.components.metrics.output.GetLoginMetrics;
|
||||||
|
|
||||||
public class MetricsComponent extends Component{
|
public class MetricsComponent extends Component{
|
||||||
String defaultPath = "metrics";
|
String defaultPath = "src/alisolarflare/resources";
|
||||||
String defaultFilePath = (defaultPath + "/metrics.txt");
|
String defaultFilePath = (defaultPath + "/metrics.txt");
|
||||||
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");
|
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");
|
||||||
|
|
||||||
|
|
|
@ -13,54 +13,28 @@ import java.util.List;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
|
||||||
public class MetricsFile {
|
public class MetricsFile {
|
||||||
private String fileName = "AliPresents/metrics/playerLogins.txt";
|
private String fileName = "src/alisolarflare/resources/metrics/playerLogins.txt";
|
||||||
public MetricsFile(String directory){
|
public MetricsFile(String filePath){
|
||||||
this.fileName = directory;
|
this.fileName = filePath;
|
||||||
}
|
}
|
||||||
public void AddLine(String string){
|
public void AddLine(String string){
|
||||||
BufferedWriter inputStream = null;
|
BufferedWriter inputStream = null;
|
||||||
String[] fileNames = {
|
try {
|
||||||
"/AliPresents/metrics/playerLogins.txt",
|
TBMCCoreAPI.sendDebugMessage("Trying to Open File: "+fileName+"...");
|
||||||
"AliPresents/metrics/playerLogins.txt",
|
File file = new File(fileName);
|
||||||
"/metrics/playerLogins.txt",
|
TBMCCoreAPI.sendDebugMessage("File Exists: " + file.exists());
|
||||||
"metrics/playerLogins.txt",
|
inputStream = new BufferedWriter(new FileWriter(fileName, true));
|
||||||
"/playerLogins.txt",
|
TBMCCoreAPI.sendDebugMessage("Input Stream Created!");
|
||||||
"playerLogins.txt",
|
TBMCCoreAPI.sendDebugMessage("Trying to write to file...");
|
||||||
|
inputStream.write(string);
|
||||||
|
TBMCCoreAPI.sendDebugMessage("Ending with newLine...");
|
||||||
"/AliPresents/metrics/playerLogins",
|
inputStream.newLine();
|
||||||
"AliPresents/metrics/playerLogins",
|
TBMCCoreAPI.sendDebugMessage("Closing File...");
|
||||||
"/metrics/playerLogins",
|
inputStream.close();
|
||||||
"metrics/playerLogins",
|
TBMCCoreAPI.sendDebugMessage("File Closed!");
|
||||||
"/playerLogins",
|
} catch (IOException e) {
|
||||||
"playerLogins",
|
TBMCCoreAPI.sendDebugMessage(fileName +" Input Stream could not be created! ");
|
||||||
|
TBMCCoreAPI.sendDebugMessage(e.toString());
|
||||||
".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);
|
|
||||||
TBMCCoreAPI.sendDebugMessage("File Exists: " + file.exists());
|
|
||||||
inputStream = new BufferedWriter(new FileWriter(fileName, true));
|
|
||||||
TBMCCoreAPI.sendDebugMessage("Input Stream Created!");
|
|
||||||
TBMCCoreAPI.sendDebugMessage("Trying to write to file...");
|
|
||||||
inputStream.write(string);
|
|
||||||
TBMCCoreAPI.sendDebugMessage("Ending with newLine...");
|
|
||||||
inputStream.newLine();
|
|
||||||
TBMCCoreAPI.sendDebugMessage("Closing File...");
|
|
||||||
inputStream.close();
|
|
||||||
TBMCCoreAPI.sendDebugMessage("File Closed!");
|
|
||||||
} catch (IOException e) {
|
|
||||||
TBMCCoreAPI.sendDebugMessage(fileName +" Input Stream could not be created! ");
|
|
||||||
TBMCCoreAPI.sendDebugMessage(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<String> toArrayList(){
|
public List<String> toArrayList(){
|
||||||
|
|
15
src/alisolarflare/components/spawn/SpawnComponent.java
Normal file
15
src/alisolarflare/components/spawn/SpawnComponent.java
Normal 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
src/alisolarflare/components/spawn/cows/CowSpawnLoop.java
Normal file
47
src/alisolarflare/components/spawn/cows/CowSpawnLoop.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue