Skip to content

Commit

Permalink
Update to latest BattleMcAPI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Dec 18, 2019
1 parent 5162176 commit dd3c527
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 785 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>mc.alk</groupId>
<artifactId>BattleCore</artifactId>
<packaging>jar</packaging>
<version>2.3.3</version>
<version>2.4.0-SNAPSHOT</version>
<name>BattleCore</name>
<properties>
<maven.build.timestamp.format>yyyy_MM_dd</maven.build.timestamp.format>
Expand Down Expand Up @@ -96,9 +96,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mc.alk</groupId>
<groupId>org.battleplugins</groupId>
<artifactId>McAPI</artifactId>
<version>2.12.0</version>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- unknown plugins that I had to add to the repo -->
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/mc/alk/battlecore/BattlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import mc.alk.battlecore.nukkit.platform.BattleNukkitCodeHandler;
import mc.alk.battlecore.sponge.platform.BattleSpongeCodeHandler;
import mc.alk.battlecore.util.Log;
import mc.alk.mc.APIType;
import mc.alk.mc.plugin.MCPlugin;
import org.battleplugins.PlatformType;
import org.battleplugins.plugin.Plugin;

public class BattlePlugin extends MCPlugin {
public class BattlePlugin extends Plugin {

@Override
public void onEnable() {
APIType api = getPlatform().getAPIType();
if (api == APIType.BUKKIT)
platformCode.put(APIType.BUKKIT, new BattleBukkitCodeHandler());
PlatformType platformType = this.getPlatform().getType();
if (platformType == PlatformType.BUKKIT)
platformCode.put(PlatformType.BUKKIT, new BattleBukkitCodeHandler());

if (api == APIType.NUKKIT)
platformCode.put(APIType.NUKKIT, new BattleNukkitCodeHandler());
if (platformType == PlatformType.NUKKIT)
platformCode.put(PlatformType.NUKKIT, new BattleNukkitCodeHandler());

if (api == APIType.SPONGE)
platformCode.put(APIType.SPONGE, new BattleSpongeCodeHandler());
if (platformType == PlatformType.SPONGE)
platformCode.put(PlatformType.SPONGE, new BattleSpongeCodeHandler(this));

Log.setPlugin(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package mc.alk.battlecore.bukkit.economy;

import mc.alk.battlecore.economy.EconomyHandler;
import mc.alk.bukkit.BukkitOfflinePlayer;
import mc.alk.mc.MCOfflinePlayer;

import net.milkbowl.vault.economy.Economy;

import org.battleplugins.bukkit.entity.living.player.BukkitOfflinePlayer;
import org.battleplugins.entity.living.player.OfflinePlayer;

import java.util.OptionalDouble;

public class VaultEconomyHandler implements EconomyHandler {
Expand All @@ -17,50 +18,50 @@ public VaultEconomyHandler(Economy economy) {
}

@Override
public boolean hasAccount(MCOfflinePlayer player) {
public boolean hasAccount(OfflinePlayer player) {
return economy.hasAccount(((BukkitOfflinePlayer) player).getHandle());
}

@Override
public boolean hasAccount(MCOfflinePlayer player, String world) {
public boolean hasAccount(OfflinePlayer player, String world) {
return economy.hasAccount(((BukkitOfflinePlayer) player).getHandle(), world);
}

@Override
public void createAccount(MCOfflinePlayer player) {
public void createAccount(OfflinePlayer player) {
economy.createPlayerAccount(((BukkitOfflinePlayer) player).getHandle());
}

@Override
public void createAccount(MCOfflinePlayer player, String world) {
public void createAccount(OfflinePlayer player, String world) {
economy.createPlayerAccount(((BukkitOfflinePlayer) player).getHandle(), world);
}

@Override
public OptionalDouble getBalance(MCOfflinePlayer player) {
public OptionalDouble getBalance(OfflinePlayer player) {
if (!hasAccount(player))
return OptionalDouble.empty();

return OptionalDouble.of(economy.getBalance(((BukkitOfflinePlayer) player).getHandle()));
}

@Override
public OptionalDouble getBalance(MCOfflinePlayer player, String world) {
public OptionalDouble getBalance(OfflinePlayer player, String world) {
if (!hasAccount(player, world))
return OptionalDouble.empty();

return OptionalDouble.of(economy.getBalance(((BukkitOfflinePlayer) player).getHandle(), world));
}

@Override
public void setBalance(MCOfflinePlayer player, double balance) {
public void setBalance(OfflinePlayer player, double balance) {
// Withdraw current amount so account is empty
economy.withdrawPlayer(((BukkitOfflinePlayer) player).getHandle(), getBalance(player).orElse(0));
economy.depositPlayer(((BukkitOfflinePlayer) player).getHandle(), balance);
}

@Override
public void setBalance(MCOfflinePlayer player, double balance, String world) {
public void setBalance(OfflinePlayer player, double balance, String world) {
// Withdraw current amount so account is empty
economy.withdrawPlayer(((BukkitOfflinePlayer) player).getHandle(), world, getBalance(player).orElse(0));
economy.depositPlayer(((BukkitOfflinePlayer) player).getHandle(), world, balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import mc.alk.battlecore.bukkit.economy.VaultEconomyHandler;
import mc.alk.battlecore.economy.EconomyController;
import mc.alk.mc.plugin.platform.PlatformCodeHandler;

import net.milkbowl.vault.economy.Economy;

import org.battleplugins.plugin.platform.PlatformCodeHandler;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.gson.GsonBuilder;
import mc.alk.battlecore.util.FileUtil;
import mc.alk.battlecore.util.Log;
import mc.alk.mc.scheduler.Scheduler;
import org.battleplugins.scheduler.Scheduler;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/mc/alk/battlecore/economy/EconomyController.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package mc.alk.battlecore.economy;

import mc.alk.mc.MCOfflinePlayer;
import org.battleplugins.entity.living.player.OfflinePlayer;

import java.util.OptionalDouble;

public class EconomyController {

private static EconomyHandler handler;

public static boolean hasAccount(MCOfflinePlayer player) {
public static boolean hasAccount(OfflinePlayer player) {
return handler.hasAccount(player);
}

public static boolean hasAccount(MCOfflinePlayer player, String world) {
public static boolean hasAccount(OfflinePlayer player, String world) {
return handler.hasAccount(player, world);
}

public static void createAccount(MCOfflinePlayer player) {
public static void createAccount(OfflinePlayer player) {
handler.createAccount(player);
}

public static void createAccount(MCOfflinePlayer player, String world) {
public static void createAccount(OfflinePlayer player, String world) {
handler.createAccount(player, world);
}

public static OptionalDouble getBalance(MCOfflinePlayer player) {
public static OptionalDouble getBalance(OfflinePlayer player) {
return handler.getBalance(player);
}

public static OptionalDouble getBalance(MCOfflinePlayer player, String world) {
public static OptionalDouble getBalance(OfflinePlayer player, String world) {
return handler.getBalance(player, world);
}

public static void depositBalance(MCOfflinePlayer player, double balance) {
public static void depositBalance(OfflinePlayer player, double balance) {
handler.depositBalance(player, balance);
}

public static void depositBalance(MCOfflinePlayer player, double balance, String world) {
public static void depositBalance(OfflinePlayer player, double balance, String world) {
handler.depositBalance(player, balance, world);
}

public static void withdrawBalance(MCOfflinePlayer player, double balance) {
public static void withdrawBalance(OfflinePlayer player, double balance) {
handler.withdrawBalance(player, balance);
}

public static void withdrawBalance(MCOfflinePlayer player, double balance, String world) {
public static void withdrawBalance(OfflinePlayer player, double balance, String world) {
handler.withdrawBalance(player, balance, world);
}

public static void setBalance(MCOfflinePlayer player, double balance) {
public static void setBalance(OfflinePlayer player, double balance) {
handler.setBalance(player, balance);
}

public static void setBalance(MCOfflinePlayer player, double balance, String world) {
public static void setBalance(OfflinePlayer player, double balance, String world) {
handler.setBalance(player, balance, world);
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/mc/alk/battlecore/economy/EconomyHandler.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package mc.alk.battlecore.economy;

import mc.alk.mc.MCOfflinePlayer;
import org.battleplugins.entity.living.player.OfflinePlayer;

import java.util.OptionalDouble;

public interface EconomyHandler {

boolean hasAccount(MCOfflinePlayer player);
boolean hasAccount(MCOfflinePlayer player, String world);
void createAccount(MCOfflinePlayer player);
void createAccount(MCOfflinePlayer player, String world);
boolean hasAccount(OfflinePlayer player);
boolean hasAccount(OfflinePlayer player, String world);
void createAccount(OfflinePlayer player);
void createAccount(OfflinePlayer player, String world);

OptionalDouble getBalance(MCOfflinePlayer player);
OptionalDouble getBalance(MCOfflinePlayer player, String world);
OptionalDouble getBalance(OfflinePlayer player);
OptionalDouble getBalance(OfflinePlayer player, String world);

default void depositBalance(MCOfflinePlayer player, double balance) {
default void depositBalance(OfflinePlayer player, double balance) {
setBalance(player, getBalance(player).orElse(0) + balance);
}

default void depositBalance(MCOfflinePlayer player, double balance, String world) {
default void depositBalance(OfflinePlayer player, double balance, String world) {
setBalance(player, getBalance(player).orElse(0) + balance, world);
}

default void withdrawBalance(MCOfflinePlayer player, double balance) {
default void withdrawBalance(OfflinePlayer player, double balance) {
setBalance(player, getBalance(player).orElse(0) - balance);
}

default void withdrawBalance(MCOfflinePlayer player, double balance, String world) {
default void withdrawBalance(OfflinePlayer player, double balance, String world) {
setBalance(player, getBalance(player).orElse(0) - balance, world);
}

void setBalance(MCOfflinePlayer player, double balance);
void setBalance(MCOfflinePlayer player, double balance, String world);
void setBalance(OfflinePlayer player, double balance);
void setBalance(OfflinePlayer player, double balance, String world);
}
Loading

0 comments on commit dd3c527

Please sign in to comment.