Skip to content

Commit

Permalink
#patch Fixed plugin "crash" none paper software servers (#56)
Browse files Browse the repository at this point in the history
* Bump version from 1.3.11 to 1.3.11-SNAPSHOT0

* Fixed VersionUtils.teleport on none paper software servers

* Bump version from 1.3.11-SNAPSHOT0 to 1.3.11-SNAPSHOT1

* Fixed CommandArgument could have multiple permissions while only the first one was checked

* Removed depreciated class User usage

* Fixed MaterialUtils.getMat did not force default material on null

* Fixed some sonarcloud code bugs

* Bump version from 1.3.11-SNAPSHOT1 to 1.3.11-SNAPSHOT2

* Fixed Security Hotspots

* Bump version from 1.3.11-SNAPSHOT2 to 1.3.11-SNAPSHOT3

* Revert MaterialUtils

* Bump version from 1.3.11-SNAPSHOT3 to 1.3.11-SNAPSHOT4

* Optimized Command Permission check

* Bump version from 1.3.11-SNAPSHOT4 to 1.3.11-SNAPSHOT5

---------

Co-authored-by: version-bump[github-action] <41898282+version-bump[github-action]@users.noreply.github.com>
  • Loading branch information
Tigerpanzer02 and version-bump[github-action] authored Jul 10, 2024
1 parent dd67de5 commit 773f7fb
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,20 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
for(CommandArgument argument : entry.getValue()) {
if(argument.getArgumentName().equalsIgnoreCase(args[0])) {
//does it make sense that it is a list?
boolean gotPermissions = false;
for(String perm : argument.getPermissions()) {
if(perm.isEmpty() || plugin.getBukkitHelper().hasPermission(sender, perm)) {
break;
gotPermissions = true;
}
//user has no permission to execute command
}
if(!gotPermissions) {
new MessageBuilder("COMMANDS_NO_PERMISSION").asKey().send(sender);
return true;
}
if(checkSenderIsExecutorType(sender, argument.getValidExecutors())) {
argument.execute(sender, args);
return true;
}
//return true even if sender is not good executor or hasn't got permission
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void registerKits(List<String> optionalConfigurations) {
}
} catch (Exception exception) {
plugin.getDebugger().debug(Level.WARNING, "ERROR IN LOADING KITS");
exception.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public class User implements IUser {
private final Map<String, Double> cooldowns = new HashMap<>();
private boolean initialized;

@Deprecated
public User(Player player) {
this(player.getUniqueId());
}

public User(UUID uuid) {
this.uuid = uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ private void throwException(@NotNull SQLException exception) {
plugin.getDebugger().debug(Level.WARNING, "SQLException occurred! Cause: {0} ({1})", exception.getSQLState(), exception.getErrorCode());
plugin.getMessageUtils().errorOccurred();
Bukkit.getConsoleSender().sendMessage("Check configuration of mysql.yml file or try to disable mysql option in config.yml");
exception.printStackTrace();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import plugily.projects.minigamesbox.classic.PluginMain;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -36,6 +38,7 @@ public class Cuboid {
private final double xMinCentered, xMaxCentered, yMinCentered, yMaxCentered, zMinCentered, zMaxCentered;
private final World world;


public Cuboid(final Location point1, final Location point2) {
xMin = Math.min(point1.getBlockX(), point2.getBlockX());
xMax = Math.max(point1.getBlockX(), point2.getBlockX());
Expand Down Expand Up @@ -124,10 +127,10 @@ public Location getMaxPoint() {
}

public Location getRandomLocation() {
final Random rand = new Random();
final int x = rand.nextInt(Math.abs(xMax - xMin) + 1) + xMin;
final int y = rand.nextInt(Math.abs(yMax - yMin) + 1) + yMin;
final int z = rand.nextInt(Math.abs(zMax - zMin) + 1) + zMin;
PluginMain plugin = JavaPlugin.getPlugin(PluginMain.class);
final int x = plugin.getRandom().nextInt(Math.abs(xMax - xMin) + 1) + xMin;
final int y = plugin.getRandom().nextInt(Math.abs(yMax - yMin) + 1) + yMin;
final int z = plugin.getRandom().nextInt(Math.abs(zMax - zMin) + 1) + zMin;
return new Location(world, x, y, z);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void takeOneItem(Player player, ItemStack stack) {
* @return serialized number
*/
public int serializeInt(int i) {
return (i % 9) == 0 ? i : (int) ((Math.ceil(i / 9) * 9) + 9);
return (i % 9) == 0 ? i : (int) ((Math.ceil((double) i / 9) * 9) + 9);
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static boolean isDoor(Material mat) {

private static Material getMat(String name) {
Material material = Material.getMaterial(name.toUpperCase());
if (material== null){
if(material == null) {
material = XMaterial.OAK_SIGN.parseMaterial();
}
return Material.getMaterial(name.toUpperCase());
return material;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
invFile.delete();
}


FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);

invConfig.set("ExperienceProgress", player.getExp());
Expand Down Expand Up @@ -148,7 +149,6 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
plugin.getLogger().log(Level.INFO, "Saved inventory of {0}", player.getName());
return true;
} catch(Exception ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
return false;
Expand Down Expand Up @@ -181,14 +181,12 @@ private static Inventory getInventoryFromFile(JavaPlugin plugin, String uuid) {
try {
inventory.setContents(invContents);
} catch(IllegalArgumentException ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot get inventory of player! Inventory has more items than the default content size.");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
}
file.delete();
return inventory;
} catch(Exception ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
return Bukkit.createInventory(null, 9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void startSubmitting() {
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
scheduler.scheduleAtFixedRate(
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
submitTask, initialDelay + secondDelay, 1800000, TimeUnit.MILLISECONDS);
}

private void submitData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ public static CompletableFuture<Boolean> teleport(Entity entity, Location locati

try {
return Bukkit.getScheduler().callSyncMethod(plugin, () -> PaperLib.teleportAsync(entity, location)).get();
} catch(InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch(CancellationException e) {
// ignored
} catch(InterruptedException | ExecutionException | CancellationException e) {
Thread.currentThread().interrupt();
}
} else {
entity.teleport(location);
return CompletableFuture.completedFuture(Boolean.TRUE);
}
return new CompletableFuture<>();
return CompletableFuture.completedFuture(Boolean.FALSE);
}

public static void sendParticles(String particleName, Player player, Location location, int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static double round(double value, int places) {
throw new IllegalArgumentException();
}

BigDecimal bd = new BigDecimal(value);
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
group=plugily.projects
version=1.3.11
version=1.3.11-SNAPSHOT5

0 comments on commit 773f7fb

Please sign in to comment.