Nothing to see here, just some boring patches and fixes!

This commit is contained in:
TfT_02 2013-01-11 22:31:21 +01:00
parent e6607783e9
commit 6f29e475ee
3 changed files with 156 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Anniversary;
public class McmmoCommand implements CommandExecutor {
@Override
@ -30,6 +31,8 @@ public class McmmoCommand implements CommandExecutor {
}
sender.sendMessage(ChatColor.YELLOW + "Running version: " + ChatColor.DARK_AQUA + mcMMO.p.getDescription().getVersion());
Anniversary anniversary = new Anniversary();
anniversary.anniversaryCheck(sender);
return true;
}
}

View File

@ -76,6 +76,7 @@ import com.gmail.nossr50.runnables.UserPurgeTask;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.RepairManagerFactory;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.util.Anniversary;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Leaderboard;
import com.gmail.nossr50.util.Metrics;
@ -245,6 +246,10 @@ public class mcMMO extends JavaPlugin {
// Automatically starts and stores itself
MobStoreCleaner cleaner = new MobStoreCleaner();
// Create Anniversary files
Anniversary anniversary = new Anniversary();
anniversary.createAnniversaryFile();
}
/**

View File

@ -0,0 +1,148 @@
package com.gmail.nossr50.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import com.gmail.nossr50.mcMMO;
public class Anniversary {
private Random random = new Random();
public static ArrayList<String> hasCelebrated;
//This gets called onEnable
public void createAnniversaryFile() {
File anniversaryFile = new File(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "anniversary");
if (!anniversaryFile.exists()) {
try {
anniversaryFile.createNewFile();
} catch (IOException ex) {
System.out.println(ex);
}
}
hasCelebrated = new ArrayList<String>();
try {
hasCelebrated.clear();
BufferedReader reader = new BufferedReader(new FileReader(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "players"));
String line = reader.readLine();
while (line != null) {
hasCelebrated.add(line);
line = reader.readLine();
}
reader.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
//This gets called from /mcmmo command
public void anniversaryCheck(final CommandSender sender) {
GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6);
GregorianCalendar day = new GregorianCalendar();
int celebrationCheck = 0;
for (String celebrated : hasCelebrated) {
if (sender.getName().equalsIgnoreCase(celebrated)) {
celebrationCheck = 1;
}
}
if (celebrationCheck == 0) {
if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) {
sender.sendMessage(ChatColor.BLUE + "Happy 2 Year Anniversary! In honor of all of");
sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
final int firework_amount = 10;
for (int i = 0; i < firework_amount; i++) {
int delay = (int) (Math.random() * 3) + 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() {
@Override
public void run() {
spawnFireworks((Player) sender);
}
}, 20 * delay);
}
}
hasCelebrated.add(sender.getName());
}
}
private boolean getDateRange(Date date, Date start, Date end) {
return !(date.before(start) || date.after(end));
}
private void spawnFireworks(Player player) {
int power = (int) (Math.random() * 3) + 1;
int type = (int) (Math.random() * 5) + 1;
Type typen = Type.BALL;
if (type == 1) typen = Type.BALL;
if (type == 2) typen = Type.BALL_LARGE;
if (type == 3) typen = Type.BURST;
if (type == 4) typen = Type.CREEPER;
if (type == 5) typen = Type.STAR;
Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
FireworkMeta fireworkmeta = fireworks.getFireworkMeta();
FireworkEffect effect = FireworkEffect.builder().flicker(random.nextBoolean()).withColor(colorchoose()).withFade(colorchoose()).with(typen).trail(random.nextBoolean()).build();
fireworkmeta.addEffect(effect);
fireworkmeta.setPower(power);
fireworks.setFireworkMeta(fireworkmeta);
}
private List<Color> colorchoose() {
// Thanks Zomis and Tejpbit for the help with this function!
int numberofcolors = random.nextInt(17) + 1;
List<Color> allcolors = new ArrayList<Color>();
allcolors.add(Color.AQUA);
allcolors.add(Color.BLACK);
allcolors.add(Color.BLUE);
allcolors.add(Color.FUCHSIA);
allcolors.add(Color.GRAY);
allcolors.add(Color.GREEN);
allcolors.add(Color.LIME);
allcolors.add(Color.MAROON);
allcolors.add(Color.NAVY);
allcolors.add(Color.OLIVE);
allcolors.add(Color.ORANGE);
allcolors.add(Color.PURPLE);
allcolors.add(Color.RED);
allcolors.add(Color.SILVER);
allcolors.add(Color.TEAL);
allcolors.add(Color.WHITE);
allcolors.add(Color.YELLOW);
List<Color> choosencolors = new ArrayList<Color>();
for (int i = 0; i < numberofcolors; i++) {
choosencolors.add(allcolors.remove(random.nextInt(allcolors.size())));
}
return choosencolors;
}
}