Skip to content

Commit

Permalink
Added AutoUpdate And IriduimColorAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehran1022mm committed Jun 15, 2023
1 parent ba35316 commit f0c71de
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 78 deletions.
25 changes: 22 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ir</groupId>
<artifactId>Event-Core</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
<packaging>jar</packaging>

<name>Event-Core</name>
Expand All @@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -69,6 +69,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>iridiumdevelopment</id>
<url>https://nexus.iridiumdevelopment.net/repository/maven-releases/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -94,5 +98,20 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.iridium</groupId>
<artifactId>IridiumColorAPI</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>
116 changes: 74 additions & 42 deletions src/main/java/ir/Mehran1022/EventCore/Commands/EventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ of this software and associated documentation files (the "Software"), to deal

package ir.Mehran1022.EventCore.Commands;

import ir.Mehran1022.EventCore.Configuration;
import ir.Mehran1022.EventCore.Main;
import ir.Mehran1022.EventCore.Managers.ConfigManager;
import ir.Mehran1022.EventCore.Utils.Common;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
Expand All @@ -36,6 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand All @@ -52,15 +53,15 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class EventCommand implements CommandExecutor {
public class EventCommand implements CommandExecutor, TabCompleter {

public static Boolean Active = false;

public static String EventDesc;

public static List<Player> Players = new ArrayList<>();

@Override
public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNull String label, String[] args) {
if (!command.getName().equalsIgnoreCase("event")) { return true; }

Expand Down Expand Up @@ -153,13 +154,13 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
if (args[0].equalsIgnoreCase("reload")) {
long start = System.currentTimeMillis();
if (!sender.hasPermission("eventcore.admin")) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.NO_PERMISSION);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION);
return true;
}
Configuration.loadConfig();
ConfigManager.loadConfig();
long stop = System.currentTimeMillis();
long time = stop - start;
Common.SendMessage(sender, Configuration.PREFIX + "&aTook &c" + time + "ms &aTo Reload.");
Common.SendMessage(sender, ConfigManager.PREFIX + "&aTook &c" + time + "ms &aTo Reload.");
}
if (!(sender instanceof Player)) {
Common.SendMessage(sender, "Only Players Allowed.");
Expand All @@ -185,128 +186,159 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
if (args[0].equalsIgnoreCase("start")) {

if (!sender.hasPermission("eventcore.admin")) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.NO_PERMISSION);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION);
return true;
}
if (Active) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.ALREADY_STARTED);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.ALREADY_STARTED);
return true;
}
EventDesc = args.length > 1 ? String.join(" ", args).substring(6) : Configuration.NO_DESC;
EventDesc = args.length > 1 ? String.join(" ", args).substring(6) : ConfigManager.NO_DESC;
Active = true;
Players.clear();
String BossbarString = Configuration.BOSSBAR.replace("[Desc]", EventDesc);
String BossbarString = ConfigManager.BOSSBAR.replace("[Desc]", EventDesc);
BossBar Bossbar = Bukkit.createBossBar(BossbarString, BarColor.RED, BarStyle.SOLID);
Bossbar.setProgress(1.0);
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + EventDesc));
Bukkit.broadcastMessage(Common.Color(ConfigManager.PREFIX + EventDesc));

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

