- Баллы
- 153
Здравствуйте, уважаемые форумчане! Пытался написать свой плагин. Но консоль выдает ошибку unsupported major.minor version 51.0. Слышал что это связанно с версией java, поставил 7-ку, все тоже самое... Код плагина:
Код:
package ru.BeLkA.police;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
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.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Core extends JavaPlugin implements Listener {
private String Prefix = ChatColor.YELLOW + "[ПОЛИЦИЯ] ";
private String SendToPolice = ChatColor.GREEN + "Ваш вызов полиции отправлен.";
private String NotOnline1 = "Сейчас не Он-Лайн";
private int TimeBetweenMsg = 10;
private String Call = "Прием, ПОЛИЦИЯ! Вызов от игрока";
private String NoConsole = "Консоль идет лесом";
private String WaitForAnotherMsg = "Вы должны подождать, прежде чем отправить вызов снова!";
private Map<String, Long> LastCommand = new HashMap();
public void onEnable() {
getLogger().info(" Плагин включен");
getServer().getPluginManager().registerEvents(this, this);
getCommand("police").setExecutor(this);
getCommand("pkill").setExecutor(this);
NewConfig();
ConfigRead();
}
public void NewConfig() {
File f = new File(getDataFolder(), "config.yml");
if (!f.exists()) {
YamlConfiguration config = new YamlConfiguration();
config.set("Time-Between-Messages", Integer.valueOf(this.TimeBetweenMsg));
config.set("Answer-From-Police", this.SendToPolice);
config.set("Not-Online-When-Kill", this.NotOnline1);
config.set("No-Console-Message", this.NoConsole);
config.set("Call-To-Police-Message", this.Call);
config.set("Wait-For-Another-Call", this.WaitForAnotherMsg);
try
{
config.save(f);
} catch (IOException ex) {
System.out.println(ex.toString());
}
}
}
public void ConfigRead() {
File f = new File(getDataFolder(), "config.yml");
FileConfiguration config = new YamlConfiguration();
try {
config.load(f);
} catch (IOException|InvalidConfigurationException e) {
System.out.println(e.toString());
}
}
public boolean onCommand(CommandSender sender,Command cmd,String cmdlabel,String[] args){
Player p = null;
if(cmd.getName().equalsIgnoreCase("police"))
if (!(sender instanceof Player))
p = (Player)sender;
if(p.hasPermission("police.send")) {
p.sendMessage(Prefix + this.getConfig().getString("Answer-From-Police"));
Player[] pa = this.getServer().getOnlinePlayers();
for (Player pc : pa)
if (pc.hasPermission("police.recieve")) {
pc.sendMessage(Prefix + this.getConfig().getString("Call-To-Police-Message") + p.getName());
if ((sender instanceof Player)) {
sender.sendMessage(this.getConfig().getString("No-Console-Message"));
return true;
}
{
if(cmd.getName().equalsIgnoreCase("pkill")) {
Player target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(Prefix + args[0] + " " + this.getConfig().getString("Not-Online-When-Kill") + " ");
return true;
}
target.setHealth(0);
}
}
}
}
return false;
}
@EventHandler
public void onLogin(PlayerLoginEvent event) {
Player[] players = getServer().getOnlinePlayers();
for(Player player : players){
if(player.hasPermission("police.recieve")){
player.sendMessage(Prefix + ChatColor.WHITE + " Игрок " + ChatColor.DARK_RED + ChatColor.BOLD + event.getPlayer().getName() + ", IP Адрес -" + ChatColor.YELLOW + "[" + event.getPlayer().getAddress().getAddress().getHostAddress() + "]");
}
}
}
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
if ((this.getConfig().getInt("Time-Between-Messages") == 0));
long timeNow = new Date().getTime();
if (this.LastCommand.containsKey(event.getPlayer().getName()))
{
long diff = timeNow - ((Long)this.LastCommand.get(event.getPlayer().getName())).longValue();
if (diff < this.getConfig().getInt("Time-Between-Messages") * 1000)
{
event.getPlayer().sendMessage(Prefix + ChatColor.RED + this.getConfig().getString("Wait-For-Another-Call"));
event.setCancelled(true);
return;
}
}
}
}