コード例 #1
0
ファイル: UserMap.java プロジェクト: jawfy/PluginDevelopment
 public void trackUUID(final UUID uuid, final String name, boolean replace) {
   if (uuid != null) {
     keys.add(uuid);
     if (name != null && name.length() > 0) {
       final String keyName = StringUtil.safeString(name);
       if (!names.containsKey(keyName)) {
         names.put(keyName, uuid);
         uuidMap.writeUUIDMap();
       } else if (!names.get(keyName).equals(uuid)) {
         if (replace) {
           ess.getLogger()
               .info(
                   "Found new UUID for "
                       + name
                       + ". Replacing "
                       + names.get(keyName).toString()
                       + " with "
                       + uuid.toString());
           names.put(keyName, uuid);
           uuidMap.writeUUIDMap();
         } else {
           if (ess.getSettings().isDebug()) {
             ess.getLogger()
                 .info(
                     "Found old UUID for "
                         + name
                         + " ("
                         + uuid.toString()
                         + "). Not adding to usermap.");
           }
         }
       }
     }
   }
 }
コード例 #2
0
ファイル: Backup.java プロジェクト: EderHD/Essentials
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}

		final ISettings settings = ess.getSettings();

		final net.ess3.settings.Backup backupSettings = settings.getData().getGeneral().getBackup();

		String backupCommand = backupSettings.getCommand() == null || backupSettings.getCommand().isEmpty() ? ("NORUN") : backupSettings.getCommand();
		
		/*if (backupCommand.equals("NORUN")) { TODO: Un-comment if you do not want commands to be run if there is no backup command
			return;
		}*/

		ess.getLogger().log(Level.INFO, _("backupStarted"));

		if (!backupSettings.getCommandsBeforeBackup().isEmpty())
		{
			final CommandSender consoleSender = server.getConsoleSender();
			for (String command : backupSettings.getCommandsBeforeBackup())
			{
				server.dispatchCommand(consoleSender, command);
			}
		}

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(backupCommand));
	}
コード例 #3
0
ファイル: UserMap.java プロジェクト: jawfy/PluginDevelopment
 public void removeUser(final String name) {
   if (names == null) {
     ess.getLogger().warning("Name collection is null, cannot remove user.");
     return;
   }
   UUID uuid = names.get(name);
   if (uuid != null) {
     keys.remove(uuid);
     users.invalidate(uuid);
   }
   names.remove(name);
   names.remove(StringUtil.safeString(name));
 }
コード例 #4
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPluginDisable(final PluginDisableEvent event) {
   if (event.getPlugin().getName().equals("EssentialsChat")) {
     ess.getSettings().setEssentialsChatActive(false);
   }
   ess.getAlternativeCommandsHandler().removePlugin(event.getPlugin());
   // Check to see if the plugin thats being disabled is the one we are using
   if (ess.getPaymentMethod() != null
       && Methods.hasMethod()
       && Methods.checkDisabled(event.getPlugin())) {
     Methods.reset();
     ess.getLogger().log(Level.INFO, "Payment method was disabled. No longer accepting payments.");
   }
 }
コード例 #5
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPluginEnable(final PluginEnableEvent event) {
   if (event.getPlugin().getName().equals("EssentialsChat")) {
     ess.getSettings().setEssentialsChatActive(true);
   }
   ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
   ess.getPermissionsHandler().checkPermissions();
   ess.getAlternativeCommandsHandler().addPlugin(event.getPlugin());
   if (!Methods.hasMethod() && Methods.setMethod(ess.getServer().getPluginManager())) {
     ess.getLogger()
         .log(
             Level.INFO,
             "Payment method found ("
                 + Methods.getMethod().getLongName()
                 + " version: "
                 + ess.getPaymentMethod().getMethod().getVersion()
                 + ")");
   }
 }
