Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package iwcs.pony;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.*;
- import org.bukkit.event.entity.*;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import iwcs.pony.Database;
- import iwcs.pony.Util;
- /* Errorlist:
- * 0 - onEnable() > Unable to load config
- */
- public class Main extends JavaPlugin implements Listener {
- private Database Database = new Database();
- private Util Util = new Util();
- //Variables
- private double random = 0; //A variable for random numbers
- private File configFile = new File(getDataFolder(), "config.yml"); //File for config
- public File databaseFile = new File(getDataFolder(), "database.yml"); //File for database
- public int permissionPlugin = 0; //Type of permission plugin in charge
- public Logger console = getLogger(); //Console (to use instead of getLogger())
- public FileConfiguration config = getConfig(); //Config file
- public FileConfiguration database = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "database.yml")); //Database
- //String[]'s
- public String[] helpForPony = {
- ChatColor.GRAY + "Not ready =\\"
- };
- public String[] helpForPlgn = {};
- public String[] helpForCast = {};
- @Override
- public void onEnable() {
- Bukkit.getPluginManager().registerEvents(this, this);
- if (configFile.exists()) {
- try {
- config.load(configFile);
- } catch (IOException | InvalidConfigurationException e) {
- Util.throwException(e, 0); //* * * ERROR 0 * * *
- }
- } else {
- this.saveDefaultConfig();
- }
- if (databaseFile.exists()) {
- try {
- database.load(databaseFile);
- } catch (IOException | InvalidConfigurationException e) {
- Util.throwException(e, 0); //* * * ERROR 4 * * * (a)
- }
- } else {
- try {
- database.loadFromString("");
- database.save(databaseFile);
- } catch (InvalidConfigurationException | IOException e) {
- Util.throwException(e, 0); //* * * ERROR 4 * * * (b)
- }
- }
- if (Bukkit.getPluginManager().getPlugin("PermissionsEx") != null) {
- permissionPlugin = 1;
- getLogger().info("Your PermissionsEx doesn't like ponies! I swear it!");
- } else if (Bukkit.getPluginManager().getPlugin("PermissionsBukkit") != null) {
- getLogger().info("This PermissionsBukkit is a ponyhater. Info 100%.");
- permissionPlugin = 2;
- } else {
- getLogger().warning("I don't see a pemission plugin... Anarchy?");
- permissionPlugin = 3;
- }
- }
- @Override
- public void onLoad() {
- random = Math.random();
- if (random < 0.33) {
- console.info("org.pinkiePie.party(new Server getServer());");
- } else if (random < 0.66) {
- console.info("Twilight asks permission to enter the server...");
- } else {
- console.info("Rainbow Dash thinks your server is now 20% cooler");
- }
- }
- //Command processing
- private void commandPony(CommandSender sender, String[] args) {
- if (args.length < 1) {
- Util.help(0, sender);
- } else {
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- switch (args[0].toLowerCase()) {
- case "earth":
- if (Util.hasPerm(pony, "pony.earth", true)) {
- Database.setRace(pony, "earth");
- Database.save();
- pony.sendMessage(config.getString("msgEarthSet", ChatColor.GOLD + "You are an earth pony now!"));
- } else {
- Util.noPerm(pony);
- }
- break;
- case "pegasus":
- if (Util.hasPerm(pony, "pony.pegasus", true)) {
- Database.setRace(pony, "pegasus");
- Database.save();
- pony.sendMessage(config.getString("msgPegasusSet", ChatColor.GOLD + "You are a pegasus now!"));
- } else {
- Util.noPerm(pony);
- }
- break;
- case "unicorn":
- if (Util.hasPerm(pony, "pony.unicorn", true)) {
- Database.setRace(pony, "unicorn");
- Database.save();
- pony.sendMessage(config.getString("msgUnicornSet", ChatColor.GOLD + "You are a unicorn now!"));
- } else {
- Util.noPerm(pony);
- }
- break;
- case "alicorn":
- if (Util.hasPerm(pony, "pony.alicorn", false)) {
- Database.setRace(pony, "alicorn");
- Database.save();
- pony.sendMessage(config.getString("msgAlicornSet", ChatColor.GOLD + "You are an alicorn now!"));
- } else {
- Util.noPerm(pony);
- }
- break;
- case "human":
- if (Util.hasPerm(pony, "pony.human", false)) {
- Database.setRace(pony, "human");
- Database.save();
- pony.sendMessage(config.getString("msgHumanSet", ChatColor.GOLD + "You are a human now!"));
- } else {
- Util.noPerm(pony);
- }
- break;
- case "current":
- if (Util.hasPerm(pony, "pony.current", true)) {
- switch (Database.getRace(pony)) {
- case "earth":
- pony.sendMessage(config.getString("msgEarthCurrMe", ChatColor.GOLD + "You are an earth pony"));
- break;
- case "pegasus":
- pony.sendMessage(config.getString("msgPegasusCurrMe", ChatColor.GOLD + "You are a pegasus"));
- break;
- case "unicorn":
- pony.sendMessage(config.getString("msgUnicornCurrMe", ChatColor.GOLD + "You are a uncorn"));
- break;
- case "alicorn":
- pony.sendMessage(config.getString("msgAlicornCurrMe", ChatColor.GOLD + "You are an alicorn"));
- break;
- case "human":
- pony.sendMessage(config.getString("msgHumanCurrMe", ChatColor.GOLD + "You are a human"));
- break;
- default:
- pony.sendMessage(config.getString("msgUnknownCurrMe", ChatColor.RED + "Wait, who are you?.. You better tell admins 'bout this"));
- Util.throwException(null, 10); //* * * ERROR 10 * * *
- }
- } else {
- Util.noPerm(pony);
- }
- break;
- case "default":
- if (Util.hasPerm(pony, "pony.default", true)) {
- Database.setDefault(pony);
- }
- break;
- default:
- pony.sendMessage(config.getString("msgUnknownArgPony", ChatColor.GRAY + "Argument was not recognized; run " + ChatColor.GOLD + "/pony help" + ChatColor.GRAY + " for help"));
- }
- } else {
- getLogger().info("This command can only be performed by a player, use /ponyplgn instead");
- }
- }
- }
- private void commandPlgn(CommandSender sender, String[] args) {
- //get|set|reset|gerror|getraw|setraw|totalreset|getconfig|savedata
- switch (args[0].toLowerCase()) {
- case "get":
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- if (Util.hasPerm(pony, "pony.current.others", false)) {
- if (args.length > 2) {
- switch (database.getString(args[1])) {
- case "earth":
- pony.sendMessage(config.getString("msgEarthCurrOth", ChatColor.GOLD + "That's an earth pony"));
- break;
- case "pegasus":
- pony.sendMessage(config.getString("msgPegasusCurrOth", ChatColor.GOLD + "That's a pegasus"));
- break;
- case "unicorn":
- pony.sendMessage(config.getString("msgUnicornCurrOth", ChatColor.GOLD + "That's a unicorn"));
- break;
- case "alicorn":
- pony.sendMessage(config.getString("msgAlicornCurrOth", ChatColor.GOLD + "That's an alicorn"));
- break;
- case "human":
- pony.sendMessage(config.getString("msgHumanCurrOth", ChatColor.GOLD + "That's a human"));
- break;
- default:
- pony.sendMessage(config.getString("msgUnknownCurrOth", ChatColor.RED + "Erm... I HAVE NO IDEA! >:D"));
- Util.throwException(null, 11); //* * * ERROR 11 * * *
- }
- } else {
- pony.sendMessage(ChatColor.RED + "Usage: /ponyplgn get <nickname>");
- }
- } else {
- Util.noPerm(pony);
- }
- } else {
- if (args.length > 2) {
- switch (database.getString(args[1])) {
- case "earth":
- console.info(args[1] + " is an earth pony");
- break;
- case "pegasus":
- console.info(args[1] + " is a pegasus");
- break;
- case "unicorn":
- console.info(args[1] + " is a unicorn");
- break;
- case "alicorn":
- console.info(args[1] + " is an alicorn");
- break;
- case "human":
- console.info(args[1] + " is a human");
- break;
- default:
- console.info(args[1] + " is not in the database");
- Util.throwException(null, 11); //* * * ERROR 11 * * *
- }
- } else {
- console.info("Usage: /ponyplgn get <nickname>");
- }
- }
- break;
- case "set":
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- if (Util.hasPerm(pony, "pony.set", false)) {
- if (args.length > 3) {
- String r = args[2].toLowerCase();
- if (r == "earth" || r == "pegasus" || r == "unicorn" || r == "alicorn" || r == "human") {
- Database.setRace(getServer().getOfflinePlayer(args[1]).getPlayer(), r);
- pony.sendMessage(ChatColor.GOLD + args[1] + "'s race set to " + r);
- } else
- sender.sendMessage(new String[] {ChatColor.RED + "Unknown race type.", ChatColor.GRAY + "Avaliable types: earth, pegasus, unicorn, alicorn, human"});
- } else {
- sender.sendMessage(ChatColor.RED + "Usage: /ponyplgn set <nickname> <newRace>");
- }
- } else {
- Util.noPerm(pony);
- }
- } else {
- if (args.length > 3) {
- String r = args[2].toLowerCase();
- if (r == "earth" || r == "pegasus" || r == "unicorn" || r == "alicorn" || r == "human") {
- Database.setRace(getServer().getOfflinePlayer(args[1]).getPlayer(), r);
- console.info(args[1] + "'s race set to " + r);
- } else
- console.info("Unknown race type. Avaliable types: earth, pegasus, unicorn, alicorn, human");
- } else {
- console.info("Usage: /ponyplgn set <nickname> <newRace>");
- }
- }
- break;
- case "reset":
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- if (Util.hasPerm(pony, "pony.reset", false)) {
- if (args.length > 2) {
- Database.setDefault(getServer().getOfflinePlayer(args[1]).getPlayer());
- pony.sendMessage(ChatColor.GOLD + args[1] + "'s race reset to default");
- } else {
- pony.sendMessage(ChatColor.RED + "Usage: /ponyplgn reset <nickname>");
- }
- } else {
- Util.noPerm(pony);
- }
- } else {
- if (args.length > 2) {
- Database.setDefault(getServer().getOfflinePlayer(args[1]).getPlayer());
- console.info(args[1] + "'s race reset to default");
- } else {
- console.info("Usage: /ponyplgn reset <nickname>");
- }
- }
- break;
- case "gerror":
- if (sender instanceof Player) {
- if (args.length > 2) {
- try {
- sender.sendMessage(Util.gerror(new Integer(args[1])));
- } catch (NumberFormatException e) {
- sender.sendMessage(ChatColor.RED + args[1] + " is not numeric");
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Usage: /ponyplgn gerror <errorNumber>");
- }
- } else {
- if (args.length > 2) {
- try {
- console.info(Util.gerror(new Integer(args[1])));
- } catch (NumberFormatException e) {
- console.info(args[1] + " is not numeric");
- }
- } else {
- console.info("Usage: /ponyplgn gerror <errorNumber>");
- }
- }
- break;
- case "getraw":
- if (sender instanceof Player) {
- if (Util.hasPerm((Player) sender, "pony.current.raw", false)) {
- if (args.length < 2) {
- if (database.contains(args[1])) {
- sender.sendMessage(ChatColor.GOLD + args[1] + ": " + database.getString(args[1]));
- } else {
- sender.sendMessage(ChatColor.GOLD + args[1] + " is not in the database");
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Usage: /ponyplgn getraw <nickname>");
- }
- } else {
- Util.noPerm((Player) sender);
- }
- } else {
- if (args.length < 2) {
- if (database.contains(args[1])) {
- console.info(args[1] + ": " + database.getString(args[1]));
- } else {
- console.info(args[1] + " is not in the database");
- }
- } else {
- console.info("Usage: /ponyplgn getraw <nickname>");
- }
- }
- case "setraw":
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- if (Util.hasPerm(pony, "pony.set.raw", false)) {
- if (args.length > 3) {
- database.set(args[1], args[2]);
- pony.sendMessage(ChatColor.GOLD + args[1] + "'s race set to " + args[2]);
- } else {
- pony.sendMessage(ChatColor.RED + "Usage: /ponyplgn setraw <nickname> <newRace>");
- }
- } else {
- Util.noPerm(pony);
- }
- } else {
- if (args.length > 3) {
- database.set(args[1], args[2]);
- console.info(ChatColor.GOLD + args[1] + "'s race set to " + args[2]);
- } else {
- console.info(ChatColor.RED + "Usage: /ponyplgn setraw <nickname> <newRace>");
- }
- }
- break;
- case "totalreset":
- if (sender instanceof Player) {
- if (Util.hasPerm((Player) sender, "pony.reset.all", false)) {
- try {
- FileConfiguration database2 = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "database_old.yml"));
- database2.loadFromString(database.saveToString());
- database2.save(new File(getDataFolder(), "database_old.yml"));
- database.loadFromString("");
- database.save(databaseFile);
- sender.sendMessage(ChatColor.GOLD + "Database cleaned." + ChatColor.GRAY + "Copy saved to database_old.yml");
- } catch (InvalidConfigurationException | IOException e) {
- Util.throwException(e, 0); //* * * ERROR 4 * * * (c)
- sender.sendMessage(ChatColor.GOLD + "Caught some exception, see console for details");
- }
- } else {
- Util.noPerm((Player) sender);
- }
- } else {
- try {
- FileConfiguration database2 = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "database_old.yml"));
- database2.loadFromString(database.saveToString());
- database2.save(new File(getDataFolder(), "database_old.yml"));
- database.loadFromString("");
- database.save(databaseFile);
- console.info(ChatColor.GOLD + "Database cleaned." + ChatColor.GRAY + "Copy saved to database_old.yml");
- } catch (InvalidConfigurationException | IOException e) {
- Util.throwException(e, 0); //* * * ERROR 4 * * * (c)
- }
- }
- case "savedata":
- if (sender instanceof Player) {
- if (Util.hasPerm((Player) sender, "pony.save", false)) {
- Database.save();
- sender.sendMessage(ChatColor.GOLD + "Database saved");
- } else {
- Util.noPerm((Player) sender);
- }
- } else {
- Database.save();
- console.info(ChatColor.GOLD + "Database saved");
- }
- case "reload":
- if (sender instanceof Player) {
- if (Util.hasPerm((Player) sender, "pony.reload", false)) {
- Database.save();
- sender.sendMessage(ChatColor.GOLD + "Database saved");
- onEnable();
- sender.sendMessage(ChatColor.GOLD + "Database & config reloaded");
- } else {
- Util.noPerm((Player) sender);
- }
- } else {
- Database.save();
- console.info(ChatColor.GOLD + "Database saved");
- onEnable();
- console.info(ChatColor.GOLD + "Database & config reloaded");
- }
- default:
- }
- }
- private void commandCast(CommandSender sender, String[] args) {
- if (sender instanceof Player) {
- Player pony = (Player) sender;
- if (Util.hasPerm(pony, "pony.cast", true /*, of course true!*/)) {
- if (Database.getRace(pony) == "unicorn" || Database.getRace(pony) == "alicorn") {
- switch (args[0].toLowerCase()) {
- case "hjump":
- pony.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 0));
- pony.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1200, 0));
- break;
- case "regen":
- pony.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 300, 0));
- pony.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 600, 1));
- break;
- case "haste":
- pony.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1200, 0));
- pony.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1200, 0));
- break;
- case "nregen":
- if (pony.getFoodLevel() > 6) {
- pony.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0));
- pony.setFoodLevel(pony.getFoodLevel() - 6);
- } else {
- pony.setFoodLevel(0);
- }
- case "clear":
- for (int i = 0; i < pony.getActivePotionEffects().toArray().length; i++) {
- pony.removePotionEffect((PotionEffectType) pony.getActivePotionEffects().toArray()[i]);
- }
- pony.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0));
- }
- } else {
- pony.sendMessage(config.getString("msgCastWrongRace", ChatColor.GOLD + "Sorry, your magical skills are too bad to cast spells!"));
- }
- }
- } else {
- getLogger().info("This command can only be performed by a player, use /ponyplgn instead");
- }
- }
- @EventHandler
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- switch (command.getName()) {
- case "pony":
- commandPony(sender, args);
- break;
- case "ponyplgn":
- commandPlgn(sender, args);
- break;
- case "cast":
- commandCast(sender, args);
- }
- return true;
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent event) {
- Database.checkRace(event.getPlayer());
- }
- @EventHandler
- public void onRespawn(PlayerRespawnEvent event) {
- Database.checkRace(event.getPlayer());
- }
- @EventHandler
- public void onGamemodeChange(PlayerGameModeChangeEvent event) {
- Database.pegasusCheck(event.getPlayer());
- }
- @EventHandler
- public void onFoodLevelChange(FoodLevelChangeEvent event) {
- Database.pegasusCheck((Player) event.getEntity());
- }
- @EventHandler
- public void onAttack(EntityDamageByEntityEvent event) {
- if (event.getDamager() instanceof Player) {
- if (Database.getRace((Player) event.getDamager()) == "unicorn" && !(((Player) event.getDamager()).getGameMode() == GameMode.valueOf("CREATIVE"))) {
- if (event.getDamage() - 4.0 < 0) {
- event.setCancelled(true);
- } else {
- event.setDamage(event.getDamage() - 4.0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement