-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added KitAbilityManager Added ArmorHelper.getArmorTypes
- Loading branch information
1 parent
b53831d
commit ef79004
Showing
8 changed files
with
288 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...GamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/kits/KitAbility.java
This file was deleted.
Oops, something went wrong.
107 changes: 0 additions & 107 deletions
107
...x Classic/src/main/java/plugily/projects/minigamesbox/classic/kits/KitAbilityHandler.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
... Classic/src/main/java/plugily/projects/minigamesbox/classic/kits/ability/KitAbility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* MiniGamesBox - Library box with massive content that could be seen as minigames core. | ||
* Copyright (C) 2023 Plugily Projects - maintained by Tigerpanzer_02 and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package plugily.projects.minigamesbox.classic.kits.ability; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import plugily.projects.minigamesbox.classic.PluginMain; | ||
import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; | ||
import plugily.projects.minigamesbox.classic.user.User; | ||
import plugily.projects.minigamesbox.classic.utils.helper.ArmorHelper; | ||
import plugily.projects.minigamesbox.classic.utils.version.events.api.PlugilyPlayerInteractEvent; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public class KitAbility { | ||
private static final PluginMain plugin = JavaPlugin.getPlugin(PluginMain.class); | ||
private static final Map<String, KitAbility> kitAbilities = new HashMap<>(); | ||
|
||
static { | ||
kitAbilities.put("NO_ARMOUR", new KitAbility("NO_ARMOUR", inventoryClickEvent -> { | ||
if(!(inventoryClickEvent.getInventory().getType().equals(InventoryType.PLAYER) || inventoryClickEvent.getInventory().getType().equals(InventoryType.CRAFTING))) { | ||
return; | ||
} | ||
User user = plugin.getUserManager().getUser((Player) inventoryClickEvent.getWhoClicked()); | ||
Bukkit.getScheduler().runTaskLater(plugin, () -> { | ||
for(ItemStack stack : inventoryClickEvent.getWhoClicked().getInventory().getArmorContents()) { | ||
if(stack == null || !ArmorHelper.getArmorTypes().contains(stack.getType())) { | ||
continue; | ||
} | ||
//we cannot cancel event using scheduler, we must remove all armor contents from inventory manually | ||
new MessageBuilder("KIT_CANNOT_WEAR_ARMOR").asKey().send(user.getPlayer()); | ||
inventoryClickEvent.getWhoClicked().getInventory().setHelmet(new ItemStack(Material.AIR, 1)); | ||
inventoryClickEvent.getWhoClicked().getInventory().setChestplate(new ItemStack(Material.AIR, 1)); | ||
inventoryClickEvent.getWhoClicked().getInventory().setLeggings(new ItemStack(Material.AIR, 1)); | ||
inventoryClickEvent.getWhoClicked().getInventory().setBoots(new ItemStack(Material.AIR, 1)); | ||
return; | ||
} | ||
}, 1); | ||
}, playerInteractHandler -> { | ||
if(ArmorHelper.getArmorTypes().contains(playerInteractHandler.getItem().getType())) { | ||
playerInteractHandler.setCancelled(true); | ||
new MessageBuilder("KIT_CANNOT_WEAR_ARMOR").asKey().player(playerInteractHandler.getPlayer()).sendPlayer(); | ||
} | ||
})); | ||
} | ||
|
||
private final String name; | ||
private final Consumer<InventoryClickEvent> clickConsumer; | ||
private final Consumer<PlugilyPlayerInteractEvent> interactConsumer; | ||
|
||
public KitAbility(String name, Consumer<InventoryClickEvent> inventoryClickHandler, Consumer<PlugilyPlayerInteractEvent> playerInteractHandler) { | ||
this.name = name; | ||
this.clickConsumer = inventoryClickHandler; | ||
this.interactConsumer = playerInteractHandler; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Consumer<InventoryClickEvent> getClickConsumer() { | ||
return clickConsumer; | ||
} | ||
|
||
public Consumer<PlugilyPlayerInteractEvent> getInteractConsumer() { | ||
return interactConsumer; | ||
} | ||
|
||
public static Map<String, KitAbility> getKitAbilities() { | ||
return Collections.unmodifiableMap(kitAbilities); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...c/src/main/java/plugily/projects/minigamesbox/classic/kits/ability/KitAbilityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* MiniGamesBox - Library box with massive content that could be seen as minigames core. | ||
* Copyright (C) 2023 Plugily Projects - maintained by Tigerpanzer_02 and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package plugily.projects.minigamesbox.classic.kits.ability; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import plugily.projects.minigamesbox.classic.PluginMain; | ||
import plugily.projects.minigamesbox.classic.user.User; | ||
import plugily.projects.minigamesbox.classic.utils.version.events.api.PlugilyPlayerInteractEvent; | ||
|
||
public class KitAbilityHandler implements Listener { | ||
|
||
private final PluginMain plugin; | ||
|
||
public KitAbilityHandler(PluginMain plugin) { | ||
this.plugin = plugin; | ||
if(!plugin.getConfigPreferences().getOption("KITS")) { | ||
return; | ||
} | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onKitInventoryClick(InventoryClickEvent event) { | ||
if(!(event.getWhoClicked() instanceof Player)) { | ||
return; | ||
} | ||
User user = plugin.getUserManager().getUser((Player) event.getWhoClicked()); | ||
if(!plugin.getArenaRegistry().isInArena((Player) event.getWhoClicked())) { | ||
return; | ||
} | ||
for(KitAbility kitAbility : plugin.getKitAbilityManager().getKitAbilities().values()) { | ||
if(user.getKit().hasAbility(kitAbility)) { | ||
kitAbility.getClickConsumer().accept(event); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onKitInteractClick(PlugilyPlayerInteractEvent event) { | ||
if(!plugin.getArenaRegistry().isInArena(event.getPlayer())) { | ||
return; | ||
} | ||
if(!event.hasItem()) { | ||
return; | ||
} | ||
for(KitAbility kitAbility : plugin.getKitAbilityManager().getKitAbilities().values()) { | ||
if(plugin.getUserManager().getUser(event.getPlayer()).getKit().hasAbility(kitAbility)) { | ||
kitAbility.getInteractConsumer().accept(event); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.