Initial Commit

Far from v1.0.0, but a start!
This commit is contained in:
MistPhizzle 2014-06-12 19:21:20 -04:00
commit 9d9f6672ed
34 changed files with 3298 additions and 0 deletions

7
.classpath Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
<classpathentry kind="lib" path="C:/Users/Shawn/Documents/LocalServer/BukkitForPlugins.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

22
.gitattributes vendored Normal file
View file

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

38
.gitignore vendored Normal file
View file

@ -0,0 +1,38 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Icon must ends with two \r.
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
bin/

17
.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProjectKorra</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

View file

@ -0,0 +1,43 @@
package Utilities;
import java.util.jar.JarFile;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
public class AbilityLoadEvent<T> extends Event{
private static final HandlerList handlers = new HandlerList();
private final Plugin plugin;
private final T loadable;
private final JarFile jarFile;
public AbilityLoadEvent(Plugin plugin, T loadable, JarFile jarFile) {
this.plugin = plugin;
this.loadable = loadable;
this.jarFile = jarFile;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public JarFile getJarFile() {
return jarFile;
}
public T getLoadable() {
return loadable;
}
public Plugin getPlugin() {
return plugin;
}
}

View file

@ -0,0 +1,62 @@
package Utilities;
public class AbilityLoadable implements Cloneable {
private final String name;
public AbilityLoadable(String name) {
this.name = name;
}
@Override
public AbilityLoadable clone() {
try {
return (AbilityLoadable) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
public LoadResult init() {
return new LoadResult();
}
public boolean isInternal() {
return false;
}
public final String getName() {
return name;
}
public static final class LoadResult {
private final Result result;
private final String reason;
public LoadResult() {
this(Result.SUCCESS, "");
}
public LoadResult(String failReason) {
this(Result.FAILURE, failReason);
}
public LoadResult(Result result, String reason) {
this.result = result;
this.reason = reason;
}
public String getReason() {
return reason;
}
public Result getResult() {
return result;
}
public enum Result {
FAILURE, SUCCESS
}
}
}

View file

@ -0,0 +1,155 @@
package Utilities;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import Utilities.AbilityLoadable.LoadResult;
import Utilities.AbilityLoadable.LoadResult.Result;
public class AbilityLoader <T extends AbilityLoadable> implements Listener {
private final Plugin plugin;
private final File dir;
private ClassLoader loader;
private final Object[] paramTypes;
private final Class<?>[] ctorParams;
private final ArrayList<File> files;
private final List<T> loadables;
public AbilityLoader(Plugin plugin, File dir, Object... paramTypes) {
this.plugin = plugin;
this.dir = dir;
this.paramTypes = paramTypes;
this.files = new ArrayList<File>();
this.loadables = new ArrayList<T>(0);
for (File f: dir.listFiles(new FileExtensionFilter(".jar"))) {
files.add(f);
}
List<Class<?>> constructorParams = new ArrayList<Class<?>>();
for (Object paramType : paramTypes)
constructorParams.add(paramType.getClass());
this.ctorParams = constructorParams.toArray(new Class<?>[0]);
List<URL> urls = new ArrayList<URL>();
for (File file: files) {
try {
urls.add(file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
this.loader = URLClassLoader.newInstance(urls.toArray(new URL[0]), plugin.getClass().getClassLoader());
}
public Logger getLogger() {
return plugin.getLogger();
}
public final List<T> load(Class<? extends AbilityLoadable> classType) {
for (File file: files) {
try {
final JarFile jarFile = new JarFile(file);
String mainClass = null;
if (jarFile.getEntry("path.yml") != null) {
JarEntry element = jarFile.getJarEntry("path.yml");
BufferedReader reader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(element)));
mainClass = reader.readLine().substring(12);
}
if (mainClass != null) {
Class<?> clazz = Class.forName(mainClass, true, loader);
if (clazz != null) {
Class<? extends AbilityLoadable> loadableClass = clazz.asSubclass(classType);
Constructor<? extends AbilityLoadable> ctor = loadableClass.getConstructor(ctorParams);
T loadable = (T) ctor.newInstance(paramTypes);
LoadResult result = loadable.init();
if (result.getResult().equals(Result.SUCCESS)) {
loadables.add(loadable);
AbilityLoadEvent<T> event = new AbilityLoadEvent<T>(plugin, loadable, jarFile);
plugin.getServer().getPluginManager().callEvent(event);
continue;
}
String reason = result.getReason();
if (reason != null && !reason.isEmpty()) {
getLogger().log(Level.INFO, "The JAR file " + file.getName() + " was unable to load because: " + reason);
}
} else {
jarFile.close();
throw new ClassNotFoundException();
}
} else {
jarFile.close();
throw new ClassNotFoundException();
}
} catch (ClassCastException e) {
e.printStackTrace();
getLogger().log(Level.WARNING, "The JAR file " + file.getPath() + " is in the wrong directory");
getLogger().log(Level.WARNING, "The JAR file " + file.getName() + " failed to load");
} catch (ClassNotFoundException e) {
e.printStackTrace();
getLogger().log(Level.WARNING, "Invalid path.yml");
getLogger().log(Level.WARNING, "The JAR file " + file.getName() + " failed to load.");
} catch (Exception e) {
e.printStackTrace();
getLogger().log(Level.WARNING, "Unknown cause");
getLogger().log(Level.WARNING, "The JAR file " + file.getName() + " failed to load");
}
}
return loadables;
}
public List<T> reload(Class<? extends AbilityLoadable> classType) {
unload();
List<URL> urls = new ArrayList<URL>();
files.clear();
for (String loadableFile: dir.list()) {
if (loadableFile.endsWith(".jar")) {
File file = new File(dir, loadableFile);
files.add(file);
try {
urls.add(file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
this.loader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), plugin.getClass().getClassLoader());
return load(classType);
}
public void unload() {
loadables.clear();
}
}

View file

@ -0,0 +1,19 @@
package Utilities;
import java.io.File;
import java.io.FileFilter;
public final class FileExtensionFilter implements FileFilter {
private final String extension;
public FileExtensionFilter(String extension) {
this.extension = extension;
}
@Override
public boolean accept(File file) {
return file.getName().endsWith(extension);
}
}

View file

@ -0,0 +1,43 @@
package com.projectkorra.ProjectKorra.Ability;
import Utilities.AbilityLoadable;
public class AbilityModule extends AbilityLoadable implements Cloneable {
public AbilityModule(final String name) {
super(name);
// TODO Auto-generated constructor stub
}
public void onThisLoad() {
// TODO Auto-generated method stub
}
// Must be overridden
public String version() {
return "outdated";
}
public String getElement() {
return "";
}
public String getAuthor() {
return "";
}
public void stop() {
}
public boolean isShiftAbility() {
return false;
}
public String getDescription() {
return "";
}
}

View file

@ -0,0 +1,65 @@
package com.projectkorra.ProjectKorra.Ability;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import com.projectkorra.ProjectKorra.Element;
import com.projectkorra.ProjectKorra.ProjectKorra;
import Utilities.AbilityLoader;
public class AbilityModuleManager {
static ProjectKorra plugin;
public static List<AbilityModule> ability;
private final AbilityLoader<AbilityModule> loader;
public static HashSet<String> abilities;
public static HashSet<String> waterbendingabilities;
public static HashSet<String> airbendingabilities;
public static HashSet<String> earthbendingabilities;
public static HashSet<String> firebendingabilities;
public static HashSet<String> chiabilities;
public static HashSet<String> shiftabilities;
public static HashMap<String, String> authors;
public static HashMap<String, String> descriptions;
public AbilityModuleManager(final ProjectKorra plugin) {
AbilityModuleManager.plugin = plugin;
final File path = new File(plugin.getDataFolder().toString() + "/Abilities/");
if (!path.exists()) {
path.mkdir();
}
loader = new AbilityLoader<AbilityModule>(plugin, path, new Object[] {});
abilities = new HashSet<String>();
waterbendingabilities = new HashSet<String>();
airbendingabilities = new HashSet<String>();
earthbendingabilities = new HashSet<String>();
firebendingabilities = new HashSet<String>();
chiabilities = new HashSet<String>();
shiftabilities = new HashSet<String>();
descriptions = new HashMap<String, String>();
authors = new HashMap<String, String>();
ability = loader.load(AbilityModule.class);
fill();
}
private void fill() {
for (AbilityModule ab: ability) {
ab.onThisLoad();
abilities.add(ab.getName());
if (ab.getElement() == Element.Air.toString()) airbendingabilities.add(ab.getName());
if (ab.getElement() == Element.Water.toString()) waterbendingabilities.add(ab.getName());
if (ab.getElement() == Element.Earth.toString()) earthbendingabilities.add(ab.getName());
if (ab.getElement() == Element.Fire.toString()) firebendingabilities.add(ab.getName());
if (ab.getElement() == Element.Chi.toString()) chiabilities.add(ab.getName());
if (ab.isShiftAbility()) shiftabilities.add(ab.getName());
descriptions.put(ab.getName(), ab.getDescription());
authors.put(ab.getName(), ab.getAuthor());
}
}
}

View file

@ -0,0 +1,27 @@
package com.projectkorra.ProjectKorra.Ability;
import com.projectkorra.ProjectKorra.Element;
public interface BendingAbility {
/*
* The Description that will show when /bending help is used.
*/
public String getDescription();
/*
* The name of the ability for /bending display
*/
public String getAbilityName();
/*
* What element is required to Bend the element?
*/
public Element getElement();
/*
* Begins the Ability.
*/
public void start();
/*
* Progresses the ability.
*/
public void progressAll();
}

View file

@ -0,0 +1,109 @@
package com.projectkorra.ProjectKorra;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.airbending.AirPassive;
import com.projectkorra.ProjectKorra.airbending.chiblocking.ChiPassive;
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
import com.projectkorra.ProjectKorra.firebending.FirePassive;
import com.projectkorra.ProjectKorra.waterbending.Plantbending;
import com.projectkorra.ProjectKorra.waterbending.WaterPassive;
public class BendingManager implements Runnable {
public ProjectKorra plugin;
ArrayList<World> worlds = new ArrayList<World>();
ConcurrentHashMap<World, Boolean> nights = new ConcurrentHashMap<World, Boolean>();
ConcurrentHashMap<World, Boolean> days = new ConcurrentHashMap<World, Boolean>();
static final String defaultsunrisemessage = "You feel the strength of the rising sun empowering your firebending.";
static final String defaultsunsetmessage = "You feel the empowering of your firebending subside as the sun sets.";
static final String defaultmoonrisemessage = "You feel the strength of the rising moon empowering your waterbending.";
static final String defaultmoonsetmessage = "You feel the empowering of your waterbending subside as the moon sets.";
public BendingManager(ProjectKorra plugin) {
this.plugin = plugin;
}
public void run() {
try {
AirPassive.handlePassive(Bukkit.getServer());
ChiPassive.handlePassive();
WaterPassive.handlePassive();
FirePassive.handlePassive();
EarthPassive.revertSands();
Plantbending.regrow();
handleDayNight();
} catch (Exception e) {
Methods.stopBending();
e.printStackTrace();
}
}
public void handleDayNight() {
for (World world: plugin.getServer().getWorlds()) {
if (world.getWorldType() == WorldType.NORMAL && !worlds.contains(world)) {
worlds.add(world);
nights.put(world, false);
days.put(world, false);
}
}
ArrayList<World> removeworlds = new ArrayList<World>();
for (World world: worlds) {
if (!plugin.getServer().getWorlds().contains(world)) {
removeworlds.add(world);
continue;
}
boolean night = nights.get(world);
boolean day = days.get(world);
if (Methods.isDay(world) && !day) {
for (Player player: world.getPlayers()) {
if (Methods.isBender(player.getName(), Element.Fire) && player.hasPermission("bending.message.daymessage")) {
player.sendMessage(ChatColor.RED + defaultsunrisemessage);
}
}
days.replace(world, true);
}
if (!Methods.isDay(world) && day) {
for (Player player: world.getPlayers()) {
if (Methods.isBender(player.getName(), Element.Fire) && player.hasPermission("bending.message.daymessage")) {
player.sendMessage(ChatColor.RED + defaultsunsetmessage);
}
}
days.replace(world, false);
}
if (Methods.isNight(world) && !night) {
for (Player player: world.getPlayers()) {
if (Methods.isBender(player.getName(), Element.Water) && player.hasPermission("bending.message.nightmessage")) {
player.sendMessage(ChatColor.AQUA + defaultmoonrisemessage);
}
}
nights.replace(world, true);
}
if (!Methods.isNight(world) && night) {
for (Player player: world.getPlayers()) {
if (Methods.isBender(player.getName(), Element.Water) && player.hasPermission("bending.message.nightmessage")) {
player.sendMessage(ChatColor.AQUA + defaultmoonsetmessage);
}
}
nights.replace(world, false);
}
}
for (World world: removeworlds) {
worlds.remove(world);
}
}
}

View file

@ -0,0 +1,64 @@
package com.projectkorra.ProjectKorra;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class BendingPlayer {
public static ConcurrentHashMap<String, BendingPlayer> players = new ConcurrentHashMap<String, BendingPlayer>();
public static ConcurrentHashMap<String, Long> blockedChi = new ConcurrentHashMap<String, Long>();
UUID uuid;
String player;
ArrayList<Element> elements;
HashMap<Integer, String> abilities;
boolean permaRemoved;
boolean isToggled;
public BendingPlayer(UUID uuid, String player, ArrayList<Element> elements, HashMap<Integer, String> abilities, boolean permaRemoved) {
this.uuid = uuid;
this.player = player;
this.elements = elements;
this.abilities = abilities;
this.permaRemoved = permaRemoved;
isToggled = true;
players.put(player, this);
}
public UUID getUUID() {
return this.uuid;
}
public String getPlayerName() {
return this.player;
}
public List<Element> getElements() {
return this.elements;
}
public HashMap<Integer, String> getAbilities() {
return this.abilities;
}
public boolean isPermaRemoved() {
return this.permaRemoved;
}
public void addElement(Element e) {
this.elements.add(e);
}
public boolean hasElement(Element e) {
return this.elements.contains(e);
}
public void setElement(Element e) {
this.elements.clear();
this.elements.add(e);
}
}

View file

@ -0,0 +1,829 @@
package com.projectkorra.ProjectKorra;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager;
public class Commands {
ProjectKorra plugin;
public Commands(ProjectKorra plugin) {
this.plugin = plugin;
init();
}
String[] airaliases = {"air", "a", "airbending", "airbender"};
String[] wateraliases = {"water", "w", "waterbending", "waterbender"};
String[] earthaliases = {"earth", "e", "earthbending", "earthbender"};
String[] firealiases = {"fire", "f", "firebending", "firebender"};
String[] chialiases = {"chi", "c", "chiblocking", "chiblocker"};
String[] helpaliases = {"help", "h"};
String[] versionaliases = {"version", "v"};
String[] permaremovealiases = {"permaremove", "premove", "permremove", "pr"};
String[] choosealiases = {"choose", "ch"};
String[] removealiases = {"remove", "rm"};
String[] togglealiases = {"toggle", "t"};
String[] displayaliases = {"display", "d"};
String[] bindaliases = {"bind", "b"};
String[] clearaliases = {"clear", "cl", "c"};
String[] reloadaliases = {"reload", "r"};
private void init() {
PluginCommand projectkorra = plugin.getCommand("projectkorra");
CommandExecutor exe;
exe = new CommandExecutor() {
@Override
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
if (args.length == 0) {
s.sendMessage("§c/bending help [Ability/Command] §eDisplay help.");
s.sendMessage("§c/bending choose [Element] §eChoose an element.");
s.sendMessage("§c/bending bind [Ability] # §eBind an ability.");
return true;
}
if (Arrays.asList(reloadaliases).contains(args[0].toLowerCase())) {
if (args.length != 1) {
s.sendMessage("§6Proper Usage: /bending reload");
return true;
}
if (!s.hasPermission("bending.command.reload")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
plugin.reloadConfig();
s.sendMessage("§bBending config reloaded.");
return true;
}
if (Arrays.asList(clearaliases).contains(args[0].toLowerCase())) {
if (args.length > 2) {
s.sendMessage("§6Proper Usage: /bending clear <#>");
return true;
}
if (!s.hasPermission("bending.command.clear")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (!(s instanceof Player)) {
s.sendMessage("§cThis command is only usable by players.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(s.getName());
if (args.length == 1) {
bPlayer.abilities.clear();
s.sendMessage("Your bound abilities have been cleared.");
return true;
}
if (args.length == 2) {
int slot = Integer.parseInt(args[1]);
if (slot < 1 || slot > 9) {
s.sendMessage("§cThe slot must be an integer between 0 and 9.");
return true;
}
if (bPlayer.abilities.get(slot) != null) {
bPlayer.abilities.remove(slot);
}
s.sendMessage("You have cleared slot #" + slot);
return true;
}
}
if (Arrays.asList(bindaliases).contains(args[0].toLowerCase())) {
if (args.length > 3 || args.length == 1) {
s.sendMessage("§6Proper Usage: /bending bind [Ability] <#>");
return true;
}
if (!s.hasPermission("bending.command.bind")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (!(s instanceof Player)) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (args.length == 2) {
// We bind the ability to the slot they have selected..
// bending bind [Ability]
String abil = args[1];
if (!Methods.abilityExists(abil)) {
s.sendMessage("§cThat is not an ability.");
return true;
}
String ability = Methods.getAbility(abil);
if (Methods.isAirAbility(ability) && !Methods.isBender(s.getName(), Element.Air)) {
s.sendMessage("§7You must be an Airbender to bind this ability.");
return true;
}
if (Methods.isWaterAbility(ability) && !Methods.isBender(s.getName(), Element.Water)) {
s.sendMessage("§bYou must be a Waterbender to bind this ability.");
return true;
}
if (Methods.isEarthAbility(ability) && !Methods.isBender(s.getName(), Element.Earth)) {
s.sendMessage("§aYou must be an Earthbender to bind this ability.");
return true;
}
if (Methods.isFireAbility(ability) && !Methods.isBender(s.getName(), Element.Fire)) {
s.sendMessage("§cYou must be a Firebender to bind this ability.");
return true;
}
if (Methods.isChiAbility(ability) && !Methods.isBender(s.getName(), Element.Chi)) {
s.sendMessage("§6You must be a ChiBlocker to bind this ability.");
return true;
}
Methods.bindAbility((Player) s, ability);
s.sendMessage("Ability Bound.");
return true;
}
if (args.length == 3) {
// bending bind ability [Slot]
String abil = args[1];
if (!Methods.abilityExists(abil)) {
s.sendMessage("§cThat ability doesn't exist.");
return true;
}
String ability = Methods.getAbility(abil);
int slot = Integer.parseInt(args[2]);
if (slot < 1 || slot > 9) {
s.sendMessage("§cSlot must be an integer between 1 and 9.");
return true;
}
if (Methods.isAirAbility(ability) && !Methods.isBender(s.getName(), Element.Air)) {
s.sendMessage("§7You must be an Airbender to bind this ability.");
return true;
}
if (Methods.isWaterAbility(ability) && !Methods.isBender(s.getName(), Element.Water)) {
s.sendMessage("§bYou must be a Waterbender to bind this ability.");
return true;
}
if (Methods.isEarthAbility(ability) && !Methods.isBender(s.getName(), Element.Earth)) {
s.sendMessage("§aYou must be an Earthbender to bind this ability.");
return true;
}
if (Methods.isFireAbility(ability) && !Methods.isBender(s.getName(), Element.Fire)) {
s.sendMessage("§cYou must be a Firebender to bind this ability.");
return true;
}
if (Methods.isChiAbility(ability) && !Methods.isBender(s.getName(), Element.Air)) {
s.sendMessage("§6You must be a ChiBlocker to bind this ability.");
return true;
}
Methods.bindAbility((Player) s, ability, slot);
s.sendMessage("Ability Bound");
return true;
}
}
if (Arrays.asList(displayaliases).contains(args[0].toLowerCase())) {
if (args.length > 2) {
s.sendMessage("§6Proper Usage: /bending display <Element>");
return true;
}
if (!s.hasPermission("bending.command.display")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (args.length == 2) {
//bending display [Element]
if (Arrays.asList(airaliases).contains(args[1])) {
if (AbilityModuleManager.airbendingabilities.isEmpty()) {
s.sendMessage("§7There are no airbending abilities available.");
return true;
}
for (String st: AbilityModuleManager.airbendingabilities) {
s.sendMessage("§7" + st);
}
return true;
}
if (Arrays.asList(wateraliases).contains(args[1])) {
if (AbilityModuleManager.waterbendingabilities.isEmpty()) {
s.sendMessage("§bThere are no waterbending abilities available.");
return true;
}
for (String st: AbilityModuleManager.waterbendingabilities) {
s.sendMessage("§b" + st);
}
return true;
}
if (Arrays.asList(earthaliases).contains(args[1])) {
if (AbilityModuleManager.earthbendingabilities.isEmpty()) {
s.sendMessage("§aThere are no earthbending abilities available.");
return true;
}
for (String st: AbilityModuleManager.earthbendingabilities) {
s.sendMessage("§a" + st);
}
return true;
}
if (Arrays.asList(firealiases).contains(args[1])) {
if (AbilityModuleManager.firebendingabilities.isEmpty()) {
s.sendMessage("§cThere are no firebending abilities available.");
return true;
}
for (String st: AbilityModuleManager.firebendingabilities) {
s.sendMessage("§c" + st);
}
return true;
}
if (Arrays.asList(chialiases).contains(args[1])) {
if (AbilityModuleManager.chiabilities.isEmpty()) {
s.sendMessage("§6There are no chiblocking abilities available.");
return true;
}
for (String st: AbilityModuleManager.chiabilities) {
s.sendMessage("§6" + st);
}
return true;
}
}
if (args.length == 1) {
//bending display
if (!(s instanceof Player)) {
s.sendMessage("§cThis command is only usable by players.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(s.getName());
HashMap<Integer, String> abilities = bPlayer.abilities;
String slot1 = abilities.get(1);
String slot2 = abilities.get(2);
String slot3 = abilities.get(3);
String slot4 = abilities.get(4);
String slot5 = abilities.get(5);
String slot6 = abilities.get(6);
String slot7 = abilities.get(7);
String slot8 = abilities.get(8);
String slot9 = abilities.get(9);
if (slot1 != null) {
if (Methods.isAirAbility(slot1)) s.sendMessage("1 - §7" + slot1);
if (Methods.isWaterAbility(slot1)) s.sendMessage("1 - §b" + slot1);
if (Methods.isEarthAbility(slot1)) s.sendMessage("1 - §a" + slot1);
if (Methods.isFireAbility(slot1)) s.sendMessage("1 - §c" + slot1);
if (Methods.isChiAbility(slot1)) s.sendMessage("1 - §6" + slot1);
}
if (slot2 != null) {
if (Methods.isAirAbility(slot2)) s.sendMessage("2 - §7" + slot2);
if (Methods.isWaterAbility(slot2)) s.sendMessage("2 - §b" + slot2);
if (Methods.isEarthAbility(slot2)) s.sendMessage("2 - §a" + slot2);
if (Methods.isFireAbility(slot2)) s.sendMessage("2 - §c" + slot2);
if (Methods.isChiAbility(slot2)) s.sendMessage("2 - §6" + slot2);
}
if (slot3 != null) {
if (Methods.isAirAbility(slot3)) s.sendMessage("3 - §7" + slot3);
if (Methods.isWaterAbility(slot3)) s.sendMessage("3 - §b" + slot3);
if (Methods.isEarthAbility(slot3)) s.sendMessage("3 - §a" + slot3);
if (Methods.isFireAbility(slot3)) s.sendMessage("3 - §c" + slot3);
if (Methods.isChiAbility(slot3)) s.sendMessage("3 - §6" + slot3);
}
if (slot4 != null) {
if (Methods.isAirAbility(slot4)) s.sendMessage("4 - §7" + slot4);
if (Methods.isWaterAbility(slot4)) s.sendMessage("4 - §b" + slot4);
if (Methods.isEarthAbility(slot4)) s.sendMessage("4 - §a" + slot4);
if (Methods.isFireAbility(slot4)) s.sendMessage("4 - §c" + slot4);
if (Methods.isChiAbility(slot4)) s.sendMessage("4 - §6" + slot4);
}
if (slot5 != null) {
if (Methods.isAirAbility(slot5)) s.sendMessage("5 - §7" + slot5);
if (Methods.isWaterAbility(slot5)) s.sendMessage("5 - §b" + slot5);
if (Methods.isEarthAbility(slot5)) s.sendMessage("5 - §a" + slot5);
if (Methods.isFireAbility(slot5)) s.sendMessage("5 - §c" + slot5);
if (Methods.isChiAbility(slot5)) s.sendMessage("5 - §6" + slot5);
}
if (slot6 != null) {
if (Methods.isAirAbility(slot6)) s.sendMessage("6 - §7" + slot6);
if (Methods.isWaterAbility(slot6)) s.sendMessage("6 - §b" + slot6);
if (Methods.isEarthAbility(slot6)) s.sendMessage("6 - §a" + slot6);
if (Methods.isFireAbility(slot6)) s.sendMessage("6 - §c" + slot6);
if (Methods.isChiAbility(slot6)) s.sendMessage("6 - §6" + slot6);
}
if (slot7 != null) {
if (Methods.isAirAbility(slot7)) s.sendMessage("7 - §7" + slot7);
if (Methods.isWaterAbility(slot7)) s.sendMessage("7 - §b" + slot7);
if (Methods.isEarthAbility(slot7)) s.sendMessage("7 - §a" + slot7);
if (Methods.isFireAbility(slot7)) s.sendMessage("7 - §c" + slot7);
if (Methods.isChiAbility(slot7)) s.sendMessage("7 - §6" + slot7);
}
if (slot8 != null) {
if (Methods.isAirAbility(slot8)) s.sendMessage("8 - §7" + slot8);
if (Methods.isWaterAbility(slot8)) s.sendMessage("8 - §b" + slot8);
if (Methods.isEarthAbility(slot8)) s.sendMessage("8 - §a" + slot8);
if (Methods.isFireAbility(slot8)) s.sendMessage("8 - §c" + slot8);
if (Methods.isChiAbility(slot8)) s.sendMessage("8 - §6" + slot8);
}
if (slot9 != null) {
if (Methods.isAirAbility(slot9)) s.sendMessage("9 - §7" + slot9);
if (Methods.isWaterAbility(slot9)) s.sendMessage("9 - §b" + slot9);
if (Methods.isEarthAbility(slot9)) s.sendMessage("9 - §a" + slot9);
if (Methods.isFireAbility(slot9)) s.sendMessage("9 - §c" + slot9);
if (Methods.isChiAbility(slot9)) s.sendMessage("9 - §6" + slot9);
}
if (abilities.isEmpty()) {
s.sendMessage("You don't have any bound abilities.");
return true;
}
return true;
}
}
if (Arrays.asList(togglealiases).contains(args[0].toLowerCase())) {
if (args.length != 1) {
s.sendMessage("§6Proper Usage: /bending toggle");
return true;
}
if (!s.hasPermission("bending.command.toggle")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (!(s instanceof Player)) {
s.sendMessage("§cThis command is only usable by players.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(s.getName());
if (bPlayer.isToggled) {
s.sendMessage("§cYour bending has been toggled off. You will not be able to use most abilities until you toggle it back.");
bPlayer.isToggled = false;
return true;
} else {
s.sendMessage("§aYou have turned your Bending back on.");
bPlayer.isToggled = true;
return true;
}
}
if (args[0].equalsIgnoreCase("who")) {
if (args.length > 2) {
s.sendMessage("§6Proper Usage: /bending who <Player>");
return true;
}
if (!s.hasPermission("bending.command.who")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (args.length == 2) {
Player p = Bukkit.getPlayer(args[1]);
if (p == null) {
s.sendMessage("§cThat player is not online.");
return true;
}
String un = p.getName();
s.sendMessage(un + " - ");
if (Methods.isBender(un, Element.Air)) {
s.sendMessage("§7- Airbender");
}
if (Methods.isBender(un, Element.Water)) {
s.sendMessage("§b- Waterbender");
}
if (Methods.isBender(un, Element.Earth)) {
s.sendMessage("§a- Earthbender");
}
if (Methods.isBender(un, Element.Fire)) {
s.sendMessage("§c- Firebender");
}
if (Methods.isBender(un, Element.Chi)) {
s.sendMessage("§6- ChiBlocker");
}
return true;
}
if (args.length == 1) {
List<String> players = new ArrayList<String>();
for (Player player: Bukkit.getOnlinePlayers()) {
String un = player.getName();
BendingPlayer bp = Methods.getBendingPlayer(un);
if (bp.elements.size() > 1) {
players.add("§5" + un);
continue;
}
if (bp.elements.size() == 0) {
players.add(un);
continue;
}
if (Methods.isBender(un, Element.Air)) {
players.add("§7" + un);
continue;
}
if (Methods.isBender(un, Element.Water)){
players.add("§b" + un);
continue;
}
if (Methods.isBender(un, Element.Earth)) {
players.add("§a" + un);
continue;
}
if (Methods.isBender(un, Element.Chi)) {
players.add("§6" + un);
continue;
}
if (Methods.isBender(un, Element.Fire)) {
players.add("§c" + un);
continue;
}
}
for (String st: players) {
s.sendMessage(st);
}
return true;
}
}
if (Arrays.asList(versionaliases).contains(args[0].toLowerCase())) {
if (args.length != 1) {
s.sendMessage("§6Proper Usage: /bending version");
return true;
}
if (!s.hasPermission("bending.command.version")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
s.sendMessage("§aThis server is running §cProjectKorra v" + plugin.getDescription().getVersion());
return true;
}
if (Arrays.asList(removealiases).contains(args[0].toLowerCase())) {
//bending remove [Player]
if (args.length != 2) {
s.sendMessage("§6Proper Usage: /bending remove [Player]");
return true;
}
if (!s.hasPermission("bending.admin.remove")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
s.sendMessage("§cThat player is not online.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(player.getName());
bPlayer.elements.clear();
s.sendMessage("§aYou have removed the bending of §3" + player.getName());
player.sendMessage("§aYour bending has been removed by §3" + s.getName());
return true;
}
if (Arrays.asList(permaremovealiases).contains(args[0].toLowerCase())) {
//bending permaremove [Player]
if (args.length != 2) {
s.sendMessage("§6Proper Usage: /§3/bending permaremove [Player]");
return true;
}
if (!s.hasPermission("bending.admin.permaremove")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
s.sendMessage("§cThat player is not online.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(player.getName());
bPlayer.elements.clear();
bPlayer.permaRemoved = true;
player.sendMessage("§cYour bending has been permanently removed.");
s.sendMessage("§cYou have permanently removed the bending of: §3" + player.getName());
return true;
}
if (args[0].equalsIgnoreCase("add")) {
//bending add [Player] [Element]
if (args.length > 3) {
s.sendMessage("§6Proper Usage: §3/bending add [Player] [Element]");
s.sendMessage("§6Applicable Elements: §3Air, Water, Earth, Fire, Chi");
return true;
}
if (args.length == 3) {
if (!s.hasPermission("bending.command.add.others")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
s.sendMessage("§cThat player is not online.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(player.getName());
if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Air);
player.sendMessage("§7You are also an airbender.");
s.sendMessage("§3" + player.getName() + " §7is also an airbender.");
return true;
}
if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Water);
player.sendMessage("§bYou are also a waterbender.");
s.sendMessage("§3" + player.getName() + " §bis also a waterbender.");
return true;
}
if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Earth);
player.sendMessage("§aYou are also an Earthbender.");
s.sendMessage("§3" + player.getName() + " §ais also an Earthbender.");
return true;
}
if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Fire);
player.sendMessage("§aYou are also a Firebender.");
s.sendMessage("§3" + player.getName() + " §cis also a Firebender");
return true;
}
if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Chi);
player.sendMessage("§6You are also a ChiBlocker.");
s.sendMessage("§3" + player.getName() + " §6is also a ChiBlocker");
return true;
}
s.sendMessage("§cYou must specify an element.");
return true;
}
if (args.length == 2) {
// Target = Self
if (!s.hasPermission("bending.command.add")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (!(s instanceof Player)) {
s.sendMessage("§cThis command is only usable by Players.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(s.getName());
if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Air);
s.sendMessage("§7You are also an airbender.");
return true;
}
if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Water);
s.sendMessage("§bYou are also a waterbender.");
return true;
}
if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Earth);
s.sendMessage("§aYou are also an Earthbender.");
return true;
}
if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Fire);
s.sendMessage("§aYou are also a Firebender.");
return true;
}
if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) {
bPlayer.addElement(Element.Chi);
s.sendMessage("§6You are also a ChiBlocker.");
return true;
}
s.sendMessage("§cYou must specify an element.");
}
}
if (Arrays.asList(choosealiases).contains(args[0].toLowerCase())) {
// /bending choose [Player] [Element]
if (args.length > 3) {
s.sendMessage("§6Proper Usage: §3/bending choose [Player] [Element]");
s.sendMessage("§6Applicable Elements: §3Air, Water, Earth, Fire, and Chi");
return true;
}
if (args.length == 2) {
if (!s.hasPermission("bending.command.choose")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (!(s instanceof Player)) {
s.sendMessage("§cThis command is only usable by players.");
return true;
}
BendingPlayer bPlayer = Methods.getBendingPlayer(s.getName());
if (bPlayer.isPermaRemoved()) {
s.sendMessage("§cYour bending was permanently removed.");
return true;
}
if (!bPlayer.getElements().isEmpty()) {
if (!s.hasPermission("bending.command.rechoose")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
}
if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) {
bPlayer.setElement(Element.Air);
s.sendMessage("§7You are now an Airbender.");
return true;
}
if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) {
bPlayer.setElement(Element.Water);
s.sendMessage("§bYou are now a waterbender.");
return true;
}
if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) {
bPlayer.setElement(Element.Earth);
s.sendMessage("§aYou are now an Earthbender.");
return true;
}
if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) {
bPlayer.setElement(Element.Fire);
s.sendMessage("§cYou are now a Firebender.");
return true;
}
if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) {
bPlayer.setElement(Element.Chi);
s.sendMessage("§cYou are now a ChiBlocker.");
return true;
}
s.sendMessage("§6Proper Usage: §3/bending choose [Element]");
s.sendMessage("§6Applicable Elements: §3Air, Water, Earth, Fire");
return true;
}
if (args.length == 3) {
if (!s.hasPermission("bending.admin.choose")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
Player target = Bukkit.getPlayer(args[1]);
if (target == null) {
s.sendMessage("§cThat player is not online.");
return true;
}
BendingPlayer bTarget = Methods.getBendingPlayer(target.getName());
if (bTarget.isPermaRemoved()) {
s.sendMessage("§cThat player's bending was permanently removed.");
return true;
}
Element e = null;
if (Arrays.asList(airaliases).contains(args[2])) e = Element.Air;
if (Arrays.asList(wateraliases).contains(args[2])) e = Element.Water;
if (Arrays.asList(earthaliases).contains(args[2])) e = Element.Earth;
if (Arrays.asList(firealiases).contains(args[2])) e = Element.Fire;
if (Arrays.asList(chialiases).contains(args[2])) e = Element.Chi;
if (e == null) {
s.sendMessage("§cYou must specify an element.");
return true;
} else {
bTarget.setElement(e);
target.sendMessage("§cYour bending has been changed to §3" + e.toString() + " §cby §3" + s.getName());
return true;
}
}
}
if (Arrays.asList(helpaliases).contains(args[0].toLowerCase())) {
if (args.length != 2) {
s.sendMessage("§6Proper Usage: /bending help Command/Ability");
return true;
}
if (!s.hasPermission("bending.command.help")) {
s.sendMessage("§cYou don't have permission to do that.");
return true;
}
if (Arrays.asList(displayaliases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending display <Element>");
s.sendMessage("§eThis command will show you all of the elements you have bound if you do not specify an element."
+ " If you do specify an element (Air, Water, Earth, Fire, or Chi), it will show you all of the available "
+ " abilities of that element installed on the server.");
}
if (Arrays.asList(choosealiases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending choose <Player> [Element]");
s.sendMessage("§6Applicable Elements: §3Air, Water, Earth, Fire, Chi");
s.sendMessage("§eThis command will allow the user to choose a player either for himself or <Player> if specified. "
+ " This command can only be used once per player unless they have permission to rechoose their element.");
return true;
}
if (args[1].equalsIgnoreCase("add")) {
s.sendMessage("§6Proper Usage: §3/bending add <Player> [Element]");
s.sendMessage("§6Applicable Elements: §3Air, Water, Earth, Fire, Chi");
s.sendMessage("§eThis command will allow the user to add an element to the targeted <Player>, or themselves if the target"
+ " is not specified. This command is typically reserved for server administrators.");
return true;
}
if (Arrays.asList(permaremovealiases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending permaremove <Player>");
s.sendMessage("§eThis command will permanently remove the Bending of the targeted <Player>. Once removed, a player"
+ " may only receive Bending again if this command is run on them again. This command is typically reserved for"
+ " administrators.");
return true;
}
if (Arrays.asList(versionaliases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending version");
s.sendMessage("§eThis command will print out the version of ProjectKorra this server is running.");
return true;
}
if (Arrays.asList(removealiases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending remove [Player]");
s.sendMessage("§eThis command will remove the element of the targeted [Player]. The player will be able to re-pick "
+ " their element after this command is run on them, assuming their Bending was not permaremoved.");
return true;
}
if (Arrays.asList(togglealiases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending toggle");
s.sendMessage("§eThis command will toggle a player's own Bending on or off. If toggled off, all abilities should stop"
+ " working until it is toggled back on. Logging off will automatically toggle your Bending back on.");
return true;
}
if (args[1].equalsIgnoreCase("who")) {
s.sendMessage("§6Proper Usage: §3/bending who <Player>");
s.sendMessage("§eThis command will tell you what element all players that are online are (If you don't specify a player)"
+ " or give you information about the player that you specify.");
return true;
}
if (Arrays.asList(clearaliases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending clear <slot>");
s.sendMessage("§eThis command will clear the bound ability from the slot you specify (if you specify one."
+ " If you choose not to specify a slot, all of your abilities will be cleared.");
}
if (Arrays.asList(reloadaliases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending reload");
s.sendMessage("§eThis command will reload the Bending config file.");
return true;
}
if (Arrays.asList(bindaliases).contains(args[1].toLowerCase())) {
s.sendMessage("§6Proper Usage: §3/bending bind [Ability] <Slot>");
s.sendMessage("§eThis command will bind an ability to the slot you specify (if you specify one), or the slot currently"
+ " selected in your hotbar (If you do not specify a Slot #).");
}
if (Methods.abilityExists(args[1])) {
String ability = Methods.getAbility(args[1]);
if (Methods.isAirAbility(ability)) {
s.sendMessage("§7" + ability + " - ");
s.sendMessage("§7" + AbilityModuleManager.descriptions.get(ability));
}
if (Methods.isWaterAbility(ability)) {
s.sendMessage("§b" + ability + " - ");
s.sendMessage("§b" + AbilityModuleManager.descriptions.get(ability));
}
if (Methods.isEarthAbility(ability)) {
s.sendMessage("§a" + ability + " - ");
s.sendMessage("§a" + AbilityModuleManager.descriptions.get(ability));
}
if (Methods.isFireAbility(ability)) {
s.sendMessage("§c" + ability + " - ");
s.sendMessage("§c" + AbilityModuleManager.descriptions.get(ability));
}
if (Methods.isChiAbility(ability)) {
s.sendMessage("§6" + ability + " - ");
s.sendMessage("§6" + AbilityModuleManager.descriptions.get(ability));
}
}
}
return true;
}
}; projectkorra.setExecutor(exe);
}
}

View file

@ -0,0 +1,69 @@
package com.projectkorra.ProjectKorra;
import java.util.ArrayList;
public class ConfigManager {
static ProjectKorra plugin;
public ConfigManager(ProjectKorra plugin) {
ConfigManager.plugin = plugin;
configCheck();
}
public static void configCheck() {
ArrayList<String> earthbendable = new ArrayList<String>();
earthbendable.add("STONE");
earthbendable.add("COAL_ORE");
earthbendable.add("DIAMOND_ORE");
earthbendable.add("DIRT");
earthbendable.add("GOLD_ORE");
earthbendable.add("GRASS");
earthbendable.add("GRAVEL");
earthbendable.add("IRON_ORE");
earthbendable.add("LAPIS_ORE");
earthbendable.add("NETHERRACK");
earthbendable.add("REDSTONE_ORE");
earthbendable.add("SAND");
earthbendable.add("SANDSTONE");
plugin.getConfig().addDefault("Properties.GlobalCooldown", 500);
plugin.getConfig().addDefault("Properties.Air.CanBendWithWeapons", false);
plugin.getConfig().addDefault("Properties.Water.CanBendWithWeapons", true);
plugin.getConfig().addDefault("Properties.Water.NightFactor", 1.5);
plugin.getConfig().addDefault("Properties.Earth.CanBendWithWeapons", true);
plugin.getConfig().addDefault("Properties.Earth.EarthbendableBlocks", earthbendable);
plugin.getConfig().addDefault("Properties.Fire.CanBendWithWeapons", true);
plugin.getConfig().addDefault("Properties.Fire.NightFactor", 1.5);
plugin.getConfig().addDefault("Properties.Chi.CanBendWithWeapons", true);
plugin.getConfig().addDefault("Abilities.Air.Passive.Factor", 0.3);
plugin.getConfig().addDefault("Abilities.Air.Passive.Speed", 2);
plugin.getConfig().addDefault("Abilities.Air.Passive.Jump", 3);
plugin.getConfig().addDefault("Abilities.Water.Passive.SwimSpeedFactor", 0.7);
plugin.getConfig().addDefault("Abilities.Water.Plantbending.RegrowTime", 180000);
plugin.getConfig().addDefault("Abilities.Earth.Passive.Duration", 2500);
plugin.getConfig().addDefault("Abilities.Chi.Passive.FallReductionFactor", 0.5);
plugin.getConfig().addDefault("Abilities.Chi.Passive.Speed", 1);
plugin.getConfig().addDefault("Abilities.Chi.Passive.Jump", 2);
plugin.getConfig().addDefault("Storage.engine", "sqlite");
plugin.getConfig().addDefault("Storage.MySQL.host", "localhost");
plugin.getConfig().addDefault("Storage.MySQL.port", 3306);
plugin.getConfig().addDefault("Storage.MySQL.pass", "");
plugin.getConfig().addDefault("Storage.MySQL.db", "minecraft");
plugin.getConfig().addDefault("Storage.MySQL.user", "root");
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
}
}

View file

@ -0,0 +1,68 @@
package com.projectkorra.ProjectKorra;
import com.projectkorra.ProjectKorra.Storage.Database;
import com.projectkorra.ProjectKorra.Storage.MySQL;
import com.projectkorra.ProjectKorra.Storage.SQLite;
public class DBConnection {
public static Database sql;
public static String host;
public static int port;
public static String db;
public static String user;
public static String pass;
public static void init() {
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
sql = new MySQL(ProjectKorra.log, "[ProjectKorra] Establishing MySQL Connection...", host, port, user, pass, db);
((MySQL) sql).open();
ProjectKorra.log.info("[ProjectKorra] Database connection established.");
if (!sql.tableExists("pk_players")) {
ProjectKorra.log.info("Creating pk_players table");
String query = "CREATE TABLE `pk_players` ("
+ "`id` int(32) NOT NULL AUTO_INCREMENT,"
+ "`uuid` varchar(255),"
+ "`player` varchar(255),"
+ "`element` varchar(255),"
+ "`permaremoved` varchar(5),"
+ "`slot1` varchar(255),"
+ "`slot2` varchar(255),"
+ "`slot3` varchar(255),"
+ "`slot4` varchar(255),"
+ "`slot5` varchar(255),"
+ "`slot6` varchar(255),"
+ "`slot7` varchar(255),"
+ "`slot8` varchar(255),"
+ "`slot9` varchar(255),"
+ " PRIMARY KEY (id));";
sql.modifyQuery(query);
}
} else {
sql = new SQLite(ProjectKorra.log, "[ProjectKorra] Establishing SQLite Connection.", "projectkorra.db", ProjectKorra.plugin.getDataFolder().getAbsolutePath());
((SQLite) sql).open();
if (!sql.tableExists("pk_players")) {
ProjectKorra.log.info("Creating pk_players table.");
String query = "CREATE TABLE `pk_players` ("
+ "`id` INTEGER PRIMARY KEY,"
+ "`uuid` TEXT(255),"
+ "`player` TEXT(255),"
+ "`element` TEXT(255),"
+ "`permaremoved` TEXT(5),"
+ "`slot1` TEXT(255),"
+ "`slot2` TEXT(255),"
+ "`slot3` TEXT(255),"
+ "`slot4` TEXT(255),"
+ "`slot5` TEXT(255),"
+ "`slot6` TEXT(255),"
+ "`slot7` TEXT(255),"
+ "`slot8` TEXT(255),"
+ "`slot9` TEXT(255));";
sql.modifyQuery(query);
}
}
}
}

View file

@ -0,0 +1,15 @@
package com.projectkorra.ProjectKorra;
public enum Element {
Air, Water, Earth, Fire, Chi;
public static Element getType(String string) {
for (Element element: Element.values()) {
if (element.toString().equalsIgnoreCase(string)) {
return element;
}
}
return null;
}
}

View file

@ -0,0 +1,559 @@
package com.projectkorra.ProjectKorra;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import com.projectkorra.ProjectKorra.Ability.AbilityModule;
import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager;
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
public class Methods {
static ProjectKorra plugin;
public Methods(ProjectKorra plugin) {
Methods.plugin = plugin;
}
public static boolean isBender(String player, Element element) {
BendingPlayer bPlayer = getBendingPlayer(player);
if (bPlayer.hasElement(element)) return true;
return false;
}
public static BendingPlayer getBendingPlayer(String player) {
return BendingPlayer.players.get(player);
}
public static void createBendingPlayer(UUID uuid, String player) {
/*
* This will run when the player logs in.
*/
ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
try {
if (!rs2.next()) { // Data doesn't exist, we want a completely new player.
new BendingPlayer(uuid, player, new ArrayList<Element>(), new HashMap<Integer, String>(), false);
DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')");
ProjectKorra.log.info("Created new BendingPlayer for " + player);
} else {
// The player has at least played before.
String player2 = rs2.getString("player");
if (!player.equalsIgnoreCase(player2)) DBConnection.sql.modifyQuery("UPDATE pk_players SET player = '" + player2 + "' WHERE uuid = '" + uuid.toString() + "'"); // They have changed names.
String element = rs2.getString("element");
String permaremoved = rs2.getString("permaremoved");
String slot1 = rs2.getString("slot1");
String slot2 = rs2.getString("slot2");
String slot3 = rs2.getString("slot3");
String slot4 = rs2.getString("slot4");
String slot5 = rs2.getString("slot5");
String slot6 = rs2.getString("slot6");
String slot7 = rs2.getString("slot7");
String slot8 = rs2.getString("slot8");
String slot9 = rs2.getString("slot9");
boolean p = false;
ArrayList<Element> elements = new ArrayList<Element>();
if (element != null) { // Player has an element.
if (element.contains("a")) elements.add(Element.Air);
if (element.contains("w")) elements.add(Element.Water);
if (element.contains("e")) elements.add(Element.Earth);
if (element.contains("f")) elements.add(Element.Fire);
if (element.contains("c")) elements.add(Element.Chi);
}
HashMap<Integer, String> abilities = new HashMap<Integer, String>();
if (slot1 != null) abilities.put(1, slot1);
if (slot2 != null) abilities.put(2, slot2);
if (slot3 != null) abilities.put(3, slot3);
if (slot4 != null) abilities.put(4, slot4);
if (slot5 != null) abilities.put(5, slot5);
if (slot6 != null) abilities.put(6, slot6);
if (slot7 != null) abilities.put(7, slot7);
if (slot8 != null) abilities.put(8, slot8);
if (slot9 != null) abilities.put(9, slot9);
if (permaremoved == null) p = false;
if (permaremoved.equals("true")) p = true;
if (permaremoved.equals("false")) p = false;
new BendingPlayer(uuid, player2, elements, abilities, p);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void saveBendingPlayer(String player) {
BendingPlayer bPlayer = BendingPlayer.players.get(player);
if (bPlayer == null) return;
String uuid = bPlayer.uuid.toString();
StringBuilder elements = new StringBuilder();
if (bPlayer.hasElement(Element.Air)) elements.append("a");
if (bPlayer.hasElement(Element.Water)) elements.append("w");
if (bPlayer.hasElement(Element.Earth)) elements.append("e");
if (bPlayer.hasElement(Element.Fire)) elements.append("f");
if (bPlayer.hasElement(Element.Chi)) elements.append("c");
HashMap<Integer, String> abilities = bPlayer.abilities;
if (abilities.get(1) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot1 = '" + abilities.get(1) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(2) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot2 = '" + abilities.get(2) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(3) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot3 = '" + abilities.get(3) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(4) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot4 = '" + abilities.get(4) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(5) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot5 = '" + abilities.get(5) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(6) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot6 = '" + abilities.get(6) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(7) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot7 = '" + abilities.get(7) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(8) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot8 = '" + abilities.get(8) + "' WHERE uuid = '" + uuid + "'");
if (abilities.get(9) != null) DBConnection.sql.modifyQuery("UPDATE pk_players SET slot9 = '" + abilities.get(9) + "' WHERE uuid = '" + uuid + "'");
DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements + "' WHERE uuid = '" + uuid + "'");
boolean permaRemoved = bPlayer.permaRemoved;
if (permaRemoved) {
DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = 'true' WHERE uuid = '" + uuid + "'");
} else {
DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = 'false' WHERE uuid = '" + uuid + "'");
}
}
public static void stopBending() {
List<AbilityModule> abilities = AbilityModuleManager.ability;
for (AbilityModule ab: abilities) {
ab.stop();
}
EarthPassive.removeAll();
}
public static boolean isSolid(Block block) {
if (Arrays.asList(nonOpaque).contains(block.getTypeId())) return false;
return true;
}
public static String getAbility(String string) {
for (String st: AbilityModuleManager.abilities) {
if (st.equalsIgnoreCase(string)) return st;
}
return null;
}
public static void bindAbility(Player player, String ability) {
int slot = player.getInventory().getHeldItemSlot() + 1;
BendingPlayer bPlayer = getBendingPlayer(player.getName());
bPlayer.abilities.put(slot, ability);
}
public static void bindAbility(Player player, String ability, int slot) {
BendingPlayer bPlayer = getBendingPlayer(player.getName());
bPlayer.abilities.put(slot, ability);
}
public static boolean abilityExists(String string) {
if (getAbility(string) == null) return false;
return true;
}
public static List<Entity> getEntitiesAroundPoint(Location location,
double radius) {
List<Entity> entities = location.getWorld().getEntities();
List<Entity> list = location.getWorld().getEntities();
for (Entity entity : entities) {
if (entity.getWorld() != location.getWorld()) {
list.remove(entity);
} else if (entity.getLocation().distance(location) > radius) {
list.remove(entity);
}
}
return list;
}
public static Entity getTargetedEntity(Player player, double range,
List<Entity> avoid) {
double longestr = range + 1;
Entity target = null;
Location origin = player.getEyeLocation();
Vector direction = player.getEyeLocation().getDirection().normalize();
for (Entity entity : origin.getWorld().getEntities()) {
if (avoid.contains(entity))
continue;
if (entity.getLocation().distance(origin) < longestr
&& getDistanceFromLine(direction, origin,
entity.getLocation()) < 2
&& (entity instanceof LivingEntity)
&& entity.getEntityId() != player.getEntityId()
&& entity.getLocation().distance(
origin.clone().add(direction)) < entity
.getLocation().distance(
origin.clone().add(
direction.clone().multiply(-1)))) {
target = entity;
longestr = entity.getLocation().distance(origin);
}
}
return target;
}
public static boolean isAbilityInstalled(String name, String author) {
String ability = getAbility(name);
if (ability == null) return false;
if (AbilityModuleManager.authors.get(name).equalsIgnoreCase(author)) return true;
return false;
}
public static double getDistanceFromLine(Vector line, Location pointonline,
Location point) {
Vector AP = new Vector();
double Ax, Ay, Az;
Ax = pointonline.getX();
Ay = pointonline.getY();
Az = pointonline.getZ();
double Px, Py, Pz;
Px = point.getX();
Py = point.getY();
Pz = point.getZ();
AP.setX(Px - Ax);
AP.setY(Py - Ay);
AP.setZ(Pz - Az);
return (AP.crossProduct(line).length()) / (line.length());
}
public static boolean canBend(String player, String ability) {
BendingPlayer bPlayer = getBendingPlayer(player);
Player p = Bukkit.getPlayer(player);
if (!bPlayer.isToggled) return false;
if (p == null) return false;
if (!p.hasPermission("bending.ability." + ability)) return false;
if (isAirAbility(ability) && !isBender(player, Element.Air)) return false;
if (isWaterAbility(ability) && !isBender(player, Element.Water)) return false;
if (isEarthAbility(ability) && !isBender(player, Element.Earth)) return false;
if (isFireAbility(ability) && !isBender(player, Element.Fire)) return false;
if (isChiAbility(ability) && !isBender(player, Element.Chi)) return false;
return true;
}
public static boolean canBendPassive(String player, Element element) {
BendingPlayer bPlayer = getBendingPlayer(player);
if (!bPlayer.isToggled) return false;
if (!bPlayer.hasElement(element)) return false;
return true;
}
public static boolean isAirAbility(String ability) {
return AbilityModuleManager.airbendingabilities.contains(ability);
}
public static boolean isWaterAbility(String ability) {
return AbilityModuleManager.waterbendingabilities.contains(ability);
}
public static boolean isEarthAbility(String ability) {
return AbilityModuleManager.earthbendingabilities.contains(ability);
}
public static boolean isFireAbility(String ability) {
return AbilityModuleManager.firebendingabilities.contains(ability);
}
public static boolean isChiAbility(String ability) {
return AbilityModuleManager.chiabilities.contains(ability);
}
public static boolean isWater(Block block) {
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) return true;
return false;
}
public static String getBoundAbility(Player player) {
BendingPlayer bPlayer = getBendingPlayer(player.getName());
int slot = player.getInventory().getHeldItemSlot() + 1;
return bPlayer.abilities.get(slot);
}
public static boolean isWaterbendable(Block block, Player player) {
byte full = 0x0;
if (TempBlock.isTempBlock(block)) return false;
if ((block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) && block.getData() == full) return true;
if (block.getType() == Material.ICE || block.getType() == Material.SNOW || block.getType() == Material.PACKED_ICE) return true;
if (canPlantbend(player) && isPlant(block)) return true;
return false;
}
public static boolean canPlantbend(Player player) {
return player.hasPermission("bending.ability.plantbending");
}
public static boolean isPlant(Block block) {
if (Arrays.asList(plantIds).contains(block.getTypeId())) return true;
return false;
}
public static boolean isAdjacentToThreeOrMoreSources(Block block) {
if (TempBlock.isTempBlock(block)) return false;
int sources = 0;
byte full = 0x0;
BlockFace[] faces = {BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH };
for (BlockFace face: faces) {
Block blocki = block.getRelative(face);
if (isWater(block) && blocki.getData() == full) sources++;
if (blocki.getType() == Material.ICE || blocki.getType() == Material.PACKED_ICE) sources++;
}
if (sources >= 2) return true;
return false;
}
public static List<Block> getBlocksAroundPoint(Location location, double radius) {
List<Block> blocks = new ArrayList<Block>();
int xorg = location.getBlockX();
int yorg = location.getBlockY();
int zorg = location.getBlockZ();
int r = (int) radius * 4;
for (int x = xorg - r; x <= xorg + r; x++) {
for (int y = yorg - r; y <= yorg + r; y++) {
for (int z = zorg - r; z <= zorg + r; z++) {
Block block = location.getWorld().getBlockAt(x, y, z);
// if
// (block.getLocation().distance(originblock.getLocation())
// <= radius) {
if (block.getLocation().distance(location) <= radius) {
blocks.add(block);
}
}
}
}
return blocks;
}
public static boolean isEarthbendable(Player player, Block block) {
Material material = block.getType();
for (String s: plugin.getConfig().getStringList("Properties.Earth.EarthbendableBlocks")) {
if (material == Material.getMaterial(s)) {
return true;
}
}
return false;
}
public static boolean isChiBlocked(String player) {
long currTime = System.currentTimeMillis();
long duration = ProjectKorra.plugin.getConfig().getLong("Abilities.Chi.Passive.BlockChi.Duration");
if (BendingPlayer.blockedChi.contains(player)) {
if (BendingPlayer.blockedChi.get(player) + duration >= currTime) {
BendingPlayer.blockedChi.remove(player);
return false;
}
}
return true;
}
public static boolean isWeapon(Material mat) {
if (mat == null) return false;
if (mat == Material.WOOD_AXE || mat == Material.WOOD_PICKAXE
|| mat == Material.WOOD_SPADE || mat == Material.WOOD_SWORD
|| mat == Material.STONE_AXE || mat == Material.STONE_PICKAXE
|| mat == Material.STONE_SPADE || mat == Material.STONE_SWORD
|| mat == Material.IRON_AXE || mat == Material.IRON_PICKAXE
|| mat == Material.IRON_SWORD || mat == Material.IRON_SPADE
|| mat == Material.DIAMOND_AXE || mat == Material.DIAMOND_PICKAXE
|| mat == Material.DIAMOND_SWORD || mat == Material.DIAMOND_SPADE)
return true;
return false;
}
public static boolean isTransparentToEarthbending(Player player, Block block) {
if (Arrays.asList(transparentToEarthbending).contains(block.getTypeId())) return true;
return false;
}
public static double firebendingDayAugment(double value, World world) {
if (isDay(world)) {
return plugin.getConfig().getDouble("Properties.Fire.DayFactor") * value;
}
return value;
}
public static double getFirebendingDayAugment(World world) {
if (isDay(world)) return plugin.getConfig().getDouble("Properties.Fire.DayFactor");
return 1;
}
public static double waterbendingNightAugment(double value, World world) {
if (isNight(world)) {
return plugin.getConfig().getDouble("Properties.Water.NightFactor") * value;
}
return value;
}
public static double getWaterbendingNightAugment(World world) {
if (isNight(world)) return plugin.getConfig().getDouble("Properties.Water.NightFactor");
return 1;
}
public static boolean isNight(World world) {
if (world.getEnvironment() == Environment.NETHER || world.getEnvironment() == Environment.THE_END) {
return false;
}
long time = world.getTime();
if (time >= 12950 && time <= 23050) {
return true;
}
return false;
}
public static void damageEntity(Player player, Entity entity, double damage) {
if (entity instanceof LivingEntity) {
((LivingEntity) entity).damage(damage, player);
((LivingEntity) entity)
.setLastDamageCause(new EntityDamageByEntityEvent(player,
entity, DamageCause.CUSTOM, damage));
}
}
public static boolean isDay(World world) {
long time = world.getTime();
if (time >= 23500 || time <= 12500) {
return true;
}
return false;
}
public static int getIntCardinalDirection(Vector vector) {
BlockFace face = getCardinalDirection(vector);
switch (face) {
case SOUTH:
return 7;
case SOUTH_WEST:
return 6;
case WEST:
return 3;
case NORTH_WEST:
return 0;
case NORTH:
return 1;
case NORTH_EAST:
return 2;
case EAST:
return 5;
case SOUTH_EAST:
return 8;
}
return 4;
}
public static Collection<ItemStack> getDrops(Block block, Material type,
byte data, ItemStack breakitem) {
BlockState tempstate = block.getState();
block.setType(type);
block.setData(data);
Collection<ItemStack> item = block.getDrops();
tempstate.update(true);
return item;
}
public static void dropItems(Block block, Collection<ItemStack> items) {
for (ItemStack item : items)
block.getWorld().dropItem(block.getLocation(), item);
}
public static Location getTargetedLocation(Player player, int range) {
return getTargetedLocation(player, range, 0);
}
public static Location getTargetedLocation(Player player,
double originselectrange, Integer... nonOpaque2) {
Location origin = player.getEyeLocation();
Vector direction = origin.getDirection();
HashSet<Byte> trans = new HashSet<Byte>();
trans.add((byte) 0);
if (nonOpaque2 == null) {
trans = null;
} else {
for (int i : nonOpaque2) {
trans.add((byte) i);
}
}
Block block = player.getTargetBlock(trans, (int) originselectrange + 1);
double distance = block.getLocation().distance(origin) - 1.5;
Location location = origin.add(direction.multiply(distance));
return location;
}
public static BlockFace getCardinalDirection(Vector vector) {
BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST,
BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH,
BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
Vector n, ne, e, se, s, sw, w, nw;
w = new Vector(-1, 0, 0);
n = new Vector(0, 0, -1);
s = n.clone().multiply(-1);
e = w.clone().multiply(-1);
ne = n.clone().add(e.clone()).normalize();
se = s.clone().add(e.clone()).normalize();
nw = n.clone().add(w.clone()).normalize();
sw = s.clone().add(w.clone()).normalize();
Vector[] vectors = { n, ne, e, se, s, sw, w, nw };
double comp = 0;
int besti = 0;
for (int i = 0; i < vectors.length; i++) {
double dot = vector.dot(vectors[i]);
if (dot > comp) {
comp = dot;
besti = i;
}
}
return faces[besti];
}
private static Integer[] plantIds = { 6, 18, 31, 32, 37, 38, 39, 40, 59, 81, 83, 86, 99, 100, 103, 104, 105, 106, 111, 161, 175};
public static Integer[] transparentToEarthbending = {0, 6, 8, 9, 10, 11, 30, 31, 32, 37, 38, 39, 40, 50, 51, 59, 78, 83, 106};
public static Integer[] nonOpaque = {0, 6, 8, 9, 10, 11, 27, 28, 30, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 68, 69, 70, 72,
75, 76, 77, 78, 83, 90, 93, 94, 104, 105, 106, 111, 115, 119, 127, 131, 132};
}

View file

@ -0,0 +1,88 @@
package com.projectkorra.ProjectKorra;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.projectkorra.ProjectKorra.airbending.chiblocking.ChiPassive;
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
import com.projectkorra.ProjectKorra.waterbending.WaterPassive;
public class PKListener implements Listener {
ProjectKorra plugin;
public PKListener(ProjectKorra plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Methods.createBendingPlayer(e.getPlayer().getUniqueId(), e.getPlayer().getName());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
Methods.saveBendingPlayer(e.getPlayer().getName());
BendingPlayer.players.remove(e.getPlayer().getName());
}
@EventHandler
public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) {
Entity en = e.getEntity();
if (en instanceof Player) {
Player p = (Player) en; // This is the player getting hurt.
if (e.getDamager() instanceof Player) { // This is the player hitting someone.
Player damager = (Player) e.getDamager();
if (Methods.canBendPassive(damager.getName(), Element.Chi)) {
if (e.getCause() == DamageCause.ENTITY_ATTACK) {
if (damager.getItemInHand() != null && Methods.isWeapon(damager.getItemInHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) {
// Above method checks if the player has an item in their hand, if it is a weapon, and if they can bend with weapons.
if (Methods.getBoundAbility(damager) == null) { // We don't want them to be able to block chi if an ability is bound.
if (ChiPassive.willChiBlock(p)) {
ChiPassive.blockChi(p);
}
}
}
}
}
}
}
}
@EventHandler
public void onPlayerDamage(EntityDamageEvent e) {
Entity en = e.getEntity();
if (en instanceof Player) { // Player is the one being hurt.
Player p = (Player) en;
if (e.getCause() == DamageCause.FALL) { // Result is Fall Damage
if (Methods.canBendPassive(p.getName(), Element.Air)) {
e.setDamage(0.0);
}
if (Methods.canBendPassive(p.getName(), Element.Chi)) {
double initdamage = e.getDamage();
double newdamage = e.getDamage() * ChiPassive.FallReductionFactor;
double finaldamage = initdamage - newdamage;
e.setDamage(finaldamage);
}
if (Methods.canBendPassive(p.getName(), Element.Water)) {
if (WaterPassive.applyNoFall(p)) {
e.setDamage(0.0);
}
}
if (Methods.canBendPassive(p.getName(), Element.Earth)) {
if (EarthPassive.softenLanding(p)) {
e.setDamage(0.0);
}
}
}
}
}
}

View file

@ -0,0 +1,51 @@
package com.projectkorra.ProjectKorra;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager;
public class ProjectKorra extends JavaPlugin {
public static ProjectKorra plugin;
public static Logger log;
@Override
public void onEnable() {
ProjectKorra.log = this.getLogger();
plugin = this;
new Methods(this);
getServer().getPluginManager().registerEvents(new PKListener(this), this);
new Commands(this);
new AbilityModuleManager(this);
new ConfigManager(this);
DBConnection.host = getConfig().getString("Storage.MySQL.host");
DBConnection.port = getConfig().getInt("Storage.MySQL.port");
DBConnection.pass = getConfig().getString("Storage.MySQL.pass");
DBConnection.db = getConfig().getString("Storage.MySQL.db");
DBConnection.user = getConfig().getString("Storage.MySQL.user");
getServer().getScheduler().scheduleSyncRepeatingTask(this, new BendingManager(this), 0, 1);
DBConnection.init();
for (Player player: Bukkit.getOnlinePlayers()) {
Methods.createBendingPlayer(player.getUniqueId(), player.getName());
}
}
@Override
public void onDisable() {
for (Player player: Bukkit.getOnlinePlayers()) {
Methods.saveBendingPlayer(player.getName());
}
DBConnection.sql.close();
}
}

View file

@ -0,0 +1,127 @@
package com.projectkorra.ProjectKorra.Storage;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.DatabaseMetaData;
import java.util.logging.Logger;
public abstract class Database {
protected final Logger log;
protected final String prefix;
protected final String dbprefix;
protected Connection connection = null;
public Database(Logger log, String prefix, String dbprefix) {
this.log = log;
this.prefix = prefix;
this.dbprefix = dbprefix;
}
/**
* Print information to console
*
* @param message The string to print to console
*/
protected void printInfo(String message) {
log.info(prefix + dbprefix + message);
}
/**
* Print error to console
*
* @param message The string to print to console
* @param severe If {@param severe} is true print an error, else print a warning
*/
protected void printErr(String message, boolean severe) {
if (severe) log.severe(prefix + dbprefix + message);
else log.warning(prefix + dbprefix + message);
}
/**
* Returns the current Connection
*
* @return Connection if exists, else null
*/
public Connection getConnection() {
return this.connection;
}
/**
* Opens connection to Database
*
* @return Connection if successful
*/
abstract Connection open();
/**
* Close connection to Database
*/
public void close() {
if (!(this.connection == null)) {
try {
this.connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
this.printErr("There was no SQL connection open.", false);
}
}
/**
* Queries the Database, for queries which modify data
*
* @param query Query to run
*/
public void modifyQuery(String query) {
try {
Statement stmt = this.connection.createStatement();
stmt.execute(query);
stmt.close();
} catch(SQLException e) {
e.printStackTrace();
}
}
/**
* Queries the Database, for queries which return results
*
* @param query Query to run
* @return Result set of ran query
*/
public ResultSet readQuery(String query) {
try {
Statement stmt = this.connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
return rs;
} catch(SQLException e) {
e.printStackTrace();
return null;
}
}
/**
* Check database to see if {@param table} exists
*
* @param table Table name to check
* @return True if table exists, else false
*/
public boolean tableExists(String table) {
try {
DatabaseMetaData dmd = this.connection.getMetaData();
ResultSet rs = dmd.getTables(null, null, table, null);
if(rs.next()) return true;
else return false;
} catch(Exception e) {
e.printStackTrace();
return false;
}
}
}

View file

@ -0,0 +1,51 @@
package com.projectkorra.ProjectKorra.Storage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;
public class MySQL extends Database {
private String host = "localhost";
private int port = 3306;
private String user;
private String pass = "";
private String database;
public MySQL(Logger log, String prefix, String host, int port, String user, String pass, String database) {
super(log, prefix, "[MySQL] ");
this.host = host;
this.port = port;
this.user = user;
this.pass = pass;
this.database = database;
}
public MySQL(Logger log, String prefix, String user, String pass, String database) {
super(log, prefix, "[MySQL] ");
this.user = user;
this.pass = pass;
this.database = database;
}
@Override
public Connection open() {
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database;
this.connection = DriverManager.getConnection(url, this.user, this.pass);
this.printInfo("Connection established!");
return this.connection;
} catch(ClassNotFoundException e) {
this.printErr("JDBC driver not found!", true);
return null;
} catch(SQLException e) {
e.printStackTrace();
return null;
}
}
}

View file

@ -0,0 +1,46 @@
package com.projectkorra.ProjectKorra.Storage;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;
public class SQLite extends Database {
private String location;
private String database;
private File SQLfile;
public SQLite(Logger log, String prefix, String database, String location) {
super(log, prefix, "[SQLite] ");
this.database = database;
this.location = location;
File folder = new File(this.location);
if (!folder.exists()) {
folder.mkdirs();
}
this.SQLfile = new File(folder.getAbsolutePath() + File.separator + this.database);
}
@Override
public Connection open() {
try {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.SQLfile.getAbsolutePath());
this.printInfo("Connection established!");
return this.connection;
} catch(ClassNotFoundException e) {
this.printErr("JDBC driver not found!", true);
return null;
} catch(SQLException e) {
this.printErr("SQL exception during connection.", true);
return null;
}
}
}

View file

@ -0,0 +1,121 @@
package com.projectkorra.ProjectKorra;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
public class TempBlock {
public static ConcurrentHashMap<Block, TempBlock> instances = new ConcurrentHashMap<Block, TempBlock>();
Block block;
Material newtype;
byte newdata;
BlockState state;
public TempBlock(Block block, Material newtype, byte newdata) {
this.block = block;
this.newdata = newdata;
this.newtype = newtype;
if (instances.containsKey(block)) {
TempBlock temp = instances.get(block);
if (newtype != temp.newtype) {
temp.block.setType(newtype);
temp.newtype = newtype;
}
if (newdata != temp.newdata) {
temp.block.setData(newdata);
temp.newdata = newdata;
}
state = temp.state;
instances.replace(block, temp);
} else {
state = block.getState();
block.setType(newtype);
block.setData(newdata);
instances.put(block, this);
}
if (state.getType() == Material.FIRE)
state.setType(Material.AIR);
}
public void revertBlock() {
state.update(true);
instances.remove(block);
}
public static void revertBlock(Block block, Material defaulttype) {
if (instances.containsKey(block)) {
instances.get(block).revertBlock();
} else {
if ((defaulttype == Material.WATER
|| defaulttype == Material.STATIONARY_WATER || defaulttype == Material.AIR)
&& Methods.isAdjacentToThreeOrMoreSources(block)) {
block.setType(Material.WATER);
block.setData((byte) 0x0);
} else {
block.setType(defaulttype);
}
}
// block.setType(defaulttype);
}
public static void removeBlock(Block block) {
if (instances.containsKey(block)) {
instances.remove(block);
}
}
public static boolean isTempBlock(Block block) {
if (instances.containsKey(block))
return true;
return false;
}
public static boolean isTouchingTempBlock(Block block) {
BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST,
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN };
for (BlockFace face : faces) {
if (instances.containsKey(block.getRelative(face)))
return true;
}
return false;
}
public static TempBlock get(Block block) {
if (isTempBlock(block))
return instances.get(block);
return null;
}
public Location getLocation() {
return block.getLocation();
}
public Block getBlock() {
return block;
}
public static void removeAll() {
for (Block block : instances.keySet()) {
revertBlock(block, Material.AIR);
}
}
public void setType(Material material) {
setType(material, newdata);
}
public void setType(Material material, byte data) {
newtype = material;
newdata = data;
block.setType(material);
block.setData(data);
}
}

View file

@ -0,0 +1,57 @@
package com.projectkorra.ProjectKorra.airbending;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.projectkorra.ProjectKorra.Element;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
public class AirPassive {
private static ConcurrentHashMap<Player, Float> food = new ConcurrentHashMap<Player, Float>();
private static float factor = (float) ProjectKorra.plugin.getConfig().getDouble("Abilities.Air.Passive.Factor");
private static int speedPower = ProjectKorra.plugin.getConfig().getInt("Abilities.Air.Passive.Speed");
private static int jumpPower = ProjectKorra.plugin.getConfig().getInt("Abilities.Air.Passive.Jump");
public static float getExhaustion(Player player, float level) {
if (!food.keySet().contains(player)) {
food.put(player, level);
return level;
} else {
float oldlevel = food.get(player);
if (level < oldlevel) {
level = 0;
} else {
level = (level - oldlevel) * factor + oldlevel;
}
food.replace(player, level);
return level;
}
}
public static void handlePassive(Server server) {
for (World world: server.getWorlds()) {
for (Player player: world.getPlayers()) {
if (!player.isOnline()) return;
if (Methods.canBendPassive(player.getName(), Element.Air)) {
player.setExhaustion(getExhaustion(player, player.getExhaustion())); // Handles Food Passive
if (player.isSprinting()) {
if (!player.hasPotionEffect(PotionEffectType.SPEED)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, speedPower - 1)); // Handles Speed Passive
}
if (!player.hasPotionEffect(PotionEffectType.JUMP)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, jumpPower - 1)); // Handles jump passive.
}
}
}
}
}
}
}

View file

@ -0,0 +1,56 @@
package com.projectkorra.ProjectKorra.airbending.chiblocking;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.projectkorra.ProjectKorra.BendingPlayer;
import com.projectkorra.ProjectKorra.Element;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
public class ChiPassive {
public static double FallReductionFactor = ProjectKorra.plugin.getConfig().getDouble("Abilities.Chi.Passive.FallReductionFactor");
public static int jumpPower = ProjectKorra.plugin.getConfig().getInt("Abilities.Chi.Passive.Jump");
public static int speedPower = ProjectKorra.plugin.getConfig().getInt("Abilities.Chi.Passive.Speed");
public static int dodgeChance = ProjectKorra.plugin.getConfig().getInt("Abilities.Chi.Passive.ChiBlock.DodgeChance");
public static int duration = ProjectKorra.plugin.getConfig().getInt("Abilities.Chi.Passive.ChiBlock.Duration");
public static boolean willChiBlock(Player player) {
Random rand = new Random();
if (rand.nextInt(99) + 1 < dodgeChance) {
return false;
}
if (Methods.isChiBlocked(player.getName())) return false;
return true;
}
public static void blockChi(Player player) {
BendingPlayer.blockedChi.put(player.getName(), System.currentTimeMillis());
}
public static void handlePassive() {
for (Player player: Bukkit.getOnlinePlayers()) {
if (Methods.canBendPassive(player.getName(), Element.Chi)) {
if (player.isSprinting()) {
if (!player.hasPotionEffect(PotionEffectType.JUMP)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, jumpPower - 1));
}
if (!player.hasPotionEffect(PotionEffectType.SPEED)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, speedPower - 1));
}
}
}
if (BendingPlayer.blockedChi.contains(player.getName())) {
if (BendingPlayer.blockedChi.get(player.getName()) + duration >= System.currentTimeMillis()) {
BendingPlayer.blockedChi.remove(player.getName());
}
}
}
}
}

View file

@ -0,0 +1,84 @@
package com.projectkorra.ProjectKorra.earthbending;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
public class EarthPassive {
public static ConcurrentHashMap<Block, Long> sandblocks = new ConcurrentHashMap<Block, Long>();
public static ConcurrentHashMap<Block, Material> sandidentities = new ConcurrentHashMap<Block, Material>();
private static final long duration = ProjectKorra.plugin.getConfig().getLong("Abilities.Earth.Passive.Duration");
public static boolean softenLanding(Player player) {
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (Methods.isEarthbendable(player, block) || Methods.isTransparentToEarthbending(player, block)) {
if (!Methods.isTransparentToEarthbending(player, block)) {
Material type = block.getType();
if (Methods.isSolid(block.getRelative(BlockFace.DOWN))) {
block.setType(Material.SAND);
if (!sandblocks.containsKey(block)) {
sandidentities.put(block, type);
sandblocks.put(block, System.currentTimeMillis());
}
}
}
for (Block affectedBlock: Methods.getBlocksAroundPoint(block.getLocation(), 2)) {
if (Methods.isEarthbendable(player, affectedBlock)) {
if (Methods.isSolid(affectedBlock.getRelative(BlockFace.DOWN))) {
Material type = affectedBlock.getType();
affectedBlock.setType(Material.SAND);
if (!sandblocks.containsKey(affectedBlock)) {
sandidentities.putIfAbsent(affectedBlock, type);
sandblocks.put(affectedBlock, System.currentTimeMillis());
}
}
}
}
return true;
}
if (Methods.isEarthbendable(player, block) || Methods.isTransparentToEarthbending(player, block)) {
return true;
}
return false;
}
public static boolean isPassiveSand(Block block) {
return (sandblocks.containsKey(block));
}
public static void revertSand(Block block) {
Material type = sandidentities.get(block);
sandidentities.remove(block);
sandblocks.remove(block);
if (block.getType() == Material.SAND) {
block.setType(type);
}
}
public static void revertSands() {
for (Block block: sandblocks.keySet()) {
if (System.currentTimeMillis() >= sandblocks.get(block) + duration) {
revertSand(block);
}
}
}
public static void revertAllSand() {
for (Block block: sandblocks.keySet()) {
revertSand(block);
}
}
public static void removeAll() {
revertAllSand();
}
}

View file

@ -0,0 +1,21 @@
package com.projectkorra.ProjectKorra.firebending;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.Element;
import com.projectkorra.ProjectKorra.Methods;
public class FirePassive {
public static void handlePassive() {
for (Player player: Bukkit.getOnlinePlayers()) {
if (Methods.canBendPassive(player.getName(), Element.Fire)) {
if (player.getFireTicks() > 80) {
player.setFireTicks(80);
}
}
}
}
}

View file

@ -0,0 +1,196 @@
package com.projectkorra.ProjectKorra.firebending;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
import com.projectkorra.ProjectKorra.waterbending.Plantbending;
public class FireStream {
public static ConcurrentHashMap<Integer, FireStream> instances = new ConcurrentHashMap<Integer, FireStream>();
public static ConcurrentHashMap<Block, Player> ignitedblocks = new ConcurrentHashMap<Block, Player>();
public static ConcurrentHashMap<Block, Long> ignitedtimes = new ConcurrentHashMap<Block, Long>();
public static ConcurrentHashMap<LivingEntity, Player> ignitedentities = new ConcurrentHashMap<LivingEntity, Player>();
static final long soonesttime = ProjectKorra.plugin.getConfig().getLong("Properties.GlobalCooldown");
public static int firedamage = 3;
public static int tickdamage = 2;
private static int ID = Integer.MIN_VALUE;
private static double speed = 15;
private static long interval = (long) (1000. / speed);
private static long dissipateAfter = 400;
private Player player;
private Location origin;
private Location location;
private Vector direction;
private int id;
private long time;
private double range;
public FireStream(Location location, Vector direction, Player player,
int range) {
this.range = Methods.firebendingDayAugment(range, player.getWorld());
this.player = player;
origin = location.clone();
this.location = origin.clone();
this.direction = direction.clone();
this.direction.setY(0);
this.direction = this.direction.clone().normalize();
this.location = this.location.clone().add(this.direction);
id = ID;
if (ID >= Integer.MAX_VALUE) {
ID = Integer.MIN_VALUE;
}
ID++;
time = System.currentTimeMillis();
instances.put(id, this);
}
public boolean progress() {
// if (Tools.isRegionProtectedFromBuild(player, Abilities.Blaze, location)) {
// remove();
// return false;
// }
if (System.currentTimeMillis() - time >= interval) {
location = location.clone().add(direction);
time = System.currentTimeMillis();
if (location.distance(origin) > range) {
remove();
return false;
}
Block block = location.getBlock();
if (isIgnitable(player, block)) {
ignite(block);
return true;
} else if (isIgnitable(player, block.getRelative(BlockFace.DOWN))) {
ignite(block.getRelative(BlockFace.DOWN));
location = block.getRelative(BlockFace.DOWN).getLocation();
return true;
} else if (isIgnitable(player, block.getRelative(BlockFace.UP))) {
ignite(block.getRelative(BlockFace.UP));
location = block.getRelative(BlockFace.UP).getLocation();
return true;
} else {
remove();
return false;
}
}
return false;
}
private void ignite(Block block) {
if (Methods.isPlant(block)) {
new Plantbending(block);
}
block.setType(Material.FIRE);
ignitedblocks.put(block, this.player);
ignitedtimes.put(block, System.currentTimeMillis());
}
public static boolean isIgnitable(Player player, Block block) {
// if (Tools.isRegionProtectedFromBuild(player, Abilities.Blaze,
// block.getLocation()))
// return false;
Material[] overwriteable = { Material.SAPLING, Material.LONG_GRASS,
Material.DEAD_BUSH, Material.YELLOW_FLOWER, Material.RED_ROSE,
Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.FIRE,
Material.SNOW, Material.TORCH };
if (Arrays.asList(overwriteable).contains(block.getType())) {
return true;
} else if (block.getType() != Material.AIR) {
return false;
}
Material[] ignitable = { Material.BEDROCK, Material.BOOKSHELF,
Material.BRICK, Material.CLAY, Material.CLAY_BRICK,
Material.COAL_ORE, Material.COBBLESTONE, Material.DIAMOND_ORE,
Material.DIAMOND_BLOCK, Material.DIRT, Material.ENDER_STONE,
Material.GLOWING_REDSTONE_ORE, Material.GOLD_BLOCK,
Material.GRAVEL, Material.GRASS, Material.HUGE_MUSHROOM_1,
Material.HUGE_MUSHROOM_2, Material.LAPIS_BLOCK,
Material.LAPIS_ORE, Material.LOG, Material.MOSSY_COBBLESTONE,
Material.MYCEL, Material.NETHER_BRICK, Material.NETHERRACK,
Material.OBSIDIAN, Material.REDSTONE_ORE, Material.SAND,
Material.SANDSTONE, Material.SMOOTH_BRICK, Material.STONE,
Material.SOUL_SAND, Material.SNOW_BLOCK, Material.WOOD,
Material.WOOL, Material.LEAVES };
Block belowblock = block.getRelative(BlockFace.DOWN);
if (Arrays.asList(ignitable).contains(belowblock.getType())) {
return true;
}
return false;
}
private void remove() {
instances.remove(id);
}
public static void removeAll() {
for (Block block : ignitedblocks.keySet())
remove(block);
}
public static void dissipateAll() {
if (dissipateAfter != 0)
for (Block block : ignitedtimes.keySet()) {
if (block.getType() != Material.FIRE) {
remove(block);
} else {
long time = ignitedtimes.get(block);
if (System.currentTimeMillis() > time + dissipateAfter) {
block.setType(Material.AIR);
remove(block);
}
}
}
}
public static boolean progress(int ID) {
return instances.get(ID).progress();
}
public static String getDescription() {
return "This ability no longer exists.";
}
public static void remove(Block block) {
if (ignitedblocks.containsKey(block)) {
ignitedblocks.remove(block);
}
if (ignitedtimes.containsKey(block)) {
ignitedtimes.remove(block);
}
}
public static void removeAroundPoint(Location location, double radius) {
for (int id : instances.keySet()) {
FireStream stream = instances.get(id);
if (stream.location.getWorld().equals(location.getWorld()))
if (stream.location.distance(location) <= radius)
instances.remove(id);
}
}
}

View file

@ -0,0 +1,64 @@
package com.projectkorra.ProjectKorra.waterbending;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Material;
import org.bukkit.block.Block;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
public class Plantbending {
private static final long regrowtime = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.Plantbending.RegrowTime");
private static ConcurrentHashMap<Integer, Plantbending> instances = new ConcurrentHashMap<Integer, Plantbending>();
private static int ID = Integer.MIN_VALUE;
private Block block;
private Material type;
private byte data;
private long time;
private int id;
public Plantbending(Block block) {
if (regrowtime != 0) {
this.block = block;
type = block.getType();
data = block.getData();
time = System.currentTimeMillis() + regrowtime / 2
+ (long) (Math.random() * (double) regrowtime) / 2;
id = ID;
instances.put(id, this);
if (ID >= Integer.MAX_VALUE) {
ID = Integer.MIN_VALUE;
} else {
ID++;
}
}
}
private void revert() {
if (block.getType() == Material.AIR) {
block.setType(type);
block.setData(data);
} else {
Methods.dropItems(block, Methods.getDrops(block, type, data, null));
}
instances.remove(id);
}
public static void regrow() {
for (int id : instances.keySet()) {
Plantbending plantbending = instances.get(id);
if (plantbending.time < System.currentTimeMillis()) {
plantbending.revert();
}
}
}
public static void regrowAll() {
for (int id : instances.keySet())
instances.get(id).revert();
}
}

View file

@ -0,0 +1,48 @@
package com.projectkorra.ProjectKorra.waterbending;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.Element;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager;
public class WaterPassive {
private static double swimFactor = ProjectKorra.plugin.getConfig().getDouble("Abilities.Water.Passive.SwimSpeedFactor");
public static boolean applyNoFall(Player player) {
Block block = player.getLocation().getBlock();
Block fallblock = block.getRelative(BlockFace.DOWN);
if (Methods.isWaterbendable(block, player) && !Methods.isPlant(block)) return true;
if (fallblock.getType() == Material.AIR) return true;
if ((Methods.isWaterbendable(fallblock, player) && !Methods.isPlant(fallblock)) || fallblock.getType() == Material.SNOW_BLOCK)
return true;
return false;
}
public static void handlePassive() {
for (Player player: Bukkit.getServer().getOnlinePlayers()) {
String ability = Methods.getBoundAbility(player);
if (Methods.canBendPassive(player.getName(), Element.Water)) {
if (ability == null || !AbilityModuleManager.shiftabilities.contains(ability)) {
if (player.isSneaking() && Methods.isWater(player.getLocation().getBlock())) {
player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(swimFactor));
}
}
if (player.getLocation().getBlock().isLiquid()) {
for (Block block: Methods.getBlocksAroundPoint(player.getLocation(), 2)) {
if (Methods.isAdjacentToThreeOrMoreSources(block) && Methods.isWater(block)) {
byte full = 0x0;
block.setType(Material.WATER);
block.setData(full);
}
}
}
}
}
}
}

58
src/config.yml Normal file
View file

@ -0,0 +1,58 @@
Properties:
GlobalCooldown: 500
Air:
CanBendWithWeapons: false
Water:
CanBendWithWeapons: false
NightFactor: 1.5
Earth:
CanBendWithWeapons: true
EarthbendableBlocks:
- STONE
- COAL_ORE
- DIAMOND_ORE
- DIRT
- GOLD_ORE
- GRASS
- GRAVEL
- IRON_ORE
- LAPIS_ORE
- NETHERRACK
- REDSTONE_ORE
- SAND
- SANDSTONE
Fire:
CanBendWithWeapons: true
DayFactor: 1.5
Chi:
CanBendWithWeapons: false
Abilities:
Air:
Passive:
Factor: 0.3
Speed: 2
Jump: 3
Water:
Passive:
SwimSpeedFactor: 0.7
Plantbending:
RegrowTime: 180000
Earth:
Passive:
Duration: 2500
Chi:
Passive:
FallReductionFactor: 0.5
Speed: 1
Jump: 2
BlockChi:
Duration: 2500
DodgeChance: 25
Storage:
engine: sqlite
MySQL:
host: localhost
port: 3306
pass: ''
db: minecraft
user: root

8
src/plugin.yml Normal file
View file

@ -0,0 +1,8 @@
name: ProjectKorra
author: ProjectKorra
version: 0.0.0
main: com.projectkorra.ProjectKorra.ProjectKorra
commands:
projectkorra:
aliases: [bending,mtla,tla,korra]
usage: /<command>