Java Code Examples for ch.njol.skript.Skript#exception()

The following examples show how to use ch.njol.skript.Skript#exception() . 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: Language.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Use this preferably like this:
 * 
 * <pre>
 * final boolean wasLocal = Language.setUseLocal(true / false);
 * try {
 * 	// whatever
 * } finally {
 * 	Language.setUseLocal(wasLocal);
 * }
 * </pre>
 * 
 * @param b Whether to enable localisation or not
 * @return Previous state
 */
public static boolean setUseLocal(final boolean b) {
	if (useLocal == b)
		return b;
	if (localized == null)
		return false;
	useLocal = b;
	for (final LanguageChangeListener l : listeners) {
		try {
			l.onLanguageChange();
		} catch (final Exception e) {
			Skript.exception(e, "Error while changing the language " + (b ? "from english to" : "to english from") + " " + name, "Listener: " + l);
		}
	}
	return !b;
}
 
Example 2
Source File: FlatFileStorage.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected final boolean connect() {
	synchronized (connectionLock) {
		synchronized (changesWriter) {
			if (changesWriter.get() != null)
				return true;
			try (FileOutputStream fos = new FileOutputStream(file, true)){
				changesWriter.set(new PrintWriter(new OutputStreamWriter(fos, UTF_8)));
				loaded = true;
				return true;
			} catch (IOException e) { // close() might throw ANY IOException
				Skript.exception(e);
				return false;
			}
		}
	}
}
 
Example 3
Source File: WorldGuard6Hook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean init() {
    supportsUUIDs = Skript.methodExists(DefaultDomain.class, "getUniqueIds");
    
    // Manually load syntaxes for regions, because we're in module package
    try {
        Skript.getAddonInstance().loadClasses("ch.njol.skript.hooks.regions");
    } catch (IOException e) {
        Skript.exception(e);
        return false;
    }
    return super.init();
}
 
Example 4
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean init() {
    supportsUUIDs = Skript.methodExists(DefaultDomain.class, "getUniqueIds");
    
    // Manually load syntaxes for regions, because we're in module package
    try {
        Skript.getAddonInstance().loadClasses("ch.njol.skript.hooks.regions");
    } catch (IOException e) {
        Skript.exception(e);
        return false;
    }
    return super.init();
}
 
Example 5
Source File: PassengerUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
public static Entity[] getPassenger(Entity e) {
	if (hasMultiplePassenger()) {
		return e.getPassengers().toArray(new Entity[0]);
	} else {
		try {
			return new Entity[]{(Entity)getPassenger.invoke(e)};		
		} catch (final Exception ex) { //I don't think it can happen, but just in case.
			Skript.exception(ex, "A error occured while trying to get a passenger in version lower than 1.11.2.");
		} 
	}
	return null;
}
 
Example 6
Source File: PassengerUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add the passenger to the vehicle
 * @param vehicle - The entity vehicle
 * @param passenger - The entity passenger
 */
public static void addPassenger(Entity vehicle, Entity passenger) {
	if (vehicle == null || passenger == null)
		return;
	if (hasMultiplePassenger()) {
		vehicle.addPassenger(passenger);
	} else {
		try {
			vehicle.eject();
			setPassenger.invoke(vehicle, passenger);
		} catch (final Exception ex) { 
			Skript.exception(ex, "A error occured while trying to set a passenger in version lower than 1.11.2.");
		}
	}
}
 
Example 7
Source File: MagicBlockCompat.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setBlock(Block block, Material type, @Nullable BlockValues values, int flags) {
	block.setType(type);
	
	if (values != null) {
		MagicBlockValues ourValues = (MagicBlockValues) values;
		try {
			setDataMethod.invokeExact(block, (byte) ourValues.data);
		} catch (Throwable e) {
			Skript.exception(e);
		}
	}
}
 
Example 8
Source File: MagicBlockCompat.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public BlockState fallingBlockToState(FallingBlock entity) {
	BlockState state = entity.getWorld().getBlockAt(0, 0, 0).getState();
	state.setType(entity.getMaterial());
	try {
		setRawDataMethod.invokeExact(state, (byte) getBlockDataMethod.invokeExact(entity));
	} catch (Throwable e) {
		Skript.exception(e);
	}
	return state;
}
 
Example 9
Source File: Aliases.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads aliases from Skript's standard locations.
 * Exceptions will be logged, but not thrown.
 */
public static void load() {
	try {
		long start = System.currentTimeMillis();
		loadInternal();
		Skript.info("Loaded " + provider.getAliasCount() + " aliases in " + (System.currentTimeMillis() - start) + "ms");
	} catch (IOException e) {
		Skript.exception(e);
	}
}
 
Example 10
Source File: EffLoadServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
  protected void execute(Event e) {
Path p = Paths.get(path.getSingle(e));
if (Files.isRegularFile(p)) {
	try {
		lastLoaded = Bukkit.loadServerIcon(p.toFile());
	} catch (NullPointerException | IllegalArgumentException ignored) {
	} catch (Exception ex) {
		Skript.exception(ex);
	}
}
  }
 
Example 11
Source File: EffExceptionDebug.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event e) {
	Skript.exception("Created by a script (debugging)...");
}