use of net.md_5.bungee.api.plugin.Plugin in project CloudNet by Dytanic.
the class GameServer method bootstrap.
@Override
public boolean bootstrap() throws Exception {
serverProcess.setServerStage(ServerStage.DOWNLOAD);
long startupTime = System.currentTimeMillis();
for (ServerInstallablePlugin url : serverProcess.getMeta().getDownloadablePlugins()) {
switch(url.getPluginResourceType()) {
case URL:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
try {
URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
case MASTER:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
try {
URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
urlConnection.setRequestProperty("-Xmessage", "plugin");
urlConnection.setRequestProperty("-Xvalue", url.getName());
urlConnection.connect();
System.out.println("Downloading " + url.getName() + ".jar");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
System.out.println("Download was completed successfully!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
default:
break;
}
}
for (ServerInstallablePlugin url : serverProcess.getMeta().getTemplate().getInstallablePlugins()) {
switch(url.getPluginResourceType()) {
case URL:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
try {
URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
case MASTER:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
try {
URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
urlConnection.setRequestProperty("-Xmessage", "plugin");
urlConnection.setRequestProperty("-Xvalue", url.getName());
urlConnection.connect();
System.out.println("Downloading " + url.getName() + ".jar");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
System.out.println("Download was completed successfully!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
default:
break;
}
}
if (serverGroup.getTemplates().size() == 0 && serverProcess.getMeta().getUrl() == null)
return false;
if (serverGroup.getGroupMode().equals(ServerGroupMode.STATIC)) {
if (!Files.exists(dir))
if (!a())
return false;
} else if (!a())
return false;
for (ServerInstallablePlugin plugin : serverProcess.getMeta().getDownloadablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
for (ServerInstallablePlugin plugin : serverProcess.getMeta().getTemplate().getInstallablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
serverProcess.setServerStage(ServerStage.COPY);
if (serverGroup.getServerType().equals(ServerGroupType.BUKKIT))
if (!Files.exists(Paths.get(path + "/spigot.jar")))
FileCopy.copyFileToDirectory(new File("local/spigot.jar"), new File(path));
if (serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
if (!Files.exists(Paths.get(path + "/config")))
Files.createDirectories(Paths.get(path + "/config"));
if (!Files.exists(Paths.get(path + "/config/glowstone.yml")))
FileCopy.insertData("files/glowstone.yml", path + "/config/glowstone.yml");
}
if (!Files.exists(Paths.get(path + "/server.properties")))
FileCopy.insertData("files/server.properties", path + "/server.properties");
if (!Files.exists(Paths.get(path + "/bukkit.yml")))
FileCopy.insertData("files/bukkit.yml", path + "/bukkit.yml");
if (!serverProcess.getMeta().isOnlineMode())
if (!Files.exists(Paths.get(path + "/spigot.yml")))
FileCopy.insertData("files/spigot.yml", path + "/spigot.yml");
Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
FileCopy.copyFilesInDirectory(new File("local/global"), new File(path));
String motd = "Default Motd";
int maxPlayers = 0;
if (!serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
Properties properties = new Properties();
try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/server.properties")))) {
properties.load(inputStreamReader);
}
Enumeration enumeration = this.serverProcess.getMeta().getServerProperties().keys();
while (enumeration.hasMoreElements()) {
String x = enumeration.nextElement().toString();
properties.setProperty(x, this.serverProcess.getMeta().getServerProperties().getProperty(x));
}
properties.setProperty("server-ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
properties.setProperty("server-port", serverProcess.getMeta().getPort() + NetworkUtils.EMPTY_STRING);
properties.setProperty("online-mode", serverProcess.getMeta().isOnlineMode() + NetworkUtils.EMPTY_STRING);
// properties.setProperty("server-name", serverProcess.getMeta().getServiceId().getServerId());
motd = properties.getProperty("motd");
maxPlayers = Integer.parseInt(properties.getProperty("max-players"));
try (OutputStream outputStream = Files.newOutputStream(Paths.get(path + "/server.properties"))) {
properties.store(outputStream, "CloudNet-Wrapper EDIT");
}
} else {
try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(inputStreamReader);
Configuration section = configuration.getSection("server");
section.set("ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
section.set("port", serverProcess.getMeta().getPort());
maxPlayers = section.getInt("max-players");
motd = section.getString("motd");
configuration.set("server", section);
configuration.set("console.use-jline", false);
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, outputStreamWriter);
}
}
}
this.serverInfo = new ServerInfo(serverProcess.getMeta().getServiceId(), CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP(), this.getServerProcess().getMeta().getPort(), false, new ArrayList<>(), serverProcess.getMeta().getMemory(), motd, 0, maxPlayers, ServerState.OFFLINE, this.serverProcess.getMeta().getServerConfig(), serverProcess.getMeta().getTemplate());
if (!Files.exists(Paths.get(path + "/CLOUD"))) {
Files.createDirectory(Paths.get(path + "/CLOUD"));
}
new Document().append("serviceId", serverProcess.getMeta().getServiceId()).append("serverProcess", serverProcess.getMeta()).append("serverInfo", serverInfo).append("ssl", CloudNetWrapper.getInstance().getOptionSet().has("ssl")).append("memory", serverProcess.getMeta().getMemory()).saveAsConfig(Paths.get(path + "/CLOUD/config.json"));
new Document().append("connection", new ConnectableAddress(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost(), CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetPort())).saveAsConfig(Paths.get(path + "/CLOUD/connection.json"));
CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutAddServer(this.serverInfo, this.serverProcess.getMeta()));
System.out.println("Server " + toString() + " started in [" + (System.currentTimeMillis() - startupTime) + " milliseconds]");
this.startupTimeStamp = System.currentTimeMillis();
startProcess();
serverProcess.setServerStage(ServerStage.PROCESS);
CloudNetWrapper.getInstance().getServers().put(this.serverProcess.getMeta().getServiceId().getServerId(), this);
serverProcess.setServerStage(ServerStage.NET_INIT);
return true;
}
use of net.md_5.bungee.api.plugin.Plugin in project solinia3-core by mixxit.
the class Solinia3CoreEntityListener method onEntityDamage.
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled())
return;
if (!(event instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
// If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
if (event.getCause().equals(DamageCause.THORNS)) {
damagecause.setDamage(DamageModifier.BLOCKING, 0);
} else {
// Only give them 15% blocking
double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
}
}
// and check they are not mezzed
try {
if (damagecause.getDamager() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) attacker;
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
// cancel attacks on mobs mezzed
if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
if (mezExpiry != null) {
((Creature) attacker).setTarget(null);
if (solCreatureEntity.isPet()) {
Wolf wolf = (Wolf) attacker;
wolf.setTarget(null);
solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
}
event.setCancelled(true);
return;
}
}
}
try {
Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
if (mzExpiry != null) {
if (attacker instanceof Player) {
attacker.sendMessage("* You are mezzed!");
}
Utils.CancelEvent(event);
;
return;
}
} catch (CoreStateInitException e) {
}
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
}
}
} catch (CoreStateInitException e) {
// skip
}
// Remove buffs on recipient (invis should drop)
try {
if (event.getEntity() instanceof LivingEntity) {
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.isInvulnerable()) {
event.setDamage(0);
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
}
}
}
// see if any runes want to reduce this damage
if (event.getEntity() instanceof LivingEntity) {
if (!event.getCause().equals(DamageCause.THORNS)) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.getRune() > 0) {
event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
if (event.getDamage() <= 0) {
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
}
return;
}
}
}
} catch (CoreStateInitException e) {
// skip
}
if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
// code
if (event.getCause().equals(DamageCause.THORNS)) {
if (damagecause.getDamager() instanceof Player) {
LivingEntity recipient = (LivingEntity) event.getEntity();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
String name = recipient.getName();
if (recipient.getCustomName() != null)
name = recipient.getCustomName();
((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
}
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solentity;
try {
solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
Utils.CancelEvent(event);
solentity.removeDeathSaves(plugin);
solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
return;
}
solentity.damageHook(event.getDamage(), damagecause.getDamager());
} catch (CoreStateInitException e) {
// skip
}
}
return;
}
try {
Entity damager = damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
damager = (LivingEntity) arr.getShooter();
// Modify Player Bow Damage
if (arr.getShooter() instanceof Player) {
Player shooter = (Player) arr.getShooter();
ItemStack mainitem = shooter.getInventory().getItemInMainHand();
if (mainitem != null) {
if (mainitem.getType() == Material.BOW) {
int dmgmodifier = 0;
if (Utils.IsSoliniaItem(mainitem)) {
try {
ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
dmgmodifier = item.getDamage();
}
} catch (SoliniaItemException e) {
// sok just skip
}
}
event.setDamage(event.getDamage() + dmgmodifier);
}
}
}
} else {
}
}
if (!(damager instanceof LivingEntity))
return;
LivingEntity attacker = (LivingEntity) damager;
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
if (attacker == null)
return;
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
if (soldefender.isPet()) {
Wolf wolf = (Wolf) event.getEntity();
if (wolf != null) {
if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
Utils.CancelEvent(event);
;
return;
}
} else {
Utils.CancelEvent(event);
;
return;
}
}
}
if (!(event instanceof EntityDamageByEntityEvent)) {
soldefender.damageHook(event.getDamage(), damagecause.getDamager());
return;
}
solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
} catch (CoreStateInitException e) {
}
}
}
use of net.md_5.bungee.api.plugin.Plugin in project solinia3-core by mixxit.
the class CommandCharacter method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
if (args.length == 0) {
player.sendMessage("Your Characters: ");
String main = "ALT";
if (solplayer.isMain()) {
main = "MAIN";
}
player.sendMessage("- " + ChatColor.LIGHT_PURPLE + solplayer.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - " + ChatColor.GREEN + "ACTIVE" + ChatColor.RESET);
for (ISoliniaPlayer character : StateManager.getInstance().getPlayerManager().getCharactersByPlayerUUID(player.getUniqueId())) {
if (character.getCharacterId().equals(solplayer.getCharacterId()))
continue;
if (character.isMain()) {
main = "MAIN";
} else {
main = "ALT";
}
TextComponent tc = new TextComponent();
tc.setText("- " + ChatColor.LIGHT_PURPLE + character.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - ");
String details = ChatColor.GOLD + character.getFullNameWithTitle() + " Level: " + character.getLevel() + ChatColor.RESET;
TextComponent tc2 = new TextComponent();
String changetext = "/character load " + character.getCharacterId().toString();
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
tc2.setText(ChatColor.RED + "Already changed this session" + ChatColor.RESET);
} else {
tc2.setText(ChatColor.AQUA + "[Click to Switch]" + ChatColor.RESET);
tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, changetext));
}
tc.addExtra(tc2);
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
sender.spigot().sendMessage(tc);
}
player.sendMessage("Note, new characters may not be visible for up to 15 minutes");
player.sendMessage("Use '/character new' to create a new character");
} else {
switch(args[0].toUpperCase()) {
case "NEW":
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
return true;
}
ISoliniaPlayer newPlayer = StateManager.getInstance().getPlayerManager().createNewPlayerAlt(plugin, player);
if (newPlayer != null) {
player.sendMessage("Your character has been stored and a new character created");
player.sendMessage("Please check you have not dropped any items due to your character change");
} else {
player.sendMessage("Problem creating your new character");
}
break;
case "LOAD":
if (args.length < 2) {
player.sendMessage("You must provide the character UUID");
return true;
}
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
return true;
}
UUID characterUUID = UUID.fromString(args[1]);
ISoliniaPlayer loadedPlayer = StateManager.getInstance().getPlayerManager().loadPlayerAlt(plugin, player, characterUUID);
if (loadedPlayer != null) {
player.sendMessage("Your character has been stored and your new character loaded");
player.sendMessage("Please check you have not dropped any items due to your character change");
} else {
player.sendMessage("Problem loading requested character");
}
break;
default:
player.sendMessage("Unknown character subcommand");
break;
}
}
} catch (CoreStateInitException e) {
}
return true;
}
use of net.md_5.bungee.api.plugin.Plugin in project solinia3-core by mixxit.
the class CommandEffects method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
try {
SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(player);
if (spells == null)
return true;
if (args.length == 0) {
player.sendMessage(ChatColor.GOLD + "Active Spell Effects on you:" + ChatColor.WHITE);
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
if (solplayer.getExperienceBonusExpires() != null) {
System.out.println("Experience Bonus was not null: " + solplayer.getExperienceBonusExpires().toString());
LocalDateTime datetime = LocalDateTime.now();
Timestamp nowtimestamp = Timestamp.valueOf(datetime);
Timestamp expiretimestamp = solplayer.getExperienceBonusExpires();
if (expiretimestamp != null) {
System.out.println("Experience Bonus expire timestamp " + solplayer.getExperienceBonusExpires() + " vs Now: " + nowtimestamp.toString());
if (!nowtimestamp.after(expiretimestamp)) {
System.out.println("Experience bonus was after, displaying in effects");
int secondsleft = (int) Math.floor(Utils.compareTwoTimeStamps(expiretimestamp, nowtimestamp));
TextComponent tc = new TextComponent();
tc.setText("- " + ChatColor.GREEN + "100% Experience Potion" + ChatColor.RESET + " " + secondsleft + " seconds");
sender.spigot().sendMessage(tc);
}
}
} else {
System.out.println("Experience Bonus was null");
}
for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
String removetext = "";
ChatColor spellcolor = ChatColor.GREEN;
if (spell.isBeneficial()) {
removetext = "/effects remove " + spell.getId();
} else {
removetext = "Unremovable spell";
spellcolor = ChatColor.RED;
}
TextComponent tc = new TextComponent();
tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
TextComponent tc2 = new TextComponent();
tc2.setText(removetext);
if (spell.isBeneficial()) {
tc2.setText(ChatColor.GRAY + "Click here to remove" + ChatColor.RESET);
tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, removetext));
}
tc.addExtra(tc2);
sender.spigot().sendMessage(tc);
}
} else {
if (args.length < 2)
return true;
int spellid = Integer.parseInt(args[1]);
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
if (spell == null) {
player.sendMessage("That spell does not exist");
return true;
}
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, player.getUniqueId(), spell.getId());
if (!spell.isBeneficial()) {
player.sendMessage("Can only remove beneficial spells");
return true;
}
player.sendMessage("Spell Effect removed");
}
} catch (CoreStateInitException e) {
player.sendMessage(e.getMessage());
}
}
return true;
}
use of net.md_5.bungee.api.plugin.Plugin in project solinia3-core by mixxit.
the class SoliniaLivingEntity method doAttack.
private DamageHitInfo doAttack(Plugin plugin, ISoliniaLivingEntity defender, DamageHitInfo hit) {
if (defender == null)
return hit;
// for riposte
int originalDamage = hit.damage_done;
hit = defender.avoidDamage(this, hit);
if (hit.avoided == true) {
if (hit.riposted == true && originalDamage > 0) {
if (defender.isPlayer()) {
((Player) defender.getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You riposte the attack!");
defender.tryIncreaseSkill("RIPOSTE", 1);
}
if (isPlayer()) {
((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* " + defender.getBukkitLivingEntity().getCustomName() + " ripostes your attack!");
damage(plugin, originalDamage, getBukkitLivingEntity());
}
}
if (hit.dodged == true) {
if (defender.isPlayer()) {
((Player) defender.getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You dodge the attack!");
defender.tryIncreaseSkill("DODGE", 1);
}
if (isPlayer()) {
((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* " + defender.getBukkitLivingEntity().getCustomName() + " dodges your attack!");
}
}
}
if (hit.damage_done >= 0) {
if (defender.checkHitChance(this, hit)) {
hit = defender.meleeMitigation(this, hit);
if (hit.damage_done > 0) {
hit = applyDamageTable(hit);
hit = commonOutgoingHitSuccess(defender, hit);
}
} else {
if (getBukkitLivingEntity() instanceof Player) {
((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You tried to hit " + defender.getBukkitLivingEntity().getCustomName() + ", but missed!"));
}
if (defender.getBukkitLivingEntity() instanceof Player) {
((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(getBukkitLivingEntity().getCustomName() + " tried to hit you, but missed!"));
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
solplayer.tryIncreaseSkill("DEFENSE", 1);
} catch (CoreStateInitException e) {
// skip
}
}
hit.damage_done = 0;
}
}
return hit;
}
Aggregations