Пример #1
0
	public void neutral(CommandSender sender, Command cmd, String label, String[] args){
		if(!(sender instanceof Player)){
			sender.sendMessage("Musisz byc na serwerze!");
			return;
		}
		if(args.length !=2){
			sender.sendMessage("Correct usage: /g neutral <tag>");
			return;
		}
		Player p = (Player) sender;
		User u = User.get(p);
		if(!u.hasGuild()){
			p.sendMessage("Nie jestes w zadnej gildii!");
			return;
		}
		if(!u.isAdmin()){
			p.sendMessage("Musisz byc adminem gildii aby to zrobic!");
			return;
		}
		if(!GuildUtils.tagExists(args[1])){
			p.sendMessage("Nie ma takiej gildii!");
			return;
		}
		Guild g = Guild.get(args[1]);
		if(g.equals(u.getGuild())){
			p.sendMessage("Podaj gildie inna niz twoja!");
			return;
		}
		if(u.getGuild().getAllies().contains(g)){
			u.getGuild().removeAlly(g);
			g.removeAlly(u.getGuild());
			Bukkit.broadcastMessage("�ildia � + u.getGuild().getTag() + " �erwala sojusz z gildia � + g.getTag());
			return;
		}
		if(u.getGuild().getEnemies().contains(g)){
			if(u.getGuild().getNeutralInvs().contains(g)){
				u.getGuild().removeNeutralInv(g);
				u.getGuild().removeEnemy(g);
				g.removeEnemy(u.getGuild());
				Bukkit.broadcastMessage("�ildia � + u.getGuild().getTag() + " �akonczyla wojne z gildia � + g.getTag());
				return;
			}
			if(g.getNeutralInvs().contains(u.getGuild())){
				p.sendMessage("Juz poprosiles te gildie o neutralnosc!");
				return;
			}
			g.addNeutralInv(u.getGuild());
			p.sendMessage("�oprosiles gildie � + g.getTag() + "� neutralnosc!");
			for(User m : g.getMembers()){
				if(m.isOnline()) m.getPlayer().sendMessage("�ildia � + u.getGuild().getTag() + " �rosi o neutralnosc!");
			}
			return;
		}
		p.sendMessage("Wasze gildie sa juz neutralne wzgledem siebie!");
	}
 @EventHandler
 public void onAttack(EntityDamageByEntityEvent e) {
   if (!(e.getEntity() instanceof Player)) return;
   User attacked = User.get((Player) e.getEntity());
   User attacker = null;
   if (e.getDamager() instanceof Player) attacker = User.get((Player) e.getDamager());
   if (e.getDamager() instanceof Projectile) {
     ProjectileSource ps = ((Projectile) e.getDamager()).getShooter();
     if (ps instanceof Player) attacker = User.get((Player) ps);
   }
   if (attacker == null) return;
   if (!attacked.hasGuild() || !attacker.hasGuild()) return;
   if (attacker.getGuild().equals(attacked.getGuild())) {
     e.setCancelled(true);
     return;
   }
   if (attacker.getGuild().getAllies().contains(attacked.getGuild())) {
     e.setCancelled(true);
     return;
   }
 }