Java Code Examples for org.bukkit.plugin.Plugin#getServer()

The following examples show how to use org.bukkit.plugin.Plugin#getServer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleManager.java    From ExploitFixer with GNU General Public License v3.0 5 votes vote down vote up
public ModuleManager(final Plugin plugin, final Configuration configYml, final Configuration messagesYml) {
	this.plugin = plugin;
	this.commandsModule = new CommandsModule(configYml);
	this.connectionModule = new ConnectionModule(configYml);
	this.customPayloadModule = new CustomPayloadModule(plugin, this, configYml);
	this.itemsFixModule = new ItemsFixModule(plugin, configYml);
	this.messagesModule = new MessagesModule(plugin.getDescription().getVersion(), messagesYml);
	this.notificationsModule = new NotificationsModule(plugin.getServer().getConsoleSender(), configYml);
	this.packetsModule = new PacketsModule(plugin, this, configYml);
	this.exploitPlayerManager = new ExploitPlayerManager(plugin, plugin.getServer(), this);
}
 
Example 2
Source File: Dispatcher.java    From Chimera with MIT License 5 votes vote down vote up
public static Dispatcher of(Plugin plugin) {
    var prefix = plugin.getName().toLowerCase();
    var server = ((CraftServer) plugin.getServer());
    
    var map = new SpigotMap(prefix, plugin, (CraftCommandMap) server.getCommandMap());
    var root = new Root(prefix, map);
    var dispatcher = new Dispatcher(server, root);
    map.dispatcher = dispatcher;
    
    server.getPluginManager().registerEvents(dispatcher, plugin);
    
    return dispatcher;
}
 
Example 3
Source File: SpringSpigotAutoConfiguration.java    From mcspring-boot with MIT License 4 votes vote down vote up
@Bean(destroyMethod = "")
Server serverBean(Plugin plugin) {
    return plugin.getServer();
}
 
Example 4
Source File: ExploitPlayer.java    From ExploitFixer with GNU General Public License v3.0 4 votes vote down vote up
public void addVls(final Plugin plugin, final Cancellable event, final PacketWrapper packet,
		final HamsterPlayer hamsterPlayer, final ViolationModule module, final double amount) {
	final Player player = hamsterPlayer.getPlayer();
	final Violations violations = (Violations) module.getViolations();

	if (violations != null) {
		final Server server = plugin.getServer();
		final double currentTime = System.currentTimeMillis();

		if (currentTime - lastViolation >= 1000) {
			lastViolation = currentTime;

			for (final ViolationModule violationModule : new HashSet<>(this.violations.keySet())) {
				final double vls = this.violations.get(violationModule) - violationModule.getReduceVls();

				if (vls <= 0) {
					this.violations.remove(violationModule);
				} else {
					this.violations.put(violationModule, vls);
				}
			}
		}

		final double newVls = getViolations(module) + amount;

		this.violations.put(module, newVls);

		if (event instanceof Cancellable && module.getCancelVls() <= newVls) {
			((Cancellable) event).setCancelled(true);
		}

		for (final int threshold : violations.getViolations()) {
			if (threshold <= newVls) {
				final Collection<String> commands = violations.getCommands(threshold);

				if (commands != null && !commands.isEmpty() && !punishments.contains(commands)) {
					for (final String punishCommand : commands) {
						if (punishCommand.equals("kick")) {
							final String locale = VersionUtil.getLocale(player);
							final String kickMessage = messagesModule.getKickMessage(module, locale);

							hamsterPlayer.disconnect(kickMessage);
							hamsterPlayer.closeChannel();
							exploitPlayerManager.addPunishment();
						} else if (punishCommand.equals("notification")) {
							final String moduleName = module.getName();

							if (packet != null) {
								final PacketType packetType = packet.getType();
								final String name;

								if (packetType != null) {
									name = packetType.toString();
								} else {
									name = moduleName;
								}

								notificationsModule.sendNotification(name, player, (int) newVls);
							} else {
								notificationsModule.sendNotification(moduleName, player, (int) newVls);
							}
						} else {
							server.getScheduler().runTask(plugin, () -> {
								server.dispatchCommand(server.getConsoleSender(),
										punishCommand.replace("%player%", player.getName()));
							});
						}
					}

					punishments.add(commands);
				}
			}
		}
	}
}