new BukkitRunnable() {
@Override
public void run() {
Active = false;
Players.clear();
Bossbar.removeAll();
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + Configuration.END));
Bukkit.broadcastMessage(Common.Color(ConfigManager.PREFIX + ConfigManager.END));
}
}.runTaskLater(Main.getInstance(), Configuration.DURATION * 20L);
}.runTaskLater(Main.getInstance(), ConfigManager.DURATION * 20L);
}
if (args[0].equalsIgnoreCase("join")) {
if (!Active) {
Common.SendMessage(sender,Configuration.PREFIX + Configuration.NO_EVENT);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_EVENT);
return true;
}
Player Player = (org.bukkit.entity.Player) sender;
UUID uuid = Player.getUniqueId();
if (Main.Config.contains(uuid.toString())) {
if (Objects.equals(Main.Config.get(uuid.toString() + ".BANNED"), true)) {
Common.SendMessage(Player,Configuration.PREFIX + Configuration.BLOCKED);
if (Main.PlayersData.contains(uuid.toString())) {
if (Objects.equals(Main.PlayersData.get(uuid.toString() + ".BANNED"), true)) {
Common.SendMessage(Player, ConfigManager.PREFIX + ConfigManager.BLOCKED);
return true;
}
}
if (Players.contains(Player)) {
Common.SendMessage(Player, Configuration.PREFIX + "&cAlready Connected.");
Common.SendMessage(Player, ConfigManager.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());
if (Main.EconomyPluginFound && ConfigManager.ENABLE_COST) {
EconomyResponse Response = Main.getEconomy().withdrawPlayer(Player, ConfigManager.COST);
Common.SendMessage(Player, ConfigManager.PREFIX + "This Event Subtracted " + ConfigManager.COST.toString() + "$ From Your Money. You Have " + Main.getEconomy().format(Response.balance) + "$ Now");
System.out.println("Withdrew " + ConfigManager.COST + " From " + Player.getName());
}
Common.SendToAnotherServer(Player, Configuration.SERVER_NAME);
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + "&b" + Player.getName() + "&f Has Joined The Event."));
Common.SendToAnotherServer(Player, ConfigManager.SERVER_NAME);
Bukkit.broadcastMessage(Common.Color(ConfigManager.PREFIX + "&b" + Player.getName() + "&f Has Joined The Event."));
}
return true;
}
if (args[0].equalsIgnoreCase("end")) {
if (!sender.hasPermission("eventcore.admin")) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.NO_PERMISSION);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION);
return true;
}
if (!Active) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.NO_EVENT);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_EVENT);
return true;
}
Active = false;
Players.clear();
Bukkit.broadcastMessage(Common.Color(Configuration.PREFIX + Configuration.END));
Common.SendMessage(sender, Configuration.PREFIX + "&aClosed The Active Event.");
Bukkit.broadcastMessage(Common.Color(ConfigManager.PREFIX + ConfigManager.END));
Common.SendMessage(sender, ConfigManager.PREFIX + "&aClosed The Active Event.");
}
if (args[0].equalsIgnoreCase("block")) {
if (!sender.hasPermission("eventcore.admin")) {
sender.sendMessage(Configuration.PREFIX + Configuration.NO_PERMISSION);
sender.sendMessage(ConfigManager.PREFIX + ConfigManager.NO_PERMISSION);
return true;
}
if (args[1].length() < 1) {
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
Common.SendMessage(sender, Configuration.PREFIX + (Configuration.OFFLINE).replace("[Player]", args[1]));
Common.SendMessage(sender, ConfigManager.PREFIX + (ConfigManager.OFFLINE).replace("[Player]", args[1]));
return true;
}
String playerName = player.getName();
UUID uuid = player.getUniqueId();
if (Main.Config.contains(uuid.toString())) {
Main.Config.set(uuid.toString() + ".BANNED", true);
if (Main.PlayersData.contains(uuid.toString())) {
Main.PlayersData.set(uuid.toString() + ".BANNED", true);
try {
Main.Config.save(Main.File);
Main.PlayersData.save(Main.File);
} catch (IOException e) {
e.printStackTrace();
}
Common.SendMessage(sender, Configuration.PREFIX + (Configuration.BLOCK).replace("[Player]", playerName));
Common.SendMessage(sender, ConfigManager.PREFIX + (ConfigManager.BLOCK).replace("[Player]", playerName));
}
}
if (args[0].equalsIgnoreCase("unblock")) {
if (!sender.hasPermission("eventcore.admin")) {
Common.SendMessage(sender, Configuration.PREFIX + Configuration.NO_PERMISSION);
Common.SendMessage(sender, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION);
return true;
}
if (args[1].length() < 1) {
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
Common.SendMessage(sender, Configuration.PREFIX + (Configuration.OFFLINE).replace("[Player]", args[1]));
Common.SendMessage(sender, ConfigManager.PREFIX + (ConfigManager.OFFLINE).replace("[Player]", args[1]));
return true;
}
String playerName = player.getName();
UUID uuid = player.getUniqueId();
if (Main.Config.contains(uuid.toString())) {
Main.Config.set(uuid.toString() + ".BANNED", false);
if (Main.PlayersData.contains(uuid.toString())) {
Main.PlayersData.set(uuid.toString() + ".BANNED", false);
try {
Main.Config.save(Main.File);
Main.PlayersData.save(Main.File);
} catch (IOException e) {
e.printStackTrace();
}
Common.SendMessage(sender, Configuration.PREFIX + (Configuration.UNBLOCK).replace("[Player]", playerName));
Common.SendMessage(sender, ConfigManager.PREFIX + (ConfigManager.UNBLOCK).replace("[Player]", playerName));
}
}
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
List<String> ArrayList = new ArrayList<>();
List<String> Args1 = new ArrayList<>();
if (args.length == 1) {
if (sender.hasPermission("eventcore.admin")) {
ArrayList.add("Join");
ArrayList.add("End");
ArrayList.add("Start");
ArrayList.add("Block");
ArrayList.add("UnBlock");
ArrayList.add("Help");
ArrayList.add("Reload");
return ArrayList;
} else {
ArrayList.add("Join");
ArrayList.add("Help");
return ArrayList;
}
}
if (args[1].length() >= 1) {
if (!args[1].equalsIgnoreCase("Block") && !args[1].equalsIgnoreCase("UnBlock")) { return null; }
if (sender.hasPermission("eventcore.admin")) {
for (Player player : Bukkit.getOnlinePlayers()) {
Args1.add(player.getName());
}
return Args1;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ of this software and associated documentation files (the "Software"), to deal

package ir.Mehran1022.EventCore.Listeners;

import ir.Mehran1022.EventCore.Configuration;
import ir.Mehran1022.EventCore.Managers.ConfigManager;
import ir.Mehran1022.EventCore.Utils.Common;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -39,21 +39,21 @@ public void OnInvClick (InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (Objects.requireNonNull(event.getCurrentItem()).getType().name().equals("EMERALD")) {
player.closeInventory();
Common.Confirmation(player, Configuration.PREFIX + "You Are Going To Join An Event. Are you Sure??", "/event join");
Common.Confirmation(player, ConfigManager.PREFIX + "You Are Going To Join An Event. Are you Sure??", "/event join");
}
if (event.getCurrentItem().getType().name().equals("EMERALD_BLOCK")) {
player.closeInventory();
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, Configuration.PREFIX + Configuration.NO_PERMISSION); return; }
Common.Confirmation(player, Configuration.PREFIX + "You Are Going To Start An Event. Are you Sure??", "/event start");
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION); return; }
Common.Confirmation(player, ConfigManager.PREFIX + "You Are Going To Start An Event. Are you Sure??", "/event start");
}
if (event.getCurrentItem().getType().name().equals("REDSTONE_BLOCK")) {
player.closeInventory();
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, Configuration.PREFIX + Configuration.NO_PERMISSION); return; }
Common.Confirmation(player, Configuration.PREFIX + "You Are Going To Close An Event. Are you Sure??", "/event end");
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION); return; }
Common.Confirmation(player, ConfigManager.PREFIX + "You Are Going To Close An Event. Are you Sure??", "/event end");
}
if (event.getCurrentItem().getType().name().equals("GRINDSTONE")) {
player.closeInventory();
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, Configuration.PREFIX + Configuration.NO_PERMISSION); return; }
if (!player.hasPermission("eventcore.admin")) { Common.SendMessage(player, ConfigManager.PREFIX + ConfigManager.NO_PERMISSION); return; }
player.performCommand("event reload");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ of this software and associated documentation files (the "Software"), to deal

