Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Papi #3

Draft
wants to merge 7 commits into
base: 2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

rm -rf /e/Games/Minecraft/Server/serveur_dev_1164/plugins/pvparena-*-SNAPSHOT.jar
cp target/pvparena-*-SNAPSHOT.jar /e/Games/Minecraft/Server/serveur_dev_1164/plugins/
echo "deployed !"
sleep 1
echo "launching server..."

cd /e/Games/Minecraft/Server/serveur_dev_1164/
./start.sh
sleep 2
4 changes: 2 additions & 2 deletions doc/mods/powerups.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ This mod allows spawning of items that give special powers / bad things, fully c

Unzip the module files (files tab, "PA Files v*.*.*") into the /pvparena/files folder and install them via

- `/pa install [modname]`, activate per arena via
- `/pa [arenaname] !tm [modname]`
- `/pa modules install powerups`, activate per arena via
- `/pa [arenaname] !tm powerups`

## Setup

Expand Down
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<properties>
<buildVersion></buildVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<papi.version>2.10.9</papi.version>
</properties>

<repositories>
Expand All @@ -22,6 +23,10 @@
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -38,10 +43,28 @@
<version>1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>${papi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>17.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>5.3</version>
</dependency>
</dependencies>

Expand Down
151 changes: 123 additions & 28 deletions src/main/java/net/slipcor/pvparena/PVPArena.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.slipcor.pvparena;

import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
import net.slipcor.pvparena.api.PvpArenaPlaceholderExpansion;
import net.slipcor.pvparena.arena.Arena;
import net.slipcor.pvparena.arena.ArenaClass;
import net.slipcor.pvparena.arena.ArenaPlayer;
Expand All @@ -10,6 +12,10 @@
import net.slipcor.pvparena.core.Language;
import net.slipcor.pvparena.core.Language.MSG;
import net.slipcor.pvparena.core.StringParser;
import net.slipcor.pvparena.database.Database;
import net.slipcor.pvparena.database.MySQL;
import net.slipcor.pvparena.database.PlayerArenaStats;
import net.slipcor.pvparena.database.SQLite;
import net.slipcor.pvparena.listeners.BlockListener;
import net.slipcor.pvparena.listeners.EntityListener;
import net.slipcor.pvparena.listeners.InventoryListener;
Expand Down Expand Up @@ -63,6 +69,9 @@ public class PVPArena extends JavaPlugin {
private UpdateChecker updateChecker;
private boolean shuttingDown;

private Database database;
private boolean mysql;

public static PVPArena getInstance() {
return instance;
}
Expand Down Expand Up @@ -106,6 +115,24 @@ public UpdateChecker getUpdateChecker() {
return this.updateChecker;
}

/**
* Returns the database instance
*
* @return Database instance
*/
public Database getDatabase() {
return database;
}

/**
* Checks if MySQL is used or not
*
* @return if MySQL is used (false means that SQLite is being used)
*/
public boolean isMysqlDatabase() {
return mysql;
}

/**
* Check if a CommandSender has admin permissions
*
Expand Down Expand Up @@ -358,6 +385,9 @@ public List<String> onTabComplete(final CommandSender sender, final Command cmd,

@Override
public void onDisable() {
if(this.database != null) {
this.database.closeConnection();
}
this.shuttingDown = true;
ArenaManager.reset(true);
Debugger.destroy();
Expand All @@ -370,35 +400,17 @@ public void onEnable() {
this.shuttingDown = false;
instance = this;

// TODO: Enable bStats
// Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);

this.saveDefaultConfig();
if (!this.getConfig().contains("shortcuts")) {
final List<String> ffa = new ArrayList<>();
final List<String> teams = new ArrayList<>();

ffa.add("arena1");
ffa.add("arena2");

teams.add("teamarena1");
teams.add("teamarena2");

this.getConfig().options().copyDefaults(true);
this.getConfig().addDefault("shortcuts.freeforall", ffa);
this.getConfig().addDefault("shortcuts.teams", teams);

this.saveConfig();
// Small check to make sure that PlaceholderAPI is installed
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){
new PvpArenaPlaceholderExpansion(this).register();
}

if (this.getConfig().contains("update.type") || this.getConfig().contains("update.mode")) {
this.getConfig().set("update.plugin", this.getConfig().getString("update.mode", "announce"));
this.getConfig().set("update.modules", this.getConfig().getBoolean("update.modules", true) ? "download" : "announce");
this.getConfig().set("update.type", null);
this.getConfig().set("update.mode", null);
getCommand("test").setExecutor(new TestCommand());

this.saveConfig();
}
// TODO: Enable bStats
// Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);

this.initDefaultConfig();

this.getDataFolder().mkdir();
new File(this.getDataFolder().getPath() + "/arenas").mkdir();
Expand Down Expand Up @@ -429,8 +441,6 @@ public void onEnable() {
Language.init(this.getConfig().getString("language", "en"));
Help.init(this.getConfig().getString("language", "en"));

StatisticsManager.initialize();

this.getServer().getPluginManager()
.registerEvents(new BlockListener(), this);
this.getServer().getPluginManager().registerEvents(new EntityListener(),
Expand All @@ -455,8 +465,93 @@ public void onEnable() {
ArenaManager.readShortcuts(this.getConfig().getConfigurationSection("shortcuts"));
}

this.initDatabase();

this.updateChecker = new UpdateChecker(this.getFile());

StatisticsManager.initialize();

Language.logInfo(MSG.LOG_PLUGIN_ENABLED, this.getDescription().getFullName());
}

/**
* Set default values to config
*/
private void initDefaultConfig() {

boolean mustSave = false;

this.saveDefaultConfig();
if (!this.getConfig().contains("shortcuts")) {
final List<String> ffa = new ArrayList<>();
final List<String> teams = new ArrayList<>();

ffa.add("arena1");
ffa.add("arena2");

teams.add("teamarena1");
teams.add("teamarena2");

this.getConfig().options().copyDefaults(true);
this.getConfig().addDefault("shortcuts.freeforall", ffa);
this.getConfig().addDefault("shortcuts.teams", teams);

mustSave = true;
}

if (this.getConfig().contains("update.type") || this.getConfig().contains("update.mode")) {
this.getConfig().set("update.plugin", this.getConfig().getString("update.mode", "announce"));
this.getConfig().set("update.modules", this.getConfig().getBoolean("update.modules", true) ? "download" : "announce");
this.getConfig().set("update.type", null);
this.getConfig().set("update.mode", null);

mustSave = true;
}

if (this.getConfig().contains("mysql.enabled") || this.getConfig().contains("mysql.host")) {
this.getConfig().set("mysql.enabled", true);
this.getConfig().set("mysql.host", "localhost");
this.getConfig().set("mysql.port", 3306);
this.getConfig().set("mysql.user", "root");
this.getConfig().set("mysql.pass", "root");
this.getConfig().set("mysql.base", "pvparena");
this.getConfig().set("mysql.prefix", "pvparena_");

mustSave = true;
}

if(mustSave){
this.saveConfig();
}
}

private void initDatabase(){
// try to connect to database
final boolean isMysqlEnabled = getConfig().getBoolean("mysql.enabled", true);
if (isMysqlEnabled) {
PVPArena.getInstance().getLogger().info("Connecting to MySQL database");
this.database = new MySQL(this, getConfig().getString("mysql.host"),
getConfig().getString("mysql.port"),
getConfig().getString("mysql.base"), getConfig().getString("mysql.user"),
getConfig().getString("mysql.pass"));
if (this.database.getConnection() != null) {
this.mysql = true;
PVPArena.getInstance().getLogger().info("Successfully connected to MySQL database.");
}
}
if (!isMysqlEnabled || !this.mysql) {
this.database = new SQLite(this, "database.db");
if (isMysqlEnabled) {
PVPArena.getInstance().getLogger().warning( "No connection to the mySQL Database! Using SQLite for storing data as fallback.");
} else {
PVPArena.getInstance().getLogger().info("Using SQLite for storing data.");
}
if (this.database.getConnection() != null) {
this.mysql = false;
PVPArena.getInstance().getLogger().info("Successfully connected to SQLite database.");
}
}
this.database.init();
}

}
22 changes: 22 additions & 0 deletions src/main/java/net/slipcor/pvparena/TestCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.slipcor.pvparena;

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class TestCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if(commandSender instanceof Player){
Player p = (Player) commandSender;
String replaced = PlaceholderAPI.setPlaceholders(p, args[0]);
p.sendMessage(replaced);
}

return false;
}
}
Loading