Permalink
Browse files

Add Boss Bar functions (MC 1.9+)

  • Loading branch information...
PseudoKnight committed Jan 3, 2018
1 parent 7033636 commit 0c51befee2bc03fc8dbba892e0db756b57dbcb3f
@@ -0,0 +1,25 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.enums.MCBarColor;
import com.laytonsmith.abstraction.enums.MCBarStyle;
import java.util.List;
public interface MCBossBar extends AbstractionObject {
String getTitle();
void setTitle(String title);
MCBarColor getColor();
void setColor(MCBarColor color);
MCBarStyle getStyle();
void setStyle(MCBarStyle style);
double getProgress();
void setProgress(double progress);
void addPlayer(MCPlayer player);
void removePlayer(MCPlayer player);
void removeAllPlayers();
List<MCPlayer> getPlayers();
boolean isVisible();
void setVisible(boolean visible);
}
@@ -1,5 +1,7 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.enums.MCBarColor;
import com.laytonsmith.abstraction.enums.MCBarStyle;
import com.laytonsmith.abstraction.enums.MCInventoryType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.pluginmessages.MCMessenger;
@@ -116,4 +118,6 @@
* @return The command's captured output, if possible, otherwise an empty string, never null.
*/
public String dispatchAndCaptureCommand(MCCommandSender commandSender, String cmd);
MCBossBar createBossBar(String title, MCBarColor color, MCBarStyle style);
}
@@ -0,0 +1,116 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.abstraction.MCBossBar;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import com.laytonsmith.abstraction.enums.MCBarColor;
import com.laytonsmith.abstraction.enums.MCBarStyle;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class BukkitMCBossBar implements MCBossBar {
private BossBar bb;
public BukkitMCBossBar(BossBar bb) {
this.bb = bb;
}
@Override
public Object getHandle() {
return bb;
}
@Override
public String getTitle() {
return bb.getTitle();
}
@Override
public void setTitle(String title) {
bb.setTitle(title);
}
@Override
public MCBarColor getColor() {
return MCBarColor.valueOf(bb.getColor().name());
}
@Override
public void setColor(MCBarColor color) {
bb.setColor(BarColor.valueOf(color.name()));
}
@Override
public MCBarStyle getStyle() {
return MCBarStyle.valueOf(bb.getStyle().name());
}
@Override
public void setStyle(MCBarStyle style) {
bb.setStyle(BarStyle.valueOf(style.name()));
}
@Override
public double getProgress() {
return bb.getProgress();
}
@Override
public void setProgress(double progress) {
bb.setProgress(progress);
}
@Override
public void addPlayer(MCPlayer player) {
bb.addPlayer((Player) player.getHandle());
}
@Override
public void removePlayer(MCPlayer player) {
bb.removePlayer((Player) player.getHandle());
}
@Override
public void removeAllPlayers() {
bb.removeAll();
}
@Override
public List<MCPlayer> getPlayers() {
List<MCPlayer> players = new ArrayList<>();
for(Player player : bb.getPlayers()) {
players.add(new BukkitMCPlayer(player));
}
return players;
}
@Override
public boolean isVisible() {
return bb.isVisible();
}
@Override
public void setVisible(boolean visible) {
bb.setVisible(visible);
}
@Override
public String toString() {
return bb.toString();
}
@Override
public boolean equals(Object obj) {
return obj instanceof BukkitMCBossBar && bb.equals(((BukkitMCBossBar) obj).bb);
}
@Override
public int hashCode() {
return bb.hashCode();
}
}
@@ -1,6 +1,7 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.PureUtilities.Common.ReflectionUtils;
import com.laytonsmith.abstraction.MCBossBar;
import com.laytonsmith.abstraction.MCCommandMap;
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCConsoleCommandSender;
@@ -19,6 +20,8 @@
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import com.laytonsmith.abstraction.bukkit.pluginmessages.BukkitMCMessenger;
import com.laytonsmith.abstraction.enums.MCBarColor;
import com.laytonsmith.abstraction.enums.MCBarStyle;
import com.laytonsmith.abstraction.enums.MCInventoryType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.pluginmessages.MCMessenger;
@@ -29,6 +32,8 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
@@ -500,4 +505,14 @@ public void clearRecipes() {
public void resetRecipes() {
s.resetRecipes();
}
@Override
public MCBossBar createBossBar(String title, MCBarColor color, MCBarStyle style) {
try {
return new BukkitMCBossBar(s.createBossBar(title, BarColor.valueOf(color.name()), BarStyle.valueOf(style.name())));
} catch(NoSuchMethodError ex) {
// Probably prior to 1.9
return null;
}
}
}
@@ -0,0 +1,14 @@
package com.laytonsmith.abstraction.enums;
import com.laytonsmith.annotations.MEnum;
@MEnum("BarColor")
public enum MCBarColor {
PINK,
BLUE,
RED,
GREEN,
YELLOW,
PURPLE,
WHITE
}
@@ -0,0 +1,12 @@
package com.laytonsmith.abstraction.enums;
import com.laytonsmith.annotations.MEnum;
@MEnum("BarStyle")
public enum MCBarStyle {
SOLID,
SEGMENTED_6,
SEGMENTED_10,
SEGMENTED_12,
SEGMENTED_20
}
Oops, something went wrong.

0 comments on commit 0c51bef

Please sign in to comment.