コード例 #6
0
ファイル: UserMap.java プロジェクト: jawfy/PluginDevelopment
  public User getUser(final String name) {
    try {
      final String sanitizedName = StringUtil.safeString(name);
      if (names.containsKey(sanitizedName)) {
        final UUID uuid = names.get(sanitizedName);
        return getUser(uuid);
      }

      final File userFile = getUserFileFromString(sanitizedName);
      if (userFile.exists()) {
        ess.getLogger().info("Importing user " + name + " to usermap.");
        User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
        trackUUID(user.getBase().getUniqueId(), user.getName(), true);
        return user;
      }
      return null;
    } catch (UncheckedExecutionException ex) {
      return null;
    }
  }
コード例 #7
0
ファイル: Backup.java プロジェクト: riki652/Essentials
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}
		@Cleanup
		final ISettings settings = ess.getSettings();
		settings.acquireReadLock();
		final String command = settings.getData().getGeneral().getBackup().getCommand();
		if (command == null || command.isEmpty())
		{
			return;
		}
		ess.getLogger().log(Level.INFO, _("backupStarted"));
		final CommandSender consoleSender = server.getConsoleSender();
		server.dispatchCommand(consoleSender, "save-all");
		server.dispatchCommand(consoleSender, "save-off");

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(command));
	}
コード例 #8
0
	@EventHandler(priority = EventPriority.LOWEST)
	public void onPlayerChat(final AsyncPlayerChatEvent event) // TODO: Does this update work?
	{
		final IUser user = userMap.getUser(event.getPlayer());
		if (user.getData().isMuted())
		{
			event.setCancelled(true);
			user.sendMessage(_("§6You have been muted!"));
			ess.getLogger().info(_("{0} tried to speak, but is muted.", user.getName()));
		}
		final Iterator<Player> it = event.getRecipients().iterator();
		while (it.hasNext())
		{
			final IUser u = userMap.getUser(it.next());
			if (u.getData().getIgnore().contains(user.getName()))
			{
				it.remove();
			}
		}
		user.updateActivity(true);
		user.setDisplayNick();
	}
コード例 #9
0
 public List<String> getItems() throws Exception {
   if (kit == null) {
     throw new Exception(tl("kitNotFound"));
   }
   try {
     final List<String> itemList = new ArrayList<String>();
     final Object kitItems = kit.get("items");
     if (kitItems instanceof List) {
       for (Object item : (List) kitItems) {
         if (item instanceof String) {
           itemList.add(item.toString());
           continue;
         }
         throw new Exception("Invalid kit item: " + item.toString());
       }
       return itemList;
     }
     throw new Exception("Invalid item list");
   } catch (Exception e) {
     ess.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage());
     throw new Exception(tl("kitError2"), e);
   }
 }
