Skip to content

Commit

Permalink
Merge branch 'main' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 18, 2024
2 parents 57ca45f + 3b98dfb commit 18300aa
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 702 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Crate:
* Update /cc additem to take input for tiers which only work for cosmic/casino, /cc additem <crate_name> <prize_number> [tier]
* Update /cc additem again to take input for custom chance, Note: The max range by default is still 100 so keep it under 100. /cc additem <crate_name> <prize_number> <chance> [tier]
* [tier] is an optional arg.
* No longer create a snapshot of the holder when checking for inventoryholders

## Fixes:
* Fixed issues with crates being broken in worlds created by world plugins.
Expand Down
2 changes: 1 addition & 1 deletion paper/run/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Mon Feb 12 15:13:53 GMT-03:00 2024
#Sat Feb 17 13:54:46 EST 2024
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
Expand Down
68 changes: 32 additions & 36 deletions paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.badbones69.crazycrates;

import com.badbones69.crazycrates.api.MigrateManager;
import com.badbones69.crazycrates.api.builders.types.CrateAdminMenu;
import com.badbones69.crazycrates.api.builders.types.CrateMainMenu;
import com.badbones69.crazycrates.api.builders.types.CratePreviewMenu;
import com.badbones69.crazycrates.api.builders.types.CrateTierMenu;
import com.badbones69.crazycrates.api.enums.Permissions;
import com.badbones69.crazycrates.listeners.BrokeLocationsListener;
import com.badbones69.crazycrates.listeners.CrateControlListener;
import com.badbones69.crazycrates.listeners.MiscListener;
import com.badbones69.crazycrates.listeners.crates.CosmicCrateListener;
import com.badbones69.crazycrates.listeners.crates.CrateOpenListener;
import com.badbones69.crazycrates.listeners.crates.MobileCrateListener;
import com.badbones69.crazycrates.listeners.crates.QuadCrateListener;
import com.badbones69.crazycrates.listeners.crates.WarCrateListener;
import com.badbones69.crazycrates.listeners.menus.CrateAdminListener;
import com.badbones69.crazycrates.listeners.menus.CrateMenuListener;
import com.badbones69.crazycrates.listeners.menus.CratePreviewListener;
import com.badbones69.crazycrates.listeners.menus.CrateTierListener;
import com.badbones69.crazycrates.listeners.crates.*;
import com.badbones69.crazycrates.listeners.other.EntityDamageListener;
import com.badbones69.crazycrates.tasks.BukkitUserManager;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
Expand All @@ -25,13 +21,13 @@
import com.badbones69.crazycrates.api.FileManager;
import dev.triumphteam.cmd.bukkit.BukkitCommandManager;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.common.config.ConfigManager;
import com.badbones69.crazycrates.support.placeholders.PlaceholderAPISupport;
import com.badbones69.crazycrates.support.libraries.PluginSupport;

