-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
184 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.spleefleague.core.halloween; | ||
|
||
import com.mongodb.client.MongoCursor; | ||
import com.spleefleague.core.SpleefLeague; | ||
import com.spleefleague.core.io.DBEntity; | ||
import com.spleefleague.core.io.DBLoad; | ||
import com.spleefleague.core.io.DBLoadable; | ||
import com.spleefleague.core.io.EntityBuilder; | ||
import com.spleefleague.core.io.TypeConverter; | ||
import java.util.ArrayList; | ||
import org.bson.Document; | ||
import org.bson.types.ObjectId; | ||
import org.bukkit.Location; | ||
|
||
/** | ||
* | ||
* @author Jonas | ||
*/ | ||
public class Candy extends DBEntity implements DBLoadable{ | ||
|
||
@DBLoad(fieldName = "location", typeConverter = TypeConverter.LocationConverter.class) | ||
private Location location; | ||
|
||
public Location getLocation() { | ||
return location; | ||
} | ||
|
||
private static Candy[] candies; | ||
|
||
public static void init() { | ||
ArrayList<Candy> candies = new ArrayList<>(); | ||
MongoCursor<Document> dbc = SpleefLeague.getInstance().getMongo().getDatabase("Halloween").getCollection("Candy").find().iterator(); | ||
while(dbc.hasNext()) { | ||
candies.add(EntityBuilder.load(dbc.next(), Candy.class)); | ||
} | ||
Candy.candies = candies.toArray(new Candy[0]); | ||
} | ||
|
||
public static Candy getCandy(ObjectId _id) { | ||
for(Candy candy : getCandies()) { | ||
if(candy.getObjectId().equals(_id)) { | ||
return candy; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static Candy[] getCandies() { | ||
return candies; | ||
} | ||
|
||
public static class CandyObjectIdConverter extends TypeConverter<ObjectId, Candy> { | ||
|
||
@Override | ||
public Candy convertLoad(ObjectId t) { | ||
return Candy.getCandy(t); | ||
} | ||
|
||
@Override | ||
public ObjectId convertSave(Candy v) { | ||
return v.getObjectId(); | ||
} | ||
|
||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/spleefleague/core/halloween/HalloweenListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.spleefleague.core.halloween; | ||
|
||
import com.spleefleague.core.SpleefLeague; | ||
import com.spleefleague.core.chat.Theme; | ||
import com.spleefleague.core.io.Settings; | ||
import com.spleefleague.core.player.SLPlayer; | ||
import com.spleefleague.core.utils.Area; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.Action; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.event.player.PlayerMoveEvent; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
/** | ||
* | ||
* @author Jonas | ||
*/ | ||
public class HalloweenListener implements Listener{ | ||
|
||
private static Listener instance; | ||
private final Area portalArea; | ||
private final Location portalTarget; | ||
private final PotionEffect positive, negative; | ||
|
||
public static void init() { | ||
if(instance == null) { | ||
instance = new HalloweenListener(); | ||
Bukkit.getPluginManager().registerEvents(instance, SpleefLeague.getInstance()); | ||
} | ||
} | ||
|
||
private HalloweenListener() { | ||
portalArea = Settings.get("halloween_portal_area", Area.class); | ||
portalTarget = Settings.getLocation("halloween_portal_target"); | ||
positive = new PotionEffect(PotionEffectType.SPEED, 20 * 15, 1); | ||
negative = new PotionEffect(PotionEffectType.SLOW, 20 * 15, 1); | ||
} | ||
|
||
@EventHandler | ||
public void onInteract(PlayerInteractEvent event) { | ||
if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.SKULL) { | ||
for(Candy candy : Candy.getCandies()) { | ||
if(candy.getLocation().equals(event.getClickedBlock().getLocation())) { | ||
SLPlayer slp = SpleefLeague.getInstance().getPlayerManager().get(event.getPlayer()); | ||
if(!slp.getCandy().contains(candy)) { | ||
slp.getCandy().add(candy); | ||
slp.sendMessage(Theme.SUCCESS + "" + slp.getCandy().size() + "/" + Candy.getCandies().length); | ||
if(Math.random() < 0.5) { | ||
event.getPlayer().addPotionEffect(positive); | ||
} | ||
else { | ||
event.getPlayer().addPotionEffect(negative); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onMove(PlayerMoveEvent event) { | ||
SLPlayer slp = SpleefLeague.getInstance().getPlayerManager().get(event.getPlayer()); | ||
if(slp != null) { | ||
if(slp.getCandy().size() >= Candy.getCandies().length) { | ||
event.getPlayer().teleport(portalTarget); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters