Skip to content

Commit

Permalink
Update 1.0.4
Browse files Browse the repository at this point in the history
Custom MySQL port
  • Loading branch information
Avalanche7CZ committed Jan 18, 2024
1 parent 6fa6f1f commit c805500
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 644 deletions.
Binary file not shown.
97 changes: 34 additions & 63 deletions src/main/java/net/arcturus/mc/bcl/BetterChunkLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,94 @@

import java.io.File;
import java.util.UUID;

import net.arcturus.mc.bcl.datastore.DataStoreManager;
import net.arcturus.mc.bcl.datastore.MySqlDataStore;
import net.arcturus.mc.bcl.datastore.XmlDataStore;
import net.kaikk.mc.bcl.forgelib.BCLForgeLib;

import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class BetterChunkLoader extends JavaPlugin {
private static BetterChunkLoader instance;

private Config config;

public void onLoad() {
// Register XML DataStore
DataStoreManager.registerDataStore("XML", XmlDataStore.class);

// Register MySQL DataStore
DataStoreManager.registerDataStore("MySQL", MySqlDataStore.class);
}

public void onEnable() {
// check if forge is running
try {
Class.forName("net.minecraftforge.common.ForgeVersion");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Thermos/KCauldron/Crucible and BCLForgeLib are needed to run this plugin!");
throw new RuntimeException("Cauldron/KCauldron and BCLForgeLib are needed to run this plugin!");
}

// check if BCLForgeLib is present
try {
Class.forName("net.kaikk.mc.bcl.forgelib.BCLForgeLib");
} catch (ClassNotFoundException e) {
throw new RuntimeException("BCLForgeLib is needed to run this plugin!");
}

Bukkit.getConsoleSender().sendMessage("=========================");
Bukkit.getConsoleSender().sendMessage("BetterChunkLoader");
Bukkit.getConsoleSender().sendMessage("Version " + getDescription().getVersion());
Bukkit.getConsoleSender().sendMessage("Fork Author: Avalanche7CZ");
Bukkit.getConsoleSender().sendMessage("=========================");

instance=this;

instance = this;
try {
// load config
this.getLogger().info("Loading config...");
getLogger().info("Loading config...");
this.config = new Config(this);

// instantiate data store, if needed
if (DataStoreManager.getDataStore()==null) {
DataStoreManager.setDataStoreInstance(config.dataStore);
}

// load datastore
this.getLogger().info("Loading "+DataStoreManager.getDataStore().getName()+" Data Store...");
if (DataStoreManager.getDataStore() == null)
DataStoreManager.setDataStoreInstance(this.config.dataStore);
getLogger().info("Loading " + DataStoreManager.getDataStore().getName() + " Data Store...");
DataStoreManager.getDataStore().load();

this.getLogger().info("Loaded "+DataStoreManager.getDataStore().getChunkLoaders().size()+" chunk loaders data.");
this.getLogger().info("Loaded "+DataStoreManager.getDataStore().getPlayersData().size()+" players data.");

// load always on chunk loaders
int count=0;
getLogger().info("Loaded " + DataStoreManager.getDataStore().getChunkLoaders().size() + " chunk loaders data.");
getLogger().info("Loaded " + DataStoreManager.getDataStore().getPlayersData().size() + " players data.");
int count = 0;
for (CChunkLoader cl : DataStoreManager.getDataStore().getChunkLoaders()) {
if (cl.isLoadable()) {
BCLForgeLib.instance().addChunkLoader(cl);
count++;
}
}

this.getLogger().info("Loaded "+count+" always-on chunk loaders.");

this.getLogger().info("Loading Listeners...");
this.getServer().getPluginManager().registerEvents(new EventListener(this), this);
this.getCommand("betterchunkloader").setExecutor(new CommandExec(this));

getLogger().info("Loaded " + count + " always-on chunk loaders.");
getLogger().info("Loading Listeners...");
getServer().getPluginManager().registerEvents(new EventListener(this), (Plugin)this);
getCommand("betterchunkloader").setExecutor(new CommandExec(this));
getLogger().info("Load complete.");
} catch (Exception e) {
e.printStackTrace();
this.getLogger().warning("Load failed!");
Bukkit.getPluginManager().disablePlugin(this);
getLogger().warning("Load failed!");
Bukkit.getPluginManager().disablePlugin((Plugin)this);
}
}

public void onDisable() {
for (CChunkLoader cl : DataStoreManager.getDataStore().getChunkLoaders()) {
for (CChunkLoader cl : DataStoreManager.getDataStore().getChunkLoaders())
BCLForgeLib.instance().removeChunkLoader(cl);
}
instance=null;
instance = null;
}

public static BetterChunkLoader instance() {
return instance;
}

public static long getPlayerLastPlayed(UUID playerId) {
OfflinePlayer player = Bukkit.getOfflinePlayer(playerId);
if (player.getLastPlayed()!=0) {
if (player.getLastPlayed() != 0L)
return player.getLastPlayed();
} else if (player.getName()!=null && !player.getName().isEmpty()) {
if (player.getName() != null && !player.getName().isEmpty())
return getPlayerDataLastModified(playerId);
}

return 0;
return 0L;
}

public static long getPlayerDataLastModified(UUID playerId) {
File playerData =new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"+File.separator+playerId.toString()+".dat");
if (playerData.exists()) {
File playerData = new File(((World)Bukkit.getWorlds().get(0)).getWorldFolder(), "playerdata" + File.separator + playerId.toString() + ".dat");
if (playerData.exists())
return playerData.lastModified();
}
return 0;
return 0L;
}

public Config config() {
return this.config;
}
}