package ir.Mehran1022.EventCore.Listeners;

import ir.Mehran1022.EventCore.Configuration;
import ir.Mehran1022.EventCore.Main;
import ir.Mehran1022.EventCore.Managers.ConfigManager;
import ir.Mehran1022.EventCore.Utils.Common;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import sun.jvm.hotspot.debugger.MachineDescriptionIntelX86;

import java.io.IOException;
import java.util.UUID;
Expand All @@ -43,17 +42,17 @@ public class PlayerJoinEvent implements Listener {
public void EventNotification (org.bukkit.event.player.PlayerJoinEvent event) {
Player player = event.getPlayer();
if (Active) {
Common.SendMessage(player, Configuration.PREFIX + EventDesc);
Common.SendMessage(player, ConfigManager.PREFIX + EventDesc);
}
}
@EventHandler
public void DataSave (org.bukkit.event.player.PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
Main.Config.set(uuid.toString() + ".NAME", player.getName());
Main.Config.set(uuid.toString() + ".BANNED", false);
Main.PlayersData.set(uuid.toString() + ".NAME", player.getName());
Main.PlayersData.set(uuid.toString() + ".BANNED", false);
try {
Main.Config.save(Main.File);
Main.PlayersData.save(Main.File);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit f0c71de

Please sign in to comment.