use of org.bukkit.metadata.FixedMetadataValue in project MyPet by xXKeyleXx.
the class MyPet method createEntity.
public SpawnFlags createEntity() {
lastUsed = System.currentTimeMillis();
if (status != PetState.Here && getOwner().isOnline()) {
Player owner = getOwner().getPlayer();
if (owner.isDead()) {
status = PetState.Despawned;
return SpawnFlags.OwnerDead;
}
if (owner.getGameMode().name().equals("SPECTATOR")) {
return SpawnFlags.Spectator;
}
if (respawnTime <= 0) {
Location loc = petOwner.getPlayer().getLocation();
if (!WorldGroup.getGroupByWorld(loc.getWorld().getName()).getName().equals(getWorldGroup())) {
return SpawnFlags.WrongWorldGroup;
}
if (owner.isFlying()) {
boolean groundFound = false;
for (int i = 10; i >= 0; i--) {
Block b = loc.getBlock();
if (b.getRelative(BlockFace.DOWN).getType().isSolid()) {
groundFound = true;
break;
}
loc = loc.subtract(0, 1, 0);
}
if (!groundFound) {
return SpawnFlags.Flying;
}
}
MyPetCallEvent event = new MyPetCallEvent(this);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return SpawnFlags.NotAllowed;
}
MyPetMinecraftEntity minecraftEntity = MyPetApi.getEntityRegistry().createMinecraftEntity(this, loc.getWorld());
if (minecraftEntity == null) {
status = PetState.Despawned;
return SpawnFlags.Canceled;
}
bukkitEntity = minecraftEntity.getBukkitEntity();
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
Random r = new Random(petOwner.getInternalUUID().toString().hashCode());
String random = RandomStringUtils.random(10, 0, 0, true, true, null, r);
Team t;
if (owner.getScoreboard().getTeam("MyPet-" + random) != null) {
t = owner.getScoreboard().getTeam("MyPet-" + random);
} else {
t = owner.getScoreboard().registerNewTeam("MyPet-" + random);
t.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
}
for (String entry : t.getEntries()) {
t.removeEntry(entry);
}
t.addEntry(minecraftEntity.getUniqueID().toString());
}
if (getYSpawnOffset() > 0) {
loc = loc.add(0, getYSpawnOffset(), 0);
}
loc.setPitch(0);
loc.setYaw(0);
Location origin = loc.clone();
boolean positionFound = false;
loc.subtract(1, 0, 1);
for (double x = 0; x <= 2; x += 0.5) {
for (double z = 0; z <= 2; z += 0.5) {
if (x != 1 && z != 1) {
minecraftEntity.setLocation(loc);
if (MyPetApi.getPlatformHelper().canSpawn(loc, minecraftEntity)) {
Block b = loc.getBlock();
if (b.getRelative(BlockFace.DOWN).getType().isSolid()) {
positionFound = true;
break;
}
}
}
loc.add(0, 0, 0.5);
}
if (positionFound) {
break;
}
loc.subtract(0, 0, 2);
loc.add(0.5, 0, 0);
}
if (!positionFound) {
minecraftEntity.setLocation(origin);
if (!MyPetApi.getPlatformHelper().canSpawn(origin, minecraftEntity)) {
status = PetState.Despawned;
return SpawnFlags.NoSpace;
}
}
if (MyPetApi.getEntityRegistry().spawnMinecraftEntity(minecraftEntity, loc.getWorld())) {
bukkitEntity.setMetadata("MyPet", new FixedMetadataValue(MyPetApi.getPlugin(), this));
status = PetState.Here;
if (worldGroup == null || worldGroup.equals("")) {
setWorldGroup(WorldGroup.getGroupByWorld(loc.getWorld().getName()).getName());
}
autoAssignSkilltree();
wantsToRespawn = false;
return SpawnFlags.Success;
}
return SpawnFlags.Canceled;
}
}
if (status == PetState.Dead) {
return SpawnFlags.Dead;
} else {
return SpawnFlags.AlreadyHere;
}
}
use of org.bukkit.metadata.FixedMetadataValue in project MyPet by xXKeyleXx.
the class EntityListener method on.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on(EntityShootBowEvent event) {
if (Configuration.Misc.ALLOW_RANGED_LEASHING) {
if (event.getEntity() instanceof Player) {
if (event.getProjectile() instanceof Arrow) {
Player player = (Player) event.getEntity();
Arrow projectile = (Arrow) event.getProjectile();
PlayerInventory inventory = player.getInventory();
if (event.getBow() != null) {
projectile.setMetadata("MyPetLeashItem", new FixedMetadataValue(MyPetApi.getPlugin(), event.getBow().clone()));
}
ItemStack arrow = null;
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
switch(inventory.getItemInOffHand().getType()) {
case ARROW:
case TIPPED_ARROW:
case SPECTRAL_ARROW:
arrow = inventory.getItemInOffHand();
}
switch(inventory.getItemInMainHand().getType()) {
case ARROW:
case TIPPED_ARROW:
case SPECTRAL_ARROW:
arrow = inventory.getItemInMainHand();
}
}
if (arrow == null) {
int firstArrow = -1;
int normalArrow = inventory.first(Material.ARROW);
if (normalArrow != -1) {
arrow = inventory.getItem(inventory.first(Material.ARROW));
firstArrow = normalArrow;
}
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
int tippedFirst = inventory.first(Material.TIPPED_ARROW);
if (tippedFirst != -1 && firstArrow > tippedFirst) {
arrow = inventory.getItem(inventory.first(Material.TIPPED_ARROW));
firstArrow = tippedFirst;
}
}
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
int spectralFirst = inventory.first(Material.SPECTRAL_ARROW);
if (spectralFirst != -1 && firstArrow > spectralFirst) {
arrow = inventory.getItem(inventory.first(Material.SPECTRAL_ARROW));
}
}
}
if (arrow != null) {
projectile.setMetadata("MyPetLeashItemArrow", new FixedMetadataValue(MyPetApi.getPlugin(), arrow.clone()));
}
}
}
}
}
use of org.bukkit.metadata.FixedMetadataValue in project WildernessTp by AcmeProject.
the class TeleportGoneWild method n0tAGreifClam.
public boolean n0tAGreifClam(Location l0c0, Player player) {
if (instace.useExperimentalChekar && player != null) {
try {
player.setMetadata("nocheat.exempt", new FixedMetadataValue(instace, true));
BlurredBlockBreakEvent iHopePluginsDontFreakOutOverThis = new BlurredBlockBreakEvent(l0c0.getBlock(), new JohnBonifield(player));
instace.getServer().getPluginManager().callEvent(iHopePluginsDontFreakOutOverThis);
player.removeMetadata("nocheat.exempt", instace);
return !iHopePluginsDontFreakOutOverThis.isExposed();
} catch (Throwable rock) {
if (!isDebug)
instace.getLogger().warning("Unable to useExperimentalClaimCheck. For more details, set the following in the config.yml: debug: true");
else
rock.printStackTrace();
}
}
if (dataaaastorege != null) {
return instace.dataaaastorege.getClaimAt(l0c0, true, null) == null;
}
return true;
}
use of org.bukkit.metadata.FixedMetadataValue in project Minigames by AddstarMC.
the class ScoreboardDisplay method load.
@SuppressWarnings("deprecation")
public static ScoreboardDisplay load(Minigame minigame, ConfigurationSection section) {
int width = section.getInt("width");
int height = section.getInt("height");
Location location = MinigameUtils.loadShortLocation(section.getConfigurationSection("location"));
BlockFace facing = BlockFace.valueOf(section.getString("dir"));
// from invalid world
if (location == null) {
return null;
}
ScoreboardDisplay display = new ScoreboardDisplay(minigame, width, height, location, facing);
display.setOrder(ScoreboardOrder.valueOf(section.getString("order")));
// Convert type to new stat
if (section.contains("type")) {
ScoreboardType type = ScoreboardType.valueOf(section.getString("type"));
switch(type) {
case BEST_KILLS:
display.setStat(MinigameStats.Kills, StatValueField.Max);
break;
case BEST_SCORE:
display.setStat(MinigameStats.Score, StatValueField.Max);
break;
case COMPLETIONS:
display.setStat(MinigameStats.Wins, StatValueField.Total);
break;
case FAILURES:
display.setStat(MinigameStats.Losses, StatValueField.Total);
break;
case LEAST_DEATHS:
display.setStat(MinigameStats.Deaths, StatValueField.Min);
break;
case LEAST_REVERTS:
display.setStat(MinigameStats.Reverts, StatValueField.Min);
break;
case LEAST_TIME:
display.setStat(MinigameStats.CompletionTime, StatValueField.Min);
break;
case TOTAL_DEATHS:
display.setStat(MinigameStats.Deaths, StatValueField.Total);
break;
case TOTAL_KILLS:
display.setStat(MinigameStats.Kills, StatValueField.Total);
break;
case TOTAL_REVERTS:
display.setStat(MinigameStats.Reverts, StatValueField.Total);
break;
case TOTAL_SCORE:
display.setStat(MinigameStats.Score, StatValueField.Total);
break;
case TOTAL_TIME:
display.setStat(MinigameStats.CompletionTime, StatValueField.Total);
break;
default:
break;
}
section.set("type", null);
// Load stat
} else {
MinigameStat stat = MinigameStats.getStat(section.getString("stat", "wins"));
StatValueField field = StatValueField.valueOf(section.getString("field", "Total"));
display.setStat(stat, field);
}
Block block = location.getBlock();
block.setMetadata("MGScoreboardSign", new FixedMetadataValue(Minigames.plugin, true));
block.setMetadata("Minigame", new FixedMetadataValue(Minigames.plugin, minigame));
return display;
}
use of org.bukkit.metadata.FixedMetadataValue in project Minigames by AddstarMC.
the class SpawnEntityAction method executeNodeAction.
@Override
public void executeNodeAction(MinigamePlayer player, Node node) {
if (player == null || !player.isInMinigame())
return;
final Entity ent = node.getLocation().getWorld().spawnEntity(node.getLocation(), EntityType.valueOf(type.getFlag()));
final double vx = Double.valueOf(settings.get("velocityx"));
final double vy = Double.valueOf(settings.get("velocityy"));
final double vz = Double.valueOf(settings.get("velocityz"));
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
@Override
public void run() {
ent.setVelocity(new Vector(vx, vy, vz));
}
});
if (ent instanceof LivingEntity) {
LivingEntity lent = (LivingEntity) ent;
if (settings.containsKey("displayname")) {
lent.setCustomName(settings.get("displayname"));
lent.setCustomNameVisible(Boolean.getBoolean(settings.get("displaynamevisible")));
}
}
ent.setMetadata("MinigameEntity", new FixedMetadataValue(Minigames.plugin, true));
player.getMinigame().getBlockRecorder().addEntity(ent, player, true);
}
Aggregations