Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Update 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonmaribo committed Jan 16, 2021
1 parent 8383f43 commit 997d42f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/dk/simonmaribo/endcrate/CrateOpen.java
Expand Up @@ -46,6 +46,9 @@ public static void openEndCrate(Block block, Player player){
armorStand.setSmall(true);
armorStand.setVisible(false);
armorStand.setCustomName("EndCrateArmorStand");
Main.getArmorStandList().add(armorStand);


ItemStack head = SkullCreator.itemFromUrl("http://textures.minecraft.net/texture/1fe8e7f2db8eaa88a041c89d4c353d066cc4edef77edcf5e08bb5d3baad");
armorStand.setHelmet(head);
final Collection<? extends Player> players = Bukkit.getOnlinePlayers();
Expand Down Expand Up @@ -100,12 +103,13 @@ public void run() {
i++;
if (i == 1) {
Location loc = armorStand.getEyeLocation();
loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1f, false, false);
loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 0f, false, false);
ParticleEffect.CLOUD.send(players, armorStand.getLocation().add(0, 1, 0), 0, 0, 0, 0.1, 10);
player.playSound(armorStand.getLocation(), Sound.LEVEL_UP, (float) 1.99, 0);
}
if (i == 50) {
armorStand.remove();
Main.getArmorStandList().remove(armorStand);

cancel();
}
Expand All @@ -123,12 +127,14 @@ public void run() {
hologram.setVisible(false);
hologram.setCustomNameVisible(true);
hologram.setCustomName(Main.getColored(holoOverCrate));
Main.getArmorStandList().add(hologram);

ArmorStand hologram2 = (ArmorStand) armorStand.getWorld().spawnEntity(armorStand.getLocation().add(0, -0.8, 0), EntityType.ARMOR_STAND);
hologram2.setGravity(false);
hologram2.setVisible(false);
hologram2.setCustomNameVisible(true);
hologram2.setCustomName(Main.getColored(prizeWon.getName()));
Main.getArmorStandList().add(hologram2);

}
if(i == 5){
Expand All @@ -139,6 +145,7 @@ public void run() {
for (Entity ent : armorStand.getWorld().getChunkAt(armorStand.getLocation()).getEntities()){
if(ent.getCustomName() != null) {
if (ent.getCustomName().equals(Main.getColored(holoOverCrate)) || ent.getCustomName().equals(Main.getColored(prizeWon.getName()))) {
Main.getArmorStandList().remove((ArmorStand) ent);
ent.remove();
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/dk/simonmaribo/endcrate/Main.java
Expand Up @@ -13,10 +13,14 @@
import dk.simonmaribo.endcrate.commands.EndcrateCommand;

import dk.simonmaribo.endcrate.listener.EndCrateClickEvent;
import dk.simonmaribo.endcrate.listener.EndCratePreviewClickEvent;
import dk.simonmaribo.endcrate.listener.EntityClickEvent;
import dk.simonmaribo.endcrate.utils.ConfigWrapper;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -43,6 +47,12 @@ public static Plugin getInstance() {
return instance;
}

private static List<ArmorStand> armorStandList = new ArrayList<>();

public static List<ArmorStand> getArmorStandList() {
return armorStandList;
}

@Override
public void onEnable() {
if(Bukkit.getPluginManager().getPlugin("ParticleLIB") == null){
Expand All @@ -65,13 +75,18 @@ public void onEnable() {

getCommand("endcrate").setExecutor(new EndcrateCommand(this));
getServer().getPluginManager().registerEvents(new EndCrateClickEvent(this), this);
getServer().getPluginManager().registerEvents(new EndCratePreviewClickEvent(this), this);
getServer().getPluginManager().registerEvents(new EntityClickEvent(this), this);
rc = new CrateConfig();
rc.reload();
rc.reloadLocations();
}

@Override
public void onDisable() {
for(Entity ent : armorStandList){
ent.remove();
}
}

public static String getColored(String s){return ChatColor.translateAlternateColorCodes('&', s);}
Expand Down
Expand Up @@ -44,7 +44,6 @@ public void onCrateClick(PlayerInteractEvent event){
event.setCancelled(true);
if (Main.endcrateYML.getBoolean("EndCrate.Preview")) {
player.openInventory(Main.rc.getPreview());

}
}
}
Expand Down Expand Up @@ -91,6 +90,7 @@ public void onCrateClick(PlayerInteractEvent event){
player.sendMessage(Main.getColored(Main.messagesYML.getString("no-key")));
}
}
return;
}
}
}
Expand Down
@@ -0,0 +1,36 @@
/*
AUTHOR: FlupMC
CONTRIBUTORS: Steilgaard
WEBSITE: simonmaribo.dk
SUPPORT: discord.simonmaribo.dk
Copyright 2021 © Simon Maribo
*/
package dk.simonmaribo.endcrate.listener;

import dk.simonmaribo.endcrate.Main;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

public class EndCratePreviewClickEvent implements Listener {
private Main main;

public EndCratePreviewClickEvent(Main main) {
this.main = main;
}

@EventHandler
public void onEndCratePreviewClick(InventoryClickEvent event){
Player player = (Player) event.getWhoClicked();
if(event.getClickedInventory().getTitle() == Main.rc.getPreview().getTitle()){
if (String.valueOf(event.getClickedInventory()).replaceAll("Custom", "").equals(String.valueOf(Main.rc.getPreview()).replaceAll("Custom", ""))) {
event.setCancelled(true);
}
}

}
}
33 changes: 33 additions & 0 deletions src/dk/simonmaribo/endcrate/listener/EntityClickEvent.java
@@ -0,0 +1,33 @@
/*
AUTHOR: FlupMC
CONTRIBUTORS: Steilgaard
WEBSITE: simonmaribo.dk
SUPPORT: discord.simonmaribo.dk
Copyright 2021 © Simon Maribo
*/

package dk.simonmaribo.endcrate.listener;

import dk.simonmaribo.endcrate.Main;
import org.bukkit.entity.ArmorStand;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;

public class EntityClickEvent implements Listener {
private Main main;
public EntityClickEvent(Main main){
this.main = main;
}

@EventHandler
public void onArmorStandClick(PlayerInteractAtEntityEvent event){
if(!(event.getRightClicked() instanceof ArmorStand)) return;

if(Main.getArmorStandList().contains((ArmorStand) event.getRightClicked())) event.setCancelled(true);

}
}
2 changes: 1 addition & 1 deletion src/messages.yml
Expand Up @@ -2,4 +2,4 @@ no-key: "&8[&aEndCrate&8] &7You do not have the required key."
already-being-used: "&8[&aEndCrate&8] &7This crate is already being used."
hologram-over-crate: "&2&l&nLimited Crate"
preview-title: "&a&lEndcrate Prices"
chance-lore: "&7Chance&8: {CHANCE}%"
chance-lore: "&7Chance&8: &a{CHANCE}%"
2 changes: 1 addition & 1 deletion src/plugin.yml
Expand Up @@ -9,7 +9,7 @@

name: EndCrate
main: dk.simonmaribo.endcrate.Main
version: 1.0.0
version: 1.0.2
authors: [Steilgaard, FlupMC]
website: www.simonmaribo.dk
depend: [ParticleLIB]
Expand Down

0 comments on commit 997d42f

Please sign in to comment.