Skip to content

Commit

Permalink
Merge pull request #7 from 4drian3d/changes
Browse files Browse the repository at this point in the history
Minor changes and removed unused code
  • Loading branch information
linsaftw authored Jul 8, 2021
2 parents 5a54fc3 + 5641aff commit facb5c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public void onPacketSending(PacketEvent event) {
final PacketContainer edited = packet.deepClone();
final StructureModifier<Integer> editedIntegers = edited.getIntegers();

if (version <= 210)
if (version <= 210) {
editedIntegers.write(0, 2002);
}

for (final SplashTranslator translator : SplashTranslator.values()) {
if (editedIntegers.read(1) == translator.getRGB()) {
for (final TranslationData data : translator.getDatas()) {
if (data.getLowestVersion() <= version && data.getHighestVersion() >= version)
if (data.getLowestVersion() <= version && data.getHighestVersion() >= version) {
editedIntegers.write(1, data.getRemap());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public AreaEffectCloudListener(final Plugin plugin, final VersionUtil versionUti

plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
for (final AreaEffectCloud cloud : effectClouds) {
if (cloud == null || cloud.isDead() || !cloud.isValid())
if (cloud == null || cloud.isDead() || !cloud.isValid()) {
effectClouds.remove(cloud);
}
else {
final Location location = cloud.getLocation();
final float radius = cloud.getRadius();
Expand All @@ -39,9 +40,11 @@ public AreaEffectCloudListener(final Plugin plugin, final VersionUtil versionUti
float f3 = (float) Math.cos(f1) * f2;
float f4 = (float) Math.sin(f1) * f2;

for (final Player player : cloud.getWorld().getPlayers())
if (versionUtil.getVersion(player) <= 106)
for (final Player player : cloud.getWorld().getPlayers()) {
if (versionUtil.getVersion(player) <= 106) {
player.spawnParticle(cloud.getParticle(), location.getX() + f3, location.getY(), location.getZ() + f4, 0, red / 255f, green / 255f, blue / 255f);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public void onPacketSending(final PacketEvent event) {
for (final PotionEffect effect : potion.getEffects()) {
for (final PotionTranslator translator : PotionTranslator.values()) {
if (effect.getType().equals(translator.getPotionEffectType())) {
for (TranslationData data : translator.getDatas())
if (data.getLowestVersion() <= version && data.getHighestVersion() >= version)
for (TranslationData data : translator.getDatas()) {
if (data.getLowestVersion() <= version && data.getHighestVersion() >= version) {
edited.getIntegers().write(7, data.getRemap());
}
}
}
}
}
Expand Down
51 changes: 3 additions & 48 deletions src/dev/_2lstudios/viarewindpotions/utils/ConfigurationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import org.bukkit.plugin.Plugin;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

public class ConfigurationUtil {
final private Plugin plugin;
Expand All @@ -19,53 +16,11 @@ public YamlConfiguration getConfiguration(String filePath) {
final File dataFolder = plugin.getDataFolder();
final File file = new File(filePath.replace("%datafolder%", dataFolder.toPath().toString()));

if (file.exists())
if (file.exists()) {
return YamlConfiguration.loadConfiguration(file);
else return new YamlConfiguration();
}

public void createConfiguration(String file) {
try {
final File dataFolder = plugin.getDataFolder();

file = file.replace("%datafolder%", dataFolder.toPath().toString());

final File configFile = new File(file);

if (!configFile.exists()) {
final String[] files = file.split("/");
final InputStream inputStream = plugin.getClass().getClassLoader().getResourceAsStream(files[files.length - 1]);
final File parentFile = configFile.getParentFile();

if (parentFile != null) parentFile.mkdirs();

if (inputStream != null) {
Files.copy(inputStream, configFile.toPath());
System.out.print(("[%pluginname%] File " + configFile + " has been created!").replace("%pluginname%", plugin.getDescription().getName()));
} else configFile.createNewFile();
}
} catch (final IOException e) {
System.out.print(("[%pluginname%] Unable to create configuration file!").replace("%pluginname%", plugin.getDescription().getName()));
} else {
return new YamlConfiguration();
}
}

public void saveConfiguration(final YamlConfiguration yamlConfiguration, final String file) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
try {
final File dataFolder = plugin.getDataFolder();

yamlConfiguration.save(file.replace("%datafolder%", dataFolder.toPath().toString()));
} catch (final IOException e) {
System.out.print(("[%pluginname%] Unable to save configuration file!").replace("%pluginname%", plugin.getDescription().getName()));
}
});
}

public void deleteConfiguration(final String file) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
final File file1 = new File(file);

if (file1.exists()) file1.delete();
});
}
}
6 changes: 4 additions & 2 deletions src/dev/_2lstudios/viarewindpotions/utils/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public int getVersion(Player player) {
if (protocolSupportVersion == latest && viaVersion != null) {
final int viaVersionVersion = getViaVersionVersion(player);

if (viaVersionVersion != latest)
if (viaVersionVersion != latest) {
return viaVersionVersion;
}
}

return protocolSupportVersion;
} else if (viaVersion != null)
} else if (viaVersion != null) {
return getViaVersionVersion(player);
}

return -1;
}
Expand Down

0 comments on commit facb5c0

Please sign in to comment.