import java.util.Arrays;
import java.util.List;
import java.util.Timer;
import java.util.function.Supplier;
import java.util.logging.Level;
Expand Down Expand Up @@ -66,25 +62,24 @@ public void onEnable() {
this.crazyHandler.cleanFiles();

// Register listeners
this.crazyHandler.getModuleLoader().addModule(new CrateTierListener());
this.crazyHandler.getModuleLoader().addModule(new CratePreviewListener());
this.crazyHandler.getModuleLoader().addModule(new CrateAdminListener());
this.crazyHandler.getModuleLoader().addModule(new CrateMenuListener());

this.crazyHandler.getModuleLoader().load();

PluginManager pluginManager = getServer().getPluginManager();

pluginManager.registerEvents(new BrokeLocationsListener(), this);

pluginManager.registerEvents(new CrateControlListener(), this);
pluginManager.registerEvents(new EntityDamageListener(), this);
pluginManager.registerEvents(new MobileCrateListener(), this);
pluginManager.registerEvents(new CosmicCrateListener(), this);
pluginManager.registerEvents(new QuadCrateListener(), this);
pluginManager.registerEvents(new CrateOpenListener(), this);
pluginManager.registerEvents(new WarCrateListener(), this);
pluginManager.registerEvents(new MiscListener(), this);
List.of(
// Menu listeners.
new CratePreviewMenu.CratePreviewListener(),
new CrateAdminMenu.CrateAdminListener(),
new CrateMainMenu.CrateMenuListener(),
new CrateTierMenu.CrateTierListener(),

// Other listeners.
new BrokeLocationsListener(),
new CrateControlListener(),
new EntityDamageListener(),
new MobileCrateListener(),
new CosmicCrateListener(),
new QuadCrateListener(),
new CrateOpenListener(),
new WarCrateListener(),
new MiscListener()
).forEach(listener -> getServer().getPluginManager().registerEvents(listener, this));

if (isLogging()) {
String prefix = this.crazyHandler.getConfigManager().getConfig().getProperty(ConfigKeys.console_prefix);
Expand Down Expand Up @@ -112,15 +107,16 @@ public void onDisable() {
// End all crates.
SessionManager.endCrates();

// Remove quick crate rewards
this.crazyHandler.getCrateManager().purgeRewards();
if (this.crazyHandler != null) {
// Remove quick crate rewards
this.crazyHandler.getCrateManager().purgeRewards();

// Purge holograms.
if (this.crazyHandler.getCrateManager().getHolograms() != null)
this.crazyHandler.getCrateManager().getHolograms().removeAllHolograms();
// Purge holograms.
if (this.crazyHandler.getCrateManager().getHolograms() != null) this.crazyHandler.getCrateManager().getHolograms().removeAllHolograms();

// Unload the plugin.
this.crazyHandler.unload();
// Unload the plugin.
this.crazyHandler.unload();
}

if (this.timer != null) this.timer.cancel();
}
Expand Down
10 changes: 0 additions & 10 deletions paper/src/main/java/com/badbones69/crazycrates/CrazyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.badbones69.crazycrates.support.metrics.MetricsManager;
import com.badbones69.crazycrates.tasks.BukkitUserManager;
import com.badbones69.crazycrates.tasks.InventoryManager;
import com.badbones69.crazycrates.api.modules.ModuleLoader;
import com.badbones69.crazycrates.api.utils.FileUtils;

public class CrazyHandler extends CrazyCratesPlugin {
Expand All @@ -22,7 +21,6 @@ public CrazyHandler(CrazyCrates plugin) {
private InventoryManager inventoryManager;
private BukkitUserManager userManager;
private CrateManager crateManager;
private ModuleLoader moduleLoader;
private FileManager fileManager;
private MetricsManager metrics;

Expand Down Expand Up @@ -64,9 +62,6 @@ public void load() {
CommandManager commandManager = new CommandManager();
commandManager.load();

this.moduleLoader = new ModuleLoader();
this.moduleLoader.load();

// Load metrics.
boolean metrics = getConfigManager().getConfig().getProperty(ConfigKeys.toggle_metrics);

Expand Down Expand Up @@ -106,11 +101,6 @@ public CrateManager getCrateManager() {
return this.crateManager;
}

@NotNull
public ModuleLoader getModuleLoader() {
return this.moduleLoader;
}

@NotNull
public FileManager getFileManager() {
return this.fileManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.utils.MsgUtils;
Expand Down Expand Up @@ -103,6 +104,10 @@ public List<Tier> getTiers() {
return this.tiers;
}

public InventoryView getView() {
return getPlayer().getOpenInventory();
}

@Override
@NotNull
public Inventory getInventory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package com.badbones69.crazycrates.api.builders.types;

import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.api.enums.Permissions;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import us.crazycrew.crazycrates.api.enums.types.CrateType;
import com.badbones69.crazycrates.api.builders.InventoryBuilder;
import us.crazycrew.crazycrates.api.enums.types.KeyType;
import us.crazycrew.crazycrates.api.users.UserManager;
import java.util.HashMap;

public class CrateAdminMenu extends InventoryBuilder {

Expand All @@ -24,4 +40,66 @@ public InventoryBuilder build() {

return this;
}

public static class CrateAdminListener implements Listener {

@NotNull
private final CrazyCrates plugin = CrazyCrates.get();

@NotNull
private final CrateManager crateManager = this.plugin.getCrateManager();

@NotNull
private final UserManager userManager = this.plugin.getCrazyHandler().getUserManager();

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (!(inventory.getHolder(false) instanceof CrateAdminMenu holder)) return;

event.setCancelled(true);

Player player = holder.getPlayer();

InventoryView view = holder.getView();

if (event.getClickedInventory() != view.getTopInventory()) return;

if (!Permissions.CRAZYCRATES_ACCESS.hasPermission(player)) {
player.closeInventory(InventoryCloseEvent.Reason.CANT_USE);
player.sendMessage(Messages.no_permission.getString());
return;
}

ItemStack item = event.getCurrentItem();

if (item == null || item.getType() == Material.AIR) return;

if (!this.crateManager.isKey(item)) return;

Crate crate = this.crateManager.getCrateFromKey(item);

ClickType clickType = event.getClick();

switch (clickType) {
case LEFT -> player.getInventory().addItem(crate.getKey());

case RIGHT -> {
this.userManager.addKeys(1, player.getUniqueId(), crate.getName(), KeyType.virtual_key);

ItemStack key = crate.getKey();

if (key.getItemMeta() != null) {
HashMap<String, String> placeholders = new HashMap<>();

placeholders.put("%amount%", String.valueOf(1));
placeholders.put("%key%", crate.getKeyName());

player.sendMessage(Messages.obtaining_keys.getMessage(placeholders).toString());
}
}
}
}
}
}
Loading

0 comments on commit 18300aa

Please sign in to comment.