diff --git a/.idea/artifacts/PetFaction_jar.xml b/.idea/artifacts/PetFaction_jar.xml
new file mode 100644
index 0000000..99fbab4
--- /dev/null
+++ b/.idea/artifacts/PetFaction_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/../../Server/plugins
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/worldedit_bukkit_6_1_7_2.xml b/.idea/libraries/worldedit_bukkit_6_1_7_2.xml
new file mode 100644
index 0000000..9bfe489
--- /dev/null
+++ b/.idea/libraries/worldedit_bukkit_6_1_7_2.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/worldguard.xml b/.idea/libraries/worldguard.xml
new file mode 100644
index 0000000..25415f8
--- /dev/null
+++ b/.idea/libraries/worldguard.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/config.yml b/src/config.yml
index 76b12c3..782453c 100644
--- a/src/config.yml
+++ b/src/config.yml
@@ -2,12 +2,14 @@
# Github: github.com/Niketion/PetFaction
faction-depend: true
list-commands:
+ - '&7&m+--------------------------------------------------+'
- '&a/pet gui &7- Open gui'
- '&a/pet shop &7- Open shop'
- '&a/pet here &7- Teletransport the pet into your position'
- '&a/pet change &7- Change your pet'
- '&a/pet name &7- Change name'
- '&a/pet away &7- Despawn pet'
+ - '&7&m+--------------------------------------------------+'
arguments-not-found: '&cArguments not found...'
duration-potion-pet: 10 #minutes
vip-pet: "&eBuy vip to buy this pet!"
diff --git a/src/github/niketion/petfaction/Main.java b/src/github/niketion/petfaction/Main.java
index 4fb2d8f..b714ddb 100644
--- a/src/github/niketion/petfaction/Main.java
+++ b/src/github/niketion/petfaction/Main.java
@@ -1,5 +1,6 @@
package github.niketion.petfaction;
+import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import github.niketion.petfaction.command.CommandPet;
import github.niketion.petfaction.listener.ListenerPetFaction;
import github.niketion.petfaction.petfollow.*;
@@ -7,8 +8,12 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
-import org.bukkit.entity.*;
+import org.bukkit.entity.Animals;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Monster;
+import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@@ -269,4 +274,14 @@ public boolean hasPet(Player player) {
return false;
}
}
+
+ public WorldGuardPlugin getWorldGuard() {
+ Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
+
+ if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
+ return null;
+ }
+
+ return (WorldGuardPlugin) plugin;
+ }
}
diff --git a/src/github/niketion/petfaction/SpawnEntity.java b/src/github/niketion/petfaction/SpawnEntity.java
index d4be5aa..c4d7911 100644
--- a/src/github/niketion/petfaction/SpawnEntity.java
+++ b/src/github/niketion/petfaction/SpawnEntity.java
@@ -9,47 +9,41 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
-import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
/**
- This class has been designed to bypass the
- "mob-spawning" of worldguard or other plugins
+ * This class has been designed to bypass the
+ * "mob-spawning" of worldguard or other plugins
*/
-class SpawnEntity implements Listener {
+public class SpawnEntity implements Listener {
private Main main = Main.getInstance();
private Player player;
- /** Check if entity spawned is a pet */
- private boolean isPet = false;
+ /**
+ * Check if entity spawned is a pet
+ */
+ private static boolean isPet = false;
+
+ public static void setPet(boolean pet) {
+ isPet = pet;
+ }
SpawnEntity(Player player) {
this.player = player;
}
- SpawnEntity() { }
-
- @EventHandler(ignoreCancelled = true)
- public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
- if (event.getMessage().contains("/pet")) {
- isPet = true;
- main.getServer().getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
- @Override
- public void run() {
- isPet = false;
- }
- }, 5L);
- }
+ SpawnEntity() {
}
private boolean force = true;
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onSpawn(CreatureSpawnEvent event){
- if (force){
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onSpawn(CreatureSpawnEvent event) {
+ if (force) {
if (isPet)
event.setCancelled(false);
}
@@ -59,56 +53,56 @@ void spawn() {
force = false;
//try {
- FileConfiguration config = main.getConfig();
- FileConfiguration petConfig = new FilePet(player).getPetConfig();
- World worldPlayer = player.getWorld();
+ FileConfiguration config = main.getConfig();
+ FileConfiguration petConfig = new FilePet(player).getPetConfig();
+ World worldPlayer = player.getWorld();
- for (World worlds : main.getServer().getWorlds())
- for (Entity entities : worlds.getEntities())
- if (entities.hasMetadata(player.getName())) {
- entities.remove();
- }
+ for (World worlds : main.getServer().getWorlds())
+ for (Entity entities : worlds.getEntities())
+ if (entities.hasMetadata(player.getName())) {
+ entities.remove();
+ }
- if (main.petDeath.contains(player.getName())) {
- player.sendMessage(main.getFormat(config.getString("pet-death").replaceAll("%number%", String.valueOf(config.getInt("pet-death-minutes")))));
- return;
- }
+ if (main.petDeath.contains(player.getName())) {
+ player.sendMessage(main.getFormat(config.getString("pet-death").replaceAll("%number%", String.valueOf(config.getInt("pet-death-minutes")))));
+ return;
+ }
- String namePet = petConfig.getString("name");
+ String namePet = petConfig.getString("name");
- // Get pet, set character
- LivingEntity entity = (LivingEntity) worldPlayer.spawnEntity(player.getLocation(), EntityType.valueOf(petConfig.getString("pet")));
- if (entity instanceof Ageable) {
- ((Ageable) entity).setBaby();
- ((Ageable) entity).setAgeLock(true);
- }
+ // Get pet, set character
+ LivingEntity entity = (LivingEntity) worldPlayer.spawnEntity(player.getLocation(), EntityType.valueOf(petConfig.getString("pet")));
+ if (entity instanceof Ageable) {
+ ((Ageable) entity).setBaby();
+ ((Ageable) entity).setAgeLock(true);
+ }
- double hearts = (double) config.getInt("gui.1.hearts." + petConfig.getInt("hearts")) * 2;
- entity.setMaxHealth(hearts);
- entity.setHealth(hearts);
+ double hearts = (double) config.getInt("gui.1.hearts." + petConfig.getInt("hearts")) * 2;
+ entity.setMaxHealth(hearts);
+ entity.setHealth(hearts);
- if (!(petConfig.getInt("level") == 0)) {
- for (PotionEffect effect : player.getActivePotionEffects())
- player.removePotionEffect(effect.getType());
+ if (!(petConfig.getInt("level") == 0)) {
+ for (PotionEffect effect : player.getActivePotionEffects())
+ player.removePotionEffect(effect.getType());
- ConfigurationSection sectionPotion = petConfig.getConfigurationSection("potion-pet");
+ ConfigurationSection sectionPotion = petConfig.getConfigurationSection("potion-pet");
- if (sectionPotion != null)
- for (String strings : sectionPotion.getKeys(false))
- player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(strings), config.getInt("duration-potion-pet") * 60 * 20,
- petConfig.getInt("potion-pet." + strings) - 1));
+ if (sectionPotion != null)
+ for (String strings : sectionPotion.getKeys(false))
+ player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(strings), config.getInt("duration-potion-pet") * 60 * 20,
+ petConfig.getInt("potion-pet." + strings) - 1));
- }
+ }
- if (namePet != null) {
- entity.setCustomName(main.getFormat(namePet + config.getString("level-pet").replaceAll("%level%", String.valueOf(petConfig.getInt("level")))));
- } else {
- entity.setCustomName(main.getFormat(config.getString("default-name-pet").replaceAll("%player%", player.getName()) + " " + config.getString("level-pet").replaceAll("%level%",
- String.valueOf(petConfig.getInt("level")))));
- }
- entity.setMetadata(player.getName(), new FixedMetadataValue(Main.getInstance(), "yes!"));
+ if (namePet != null) {
+ entity.setCustomName(main.getFormat(namePet + config.getString("level-pet").replaceAll("%level%", String.valueOf(petConfig.getInt("level")))));
+ } else {
+ entity.setCustomName(main.getFormat(config.getString("default-name-pet").replaceAll("%player%", player.getName()) + " " + config.getString("level-pet").replaceAll("%level%",
+ String.valueOf(petConfig.getInt("level")))));
+ }
+ entity.setMetadata(player.getName(), new FixedMetadataValue(Main.getInstance(), "yes!"));
- main.getPetFollow(player, entity);
+ main.getPetFollow(player, entity);
//} catch (NullPointerException ignored) {}
force = true;
}
diff --git a/src/github/niketion/petfaction/command/CommandPet.java b/src/github/niketion/petfaction/command/CommandPet.java
index d63380b..a113893 100644
--- a/src/github/niketion/petfaction/command/CommandPet.java
+++ b/src/github/niketion/petfaction/command/CommandPet.java
@@ -2,10 +2,10 @@
import github.niketion.petfaction.Main;
import github.niketion.petfaction.Permissions;
+import github.niketion.petfaction.SpawnEntity;
import github.niketion.petfaction.file.FilePet;
import github.niketion.petfaction.gui.GUI;
import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -19,7 +19,8 @@
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
-import java.util.*;
+import java.util.Arrays;
+import java.util.List;
public class CommandPet implements CommandExecutor {
@@ -30,6 +31,14 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
return false;
}
+ SpawnEntity.setPet(true);
+ Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
+ @Override
+ public void run() {
+ SpawnEntity.setPet(false);
+ }
+ }, 5L);
+
assert commandSender instanceof Player;
Player player = (Player) commandSender;
@@ -54,6 +63,8 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
if (Main.getInstance().hasPet(player)) {
Main.getInstance().spawnPetHere(player);
}
+
+
return true;
case "away":
if (hasPermission(player, Permissions.COMMAND_AWAY))
@@ -111,7 +122,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}
/**
- * List arguments of command and credits
+ * List arguments
*
* @param commandSender - Who receives the message
*/
@@ -119,7 +130,6 @@ private void listArguments(CommandSender commandSender) {
for (String loopMessages : getConfig().getStringList("list-commands")) {
commandSender.sendMessage(format(loopMessages));
}
- commandSender.sendMessage(ChatColor.DARK_AQUA+"Plugin developed by "+ChatColor.AQUA+"@Niketion");
}
/**