コード例 #10
0
	public void delayedJoin(final Player player)
	{
		if (!player.isOnline())
		{
			return;
		}
		ess.getBackup().startTask();
		final IUser user = userMap.getUser(player);
		user.setDisplayNick();
		user.updateCompass();
		user.getData().setTimestamp(TimestampType.LOGIN, System.currentTimeMillis());
		user.updateActivity(false);

		if (!ess.getVanishedPlayers().isEmpty() && !Permissions.VANISH_SEE_OTHERS.isAuthorized(user))
		{
			for (String p : ess.getVanishedPlayers())
			{
				final Player toVanish = userMap.getUser(p).getPlayer();
				if (toVanish.isOnline())
				{
					user.setVanished(true);
				}
			}
		}

		if (Permissions.SLEEPINGIGNORED.isAuthorized(user))
		{
			ess.getPlugin().scheduleSyncDelayedTask(
					new Runnable()
					{
						@Override
						public void run()
						{
							user.getPlayer().setSleepingIgnored(true);
						}
					});
		}

		final Commands settings = ess.getSettings().getData().getCommands();

		if (!settings.isDisabled("motd") && Permissions.MOTD.isAuthorized(user))
		{
			try
			{
				final IText input = new TextInput(user, "motd", true, ess);
				final IText output = new KeywordReplacer(input, user, ess);
				final TextPager pager = new TextPager(output, true);
				pager.showPage("1", null, "motd", user);
			}
			catch (IOException ex)
			{
				if (ess.getSettings().isDebug())
				{
					ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);
				}
				else
				{
					ess.getLogger().log(Level.WARNING, ex.getMessage());
				}
			}
		}

		if (!settings.isDisabled("mail") && Permissions.MAIL.isAuthorized(user))
		{
			final List<String> mail = user.getMails();
			if (mail.isEmpty())
			{
				final String msg = _("§6You have no new mail.");
				if (!msg.isEmpty())
				{
					user.sendMessage(msg);
				}
			}
			else
			{
				user.sendMessage(_("§6You have§c {0} §6messages! Type §c/mail read§6 to view your mail.", mail.size()));
			}
		}
		if (Permissions.FLY_SAFELOGIN.isAuthorized(user))
		{
			final Location loc = user.getPlayer().getLocation();
			final World world = loc.getWorld();
			final int x = loc.getBlockX();
			int y = loc.getBlockY();
			final int z = loc.getBlockZ();
			while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1)
			{
				y--;
			}

			if (loc.getBlockY() - y > 1 || y < 0)
			{
				user.getPlayer().setAllowFlight(true);
				user.getPlayer().setFlying(true);
				user.sendMessage(_("§6Set fly mode§c {0} §6for {1}§6.", _("enabled"), user.getPlayer().getDisplayName()));
			}
		}
	}
コード例 #11
0
  public void expandItems(final User user, final List<String> items) throws Exception {
    try {
      IText input = new SimpleTextInput(items);
      IText output = new KeywordReplacer(input, user.getSource(), ess);

      boolean spew = false;
      final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
      for (String kitItem : output.getLines()) {
        if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) {
          BigDecimal value =
              new BigDecimal(
                  kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
          Trade t = new Trade(value, ess);
          t.pay(user, OverflowType.DROP);
          continue;
        }

        if (kitItem.startsWith("/")) {
          String command = kitItem.substring(1);
          String name = user.getName();
          command = command.replace("{player}", name);
          Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
          continue;
        }

        final String[] parts = kitItem.split(" +");
        final ItemStack parseStack =
            ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

        if (parseStack.getType() == Material.AIR) {
          continue;
        }

        final MetaItemStack metaStack = new MetaItemStack(parseStack);

        if (parts.length > 2) {
          // We pass a null sender here because kits should not do perm checks
          metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
        }

        final Map<Integer, ItemStack> overfilled;
        final boolean allowOversizedStacks = user.isAuthorized("essentials.oversizedstacks");
        if (allowOversizedStacks) {
          overfilled =
              InventoryWorkaround.addOversizedItems(
                  user.getBase().getInventory(),
                  ess.getSettings().getOversizedStackSize(),
                  metaStack.getItemStack());
        } else {
          overfilled =
              InventoryWorkaround.addItems(user.getBase().getInventory(), metaStack.getItemStack());
        }
        for (ItemStack itemStack : overfilled.values()) {
          int spillAmount = itemStack.getAmount();
          if (!allowOversizedStacks) {
            itemStack.setAmount(
                spillAmount < itemStack.getMaxStackSize()
                    ? spillAmount
                    : itemStack.getMaxStackSize());
          }
          while (spillAmount > 0) {
            user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
            spillAmount -= itemStack.getAmount();
          }
          spew = true;
        }
      }
      user.getBase().updateInventory();
      if (spew) {
        user.sendMessage(tl("kitInvFull"));
      }
    } catch (Exception e) {
      user.getBase().updateInventory();
      ess.getLogger().log(Level.WARNING, e.getMessage());
      throw new Exception(tl("kitError2"), e);
    }
  }