84 changes: 42 additions & 42 deletions src/main/java/net/arcturus/mc/bcl/BlockLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,37 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;

@XmlRootElement
@XmlAccessorType(value=XmlAccessType.NONE)
@XmlAccessorType(XmlAccessType.NONE)
public class BlockLocation {
@XmlAttribute
private String world;

@XmlAttribute
private int x;

@XmlAttribute
private int y;

@XmlAttribute
private int x,y,z;
private int z;

BlockLocation() {}

public BlockLocation(Block block) {
this(block.getLocation());
}

public BlockLocation(Location location) {
this(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}

public BlockLocation(String world, int x, int y, int z) {
this.world = world;
this.x = x;
Expand All @@ -37,74 +43,68 @@ public BlockLocation(String world, int x, int y, int z) {
}

public World getWorld() {
return Bukkit.getServer().getWorld(world);
return Bukkit.getServer().getWorld(this.world);
}

public String getWorldName() {
return this.world;
}

public Chunk getChunk() {
return this.getWorld().getChunkAt(this.getChunkX(), this.getChunkZ());
return getWorld().getChunkAt(getChunkX(), getChunkZ());
}

public Block getBlock() {
World world = this.getWorld();
if (world==null) {
World world = getWorld();
if (world == null)
return null;
}
return world.getBlockAt(x, y, z);
return world.getBlockAt(this.x, this.y, this.z);
}

public Location getLocation() {
Block block = this.getBlock();
if (block==null) {
Block block = getBlock();
if (block == null)
return null;
}
return block.getLocation();
}

public int getChunkX() {
return (int) (Math.floor(this.x/16.00));
return (int)Math.floor(this.x / 16.0D);
}

public int getChunkZ() {
return (int) (Math.floor(this.z/16.00));
return (int)Math.floor(this.z / 16.0D);
}

@Override

public boolean equals(Object obj) {
if (obj instanceof BlockLocation) {
BlockLocation loc = (BlockLocation) obj;
return this.x == loc.x && this.y == loc.y && this.z == loc.z && this.world.equals(loc.world);
} else if (obj instanceof Location) {
Location loc = (Location) obj;
return this.x == loc.getBlockX() && this.y == loc.getBlockY() && this.z == loc.getBlockZ() && this.world.equals(loc.getWorld().getName());
BlockLocation loc = (BlockLocation)obj;
return (this.x == loc.x && this.y == loc.y && this.z == loc.z && this.world.equals(loc.world));
}
if (obj instanceof Location) {
Location loc = (Location)obj;
return (this.x == loc.getBlockX() && this.y == loc.getBlockY() && this.z == loc.getBlockZ() && this.world.equals(loc.getWorld().getName()));
}
return false;
}

@Override

public int hashCode() {
return 37*(37*(37*this.world.hashCode()+this.x)+this.y)+this.z;
return 37 * (37 * (37 * this.world.hashCode() + this.x) + this.y) + this.z;
}

@Override

public String toString() {
return this.world+":"+this.x+","+this.y+","+this.z;
return this.world + ":" + this.x + "," + this.y + "," + this.z;
}

public int getX() {
return x;
return this.x;
}

public int getY() {
return y;
return this.y;
}

public int getZ() {
return z;
return this.z;
}


}
Loading

0 comments on commit c805500

Please sign in to comment.