From 26cbc29f8849a1f034c83eb61736859e3da1633d Mon Sep 17 00:00:00 2001 From: ChickenStyle Date: Sun, 4 Apr 2021 16:35:29 +0300 Subject: [PATCH] 1.0.6 --- LuckyCubes/config.yml | 3 ++ LuckyCubes/plugin.yml | 2 +- .../src/me/chickenstyle/luckyblocks/Main.java | 9 +++-- .../me/chickenstyle/luckyblocks/Message.java | 3 +- .../luckyblocks/events/PlaceBlockEvent.java | 33 +++++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/LuckyCubes/config.yml b/LuckyCubes/config.yml index 4fe5455..739cf94 100644 --- a/LuckyCubes/config.yml +++ b/LuckyCubes/config.yml @@ -5,6 +5,7 @@ messages: giveMessage: "&6{player} &agave you &6{amount} &ax&6{luckycube}" getReward: "&7You got &6{amount} &ax&6{item}" cooldown: "&cYou have to wait &6{seconds} &cto open another luckycube!" + disableCommandUse: "&cYou cannot use commands while opening a luckycube!" spinningAnimation: @@ -14,6 +15,8 @@ spinningAnimation: sendMessageOnReward: true +disableCommandsOnOpen: true + # allows player to exit the gui animation! allowExitInGUI: false diff --git a/LuckyCubes/plugin.yml b/LuckyCubes/plugin.yml index 3644954..38cdc46 100644 --- a/LuckyCubes/plugin.yml +++ b/LuckyCubes/plugin.yml @@ -1,6 +1,6 @@ main: me.chickenstyle.luckyblocks.Main name: LuckyCubes -version: 1.0.5 +version: 1.0.6 description: implements cool luckyblocks to the game api-version: 1.13 commands: diff --git a/LuckyCubes/src/me/chickenstyle/luckyblocks/Main.java b/LuckyCubes/src/me/chickenstyle/luckyblocks/Main.java index 0c1e3bd..ea17ce7 100644 --- a/LuckyCubes/src/me/chickenstyle/luckyblocks/Main.java +++ b/LuckyCubes/src/me/chickenstyle/luckyblocks/Main.java @@ -1,5 +1,6 @@ package me.chickenstyle.luckyblocks; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -58,8 +59,12 @@ public void onEnable() { creatingLuckyCube = new HashMap(); stands = new HashSet(); - this.getConfig().options().copyDefaults(); - saveDefaultConfig(); + File config = new File(getDataFolder(),"config.yml"); + + if (!config.exists()) { + this.getConfig().options().copyDefaults(); + saveDefaultConfig(); + } new CustomLuckyBlocks(this); //Loads proper data :) diff --git a/LuckyCubes/src/me/chickenstyle/luckyblocks/Message.java b/LuckyCubes/src/me/chickenstyle/luckyblocks/Message.java index ed7f98e..dc0aa71 100644 --- a/LuckyCubes/src/me/chickenstyle/luckyblocks/Message.java +++ b/LuckyCubes/src/me/chickenstyle/luckyblocks/Message.java @@ -9,7 +9,8 @@ public enum Message { GIVE_MESSAGE(color(getString("messages.giveMessage"))), GET_REWARD(color(getString("messages.getReward"))), COOLDOWN(color(getString("messages.cooldown"))), - PLACE_ON_GROUND(color(getString("messages.placeOnGround"))); + PLACE_ON_GROUND(color(getString("messages.placeOnGround"))), + DISABLE_COMMAND(color(getString("messages.disableCommandUse"))); private String error; Message(String error) { diff --git a/LuckyCubes/src/me/chickenstyle/luckyblocks/events/PlaceBlockEvent.java b/LuckyCubes/src/me/chickenstyle/luckyblocks/events/PlaceBlockEvent.java index 9767fba..ecff8ec 100644 --- a/LuckyCubes/src/me/chickenstyle/luckyblocks/events/PlaceBlockEvent.java +++ b/LuckyCubes/src/me/chickenstyle/luckyblocks/events/PlaceBlockEvent.java @@ -2,15 +2,19 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Random; import java.util.UUID; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.inventory.ItemStack; import me.chickenstyle.luckyblocks.LuckyCube; @@ -23,12 +27,41 @@ public class PlaceBlockEvent implements Listener{ + @EventHandler + public void onPlayerCommand(PlayerCommandPreprocessEvent e) { + if (Main.getInstance().getConfig().getBoolean("disableCommandsOnOpen")) { + if (Main.opening.contains(e.getPlayer().getUniqueId())) { + e.setCancelled(true); + e.getPlayer().sendMessage(Message.DISABLE_COMMAND.getMSG()); + } + } + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent e) { + List ents = new ArrayList<>(); + for (Entity ent:e.getChunk().getEntities()) { + if (Main.stands.contains(ent)) { + ent.remove(); + ents.add(ent); + } + } + + ents.forEach(ent -> { + Main.stands.remove(ent); + }); + + } + + HashMap cooldown = new HashMap<>(); @SuppressWarnings("deprecation") @EventHandler public void onBlockPlace(PlayerInteractEvent e) { Player player = e.getPlayer(); + + if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (player.getItemInHand() != null && !player.getItemInHand().getType().equals(Material.AIR)) { if (Main.getVersionHandler().isLuckyBlock(player.getItemInHand())) { e.setCancelled(true);