-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from Syrent/development
Remove VRUoM from project
- Loading branch information
Showing
17 changed files
with
367 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/ir/syrent/velocityvanish/velocity/vruom/VRUoMPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ir.syrent.velocityvanish.velocity.vruom; | ||
|
||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import org.slf4j.Logger; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class VRUoMPlugin { | ||
|
||
private static VRUoMPlugin instance; | ||
private static ProxyServer server; | ||
private static Logger logger; | ||
private static Path dataDirectory; | ||
|
||
public VRUoMPlugin(ProxyServer server, Logger logger) { | ||
instance = this; | ||
VRUoMPlugin.server = server; | ||
VRUoMPlugin.logger = logger; | ||
} | ||
|
||
public VRUoMPlugin(ProxyServer server, Logger logger, Path dataDirectory) { | ||
instance = this; | ||
VRUoMPlugin.server = server; | ||
VRUoMPlugin.logger = logger; | ||
VRUoMPlugin.dataDirectory = dataDirectory; | ||
} | ||
|
||
public static VRUoMPlugin get() { | ||
return instance; | ||
} | ||
|
||
public static ProxyServer getServer() { | ||
return server; | ||
} | ||
|
||
public static Logger getLogger() { | ||
return logger; | ||
} | ||
|
||
public static Path getDataDirectory() { | ||
return dataDirectory; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/main/java/ir/syrent/velocityvanish/velocity/vruom/VRuom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package ir.syrent.velocityvanish.velocity.vruom; | ||
|
||
import com.velocitypowered.api.command.Command; | ||
import com.velocitypowered.api.command.CommandMeta; | ||
import com.velocitypowered.api.plugin.Plugin; | ||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import com.velocitypowered.api.scheduler.ScheduledTask; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class VRuom { | ||
|
||
private final static Plugin DESCRIPTION; | ||
private final static Logger logger; | ||
private static boolean debug = false; | ||
|
||
static { | ||
DESCRIPTION = VRUoMPlugin.get().getClass().getAnnotation(Plugin.class); | ||
logger = VRUoMPlugin.getLogger(); | ||
} | ||
|
||
public static Object getPlugin() { | ||
return VRUoMPlugin.get(); | ||
} | ||
|
||
public static Plugin getDescription() { | ||
return DESCRIPTION; | ||
} | ||
|
||
public static ProxyServer getServer() { | ||
return VRUoMPlugin.getServer(); | ||
} | ||
|
||
public static Path getDataDirectory() { | ||
return VRUoMPlugin.getDataDirectory(); | ||
} | ||
|
||
/** | ||
* @deprecated Use {@link #getDataDirectory()} instead | ||
* Data folder is accessible through the DataDirectory constructor in the Velocity main class\ | ||
*/ | ||
public static File getDataFolder() { | ||
return new File("plugins", getDescription().name()); | ||
} | ||
|
||
public static void registerListener(Object listener) { | ||
getServer().getEventManager().register(VRUoMPlugin.get(), listener); | ||
} | ||
|
||
public static void registerCommand(String name, Collection<String> aliases, Command command) { | ||
CommandMeta meta = getServer().getCommandManager().metaBuilder(name).aliases(aliases.toArray(new String[0])).build(); | ||
getServer().getCommandManager().register(meta, command); | ||
} | ||
|
||
public static Collection<Player> getOnlinePlayers() { | ||
return getServer().getAllPlayers(); | ||
} | ||
|
||
public static Optional<Player> getPlayer(String username) { | ||
for (Player player : getOnlinePlayers()) { | ||
if (player.getUsername().equalsIgnoreCase(username)) { | ||
return Optional.of(player); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public static void setDebug(boolean debug) { | ||
VRuom.debug = debug; | ||
} | ||
|
||
public static void log(String message) { | ||
logger.info(message); | ||
} | ||
|
||
public static void debug(String message) { | ||
if (debug) { | ||
log("[Debug] " + message); | ||
} | ||
} | ||
|
||
public static void warn(String message) { | ||
logger.warn(message); | ||
} | ||
|
||
public static void error(String message) { | ||
logger.error(message); | ||
} | ||
|
||
public static void run(RunnableExc runnable) { | ||
try { | ||
runnable.run(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@FunctionalInterface public interface RunnableExc { | ||
void run() throws Exception; | ||
} | ||
|
||
public static ScheduledTask runAsync(Runnable runnable) { | ||
return getServer().getScheduler().buildTask(VRUoMPlugin.get(), runnable).schedule(); | ||
} | ||
|
||
public static ScheduledTask runAsync(Runnable runnable, long delay, TimeUnit delayUnit) { | ||
return getServer().getScheduler().buildTask(VRUoMPlugin.get(), runnable).delay(delay, delayUnit).schedule(); | ||
} | ||
|
||
public static ScheduledTask runAsync(Runnable runnable, long delay, TimeUnit delayUnit, long period, TimeUnit periodUnit) { | ||
return getServer().getScheduler().buildTask(VRUoMPlugin.get(), runnable).delay(delay, delayUnit).repeat(period, periodUnit).schedule(); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ain/java/ir/syrent/velocityvanish/velocity/vruom/configuration/ConfigurateYamlConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ir.syrent.velocityvanish.velocity.vruom.configuration; | ||
|
||
import ir.syrent.velocityvanish.velocity.vruom.VRUoMPlugin; | ||
import ir.syrent.velocityvanish.velocity.vruom.utils.ResourceUtils; | ||
import org.spongepowered.configurate.CommentedConfigurationNode; | ||
import org.spongepowered.configurate.ConfigurateException; | ||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader; | ||
|
||
import java.io.File; | ||
|
||
public class ConfigurateYamlConfig { | ||
|
||
private final String fileName; | ||
private YamlConfigurationLoader loader; | ||
|
||
public CommentedConfigurationNode root; | ||
|
||
public ConfigurateYamlConfig(String fileName) { | ||
this.fileName = fileName; | ||
} | ||
|
||
public void create() { | ||
File copyFile = new File(VRUoMPlugin.getDataDirectory().toFile(), fileName); | ||
if (!copyFile.exists()) { | ||
copyFile.getParentFile().mkdirs(); | ||
ResourceUtils.copyResource(fileName, copyFile); | ||
} | ||
|
||
loader = YamlConfigurationLoader.builder().file(copyFile).build(); | ||
} | ||
|
||
public void load() { | ||
if (loader == null) { | ||
create(); | ||
} | ||
|
||
try { | ||
root = loader.load(); | ||
} catch (ConfigurateException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.