Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/me/pkt77/giants/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa
if (sender instanceof Player) {
player = (Player) sender;
if (player.hasPermission("giants.reload")) {
API.getFileHandler().loadConfig();
_giants.getAPI().getFileHandler().loadConfig();
sender.sendMessage(ChatColor.GREEN + "Giants config file reloaded.");
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command");
}
} else {
API.getFileHandler().loadConfig();
_giants.getAPI().getFileHandler().loadConfig();
_giants.log.info("Giants config file reloaded.");
}
}
}
}
return true;
}
}
}
16 changes: 14 additions & 2 deletions src/me/pkt77/giants/Giants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class Giants extends JavaPlugin {
public final Logger log = Logger.getLogger("Minecraft");
private API api;

/*
* CHANGE LOG:
Expand Down Expand Up @@ -53,13 +54,24 @@ public class Giants extends JavaPlugin {

@Override
public void onEnable() {
new API(this);
api = new API();
api.setup(this);
if (Bukkit.getPluginManager().getPlugin("Spout") != null) {
log.info("[Giants] Found SpoutPlugin: Enabling Spout features.");
new GiantEgg(this);
new SpoutListener(this);
} else {
log.info("[Giants] Cannot Find SpoutPlugin: Disabling Spout features.");
}
log.info("[Giants] --- Enabled ---");
}
}

@Override
public void onDisable(){
log.info("[Giants] --- Disabled ---");
}

public API getAPI(){
return api;
}
}
42 changes: 23 additions & 19 deletions src/me/pkt77/giants/events/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Listeners(Giants giants) {

@EventHandler
public void onGiantSpawn(SpawnEvent event) {
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Debug Mode").equalsIgnoreCase("true")) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Debug Mode").equalsIgnoreCase("true")) {
String message = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Language.Debug Message");
if (message != null) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
Expand All @@ -59,7 +59,7 @@ public void GiantSpawnEvent(CreatureSpawnEvent event) {
EntityType type = event.getEntityType();
SpawnReason spawnReason = event.getSpawnReason();

if (!API.getGiantSpawnWorlds().contains(entity.getWorld().getName())) {
if (!_giants.getAPI().getGiantSpawnWorlds().contains(entity.getWorld().getName())) {
return;
}

Expand Down Expand Up @@ -99,6 +99,10 @@ public void GiantSpawnEvent(CreatureSpawnEvent event) {
if (spawngiant == 1) {
SpawnEvent SE = new SpawnEvent(location);
Bukkit.getServer().getPluginManager().callEvent(SE);
if (SE.isCancelled()){
spawngiant = 0;
return;
}
}
}
}
Expand All @@ -116,7 +120,7 @@ public void GiantHealth(EntityRegainHealthEvent event) {
health = 100;
}

if (API.isGiant(entity)) {
if (_giants.getAPI().isGiant(entity)) {
event.setAmount(health);
}
}
Expand All @@ -138,9 +142,9 @@ public void FireAttack(EntityTargetEvent event) {
}

if ((entity instanceof LivingEntity)) {
if (API.isGiant(entity)) {
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Fire Attack.Enabled").equalsIgnoreCase("true")) {
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Fire Attack").equalsIgnoreCase("true")) {
if (_giants.getAPI().isGiant(entity)) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Fire Attack.Enabled").equalsIgnoreCase("true")) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Fire Attack").equalsIgnoreCase("true")) {
target.getLocation().getWorld().playSound(target.getLocation(), Sound.FIRE, 1, 0);
}
try {
Expand All @@ -161,7 +165,7 @@ public void LightningAttack(EntityTargetEvent event) {
Entity target = event.getTarget();

if ((entity instanceof LivingEntity)) {
if (API.isGiant(entity)) {
if (_giants.getAPI().isGiant(entity)) {
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Lightning Attack").equalsIgnoreCase("true")) {
try {
target.getLocation().getWorld().strikeLightning(target.getLocation());
Expand All @@ -185,7 +189,7 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) {
}

for (Entity entity : player.getNearbyEntities(15, 12, 15)) {
if (API.isGiant(entity)) {
if (_giants.getAPI().isGiant(entity)) {
if (entity.getNearbyEntities(15, 12, 15).contains(player) && !entity.getNearbyEntities(5, 3, 5).contains(player)) {
inRange = true;
}
Expand All @@ -195,7 +199,7 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) {
Vector direction = ((LivingEntity) entity).getEyeLocation().getDirection().multiply(2);
Fireball fireball = entity.getWorld().spawn(((LivingEntity) entity).getEyeLocation().add(direction.getX(), direction.getY() - 5, direction.getZ()), Fireball.class);
fireball.setShooter((LivingEntity) entity);
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Throw Boulder Attack").equalsIgnoreCase("true")) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Throw Boulder Attack").equalsIgnoreCase("true")) {
player.getLocation().getWorld().playSound(player.getLocation(), Sound.GHAST_FIREBALL, 1, 0);
}
}
Expand All @@ -208,8 +212,8 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) {
@EventHandler
public void KickAttack(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Enabled").equalsIgnoreCase("true")) {
String config = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Kick Height");
if (v.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Enabled").equalsIgnoreCase("true")) {
String config = _giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Kick Height");
int height;

try {
Expand All @@ -225,7 +229,7 @@ public void KickAttack(PlayerMoveEvent event) {
}
if (chance == 50) {
for (Entity entity : player.getNearbyEntities(5, 5, 5)) {
if (API.isGiant(entity)) {
if (_giants.getAPI().isGiant(entity)) {
if (entity.getNearbyEntities(5, 5, 5).contains(player)) {
player.setVelocity(new Vector(0, height, 0));
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Kick Attack").equalsIgnoreCase("true")) {
Expand All @@ -241,15 +245,15 @@ public void KickAttack(PlayerMoveEvent event) {
@EventHandler
public void StompAttack(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Stomp Attack").equalsIgnoreCase("true")) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Stomp Attack").equalsIgnoreCase("true")) {
Random pick = new Random();
int chance = 0;
for (int counter = 1; counter <= 1; counter++) {
chance = 1 + pick.nextInt(100);
}
if (chance == 50) {
for (Entity entity : player.getNearbyEntities(3, 2, 3)) {
if (API.isGiant(entity)) {
if (_giants.getAPI().isGiant(entity)) {
if (entity.getNearbyEntities(3, 2, 3).contains(player)) {
player.getLocation().getWorld().createExplosion(player.getLocation(), 1.0F);
}
Expand All @@ -262,7 +266,7 @@ public void StompAttack(PlayerMoveEvent event) {
@EventHandler
public void GiantDrops(EntityDeathEvent event) {
Entity entity = event.getEntity();
String string = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Giant Stats.Experience");
String string = _giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Giant Stats.Experience");
int exp;

try {
Expand All @@ -271,12 +275,12 @@ public void GiantDrops(EntityDeathEvent event) {
exp = 5;
}

if (API.isGiant(entity)) {
if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Death").equalsIgnoreCase("true")) {
if (_giants.getAPI().isGiant(entity)) {
if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Death").equalsIgnoreCase("true")) {
entity.getLocation().getWorld().playSound(entity.getLocation(), Sound.ENDERDRAGON_GROWL, 1, 0);
}
event.setDroppedExp(exp);
List<String> newDrop = API.getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Giant Stats.Drops");
List<String> newDrop = _giants.getAPI().getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Giant Stats.Drops");
if (newDrop == null || newDrop.contains("") || newDrop.toString().equalsIgnoreCase("[]")) {
return;
}
Expand Down Expand Up @@ -342,4 +346,4 @@ public void GiantDrops(EntityDeathEvent event) {
event.getDrops().addAll(drops);
}
}
}
}
8 changes: 4 additions & 4 deletions src/me/pkt77/giants/spout/SpoutListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.getspout.spoutapi.material.CustomItem;

public class SpoutListener implements Listener {
private Giants _giants;
private Giants giants;

public SpoutListener(Giants giants) {
_giants = giants;
_giants.getServer().getPluginManager().registerEvents(this, giants);
this.giants = giants;
this.giants.getServer().getPluginManager().registerEvents(this, giants);
}

@EventHandler
Expand All @@ -38,4 +38,4 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}
}
}
}
20 changes: 12 additions & 8 deletions src/me/pkt77/giants/utils/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@
import org.bukkit.entity.LivingEntity;

public class API {
private static Giants _giants;
private static Giants giants;
private Commands commands;
private static FileHandler fileHandler;

@Deprecated
public API(Giants giants) {
_giants = giants;
}

public void setup(Giants giants){
this.giants = giants;
new Listeners(_giants);
commands = new Commands(_giants);
_giants.getCommand("giants").setExecutor(commands);
this.giants.getCommand("giants").setExecutor(commands);
fileHandler = new FileHandler(_giants);
}

public static boolean isGiant(Entity entity) {
public boolean isGiant(Entity entity) {
return entity instanceof Giant;
}

public static boolean isGiant(LivingEntity livingEntity) {
public boolean isGiant(LivingEntity livingEntity) {
return livingEntity instanceof Giant;
}

public static List<String> getGiantSpawnWorlds() {
public List<String> getGiantSpawnWorlds() {
return getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Spawn Settings.Worlds");
}

public static FileHandler getFileHandler() {
public FileHandler getFileHandler() {
return fileHandler;
}
}
}