use of org.bukkit.potion.PotionEffect in project Bukkit by Bukkit.
the class EffectCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(getUsage());
return true;
}
final Player player = sender.getServer().getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + String.format("Player, %s, not found", args[0]));
return true;
}
if ("clear".equalsIgnoreCase(args[1])) {
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
sender.sendMessage(String.format("Took all effects from %s", args[0]));
return true;
}
PotionEffectType effect = PotionEffectType.getByName(args[1]);
if (effect == null) {
effect = PotionEffectType.getById(getInteger(sender, args[1], 0));
}
if (effect == null) {
sender.sendMessage(ChatColor.RED + String.format("Effect, %s, not found", args[1]));
return true;
}
int duration = 600;
int duration_temp = 30;
int amplification = 0;
if (args.length >= 3) {
duration_temp = getInteger(sender, args[2], 0, 1000000);
if (effect.isInstant()) {
duration = duration_temp;
} else {
duration = duration_temp * 20;
}
} else if (effect.isInstant()) {
duration = 1;
}
if (args.length >= 4) {
amplification = getInteger(sender, args[3], 0, 255);
}
if (duration_temp == 0) {
if (!player.hasPotionEffect(effect)) {
sender.sendMessage(String.format("Couldn't take %s from %s as they do not have the effect", effect.getName(), args[0]));
return true;
}
player.removePotionEffect(effect);
broadcastCommandMessage(sender, String.format("Took %s from %s", effect.getName(), args[0]));
} else {
final PotionEffect applyEffect = new PotionEffect(effect, duration, amplification);
player.addPotionEffect(applyEffect, true);
broadcastCommandMessage(sender, String.format("Given %s (ID %d) * %d to %s for %d seconds", effect.getName(), effect.getId(), amplification, args[0], duration_temp));
}
return true;
}
use of org.bukkit.potion.PotionEffect in project xAuth by CypherX.
the class PlayerDataHandler method restoreData.
public void restoreData(xAuthPlayer xp, Player p) {
ItemStack[] items = null;
ItemStack[] armor = null;
Location loc = null;
Collection<PotionEffect> potFx = null;
int fireTicks = 0;
int remainingAir = 300;
// Use cached copy of player data, if it exists
PlayerData playerData = xp.getPlayerData();
if (playerData != null) {
items = playerData.getItems();
armor = playerData.getArmor();
loc = playerData.getLocation();
potFx = playerData.getPotionEffects();
fireTicks = playerData.getFireTicks();
remainingAir = playerData.getRemainingAir();
} else {
Connection conn = plugin.getDbCtrl().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format("SELECT `items`, `armor`, `location`, `potioneffects`, `fireticks`, `remainingair` FROM `%s` WHERE `playername` = ?", plugin.getDbCtrl().getTable(Table.PLAYERDATA));
ps = conn.prepareStatement(sql);
ps.setString(1, p.getName());
rs = ps.executeQuery();
if (rs.next()) {
items = buildItemStack(rs.getString("items"));
armor = buildItemStack(rs.getString("armor"));
String rsLoc = rs.getString("location");
if (rsLoc != null) {
String[] locSplit = rsLoc.split(":");
loc = new Location(Bukkit.getWorld(locSplit[0]), Double.parseDouble(locSplit[1]), Double.parseDouble(locSplit[2]), Double.parseDouble(locSplit[3]), Float.parseFloat(locSplit[4]), Float.parseFloat(locSplit[5]));
}
String rsPotFx = rs.getString("potioneffects");
if (rsPotFx != null)
potFx = buildPotFx(rsPotFx);
fireTicks = rs.getInt("fireticks");
remainingAir = rs.getInt("remainingair");
}
} catch (SQLException e) {
xAuthLog.severe("Failed to load playerdata from database for player: " + p.getName(), e);
} finally {
plugin.getDbCtrl().close(conn, ps, rs);
}
}
PlayerInventory pInv = p.getInventory();
boolean hideInv = plugin.getConfig().getBoolean("guest.hide-inventory");
boolean hideLoc = plugin.getConfig().getBoolean("guest.protect-location");
if (hideInv && items != null) {
// Fix for inventory extension plugins
if (pInv.getSize() > items.length) {
ItemStack[] newItems = new ItemStack[pInv.getSize()];
for (int i = 0; i < items.length; i++) newItems[i] = items[i];
items = newItems;
}
//End Fix for inventory extension plugins
pInv.setContents(items);
}
if (hideInv && armor != null)
pInv.setArmorContents(armor);
if (hideLoc && loc != null && p.getHealth() > 0)
p.teleport(loc);
if (potFx != null)
p.addPotionEffects(potFx);
p.setFireTicks(fireTicks);
p.setRemainingAir(remainingAir);
xp.setPlayerData(null);
Connection conn = plugin.getDbCtrl().getConnection();
PreparedStatement ps = null;
try {
String sql = String.format("DELETE FROM `%s` WHERE `playername` = ?", plugin.getDbCtrl().getTable(Table.PLAYERDATA));
ps = conn.prepareStatement(sql);
ps.setString(1, p.getName());
ps.executeUpdate();
} catch (SQLException e) {
xAuthLog.severe("Could not delete playerdata record from database for player: " + p.getName(), e);
} finally {
plugin.getDbCtrl().close(conn, ps);
}
}
use of org.bukkit.potion.PotionEffect in project xAuth by CypherX.
the class PlayerDataHandler method storeData.
public void storeData(xAuthPlayer xp, Player p) {
PlayerInventory pInv = p.getInventory();
ItemStack[] items = pInv.getContents();
ItemStack[] armor = pInv.getArmorContents();
Location loc = p.isDead() ? null : p.getLocation();
Collection<PotionEffect> potEffects = p.getActivePotionEffects();
int fireTicks = p.isDead() ? 0 : p.getFireTicks();
int remainingAir = p.getRemainingAir();
String strItems = null;
String strArmor = null;
String strLoc = null;
String strPotFx = buildPotFxString(potEffects);
xp.setPlayerData(new PlayerData(items, armor, loc, potEffects, fireTicks, remainingAir));
boolean hideInv = plugin.getConfig().getBoolean("guest.hide-inventory");
boolean hideLoc = plugin.getConfig().getBoolean("guest.protect-location");
if (hideInv) {
strItems = buildItemString(items);
strArmor = buildItemString(armor);
pInv.clear();
pInv.setHelmet(null);
pInv.setChestplate(null);
pInv.setLeggings(null);
pInv.setBoots(null);
}
if (hideLoc && !p.isDead()) {
strLoc = loc.getWorld().getName() + ":" + loc.getX() + ":" + loc.getY() + ":" + loc.getZ() + ":" + loc.getYaw() + ":" + loc.getPitch();
p.teleport(plugin.getLocMngr().getLocation(p.getWorld()));
}
for (PotionEffect effect : p.getActivePotionEffects()) p.addPotionEffect(new PotionEffect(effect.getType(), 0, 0), true);
p.setFireTicks(0);
p.setRemainingAir(300);
// only store player data if there's something to insert
if (strItems != null || strArmor != null || strLoc != null || strPotFx != null) {
Connection conn = plugin.getDbCtrl().getConnection();
PreparedStatement ps = null;
try {
String sql;
if (plugin.getDbCtrl().isMySQL())
sql = String.format("INSERT IGNORE INTO `%s` VALUES (?, ?, ?, ?, ?, ?, ?)", plugin.getDbCtrl().getTable(Table.PLAYERDATA));
else
sql = String.format("INSERT INTO `%s` SELECT ?, ?, ?, ?, ?, ?, ? FROM DUAL WHERE NOT EXISTS (SELECT * FROM `%s` WHERE `playername` = ?)", plugin.getDbCtrl().getTable(Table.PLAYERDATA), plugin.getDbCtrl().getTable(Table.PLAYERDATA));
ps = conn.prepareStatement(sql);
ps.setString(1, p.getName());
ps.setString(2, strItems);
ps.setString(3, strArmor);
ps.setString(4, strLoc);
ps.setString(5, strPotFx);
ps.setInt(6, fireTicks);
ps.setInt(7, remainingAir);
if (!plugin.getDbCtrl().isMySQL())
ps.setString(8, p.getName());
ps.executeUpdate();
} catch (SQLException e) {
xAuthLog.severe("Failed to insert player data into database!", e);
} finally {
plugin.getDbCtrl().close(conn, ps);
}
}
}
use of org.bukkit.potion.PotionEffect in project xAuth by CypherX.
the class PlayerDataHandler method buildPotFx.
private Collection<PotionEffect> buildPotFx(String str) {
String[] effectSplit = str.split(";");
String[] type = effectSplit[0].split(",");
String[] duration = effectSplit[1].split(",");
String[] amplifier = effectSplit[2].split(",");
Collection<PotionEffect> effects = new ArrayList<PotionEffect>();
for (int i = 0; i < type.length; i++) {
PotionEffectType potFxType = PotionEffectType.getById(Integer.parseInt(type[i]));
int potFxDur = Integer.parseInt(duration[i]);
int potFxAmp = Integer.parseInt(amplifier[i]);
effects.add(new PotionEffect(potFxType, potFxDur, potFxAmp));
}
return effects;
}
use of org.bukkit.potion.PotionEffect in project Minigames by AddstarMC.
the class PlayerData method spectateMinigame.
public void spectateMinigame(MinigamePlayer player, Minigame minigame) {
SpectateMinigameEvent event = new SpectateMinigameEvent(player, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
boolean tpd = false;
if (minigame.getSpectatorLocation() != null)
tpd = player.teleport(minigame.getSpectatorLocation());
else {
player.sendMessage(MinigameUtils.getLang("minigame.error.noSpectatePos"), "error");
return;
}
if (!tpd) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
return;
}
player.storePlayerData();
player.setMinigame(minigame);
player.setGamemode(GameMode.ADVENTURE);
minigame.addSpectator(player);
if (minigame.canSpectateFly()) {
player.getPlayer().setAllowFlight(true);
}
for (MinigamePlayer pl : minigame.getPlayers()) {
pl.getPlayer().hidePlayer(player.getPlayer());
}
player.getPlayer().setScoreboard(minigame.getScoreboardManager());
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
player.sendMessage(MinigameUtils.formStr("player.spectate.join.plyMsg", minigame.getName(true)) + "\n" + MinigameUtils.formStr("player.spectate.join.plyHelp", "\"/minigame quit\""), null);
mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.join.minigameMsg", player.getName(), minigame.getName(true)), null, player);
}
}
Aggregations