Skip to content

Commit

Permalink
Added Cost Feature And bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehran1022mm committed Jun 6, 2023
1 parent 1d9ac0e commit 35b773f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 18 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<id>xenondevs</id>
<url>https://repo.xenondevs.xyz/releases</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -84,5 +88,11 @@
<artifactId>inventory-access-r5</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
19 changes: 14 additions & 5 deletions src/main/java/ir/Mehran1022/EventCore/Commands/EventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ of this software and associated documentation files (the "Software"), to deal
import ir.Mehran1022.EventCore.Configuration;
import ir.Mehran1022.EventCore.Main;
import ir.Mehran1022.EventCore.Utils.Common;
import net.milkbowl.vault.economy.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -49,9 +51,9 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class EventCommand implements CommandExecutor {
private Main Plugin;
public static Boolean Active = false;
public static String EventDesc;
public static List<Player> Players = new ArrayList<>();
Expand Down Expand Up @@ -190,10 +192,12 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
Players.clear();
String BossbarString = Configuration.BOSSBAR.replace("[Desc]", EventDesc);
BossBar Bossbar = Bukkit.createBossBar(BossbarString, BarColor.RED, BarStyle.SOLID);
Bossbar.setProgress(1.0);
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + EventDesc));
for (Player player : Bukkit.getOnlinePlayers()) {
Common.SendTitle(player, Configuration.TITLE, Configuration.SUBTITLE, Configuration.FADEIN, Configuration.STAY, Configuration.FADEOUT);
Bossbar.addPlayer(player);

for (Player P : Bukkit.getOnlinePlayers()) {
Bossbar.addPlayer(P);
P.sendTitle(Common.Color(Configuration.TITLE), Common.Color(Configuration.SUBTITLE), Configuration.FADEIN, Configuration.STAY, Configuration.FADEOUT);
}
Common.SendActionBar((Player) sender, "&aSuccessfully Created An Event With Duration Of " + Configuration.DURATION + "Seconds.");

Expand All @@ -205,7 +209,7 @@ public void run() {
Bossbar.removeAll();
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + Configuration.END));
}
}.runTaskLater(Plugin, Configuration.DURATION * 20L);
}.runTaskLater(Main.getInstance(), Configuration.DURATION * 20L);
}
if (args[0].equalsIgnoreCase("join")) {
if (!Active) {
Expand All @@ -217,6 +221,11 @@ public void run() {
Common.SendMessage(Player, Configuration.PREFIX + "&cAlready Connected.");
} else {
Players.add(Player);
if (Main.EconomyPluginFound && Configuration.ENABLE_COST) {
EconomyResponse Response = Main.getEconomy().withdrawPlayer(Player, Configuration.COST);
Common.SendMessage(Player, Configuration.PREFIX + "This Event Subtracted " + Configuration.COST.toString() + "$ From Your Money. You Have " + Main.getEconomy().format(Response.balance) + "$ Now");
System.out.println("Withdrew " + Configuration.COST + " From " + Player.getName());
}
Common.SendToAnotherServer(Player, Configuration.SERVER_NAME);
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + "&b" + Player.getName() + "&f Has Joined The Event."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

package ir.Mehran1022.EventCore;
package ir.Mehran1022.EventCore.Commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -38,6 +38,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if (args.length == 1) {
ArrayList.add("End");
ArrayList.add("Start");
ArrayList.add("Join");
ArrayList.add("Reload");
ArrayList.add("Help");
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/ir/Mehran1022/EventCore/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public final class Configuration {
public static String END;
public static String NO_EVENT;
public static String SERVER_NAME;
public static int DURATION;
public static Integer DURATION;
public static String BOSSBAR;
public static String TITLE;
public static String SUBTITLE;
public static int FADEIN;
public static int STAY;
public static int FADEOUT;
public static Integer FADEIN;
public static Integer STAY;
public static Integer FADEOUT;
public static Boolean ENABLE_COST;
public static Double COST;
public static void loadConfig() {
Main instance = Main.getInstance();
instance.reloadConfig();
Expand All @@ -60,7 +62,9 @@ public static void loadConfig() {
TITLE = Common.Color(config.getString("Titles.Title"));
SUBTITLE = Common.Color(config.getString("Titles.Subtitle"));
FADEIN = config.getInt("Titles.FadeIn");
FADEIN = config.getInt("Titles.Stay");
FADEIN = config.getInt("Titles.FadeOut");
STAY = config.getInt("Titles.Stay");
FADEOUT = config.getInt("Titles.FadeOut");
ENABLE_COST = config.getBoolean("Cost.Enabled");
COST = config.getDouble("Cost.Cost");
}
}
31 changes: 31 additions & 0 deletions src/main/java/ir/Mehran1022/EventCore/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,35 @@ of this software and associated documentation files (the "Software"), to deal
package ir.Mehran1022.EventCore;

import ir.Mehran1022.EventCore.Commands.EventCommand;
import ir.Mehran1022.EventCore.Commands.TabCompleter;
import ir.Mehran1022.EventCore.Listeners.InventoryClickListener;
import ir.Mehran1022.EventCore.Listeners.PlayerJoinEvent;
import ir.Mehran1022.EventCore.Utils.Common;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public final class Main extends JavaPlugin {

public static Main instance;
private static Economy econ = null;
public static boolean EconomyPluginFound = true;

@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
Configuration.loadConfig();
LoadThings();
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
EconomyPluginFound = setupEconomy();
if (!EconomyPluginFound) {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
Common.Log("&c[Event-Core] Can't Use Cost Feature. Vault Not Found.");
} else {
Common.Log("&c[Event-Core] Can't Use Cost Feature. Failed To Get Economy Plugin.");
}
}
Metrics Metrics = new Metrics(this, 18612);
}
private void LoadThings () {
Expand All @@ -47,6 +62,22 @@ private void LoadThings () {
Common.RegisterEvent(new InventoryClickListener(), this);
Common.RegisterTabCompleter(new TabCompleter(), "event");
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
System.out.println("Vault Is Null.");
return false;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
System.out.println("RegisteredServiceProvider IS Null.");
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public static Economy getEconomy () {
return econ;
}
public static Main getInstance () {
return instance;
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/ir/Mehran1022/EventCore/Utils/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Common {
public static String Color (String Message) {
return ChatColor.translateAlternateColorCodes('&', Message);
}
// public static void Log (String Message) { Main.getInstance().getLogger().info(Color(Message)); }
public static void Log (String Message) { Main.getInstance().getServer().getConsoleSender().sendMessage((Color(Message))); }
public static void RegisterEvent (Listener ListenerClass, Plugin PluginClass) {
Main.getInstance().getServer().getPluginManager().registerEvents(ListenerClass, PluginClass);
}
Expand All @@ -60,9 +60,6 @@ public static void RegisterTabCompleter (TabCompleter Class, String CommandName)
}
public static void SendMessage (CommandSender Player, String Message) {
Player.sendMessage(Color(Message));
}
public static void SendTitle (Player Player, String Title, String SubTitle, int FadeIn,int Stay, int FadeOut) {
Player.sendTitle(Color(Title), Color(SubTitle), FadeIn, Stay, FadeOut);
}
public static void Ban (Player Player, String Reason) {
String UserName = Player.getName();
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Prefix: "&c&lEVENT&f&l »"
Prefix: "&c&lEVENT&f&l »&r"
EventServer: "event" # Your Bungeecord Event Server Name
Duration: 300 # Events Duration In Seconds
Cost:
Enabled: true # Withdraw Money From Players On Joining
Cost: 15.0
Messages:
NoPermission: "&cYou Dont Have Enough Permissions." # eventcore.admin
AlreadyStarted: "&cThere Is A Active Event."
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Event-Core
version: '${project.version}'
main: ir.Mehran1022.EventCore.Main
api-version: 1.13
softdepend:
- Vault
commands:
event:
usage: "/<command> <args>"

0 comments on commit 35b773f

Please sign in to comment.