Added sign to modify lives

This commit is contained in:
Daniel Saukel 2016-06-19 14:15:27 +02:00
parent 45dc39b6e1
commit 5ff968d394
4 changed files with 127 additions and 1 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.12.1-SNAPSHOT${buildNo}</version>
<version>0.13-SNAPSHOT${buildNo}</version>
<packaging>jar</packaging>
<name>DungeonsXL</name>
<url>https://dre2n.github.io</url>

View File

@ -146,6 +146,8 @@ public enum DMessages implements Messages {
PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."),
PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"),
PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"),
PLAYER_LIVES_ADDED("Player_LivesAdded", "&6Received a bonus of &4&v1&6 lives."),
PLAYER_LIVES_REMOVED("Player_LivesRemoved", "&6You lost &4&v1&6 lives!"),
PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"),
PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."),
PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"),

View File

@ -34,6 +34,7 @@ public enum DSignTypeDefault implements DSignType {
FLOOR("Floor", "floor", false, FloorSign.class),
INTERACT("Interact", "interact", true, InteractSign.class),
LEAVE("Leave", "leave", true, LeaveSign.class),
LIVES_MODIFIER("Lives", "lives", false, LivesModifierSign.class),
LOBBY("Lobby", "lobby", true, LobbySign.class),
MOB("Mob", "mob", false, DMobSign.class),
MESSAGE("MSG", "msg", false, MessageSign.class),

View File

@ -0,0 +1,123 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.itemsxl.util.commons.util.EnumUtil;
import io.github.dre2n.itemsxl.util.commons.util.NumberUtil;
import io.github.dre2n.itemsxl.util.commons.util.messageutil.MessageUtil;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
public class LivesModifierSign extends DSign {
public enum Target {
GAME,
GROUP,
PLAYER,
}
private DSignType type = DSignTypeDefault.LIVES_MODIFIER;
private int lives;
private Target target;
public LivesModifierSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
/* Getters and setters */
/**
* @return the lives to add / remove
*/
public int getLives() {
return lives;
}
/**
* @param lives
* the lives to add / remove
*/
public void setLives(int lives) {
this.lives = lives;
}
/* Actions */
@Override
public boolean check() {
return NumberUtil.parseInt(lines[1]) != 0;
}
@Override
public void onInit() {
lives = NumberUtil.parseInt(lines[1]);
if (EnumUtil.isValidEnum(Target.class, lines[2].toUpperCase())) {
target = Target.valueOf(lines[2].toUpperCase());
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public boolean onPlayerTrigger(Player player) {
switch (target) {
case GAME:
for (Player gamePlayer : Game.getByPlayer(player).getPlayers()) {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (gamePlayer != null) {
modifyLives(dPlayer);
}
}
break;
case GROUP:
for (DGamePlayer dPlayer : DGroup.getByPlayer(player).getDGamePlayers()) {
modifyLives(dPlayer);
}
break;
case PLAYER:
modifyLives(DGamePlayer.getByPlayer(player));
}
return true;
}
public void modifyLives(DGamePlayer dPlayer) {
dPlayer.setLives(dPlayer.getLives() + lives);
if (lives > 0) {
MessageUtil.sendMessage(dPlayer.getPlayer(), DMessages.PLAYER_LIVES_ADDED.getMessage(String.valueOf(lives)));
} else {
MessageUtil.sendMessage(dPlayer.getPlayer(), DMessages.PLAYER_LIVES_REMOVED.getMessage(String.valueOf(-1 * lives)));
}
}
@Override
public DSignType getType() {
return type;
}
}