129 lines
5.1 KiB
Java
129 lines
5.1 KiB
Java
package eu.univento.teamvento;
|
|
|
|
import eu.univento.commons.server.ServerType;
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.command.CommandFramework;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.server.ServerSettings;
|
|
import eu.univento.teamvento.commands.WorldCommands;
|
|
import eu.univento.teamvento.listener.Events;
|
|
import eu.univento.teamvento.listener.JoinQuit;
|
|
import eu.univento.teamvento.listener.MenuEvents;
|
|
import eu.univento.teamvento.listener.SignInteract;
|
|
import eu.univento.teamvento.generator.GeneratorManager;
|
|
import eu.univento.teamvento.plot.PlotManager;
|
|
import org.bukkit.*;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.entity.Entity;
|
|
import org.bukkit.entity.EntityType;
|
|
import org.bukkit.entity.Firework;
|
|
import org.bukkit.entity.Sheep;
|
|
import org.bukkit.inventory.meta.FireworkMeta;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.bukkit.util.Vector;
|
|
|
|
import java.io.File;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
|
|
public class TeamVento extends JavaPlugin {
|
|
|
|
private static final File file = new File("plugins/Core", "worlds.yml");
|
|
private static final FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
|
|
|
public static File getConfigFile() {
|
|
return file;
|
|
}
|
|
|
|
public static FileConfiguration getCfg() {
|
|
return cfg;
|
|
}
|
|
|
|
private static TeamVento instance;
|
|
public static TeamVento getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
private Random random = new Random();
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
instance = this;
|
|
/*
|
|
if(Bukkit.getWorld("plots") == null) {
|
|
WorldCreator creator = new WorldCreator("plots");
|
|
creator.generator(new VoidGenerator());
|
|
creator.type(WorldType.CUSTOMIZED);
|
|
creator.generateStructures(false);
|
|
Bukkit.createWorld(creator);
|
|
getCfg().set("plots", "void");
|
|
try {
|
|
getCfg().save(getConfigFile());
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
*/
|
|
|
|
CommandFramework commandFramework = new CommandFramework(this);
|
|
commandFramework.registerCommands(new WorldCommands());
|
|
|
|
PluginManager pm = Bukkit.getPluginManager();
|
|
pm.registerEvents(new JoinQuit(), getInstance());
|
|
pm.registerEvents(new SignInteract(), getInstance());
|
|
pm.registerEvents(new MenuEvents(), getInstance());
|
|
pm.registerEvents(new Events(), getInstance());
|
|
|
|
//new PlotInfo(this, "plotinfo", "info about a plot", "pi");
|
|
|
|
for(String world : getCfg().getKeys(true)) {
|
|
World loadedWorld = Bukkit.createWorld(GeneratorManager.getWorldCreator(world, getCfg().getString(world)));
|
|
loadedWorld.setDifficulty(Difficulty.HARD);
|
|
loadedWorld.setPVP(false);
|
|
loadedWorld.setAnimalSpawnLimit(0);
|
|
}
|
|
|
|
ServerSettings.setServerType(ServerType.TEAM_BUILD);
|
|
ServerSettings.setGameMode(GameMode.CREATIVE);
|
|
//PlotManager.update();
|
|
//PlotManager.setLastPlot(PlotManager.getPlotByOwner(Config.readString("lastPlot")));
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> Bukkit.getWorlds().stream().filter(world -> world.getTime() > 7698).forEach(world -> world.setTime(0)), 100 * 20L, 20L);
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> Events.redstone = 0, 1L, 10 * 20L);
|
|
|
|
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
|
for(CustomPlayer player : Core.getOnlinePlayers()) {
|
|
if(player.getItemInHand().getType() == Material.SHEARS) {
|
|
Sheep sheep = (Sheep) player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.SHEEP);
|
|
sheep.setColor(DyeColor.values()[random.nextInt(DyeColor.values().length)]);
|
|
sheep.setVelocity(new Vector(random.nextDouble() * (random.nextBoolean() ? 1 : -1), 2, random.nextDouble() * (random.nextBoolean() ? 1 : -1)));
|
|
sheep.setAI(true);
|
|
|
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
|
Location loc = sheep.getEyeLocation();
|
|
final Firework firework = (Firework) player.getWorld().spawnEntity(loc, EntityType.FIREWORK);
|
|
FireworkMeta meta = firework.getFireworkMeta();
|
|
FireworkEffect effect = FireworkEffect.builder().withColor(sheep.getColor().getColor()).with(FireworkEffect.Type.BALL).build();
|
|
meta.addEffect(effect);
|
|
firework.setFireworkMeta(meta);
|
|
|
|
Bukkit.getScheduler().runTaskLater(this, firework::detonate, 1L);
|
|
sheep.remove();
|
|
}, 20L);
|
|
}
|
|
}
|
|
}, 20L, 10L);
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
Config.write(PlotManager.getLastPlot().getOwner().toString());
|
|
Bukkit.getWorld("plots").getLivingEntities().forEach(Entity::remove);
|
|
}
|
|
} |