From a573e57255a4d9bfa89c62b4348610c61ceea830 Mon Sep 17 00:00:00 2001 From: Zolli Date: Sun, 24 Feb 2013 19:52:39 +0100 Subject: [PATCH] *Some work on end visiting logic. EnderDragon counts now stored in file --- resources/config.yml | 5 +++- resources/en.yml | 3 +++ resources/storage.yml | 3 ++- .../EnderCore/Listeners/playerListener.java | 27 ++++++++++++++++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/resources/config.yml b/resources/config.yml index fbe40e6..0af5203 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -21,9 +21,12 @@ database: username: 'root' password: '' +dragons: + desiredDragonCount: '1' + debug: debugStatus: 'false' worlds: mainWorld: 'defaultWorld' - netherWorld: 'defaultNether' + endWorld: 'defaultNether' diff --git a/resources/en.yml b/resources/en.yml index 21afb3f..633e0b4 100644 --- a/resources/en.yml +++ b/resources/en.yml @@ -6,3 +6,6 @@ commands: noPermission: 'You dont have permission to access this command! You need one of the following permission:' noConsole: 'This command must be running as player!' badUsage: 'Bad syntax! Try this:' + +defeat: + successSingle: 'Siker. :)' diff --git a/resources/storage.yml b/resources/storage.yml index 40b0454..a1fd2e5 100644 --- a/resources/storage.yml +++ b/resources/storage.yml @@ -1 +1,2 @@ -test: 'test' \ No newline at end of file +localSettings: + dragonCount: '1' diff --git a/src/com/Zolli/EnderCore/Listeners/playerListener.java b/src/com/Zolli/EnderCore/Listeners/playerListener.java index 39bc2d3..0d290c9 100644 --- a/src/com/Zolli/EnderCore/Listeners/playerListener.java +++ b/src/com/Zolli/EnderCore/Listeners/playerListener.java @@ -1,5 +1,8 @@ package com.Zolli.EnderCore.Listeners; +import org.bukkit.World; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -46,10 +49,23 @@ public playerListener(EnderCore instance) { public void playerJoin(PlayerJoinEvent e) { Player pl = e.getPlayer(); boolean played = pl.hasPlayedBefore(); + int dragonCount = 0; + /* Write player to database if is joined the server first time */ if(!played) { plugin.dbAction.addPlayer(pl); } + /* END */ + + /* Detecting ender dragons count on ender, and write it to settings */ + World ender = plugin.getServer().getWorld(this.endWorld); + for(Entity ent : ender.getEntities()) { + if(ent instanceof EnderDragon) { + dragonCount++; + } + } + plugin.ffStorage.set("localSettings.dragonCount", dragonCount); + /* END */ } /** @@ -62,17 +78,20 @@ public void goNether(PlayerChangedWorldEvent e) { ECPlayer epl = new ECPlayer(pl, plugin); String toWorld = pl.getWorld().getName(); - /* If player traveling to the nether world */ + /* If player traveling to the ender world */ if(toWorld.equalsIgnoreCase(this.endWorld)) { playerTravelEnderEvent travelEvent = new playerTravelEnderEvent(pl, pl.getWorld(), e.getFrom(), epl.isDragonDefeted()); plugin.pluginManager.callEvent(travelEvent); - if(epl.isDragonDefeted()) { - System.out.println("Igen"); + /* If enough number of dragon in the ender */ + if(plugin.config.getInt("dragons.desiredDragonCount") >= plugin.config.getInt("dragons.desiredDragonCount")) { + pl.sendMessage("Hajrá :)"); } else { - System.out.println("Nem"); + pl.teleport(plugin.getServer().getWorld(plugin.config.getString("worlds.endWorld")).getSpawnLocation()); } + /* END */ } + /* END */ } } \ No newline at end of file