Skip to content

Commit

Permalink
Fixed some bugs and added new item
Browse files Browse the repository at this point in the history
  • Loading branch information
IamTheDefender authored Jan 11, 2023
1 parent d7694b4 commit 9618aef
Show file tree
Hide file tree
Showing 7 changed files with 1,166 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/defender/itemrotation/ItemRotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import me.defender.itemrotation.listeners.onRightClick;
import me.defender.itemrotation.listeners.onShopOpen;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.defender.itemrotation.api.utils;

import me.defender.itemrotation.api.utils.gsound.GSound;
import me.defender.itemrotation.items.SugarkenRotationItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void move() {
((Player) entity).damage(this.damage, this.player);
this.star.remove();
isAlive = false;
player.playSound(player.getLocation(), GSound.ENTITY_ARROW_HIT_PLAYER.parseSound(), 1.0f, 1.0f);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package me.defender.itemrotation.api.utils;

import com.andrei1058.bedwars.api.language.Language;
import me.defender.itemrotation.items.BridgeZapperRotationItem;
import me.defender.itemrotation.items.IceBridgeRotationItem;
import me.defender.itemrotation.items.SugarkenRotationItem;
import me.defender.itemrotation.items.SuperCookieRotationItem;
import me.defender.itemrotation.items.*;
import org.bukkit.Material;

import java.util.Arrays;
Expand All @@ -27,6 +24,7 @@ public static void registerItems(){
new SuperCookieRotationItem().register();
new IceBridgeRotationItem().register();
new BridgeZapperRotationItem().register();
new FestivityMineRotationItem().register();
}

public static void addValuesToConfig(){
Expand Down
1,069 changes: 1,069 additions & 0 deletions src/main/java/me/defender/itemrotation/api/utils/gsound/GSound.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public boolean execute(Player player, Block block) {
// Player or block is null, return false
return false;
}

if(!API.getBedwarsAPI().getArenaUtil().getArenaByPlayer(player).isBlockPlaced(block)){
player.sendMessage(Language.getMsg(player, "item-rotation.Bridge-Zapper.deny"));
return false;
}
if (!isWool(block)) {
player.sendMessage(Language.getMsg(player, "item-rotation.Bridge-Zapper.deny"));
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package me.defender.itemrotation.items;

import com.hakan.core.HCore;
import me.defender.itemrotation.API;
import me.defender.itemrotation.api.RotationItem;
import me.defender.itemrotation.api.utils.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class FestivityMineRotationItem extends RotationItem {
@Override
public ItemStack getItem() {
return XMaterial.GRAY_CARPET.parseItem();
}

@Override
public String defaultName() {
return "Festivity Mine";
}

@Override
public List<String> defaultLore() {
return Arrays.asList("&7Cost: &6%price% Gold", "", "&7Spawns a mine that will blast,", "&7if enemy player walks on it", "", "%BuyStatus%");
}

@Override
public int getPrice() {
return 10;
}

@Override
public Material getCurrency() {
return Material.GOLD_INGOT;
}

@Override
public boolean execute(Player player, Block block) {
spawnGrayCarpetAndBlowUpOnEnemy(player);
return true;
}
public void spawnGrayCarpetAndBlowUpOnEnemy(Player player) {
// Get the player's foot block
Block footBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
footBlock = footBlock.getLocation().add(0,1,0).getBlock();

// Set the block to a gray carpet
footBlock.setType(XMaterial.GRAY_CARPET.parseMaterial());

// Create a new task to check for players walking on the carpet
Block finalFootBlock = footBlock;
HCore.syncScheduler().every(1).run(() -> {
// Get all players standing on the carpet
List<Player> playersOnCarpet = finalFootBlock.getWorld().getPlayers().stream()
.filter(p -> p.getLocation().getBlock().equals(finalFootBlock))
.collect(Collectors.toList());

// If there are any players on the carpet, blow them up
if (!playersOnCarpet.isEmpty()) {
boolean blast = false;
for (Player p : playersOnCarpet) {
// Check if the player is on a different team
if(!API.getBedwarsAPI().getArenaUtil().getArenaByPlayer(player).getTeam(player).getMembers().contains(p)) {
blast = true;
}
}
if(blast){
TNTPrimed tnt = (TNTPrimed) finalFootBlock.getWorld().spawnEntity(finalFootBlock.getLocation(), EntityType.PRIMED_TNT);
tnt.setFuseTicks(0); // Make the TNT explode immediately
finalFootBlock.setType(Material.AIR);
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.hakan.core.ui.inventory.InventoryGui;
import me.defender.itemrotation.api.RotationItem;
import me.defender.itemrotation.API;
import me.defender.itemrotation.api.utils.gsound.GSound;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -101,12 +102,14 @@ public void onOpen(@Nonnull Player player) {
// add item to player's inventory ._.
e.getWhoClicked().getInventory().addItem(HCore.itemBuilder(item1.getItem()).name(true, ChatColor.RED + name).build());
// send message to the player .-.
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), GSound.ENTITY_VILLAGER_YES.parseSound(), 1.0f, 1.0f);
e.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
Language.getMsg((Player)e.getWhoClicked(), "shop-new-purchase")
.replace("{prefix}", Language.getMsg((Player)e.getWhoClicked(), "prefix"))
.replace("{item}", "&a" + name)));
}else{
// send not enough resources message .-.
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), GSound.ENTITY_VILLAGER_NO.parseSound(), 1.0f, 1.0f);
e.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
Language.getMsg((Player)e.getWhoClicked(), "shop-insuff-money")
.replace("{prefix}", Language.getMsg((Player)e.getWhoClicked(), "prefix"))
Expand Down

0 comments on commit 9618aef

Please sign in to comment.