Skip to content

Commit

Permalink
v3.1.0 - 1.13 support, a lot of new config options, SimpleClans suppo…
Browse files Browse the repository at this point in the history
…rt, bug fixes
  • Loading branch information
Realizedd committed Jul 28, 2018
1 parent f158c54 commit 225763b
Show file tree
Hide file tree
Showing 69 changed files with 1,270 additions and 318 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

allprojects {
group 'me.realized'
version '3.0.5-SNAPSHOT'
version '3.1.0'
}

subprojects {
Expand Down Expand Up @@ -66,6 +66,6 @@ subprojects {
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile 'com.google.code.findbugs:jsr305:3.0.2'
compile 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compile 'org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT'
}
}
101 changes: 101 additions & 0 deletions duels-api/src/main/java/me/realized/duels/api/Duels.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package me.realized.duels.api;

import javax.annotation.Nonnull;
import lombok.NonNull;
import me.realized.duels.api.arena.ArenaManager;
import me.realized.duels.api.command.SubCommand;
import me.realized.duels.api.kit.KitManager;
import me.realized.duels.api.user.UserManager;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;

public interface Duels extends Plugin {

@Nonnull
UserManager getUserManager();


@Nonnull
ArenaManager getArenaManager();


@Nonnull
KitManager getKitManager();

Expand All @@ -33,4 +37,101 @@ public interface Duels extends Plugin {
* @return true if reload was successful, otherwise false
*/
boolean reload();


/**
* Runs the task on server thread.
*
* @param task Task to run
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSync(@NonNull final Runnable task);


/**
* Runs the task after delay on server thread.
*
* @param task Task to run
* @param delay time to delay. 20L = 1s
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSyncAfter(@NonNull final Runnable task, long delay);


/**
* Runs the task after delay on server thread repeatedly.
*
* @param task Task to run
* @param delay time to delay the start of repeat. 20L = 1s
* @param interval interval of this task. 20L = 1s
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doSyncRepeat(@NonNull final Runnable task, long delay, long interval);


/**
* Runs the task asynchronously.
*
* @param task Task to run asynchronously
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsync(@NonNull final Runnable task);


/**
* Runs the task after delay asynchronously.
*
* @param task Task to run asynchronously
* @param delay time to delay. 20L = 1s
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsyncAfter(@NonNull final Runnable task, long delay);


/**
* Runs the task after delay asynchronously repeatedly.
*
* @param task Task to run asynchronously
* @param delay time to delay the start of repeat. 20L = 1s
* @param interval interval of this task. 20L = 1s
* @return BukkitTask executed
* @since 3.1.0
*/
BukkitTask doAsyncRepeat(@NonNull final Runnable task, long delay, long interval);


/**
* @param message message to log
*/
void info(@NonNull final String message);


/**
* @param message message to log
*/
void warn(@NonNull final String message);


/**
* @param message message to log
*/
void error(@NonNull final String message);


/**
* @param message message to log
*/
void error(@NonNull final String message, @NonNull Throwable thrown);


/**
* @return version of the plugin
* @since 3.1.0
*/
String getVersion();
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
package me.realized.duels.api.extension;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Objects;
import java.util.logging.Level;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.NonNull;
import me.realized.duels.api.Duels;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public abstract class DuelsExtension {

protected Duels api;

@Getter
private boolean enabled;
private String name;
@Getter
private File folder;
@Getter
private File file;
@Getter
private File dataFolder;

final void init(final Duels api, final File folder, final File file) {
@Getter
private boolean enabled;

private File configFile;
private FileConfiguration config;

final void init(final Duels api, final String name, final File folder, final File file) {
this.api = api;
this.name = name;
this.folder = folder;
this.file = file;
this.dataFolder = new File(folder, name);
this.configFile = new File(dataFolder, "config.yml");
}

@NonNull
public final String getName() {
return getClass().getSimpleName();
return name;
}

public final void setEnabled(final boolean enabled) {
Expand All @@ -39,7 +62,90 @@ public final void setEnabled(final boolean enabled) {
this.enabled = enabled;
}

public void saveResource(@NonNull String resourcePath) {
Objects.requireNonNull(resourcePath, "resourcePath");
resourcePath = resourcePath.replace('\\', '/');

try (InputStream in = getResource(resourcePath)) {
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + file);
}

if (!dataFolder.exists()) {
dataFolder.mkdir();
}

final File outFile = new File(dataFolder, resourcePath);
int lastIndex = resourcePath.lastIndexOf('/');
File outDir = new File(dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));

if (!outDir.exists()) {
outDir.mkdirs();
}

try (OutputStream out = new FileOutputStream(outFile)) {
final byte[] buf = new byte[1024];
int len;

while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
}
} catch (IOException ex) {
api.error("Could not save resource '" + resourcePath + "'", ex);
}
}

@Nullable
public InputStream getResource(@NonNull final String filename) {
Objects.requireNonNull(filename, "filename");

try {
final URL url = getClass().getClassLoader().getResource(filename);

if (url == null) {
return null;
}

final URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
} catch (IOException ex) {
api.error("Could not find resource with filename '" + filename + "'", ex);
return null;
}
}

public FileConfiguration getConfig() {
if (config == null) {
reloadConfig();
}

return config;
}

public void reloadConfig() {
if (!configFile.exists()) {
saveResource("config.yml");
}

config = YamlConfiguration.loadConfiguration(configFile);
}

public void saveConfig() {
try {
getConfig().save(configFile);
} catch (IOException ex) {
api.error("Failed to save config", ex);
}
}

public void onEnable() {}

public void onDisable() {}

@Nullable
public String getRequiredVersion() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.realized.duels.api.kit;

import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import me.realized.duels.api.event.kit.KitCreateEvent;
Expand Down Expand Up @@ -46,4 +47,11 @@ public interface KitManager {
*/
@Nullable
Kit remove(@Nonnull final String name);


/**
* @return List of kits that are currently loaded
* @since 3.1.0
*/
List<? extends Kit> getKits();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.realized.duels.api.match;

import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import me.realized.duels.api.arena.Arena;
Expand Down Expand Up @@ -45,4 +46,11 @@ public interface Match {
*/
int getBet();


/**
* @return UnmodifiableSet of alive players in this match
* @since 3.1.0
*/
Set<Player> getPlayers();

}
Loading

0 comments on commit 225763b

Please sign in to comment.