Skip to content

Commit

Permalink
Fix deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 18, 2015
1 parent e7cc291 commit dd8f9bf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 87 deletions.
115 changes: 50 additions & 65 deletions src/main/java/net/citizensnpcs/api/ai/NavigatorParameters.java
Expand Up @@ -3,13 +3,13 @@
import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Lists;

import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.ai.event.NavigatorCallback;
import net.citizensnpcs.api.astar.AStarMachine;
import net.citizensnpcs.api.astar.pathfinder.BlockExaminer;

import com.google.common.collect.Lists;

public class NavigatorParameters implements Cloneable {
private double attackRange;
private AttackStrategy attackStrategy;
Expand All @@ -28,8 +28,7 @@ public class NavigatorParameters implements Cloneable {
private boolean useNewPathfinder;

/**
* Adds a {@link Runnable} callback that will be called every tick while the
* path is running.
* Adds a {@link Runnable} callback that will be called every tick while the path is running.
*
* @param callback
* The callback to add
Expand All @@ -40,9 +39,8 @@ public NavigatorParameters addRunCallback(Runnable callback) {
}

/**
* Adds a {@link NavigatorCallback} that will be removed
* <em>immediately</em> after being called.
*
* Adds a {@link NavigatorCallback} that will be removed <em>immediately</em> after being called.
*
* @param callback
* The callback
*/
Expand All @@ -61,17 +59,16 @@ public NavigatorParameters attackRange(double range) {
}

/**
* @return The {@link AttackStrategy} currently in use or the
* {@link #defaultAttackStrategy()} if not configured (may return
* null)
* @return The {@link AttackStrategy} currently in use or the {@link #defaultAttackStrategy()} if not configured
* (may return null)
*/
public AttackStrategy attackStrategy() {
return attackStrategy == null ? defaultStrategy : attackStrategy;
}

/**
* Sets the {@link AttackStrategy} for use when attacking entity targets.
*
*
* @param strategy
* The strategy to use
*/
Expand All @@ -88,7 +85,7 @@ public boolean avoidWater() {

/**
* Sets whether to avoid water while pathfinding
*
*
* @param avoidWater
* Whether to avoid water
*/
Expand All @@ -105,10 +102,9 @@ public float baseSpeed() {
}

/**
* Sets the base movement speed of the {@link Navigator}. Note that this is
* mob-specific and may not always be sane. Using {@link #speedModifier()}
* is preferred.
*
* Sets the base movement speed of the {@link Navigator}. Note that this is mob-specific and may not always be sane.
* Using {@link #speedModifier()} is preferred.
*
* @see #speedModifier()
* @param speed
* The new movement speed
Expand Down Expand Up @@ -154,9 +150,9 @@ public NavigatorParameters clone() {
}

/**
* Returns the configured <em>default</em> attack strategy, which tries to
* perform the most Minecraft-like attack on the target.
*
* Returns the configured <em>default</em> attack strategy, which tries to perform the most Minecraft-like attack on
* the target.
*
* @return The default strategy
*/
public AttackStrategy defaultAttackStrategy() {
Expand All @@ -165,7 +161,7 @@ public AttackStrategy defaultAttackStrategy() {

/**
* Sets the default {@link AttackStrategy}.
*
*
* @param defaultStrategy
* The new default strategy
* @see #defaultAttackStrategy()
Expand All @@ -176,14 +172,12 @@ public NavigatorParameters defaultAttackStrategy(AttackStrategy defaultStrategy)
}

/**
* Returns the distance margin or leeway that the {@link Navigator} will be
* able to stop from the target destination. The margin will be measured
* against the block distance squared.
*
* For example: if the distance margin were 2, then the {@link Navigator}
* could stop moving towards the target when it is 2 blocks squared away
* from it.
*
* Returns the distance margin or leeway that the {@link Navigator} will be able to stop from the target
* destination. The margin will be measured against the block distance squared.
*
* For example: if the distance margin were 2, then the {@link Navigator} could stop moving towards the target when
* it is 2 blocks squared away from it.
*
* @return The distance margin
*/
public double distanceMargin() {
Expand All @@ -192,7 +186,7 @@ public double distanceMargin() {

/**
* Sets the distance margin.
*
*
* @see #distanceMargin()
* @param newMargin
* The new distance margin
Expand All @@ -204,7 +198,7 @@ public NavigatorParameters distanceMargin(double newMargin) {

/**
* Adds the given {@link BlockExaminer}.
*
*
* @param examiner
* The BlockExaminer to add
*/
Expand All @@ -215,7 +209,7 @@ public NavigatorParameters examiner(BlockExaminer examiner) {

/**
* Gets a copy of all current {@link BlockExaminer}s.
*
*
* @return An array of all current examiners
*/
public BlockExaminer[] examiners() {
Expand All @@ -224,7 +218,7 @@ public BlockExaminer[] examiners() {

/**
* Modifieds the given speed value based on the current parameters.
*
*
* @param toModify
* The speed value to modify
* @return The modified speed
Expand All @@ -235,18 +229,17 @@ public float modifiedSpeed(float toModify) {

/**
* Gets the path distance margin.
*
*
* @see #pathDistanceMargin(double)
*/
public double pathDistanceMargin() {
return pathDistanceMargin;
}

/**
* Sets the path distance margin. This is how close the pathfinder should to
* the target when pathfinding. If you need to set how far the NPC should
* get away from the target, use {@link #distanceMargin(double)}.
*
* Sets the path distance margin. This is how close the pathfinder should to the target when pathfinding. If you
* need to set how far the NPC should get away from the target, use {@link #distanceMargin(double)}.
*
* @param distance
* The distance margin
*/
Expand All @@ -264,10 +257,9 @@ public float range() {
}

/**
* Sets the pathfinding range in blocks. The pathfinding range determines
* how far away the {@link Navigator} will attempt to pathfind before giving
* up to save computation.
*
* Sets the pathfinding range in blocks. The pathfinding range determines how far away the {@link Navigator} will
* attempt to pathfind before giving up to save computation.
*
* @param range
* The new range
*/
Expand Down Expand Up @@ -298,18 +290,16 @@ public void run() {
}

/**
* @return The modified movement speed as given by {@link #baseSpeed()}
* multiplied by {@link #speedModifier()}
* @return The modified movement speed as given by {@link #baseSpeed()} multiplied by {@link #speedModifier()}
*/
public float speed() {
return modifiedSpeed(baseSpeed);
}

/**
* Sets the base movement speed of the {@link Navigator}. Note that this is
* mob-specific and may not always be sane. Using {@link #speedModifier()}
* is preferred.
*
* Sets the base movement speed of the {@link Navigator}. Note that this is mob-specific and may not always be sane.
* Using {@link #speedModifier()} is preferred.
*
* @see #speedModifier()
* @param speed
* The new movement speed
Expand All @@ -330,10 +320,9 @@ public float speedModifier() {
}

/**
* Sets the movement speed modifier of the {@link Navigator}. This is a
* percentage modifier that alters the movement speed returned in
* {@link #speed()}.
*
* Sets the movement speed modifier of the {@link Navigator}. This is a percentage modifier that alters the movement
* speed returned in {@link #speed()}.
*
* @param percent
* The new speed modifier
*/
Expand All @@ -351,9 +340,8 @@ public int stationaryTicks() {
}

/**
* Sets the number of stationary ticks before navigation is cancelled with a
* {@link CancelReason} of STUCK.
*
* Sets the number of stationary ticks before navigation is cancelled with a {@link CancelReason} of STUCK.
*
* @param ticks
* The new number of stationary ticks
*/
Expand All @@ -363,9 +351,9 @@ public NavigatorParameters stationaryTicks(int ticks) {
}

/**
* Gets the {@link StuckAction} of these parameters. This will be run when
* the navigation is stuck and must either be fixed up or cancelled.
*
* Gets the {@link StuckAction} of these parameters. This will be run when the navigation is stuck and must either
* be fixed up or cancelled.
*
* @return The current stuck action
*/
public StuckAction stuckAction() {
Expand All @@ -374,7 +362,7 @@ public StuckAction stuckAction() {

/**
* Sets the {@link StuckAction} of the parameters.
*
*
* @param action
* The new stuck action
* @see #stuckAction()
Expand All @@ -393,15 +381,12 @@ public boolean useNewPathfinder() {
}

/**
* Sets whether or not to use an A* pathfinder defined in
* {@link AStarMachine} for pathfinding.
* Sets whether or not to use an A* pathfinder defined in {@link AStarMachine} for pathfinding.
*
* If this is set to false, then the Minecraft pathfinder will be used,
* which may or may not be more consistent.
* If this is set to false, then the Minecraft pathfinder will be used, which may or may not be more consistent.
*
* Note that certain API features will not be possible if this is set to
* false - this includes {@link #examiner(BlockExaminer)} and
* {@link #distanceMargin(double)}.
* Note that certain API features will not be possible if this is set to false - this includes
* {@link #examiner(BlockExaminer)} and {@link #distanceMargin(double)}.
*
* @param use
* Whether to use the A* pathfinder
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/net/citizensnpcs/api/util/Translator.java
Expand Up @@ -23,8 +23,9 @@

import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import com.google.common.io.FileWriteMode;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.io.Resources;

public class Translator {
private final Locale defaultLocale;
Expand Down Expand Up @@ -145,22 +146,15 @@ public void run() {
File file = new File(rootFolder, fileName);
if (file.exists())
return;
final InputStream stream = Translator.class.getResourceAsStream('/' + fileName);
if (stream == null)
return;
InputSupplier<InputStream> in = new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return stream;
}
};
try {
rootFolder.mkdirs();
File to = File.createTempFile(fileName, null, rootFolder);
to.deleteOnExit();
Files.copy(in, to);
if (!file.exists())
Resources.asByteSource(Resources.getResource(Translator.class, '/' + fileName))
.copyTo(Files.asByteSink(to, FileWriteMode.APPEND));
if (!file.exists()) {
to.renameTo(file);
}
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -173,10 +167,6 @@ public static interface TranslationProvider {
String getName();
}

private static ResourceBundle defaultBundle;
private static Translator instance;
public static final String PREFIX = "messages";

private static void addTranslation(TranslationProvider from, File to) {
Properties props = new Properties();
InputStream in = from.createInputStream();
Expand Down Expand Up @@ -208,8 +198,7 @@ private static void addTranslation(TranslationProvider from, File to) {
if (out != null) {
out.close();
}
}
catch (Exception e) {
} catch (Exception e) {
e.getCause(); // Do nothing
}
}
Expand Down Expand Up @@ -302,8 +291,7 @@ private static void populateDefaults(File bundleFile) {
if (stream != null) {
stream.close();
}
}
catch (Exception e) {
} catch (Exception e) {
e.getCause(); // Do nothing
}
}
Expand All @@ -314,11 +302,17 @@ public static void setInstance(File dataFolder, Locale preferredLocale) {
}

public static String translate(String key, Locale preferredLocale, Object... msg) {
return Colorizer.parseColors(msg.length == 0 ? instance.translate(key, preferredLocale) : instance.format(key,
preferredLocale, msg));
return Colorizer.parseColors(msg.length == 0 ? instance.translate(key, preferredLocale)
: instance.format(key, preferredLocale, msg));
}

public static String translate(String key, Object... msg) {
return translate(key, instance.defaultLocale, msg);
}

private static ResourceBundle defaultBundle;

private static Translator instance;

public static final String PREFIX = "messages";
}

0 comments on commit dd8f9bf

Please sign in to comment.