Add code.

This commit is contained in:
Hyperling 2018-12-28 08:55:40 -06:00
parent 9bd39116e2
commit d2ce140fe5
10 changed files with 143 additions and 0 deletions

47
pom.xml Normal file
View File

@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hyperling.minecraft</groupId>
<artifactId>CoderDojoTest</artifactId>
<version>0.1.3-SNAPSHOT</version>
<name>Coder Dojo Test</name>
<description>Test project written to learn how to do Minecraft plug-in for Coder Dojo.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version or use LATEST-->
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version-->
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,84 @@
package com.hyperling.minecraft.coderdojotest;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;
public final class CoderDojoTest extends JavaPlugin implements Listener {
public CoderDojoTest() {
}
@Override
public void onEnable() {
getLogger().info("onEnable has been accessed.");
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
getLogger().info("onDisable has been accessed.");
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
getLogger().info("Running onJoin.");
Player player = event.getPlayer();
getServer().broadcastMessage("Welcome to the server, " + player.getDisplayName() + "!");
final PlayerInventory inv = player.getInventory();
// Give diamond tools and food if not in creative
if (getServer().getDefaultGameMode() != GameMode.CREATIVE) {
getServer().broadcastMessage("Enjoy your items!");
ItemStack item;
item = new ItemStack(Material.DIAMOND_SWORD);
inv.remove(Material.DIAMOND_SWORD);
inv.addItem(item);
item = new ItemStack(Material.DIAMOND_AXE);
inv.remove(Material.DIAMOND_AXE);
inv.addItem(item);
item = new ItemStack(Material.DIAMOND_PICKAXE);
inv.remove(Material.DIAMOND_PICKAXE);
inv.addItem(item);
item = new ItemStack(Material.DIAMOND_SPADE);
inv.remove(Material.DIAMOND_SPADE);
inv.addItem(item);
item = new ItemStack(Material.DIAMOND_HOE);
inv.remove(Material.DIAMOND_HOE);
inv.addItem(item);
// Give food
item = new ItemStack(Material.GOLDEN_APPLE);
inv.remove(Material.GOLDEN_APPLE);
item.setAmount(64);
inv.addItem(item);
// These work
item = new ItemStack(Material.DIAMOND_BOOTS);
inv.setBoots(item);
item = new ItemStack(Material.DIAMOND_LEGGINGS);
inv.setLeggings(item);
item = new ItemStack(Material.DIAMOND_CHESTPLATE);
inv.setChestplate(item);
item = new ItemStack(Material.DIAMOND_HELMET);
inv.setHelmet(item);
}
else {
inv.clear();
getServer().broadcastMessage("Inventory has been cleared for Creative mode.");
}
getLogger().info("Refreshed diamond items.");
}
}

View File

@ -0,0 +1,3 @@
name: CoderDojoTest
main: com.hyperling.minecraft.coderdojotest.CoderDojoTest
version: 0.1.2

Binary file not shown.

View File

@ -0,0 +1,3 @@
name: CoderDojoTest
main: com.hyperling.minecraft.coderdojotest.CoderDojoTest
version: 0.1.2

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Thu Dec 27 10:04:47 CST 2018
version=0.1.3-SNAPSHOT
groupId=com.hyperling.minecraft
artifactId=CoderDojoTest

View File

@ -0,0 +1 @@
/home/ling/Programs/eclipse-workspace/CoderDojoTest/src/main/java/com/hyperling/minecraft/coderdojotest/CoderDojoTest.java