-
-
Notifications
You must be signed in to change notification settings - Fork 45
Adding Replacers
games647 edited this page Mar 23, 2015
·
4 revisions
TODO: more documentation
package yourdomain.yourplugin;
import com.github.games647.scoreboardstats.ScoreboardStats;
import com.github.games647.scoreboardstats.variables.ReplaceEvent;
import com.github.games647.scoreboardstats.variables.VariableReplacer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class YourPlugin extends JavaPlugin implements VariableReplacer {
@Override
public void onEnable() {
if (Bukkit.getPluginManager().isPluginEnabled("ScoreboardStats")) {
ScoreboardStats scoreboardstats = JavaPlugin
.getPlugin(ScoreboardStats.class);
scoreboardstats.getReplaceManager().register(this, this, "variable");
}
}
public void onReplace(Player player, String var, ReplaceEvent replaceEvent) {
replaceEvent.setScore(321);
}
} private void registerReplacerInterface(ReplaceManager replaceManager) {
replaceManager.register(new VariableReplacer() {
@Override
public void onReplace(Player player, String var
, ReplaceEvent replaceEvent) {
//there are multiple variables registered on this replacer
//so we need to check which one is needed
if ("variableName".equals(var)) {
replaceEvent.setScore(1337);
} else {
replaceEvent.setScore(1336);
}
}
}, this, "variableName", "secondVariable");
} private void registerReplacerInterface(ReplaceManager replaceManager) {
replaceManager.register(new ReplacerInterface(), this, "thirdVariable");
}package yourdomain.yourplugin;
import com.github.games647.scoreboardstats.variables.ReplaceEvent;
import com.github.games647.scoreboardstats.variables.VariableReplacer;
import org.bukkit.entity.Player;
public class ReplacerInterface implements VariableReplacer {
public void onReplace(Player player, String var, ReplaceEvent replaceEvent) {
//the replacer is only registered for one variable
//so it will ever be this variable
replaceEvent.setScore(123);
}
} private void registerReplacerAbstract(ReplaceManager replaceManager) {
replaceManager
.register(new VariableReplaceAdapter<YourPlugin>(this, "var") {
@Override
public void onReplace(Player player, String var
, ReplaceEvent replaceEvent) {
replaceEvent.setScore(1337);
}
});
} private void registerReplacerAbstract(ReplaceManager replaceManager) {
replaceManager.register(new ReplacerClass(this));
}package yourdomain.yourplugin;
import com.github.games647.scoreboardstats.variables.ReplaceEvent;
import com.github.games647.scoreboardstats.variables.VariableReplaceAdapter;
import org.bukkit.entity.Player;
public class ReplacerClass extends VariableReplaceAdapter<YourPlugin> {
public ReplacerClass(YourPlugin plugin) {
super(plugin, "variable");
}
// or this one
// public ReplacerClass(YourPlugin plugin) {
// super(plugin, "&cShowcase", false, false, false, "variable");
// }
public void onReplace(Player player, String var, ReplaceEvent replaceEvent) {
replaceEvent.setScore(1337);
}
}