Java Code Examples for org.bukkit.plugin.Plugin

The following are top voted examples for showing how to use org.bukkit.plugin.Plugin. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NeverLag   File: MonitorUtils.java   View source code 7 votes vote down vote up
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
		try {
			FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
			EventExecutor executor = field.get(listener);
			if (executor instanceof EventExecutorInjector) {
				EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor;
				String eventName = eventExecutorInjector.getEventName();
				if (eventName != null) {
					MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(), eventExecutorInjector.getTotalCount(),
						eventExecutorInjector.getMaxExecuteTime());
					if (record.containsKey(eventName)) {
						MonitorRecord otherMonitorRecord = record.get(eventName);
						record.put(eventName, otherMonitorRecord.merge(monitorRecord));
					} else {
						record.put(eventName, monitorRecord);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return record;
}
 
Example 2
Project: HCFCore   File: LoggerEntityHuman.java   View source code 6 votes vote down vote up
@Override
public void postSpawn(HCF plugin) {
    if (this.world.addEntity((Entity)this)) {
        Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.GOLD + "Combat logger of " + this.getName() + " has spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ));
        MinecraftServer.getServer().getPlayerList().playerFileData.load((EntityHuman)this);
    } else {
        Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.RED + "Combat logger of " + this.getName() + " failed to spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ));
    }
    this.removalTask = new BukkitRunnable(){

        public void run() {
            MinecraftServer.getServer().getPlayerList().sendAll((Packet)PacketPlayOutPlayerInfo.removePlayer((EntityPlayer)LoggerEntityHuman.this.getBukkitEntity().getHandle()));
            LoggerEntityHuman.this.destroy();
        }
    }.runTaskLater((Plugin)plugin, SettingsYML.COMBAT_LOG_DESPAWN_TICKS);
}
 
Example 3
Project: HCFCore   File: PlayerBoard.java   View source code 6 votes vote down vote up
public void setTemporarySidebar(final SidebarProvider provider, final long expiration) {
    if (this.removed.get()) {
        throw new IllegalStateException("Cannot update whilst board is removed");
    }
    this.temporaryProvider = provider;
    this.updateObjective();
    new BukkitRunnable() {
        public void run() {
            if (PlayerBoard.this.removed.get()) {
                this.cancel();
                return;
            }
            if (PlayerBoard.this.temporaryProvider == provider) {
                PlayerBoard.access$4(PlayerBoard.this, null);
                PlayerBoard.this.updateObjective();
            }
        }
    }.runTaskLaterAsynchronously((Plugin)this.plugin, expiration);
}
 
Example 4
Project: GlobalPrefix   File: GlobalPrefix.java   View source code 6 votes vote down vote up
@Override
public void onEnable() {
    instance=this;
    new ConfigManager();
    new Database();
    new Cacher();
    new Commands();
    Plugin papi= Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
    if(papi==null){
        Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §c无法找到PlaceholderAPI插件,请检查是否安装");
    } else{
      if(!new PrefixPlaceholder().hook()){
          Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §c注册PlaceholderAPI变量失败!");
      }
    }
    new Metrics(instance);
    Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §a插件加载完成!");
}
 
Example 5
Project: BlockBall   File: PlayerMetaMySQLControllerTest.java   View source code 6 votes vote down vote up
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if(Bukkit.getServer() == null)
        Bukkit.setServer(server);
    new File("BlockBall/BlockBall.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("BlockBall"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
 
Example 6
Project: HCFCore   File: PlayerBoard.java   View source code 6 votes vote down vote up
public void setDefaultSidebar(final SidebarProvider provider, final long updateInterval) {
    if (provider != this.defaultProvider) {
        this.defaultProvider = provider;
        if (this.runnable != null) {
            this.runnable.cancel();
        }
        if (provider == null) {
            this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);
            return;
        }
        (this.runnable = new BukkitRunnable() {
            public void run() {
                if (PlayerBoard.this.removed.get()) {
                    this.cancel();
                    return;
                }
                if (provider == PlayerBoard.this.defaultProvider) {
                    PlayerBoard.this.updateObjective();
                }
            }
        }).runTaskTimerAsynchronously((Plugin)this.plugin, updateInterval, updateInterval);
    }
}
 
Example 7
Project: PetBlocks   File: ParticleEffectMetaMySQLControllerIT.java   View source code 6 votes vote down vote up
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
 
Example 8
Project: HCFCore   File: PlayerBoard.java   View source code 6 votes vote down vote up
public void setDefaultSidebar(final SidebarProvider provider, final long updateInterval) {
    if (provider != this.defaultProvider) {
        this.defaultProvider = provider;
        if (this.runnable != null) {
            this.runnable.cancel();
        }
        if (provider == null) {
            this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);
            return;
        }
        (this.runnable = new BukkitRunnable() {
            public void run() {
                if (PlayerBoard.this.removed.get()) {
                    this.cancel();
                    return;
                }
                if (provider == PlayerBoard.this.defaultProvider) {
                    PlayerBoard.this.updateObjective();
                }
            }
        }).runTaskTimerAsynchronously((Plugin)this.plugin, updateInterval, updateInterval);
    }
}
 
Example 9
Project: PetBlocks   File: PlayerMetaMySQLControllerIT.java   View source code 6 votes vote down vote up
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    if (Bukkit.getServer() == null) {
        final Server server = mock(Server.class);
        when(server.getLogger()).thenReturn(Logger.getGlobal());
        Bukkit.setServer(server);
    }
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
 
Example 10
Project: NeverLag   File: SchedulerTaskInjector.java   View source code 6 votes vote down vote up
public static void uninject(Plugin plg) {
	if (plg != null) {
		for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
			if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
				try {
					FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
					Runnable runnable = field.get(pendingTask);
					if (runnable instanceof SchedulerTaskInjector) {
						field.set(pendingTask, ((SchedulerTaskInjector) runnable).getRunnable());
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example 11
Project: Uranium   File: CraftCrashReport.java   View source code 6 votes vote down vote up
public Object call() throws Exception {
    StringWriter value = new StringWriter();
    try {
        value.append("\n   Running: ").append(Bukkit.getName()).append(" version ").append(Bukkit.getVersion()).append(" (Implementing API version ").append(Bukkit.getBukkitVersion()).append(") ").append(String.valueOf(net.minecraft.server.MinecraftServer.getServer().isServerInOnlineMode()));
        value.append("\n   Plugins: {");
        for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            PluginDescriptionFile description = plugin.getDescription();
            value.append(' ').append(description.getFullName()).append(' ').append(description.getMain()).append(' ').append(Arrays.toString(description.getAuthors().toArray())).append(',');
        }
        value.append("}\n   Warnings: ").append(Bukkit.getWarningState().name());
        value.append("\n   Threads: {");
        for (Map.Entry<Thread, ? extends Object[]> entry : Thread.getAllStackTraces().entrySet()) {
            value.append(' ').append(entry.getKey().getState().name()).append(' ').append(entry.getKey().getName()).append(": ").append(Arrays.toString(entry.getValue())).append(',');
        }
        value.append("}\n   ").append(Bukkit.getScheduler().toString());
    } catch (Throwable t) {
        value.append("\n   Failed to handle CraftCrashReport:\n");
        PrintWriter writer = new PrintWriter(value);
        t.printStackTrace(writer);
        writer.flush();
    }
    return value.toString();
}
 
Example 12
Project: UltimateSpawn   File: ConfigGGM.java   View source code 6 votes vote down vote up
public static void loadConfig(Plugin plugin) {
    pl = plugin;

    file = new File(pl.getDataFolder(), "Config/Global/OnJoin/Gamemode-OnJoin.yml");
    Config = YamlConfiguration.loadConfiguration(file);

    if (!pl.getDataFolder().exists()) {
        pl.getDataFolder().mkdir();
    }

    create();

    int gamemode = Config.getInt("On-Join.Spawn.Gamemode.Gamemode");

    if ((gamemode != 0) && (gamemode != 1) && (gamemode != 2) && (gamemode != 3)) {
        Config.set("Gamemode.Value", Integer.valueOf(0));
    }
}
 
Example 13
Project: uppercore   File: Parser.java   View source code 6 votes vote down vote up
static Parser<Double> doubleValue() {
    return new Parser<Double>() {
        @Override
        public Double load(Plugin plugin, Object object) {
            if (object instanceof Number)
                return ((Number) object).doubleValue();
            else if (object instanceof String)
                return Double.parseDouble((String) object);
            else
                throw new IllegalArgumentException("Cannot parse " + object + " as short");
        }

        @Override
        public Object save(Double s) {
            return s;
        }
    };
}
 
Example 14
Project: NavyCraft2-Lite   File: NavyCraft_Timer.java   View source code 6 votes vote down vote up
public NavyCraft_Timer(Plugin plug, int seconds, Craft vehicle, Player p, String state, boolean forward) {
	//toolkit = Toolkit.getDefaultToolkit();
	plugin = plug;
	this.craft = vehicle;
	this.player = p;
	timer = new Timer();
	if(state.equals("engineCheck"))
		timer.scheduleAtFixedRate(new EngineTask(), 1000, 1000);
	else if(state.equals("engineCheck"))
		timer.schedule(new AutoMoveTask(forward), 1000);
	else if(state.equals("abandonCheck"))
		timer.scheduleAtFixedRate(new ReleaseTask(), seconds * 1000, 60000);
	else if(state.equals("takeoverCheck"))
		timer.scheduleAtFixedRate(new TakeoverTask(), seconds * 1000, 60000);
	else if(state.equals("takeoverCaptainCheck"))
		timer.scheduleAtFixedRate(new TakeoverCaptainTask(), seconds * 1000, 60000);
}
 
Example 15
Project: uppercore   File: Parser.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
static Parser<List<Action>> actionsValue() {
    return new Parser<List<Action>>() {
        @Override
        public List<Action> load(Plugin plugin, Object object) {
            if (object instanceof Collection)
                return ActionType.deserialize(plugin, (Collection<Map<String, Object>>) object);
            else
                throw new IllegalArgumentException("Cannot parse " + object + " as short");
        }

        @Override
        public Object save(List<Action> s) {
            return ActionType.serialize(s);
        }
    };
}
 
Example 16
Project: SamaGamesCore   File: Permissible.java   View source code 5 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks)
{
    if (oldpermissible == null)
    {
        return super.addAttachment(plugin, name, value, ticks);
    }
    return oldpermissible.addAttachment(plugin, name, value, ticks);
}
 
Example 17
Project: UltimateTs   File: PermsManager.java   View source code 5 votes vote down vote up
public void setPermsSystem() {
	PluginManager pm = Bukkit.getServer().getPluginManager();
	for(Plugin pl : pm.getPlugins()){
		if(pl.isEnabled()){
			String plName = pl.getName();
			if(app.contains(plName)){
				permsPlugin = pm.getPlugin(plName);
			}
		}
	}
}
 
Example 18
Project: ProjectAres   File: BukkitPluginResolver.java   View source code 5 votes vote down vote up
@Override
public @Nullable <T extends Plugin> T getPlugin(Class<T> cls) {
    try {
        return (T) JavaPlugin.getPlugin(cls.asSubclass(JavaPlugin.class));
    } catch(IllegalArgumentException e) {
        return null;
    }
}
 
Example 19
Project: SamaGamesCore   File: Permissible.java   View source code 5 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin)
{
    if (oldpermissible == null)
    {
        return super.addAttachment(plugin);
    }
    return oldpermissible.addAttachment(plugin);
}
 
Example 20
Project: UltimateSpawn   File: ConfigFDoubleJump.java   View source code 5 votes vote down vote up
public static void loadConfig(Plugin plugin) {
    pl = plugin;

    file = new File(pl.getDataFolder(), "Config/Global/Fun/DoubleJump.yml");
    Config = YamlConfiguration.loadConfiguration(file);

    if (!pl.getDataFolder().exists()) {
        pl.getDataFolder().mkdir();
    }

    create();
}
 
Example 21
Project: VoxelGamesLibv2   File: LoggedScheduler.java   View source code 5 votes vote down vote up
@Override
public BukkitTask runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable bukkitRunnable, long l,
                                             long l1) throws IllegalArgumentException {
    TaskedRunnable wrapped = new TaskedRunnable(bukkitRunnable);

    BukkitTask bukkitTask = delegate.runTaskTimerAsynchronously(plugin, wrapped, l, l1);
    wrapped.setTaskID(bukkitTask.getTaskId());
    return bukkitTask;
}
 
Example 22
Project: McLink   File: LinkLoader.java   View source code 5 votes vote down vote up
public LinkLoader(Plugin plugin) {
	setPlugin(plugin);
	File[] files = plugin.getDataFolder().listFiles();
	for (File file : files) {
		if (file.getName().equalsIgnoreCase("mclink.yml"))
			setConfig(YamlConfiguration.loadConfiguration(file));
	}
}
 
Example 23
Project: UltimateSpawn   File: ConfigCSpawn.java   View source code 5 votes vote down vote up
public static void loadConfig(Plugin plugin) {
    pl = plugin;

    file = new File(pl.getDataFolder(), "Config/Command/Spawn.yml");
    Config = YamlConfiguration.loadConfiguration(file);

    if (!pl.getDataFolder().exists()) {
        pl.getDataFolder().mkdir();
    }

    create();
}
 
Example 24
Project: TruenoNPC   File: TruenoNPC_v1_11_r1.java   View source code 5 votes vote down vote up
private JsonObject getChacheFile(Plugin plugin){
    File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
    if(file.exists()){
        try{
            JsonParser parser = new JsonParser();
            JsonElement jsonElement = parser.parse(new FileReader(file));
            return jsonElement.getAsJsonObject();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }else return null;
}
 
Example 25
Project: HCFCore   File: HCF.java   View source code 5 votes vote down vote up
@Override
public void onEnable() {
    Cooldowns.createCooldown("medic_cooldown");

    HCF.plugin = this;
    BasePlugin.getPlugin().init(this);

    ProtocolLibHook.hook(this);

    Plugin wep = getServer().getPluginManager().getPlugin("WorldEdit");
    this.worldEdit = wep instanceof WorldEditPlugin && wep.isEnabled() ? (WorldEditPlugin) wep : null;
    CustomEntityRegistration.registerCustomEntities();
    
    this.craftBukkitVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];

    SettingsYML.init(this);
    this.effectRestorer = new EffectRestorer(this);
    this.registerConfiguration();
    this.registerCommands();
    this.registerManagers();
    this.registerListeners();
    
    this.setupPermissions();

    new BukkitRunnable() {
        @Override
        public void run() {
            getServer().broadcast(ChatColor.GREEN.toString() + ChatColor.BOLD + "Saving!" + "\n" + ChatColor.GREEN + "Saved all faction and player data to the database." + "\n" + ChatColor.GRAY + "Current TPS: " + ChatColor.GRAY, "hcf.seesaves");
            saveData();
        }
    }.runTaskTimerAsynchronously(plugin, TimeUnit.MINUTES.toMillis(10L), TimeUnit.MINUTES.toMillis(10L));
}
 
Example 26
Project: NeverLag   File: EventExecutorInjector.java   View source code 5 votes vote down vote up
public static void inject(Plugin plg) {
	if (plg != null) {
		for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
			try {
				FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
				EventExecutor fieldEventExecutor = field.get(listener);
				field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 27
Project: EscapeLag   File: MonitorUtils.java   View source code 5 votes vote down vote up
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	try {
		SimpleCommandMap simpleCommandMap = Reflection
				.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class)
				.get(Bukkit.getPluginManager());
		for (Command command : simpleCommandMap.getCommands()) {
			if (command instanceof PluginCommand) {
				PluginCommand pluginCommand = (PluginCommand) command;
				if (plg.equals(pluginCommand.getPlugin())) {
					FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class,
							"executor", CommandExecutor.class);
					CommandExecutor executor = commandField.get(pluginCommand);
					if (executor instanceof CommandInjector) {
						CommandInjector commandInjector = (CommandInjector) executor;
						record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
					}

				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return record;
}
 
Example 28
Project: uppercore   File: SpigotUpdateChecker.java   View source code 5 votes vote down vote up
public SpigotUpdateChecker(Plugin plugin, String spigotFullId) {
    super(plugin, spigotFullId);
    String[] parts = spigotFullId.split("\\.");
    try {
        resId = Integer.parseInt(parts[parts.length - 1]);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid id: " + spigotFullId);
    }
}
 
Example 29
Project: VoxelGamesLibv2   File: LoggedScheduler.java   View source code 5 votes vote down vote up
public int scheduleAsyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay,
                                      long period) {
    TaskedRunnable wrapped = new TaskedRunnable(task);

    wrapped.setTaskID(delegate.scheduleAsyncRepeatingTask(plugin, wrapped, delay, period));
    return wrapped.getTaskID();
}
 
Example 30
Project: Hub   File: Hub.java   View source code 5 votes vote down vote up
public EffectLib getEffectLib()
{
    Plugin effectLib = this.getServer().getPluginManager().getPlugin("EffectLib");

    if (effectLib == null || !(effectLib instanceof EffectLib))
        return null;

    return (EffectLib) effectLib;
}
 
Example 31
Project: MCLibrary   File: Plugins.java   View source code 5 votes vote down vote up
public static boolean isDepend(String superPluginName, Plugin checkPlugin) {
    PluginDescriptionFile desc = checkPlugin.getDescription();
    List<String> softDepend = desc.getSoftDepend();
    List<String> depend = desc.getDepend();
    return softDepend != null && softDepend.contains(superPluginName)
            || depend != null && depend.contains(superPluginName);
}
 
Example 32
Project: ProjectAres   File: PlayerListener.java   View source code 5 votes vote down vote up
@Inject PlayerListener(Plugin lobby, LobbyConfig config, MinecraftService minecraftService, OnlinePlayers onlinePlayers, Audiences audiences, BossBarFactory bossBarFactory, ComponentRenderContext renderer, EventBus eventBus, GeneralFormatter generalFormatter) {
    this.lobby = lobby;
    this.config = config;
    this.minecraftService = minecraftService;
    this.onlinePlayers = onlinePlayers;
    this.audiences = audiences;
    this.bossBarFactory = bossBarFactory;
    this.renderer = renderer;
    this.eventBus = eventBus;
    this.generalFormatter = generalFormatter;
}
 
Example 33
Project: UltimateSpawn   File: ConfigCPing.java   View source code 5 votes vote down vote up
public static void loadConfig(Plugin plugin) {
    pl = plugin;

    file = new File(pl.getDataFolder(), "Config/Command/Ping.yml");
    Config = YamlConfiguration.loadConfiguration(file);

    if (!pl.getDataFolder().exists()) {
        pl.getDataFolder().mkdir();
    }

    create();
}
 
Example 34
Project: TruenoNPC   File: TruenoNPC_v1_9_r2.java   View source code 5 votes vote down vote up
private JsonObject getChacheFile(Plugin plugin){
    File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
    if(file.exists()){
        try{
            JsonParser parser = new JsonParser();
            JsonElement jsonElement = parser.parse(new FileReader(file));
            return jsonElement.getAsJsonObject();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }else return null;
}
 
Example 35
Project: EscapeLag   File: MonitorUtils.java   View source code 5 votes vote down vote up
public static void enable() {
	enable = true;
	enable_time = System.currentTimeMillis();
	for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
		if (plugin != null && plugin.isEnabled()) {
			EventExecutorInjector.inject(plugin);
			SchedulerTaskInjector.inject(plugin);
			CommandInjector.inject(plugin);
		}
	}
}
 
Example 36
Project: UltimateSpawn   File: ConfigGProtection.java   View source code 5 votes vote down vote up
public static void loadConfig(Plugin plugin) {
    pl = plugin;

    file = new File(pl.getDataFolder(), "Config/Global/Server-Protection.yml");
    Config = YamlConfiguration.loadConfiguration(file);

    if (!pl.getDataFolder().exists()) {
        pl.getDataFolder().mkdir();
    }

    create();
}
 
Example 37
Project: Uranium   File: CraftServer.java   View source code 5 votes vote down vote up
public void enablePlugins(PluginLoadOrder type) {
    // Cauldron start - initialize mod wrappers
    org.bukkit.craftbukkit.block.CraftBlock.initMappings();
    org.bukkit.craftbukkit.entity.CraftEntity.initMappings();
    // Cauldron end
    if (type == PluginLoadOrder.STARTUP) {
        helpMap.clear();
        helpMap.initializeGeneralTopics();
    }

    Plugin[] plugins = pluginManager.getPlugins();

    for (Plugin plugin : plugins) {
        if ((!plugin.isEnabled()) && (plugin.getDescription().getLoad() == type)) {
            loadPlugin(plugin);
        }
    }

    if (type == PluginLoadOrder.POSTWORLD) {
        commandMap.setFallbackCommands();
        setVanillaCommands();
        commandMap.registerServerAliases();
        loadCustomPermissions();
        DefaultPermissions.registerCorePermissions();
        helpMap.initializeCommands();
    }
}
 
Example 38
Project: TruenoNPC   File: TruenoNPC_v1_9_r1.java   View source code 5 votes vote down vote up
private JsonObject getChacheFile(Plugin plugin){
    File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
    if(file.exists()){
        try{
            JsonParser parser = new JsonParser();
            JsonElement jsonElement = parser.parse(new FileReader(file));
            return jsonElement.getAsJsonObject();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }else return null;
}
 
Example 39
Project: SamaGamesAPI   File: TinyProtocol.java   View source code 5 votes vote down vote up
/**
 * Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.
 * <p>
 * You can construct multiple instances per plugin.
 *
 * @param plugin - the plugin.
 */
public TinyProtocol(final Plugin plugin) {
    this.plugin = plugin;

    // Compute handler name
    this.handlerName = getHandlerName();

    // Prepare existing players
    registerBukkitEvents();

    try {
        registerChannelHandler();
        registerPlayers(plugin);
    } catch (IllegalArgumentException ex) {
        // Damn you, late bind
        plugin.getLogger().info("[TinyProtocol] Delaying server channel injection due to late bind.");

        new BukkitRunnable() {
            @Override
            public void run() {
                registerChannelHandler();
                registerPlayers(plugin);
                plugin.getLogger().info("[TinyProtocol] Late bind injection successful.");
            }
        }.runTask(plugin);
    }
}
 
Example 40
Project: black   File: Black.java   View source code 5 votes vote down vote up
public void prepareTheBlacknessFor(Plugin plugin) {
    if (!readyAlready) {
        Bukkit.getPluginManager().registerEvents(
            new InventoryActionsListener(),
            Objects.requireNonNull(plugin)
        );

        readyAlready = true;
    }
}